envios a medio terminar
This commit is contained in:
+129
-1
@@ -3,6 +3,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SQLite;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Policy;
|
||||
@@ -1162,6 +1163,126 @@ namespace compabetov2.database
|
||||
}
|
||||
}
|
||||
|
||||
public static Dictionary<string, dynamic> filtrarVentaFechaMes(DateTime fecha)
|
||||
{
|
||||
Dictionary<string, dynamic> estadisticas = new Dictionary<string, dynamic>();
|
||||
SQLiteDataReader reader = DAO.filtrarVentaFechaMesDAO(fecha);
|
||||
string formatoFecha = "dd/MM/yyyy";
|
||||
decimal totalDia = 0;
|
||||
decimal totalMes = 0;
|
||||
List<VentaModel> ventas = new List<VentaModel>();
|
||||
while (reader.Read())
|
||||
{
|
||||
VentaModel venta = new VentaModel(
|
||||
(decimal)reader["total"],
|
||||
(int)reader.GetInt64(0),
|
||||
reader.GetString(1)
|
||||
);
|
||||
string[] cadenasFech = venta.fecha.Split(' ');
|
||||
DateTime.TryParseExact(cadenasFech[0], formatoFecha, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime fechaVenta);
|
||||
if (fecha.Day == fechaVenta.Day)
|
||||
{
|
||||
totalDia += venta.total;
|
||||
}
|
||||
totalMes += venta.total;
|
||||
ventas.Add(venta);
|
||||
}
|
||||
|
||||
estadisticas.Add("ventasDia", totalDia);
|
||||
estadisticas.Add("ventasMes", totalMes);
|
||||
|
||||
return estadisticas;
|
||||
}
|
||||
|
||||
public static bool crearEnvio(Envio envio, List<DetalleEnvioModel> detallesEnvio)
|
||||
{
|
||||
return DAO.crearEnvioDAO(envio, detallesEnvio);
|
||||
}
|
||||
|
||||
public static bool crearEnvioDAO(Envio envio, List<DetalleEnvioModel> detallesEnvio)
|
||||
{
|
||||
var db_conexion = new Conexion();
|
||||
try
|
||||
{
|
||||
using (SQLiteConnection conexion = db_conexion.get_connection())
|
||||
{
|
||||
conexion.Open();
|
||||
|
||||
using (var transaccion = conexion.BeginTransaction())
|
||||
{
|
||||
try
|
||||
{
|
||||
string sqlEnvio = "INSERT INTO envios (fecha, direccion, telefono) VALUES(@fecha,@direccion , @telefono);";
|
||||
string sqlDetalle = "INSERT INTO detalle_envios (fk_envios, fk_producto, cantidad) VALUES(@fk_envios, @fk_producto, @cantidad);";
|
||||
string sqlIdCuenta = "SELECT idEnvios FROM envios ORDER BY idEnvios DESC LIMIT 1";
|
||||
|
||||
SQLiteCommand commandCuenta = new SQLiteCommand(sqlEnvio, conexion);
|
||||
commandCuenta.Parameters.AddWithValue("@fecha", envio.fecha);
|
||||
commandCuenta.Parameters.AddWithValue("@direccion", "");
|
||||
commandCuenta.Parameters.AddWithValue("@telefono", "");
|
||||
commandCuenta.ExecuteNonQuery();
|
||||
|
||||
SQLiteCommand commandConsulta = new SQLiteCommand(sqlIdCuenta, conexion);
|
||||
SQLiteDataReader reader = commandConsulta.ExecuteReader();
|
||||
|
||||
long idEnvio = -1;
|
||||
while (reader.Read())
|
||||
{
|
||||
idEnvio = reader.GetInt64(0);
|
||||
}
|
||||
|
||||
foreach (DetalleEnvioModel detalleEnvio in detallesEnvio)
|
||||
{
|
||||
SQLiteCommand commandDetalle = new SQLiteCommand(sqlDetalle, conexion);
|
||||
commandDetalle.Parameters.AddWithValue("@fk_envios", idEnvio);
|
||||
commandDetalle.Parameters.AddWithValue("@fk_producto", detalleEnvio.producto.idProducto);
|
||||
commandDetalle.Parameters.AddWithValue("@cantidad", detalleEnvio.cantidad);
|
||||
commandDetalle.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 SQLiteDataReader conseguirEnvioDAO()
|
||||
{
|
||||
SQLiteDataReader reader = null;
|
||||
var db_conexion = new Conexion();
|
||||
try
|
||||
{
|
||||
SQLiteConnection conexion = db_conexion.get_connection();
|
||||
|
||||
conexion.Open();
|
||||
|
||||
string sql = "SELECT * FROM envios";
|
||||
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();
|
||||
@@ -1181,6 +1302,8 @@ namespace compabetov2.database
|
||||
"DROP TABLE IF EXISTS venta",
|
||||
"DROP TABLE IF EXISTS detalle_cuenta",
|
||||
"DROP TABLE IF EXISTS cuenta",
|
||||
"DROP TABLE IF EXISTS detalle_envios",
|
||||
"DROP TABLE IF EXISTS envios",
|
||||
|
||||
"CREATE TABLE Login (idlogin INTEGER PRIMARY KEY AUTOINCREMENT, tipo TEXT NOT NULL, usuario TEXT NOT NULL, "+
|
||||
"contra TEXT NOT NULL)",
|
||||
@@ -1212,9 +1335,14 @@ namespace compabetov2.database
|
||||
"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 envios (idEnvios INTEGER PRIMARY KEY AUTOINCREMENT, fecha TEXT, direccion TEXT, telefono TEXT,responzable TEXT DEFAULT '',estado TEXT DEFAULT 'EN PROCESO')",
|
||||
|
||||
"CREATE TABLE detalle_envios (fk_envios INTEGER, fk_producto INTEGER,cantidad INTEGER, PRIMARY KEY (fk_envios, fk_producto), " +
|
||||
"FOREIGN KEY (fk_envios) REFERENCES envios(idEnvios),FOREIGN KEY (fk_producto) REFERENCES producto(idproducto))",
|
||||
|
||||
"INSERT INTO Login ( tipo, usuario, contra) VALUES('admin', 'admin', '12345');",
|
||||
"INSERT INTO Empleado ( nombre, apellidos, calle, fecha_contratacion,estado, colonia, cp, no_ext,no_int, referencia, fecha_nac, telefono,fk_idLogin) VALUES('jefe', '', '', '', '', '', '', '', '', '', '', '',1);",
|
||||
|
||||
|
||||
};
|
||||
|
||||
foreach (string consulta in consultas)
|
||||
|
||||
Reference in New Issue
Block a user