admin sin errores
This commit is contained in:
+9
-27
@@ -63,37 +63,18 @@ namespace compabetov2.admin
|
||||
//en caso de que descida cambiar la imagen
|
||||
if (!imagePath.Equals(""))
|
||||
{
|
||||
Producto productoNuevo = new Producto(producto.idProducto, nombre, "", precio, imagePath, 0);
|
||||
Producto productoNuevo = new Producto(producto.idProducto, nombre, "", precio, Path.GetFileName(imagePath), 0);
|
||||
if (service.editarProducto(productoNuevo))
|
||||
{
|
||||
//guardar imagen nueva
|
||||
string destinationFolder = Path.Combine(Application.StartupPath, "Resources");
|
||||
string destinationFile = Path.Combine(destinationFolder, Path.GetFileName(imagePath));
|
||||
File.Copy(imagePath, destinationFile, true);
|
||||
if(Path.GetFileName(imagePath) != producto.img)
|
||||
{
|
||||
//guardar imagen nueva
|
||||
string destinationFolder = Path.Combine(Application.StartupPath, "Resources");
|
||||
string destinationFile = Path.Combine(destinationFolder, Path.GetFileName(imagePath));
|
||||
File.Copy(imagePath, destinationFile, true);
|
||||
}
|
||||
|
||||
ventanaPadre.llenarLayout();
|
||||
|
||||
|
||||
//eliminar imagen antigua
|
||||
string imagenEliminada = Path.Combine(destinationFolder, producto.img);
|
||||
//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);
|
||||
}
|
||||
};
|
||||
|
||||
Close();
|
||||
|
||||
}
|
||||
@@ -111,6 +92,7 @@ namespace compabetov2.admin
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
MessageBox.Show("Por favor introduzca un precio valido", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user