boton vender de la venta venta listo
This commit is contained in:
Binary file not shown.
File diff suppressed because one or more lines are too long
+6
-6
@@ -152,7 +152,7 @@ namespace compabetov2
|
|||||||
decimal totalVendidoMes = 0;
|
decimal totalVendidoMes = 0;
|
||||||
foreach (DetalleVentaModel producto in detallesMes)
|
foreach (DetalleVentaModel producto in detallesMes)
|
||||||
{
|
{
|
||||||
totalVendidoMes += producto.cantidad * producto.producto.precion;
|
totalVendidoMes += producto.cantidad * producto.producto.precio;
|
||||||
// Crear una nueva fila
|
// Crear una nueva fila
|
||||||
DataGridViewRow nuevaFila = new DataGridViewRow();
|
DataGridViewRow nuevaFila = new DataGridViewRow();
|
||||||
|
|
||||||
@@ -164,9 +164,9 @@ namespace compabetov2
|
|||||||
|
|
||||||
// Establecer los valores de las celdas (puedes ajustar según tu necesidad)
|
// Establecer los valores de las celdas (puedes ajustar según tu necesidad)
|
||||||
productoN.Value = $"{producto.producto.nombre}";
|
productoN.Value = $"{producto.producto.nombre}";
|
||||||
precio.Value = $"{producto.producto.precion}";
|
precio.Value = $"{producto.producto.precio}";
|
||||||
cantidad.Value = $"{producto.cantidad}";
|
cantidad.Value = $"{producto.cantidad}";
|
||||||
total.Value = $"{producto.cantidad * producto.producto.precion}";
|
total.Value = $"{producto.cantidad * producto.producto.precio}";
|
||||||
|
|
||||||
// Agregar las celdas a la fila
|
// Agregar las celdas a la fila
|
||||||
nuevaFila.Cells.Add(productoN);
|
nuevaFila.Cells.Add(productoN);
|
||||||
@@ -188,7 +188,7 @@ namespace compabetov2
|
|||||||
decimal totalVendidoDia = 0;
|
decimal totalVendidoDia = 0;
|
||||||
foreach (DetalleVentaModel producto in detallesDia)
|
foreach (DetalleVentaModel producto in detallesDia)
|
||||||
{
|
{
|
||||||
totalVendidoDia += producto.cantidad * producto.producto.precion;
|
totalVendidoDia += producto.cantidad * producto.producto.precio;
|
||||||
// Crear una nueva fila
|
// Crear una nueva fila
|
||||||
DataGridViewRow nuevaFila = new DataGridViewRow();
|
DataGridViewRow nuevaFila = new DataGridViewRow();
|
||||||
|
|
||||||
@@ -200,9 +200,9 @@ namespace compabetov2
|
|||||||
|
|
||||||
// Establecer los valores de las celdas (puedes ajustar según tu necesidad)
|
// Establecer los valores de las celdas (puedes ajustar según tu necesidad)
|
||||||
productoN.Value = $"{producto.producto.nombre}";
|
productoN.Value = $"{producto.producto.nombre}";
|
||||||
precio.Value = $"{producto.producto.precion}";
|
precio.Value = $"{producto.producto.precio}";
|
||||||
cantidad.Value = $"{producto.cantidad}";
|
cantidad.Value = $"{producto.cantidad}";
|
||||||
total.Value = $"{producto.cantidad * producto.producto.precion}";
|
total.Value = $"{producto.cantidad * producto.producto.precio}";
|
||||||
|
|
||||||
// Agregar las celdas a la fila
|
// Agregar las celdas a la fila
|
||||||
nuevaFila.Cells.Add(productoN);
|
nuevaFila.Cells.Add(productoN);
|
||||||
|
|||||||
+95
-75
@@ -25,10 +25,11 @@ namespace compabetov2
|
|||||||
{
|
{
|
||||||
private int numeroPagina = 1; // Variable para rastrear el número de página actual
|
private int numeroPagina = 1; // Variable para rastrear el número de página actual
|
||||||
private Point lastPoint;
|
private Point lastPoint;
|
||||||
private List<Producto> productos;
|
private List<Variante> productos;
|
||||||
public decimal total = 0;
|
public decimal total = 0;
|
||||||
private LoginModel loginPrincipal;
|
private LoginModel loginPrincipal;
|
||||||
private Dictionary<string, Image> imagenes = new Dictionary<string, Image>();
|
private Dictionary<string, Image> imagenes = new Dictionary<string, Image>();
|
||||||
|
private List<DetalleVentaModel> carrito = new List<DetalleVentaModel>();
|
||||||
|
|
||||||
|
|
||||||
public vender(LoginModel loginPrincipal)
|
public vender(LoginModel loginPrincipal)
|
||||||
@@ -38,7 +39,7 @@ namespace compabetov2
|
|||||||
llenarLayout();
|
llenarLayout();
|
||||||
llenarComBox();
|
llenarComBox();
|
||||||
this.loginPrincipal = loginPrincipal;
|
this.loginPrincipal = loginPrincipal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void InitializeFlowLayout()
|
private void InitializeFlowLayout()
|
||||||
@@ -81,7 +82,7 @@ namespace compabetov2
|
|||||||
private void llenarComBox()
|
private void llenarComBox()
|
||||||
{
|
{
|
||||||
List<Empleado> empleados = service.conseguirEmpleados();
|
List<Empleado> empleados = service.conseguirEmpleados();
|
||||||
foreach(Empleado empleado in empleados)
|
foreach (Empleado empleado in empleados)
|
||||||
{
|
{
|
||||||
responsablecb.Items.Add(empleado.nombre);
|
responsablecb.Items.Add(empleado.nombre);
|
||||||
}
|
}
|
||||||
@@ -89,8 +90,8 @@ namespace compabetov2
|
|||||||
|
|
||||||
public void llenarLayout()
|
public void llenarLayout()
|
||||||
{
|
{
|
||||||
flowLayoutPanel3.Controls.Clear();
|
flowLayoutPanel3.Controls.Clear();
|
||||||
foreach (Producto producto in productos)
|
foreach (Variante producto in productos)
|
||||||
{
|
{
|
||||||
|
|
||||||
TableLayoutPanel carta = new TableLayoutPanel();
|
TableLayoutPanel carta = new TableLayoutPanel();
|
||||||
@@ -106,7 +107,8 @@ namespace compabetov2
|
|||||||
PictureBox pic = new PictureBox();
|
PictureBox pic = new PictureBox();
|
||||||
pic.Dock = DockStyle.Fill;
|
pic.Dock = DockStyle.Fill;
|
||||||
pic.SizeMode = PictureBoxSizeMode.Zoom;
|
pic.SizeMode = PictureBoxSizeMode.Zoom;
|
||||||
if (imagenes.ContainsKey(producto.img)) {
|
if (imagenes.ContainsKey(producto.img))
|
||||||
|
{
|
||||||
pic.Image = imagenes[producto.img];
|
pic.Image = imagenes[producto.img];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -118,9 +120,9 @@ namespace compabetov2
|
|||||||
}
|
}
|
||||||
//hay error aquí
|
//hay error aquí
|
||||||
pic.BackgroundImageLayout = ImageLayout.Stretch;
|
pic.BackgroundImageLayout = ImageLayout.Stretch;
|
||||||
pic.Tag = producto.idProducto;
|
pic.Tag = producto.idVariante;
|
||||||
Label id = new Label();
|
Label id = new Label();
|
||||||
id.Text = producto.idProducto.ToString();
|
id.Text = producto.idVariante.ToString();
|
||||||
id.BackColor = Color.FromArgb(82, 82, 82);
|
id.BackColor = Color.FromArgb(82, 82, 82);
|
||||||
id.ForeColor = Color.White;
|
id.ForeColor = Color.White;
|
||||||
id.Width = 20;
|
id.Width = 20;
|
||||||
@@ -129,7 +131,7 @@ namespace compabetov2
|
|||||||
pic.Controls.Add(id);
|
pic.Controls.Add(id);
|
||||||
|
|
||||||
Label precio = new Label();
|
Label precio = new Label();
|
||||||
precio.Text = "$" + producto.precion.ToString() + " - " + producto.nombre;
|
precio.Text = "$" + producto.precio.ToString() + " - " + producto.nombre;
|
||||||
precio.BackColor = Color.FromArgb(82, 82, 82);
|
precio.BackColor = Color.FromArgb(82, 82, 82);
|
||||||
precio.ForeColor = Color.White;
|
precio.ForeColor = Color.White;
|
||||||
precio.Width = 40;
|
precio.Width = 40;
|
||||||
@@ -166,19 +168,23 @@ namespace compabetov2
|
|||||||
int numeroContador = int.Parse(contador.Text.ToString());
|
int numeroContador = int.Parse(contador.Text.ToString());
|
||||||
|
|
||||||
// Validar que el contador no sea 0 antes de restar
|
// Validar que el contador no sea 0 antes de restar
|
||||||
|
int indexCarrito = estaEnCarrito(producto.nombre);
|
||||||
if (existeTocket(producto.nombre))
|
if (indexCarrito != -1)
|
||||||
{
|
{
|
||||||
contador.Text = (numeroContador - 1).ToString();
|
contador.Text = (numeroContador - 1).ToString();
|
||||||
total -= producto.precion;
|
total -= producto.precio;
|
||||||
label1.Text = $"Total: ${total}";
|
label1.Text = $"Total: ${total}";
|
||||||
|
|
||||||
// Obtener información del Label id y precio
|
// Obtener información del Label id y precio
|
||||||
int idProducto = int.Parse(id.Text);
|
decimal precioProducto = producto.precio;
|
||||||
decimal precioProducto = producto.precion;
|
|
||||||
|
|
||||||
// Restar al ticket existente si ya se agregó
|
// Restar al ticket existente si ya se agregó
|
||||||
RestarDelTicket(idProducto, producto.nombre, precioProducto, 1);
|
carrito[indexCarrito].cantidad = int.Parse(contador.Text);
|
||||||
|
if (carrito[indexCarrito].cantidad == 0)
|
||||||
|
{
|
||||||
|
carrito.RemoveAt(indexCarrito);
|
||||||
|
}
|
||||||
|
RestarDelTicket(producto.idVariante, producto.nombre, precioProducto, 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -201,19 +207,29 @@ namespace compabetov2
|
|||||||
btnMas.FlatAppearance.BorderSize = 0;
|
btnMas.FlatAppearance.BorderSize = 0;
|
||||||
btnMas.Click += new EventHandler(delegate (object sender, EventArgs e)
|
btnMas.Click += new EventHandler(delegate (object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if(int.Parse(contador.Text.ToString()) < 0 && !existeTocket(producto.nombre)) {
|
if (int.Parse(contador.Text.ToString()) < 0 && !existeTocket(producto.nombre))
|
||||||
contador.Text = "0";
|
{
|
||||||
|
contador.Text = "0";
|
||||||
}
|
}
|
||||||
int numeroContador = int.Parse(contador.Text.ToString());
|
int numeroContador = int.Parse(contador.Text.ToString());
|
||||||
contador.Text = (numeroContador + 1).ToString();
|
contador.Text = (numeroContador + 1).ToString();
|
||||||
total += producto.precion;
|
total += producto.precio;
|
||||||
label1.Text = $"Total: ${total}";
|
label1.Text = $"Total: ${total}";
|
||||||
|
|
||||||
// Obtener información del Label id y precio
|
// Obtener información del Label id y precio
|
||||||
int idProducto = int.Parse(id.Text);
|
int idProducto = int.Parse(id.Text);
|
||||||
decimal precioProducto = producto.precion;
|
decimal precioProducto = producto.precio;
|
||||||
// Generar ticket y agregarlo al flowLayoutPanel2
|
// Generar ticket y agregarlo al flowLayoutPanel2
|
||||||
GenerarTicket(idProducto, producto.nombre, producto.precion, int.Parse(contador.Text), total,
|
int indexCarrito = estaEnCarrito(producto.nombre);
|
||||||
|
if (indexCarrito != -1)
|
||||||
|
{
|
||||||
|
carrito[indexCarrito].cantidad = int.Parse(contador.Text);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
carrito.Add(new DetalleVentaModel(int.Parse(contador.Text), producto));
|
||||||
|
}
|
||||||
|
GenerarTicket(idProducto, producto.nombre, producto.precio, int.Parse(contador.Text), total,
|
||||||
Path.Combine(Application.StartupPath, "Resources", producto.img));
|
Path.Combine(Application.StartupPath, "Resources", producto.img));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -228,6 +244,18 @@ namespace compabetov2
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int estaEnCarrito(string nombre)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < carrito.Count; i++)
|
||||||
|
{
|
||||||
|
if (carrito[i].producto.nombre.Equals(nombre))
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
private void RestarDelTicket(int idProducto, string nombreProducto, decimal precio, int cantidad)
|
private void RestarDelTicket(int idProducto, string nombreProducto, decimal precio, int cantidad)
|
||||||
{
|
{
|
||||||
foreach (var item in flowLayoutPanel2.Controls)
|
foreach (var item in flowLayoutPanel2.Controls)
|
||||||
@@ -255,7 +283,7 @@ namespace compabetov2
|
|||||||
{
|
{
|
||||||
string textcantidad = Lbcantidad.Text;
|
string textcantidad = Lbcantidad.Text;
|
||||||
string[] cantidadCadenas = textcantidad.Split(' ');
|
string[] cantidadCadenas = textcantidad.Split(' ');
|
||||||
if(int.Parse(cantidadCadenas[1]) > 0)
|
if (int.Parse(cantidadCadenas[1]) > 0)
|
||||||
{
|
{
|
||||||
int NuevaCantiad = int.Parse(cantidadCadenas[1]) - cantidad;
|
int NuevaCantiad = int.Parse(cantidadCadenas[1]) - cantidad;
|
||||||
|
|
||||||
@@ -409,16 +437,9 @@ namespace compabetov2
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void getData()
|
private void getData()
|
||||||
{
|
{
|
||||||
this.productos = service.conseguirProductos();
|
this.productos = service.conseguirVariantes();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void vender_Load(object sender, EventArgs e)
|
private void vender_Load(object sender, EventArgs e)
|
||||||
@@ -456,7 +477,7 @@ namespace compabetov2
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void button1_Click(object sender, EventArgs e)
|
private void button1_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
@@ -497,40 +518,37 @@ namespace compabetov2
|
|||||||
|
|
||||||
private void bntImprimir_Click(object sender, EventArgs e)
|
private void bntImprimir_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
DialogResult resultado = MessageBox.Show("¿Quieres hacer esa venta?", "Confirmación de Venta", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
//List<DetalleVentaModel> detalleVentas = listaProductosVenta();
|
||||||
|
if (carrito.Count > 0)
|
||||||
if (resultado == DialogResult.Yes)
|
|
||||||
{
|
{
|
||||||
// Si la opción es "SI", imprimir el ticket
|
DialogResult resultado = MessageBox.Show("¿Quieres hacer esa venta?", "Confirmación de Venta", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
||||||
ImprimirTicket();
|
|
||||||
|
|
||||||
List<DetalleVentaModel> detalleVentas = listaProductosVenta();
|
if (resultado == DialogResult.Yes)
|
||||||
if (detalleVentas.Count > 0)
|
|
||||||
{
|
{
|
||||||
VentaModel ventaModel = new VentaModel(total,-1,"",
|
VentaModel ventaModel = new VentaModel(total, -1, "",
|
||||||
responsablecb.Text.Equals("") ? loginPrincipal.usuario : responsablecb.Text
|
responsablecb.Text.Equals("") ? loginPrincipal.usuario : responsablecb.Text
|
||||||
);
|
);
|
||||||
|
|
||||||
if (service.crearVentaDAO(ventaModel, detalleVentas))
|
if (service.crearVentaDAO(ventaModel, carrito))
|
||||||
{
|
{
|
||||||
MessageBox.Show("Venta hecha");
|
MessageBox.Show("Venta hecha");
|
||||||
eliminarProductosTocket();
|
eliminarProductosTocket();
|
||||||
llenarLayout();
|
llenarLayout();
|
||||||
total= 0;
|
total = 0;
|
||||||
|
ImprimirTicket();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MessageBox.Show("No hay ningun producto agregado");
|
// Si la opción es "NO", mostrar mensaje de venta cancelada
|
||||||
|
MessageBox.Show("Venta cancelada", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Si la opción es "NO", mostrar mensaje de venta cancelada
|
MessageBox.Show("No hay ningun producto agregado");
|
||||||
MessageBox.Show("Venta cancelada", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -554,10 +572,10 @@ namespace compabetov2
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void ImprimirContenido(PrintPageEventArgs e)
|
private void ImprimirContenido(PrintPageEventArgs e)
|
||||||
{
|
{
|
||||||
@@ -572,7 +590,7 @@ namespace compabetov2
|
|||||||
$" Fecha: {DateTime.Now.ToString("dd/MM/yyyy")}\n" +
|
$" Fecha: {DateTime.Now.ToString("dd/MM/yyyy")}\n" +
|
||||||
$" Hora: {DateTime.Now.ToString("hh:mm:ss")}\n" +
|
$" Hora: {DateTime.Now.ToString("hh:mm:ss")}\n" +
|
||||||
$" Atendió:\n " +
|
$" Atendió:\n " +
|
||||||
$" {responsable}\n" +
|
$" {responsable}\n" +
|
||||||
"Producto | Precio | Cantidad\n" +
|
"Producto | Precio | Cantidad\n" +
|
||||||
"------------------------------------\n";
|
"------------------------------------\n";
|
||||||
|
|
||||||
@@ -594,21 +612,21 @@ namespace compabetov2
|
|||||||
e.Graphics.DrawString(contenido, fuente, Brushes.Black, posicion);
|
e.Graphics.DrawString(contenido, fuente, Brushes.Black, posicion);
|
||||||
|
|
||||||
// Incrementa el número de página
|
// Incrementa el número de página
|
||||||
// Tu lógica de impresión actual aquí
|
// Tu lógica de impresión actual aquí
|
||||||
|
|
||||||
// Incrementa el número de página
|
// Incrementa el número de página
|
||||||
numeroPagina++;
|
numeroPagina++;
|
||||||
|
|
||||||
// Imprime solo dos páginas
|
// Imprime solo dos páginas
|
||||||
if (numeroPagina <= 2)
|
if (numeroPagina <= 2)
|
||||||
{
|
{
|
||||||
e.HasMorePages = true;
|
e.HasMorePages = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
e.HasMorePages = false;
|
e.HasMorePages = false;
|
||||||
numeroPagina = 1; // Reinicia el número de página para futuras impresiones
|
numeroPagina = 1; // Reinicia el número de página para futuras impresiones
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -660,11 +678,11 @@ namespace compabetov2
|
|||||||
private void button7_Click(object sender, EventArgs e)
|
private void button7_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
List<DetalleVentaModel> detalleVentas = listaProductosVenta();
|
List<DetalleVentaModel> detalleVentas = listaProductosVenta();
|
||||||
if(detalleVentas.Count > 0)
|
if (detalleVentas.Count > 0)
|
||||||
{
|
{
|
||||||
VentaModel ventaModel = new VentaModel(total);
|
VentaModel ventaModel = new VentaModel(total);
|
||||||
|
|
||||||
if(service.crearVentaDAO(ventaModel, detalleVentas))
|
if (service.crearVentaDAO(ventaModel, detalleVentas))
|
||||||
{
|
{
|
||||||
MessageBox.Show("Venta hecha");
|
MessageBox.Show("Venta hecha");
|
||||||
}
|
}
|
||||||
@@ -699,7 +717,7 @@ namespace compabetov2
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
int idProducto = int.Parse(idLabel.Text);
|
int idProducto = int.Parse(idLabel.Text);
|
||||||
Producto producto = new Producto(idProducto);
|
Variante producto = new Variante(idProducto, "", 0, 0, "", 0);
|
||||||
|
|
||||||
Label Lbcantidad = panelInfo.Controls[2] as Label;
|
Label Lbcantidad = panelInfo.Controls[2] as Label;
|
||||||
string textcantidad = Lbcantidad.Text;
|
string textcantidad = Lbcantidad.Text;
|
||||||
@@ -729,9 +747,9 @@ namespace compabetov2
|
|||||||
{
|
{
|
||||||
Cuenta ventaModel = new Cuenta(total);
|
Cuenta ventaModel = new Cuenta(total);
|
||||||
|
|
||||||
datosCuenta datoCuenta = new datosCuenta(ventaModel, detallesCuenta,this);
|
datosCuenta datoCuenta = new datosCuenta(ventaModel, detallesCuenta, this);
|
||||||
datoCuenta.Show();
|
datoCuenta.Show();
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -790,7 +808,8 @@ namespace compabetov2
|
|||||||
btnFiar.Enabled = true;
|
btnFiar.Enabled = true;
|
||||||
btnEnviar.Enabled = true;
|
btnEnviar.Enabled = true;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
|
|
||||||
bntImprimir.Enabled = false;
|
bntImprimir.Enabled = false;
|
||||||
btnFiar.Enabled = false;
|
btnFiar.Enabled = false;
|
||||||
@@ -798,7 +817,7 @@ namespace compabetov2
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -807,7 +826,7 @@ namespace compabetov2
|
|||||||
{
|
{
|
||||||
if (!txtbusqueda.Text.Equals(""))
|
if (!txtbusqueda.Text.Equals(""))
|
||||||
{
|
{
|
||||||
productos = service.conseguirProductosFiltrados(txtbusqueda.Text);
|
//productos = service.conseguirProductosFiltrados(txtbusqueda.Text);
|
||||||
llenarLayout();
|
llenarLayout();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -861,27 +880,28 @@ 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);
|
||||||
if(detallesEnvio.Count > 0){
|
if (detallesEnvio.Count > 0)
|
||||||
datosEnvio datosEnvio = new datosEnvio(envio, detallesEnvio,this);
|
{
|
||||||
|
datosEnvio datosEnvio = new datosEnvio(envio, detallesEnvio, this);
|
||||||
datosEnvio.Show();
|
datosEnvio.Show();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MessageBox.Show("No hay ningun producto agregado");
|
MessageBox.Show("No hay ningun producto agregado");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
public void eliminarProductosTocket()
|
public void eliminarProductosTocket()
|
||||||
{
|
{
|
||||||
for (int i = flowLayoutPanel2.Controls.Count -1; i > 2; i--)
|
for (int i = flowLayoutPanel2.Controls.Count - 1; i > 2; i--)
|
||||||
{
|
{
|
||||||
Control c = flowLayoutPanel2.Controls[i];
|
Control c = flowLayoutPanel2.Controls[i];
|
||||||
c.Dispose();
|
c.Dispose();
|
||||||
flowLayoutPanel1.Controls.Remove(c);
|
flowLayoutPanel1.Controls.Remove(c);
|
||||||
}
|
}
|
||||||
label1.Text = "Total: 0";
|
label1.Text = "Total: 0";
|
||||||
|
|
||||||
txtbusqueda.Text = "";
|
txtbusqueda.Text = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -108,6 +108,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="database\modelos\DetalleEnvioModel.cs" />
|
<Compile Include="database\modelos\DetalleEnvioModel.cs" />
|
||||||
<Compile Include="database\modelos\Envio.cs" />
|
<Compile Include="database\modelos\Envio.cs" />
|
||||||
|
<Compile Include="database\modelos\Variante.cs" />
|
||||||
<Compile Include="Empleados\AgregarEmpleado1.cs">
|
<Compile Include="Empleados\AgregarEmpleado1.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|||||||
+36
-9
@@ -778,7 +778,7 @@ namespace compabetov2.database
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
string sqlVenta = "INSERT INTO venta (fecha, total,responzable) VALUES(@fecha, @total,@responzable);";
|
string sqlVenta = "INSERT INTO venta (fecha, total,responzable) VALUES(@fecha, @total,@responzable);";
|
||||||
string sqlDetalle = "INSERT INTO detalle_venta (fk_venta, fk_producto, cantidad) VALUES(@idVenta, @idProducto, @cantidada);";
|
string sqlDetalle = "INSERT INTO detalle_venta (fk_venta, fk_variante, cantidad) VALUES(@idVenta, @fk_variante, @cantidada);";
|
||||||
string sqlIdVenta = "SELECT idVenta FROM venta ORDER BY idVenta DESC LIMIT 1";
|
string sqlIdVenta = "SELECT idVenta FROM venta ORDER BY idVenta DESC LIMIT 1";
|
||||||
string sqlProductoStock = "SELECT stock FROM Producto WHERE idproducto = @idproducto";
|
string sqlProductoStock = "SELECT stock FROM Producto WHERE idproducto = @idproducto";
|
||||||
string sqlProductoUpdate = "UPDATE Producto SET stock = @stock WHERE idproducto = @idproducto";
|
string sqlProductoUpdate = "UPDATE Producto SET stock = @stock WHERE idproducto = @idproducto";
|
||||||
@@ -803,12 +803,13 @@ namespace compabetov2.database
|
|||||||
{
|
{
|
||||||
SQLiteCommand commandEmpleado = new SQLiteCommand(sqlDetalle, conexion);
|
SQLiteCommand commandEmpleado = new SQLiteCommand(sqlDetalle, conexion);
|
||||||
commandEmpleado.Parameters.AddWithValue("@idVenta", idVenta);
|
commandEmpleado.Parameters.AddWithValue("@idVenta", idVenta);
|
||||||
commandEmpleado.Parameters.AddWithValue("@idProducto", detalleVenta.producto.idProducto);
|
commandEmpleado.Parameters.AddWithValue("@fk_variante", detalleVenta.producto.idVariante);
|
||||||
commandEmpleado.Parameters.AddWithValue("@cantidada", detalleVenta.cantidad);
|
commandEmpleado.Parameters.AddWithValue("@cantidada", detalleVenta.cantidad);
|
||||||
commandEmpleado.ExecuteNonQuery();
|
commandEmpleado.ExecuteNonQuery();
|
||||||
|
|
||||||
SQLiteCommand commandProdcutoStock = new SQLiteCommand(sqlProductoStock, conexion);
|
SQLiteCommand commandProdcutoStock = new SQLiteCommand(sqlProductoStock, conexion);
|
||||||
commandProdcutoStock.Parameters.AddWithValue("@idproducto", detalleVenta.producto.idProducto);
|
MessageBox.Show(detalleVenta.producto.fkProducto.ToString());
|
||||||
|
commandProdcutoStock.Parameters.AddWithValue("@idproducto", detalleVenta.producto.fkProducto);
|
||||||
SQLiteDataReader stockReader = commandProdcutoStock.ExecuteReader();
|
SQLiteDataReader stockReader = commandProdcutoStock.ExecuteReader();
|
||||||
|
|
||||||
int stockActual = -1;
|
int stockActual = -1;
|
||||||
@@ -820,10 +821,8 @@ namespace compabetov2.database
|
|||||||
|
|
||||||
SQLiteCommand commandProdcutoUpdate = new SQLiteCommand(sqlProductoUpdate, conexion);
|
SQLiteCommand commandProdcutoUpdate = new SQLiteCommand(sqlProductoUpdate, conexion);
|
||||||
commandProdcutoUpdate.Parameters.AddWithValue("@stock", stockActual - detalleVenta.cantidad);
|
commandProdcutoUpdate.Parameters.AddWithValue("@stock", stockActual - detalleVenta.cantidad);
|
||||||
commandProdcutoUpdate.Parameters.AddWithValue("@idproducto", detalleVenta.producto.idProducto);
|
commandProdcutoUpdate.Parameters.AddWithValue("@idproducto", detalleVenta.producto.fkProducto);
|
||||||
commandProdcutoUpdate.ExecuteNonQuery();
|
commandProdcutoUpdate.ExecuteNonQuery();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
transaccion.Commit();
|
transaccion.Commit();
|
||||||
@@ -1198,7 +1197,7 @@ namespace compabetov2.database
|
|||||||
|
|
||||||
conexion.Open();
|
conexion.Open();
|
||||||
|
|
||||||
string sql = "select * from detalle_venta dv, Producto p WHERE dv.fk_producto = p.idproducto and dv.fk_venta = @idVenta";
|
string sql = "select * from detalle_venta dv, variantes v WHERE dv.fk_variante = v.idVariante and dv.fk_venta = @idVenta";
|
||||||
SQLiteCommand command = new SQLiteCommand(sql, conexion);
|
SQLiteCommand command = new SQLiteCommand(sql, conexion);
|
||||||
command.Parameters.AddWithValue("@idVenta", venta.id);
|
command.Parameters.AddWithValue("@idVenta", venta.id);
|
||||||
reader = command.ExecuteReader();
|
reader = command.ExecuteReader();
|
||||||
@@ -1534,6 +1533,30 @@ namespace compabetov2.database
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static SQLiteDataReader conseguirVariantesDAO()
|
||||||
|
{
|
||||||
|
SQLiteDataReader reader = null;
|
||||||
|
var db_conexion = new Conexion();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
SQLiteConnection conexion = db_conexion.get_connection();
|
||||||
|
|
||||||
|
conexion.Open();
|
||||||
|
|
||||||
|
string sql = "SELECT * FROM variantes";
|
||||||
|
SQLiteCommand command = new SQLiteCommand(sql, conexion);
|
||||||
|
reader = command.ExecuteReader();
|
||||||
|
|
||||||
|
return reader;
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (SQLiteException ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message);
|
||||||
|
return reader;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void crearDB()
|
private static void crearDB()
|
||||||
{
|
{
|
||||||
var db_conexion = new Conexion();
|
var db_conexion = new Conexion();
|
||||||
@@ -1555,6 +1578,7 @@ namespace compabetov2.database
|
|||||||
"DROP TABLE IF EXISTS cuenta",
|
"DROP TABLE IF EXISTS cuenta",
|
||||||
"DROP TABLE IF EXISTS detalle_envios",
|
"DROP TABLE IF EXISTS detalle_envios",
|
||||||
"DROP TABLE IF EXISTS envios",
|
"DROP TABLE IF EXISTS envios",
|
||||||
|
"DROP TABLE IF EXISTS variantes",
|
||||||
|
|
||||||
"CREATE TABLE Login (idlogin INTEGER PRIMARY KEY AUTOINCREMENT, tipo TEXT NOT NULL, usuario TEXT NOT NULL, "+
|
"CREATE TABLE Login (idlogin INTEGER PRIMARY KEY AUTOINCREMENT, tipo TEXT NOT NULL, usuario TEXT NOT NULL, "+
|
||||||
"contra TEXT NOT NULL)",
|
"contra TEXT NOT NULL)",
|
||||||
@@ -1570,6 +1594,9 @@ namespace compabetov2.database
|
|||||||
"precio DECIMAL(10, 2) NOT NULL, img TEXT NOT NULL, stock INTEGER NOT NULL, " +
|
"precio DECIMAL(10, 2) NOT NULL, img TEXT NOT NULL, stock INTEGER NOT NULL, " +
|
||||||
"fk_idcategoria INTEGER NOT NULL, FOREIGN KEY (fk_idcategoria) REFERENCES Categoria (idcategoria))",
|
"fk_idcategoria INTEGER NOT NULL, FOREIGN KEY (fk_idcategoria) REFERENCES Categoria (idcategoria))",
|
||||||
|
|
||||||
|
"CREATE TABLE variantes (idVariante INTEGER PRIMARY KEY AUTOINCREMENT, nombre TEXT, precio DECIMAL(10,2), cantidad INTEGER DEFAULT 1, " +
|
||||||
|
"img TEXT,fk_producto INTEGER, FOREIGN KEY (fk_producto) REFERENCES Producto(idproducto))",
|
||||||
|
|
||||||
"CREATE TABLE Cliente (idcliente INTEGER PRIMARY KEY AUTOINCREMENT, nombres TEXT NOT NULL, apellidos TEXT NOT NULL, " +
|
"CREATE TABLE Cliente (idcliente INTEGER PRIMARY KEY AUTOINCREMENT, nombres TEXT NOT NULL, apellidos TEXT NOT NULL, " +
|
||||||
"calle TEXT NOT NULL, colonia TEXT NOT NULL, cp TEXT NOT NULL, no_ext TEXT NOT NULL, no_int TEXT NOT NULL, referencia TEXT NOT NULL, " +
|
"calle TEXT NOT NULL, colonia TEXT NOT NULL, cp TEXT NOT NULL, no_ext TEXT NOT NULL, no_int TEXT NOT NULL, referencia TEXT NOT NULL, " +
|
||||||
"telefono TEXT NOT NULL, telefono_extra TEXT NOT NULL)",
|
"telefono TEXT NOT NULL, telefono_extra TEXT NOT NULL)",
|
||||||
@@ -1578,8 +1605,8 @@ namespace compabetov2.database
|
|||||||
|
|
||||||
"CREATE TABLE venta (idVenta INTEGER PRIMARY KEY AUTOINCREMENT,fecha TEXT, total DECIMAL(10, 2),responzable TEXT DEFAULT '');",
|
"CREATE TABLE venta (idVenta INTEGER PRIMARY KEY AUTOINCREMENT,fecha TEXT, total DECIMAL(10, 2),responzable TEXT DEFAULT '');",
|
||||||
|
|
||||||
"CREATE TABLE detalle_venta (fk_venta INTEGER, fk_producto INTEGER,cantidad INTEGER DEFAULT 0, PRIMARY KEY (fk_venta, fk_producto), " +
|
"CREATE TABLE detalle_venta (fk_venta INTEGER, fk_variante INTEGER,cantidad INTEGER, PRIMARY KEY (fk_venta, fk_variante)," +
|
||||||
"FOREIGN KEY (fk_venta) REFERENCES venta(idVenta),FOREIGN KEY (fk_producto) REFERENCES producto(idproducto));",
|
"FOREIGN KEY (fk_venta) REFERENCES venta(idVenta),FOREIGN KEY (fk_variante) REFERENCES variantes(idVariante))",
|
||||||
|
|
||||||
"CREATE TABLE cuenta (idCuenta INTEGER PRIMARY KEY AUTOINCREMENT, total DECIMAL(10,2), fecha TEXT, estado TEXT DEFAULT 'ACTIVO', descripcion TEXT, cliente TEXT DEFAULT '')",
|
"CREATE TABLE cuenta (idCuenta INTEGER PRIMARY KEY AUTOINCREMENT, total DECIMAL(10,2), fecha TEXT, estado TEXT DEFAULT 'ACTIVO', descripcion TEXT, cliente TEXT DEFAULT '')",
|
||||||
|
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ namespace compabetov2.database.modelos
|
|||||||
{
|
{
|
||||||
public int idVenta;
|
public int idVenta;
|
||||||
public int cantidad;
|
public int cantidad;
|
||||||
public Producto producto;
|
public Variante producto;
|
||||||
public decimal total;
|
public decimal total;
|
||||||
|
|
||||||
public DetalleVentaModel(int cantidad, Producto producto, int id = -1, decimal total = 0)
|
public DetalleVentaModel(int cantidad, Variante producto, int id = -1, decimal total = 0)
|
||||||
{
|
{
|
||||||
this.cantidad = cantidad;
|
this.cantidad = cantidad;
|
||||||
this.producto = producto;
|
this.producto = producto;
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace compabetov2.database.modelos
|
||||||
|
{
|
||||||
|
public class Variante
|
||||||
|
{
|
||||||
|
public int idVariante;
|
||||||
|
public string nombre;
|
||||||
|
public decimal precio;
|
||||||
|
public int cantidad;
|
||||||
|
public string img;
|
||||||
|
public int fkProducto;
|
||||||
|
|
||||||
|
public Variante(int idVariante, string nombre, decimal precio, int cantidad, string img, int fkProducto)
|
||||||
|
{
|
||||||
|
this.idVariante = idVariante;
|
||||||
|
this.nombre = nombre;
|
||||||
|
this.precio = precio;
|
||||||
|
this.cantidad = cantidad;
|
||||||
|
this.img = img;
|
||||||
|
this.fkProducto = fkProducto;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+28
-10
@@ -405,15 +405,8 @@ namespace compabetov2.database
|
|||||||
{
|
{
|
||||||
DetalleVentaModel detalleVenta = new DetalleVentaModel(
|
DetalleVentaModel detalleVenta = new DetalleVentaModel(
|
||||||
(int)readerDetalleVenta.GetInt64(2),
|
(int)readerDetalleVenta.GetInt64(2),
|
||||||
new Producto(
|
new Variante(-1,"",0,0,"",-1)
|
||||||
(int)readerDetalleVenta.GetInt64(1),
|
|
||||||
readerDetalleVenta["nombre"].ToString(),
|
|
||||||
readerDetalleVenta["descripcion"].ToString(),
|
|
||||||
readerDetalleVenta.GetDecimal(6),
|
|
||||||
readerDetalleVenta["img"].ToString(),
|
|
||||||
(int)readerDetalleVenta.GetInt64(8)
|
|
||||||
),
|
|
||||||
(int)readerDetalleVenta.GetInt64(0)
|
|
||||||
) ;
|
) ;
|
||||||
detallesVenta.Add( detalleVenta );
|
detallesVenta.Add( detalleVenta );
|
||||||
}
|
}
|
||||||
@@ -455,6 +448,7 @@ namespace compabetov2.database
|
|||||||
|
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
|
|
||||||
Producto producto = new Producto(
|
Producto producto = new Producto(
|
||||||
reader.GetInt32(idIndex),
|
reader.GetInt32(idIndex),
|
||||||
reader.GetString(nombreIndex),
|
reader.GetString(nombreIndex),
|
||||||
@@ -466,7 +460,7 @@ namespace compabetov2.database
|
|||||||
|
|
||||||
productos.Add(producto);
|
productos.Add(producto);
|
||||||
}
|
}
|
||||||
|
|
||||||
return productos;
|
return productos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -498,5 +492,29 @@ namespace compabetov2.database
|
|||||||
|
|
||||||
return dic;
|
return dic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<Variante> conseguirVariantes()
|
||||||
|
{
|
||||||
|
List<Variante> variantes = new List<Variante>();
|
||||||
|
SQLiteDataReader reader = DAO.conseguirVariantesDAO();
|
||||||
|
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
decimal precio = reader.GetDecimal(2);
|
||||||
|
int cantidad = (int)reader.GetInt64(3);
|
||||||
|
int fkProducto = (int)reader.GetInt64(5);
|
||||||
|
Variante vaiante = new Variante(
|
||||||
|
(int)reader.GetInt64(0),
|
||||||
|
reader["nombre"].ToString(),
|
||||||
|
precio,
|
||||||
|
cantidad,
|
||||||
|
reader["img"].ToString(),
|
||||||
|
fkProducto
|
||||||
|
);
|
||||||
|
variantes.Add(vaiante);
|
||||||
|
}
|
||||||
|
|
||||||
|
return variantes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -1 +1 @@
|
|||||||
3f62af869539c2801b7da3577ef2feb00e7c32f1cefc777b57202fa5ad70cc96
|
63a64a54bc73e8651fb89f1a0901353ab83d35804c69edd565e24f2be4325b47
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user