crud de variante en proceso
This commit is contained in:
+146
-3
@@ -1,8 +1,11 @@
|
||||
using System;
|
||||
using compabetov2.database;
|
||||
using compabetov2.database.modelos;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -13,16 +16,156 @@ namespace compabetov2.admin
|
||||
public partial class Variantes : Form
|
||||
{
|
||||
private crud ventanaPadre;
|
||||
public Variantes(crud ventanaPadre)
|
||||
private Producto producto;
|
||||
private List<Variante> variantes = new List<Variante>();
|
||||
public Variantes(crud ventanaPadre, Producto producto)
|
||||
{
|
||||
this.ventanaPadre = ventanaPadre;
|
||||
this.producto = producto;
|
||||
InitializeComponent();
|
||||
|
||||
llenarLayout();
|
||||
}
|
||||
|
||||
public void llenarLayout()
|
||||
{
|
||||
VariantePanel.Controls.Clear();
|
||||
variantes.Clear();
|
||||
variantes = service.conseguirVariante(producto.idProducto);
|
||||
|
||||
|
||||
foreach (Variante variante in variantes)
|
||||
{
|
||||
TableLayoutPanel filaLayout = new TableLayoutPanel();
|
||||
filaLayout.RowCount = 1;
|
||||
filaLayout.ColumnCount = 2;
|
||||
filaLayout.Height = 100;
|
||||
filaLayout.Width = 1115;
|
||||
filaLayout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
|
||||
filaLayout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
|
||||
filaLayout.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
|
||||
|
||||
|
||||
TableLayoutPanel informacionProducto = new TableLayoutPanel();
|
||||
informacionProducto.RowCount = 1;
|
||||
informacionProducto.ColumnCount = 2;
|
||||
informacionProducto.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 20F));
|
||||
informacionProducto.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 80F));
|
||||
informacionProducto.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
|
||||
informacionProducto.Dock = DockStyle.Fill;
|
||||
|
||||
Label idProducto = new Label();
|
||||
idProducto.Text = variante.idVariante.ToString();
|
||||
idProducto.BackColor = Color.FromArgb(82, 82, 82);
|
||||
idProducto.ForeColor = Color.White;
|
||||
idProducto.AutoSize = true;
|
||||
idProducto.Dock = DockStyle.Left;
|
||||
|
||||
PictureBox imagen = new PictureBox();
|
||||
string rutaImg = Path.Combine(Application.StartupPath, "Resources", variante.img);
|
||||
imagen.Image = Image.FromFile(rutaImg);
|
||||
imagen.Dock = DockStyle.Fill;
|
||||
imagen.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
imagen.SizeMode = PictureBoxSizeMode.Zoom;
|
||||
imagen.Controls.Add(idProducto);
|
||||
|
||||
|
||||
Label nombreStock = new Label();
|
||||
nombreStock.Text = variante.nombre + " - $" + variante.precio;
|
||||
nombreStock.Font = new Font(nombreStock.Font.FontFamily, 14);
|
||||
nombreStock.Dock = DockStyle.Fill;
|
||||
nombreStock.TextAlign = ContentAlignment.MiddleCenter;
|
||||
|
||||
//panel de agregar stock
|
||||
TableLayoutPanel agregarPanel = new TableLayoutPanel();
|
||||
agregarPanel.Dock = DockStyle.Fill;
|
||||
agregarPanel.RowCount = 1;
|
||||
agregarPanel.ColumnCount = 2;
|
||||
agregarPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 33F));
|
||||
agregarPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 33F));
|
||||
agregarPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 33F));
|
||||
agregarPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
|
||||
|
||||
Button btnEditar = new Button();
|
||||
btnEditar.Text = "Editar";
|
||||
btnEditar.Font = new Font(btnEditar.Font.FontFamily, 20);
|
||||
btnEditar.ForeColor = Color.White;
|
||||
btnEditar.FlatStyle = FlatStyle.Flat;
|
||||
btnEditar.FlatAppearance.BorderSize = 0;
|
||||
btnEditar.BackColor = Color.FromArgb(33, 90, 255);
|
||||
btnEditar.Dock = DockStyle.Fill;
|
||||
btnEditar.Click += new EventHandler(delegate (object sender, EventArgs e)
|
||||
{
|
||||
|
||||
});
|
||||
|
||||
|
||||
Button btnEliminar = new Button();
|
||||
btnEliminar.Text = "Eliminar";
|
||||
btnEliminar.Font = new Font(btnEliminar.Font.FontFamily, 20);
|
||||
btnEliminar.ForeColor = Color.White;
|
||||
btnEliminar.FlatStyle = FlatStyle.Flat;
|
||||
btnEliminar.FlatAppearance.BorderSize = 0;
|
||||
btnEliminar.BackColor = Color.Red;
|
||||
btnEliminar.Dock = DockStyle.Fill;
|
||||
btnEliminar.Click += new EventHandler(delegate (object sender, EventArgs e)
|
||||
{
|
||||
DialogResult result = MessageBox.Show($"¿Está seguro de que desea eliminar el producto {producto.nombre}?",
|
||||
"Confirmación", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
||||
if (result == DialogResult.Yes)
|
||||
{
|
||||
if (service.eliminarProducto(producto))
|
||||
{
|
||||
//eliminar imagen antigua
|
||||
string destinationFolder = Path.Combine(Application.StartupPath, "Resources");
|
||||
string imagenEliminada = Path.Combine(destinationFolder, producto.img);
|
||||
llenarLayout();
|
||||
//se pone a esperar 1 segundo antes de eliminar la imagen
|
||||
//esto para que al programa le de tiempo de dejar de utilizar la imagen y no lance una excepcion
|
||||
Timer timer = new Timer();
|
||||
timer.Interval = 1000; // 1 segundos
|
||||
timer.Tick += delegate (object sender2, EventArgs e2)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(imagenEliminada);
|
||||
timer.Stop();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Manejar la excepción de eliminación de archivo temporal
|
||||
Console.WriteLine("Error al eliminar archivo temporal: " + ex.Message);
|
||||
}
|
||||
};
|
||||
timer.Start();
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
informacionProducto.Controls.Add(imagen, 0, 0);
|
||||
informacionProducto.Controls.Add(nombreStock, 1, 0);
|
||||
|
||||
agregarPanel.Controls.Add(btnEditar, 0, 0);
|
||||
agregarPanel.Controls.Add(btnEliminar, 1, 0);
|
||||
|
||||
filaLayout.Controls.Add(informacionProducto, 0, 0);
|
||||
filaLayout.Controls.Add(agregarPanel, 1, 0);
|
||||
VariantePanel.Controls.Add(filaLayout);
|
||||
}
|
||||
}
|
||||
|
||||
private void Variantes_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void btnAgregar_Click(object sender, EventArgs e)
|
||||
{
|
||||
addvariante ventana = new addvariante(producto,this);
|
||||
ventana.Owner = this;
|
||||
ventana.Show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user