envio terminado

This commit is contained in:
carlos
2024-01-23 20:00:50 -06:00
parent 2b2624fb41
commit f516c3d45a
10 changed files with 395 additions and 133 deletions
+229 -131
View File
@@ -29,145 +29,243 @@ namespace compabetov2
List<Envio> envios = service.conseguirEnvio(); List<Envio> envios = service.conseguirEnvio();
foreach(Envio envio in envios) foreach(Envio envio in envios)
{ {
TableLayoutPanel carta = new TableLayoutPanel(); if (envio.estado.Equals("EN PROCESO"))
carta.ColumnCount = 1;
carta.RowCount = 2;
carta.RowStyles.Add(new RowStyle(SizeType.Percent, 75F));
carta.RowStyles.Add(new RowStyle(SizeType.Percent, 25F));
carta.Width = 700;
carta.Height = 170;
FlowLayoutPanel infoPanel = new FlowLayoutPanel();
infoPanel.FlowDirection = FlowDirection.TopDown;
infoPanel.Dock = DockStyle.Fill;
Label lbFecha = new Label();
lbFecha.Text = $"Fecha: {envio.fecha}";
lbFecha.Font = new Font(lbFecha.Font.FontFamily, 12);
lbFecha.Width = 700;
Label lbDireaccion = new Label();
lbDireaccion.Text = $"Direccion: {envio.direccion}";
lbDireaccion.Font = new Font(lbDireaccion.Font.FontFamily, 12);
lbDireaccion.Width = 700;
Label lbTelefono = new Label();
lbTelefono.Text = $"Telefono: {envio.telefono}";
lbTelefono.Font = new Font(lbTelefono.Font.FontFamily, 12);
lbTelefono.Width = 700;
Label lbCliente = new Label();
lbCliente.Text = $"Cliente: {envio.cliente}";
lbCliente.Font = new Font(lbCliente.Font.FontFamily, 12);
lbCliente.Width = 700;
Label lbResponzable = new Label();
lbResponzable.Text = $"Responzable: {envio.responsable}";
lbResponzable.Font = new Font(lbResponzable.Font.FontFamily, 12);
lbResponzable.Width = 700;
TableLayoutPanel botonesPanel = new TableLayoutPanel();
botonesPanel.RowCount = 1;
botonesPanel.ColumnCount = 4;
botonesPanel.Dock = DockStyle.Fill;
botonesPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F));
botonesPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F));
botonesPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F));
botonesPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F));
botonesPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
Button btnDetalles = new Button();
btnDetalles.Text = "Detalles";
btnDetalles.Dock = DockStyle.Fill;
btnDetalles.FlatStyle = FlatStyle.Flat;
btnDetalles.FlatAppearance.BorderSize = 0;
btnDetalles.BackColor = Color.FromArgb(33, 90, 255);
btnDetalles.Font = new Font(btnDetalles.Font.FontFamily, 16);
btnDetalles.ForeColor = Color.White;
btnDetalles.Click += new EventHandler(delegate (object sender, EventArgs e)
{ {
List<DetalleEnvioModel> detalles = service.conseguirDetalleEnvio(envio.id); TableLayoutPanel carta = new TableLayoutPanel();
string mensaje = ""; carta.ColumnCount = 1;
foreach (DetalleEnvioModel detalle in detalles) carta.RowCount = 2;
{ carta.RowStyles.Add(new RowStyle(SizeType.Percent, 75F));
mensaje += $"{detalle.producto.nombre} - {detalle.cantidad}\n"; carta.RowStyles.Add(new RowStyle(SizeType.Percent, 25F));
} carta.Width = 700;
MessageBox.Show(mensaje); carta.Height = 170;
});
Button btnConcluir = new Button(); FlowLayoutPanel infoPanel = new FlowLayoutPanel();
btnConcluir.Text = "Concluir"; infoPanel.FlowDirection = FlowDirection.TopDown;
btnConcluir.Dock = DockStyle.Fill; infoPanel.Dock = DockStyle.Fill;
btnConcluir.FlatStyle = FlatStyle.Flat;
btnConcluir.FlatAppearance.BorderSize = 0; Label lbFecha = new Label();
btnConcluir.BackColor = Color.FromArgb(33, 90, 255); lbFecha.Text = $"Fecha: {envio.fecha}";
btnConcluir.Font = new Font(btnDetalles.Font.FontFamily, 16); lbFecha.Font = new Font(lbFecha.Font.FontFamily, 12);
btnConcluir.ForeColor = Color.White; lbFecha.Width = 700;
btnConcluir.Click += new EventHandler(delegate (object sender, EventArgs e)
Label lbDireaccion = new Label();
lbDireaccion.Text = $"Direccion: {envio.direccion}";
lbDireaccion.Font = new Font(lbDireaccion.Font.FontFamily, 12);
lbDireaccion.Width = 700;
Label lbTelefono = new Label();
lbTelefono.Text = $"Telefono: {envio.telefono} Estado: {envio.estado}";
lbTelefono.Font = new Font(lbTelefono.Font.FontFamily, 12);
lbTelefono.Width = 700;
Label lbCliente = new Label();
lbCliente.Text = $"Cliente: {envio.cliente}";
lbCliente.Font = new Font(lbCliente.Font.FontFamily, 12);
lbCliente.Width = 700;
Label lbResponzable = new Label();
lbResponzable.Text = $"Responzable: {envio.responsable}";
lbResponzable.Font = new Font(lbResponzable.Font.FontFamily, 12);
lbResponzable.Width = 700;
TableLayoutPanel botonesPanel = new TableLayoutPanel();
botonesPanel.RowCount = 1;
botonesPanel.ColumnCount = 4;
botonesPanel.Dock = DockStyle.Fill;
botonesPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F));
botonesPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F));
botonesPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F));
botonesPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F));
botonesPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
Button btnDetalles = new Button();
btnDetalles.Text = "Detalles";
btnDetalles.Dock = DockStyle.Fill;
btnDetalles.FlatStyle = FlatStyle.Flat;
btnDetalles.FlatAppearance.BorderSize = 0;
btnDetalles.BackColor = Color.FromArgb(33, 90, 255);
btnDetalles.Font = new Font(btnDetalles.Font.FontFamily, 16);
btnDetalles.ForeColor = Color.White;
btnDetalles.Click += new EventHandler(delegate (object sender, EventArgs e)
{
List<DetalleEnvioModel> detalles = service.conseguirDetalleEnvio(envio.id);
string mensaje = "";
foreach (DetalleEnvioModel detalle in detalles)
{
mensaje += $"{detalle.producto.nombre} - {detalle.cantidad}\n";
}
mensaje += $"Total: {envio.total}";
MessageBox.Show(mensaje);
});
Button btnConcluir = new Button();
btnConcluir.Text = "Concluir";
btnConcluir.Dock = DockStyle.Fill;
btnConcluir.FlatStyle = FlatStyle.Flat;
btnConcluir.FlatAppearance.BorderSize = 0;
btnConcluir.BackColor = Color.FromArgb(33, 90, 255);
btnConcluir.Font = new Font(btnDetalles.Font.FontFamily, 16);
btnConcluir.ForeColor = Color.White;
btnConcluir.Click += new EventHandler(delegate (object sender, EventArgs e)
{
DialogResult result = MessageBox.Show($"¿Está seguro de que desea concluir este envio?",
"Confirmación", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
List<DetalleEnvioModel> detalles = service.conseguirDetalleEnvio(envio.id);
if (service.concluirEnvio(envio, detalles))
{
llenarPanel();
}
}
});
Button btnCancelar = new Button();
btnCancelar.Text = "Cancelar";
btnCancelar.Dock = DockStyle.Fill;
btnCancelar.FlatStyle = FlatStyle.Flat;
btnCancelar.FlatAppearance.BorderSize = 0;
btnCancelar.BackColor = Color.Red;
btnCancelar.Font = new Font(btnDetalles.Font.FontFamily, 16);
btnCancelar.Click += new EventHandler(delegate (object sender, EventArgs e)
{
DialogResult result = MessageBox.Show($"¿Está seguro de que desea eliminar este envio?",
"Confirmación", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
if (service.cancelarEnvio(envio.id))
{
llenarPanel();
}
}
});
Button btnAgregar = new Button();
btnAgregar.Text = "Agregar";
btnAgregar.Dock = DockStyle.Fill;
btnAgregar.FlatStyle = FlatStyle.Flat;
btnAgregar.FlatAppearance.BorderSize = 0;
btnAgregar.BackColor = Color.FromArgb(33, 90, 255);
btnAgregar.Font = new Font(btnDetalles.Font.FontFamily, 16);
btnAgregar.ForeColor = Color.White;
btnAgregar.Click += new EventHandler(delegate (object sender, EventArgs e)
{
Envio envioEditado = new Envio(envio.id, "",
txtDireccion.Text == "" ? envio.direccion : txtDireccion.Text,
txtTelefono.Text == "" ? envio.telefono : txtTelefono.Text
, "", "",
txtCliente.Text == "" ? envio.cliente : txtCliente.Text
, 0);
if (service.editarEnvio(envioEditado))
{
llenarPanel();
txtCliente.Text = "";
txtDireccion.Text = "";
txtTelefono.Text = "";
}
});
infoPanel.Controls.Add(lbFecha);
infoPanel.Controls.Add(lbResponzable);
infoPanel.Controls.Add(lbCliente);
infoPanel.Controls.Add(lbDireaccion);
infoPanel.Controls.Add(lbTelefono);
botonesPanel.Controls.Add(btnDetalles, 0, 0);
botonesPanel.Controls.Add(btnConcluir, 1, 0);
botonesPanel.Controls.Add(btnAgregar, 2, 0);
botonesPanel.Controls.Add(btnCancelar, 3, 0);
carta.Controls.Add(infoPanel, 0, 0);
carta.Controls.Add(botonesPanel, 0, 1);
panelEnvio.Controls.Add(carta);
}
else
{ {
List<DetalleEnvioModel> detalles = service.conseguirDetalleEnvio(envio.id); TableLayoutPanel carta = new TableLayoutPanel();
string mensaje = ""; carta.ColumnCount = 1;
foreach (DetalleEnvioModel detalle in detalles) carta.RowCount = 2;
carta.RowStyles.Add(new RowStyle(SizeType.Percent, 75F));
carta.RowStyles.Add(new RowStyle(SizeType.Percent, 25F));
carta.Width = 700;
carta.Height = 170;
FlowLayoutPanel infoPanel = new FlowLayoutPanel();
infoPanel.FlowDirection = FlowDirection.TopDown;
infoPanel.Dock = DockStyle.Fill;
Label lbFecha = new Label();
lbFecha.Text = $"Fecha: {envio.fecha}";
lbFecha.Font = new Font(lbFecha.Font.FontFamily, 12);
lbFecha.Width = 700;
Label lbDireaccion = new Label();
lbDireaccion.Text = $"Direccion: {envio.direccion}";
lbDireaccion.Font = new Font(lbDireaccion.Font.FontFamily, 12);
lbDireaccion.Width = 700;
Label lbTelefono = new Label();
lbTelefono.Text = $"Telefono: {envio.telefono} Estado: {envio.estado}";
lbTelefono.Font = new Font(lbTelefono.Font.FontFamily, 12);
lbTelefono.Width = 700;
Label lbCliente = new Label();
lbCliente.Text = $"Cliente: {envio.cliente}";
lbCliente.Font = new Font(lbCliente.Font.FontFamily, 12);
lbCliente.Width = 700;
Label lbResponzable = new Label();
lbResponzable.Text = $"Responzable: {envio.responsable}";
lbResponzable.Font = new Font(lbResponzable.Font.FontFamily, 12);
lbResponzable.Width = 700;
TableLayoutPanel botonesPanel = new TableLayoutPanel();
botonesPanel.RowCount = 1;
botonesPanel.ColumnCount = 4;
botonesPanel.Dock = DockStyle.Fill;
botonesPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F));
botonesPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F));
botonesPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F));
botonesPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F));
botonesPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
Button btnDetalles = new Button();
btnDetalles.Text = "Detalles";
btnDetalles.Dock = DockStyle.Fill;
btnDetalles.FlatStyle = FlatStyle.Flat;
btnDetalles.FlatAppearance.BorderSize = 0;
btnDetalles.BackColor = Color.FromArgb(33, 90, 255);
btnDetalles.Font = new Font(btnDetalles.Font.FontFamily, 16);
btnDetalles.ForeColor = Color.White;
btnDetalles.Click += new EventHandler(delegate (object sender, EventArgs e)
{ {
mensaje += $"{detalle.producto.nombre} - {detalle.cantidad}\n"; List<DetalleEnvioModel> detalles = service.conseguirDetalleEnvio(envio.id);
} string mensaje = "";
MessageBox.Show(mensaje); foreach (DetalleEnvioModel detalle in detalles)
}); {
mensaje += $"{detalle.producto.nombre} - {detalle.cantidad}\n";
}
MessageBox.Show(mensaje);
});
Button btnCancelar = new Button(); infoPanel.Controls.Add(lbFecha);
btnCancelar.Text = "Cancelar"; infoPanel.Controls.Add(lbResponzable);
btnCancelar.Dock = DockStyle.Fill; infoPanel.Controls.Add(lbCliente);
btnCancelar.FlatStyle = FlatStyle.Flat; infoPanel.Controls.Add(lbDireaccion);
btnCancelar.FlatAppearance.BorderSize = 0; infoPanel.Controls.Add(lbTelefono);
btnCancelar.BackColor = Color.Red;
btnCancelar.Font = new Font(btnDetalles.Font.FontFamily, 16);
btnCancelar.Click += new EventHandler(delegate (object sender, EventArgs e)
{
List<DetalleEnvioModel> detalles = service.conseguirDetalleEnvio(envio.id);
string mensaje = "";
foreach (DetalleEnvioModel detalle in detalles)
{
mensaje += $"{detalle.producto.nombre} - {detalle.cantidad}\n";
}
MessageBox.Show(mensaje);
});
Button btnAgregar = new Button(); botonesPanel.Controls.Add(btnDetalles, 0, 0);
btnAgregar.Text = "Agregar";
btnAgregar.Dock = DockStyle.Fill;
btnAgregar.FlatStyle = FlatStyle.Flat;
btnAgregar.FlatAppearance.BorderSize = 0;
btnAgregar.BackColor = Color.FromArgb(33, 90, 255);
btnAgregar.Font = new Font(btnDetalles.Font.FontFamily, 16);
btnAgregar.ForeColor = Color.White;
btnAgregar.Click += new EventHandler(delegate (object sender, EventArgs e)
{
List<DetalleEnvioModel> detalles = service.conseguirDetalleEnvio(envio.id);
string mensaje = "";
foreach (DetalleEnvioModel detalle in detalles)
{
mensaje += $"{detalle.producto.nombre} - {detalle.cantidad}\n";
}
MessageBox.Show(mensaje);
});
carta.Controls.Add(infoPanel, 0, 0);
carta.Controls.Add(botonesPanel, 0, 1);
infoPanel.Controls.Add(lbFecha); panelEnvio.Controls.Add(carta);
infoPanel.Controls.Add(lbResponzable); }
infoPanel.Controls.Add(lbCliente);
infoPanel.Controls.Add(lbDireaccion);
infoPanel.Controls.Add(lbTelefono);
botonesPanel.Controls.Add(btnDetalles, 0, 0);
botonesPanel.Controls.Add(btnConcluir, 1, 0);
botonesPanel.Controls.Add(btnAgregar, 2, 0);
botonesPanel.Controls.Add(btnCancelar, 3, 0);
carta.Controls.Add(infoPanel,0,0);
carta.Controls.Add(botonesPanel,0,1);
panelEnvio.Controls.Add(carta);
} }
} }
+1 -1
View File
@@ -708,7 +708,7 @@ namespace compabetov2
{ {
List<DetalleEnvioModel> detallesEnvio = listaProductosEnvio(); List<DetalleEnvioModel> detallesEnvio = listaProductosEnvio();
string responsable = responsablecb.Text.Equals("") ? loginPrincipal.usuario : responsablecb.Text; string responsable = responsablecb.Text.Equals("") ? loginPrincipal.usuario : responsablecb.Text;
Envio envio = new Envio(-1, DateTime.Now.ToString(), "", "", responsable,"","",total); Envio envio = new Envio(-1, DateTime.Now.ToString(), "", "", responsable,"","",total+10);
if(detallesEnvio.Count > 0){ if(detallesEnvio.Count > 0){
if (service.crearEnvio(envio, detallesEnvio)) if (service.crearEnvio(envio, detallesEnvio))
{ {
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
+149 -1
View File
@@ -1212,7 +1212,7 @@ namespace compabetov2.database
{ {
try 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 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"; 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("@fecha", envio.fecha);
commandCuenta.Parameters.AddWithValue("@direccion", ""); commandCuenta.Parameters.AddWithValue("@direccion", "");
commandCuenta.Parameters.AddWithValue("@telefono", ""); commandCuenta.Parameters.AddWithValue("@telefono", "");
commandCuenta.Parameters.AddWithValue("@responzable", envio.responsable);
commandCuenta.Parameters.AddWithValue("@total", envio.total); commandCuenta.Parameters.AddWithValue("@total", envio.total);
commandCuenta.ExecuteNonQuery(); 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() private static void crearDB()
{ {
var db_conexion = new Conexion(); var db_conexion = new Conexion();
+16
View File
@@ -364,5 +364,21 @@ namespace compabetov2.database
return detallesEnvio; return detallesEnvio;
} }
public static bool editarEnvio(Envio envio)
{
return DAO.editarEnvioDAO(envio);
}
public static bool cancelarEnvio(int idEnvio)
{
return DAO.cancelarEnvioDAO(idEnvio);
}
public static bool concluirEnvio(Envio envio, List<DetalleEnvioModel> detallesEnvio)
{
return DAO.concluirEnvioDAO(envio, detallesEnvio);
}
} }
} }
Binary file not shown.
Binary file not shown.
Binary file not shown.