diff --git a/admin/Variantes.Designer.cs b/admin/Variantes.Designer.cs index 37bc1d6..3905724 100644 --- a/admin/Variantes.Designer.cs +++ b/admin/Variantes.Designer.cs @@ -40,6 +40,7 @@ this.VariantePanel.Name = "VariantePanel"; this.VariantePanel.Size = new System.Drawing.Size(1146, 516); this.VariantePanel.TabIndex = 16; + this.VariantePanel.Paint += new System.Windows.Forms.PaintEventHandler(this.VariantePanel_Paint); // // btnAgregar // @@ -59,7 +60,7 @@ this.ClientSize = new System.Drawing.Size(1171, 587); this.Controls.Add(this.btnAgregar); this.Controls.Add(this.VariantePanel); - this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.Margin = new System.Windows.Forms.Padding(2); this.Name = "Variantes"; this.Text = "Variantes"; this.Load += new System.EventHandler(this.Variantes_Load); diff --git a/admin/Variantes.cs b/admin/Variantes.cs index 4ca55eb..596b08c 100644 --- a/admin/Variantes.cs +++ b/admin/Variantes.cs @@ -113,31 +113,9 @@ namespace compabetov2.admin "Confirmación", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { - if (service.eliminarProducto(producto)) + if (service.eliminarVariante(variante.idVariante)) { - //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(); - } } }); @@ -167,5 +145,10 @@ namespace compabetov2.admin ventana.Owner = this; ventana.Show(); } + + private void VariantePanel_Paint(object sender, PaintEventArgs e) + { + + } } } diff --git a/admin/addvariante.cs b/admin/addvariante.cs index 99dd563..f6e1154 100644 --- a/admin/addvariante.cs +++ b/admin/addvariante.cs @@ -1,4 +1,5 @@ -using compabetov2.database.modelos; +using compabetov2.database; +using compabetov2.database.modelos; using System; using System.Collections.Generic; using System.ComponentModel; @@ -41,6 +42,12 @@ namespace compabetov2.admin producto.idProducto, Decimal.Parse(txtPrecioCompra.Text) ); + + if (service.insertarVariante(NuevaVariante)) + { + Close(); + ventanaPadre.llenarLayout(); + } } } diff --git a/admin/agregarproducto.cs b/admin/agregarproducto.cs index b88f5ce..1e32297 100644 --- a/admin/agregarproducto.cs +++ b/admin/agregarproducto.cs @@ -16,7 +16,7 @@ namespace compabetov2.admin public partial class agregarproducto : Form { private crud ventanaPadre; - private string imagePath; + private string imagePath = ""; public agregarproducto(crud ventanaPadre) { this.ventanaPadre = ventanaPadre; diff --git a/bin/Debug/Resources/logo.png b/bin/Debug/Resources/logo.png new file mode 100644 index 0000000..6a81398 Binary files /dev/null and b/bin/Debug/Resources/logo.png differ diff --git a/bin/Debug/compabetov2.exe b/bin/Debug/compabetov2.exe index 9c94853..109e723 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 c2b59ed..71391ce 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 732be46..13f9ed8 100644 Binary files a/bin/Debug/data.db and b/bin/Debug/data.db differ diff --git a/bin/Debug/produtos_img/logo.png b/bin/Debug/produtos_img/logo.png new file mode 100644 index 0000000..6a81398 Binary files /dev/null and b/bin/Debug/produtos_img/logo.png differ diff --git a/database/DAO.cs b/database/DAO.cs index 27c1a03..09ce953 100644 --- a/database/DAO.cs +++ b/database/DAO.cs @@ -10,6 +10,7 @@ using System.Security.Policy; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using compabetov2.admin; using compabetov2.database; using compabetov2.database.modelos; @@ -1807,6 +1808,60 @@ namespace compabetov2.database } } + public static bool insertarVarianteDAO(Variante variante) + { + var db_conexion = new Conexion(); + try + { + SQLiteConnection conexion = db_conexion.get_connection(); + conexion.Open(); + + string sql = "INSERT INTO variantes (nombre, precio, cantidad, img, fk_producto, precioCompra) " + + "VALUES(@nombre, @precio, @cantidad, @img, @fk_producto, @precioCompra);"; + + + SQLiteCommand command = new SQLiteCommand(sql, conexion); + command.Parameters.AddWithValue("@nombre", variante.nombre); + command.Parameters.AddWithValue("@precio", variante.precio); + command.Parameters.AddWithValue("@cantidad", variante.cantidad); + command.Parameters.AddWithValue("@img", variante.img); + command.Parameters.AddWithValue("@fk_producto", variante.fkProducto); + command.Parameters.AddWithValue("@precioCompra", variante.precioCompra); + command.ExecuteNonQuery(); + + return true; + } + catch (SQLiteException ex) + { + MessageBox.Show(ex.Message); + return false; + } + } + + public static bool eliminarVarianteDAO(int idVariante) + { + var db_conexion = new Conexion(); + try + { + SQLiteConnection conexion = db_conexion.get_connection(); + conexion.Open(); + + string sql = "DELETE FROM variantes WHERE idVariante = @idVariante;"; + + + SQLiteCommand command = new SQLiteCommand(sql, conexion); + command.Parameters.AddWithValue("@idVariante", idVariante); + command.ExecuteNonQuery(); + + return true; + } + catch (SQLiteException ex) + { + MessageBox.Show(ex.Message); + return false; + } + } + public static SQLiteDataReader conseguirImportesDAO() { SQLiteDataReader reader = null; diff --git a/database/service.cs b/database/service.cs index 87c2212..2b38dd0 100644 --- a/database/service.cs +++ b/database/service.cs @@ -603,6 +603,16 @@ namespace compabetov2.database return variantes; } + public static bool insertarVariante(Variante variante) + { + return DAO.insertarVarianteDAO(variante); + } + + public static bool eliminarVariante(int idVariante) + { + return DAO.eliminarVarianteDAO(idVariante); + } + public static List conseguirImportes() { List importes = new List(); diff --git a/obj/Debug/compabetov2.csproj.AssemblyReference.cache b/obj/Debug/compabetov2.csproj.AssemblyReference.cache index 7695aa1..6f8a4e4 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 632f690..9037b20 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 9c94853..109e723 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 c2b59ed..71391ce 100644 Binary files a/obj/Debug/compabetov2.pdb and b/obj/Debug/compabetov2.pdb differ