admin sin errores
This commit is contained in:
Generated
+1
@@ -117,6 +117,7 @@
|
|||||||
this.button3.TabIndex = 10;
|
this.button3.TabIndex = 10;
|
||||||
this.button3.Text = "Productos";
|
this.button3.Text = "Productos";
|
||||||
this.button3.UseVisualStyleBackColor = false;
|
this.button3.UseVisualStyleBackColor = false;
|
||||||
|
this.button3.Click += new System.EventHandler(this.button3_Click);
|
||||||
//
|
//
|
||||||
// button5
|
// button5
|
||||||
//
|
//
|
||||||
|
|||||||
+25
-2
@@ -9,6 +9,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using compabetov2.admin;
|
||||||
|
|
||||||
namespace compabetov2
|
namespace compabetov2
|
||||||
{
|
{
|
||||||
@@ -246,8 +247,30 @@ namespace compabetov2
|
|||||||
|
|
||||||
private void button2_Click(object sender, EventArgs e)
|
private void button2_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Estadiscticas verstats = new Estadiscticas();
|
if (loginPrincipal.tipo.Equals("empleado"))
|
||||||
verstats.Show();
|
{
|
||||||
|
MessageBox.Show("Usted no tiene permisos de acceder a este apartado");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Estadiscticas estadiscticas = new Estadiscticas();
|
||||||
|
estadiscticas.Owner = this;
|
||||||
|
estadiscticas.Show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void button3_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (loginPrincipal.tipo.Equals("empleado"))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Usted no tiene permisos de acceder a este apartado");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
crud crud = new crud();
|
||||||
|
crud.Owner = this;
|
||||||
|
crud.Show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-2
@@ -429,8 +429,16 @@ namespace compabetov2
|
|||||||
|
|
||||||
private void button2_Click(object sender, EventArgs e)
|
private void button2_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Estadiscticas verstats = new Estadiscticas();
|
if (loginPrincipal.tipo.Equals("empleado"))
|
||||||
verstats.Show();
|
{
|
||||||
|
MessageBox.Show("Usted no tiene permisos de acceder a este apartado");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Estadiscticas estadiscticas = new Estadiscticas();
|
||||||
|
estadiscticas.Owner = this;
|
||||||
|
estadiscticas.Show();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void txtTelefono_TextChanged(object sender, EventArgs e)
|
private void txtTelefono_TextChanged(object sender, EventArgs e)
|
||||||
|
|||||||
@@ -865,11 +865,18 @@ namespace compabetov2
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void button2_Click(object sender, EventArgs e)
|
private void button2_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (loginPrincipal.tipo.Equals("empleado"))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Usted no tiene permisos de acceder a este apartado");
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
Estadiscticas estadiscticas = new Estadiscticas();
|
Estadiscticas estadiscticas = new Estadiscticas();
|
||||||
estadiscticas.Owner = this;
|
estadiscticas.Owner = this;
|
||||||
estadiscticas.Show();
|
estadiscticas.Show();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void btnImporte_Click(object sender, EventArgs e)
|
private void btnImporte_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ namespace compabetov2.admin
|
|||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
MessageBox.Show("Por favor introduzca un precio valido", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show("Por favor introduzca un numero valido en volumen", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-23
@@ -63,37 +63,18 @@ namespace compabetov2.admin
|
|||||||
//en caso de que descida cambiar la imagen
|
//en caso de que descida cambiar la imagen
|
||||||
if (!imagePath.Equals(""))
|
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))
|
if (service.editarProducto(productoNuevo))
|
||||||
|
{
|
||||||
|
if(Path.GetFileName(imagePath) != producto.img)
|
||||||
{
|
{
|
||||||
//guardar imagen nueva
|
//guardar imagen nueva
|
||||||
string destinationFolder = Path.Combine(Application.StartupPath, "Resources");
|
string destinationFolder = Path.Combine(Application.StartupPath, "Resources");
|
||||||
string destinationFile = Path.Combine(destinationFolder, Path.GetFileName(imagePath));
|
string destinationFile = Path.Combine(destinationFolder, Path.GetFileName(imagePath));
|
||||||
File.Copy(imagePath, destinationFile, true);
|
File.Copy(imagePath, destinationFile, true);
|
||||||
|
}
|
||||||
|
|
||||||
ventanaPadre.llenarLayout();
|
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();
|
Close();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -111,6 +92,7 @@ namespace compabetov2.admin
|
|||||||
}
|
}
|
||||||
catch(Exception ex)
|
catch(Exception ex)
|
||||||
{
|
{
|
||||||
|
MessageBox.Show(ex.Message);
|
||||||
MessageBox.Show("Por favor introduzca un precio valido", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show("Por favor introduzca un precio valido", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ namespace compabetov2.admin
|
|||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
MessageBox.Show("Por favor introduzca un precio valido", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show("Por favor introduzca un numero valido en volumen", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 143 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
+27
-7
@@ -524,22 +524,42 @@ namespace compabetov2.database
|
|||||||
|
|
||||||
public static bool eliminarProductoDAO(Producto producto)
|
public static bool eliminarProductoDAO(Producto producto)
|
||||||
{
|
{
|
||||||
|
|
||||||
var db_conexion = new Conexion();
|
var db_conexion = new Conexion();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (SQLiteConnection conexion = db_conexion.get_connection())
|
using (SQLiteConnection conexion = db_conexion.get_connection())
|
||||||
{
|
{
|
||||||
conexion.Open();
|
conexion.Open();
|
||||||
|
|
||||||
string sql = "DELETE FROM Producto WHERE idproducto = @idproducto";
|
using (var transaccion = conexion.BeginTransaction())
|
||||||
|
|
||||||
using (SQLiteCommand command = new SQLiteCommand(sql, conexion))
|
|
||||||
{
|
{
|
||||||
command.Parameters.AddWithValue("@idproducto", producto.idProducto);
|
try
|
||||||
int filasAfectadas = command.ExecuteNonQuery();
|
{
|
||||||
|
string sql = "DELETE FROM Producto WHERE idproducto = @idproducto";
|
||||||
|
string sqlVariante = "DELETE FROM variantes WHERE fk_producto=@fk_producto;";
|
||||||
|
|
||||||
|
SQLiteCommand commandProducto = new SQLiteCommand(sql, conexion);
|
||||||
|
commandProducto.Parameters.AddWithValue("@idproducto", producto.idProducto);
|
||||||
|
int filasAfectadas = commandProducto.ExecuteNonQuery();
|
||||||
|
|
||||||
|
SQLiteCommand commandVariante = new SQLiteCommand(sqlVariante, conexion);
|
||||||
|
commandVariante.Parameters.AddWithValue("@fk_producto", producto.idProducto);
|
||||||
|
commandVariante.ExecuteNonQuery();
|
||||||
|
|
||||||
|
transaccion.Commit();
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (SQLiteException ex)
|
||||||
|
{
|
||||||
|
transaccion.Rollback();
|
||||||
|
MessageBox.Show(ex.Message);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (filasAfectadas > 0) { return true; }
|
|
||||||
else { return false; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user