envio terminado
This commit is contained in:
+149
-1
@@ -1212,7 +1212,7 @@ namespace compabetov2.database
|
||||
{
|
||||
try
|
||||
{
|
||||
string sqlEnvio = "INSERT INTO envios (fecha, direccion, telefono,total) VALUES(@fecha,@direccion , @telefono,@total);";
|
||||
string sqlEnvio = "INSERT INTO envios (fecha, direccion, telefono,responzable,total) VALUES(@fecha,@direccion , @telefono, @responzable, @total);";
|
||||
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";
|
||||
|
||||
@@ -1220,6 +1220,7 @@ namespace compabetov2.database
|
||||
commandCuenta.Parameters.AddWithValue("@fecha", envio.fecha);
|
||||
commandCuenta.Parameters.AddWithValue("@direccion", "");
|
||||
commandCuenta.Parameters.AddWithValue("@telefono", "");
|
||||
commandCuenta.Parameters.AddWithValue("@responzable", envio.responsable);
|
||||
commandCuenta.Parameters.AddWithValue("@total", envio.total);
|
||||
commandCuenta.ExecuteNonQuery();
|
||||
|
||||
@@ -1309,6 +1310,153 @@ namespace compabetov2.database
|
||||
}
|
||||
}
|
||||
|
||||
public static bool editarEnvioDAO(Envio envio)
|
||||
{
|
||||
var db_conexion = new Conexion();
|
||||
try
|
||||
{
|
||||
using (SQLiteConnection conexion = db_conexion.get_connection())
|
||||
{
|
||||
conexion.Open();
|
||||
|
||||
using (var transaccion = conexion.BeginTransaction())
|
||||
{
|
||||
try
|
||||
{
|
||||
string sqlCuenta = "UPDATE envios SET direccion = @direccion, telefono = @telefono, cliente = @cliente WHERE idEnvios = @idEnvios;";
|
||||
|
||||
SQLiteCommand command = new SQLiteCommand(sqlCuenta, conexion);
|
||||
command.Parameters.AddWithValue("@idEnvios", envio.id);
|
||||
command.Parameters.AddWithValue("@direccion", envio.direccion);
|
||||
command.Parameters.AddWithValue("@telefono", envio.telefono);
|
||||
command.Parameters.AddWithValue("@cliente", envio.cliente);
|
||||
command.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 cancelarEnvioDAO(int idEnvio)
|
||||
{
|
||||
var db_conexion = new Conexion();
|
||||
try
|
||||
{
|
||||
using (SQLiteConnection conexion = db_conexion.get_connection())
|
||||
{
|
||||
conexion.Open();
|
||||
|
||||
using (var transaccion = conexion.BeginTransaction())
|
||||
{
|
||||
try
|
||||
{
|
||||
string sqlCuenta = "UPDATE envios SET estado = @estado WHERE idEnvios = @idEnvios;";
|
||||
|
||||
SQLiteCommand command = new SQLiteCommand(sqlCuenta, conexion);
|
||||
command.Parameters.AddWithValue("@idEnvios", idEnvio);
|
||||
command.Parameters.AddWithValue("@estado", "CANCELADO");
|
||||
|
||||
command.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)
|
||||
{
|
||||
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 sqlEnvio = "UPDATE envios SET estado ='CONCLUIDO' WHERE idEnvios = @idEnvios;";
|
||||
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", envio.total);
|
||||
commandVenta.ExecuteNonQuery();
|
||||
|
||||
SQLiteCommand commandEnvio = new SQLiteCommand(sqlEnvio, conexion);
|
||||
commandEnvio.Parameters.AddWithValue("@idEnvios", envio.id);
|
||||
commandEnvio.ExecuteNonQuery();
|
||||
|
||||
SQLiteCommand commandConsulta = new SQLiteCommand(sqlIdVenta, conexion);
|
||||
SQLiteDataReader reader = commandConsulta.ExecuteReader();
|
||||
|
||||
long idVenta = -1;
|
||||
while (reader.Read())
|
||||
{
|
||||
idVenta = reader.GetInt64(0);
|
||||
}
|
||||
foreach (DetalleEnvioModel detalleEnvio in detallesEnvio)
|
||||
{
|
||||
SQLiteCommand commandEmpleado = new SQLiteCommand(sqlDetalle, conexion);
|
||||
commandEmpleado.Parameters.AddWithValue("@idVenta", idVenta);
|
||||
commandEmpleado.Parameters.AddWithValue("@idProducto", detalleEnvio.producto.idProducto);
|
||||
commandEmpleado.Parameters.AddWithValue("@cantidada", detalleEnvio.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()
|
||||
{
|
||||
var db_conexion = new Conexion();
|
||||
|
||||
Reference in New Issue
Block a user