importe en venta hecho
This commit is contained in:
+93
-33
@@ -575,35 +575,6 @@ namespace compabetov2.database
|
||||
}
|
||||
}
|
||||
|
||||
public static bool insertarCategoriaDAO(Categoria categoria)
|
||||
{
|
||||
var db_conexion = new Conexion();
|
||||
try
|
||||
{
|
||||
using (SQLiteConnection conexion = db_conexion.get_connection())
|
||||
{
|
||||
conexion.Open();
|
||||
|
||||
string sql = "INSERT INTO Categoria (nombre, descripcion) " +
|
||||
"VALUES (@nombre, @descripcion)";
|
||||
|
||||
using (SQLiteCommand command = new SQLiteCommand(sql, conexion))
|
||||
{
|
||||
command.Parameters.AddWithValue("@nombre", categoria.nombre);
|
||||
command.Parameters.AddWithValue("@descripcion", categoria.descripcion);
|
||||
int filasAfectadas = command.ExecuteNonQuery();
|
||||
|
||||
if (filasAfectadas > 0) { return true; }
|
||||
else { return false; }
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLiteException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool insertarClienteDAO(Cliente cliente)
|
||||
{
|
||||
@@ -767,7 +738,7 @@ namespace compabetov2.database
|
||||
}
|
||||
}
|
||||
|
||||
public static bool crearVentaDAO(VentaModel venta, List<DetalleVentaModel> detalleVentas)
|
||||
public static bool crearVentaDAO(VentaModel venta, List<DetalleVentaModel> detalleVentas, List<DetalleImporte> importes)
|
||||
{
|
||||
var db_conexion = new Conexion();
|
||||
try
|
||||
@@ -785,14 +756,16 @@ namespace compabetov2.database
|
||||
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";
|
||||
string sqlImporte = "INSERT INTO detalle_importe (fk_importe,cantidad,precio,fecha) VALUES (@fk_importe,@cantidad,@precio,@fecha)";
|
||||
|
||||
|
||||
// CREACION DE LA VENTA
|
||||
SQLiteCommand commandVenta = new SQLiteCommand(sqlVenta, conexion);
|
||||
commandVenta.Parameters.AddWithValue("@fecha", DateTime.Now.ToString());
|
||||
commandVenta.Parameters.AddWithValue("@total", venta.total);
|
||||
commandVenta.Parameters.AddWithValue("@responzable", venta.responzable);
|
||||
commandVenta.ExecuteNonQuery();
|
||||
|
||||
//CONSEGUIR EL ID DE LA VENTA PARA RELACIONARLO CON DETALLE VENTA
|
||||
SQLiteCommand commandConsulta = new SQLiteCommand(sqlIdVenta, conexion);
|
||||
SQLiteDataReader reader = commandConsulta.ExecuteReader();
|
||||
|
||||
@@ -802,6 +775,7 @@ namespace compabetov2.database
|
||||
idVenta = reader.GetInt64(0);
|
||||
}
|
||||
|
||||
// CREACION DE DETALLE VENTA
|
||||
foreach (DetalleVentaModel detalleVenta in detalleVentas)
|
||||
{
|
||||
SQLiteCommand commandEmpleado = new SQLiteCommand(sqlDetalle, conexion);
|
||||
@@ -821,10 +795,74 @@ namespace compabetov2.database
|
||||
|
||||
}
|
||||
|
||||
//ACTUALIZACION DE STOCK
|
||||
SQLiteCommand commandProdcutoUpdate = new SQLiteCommand(sqlProductoUpdate, conexion);
|
||||
commandProdcutoUpdate.Parameters.AddWithValue("@stock", stockActual - (detalleVenta.cantidad * detalleVenta.producto.cantidad));
|
||||
commandProdcutoUpdate.Parameters.AddWithValue("@idproducto", detalleVenta.producto.fkProducto);
|
||||
commandProdcutoUpdate.ExecuteNonQuery();
|
||||
|
||||
|
||||
|
||||
}
|
||||
//creacion del importe
|
||||
foreach (DetalleImporte importe in importes)
|
||||
{
|
||||
if (importe.catidad != 0)
|
||||
{
|
||||
SQLiteCommand commandDetalleImporte = new SQLiteCommand(sqlImporte, conexion);
|
||||
commandDetalleImporte.Parameters.AddWithValue("@fk_importe", importe.fkImporte);
|
||||
commandDetalleImporte.Parameters.AddWithValue("@cantidad", importe.catidad);
|
||||
commandDetalleImporte.Parameters.AddWithValue("@precio", importe.precioImporte);
|
||||
commandDetalleImporte.Parameters.AddWithValue("@fecha", DateTime.Now.ToString());
|
||||
commandDetalleImporte.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
transaccion.Commit();
|
||||
return true;
|
||||
}
|
||||
catch (SQLiteException ex)
|
||||
{
|
||||
transaccion.Rollback();
|
||||
MessageBox.Show(ex.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLiteException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool devolverImporteDAO(List<DetalleImporte> importes)
|
||||
{
|
||||
var db_conexion = new Conexion();
|
||||
try
|
||||
{
|
||||
using (SQLiteConnection conexion = db_conexion.get_connection())
|
||||
{
|
||||
conexion.Open();
|
||||
|
||||
using (var transaccion = conexion.BeginTransaction())
|
||||
{
|
||||
try
|
||||
{
|
||||
string sqlImporte = "INSERT INTO detalle_importe (fk_importe,cantidad,precio,fecha) VALUES (@fk_importe,@cantidad,@precio,@fecha)";
|
||||
//creacion del importe
|
||||
foreach (DetalleImporte importe in importes)
|
||||
{
|
||||
if (importe.catidad != 0)
|
||||
{
|
||||
SQLiteCommand commandDetalleImporte = new SQLiteCommand(sqlImporte, conexion);
|
||||
commandDetalleImporte.Parameters.AddWithValue("@fk_importe", importe.fkImporte);
|
||||
commandDetalleImporte.Parameters.AddWithValue("@cantidad", importe.catidad);
|
||||
commandDetalleImporte.Parameters.AddWithValue("@precio", importe.precioImporte);
|
||||
commandDetalleImporte.Parameters.AddWithValue("@fecha", DateTime.Now.ToString());
|
||||
commandDetalleImporte.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
transaccion.Commit();
|
||||
@@ -1389,8 +1427,6 @@ namespace compabetov2.database
|
||||
try
|
||||
{
|
||||
string sqlCuenta = "UPDATE envios SET estado = @estado WHERE idEnvios = @idEnvios;";
|
||||
string sqlStock = "select stock from Producto p where idproducto = @idProducto";
|
||||
string sqlActualizarStock = "UPDATE Producto set stock = @stock WHERE idproducto = @idProducto";
|
||||
|
||||
SQLiteCommand command = new SQLiteCommand(sqlCuenta, conexion);
|
||||
command.Parameters.AddWithValue("@idEnvios", envio.id);
|
||||
@@ -1604,6 +1640,30 @@ namespace compabetov2.database
|
||||
}
|
||||
}
|
||||
|
||||
public static SQLiteDataReader conseguirImportesDAO()
|
||||
{
|
||||
SQLiteDataReader reader = null;
|
||||
var db_conexion = new Conexion();
|
||||
try
|
||||
{
|
||||
SQLiteConnection conexion = db_conexion.get_connection();
|
||||
|
||||
conexion.Open();
|
||||
|
||||
string sql = "SELECT * FROM importe";
|
||||
SQLiteCommand command = new SQLiteCommand(sql, conexion);
|
||||
reader = command.ExecuteReader();
|
||||
|
||||
return reader;
|
||||
|
||||
}
|
||||
catch (SQLiteException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
return reader;
|
||||
}
|
||||
}
|
||||
|
||||
private static void crearDB()
|
||||
{
|
||||
var db_conexion = new Conexion();
|
||||
|
||||
Reference in New Issue
Block a user