version 1.1

This commit is contained in:
carlos
2024-02-15 00:01:19 -06:00
parent 736d8be03c
commit ea999a41e8
11 changed files with 162 additions and 138 deletions
+99 -79
View File
@@ -22,8 +22,9 @@ namespace compabetov2.database
var db_conexion = new Conexion();
try
{
using (SQLiteConnection conexion = db_conexion.get_connection()) {
using (SQLiteConnection conexion = db_conexion.get_connection())
{
conexion.Open();
string sql = "SELECT usuario, contra FROM Login WHERE usuario = @param0";
@@ -61,7 +62,7 @@ namespace compabetov2.database
}
}
catch (SQLiteException ex)
{
if (ex.Message.Contains("no such table"))
@@ -86,16 +87,16 @@ namespace compabetov2.database
try
{
SQLiteConnection conexion = db_conexion.get_connection();
conexion.Open();
string sql = "SELECT usuario, tipo FROM Login WHERE usuario = @param0";
SQLiteCommand command = new SQLiteCommand(sql, conexion);
command.Parameters.AddWithValue($"@param{0}", usuario);
reader = command.ExecuteReader();
conexion.Open();
string sql = "SELECT usuario, tipo FROM Login WHERE usuario = @param0";
SQLiteCommand command = new SQLiteCommand(sql, conexion);
command.Parameters.AddWithValue($"@param{0}", usuario);
reader = command.ExecuteReader();
return reader;
return reader;
}
catch (SQLiteException ex)
{
@@ -119,7 +120,7 @@ namespace compabetov2.database
command.Parameters.AddWithValue("@usuario", loginModel.usuario);
reader = command.ExecuteReader();
if(reader.Read())
if (reader.Read())
{
return false;
}
@@ -162,11 +163,11 @@ namespace compabetov2.database
SQLiteDataReader reader = commandConsulta.ExecuteReader();
long fkLogin = -1;
while(reader.Read())
while (reader.Read())
{
fkLogin = reader.GetInt64(0);
}
SQLiteCommand commandEmpleado = new SQLiteCommand(sqlEmpleado, conexion);
commandEmpleado.Parameters.AddWithValue("@fklogin", fkLogin);
@@ -299,7 +300,7 @@ namespace compabetov2.database
command.Parameters.AddWithValue("@telefono", empleado.telefono);
command.Parameters.AddWithValue("@img", empleado.img);
command.Parameters.AddWithValue("@fk_idLogin", empleado.fkIdLogin);
int filasAfectadas = command.ExecuteNonQuery();
if (filasAfectadas > 0) { return true; }
@@ -321,15 +322,15 @@ namespace compabetov2.database
try
{
SQLiteConnection conexion = db_conexion.get_connection();
conexion.Open();
string sql = "SELECT * FROM Empleado WHERE idempleado > 1";
SQLiteCommand command = new SQLiteCommand(sql, conexion);
reader = command.ExecuteReader();
conexion.Open();
string sql = "SELECT * FROM Empleado WHERE idempleado > 1";
SQLiteCommand command = new SQLiteCommand(sql, conexion);
reader = command.ExecuteReader();
return reader;
return reader;
}
catch (SQLiteException ex)
{
@@ -381,7 +382,8 @@ namespace compabetov2.database
}
}
public static bool eliminarEmpleadoDAO(Empleado empleado) {
public static bool eliminarEmpleadoDAO(Empleado empleado)
{
var db_conexion = new Conexion();
try
@@ -399,7 +401,7 @@ namespace compabetov2.database
SQLiteCommand command = new SQLiteCommand(sql, conexion);
command.Parameters.AddWithValue("@idempleado", empleado.idempleado);
SQLiteCommand commandLogin = new SQLiteCommand(sqlLogin, conexion);
commandLogin.Parameters.AddWithValue("@idlogin", empleado.fkIdLogin);
@@ -408,7 +410,7 @@ namespace compabetov2.database
commandLogin.ExecuteNonQuery();
transaccion.Commit();
return true;
}
catch (SQLiteException ex)
{
@@ -435,16 +437,17 @@ namespace compabetov2.database
try
{
SQLiteConnection conexion = db_conexion.get_connection();
conexion.Open();
string sql = "SELECT * FROM Producto INNER JOIN Categoria ON Producto.fk_idcategoria = Categoria.idcategoria";
SQLiteCommand command = new SQLiteCommand(sql, conexion);
reader = command.ExecuteReader();
conexion.Open();
return reader;
string sql = "SELECT * FROM Producto INNER JOIN Categoria ON Producto.fk_idcategoria = Categoria.idcategoria";
SQLiteCommand command = new SQLiteCommand(sql, conexion);
reader = command.ExecuteReader();
return reader;
}
catch (SQLiteException ex) {
catch (SQLiteException ex)
{
MessageBox.Show(ex.Message);
return reader;
}
@@ -459,28 +462,28 @@ namespace compabetov2.database
{
conexion.Open();
string sql = "INSERT INTO Producto (nombre, descripcion, precio,img, stock, fk_idcategoria) "+
string sql = "INSERT INTO Producto (nombre, descripcion, precio,img, stock, fk_idcategoria) " +
"VALUES (@nombre, @descripcion, @precio,@img , @stock, @idcategoria)";
if (!producto.img.Equals(""))
{
producto.img = guardarImg(producto.img);
}
using (SQLiteCommand command = new SQLiteCommand(sql, conexion))
{
command.Parameters.AddWithValue("@nombre", producto.nombre);
command.Parameters.AddWithValue("@nombre", producto.nombre);
command.Parameters.AddWithValue("@descripcion", producto.descripcion);
command.Parameters.AddWithValue("@precio", producto.precion);
command.Parameters.AddWithValue("@img", producto.img);
command.Parameters.AddWithValue("@stock", producto.stock);
command.Parameters.AddWithValue("@idcategoria", producto.categoria.idCategoria);
int filasAfectadas = command.ExecuteNonQuery();
if(filasAfectadas > 0) { return true; }
if (filasAfectadas > 0) { return true; }
else { return false; }
}
}
}
}
catch (SQLiteException ex)
@@ -527,10 +530,10 @@ namespace compabetov2.database
{
conexion.Open();
using(var transaccion = conexion.BeginTransaction())
using (var transaccion = conexion.BeginTransaction())
{
try
{
{
foreach (var item in stockNuevo)
{
string sql = "UPDATE Producto SET stock = @stock WHERE idproducto = @idproducto;";
@@ -556,7 +559,7 @@ namespace compabetov2.database
transaccion.Commit();
return true;
}
catch(SQLiteException ex)
catch (SQLiteException ex)
{
transaccion.Rollback();
MessageBox.Show(ex.Message);
@@ -717,15 +720,15 @@ namespace compabetov2.database
try
{
SQLiteConnection conexion = db_conexion.get_connection();
conexion.Open();
string sql = "SELECT * FROM Merma";
SQLiteCommand command = new SQLiteCommand(sql, conexion);
reader = command.ExecuteReader();
conexion.Open();
string sql = "SELECT * FROM Merma";
SQLiteCommand command = new SQLiteCommand(sql, conexion);
reader = command.ExecuteReader();
return reader;
return reader;
}
catch (SQLiteException ex)
{
@@ -1213,37 +1216,6 @@ namespace compabetov2.database
}
}
/*public static SQLiteDataReader 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);
@@ -1459,6 +1431,54 @@ namespace compabetov2.database
return false;
}
}
public static bool llenarTablaVariantes()
{
List<Producto> productos = service.conseguirProductos();
var db_conexion = new Conexion();
try
{
using (SQLiteConnection conexion = db_conexion.get_connection())
{
conexion.Open();
using (var transaccion = conexion.BeginTransaction())
{
try
{
string sql = "INSERT INTO variantes(idVariante, nombre, precio, cantidad, img, fk_producto)" +
"VALUES(@idVariante, @nombre, @precio, @cantidad, @img, @fk_producto);";
for(int i = 0; i<productos.Count; i++)
{
SQLiteCommand commandStock = new SQLiteCommand(sql, conexion);
commandStock.Parameters.AddWithValue("@idVariante", i+1);
commandStock.Parameters.AddWithValue("@nombre", productos[i].nombre);
commandStock.Parameters.AddWithValue("@precio", productos[i].precion);
commandStock.Parameters.AddWithValue("@cantidad", 1);
commandStock.Parameters.AddWithValue("@img", productos[i].img);
commandStock.Parameters.AddWithValue("@fk_producto", productos[i].idProducto);
commandStock.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 concluirEnvioDAO(Envio envio, List<DetalleEnvioModel> detallesEnvio)
{