diff --git a/Envios/envios.cs b/Envios/envios.cs index e8d609b..3f65d49 100644 --- a/Envios/envios.cs +++ b/Envios/envios.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.Reflection; using System.Text; @@ -156,6 +157,9 @@ namespace compabetov2 if (service.concluirEnvio(envio, detalles)) { llenarPanel(); + ImprimirTicketConcluido(envio); + + } } }); @@ -308,6 +312,53 @@ namespace compabetov2 } } + public static class ImpresionHelper + { + public static void ImprimirContenido(string contenido) + { + PrintDocument pd = new PrintDocument(); + pd.PrintPage += (sender, e) => + { + Font fuente = new Font("Arial", 10); + PointF posicion = new PointF(0, e.MarginBounds.Top); + e.Graphics.DrawString(contenido, fuente, Brushes.Black, posicion); + }; + + PrintDialog printDialog = new PrintDialog(); + printDialog.Document = pd; + + if (printDialog.ShowDialog() == DialogResult.OK) + { + pd.Print(); + } + } + } + private string CrearContenidoImprimir(Envio envio) + { + // Aquí deberías construir el contenido del ticket según tus necesidades + // Puedes usar StringBuilder para construir el contenido eficientemente + StringBuilder contenido = new StringBuilder(); + contenido.AppendLine($"Fecha: {envio.fecha}"); + contenido.AppendLine($"Responsable: {envio.responsable}"); + contenido.AppendLine($"Cliente: {envio.cliente}"); + contenido.AppendLine($"Direccion: {envio.direccion}"); + contenido.AppendLine($"Telefono: {envio.telefono}"); + // ... Agrega más información según sea necesario + + return contenido.ToString(); + } + + private void ImprimirTicketConcluido(Envio envio) + { + string contenido = CrearContenidoImprimir(envio); + contenido += "Estado: CONCLUIDO\n"; // Añade el estado concluido al final del ticket + ImpresionHelper.ImprimirContenido(contenido); + } + + + + + private void button1_Click(object sender, EventArgs e) { diff --git a/Ventas/datosEnvio.Designer.cs b/Ventas/datosEnvio.Designer.cs index c0afc54..8d06f48 100644 --- a/Ventas/datosEnvio.Designer.cs +++ b/Ventas/datosEnvio.Designer.cs @@ -34,8 +34,10 @@ this.label2 = new System.Windows.Forms.Label(); this.txtTelefono = new System.Windows.Forms.TextBox(); this.label3 = new System.Windows.Forms.Label(); - this.btnAceptar = new System.Windows.Forms.Button(); - this.btnCancelar = new System.Windows.Forms.Button(); + this.pictureBox2 = new System.Windows.Forms.PictureBox(); + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); this.SuspendLayout(); // // label1 @@ -44,7 +46,7 @@ this.label1.BackColor = System.Drawing.Color.Transparent; this.label1.Font = new System.Drawing.Font("Poppins", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label1.ForeColor = System.Drawing.Color.Transparent; - this.label1.Location = new System.Drawing.Point(113, 129); + this.label1.Location = new System.Drawing.Point(156, 109); this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(88, 36); @@ -54,7 +56,7 @@ // 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(117, 173); + this.txtCliente.Location = new System.Drawing.Point(160, 153); this.txtCliente.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.txtCliente.Name = "txtCliente"; this.txtCliente.Size = new System.Drawing.Size(448, 30); @@ -63,10 +65,11 @@ // 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(117, 281); + this.txtDireccion.Location = new System.Drawing.Point(160, 261); this.txtDireccion.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.txtDireccion.Multiline = true; this.txtDireccion.Name = "txtDireccion"; - this.txtDireccion.Size = new System.Drawing.Size(448, 30); + this.txtDireccion.Size = new System.Drawing.Size(448, 34); this.txtDireccion.TabIndex = 3; // // label2 @@ -75,7 +78,7 @@ this.label2.BackColor = System.Drawing.Color.Transparent; this.label2.Font = new System.Drawing.Font("Poppins", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label2.ForeColor = System.Drawing.Color.Transparent; - this.label2.Location = new System.Drawing.Point(113, 233); + this.label2.Location = new System.Drawing.Point(156, 213); this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(112, 36); @@ -85,7 +88,7 @@ // 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(116, 377); + this.txtTelefono.Location = new System.Drawing.Point(159, 357); this.txtTelefono.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.txtTelefono.Name = "txtTelefono"; this.txtTelefono.Size = new System.Drawing.Size(449, 30); @@ -97,36 +100,36 @@ this.label3.BackColor = System.Drawing.Color.Transparent; this.label3.Font = new System.Drawing.Font("Poppins", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label3.ForeColor = System.Drawing.Color.Transparent; - this.label3.Location = new System.Drawing.Point(112, 333); + this.label3.Location = new System.Drawing.Point(155, 313); this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(105, 36); this.label3.TabIndex = 4; this.label3.Text = "Telefono:"; // - // btnAceptar + // pictureBox2 // - 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(221, 439); - this.btnAceptar.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); - this.btnAceptar.Name = "btnAceptar"; - this.btnAceptar.Size = new System.Drawing.Size(103, 38); - this.btnAceptar.TabIndex = 6; - this.btnAceptar.Text = "Aceptar"; - this.btnAceptar.UseVisualStyleBackColor = true; - this.btnAceptar.Click += new System.EventHandler(this.btnAceptar_Click); + this.pictureBox2.BackColor = System.Drawing.Color.Transparent; + this.pictureBox2.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; + this.pictureBox2.Image = global::compabetov2.Properties.Resources.check1; + this.pictureBox2.Location = new System.Drawing.Point(282, 414); + this.pictureBox2.Name = "pictureBox2"; + this.pictureBox2.Size = new System.Drawing.Size(100, 69); + this.pictureBox2.TabIndex = 22; + this.pictureBox2.TabStop = false; + this.pictureBox2.Click += new System.EventHandler(this.pictureBox2_Click); // - // btnCancelar + // pictureBox1 // - 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(355, 439); - this.btnCancelar.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); - this.btnCancelar.Name = "btnCancelar"; - this.btnCancelar.Size = new System.Drawing.Size(111, 38); - this.btnCancelar.TabIndex = 8; - this.btnCancelar.Text = "Cancelar"; - this.btnCancelar.UseVisualStyleBackColor = true; - this.btnCancelar.Click += new System.EventHandler(this.btnCancelar_Click); + this.pictureBox1.BackColor = System.Drawing.Color.Transparent; + this.pictureBox1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; + this.pictureBox1.Image = global::compabetov2.Properties.Resources.cancel1; + this.pictureBox1.Location = new System.Drawing.Point(388, 414); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(100, 69); + this.pictureBox1.TabIndex = 21; + this.pictureBox1.TabStop = false; + this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click); // // datosEnvio // @@ -135,10 +138,10 @@ this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(27)))), ((int)(((byte)(104)))), ((int)(((byte)(255))))); this.BackgroundImage = global::compabetov2.Properties.Resources.Form; this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.ClientSize = new System.Drawing.Size(736, 561); + this.ClientSize = new System.Drawing.Size(789, 568); this.ControlBox = false; - this.Controls.Add(this.btnCancelar); - this.Controls.Add(this.btnAceptar); + this.Controls.Add(this.pictureBox2); + this.Controls.Add(this.pictureBox1); this.Controls.Add(this.txtTelefono); this.Controls.Add(this.label3); this.Controls.Add(this.txtDireccion); @@ -150,6 +153,8 @@ this.Name = "datosEnvio"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Load += new System.EventHandler(this.datosEnvio_Load); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -163,7 +168,7 @@ private System.Windows.Forms.Label label2; private System.Windows.Forms.TextBox txtTelefono; private System.Windows.Forms.Label label3; - private System.Windows.Forms.Button btnAceptar; - private System.Windows.Forms.Button btnCancelar; + private System.Windows.Forms.PictureBox pictureBox2; + private System.Windows.Forms.PictureBox pictureBox1; } } \ No newline at end of file diff --git a/Ventas/datosEnvio.cs b/Ventas/datosEnvio.cs index 3dca33b..7c4b475 100644 --- a/Ventas/datosEnvio.cs +++ b/Ventas/datosEnvio.cs @@ -143,21 +143,20 @@ namespace compabetov2.Ventas // Verifica la longitud de la dirección if (direccion.Length > maxCaracteresPorLinea) { - // Inserta un salto de línea después de 8 caracteres - int segmentos = direccion.Length / maxCaracteresPorLinea; - string direccionFormateada = ""; + StringBuilder direccionFormateada = new StringBuilder(); - for (int i = 0; i < segmentos; i++) + for (int i = 0; i < direccion.Length; i += maxCaracteresPorLinea) { - int inicio = i * maxCaracteresPorLinea; - direccionFormateada += direccion.Substring(inicio, maxCaracteresPorLinea) + "\n"; + int caracteresRestantes = direccion.Length - i; + int caracteresEnEstaLinea = Math.Min(caracteresRestantes, maxCaracteresPorLinea); + + direccionFormateada.AppendLine(direccion.Substring(i, caracteresEnEstaLinea)); } - return direccionFormateada; + return direccionFormateada.ToString(); } - // Devuelve la dirección sin cambios si no se necesita ajustar - return direccion; + return direccion; // Devuelve la dirección sin cambios si no es necesario ajustarla } public void ImprimirTicketEnvio() @@ -186,5 +185,27 @@ namespace compabetov2.Ventas { } + + private void pictureBox1_Click(object sender, EventArgs e) + { + Close(); + } + + private void pictureBox2_Click(object sender, EventArgs e) + { + envio.cliente = txtCliente.Text; + envio.direccion = txtDireccion.Text; + envio.telefono = txtTelefono.Text; + if (service.crearEnvio(envio, detallesEnvio)) + { + MessageBox.Show("Envio hecho"); + ImprimirTicketEnvio(); + ventanaPadre.eliminarProductosTocket(); + ventanaPadre.llenarLayout(); + ventanaPadre.total = 0; + + this.Close(); + } + } } }