diff --git a/Cuentas/cuentas.Designer.cs b/Cuentas/cuentas.Designer.cs index b30a8f8..60ed6b3 100644 --- a/Cuentas/cuentas.Designer.cs +++ b/Cuentas/cuentas.Designer.cs @@ -117,6 +117,7 @@ this.button3.TabIndex = 10; this.button3.Text = "Productos"; this.button3.UseVisualStyleBackColor = false; + this.button3.Click += new System.EventHandler(this.button3_Click); // // button5 // diff --git a/Cuentas/cuentas.cs b/Cuentas/cuentas.cs index fa4499d..7d132ba 100644 --- a/Cuentas/cuentas.cs +++ b/Cuentas/cuentas.cs @@ -9,6 +9,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using compabetov2.admin; namespace compabetov2 { @@ -55,7 +56,7 @@ namespace compabetov2 foreach (Cuenta cuenta in cuentas) { - + TableLayoutPanel carta = new TableLayoutPanel(); carta.RowCount = 1; carta.ColumnCount = 2; @@ -84,7 +85,7 @@ namespace compabetov2 total.Font = new Font(total.Font.FontFamily, 12); total.Width = 600; - Label estado = new Label(); + Label estado = new Label(); estado.Text = $"Estado: {cuenta.estado}"; estado.Font = new Font(total.Font.FontFamily, 12); estado.Width = 600; @@ -221,16 +222,16 @@ namespace compabetov2 MessageBox.Show(mensaje); }); - HUDPanel.Controls.Add(btnVer,2,0); + HUDPanel.Controls.Add(btnVer, 2, 0); carta.Controls.Add(HUDPanel, 1, 0); } - carta.Controls.Add(infoPanel,0,0); - + carta.Controls.Add(infoPanel, 0, 0); + panelCuenta.Controls.Add(carta); - + } } @@ -246,8 +247,30 @@ namespace compabetov2 private void button2_Click(object sender, EventArgs e) { - Estadiscticas verstats = new Estadiscticas(); - verstats.Show(); + if (loginPrincipal.tipo.Equals("empleado")) + { + 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(); + } } } } diff --git a/Envios/envios.cs b/Envios/envios.cs index 92f4b78..1568d00 100644 --- a/Envios/envios.cs +++ b/Envios/envios.cs @@ -429,8 +429,16 @@ namespace compabetov2 private void button2_Click(object sender, EventArgs e) { - Estadiscticas verstats = new Estadiscticas(); - verstats.Show(); + if (loginPrincipal.tipo.Equals("empleado")) + { + 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) diff --git a/Ventas/vender.cs b/Ventas/vender.cs index 7a2257d..1368c4d 100644 --- a/Ventas/vender.cs +++ b/Ventas/vender.cs @@ -866,9 +866,16 @@ namespace compabetov2 private void button2_Click(object sender, EventArgs e) { - Estadiscticas estadiscticas = new Estadiscticas(); - estadiscticas.Owner = this; - estadiscticas.Show(); + if (loginPrincipal.tipo.Equals("empleado")) + { + MessageBox.Show("Usted no tiene permisos de acceder a este apartado"); + } + else + { + Estadiscticas estadiscticas = new Estadiscticas(); + estadiscticas.Owner = this; + estadiscticas.Show(); + } } private void btnImporte_Click(object sender, EventArgs e) diff --git a/admin/addvariante.cs b/admin/addvariante.cs index cbd4a97..74e8026 100644 --- a/admin/addvariante.cs +++ b/admin/addvariante.cs @@ -63,7 +63,7 @@ namespace compabetov2.admin } 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; } } diff --git a/admin/editar.cs b/admin/editar.cs index b548368..57577f9 100644 --- a/admin/editar.cs +++ b/admin/editar.cs @@ -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); } } diff --git a/admin/editarvariante.cs b/admin/editarvariante.cs index 7137bba..2cc8c6a 100644 --- a/admin/editarvariante.cs +++ b/admin/editarvariante.cs @@ -69,7 +69,7 @@ namespace compabetov2.admin } 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; } } diff --git a/bin/Debug/Resources/1.png b/bin/Debug/Resources/1.png new file mode 100644 index 0000000..884a3ab Binary files /dev/null and b/bin/Debug/Resources/1.png differ diff --git a/bin/Debug/compabetov2.exe b/bin/Debug/compabetov2.exe index 4045321..742187f 100644 Binary files a/bin/Debug/compabetov2.exe and b/bin/Debug/compabetov2.exe differ diff --git a/bin/Debug/compabetov2.pdb b/bin/Debug/compabetov2.pdb index 877a993..b3b97f9 100644 Binary files a/bin/Debug/compabetov2.pdb and b/bin/Debug/compabetov2.pdb differ diff --git a/bin/Debug/data.db b/bin/Debug/data.db index 9128c1a..3b51c8b 100644 Binary files a/bin/Debug/data.db and b/bin/Debug/data.db differ diff --git a/database/DAO.cs b/database/DAO.cs index d2adff3..dd9c97e 100644 --- a/database/DAO.cs +++ b/database/DAO.cs @@ -524,22 +524,42 @@ namespace compabetov2.database public static bool eliminarProductoDAO(Producto producto) { + var db_conexion = new Conexion(); + try { using (SQLiteConnection conexion = db_conexion.get_connection()) { conexion.Open(); - string sql = "DELETE FROM Producto WHERE idproducto = @idproducto"; - - using (SQLiteCommand command = new SQLiteCommand(sql, conexion)) + using (var transaccion = conexion.BeginTransaction()) { - command.Parameters.AddWithValue("@idproducto", producto.idProducto); - int filasAfectadas = command.ExecuteNonQuery(); + try + { + 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; } } } } diff --git a/obj/Debug/compabetov2.csproj.AssemblyReference.cache b/obj/Debug/compabetov2.csproj.AssemblyReference.cache index 0abd72f..b5abab5 100644 Binary files a/obj/Debug/compabetov2.csproj.AssemblyReference.cache and b/obj/Debug/compabetov2.csproj.AssemblyReference.cache differ diff --git a/obj/Debug/compabetov2.csproj.GenerateResource.cache b/obj/Debug/compabetov2.csproj.GenerateResource.cache index 29b0fd9..c653f44 100644 Binary files a/obj/Debug/compabetov2.csproj.GenerateResource.cache and b/obj/Debug/compabetov2.csproj.GenerateResource.cache differ diff --git a/obj/Debug/compabetov2.exe b/obj/Debug/compabetov2.exe index 4045321..742187f 100644 Binary files a/obj/Debug/compabetov2.exe and b/obj/Debug/compabetov2.exe differ diff --git a/obj/Debug/compabetov2.pdb b/obj/Debug/compabetov2.pdb index 877a993..b3b97f9 100644 Binary files a/obj/Debug/compabetov2.pdb and b/obj/Debug/compabetov2.pdb differ