Subo cambios 457
This commit is contained in:
+118
-1
@@ -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<DetalleEnvioModel> 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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user