funcion para crear contenido a imprimir
This commit is contained in:
@@ -6,6 +6,7 @@ using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Printing;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -53,16 +54,16 @@ namespace compabetov2
|
||||
carta.Width = 220;
|
||||
carta.Height = 300;
|
||||
|
||||
PictureBox pic = new PictureBox();
|
||||
pic.Dock = DockStyle.Fill;
|
||||
pic.SizeMode = PictureBoxSizeMode.Zoom;
|
||||
string rutaImg = Path.Combine(Application.StartupPath, "Resources", producto.img);
|
||||
pic.Image = Image.FromFile(rutaImg);//hay error aquí
|
||||
pic.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
pic.Tag = producto.idProducto;
|
||||
PictureBox pic = new PictureBox();
|
||||
pic.Dock = DockStyle.Fill;
|
||||
pic.SizeMode = PictureBoxSizeMode.Zoom;
|
||||
string rutaImg = Path.Combine(Application.StartupPath, "Resources", producto.img);
|
||||
pic.Image = Image.FromFile(rutaImg);//hay error aquí
|
||||
pic.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
pic.Tag = producto.idProducto;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -111,7 +112,7 @@ namespace compabetov2
|
||||
btnMenos.BackColor = Color.FromArgb(33, 90, 255);
|
||||
btnMenos.Click += new EventHandler(delegate (object sender, EventArgs e)
|
||||
{
|
||||
|
||||
|
||||
int numeroContador = int.Parse(contador.Text.ToString());
|
||||
|
||||
// Validar que el contador no sea 0 antes de restar
|
||||
@@ -172,7 +173,9 @@ namespace compabetov2
|
||||
// Generar ticket y agregarlo al flowLayoutPanel2
|
||||
GenerarTicket(idProducto, producto.nombre, producto.precion, int.Parse(contador.Text), total, rutaImg);
|
||||
|
||||
MessageBox.Show(crearContenidoImprimir());
|
||||
|
||||
|
||||
});
|
||||
|
||||
HUD.Controls.Add(btnMenos);
|
||||
@@ -187,12 +190,6 @@ namespace compabetov2
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void RestarDelTicket(int idProducto, string nombreProducto, decimal precio, int cantidad)
|
||||
@@ -248,9 +245,9 @@ namespace compabetov2
|
||||
{
|
||||
bool existeProducto = false;
|
||||
int contador_saltar_2_vueltas = 1;
|
||||
foreach(var item in flowLayoutPanel2.Controls)
|
||||
foreach (var item in flowLayoutPanel2.Controls)
|
||||
{
|
||||
if(contador_saltar_2_vueltas <= 3)
|
||||
if (contador_saltar_2_vueltas <= 3)
|
||||
{
|
||||
contador_saltar_2_vueltas++;
|
||||
continue;
|
||||
@@ -261,17 +258,17 @@ namespace compabetov2
|
||||
string textoLb = lbnombre.Text;
|
||||
string[] cadenas = textoLb.Split(':');
|
||||
string cadena = cadenas[1].Remove(0, 1);
|
||||
|
||||
|
||||
if (cadena.Equals(nombreProducto))
|
||||
{
|
||||
|
||||
existeProducto=true;
|
||||
|
||||
existeProducto = true;
|
||||
Label Lbcantidad = panelInfo.Controls[2] as Label;
|
||||
Label Lbtotal = panelInfo.Controls[3] as Label;
|
||||
string textcantidad = Lbcantidad.Text;
|
||||
string[] cantidadCadenas = textcantidad.Split(' ');
|
||||
int NuevaCantiad = int.Parse(cantidadCadenas[1]) + 1;
|
||||
|
||||
|
||||
int NuevoTotal = (int)(NuevaCantiad * precio);
|
||||
|
||||
Lbcantidad.Text = $"Cantidad: {NuevaCantiad}";
|
||||
@@ -392,7 +389,113 @@ namespace compabetov2
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void bntImprimir_Click(object sender, EventArgs e)
|
||||
{
|
||||
ImprimirTicket();
|
||||
}
|
||||
|
||||
|
||||
private void ImprimirTicket()
|
||||
{
|
||||
using (PrintDocument documentoImpresion = new PrintDocument())
|
||||
{
|
||||
documentoImpresion.PrintPage += (sender, e) => ImprimirContenido(e);
|
||||
using (PrintDialog printDialog = new PrintDialog())
|
||||
{
|
||||
printDialog.Document = documentoImpresion;
|
||||
|
||||
if (printDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
documentoImpresion.Print();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ImprimirContenido(PrintPageEventArgs e)
|
||||
{
|
||||
|
||||
// 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\n" +
|
||||
"Producto Precio Cantidad\n" +
|
||||
"---------------------\n";
|
||||
|
||||
// Agregar detalles de productos al contenido
|
||||
foreach (TableLayoutPanel carta in cartas)
|
||||
{
|
||||
PictureBox pic = carta.Controls[0] as PictureBox;
|
||||
Label precio = pic.Controls[1] as Label;
|
||||
|
||||
contenido += $"{precio.Text}\n";
|
||||
}
|
||||
|
||||
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 string crearContenidoImprimir()
|
||||
{
|
||||
int contador_saltar_2_vueltas = 1;
|
||||
string resultado = "";
|
||||
foreach (var item in 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} --- ${precioProducto}\nCantidad: {cantidadProducto}\nTotal: {totalProducto}\n";
|
||||
|
||||
}
|
||||
return resultado;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user