estadisticas terminadas con detalle del mejor vendedor

This commit is contained in:
Carlos Sandoval
2024-06-30 03:09:38 -06:00
parent d81f706053
commit 8e6571fbc9
15 changed files with 469 additions and 311 deletions
+51 -3
View File
@@ -872,8 +872,9 @@ namespace compabetov2.database
}
}
public static bool devolverImporteDAO(List<DetalleImporte> importes)
public static bool devolverImporteDAO(VentaModel venta, List<DetalleImporte> importes)
{
var db_conexion = new Conexion();
try
{
@@ -885,7 +886,28 @@ namespace compabetov2.database
{
try
{
string sqlImporte = "INSERT INTO detalle_importe (fk_importe,cantidad,precio,fecha) VALUES (@fk_importe,@cantidad,@precio,@fecha)";
string sqlVenta = "INSERT INTO venta (fecha, total,responzable) VALUES(@fecha, @total,@responzable);";
string sqlIdVenta = "SELECT idVenta FROM venta ORDER BY idVenta DESC LIMIT 1";
string sqlImporte = "INSERT INTO detalle_importe (fk_importe,cantidad,precio,fk_venta) VALUES (@fk_importe,@cantidad,@precio,@fk_venta)";
// 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();
long idVenta = -1;
while (reader.Read())
{
idVenta = reader.GetInt64(0);
}
//creacion del importe
foreach (DetalleImporte importe in importes)
{
@@ -895,7 +917,7 @@ namespace compabetov2.database
commandDetalleImporte.Parameters.AddWithValue("@fk_importe", importe.fkImporte);
commandDetalleImporte.Parameters.AddWithValue("@cantidad", importe.cantidad);
commandDetalleImporte.Parameters.AddWithValue("@precio", importe.precioImporte);
commandDetalleImporte.Parameters.AddWithValue("@fecha", DateTime.Now.ToString());
commandDetalleImporte.Parameters.AddWithValue("@fk_venta", idVenta);
commandDetalleImporte.ExecuteNonQuery();
}
}
@@ -1917,6 +1939,32 @@ namespace compabetov2.database
}
}
public static SQLiteDataReader conseguirImportesVentaDAO(VentaModel venta)
{
SQLiteDataReader reader = null;
var db_conexion = new Conexion();
try
{
SQLiteConnection conexion = db_conexion.get_connection();
conexion.Open();
string sql = "SELECT * FROM detalle_importe WHERE fk_venta = @fk_venta;";
SQLiteCommand command = new SQLiteCommand(sql, conexion);
command.Parameters.AddWithValue("@fk_venta", venta.id);
reader = command.ExecuteReader();
return reader;
}
catch (SQLiteException ex)
{
MessageBox.Show(ex.Message);
return reader;
}
}
private static void crearDB()
{
var db_conexion = new Conexion();