diff --git a/Ventas/datosEnvio.Designer.cs b/Ventas/datosEnvio.Designer.cs index 7453b2b..b95020e 100644 --- a/Ventas/datosEnvio.Designer.cs +++ b/Ventas/datosEnvio.Designer.cs @@ -42,62 +42,69 @@ // this.label1.AutoSize = true; this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label1.Location = new System.Drawing.Point(22, 25); + this.label1.Location = new System.Drawing.Point(29, 31); + this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(62, 20); + this.label1.Size = new System.Drawing.Size(79, 25); this.label1.TabIndex = 0; this.label1.Text = "Cliente:"; // // txtCliente // this.txtCliente.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.txtCliente.Location = new System.Drawing.Point(25, 61); + this.txtCliente.Location = new System.Drawing.Point(33, 75); + this.txtCliente.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.txtCliente.Name = "txtCliente"; - this.txtCliente.Size = new System.Drawing.Size(337, 26); + this.txtCliente.Size = new System.Drawing.Size(448, 30); this.txtCliente.TabIndex = 1; // // txtDireccion // this.txtDireccion.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.txtDireccion.Location = new System.Drawing.Point(25, 149); + this.txtDireccion.Location = new System.Drawing.Point(33, 183); + this.txtDireccion.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.txtDireccion.Name = "txtDireccion"; - this.txtDireccion.Size = new System.Drawing.Size(337, 26); + this.txtDireccion.Size = new System.Drawing.Size(448, 30); this.txtDireccion.TabIndex = 3; // // label2 // this.label2.AutoSize = true; this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label2.Location = new System.Drawing.Point(22, 110); + this.label2.Location = new System.Drawing.Point(29, 135); + this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(79, 20); + this.label2.Size = new System.Drawing.Size(99, 25); this.label2.TabIndex = 2; this.label2.Text = "Direccion:"; // // txtTelefono // this.txtTelefono.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.txtTelefono.Location = new System.Drawing.Point(24, 227); + this.txtTelefono.Location = new System.Drawing.Point(32, 279); + this.txtTelefono.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.txtTelefono.Name = "txtTelefono"; - this.txtTelefono.Size = new System.Drawing.Size(338, 26); + this.txtTelefono.Size = new System.Drawing.Size(449, 30); this.txtTelefono.TabIndex = 5; // // label3 // this.label3.AutoSize = true; this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label3.Location = new System.Drawing.Point(21, 191); + this.label3.Location = new System.Drawing.Point(28, 235); + this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(75, 20); + this.label3.Size = new System.Drawing.Size(95, 25); this.label3.TabIndex = 4; this.label3.Text = "Telefono:"; // // btnAceptar // this.btnAceptar.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.btnAceptar.Location = new System.Drawing.Point(103, 277); + this.btnAceptar.Location = new System.Drawing.Point(137, 341); + this.btnAceptar.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.btnAceptar.Name = "btnAceptar"; - this.btnAceptar.Size = new System.Drawing.Size(77, 31); + this.btnAceptar.Size = new System.Drawing.Size(103, 38); this.btnAceptar.TabIndex = 6; this.btnAceptar.Text = "Aceptar"; this.btnAceptar.UseVisualStyleBackColor = true; @@ -106,9 +113,10 @@ // btnCancelar // this.btnCancelar.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.btnCancelar.Location = new System.Drawing.Point(203, 277); + this.btnCancelar.Location = new System.Drawing.Point(271, 341); + this.btnCancelar.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.btnCancelar.Name = "btnCancelar"; - this.btnCancelar.Size = new System.Drawing.Size(83, 31); + this.btnCancelar.Size = new System.Drawing.Size(111, 38); this.btnCancelar.TabIndex = 8; this.btnCancelar.Text = "Cancelar"; this.btnCancelar.UseVisualStyleBackColor = true; @@ -116,9 +124,9 @@ // // datosEnvio // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(374, 341); + this.ClientSize = new System.Drawing.Size(499, 420); this.Controls.Add(this.btnCancelar); this.Controls.Add(this.btnAceptar); this.Controls.Add(this.txtTelefono); @@ -127,8 +135,10 @@ this.Controls.Add(this.label2); this.Controls.Add(this.txtCliente); this.Controls.Add(this.label1); + this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.Name = "datosEnvio"; this.Text = "Datos del envio"; + this.Load += new System.EventHandler(this.datosEnvio_Load); this.ResumeLayout(false); this.PerformLayout(); diff --git a/Ventas/datosEnvio.cs b/Ventas/datosEnvio.cs index 02bef41..033f4ce 100644 --- a/Ventas/datosEnvio.cs +++ b/Ventas/datosEnvio.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; +using System.Drawing.Printing; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -14,6 +15,10 @@ namespace compabetov2.Ventas { public partial class datosEnvio : Form { + + public string Cliente => txtCliente.Text; + public string Direccion => txtDireccion.Text; + public string Telefono => txtTelefono.Text; private Envio envio; List detallesEnvio; vender ventanaPadre; @@ -25,6 +30,8 @@ namespace compabetov2.Ventas this.ventanaPadre = ventanaPadre; } + + private void btnAceptar_Click(object sender, EventArgs e) { envio.cliente = txtCliente.Text; @@ -33,16 +40,126 @@ namespace compabetov2.Ventas if (service.crearEnvio(envio, detallesEnvio)) { MessageBox.Show("Envio hecho"); - ventanaPadre.ImprimirTicketEnvio(); + ImprimirTicketEnvio(); ventanaPadre.eliminarProductosTocket(); ventanaPadre.llenarLayout(); ventanaPadre.total = 0; } } + private string crearContenidoImprimir() + { + int contador_saltar_2_vueltas = 1; + string resultado = ""; + foreach (var item in ventanaPadre.flowLayoutPanel2.Controls) + { + if (contador_saltar_2_vueltas <= 3) + { + contador_saltar_2_vueltas++; + continue; + } + TableLayoutPanel panelProducto = item as TableLayoutPanel; + TableLayoutPanel panelInfo = panelProducto.Controls[1] as TableLayoutPanel; + Label lbnombre = panelInfo.Controls[0] as Label; + Label lbPrecio = panelInfo.Controls[1] as Label; + Label Lbcantidad = panelInfo.Controls[2] as Label; + Label Lbtotal = panelInfo.Controls[3] as Label; + //nombre producto + string textoLbnombre = lbnombre.Text; + string[] cadenas = textoLbnombre.Split(':'); + string productoNombre = cadenas[1].Remove(0, 1); + + //precio + string textoLbPrecio = lbPrecio.Text; + cadenas = textoLbPrecio.Split('$'); + string precioProducto = cadenas[1]; + + //cantidad + string textoLbCantidad = Lbcantidad.Text; + cadenas = textoLbCantidad.Split(':'); + string cantidadProducto = cadenas[1].Remove(0, 1); + + //total + string textoLbTotal = Lbtotal.Text; + cadenas = textoLbTotal.Split('$'); + string totalProducto = cadenas[1]; + + resultado += $"{(productoNombre.Length > 10 ? $"{productoNombre}\n" : $"{productoNombre}")} | ${precioProducto} | {cantidadProducto}\n"; + + + } + return resultado; + } + + + private void ImprimirContenidoEnvio(PrintPageEventArgs e) + { + + string responsable = envio.responsable; + // Contenido que deseas imprimir + string contenido = " Mini Súper\n" + + " Compa BETO\n" + + " Saturnino Peña #44\n" + + " Lomas de la Laguna\n" + + " 311 169 2829\n" + + $" Fecha: {DateTime.Now.ToString("dd/MM/yyyy")}\n" + + $" Hora: {DateTime.Now.ToString("hh:mm:ss")}\n" + + $" Atendió:\n " + + $" {responsable}\n" + + $" ENVIO:\n " + + $" EN CAMINO:\n " + + + "Producto | Precio | Cantidad\n" + + "------------------------------------\n"; + + contenido += crearContenidoImprimir(); + + contenido += $"------------------------------------\n" + + $" Total: ${envio.total + 10}\n" + + "------------------------------------\n" + + " Mini Súper\n" + + " Compa BETO\n" + + " ¡Gracias por su compra!\n" + + "------------------------------------\n" + + " Detalle envío:\n" + + $" Cliente: {txtCliente.Text}\n" + + $" Dirección: {txtDireccion.Text}\n" + + $" Teléfono: {txtTelefono.Text}"; + + + // Configuración de la fuente y del área de impresión + Font fuente = new Font("Arial", 10); // Ajustar el tamaño de fuente según sea necesario + PointF posicion = new PointF(0, e.MarginBounds.Top); + + // Imprimir el contenido + e.Graphics.DrawString(contenido, fuente, Brushes.Black, posicion); + } + + public void ImprimirTicketEnvio() + { + using (PrintDocument documentoImpresion = new PrintDocument()) + { + documentoImpresion.PrintPage += (sender, e) => ImprimirContenidoEnvio(e); + using (PrintDialog printDialog = new PrintDialog()) + { + printDialog.Document = documentoImpresion; + + if (printDialog.ShowDialog() == DialogResult.OK) + { + documentoImpresion.Print(); + } + } + } + } + private void btnCancelar_Click(object sender, EventArgs e) { Close(); } + + private void datosEnvio_Load(object sender, EventArgs e) + { + + } } } diff --git a/Ventas/vender.Designer.cs b/Ventas/vender.Designer.cs index 7535bd4..ec13f48 100644 --- a/Ventas/vender.Designer.cs +++ b/Ventas/vender.Designer.cs @@ -376,7 +376,7 @@ private System.Windows.Forms.Button button5; private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1; private System.ComponentModel.BackgroundWorker backgroundWorker1; - private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel2; + public System.Windows.Forms.FlowLayoutPanel flowLayoutPanel2; private System.Windows.Forms.Panel panel1; private System.Windows.Forms.PictureBox pictureBox9; private System.Windows.Forms.Timer horafecha; diff --git a/Ventas/vender.cs b/Ventas/vender.cs index dc82ab1..52e6b63 100644 --- a/Ventas/vender.cs +++ b/Ventas/vender.cs @@ -23,7 +23,7 @@ namespace compabetov2 { - + private int numeroPagina = 1; // Variable para rastrear el número de página actual private Point lastPoint; private List productos; public decimal total = 0; @@ -475,7 +475,7 @@ namespace compabetov2 } } - private void flowLayoutPanel2_Paint(object sender, PaintEventArgs e) + public void flowLayoutPanel2_Paint(object sender, PaintEventArgs e) { } @@ -485,6 +485,7 @@ namespace compabetov2 } + private void bntImprimir_Click(object sender, EventArgs e) { DialogResult resultado = MessageBox.Show("¿Quieres hacer esa venta?", "Confirmación de Venta", MessageBoxButtons.YesNo, MessageBoxIcon.Question); @@ -529,74 +530,25 @@ namespace compabetov2 using (PrintDocument documentoImpresion = new PrintDocument()) { documentoImpresion.PrintPage += (sender, e) => ImprimirContenido(e); + documentoImpresion.PrintController = new StandardPrintController(); // Evita que el documento se imprima automáticamente + using (PrintDialog printDialog = new PrintDialog()) { printDialog.Document = documentoImpresion; if (printDialog.ShowDialog() == DialogResult.OK) { + // Imprime el documento documentoImpresion.Print(); } } } } - public void ImprimirTicketEnvio() - { - using (PrintDocument documentoImpresion = new PrintDocument()) - { - documentoImpresion.PrintPage += (sender, e) => ImprimirContenidoEnvio(e); - using (PrintDialog printDialog = new PrintDialog()) - { - printDialog.Document = documentoImpresion; - - if (printDialog.ShowDialog() == DialogResult.OK) - { - documentoImpresion.Print(); - } - } - } - } + - private void ImprimirContenidoEnvio(PrintPageEventArgs e) - { - - string responsable = responsablecb.SelectedItem.ToString(); - // Contenido que deseas imprimir - string contenido = " Mini Súper\n" + - " Compa BETO\n" + - " Saturnino Peña #44\n" + - " Lomas de la Laguna\n" + - " 311 169 2829\n" + - $" Fecha: {DateTime.Now.ToString("dd/MM/yyyy")}\n" + - $" Hora: {DateTime.Now.ToString("hh:mm:ss")}\n" + - $" Atendió:\n " + - $" {responsable}\n" + - $" ENVIO:\n " + - $" EN CAMINO:\n " + - - "Producto | Precio | Cantidad\n" + - "------------------------------------\n"; - - contenido += crearContenidoImprimir(); - - contenido += $"------------------------------------\n" + - $" Total: ${total}\n" + - "------------------------------------\n" + - " Mini Súper\n" + - " Compa BETO\n" + - " ¡Gracias por su compra!"; - - - // Configuración de la fuente y del área de impresión - Font fuente = new Font("Arial", 10); // Ajustar el tamaño de fuente según sea necesario - PointF posicion = new PointF(0, e.MarginBounds.Top); - - // Imprimir el contenido - e.Graphics.DrawString(contenido, fuente, Brushes.Black, posicion); - } - + private void ImprimirContenido(PrintPageEventArgs e) { @@ -631,6 +583,24 @@ namespace compabetov2 // Imprimir el contenido e.Graphics.DrawString(contenido, fuente, Brushes.Black, posicion); + + // Incrementa el número de página + // Tu lógica de impresión actual aquí + + // Incrementa el número de página + numeroPagina++; + + // Imprime solo dos páginas + if (numeroPagina <= 2) + { + e.HasMorePages = true; + } + else + { + e.HasMorePages = false; + numeroPagina = 1; // Reinicia el número de página para futuras impresiones + } + } diff --git a/bin/Debug/compabetov2.exe b/bin/Debug/compabetov2.exe index 7668b7e..b9b2961 100644 Binary files a/bin/Debug/compabetov2.exe and b/bin/Debug/compabetov2.exe differ diff --git a/bin/Debug/compabetov2.pdb b/bin/Debug/compabetov2.pdb index 1ba4872..8a3f9c6 100644 Binary files a/bin/Debug/compabetov2.pdb and b/bin/Debug/compabetov2.pdb differ diff --git a/bin/Debug/data.db b/bin/Debug/data.db index 5d8b9bb..fefe1ad 100644 Binary files a/bin/Debug/data.db and b/bin/Debug/data.db differ diff --git a/obj/Debug/compabetov2.csproj.GenerateResource.cache b/obj/Debug/compabetov2.csproj.GenerateResource.cache index 55e9b1b..5edaffc 100644 Binary files a/obj/Debug/compabetov2.csproj.GenerateResource.cache and b/obj/Debug/compabetov2.csproj.GenerateResource.cache differ diff --git a/obj/Debug/compabetov2.exe b/obj/Debug/compabetov2.exe index 7668b7e..b9b2961 100644 Binary files a/obj/Debug/compabetov2.exe and b/obj/Debug/compabetov2.exe differ diff --git a/obj/Debug/compabetov2.pdb b/obj/Debug/compabetov2.pdb index 1ba4872..8a3f9c6 100644 Binary files a/obj/Debug/compabetov2.pdb and b/obj/Debug/compabetov2.pdb differ