bugs con el stock
This commit is contained in:
+36
-2
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SQLite;
|
||||
using System.Diagnostics.Contracts;
|
||||
@@ -534,9 +535,22 @@ namespace compabetov2.database
|
||||
foreach (var item in stockNuevo)
|
||||
{
|
||||
string sql = "UPDATE Producto SET stock = @stock WHERE idproducto = @idproducto;";
|
||||
string sqlProductoStock = "SELECT stock FROM Producto WHERE idproducto = @idproducto";
|
||||
|
||||
SQLiteCommand commandProdcutoStock = new SQLiteCommand(sqlProductoStock, conexion);
|
||||
commandProdcutoStock.Parameters.AddWithValue("@idproducto", item.idProducto);
|
||||
SQLiteDataReader stockReader = commandProdcutoStock.ExecuteReader();
|
||||
|
||||
int stockActual = -1;
|
||||
while (stockReader.Read())
|
||||
{
|
||||
stockActual = int.Parse(stockReader["stock"].ToString());
|
||||
|
||||
}
|
||||
|
||||
SQLiteCommand command = new SQLiteCommand(sql, conexion);
|
||||
command.Parameters.AddWithValue("@idproducto", item.idProducto);
|
||||
command.Parameters.AddWithValue("@stock", item.stock);
|
||||
command.Parameters.AddWithValue("@stock", stockActual + item.stock);
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
@@ -767,6 +781,8 @@ namespace compabetov2.database
|
||||
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 sqlIdVenta = "SELECT idVenta FROM venta ORDER BY idVenta DESC LIMIT 1";
|
||||
string sqlProductoStock = "SELECT stock FROM Producto WHERE idproducto = @idproducto";
|
||||
string sqlProductoUpdate = "UPDATE Producto SET stock = @stock WHERE idproducto = @idproducto";
|
||||
|
||||
|
||||
SQLiteCommand commandVenta = new SQLiteCommand(sqlVenta, conexion);
|
||||
@@ -790,7 +806,25 @@ namespace compabetov2.database
|
||||
commandEmpleado.Parameters.AddWithValue("@idProducto", detalleVenta.producto.idProducto);
|
||||
commandEmpleado.Parameters.AddWithValue("@cantidada", detalleVenta.cantidad);
|
||||
commandEmpleado.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
SQLiteCommand commandProdcutoStock = new SQLiteCommand(sqlProductoStock, conexion);
|
||||
commandProdcutoStock.Parameters.AddWithValue("@idproducto", detalleVenta.producto.idProducto);
|
||||
SQLiteDataReader stockReader = commandProdcutoStock.ExecuteReader();
|
||||
|
||||
int stockActual = -1;
|
||||
while (stockReader.Read())
|
||||
{
|
||||
stockActual = int.Parse(stockReader["stock"].ToString());
|
||||
|
||||
}
|
||||
|
||||
SQLiteCommand commandProdcutoUpdate = new SQLiteCommand(sqlProductoUpdate, conexion);
|
||||
commandProdcutoUpdate.Parameters.AddWithValue("@stock", stockActual - detalleVenta.cantidad);
|
||||
commandProdcutoUpdate.Parameters.AddWithValue("@idproducto", detalleVenta.producto.idProducto);
|
||||
commandProdcutoUpdate.ExecuteNonQuery();
|
||||
|
||||
|
||||
}
|
||||
|
||||
transaccion.Commit();
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user