cuenta hecha
This commit is contained in:
+124
-2
@@ -915,7 +915,7 @@ namespace compabetov2.database
|
||||
|
||||
conexion.Open();
|
||||
|
||||
string sql = "SELECT * FROM cuenta";
|
||||
string sql = "SELECT * FROM cuenta WHERE estado = 'ACTIVO'";
|
||||
SQLiteCommand command = new SQLiteCommand(sql, conexion);
|
||||
reader = command.ExecuteReader();
|
||||
|
||||
@@ -945,6 +945,8 @@ namespace compabetov2.database
|
||||
string sqlCuenta = "INSERT INTO cuenta (total, fecha, estado, descripcion) VALUES(@total, @fecha, 'ACTIVO', @descripcion);";
|
||||
string sqlDetalle = "INSERT INTO detalle_cuenta (fk_cuenta, fk_producto, cantidad) VALUES(@fk_cuenta, @fk_producto, @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";
|
||||
|
||||
SQLiteCommand commandCuenta = new SQLiteCommand(sqlCuenta, conexion);
|
||||
commandCuenta.Parameters.AddWithValue("@fecha", DateTime.Now.ToString());
|
||||
@@ -968,6 +970,23 @@ namespace compabetov2.database
|
||||
commandDetalle.Parameters.AddWithValue("@fk_producto", detalleCuenta.producto.idProducto);
|
||||
commandDetalle.Parameters.AddWithValue("@cantidad", detalleCuenta.cantidad);
|
||||
commandDetalle.ExecuteNonQuery();
|
||||
|
||||
//modificar stock
|
||||
SQLiteCommand commandProdcutoStock = new SQLiteCommand(sqlProductoStock, conexion);
|
||||
commandProdcutoStock.Parameters.AddWithValue("@idproducto", detalleCuenta.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 - detalleCuenta.cantidad);
|
||||
commandProdcutoUpdate.Parameters.AddWithValue("@idproducto", detalleCuenta.producto.idProducto);
|
||||
commandProdcutoUpdate.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
transaccion.Commit();
|
||||
@@ -999,7 +1018,7 @@ namespace compabetov2.database
|
||||
|
||||
conexion.Open();
|
||||
|
||||
string sql = "Select 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 p.idproducto, p.nombre , dc.cantidad from detalle_cuenta dc, Producto p WHERE dc.fk_producto = p.idproducto and dc.fk_cuenta = @fk_cuenta;";
|
||||
SQLiteCommand command = new SQLiteCommand(sql, conexion);
|
||||
command.Parameters.AddWithValue("@fk_cuenta", idCuenta);
|
||||
reader = command.ExecuteReader();
|
||||
@@ -1014,6 +1033,109 @@ namespace compabetov2.database
|
||||
}
|
||||
}
|
||||
|
||||
public static bool cancelarCuentaDAO(int idCuenta)
|
||||
{
|
||||
var db_conexion = new Conexion();
|
||||
try
|
||||
{
|
||||
using (SQLiteConnection conexion = db_conexion.get_connection())
|
||||
{
|
||||
conexion.Open();
|
||||
|
||||
using (var transaccion = conexion.BeginTransaction())
|
||||
{
|
||||
try
|
||||
{
|
||||
string sqlCuenta = "UPDATE cuenta SET estado ='CANCELADO' WHERE idCuenta = @idCuenta;";
|
||||
|
||||
SQLiteCommand commandCuenta = new SQLiteCommand(sqlCuenta, conexion);
|
||||
commandCuenta.Parameters.AddWithValue("@idCuenta", idCuenta);
|
||||
commandCuenta.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 saldarCuentaDAO(Cuenta cuenta, List<DetalleCuentaModel> detallesCuentas)
|
||||
{
|
||||
var db_conexion = new Conexion();
|
||||
try
|
||||
{
|
||||
using (SQLiteConnection conexion = db_conexion.get_connection())
|
||||
{
|
||||
conexion.Open();
|
||||
|
||||
using (var transaccion = conexion.BeginTransaction())
|
||||
{
|
||||
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 sqlCuenta = "UPDATE cuenta SET estado ='SALDADO' WHERE idCuenta = @idCuenta;";
|
||||
string sqlIdVenta = "SELECT idVenta FROM venta ORDER BY idVenta DESC LIMIT 1";
|
||||
|
||||
|
||||
SQLiteCommand commandVenta = new SQLiteCommand(sqlVenta, conexion);
|
||||
commandVenta.Parameters.AddWithValue("@fecha", DateTime.Now.ToString());
|
||||
commandVenta.Parameters.AddWithValue("@total", cuenta.total);
|
||||
commandVenta.ExecuteNonQuery();
|
||||
|
||||
SQLiteCommand commandCuenta = new SQLiteCommand(sqlCuenta, conexion);
|
||||
commandCuenta.Parameters.AddWithValue("@idCuenta", cuenta.id);
|
||||
|
||||
SQLiteCommand commandConsulta = new SQLiteCommand(sqlIdVenta, conexion);
|
||||
SQLiteDataReader reader = commandConsulta.ExecuteReader();
|
||||
|
||||
long idVenta = -1;
|
||||
while (reader.Read())
|
||||
{
|
||||
idVenta = reader.GetInt64(0);
|
||||
}
|
||||
foreach (DetalleCuentaModel detalleCuenta in detallesCuentas)
|
||||
{
|
||||
MessageBox.Show(detalleCuenta.producto.idProducto.ToString());
|
||||
SQLiteCommand commandEmpleado = new SQLiteCommand(sqlDetalle, conexion);
|
||||
commandEmpleado.Parameters.AddWithValue("@idVenta", idVenta);
|
||||
commandEmpleado.Parameters.AddWithValue("@idProducto", detalleCuenta.producto.idProducto);
|
||||
commandEmpleado.Parameters.AddWithValue("@cantidada", detalleCuenta.cantidad);
|
||||
commandEmpleado.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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void crearDB()
|
||||
{
|
||||
|
||||
+13
-2
@@ -263,14 +263,25 @@ namespace compabetov2.database
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
int idProducto = (int)reader.GetInt64(0);
|
||||
DetalleCuentaModel detalleCuenta = new DetalleCuentaModel(
|
||||
new Producto(0, reader["nombre"].ToString()),
|
||||
(int)reader.GetInt64(1)
|
||||
new Producto(idProducto, reader["nombre"].ToString()),
|
||||
(int)reader.GetInt64(2)
|
||||
);
|
||||
detallesCuentas.Add(detalleCuenta);
|
||||
}
|
||||
|
||||
return detallesCuentas;
|
||||
}
|
||||
|
||||
public static bool cancelarCuenta(int idCuenta)
|
||||
{
|
||||
return DAO.cancelarCuentaDAO(idCuenta);
|
||||
}
|
||||
|
||||
public static bool saldarCuenta(Cuenta cuenta, List<DetalleCuentaModel> detallesCuentas)
|
||||
{
|
||||
return DAO.saldarCuentaDAO(cuenta, detallesCuentas);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user