crud de productos completado
This commit is contained in:
+46
-4
@@ -24,9 +24,12 @@ namespace compabetov2.admin
|
||||
llenarLayout();
|
||||
}
|
||||
|
||||
private void llenarLayout()
|
||||
public void llenarLayout()
|
||||
{
|
||||
AdminPanel.Controls.Clear();
|
||||
productos.Clear();
|
||||
productos = service.conseguirProductos();
|
||||
|
||||
|
||||
foreach (Producto producto in productos)
|
||||
{
|
||||
@@ -107,6 +110,9 @@ namespace compabetov2.admin
|
||||
btnVariante.Dock = DockStyle.Fill;
|
||||
btnVariante.Click += new EventHandler(delegate (object sender, EventArgs e)
|
||||
{
|
||||
Variantes variantes = new Variantes(this);
|
||||
variantes.Owner = this;
|
||||
variantes.Show();
|
||||
});
|
||||
|
||||
Button btnEliminar = new Button();
|
||||
@@ -119,7 +125,37 @@ namespace compabetov2.admin
|
||||
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();
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -131,13 +167,12 @@ namespace compabetov2.admin
|
||||
agregarPanel.Controls.Add(btnVariante, 1, 0);
|
||||
agregarPanel.Controls.Add(btnEliminar, 2, 0);
|
||||
|
||||
|
||||
filaLayout.Controls.Add(informacionProducto, 0, 0);
|
||||
filaLayout.Controls.Add(agregarPanel, 1, 0);
|
||||
AdminPanel.Controls.Add(filaLayout);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void crud_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
@@ -169,5 +204,12 @@ namespace compabetov2.admin
|
||||
menuprincipalForm.BringToFront();
|
||||
}
|
||||
}
|
||||
|
||||
private void btnAgregar_Click(object sender, EventArgs e)
|
||||
{
|
||||
agregarproducto agregarproducto = new agregarproducto(this);
|
||||
agregarproducto.Owner = this;
|
||||
agregarproducto.Show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user