diff --git a/Ventas/vender.cs b/Ventas/vender.cs index 9d32a90..6b7f5b1 100644 --- a/Ventas/vender.cs +++ b/Ventas/vender.cs @@ -740,7 +740,8 @@ namespace compabetov2 private void btnFiar_Click(object sender, EventArgs e) { - List detallesCuenta = listaProductosCuenta(); + List detallesCuenta = new List(); + foreach (DetalleVentaModel detalleVenta in carrito) detallesCuenta.Add(detalleVenta.convertirADetalleCuenta()); if (detallesCuenta.Count > 0) @@ -758,46 +759,6 @@ namespace compabetov2 } - private List listaProductosCuenta() - { - List detallesCuentas = new List(); - int contador_saltar_2_vueltas = 1; - foreach (var item in flowLayoutPanel2.Controls) - { - if (contador_saltar_2_vueltas <= 3) - { - contador_saltar_2_vueltas++; - continue; - } - TableLayoutPanel panelProducto = item as TableLayoutPanel; - TableLayoutPanel panelInfo = panelProducto.Controls[1] as TableLayoutPanel; - PictureBox pic = panelProducto.Controls[0] as PictureBox; - Label idLabel = null; - foreach (Control control in pic.Controls) - { - if (control is Label) - { - idLabel = (Label)control; - break; - } - } - int idProducto = int.Parse(idLabel.Text); - Producto producto = new Producto(idProducto); - - Label Lbcantidad = panelInfo.Controls[2] as Label; - string textcantidad = Lbcantidad.Text; - string[] cantidadCadenas = textcantidad.Split(' '); - int cantidad = int.Parse(cantidadCadenas[1]); - - DetalleCuentaModel detalleCuenta = new DetalleCuentaModel(producto, cantidad); - - - detallesCuentas.Add(detalleCuenta); - } - - return detallesCuentas; - } - private void responsablecb_SelectedIndexChanged(object sender, EventArgs e) { // Verificar si hay un elemento seleccionado en el ComboBox diff --git a/bin/Debug/compabetov2.exe b/bin/Debug/compabetov2.exe index 293df4a..c954e28 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 da74f7d..2cb6fb5 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 60a4827..5b9a0aa 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 cce6f4e..78ae860 100644 --- a/database/DAO.cs +++ b/database/DAO.cs @@ -942,7 +942,7 @@ namespace compabetov2.database try { string sqlCuenta = "INSERT INTO cuenta (total, fecha, estado, descripcion,cliente) VALUES(@total, @fecha, 'ACTIVO', @descripcion,@cliente);"; - string sqlDetalle = "INSERT INTO detalle_cuenta (fk_cuenta, fk_producto, cantidad) VALUES(@fk_cuenta, @fk_producto, @cantidad);"; + string sqlDetalle = "INSERT INTO detalle_cuenta (fk_cuenta, fk_variante, cantidad) VALUES(@fk_cuenta, @fk_variante, @cantidad);"; string sqlIdCuenta = "SELECT idCuenta FROM cuenta ORDER BY idCuenta DESC LIMIT 1"; string sqlProductoStock = "SELECT stock FROM Producto WHERE idproducto = @idproducto"; string sqlProductoUpdate = "UPDATE Producto SET stock = @stock WHERE idproducto = @idproducto"; @@ -967,13 +967,13 @@ namespace compabetov2.database { SQLiteCommand commandDetalle = new SQLiteCommand(sqlDetalle, conexion); commandDetalle.Parameters.AddWithValue("@fk_cuenta", idCuenta); - commandDetalle.Parameters.AddWithValue("@fk_producto", detalleCuenta.producto.idProducto); + commandDetalle.Parameters.AddWithValue("@fk_variante", detalleCuenta.producto.idVariante); commandDetalle.Parameters.AddWithValue("@cantidad", detalleCuenta.cantidad); commandDetalle.ExecuteNonQuery(); //modificar stock SQLiteCommand commandProdcutoStock = new SQLiteCommand(sqlProductoStock, conexion); - commandProdcutoStock.Parameters.AddWithValue("@idproducto", detalleCuenta.producto.idProducto); + commandProdcutoStock.Parameters.AddWithValue("@idproducto", detalleCuenta.producto.fkProducto); SQLiteDataReader stockReader = commandProdcutoStock.ExecuteReader(); int stockActual = -1; @@ -984,8 +984,8 @@ namespace compabetov2.database } SQLiteCommand commandProdcutoUpdate = new SQLiteCommand(sqlProductoUpdate, conexion); - commandProdcutoUpdate.Parameters.AddWithValue("@stock", stockActual - detalleCuenta.cantidad); - commandProdcutoUpdate.Parameters.AddWithValue("@idproducto", detalleCuenta.producto.idProducto); + commandProdcutoUpdate.Parameters.AddWithValue("@stock", stockActual - (detalleCuenta.cantidad * detalleCuenta.producto.cantidad)); + commandProdcutoUpdate.Parameters.AddWithValue("@idproducto", detalleCuenta.producto.fkProducto); commandProdcutoUpdate.ExecuteNonQuery(); } @@ -1018,7 +1018,8 @@ namespace compabetov2.database conexion.Open(); - string sql = "Select p.idproducto, p.nombre , dc.cantidad from detalle_cuenta dc, Producto p WHERE dc.fk_producto = p.idproducto and dc.fk_cuenta = @fk_cuenta;"; + string sql = "Select v.idVariante , v.nombre ,v.cantidad ,v.fk_producto , dc.cantidad from detalle_cuenta dc, variantes v " + + "WHERE dc.fk_variante = v.idVariante and dc.fk_cuenta = @fk_cuenta;"; SQLiteCommand command = new SQLiteCommand(sql, conexion); command.Parameters.AddWithValue("@fk_cuenta", idCuenta); reader = command.ExecuteReader(); @@ -1086,7 +1087,7 @@ namespace compabetov2.database try { string sqlVenta = "INSERT INTO venta (fecha, total) VALUES(@fecha, @total);"; - string sqlDetalle = "INSERT INTO detalle_venta (fk_venta, fk_producto, cantidad) VALUES(@idVenta, @idProducto, @cantidada);"; + string sqlDetalle = "INSERT INTO detalle_venta (fk_venta, fk_variante, cantidad) VALUES(@idVenta, @fk_variante, @cantidada);"; string sqlCuenta = "UPDATE cuenta SET estado ='SALDADO' WHERE idCuenta = @idCuenta;"; string sqlIdVenta = "SELECT idVenta FROM venta ORDER BY idVenta DESC LIMIT 1"; @@ -1112,7 +1113,7 @@ namespace compabetov2.database { SQLiteCommand commandEmpleado = new SQLiteCommand(sqlDetalle, conexion); commandEmpleado.Parameters.AddWithValue("@idVenta", idVenta); - commandEmpleado.Parameters.AddWithValue("@idProducto", detalleCuenta.producto.idProducto); + commandEmpleado.Parameters.AddWithValue("@fk_variante", detalleCuenta.producto.idVariante); commandEmpleado.Parameters.AddWithValue("@cantidada", detalleCuenta.cantidad); commandEmpleado.ExecuteNonQuery(); } @@ -1637,8 +1638,8 @@ namespace compabetov2.database "CREATE TABLE cuenta (idCuenta INTEGER PRIMARY KEY AUTOINCREMENT, total DECIMAL(10,2), fecha TEXT, estado TEXT DEFAULT 'ACTIVO', descripcion TEXT, cliente TEXT DEFAULT '')", - "CREATE TABLE detalle_cuenta (fk_cuenta INTEGER, fk_producto INTEGER,cantidad INTEGER, PRIMARY KEY (fk_cuenta, fk_producto), " + - "FOREIGN KEY (fk_cuenta) REFERENCES Cuenta(idCuenta),FOREIGN KEY (fk_producto) REFERENCES producto(idproducto))", + "CREATE TABLE detalle_cuenta (fk_cuenta INTEGER, fk_variante INTEGER,cantidad INTEGER, PRIMARY KEY (fk_cuenta, fk_variante), " + + "FOREIGN KEY (fk_cuenta) REFERENCES Cuenta(idCuenta),FOREIGN KEY (fk_variante) REFERENCES variantes(idVariante))", "CREATE TABLE envios (idEnvios INTEGER PRIMARY KEY AUTOINCREMENT, fecha TEXT, direccion TEXT, telefono TEXT,responzable TEXT DEFAULT '',estado TEXT DEFAULT 'EN PROCESO', total DECIMAL(10,2) DEFAULT 0,cliente TEXT)", diff --git a/database/modelos/DetalleCuentaModel.cs b/database/modelos/DetalleCuentaModel.cs index 1039fd4..6512bcc 100644 --- a/database/modelos/DetalleCuentaModel.cs +++ b/database/modelos/DetalleCuentaModel.cs @@ -9,11 +9,11 @@ namespace compabetov2.database.modelos public class DetalleCuentaModel { public int idCuenta; - public Producto producto; + public Variante producto; public int cantidad; public string nombreProducto; - public DetalleCuentaModel(Producto producto, int cantidad, int idCuenta =-1, string nombreProducto = "") + public DetalleCuentaModel(Variante producto, int cantidad, int idCuenta =-1, string nombreProducto = "") { this.idCuenta = idCuenta; this.producto = producto; diff --git a/database/modelos/DetalleVentaModel.cs b/database/modelos/DetalleVentaModel.cs index b180338..52c73cb 100644 --- a/database/modelos/DetalleVentaModel.cs +++ b/database/modelos/DetalleVentaModel.cs @@ -25,5 +25,10 @@ namespace compabetov2.database.modelos { return new DetalleEnvioModel(-1,this.producto,this.cantidad); } + + public DetalleCuentaModel convertirADetalleCuenta() + { + return new DetalleCuentaModel(this.producto, this.cantidad, -1); + } } } diff --git a/database/service.cs b/database/service.cs index 9e1d9e2..7c6beb6 100644 --- a/database/service.cs +++ b/database/service.cs @@ -262,10 +262,10 @@ namespace compabetov2.database while (reader.Read()) { - int idProducto = (int)reader.GetInt64(0); + int idVariaante = (int)reader.GetInt64(0); DetalleCuentaModel detalleCuenta = new DetalleCuentaModel( - new Producto(idProducto, reader["nombre"].ToString()), - (int)reader.GetInt64(2) + new Variante(idVariaante, reader["nombre"].ToString(),0,(int)reader.GetInt64(2),"",(int)reader.GetInt64(3)), + (int)reader.GetInt64(4) ); detallesCuentas.Add(detalleCuenta); } diff --git a/obj/Debug/compabetov2.exe b/obj/Debug/compabetov2.exe index 293df4a..c954e28 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 da74f7d..2cb6fb5 100644 Binary files a/obj/Debug/compabetov2.pdb and b/obj/Debug/compabetov2.pdb differ