public static Font getFont(string text, int width, FontStyle style = FontStyle.Bold, string font = "Times new roman") { int num1 = 25; Font font1 = new Font(font, (float)num1, style); Size stringSize = PrinterTicket.getStringSize(text, font1); if (stringSize.Width > width) { int num2 = 0; Font font2; for (; stringSize.Width > width; stringSize = PrinterTicket.getStringSize(text, font2)) { num2 += 2; font2 = new Font(font, (float)(num1 - num2), style); } font1 = new Font(font, (float)(num1 - num2), style); } else if (stringSize.Width < width) { int num2 = 0; Font font2; for (; stringSize.Width < width; stringSize = PrinterTicket.getStringSize(text, font2)) { num2 += 2; font2 = new Font(font, (float)(num1 + num2), style); } font1 = new Font(font, (float)(num1 + num2), style); } return(font1); }
public Panel_productos_Faltantes_Bodega(int depotID) { this.InitializeComponent(); this.depot = new Bodega(depotID); this.dataGrid1.RowsDefaultCellStyle.WrapMode = DataGridViewTriState.True; this.dataGrid1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders; this.printer = new PrinterTicket(); this.printDialog1.PrinterSettings.PrinterName = this.printer.printerName; }
public static int getLastLetterByMeasuring(string text, Font font, int paperWidth) { int num = -1; for (int index = 0; index < text.Length; ++index) { if (PrinterTicket.getStringSize(text.Substring(0, index + 1), font).Width >= paperWidth) { num = index - 1 < 0 ? 0 : index - 1; break; } } return(num); }
private void Panel_Configuracion_Load(object sender, EventArgs e) { this.printer = new PrinterTicket(); if (printer.printerName == "" || !printerExist(printer.printerName)) { return; } this.pd = new PrintDialog(); this.pd.PrinterSettings.PrinterName = this.printer.printerName; setzoom(); //this.setTicketSize(); this.ticketPanel.Enabled = true; this.ticketPanel.Show(); }
private void phoneLbl_SizeChanged(object sender, EventArgs e) { if (this.pd == null) { return; } string text = (sender as Control).Text; Size stringSize = PrinterTicket.getStringSize(text, (sender as Control).Font); int width = this.pd.PrinterSettings.DefaultPageSettings.PaperSize.Width; string str = "\r\n"; for (; stringSize.Width > width; stringSize = PrinterTicket.getStringSize(text, (sender as Control).Font)) { int letterByMeasuring = PrinterTicket.getLastLetterByMeasuring(text, (sender as Control).Font, width); text = text.Insert(letterByMeasuring, text[letterByMeasuring] == ' ' || text[letterByMeasuring] != ' ' && text[letterByMeasuring - 1] == ' ' ? str : "-" + str); } }
public Size printCentered(Graphics g, int y, string text, Font font, int paperWidth) { string str1 = ""; string str2 = "\r\n"; int length = text.IndexOf(str2) > -1 ? text.IndexOf(str2) : text.Length; int startIndex = 0; do { string str3 = text.Substring(startIndex, length).Trim(); Size size; for (size = PrinterTicket.getStringSize(str3, font); size.Width > paperWidth; size = PrinterTicket.getStringSize(str3, font)) { int letterByMeasuring = PrinterTicket.getLastLetterByMeasuring(str3, font, paperWidth); str3 = str3.Insert(letterByMeasuring, str3[letterByMeasuring] == ' ' || str3[letterByMeasuring] != ' ' && str3[letterByMeasuring - 1] == ' ' ? str2 : "-" + str2); } if (str3.IndexOf(str2) > -1) { size = this.printCentered(g, y, str3, font, paperWidth); } else { g.DrawString(str3, font, Brushes.Black, (float)((paperWidth - size.Width) / 2), (float)y); } y += size.Height; str1 = str1 + str3 + str2; startIndex += length + str2.Length; if (startIndex >= text.Length) { length = -1; } else { while (text.Substring(startIndex).IndexOf(str2) > -1 && text.Substring(startIndex).IndexOf(str2) == 0) { startIndex += str2.Length; } string str4 = text.Substring(startIndex); string str5 = str4.IndexOf(str2) > -1 ? str4.Substring(0, str4.IndexOf(str2)) : str4.Substring(0, str4.Length); length = str5.Length > 0 ? str5.Length : -1; } }while (length > -1 && length < text.Length); return(PrinterTicket.getStringSize(str1.Trim(), font)); }
private async void getFitString(Control control, string text) { if (pd != null) { control.Text = await Task.Run <string>((Func <string>)(() => { string str1 = ""; int width = this.pd.PrinterSettings.DefaultPageSettings.PaperSize.Width; string str2 = "\r\n"; int length = text.IndexOf(str2) > -1 ? text.IndexOf(str2) : text.Length; int startIndex = 0; do { string text1 = text.Substring(startIndex, length).Trim(); for (Size stringSize = PrinterTicket.getStringSize(text1, control.Font); stringSize.Width > width; stringSize = PrinterTicket.getStringSize(text1, control.Font)) { int letterByMeasuring = PrinterTicket.getLastLetterByMeasuring(text1, control.Font, width); text1 = text1.Insert(letterByMeasuring, text1[letterByMeasuring] == ' ' || text1[letterByMeasuring] != ' ' && text1[letterByMeasuring - 1] == ' ' ? str2 : "-" + str2); } str1 = str1 + text1 + str2; startIndex += length + str2.Length; if (startIndex >= text.Length) { length = -1; } else { while (text.Substring(startIndex).IndexOf(str2) > -1 && text.Substring(startIndex).IndexOf(str2) == 0) { startIndex += str2.Length; } string str3 = text.Substring(startIndex); string str4 = str3.IndexOf(str2) > -1 ? str3.Substring(0, str3.IndexOf(str2)) : str3.Substring(0, str3.Length); length = str4.Length > 0 ? str4.Length : -1; } }while (length > -1 && length < text.Length); return(str1.Trim()); })); } }
private async void paymentDebtBtn_Click(object sender, EventArgs e) { paymentDebtBtn.Enabled = false; Cliente customer = await Task.Run(() => new Cliente(this.employee.CustomerID)); if (customer.Debt <= 0.0) { return; } FormPagar form = new FormPagar("$" + customer.Debt.ToString("n2"), false, 0.0); //DarkForm darkForm = new DarkForm(); //darkForm.Show(); if (form.ShowDialog() == DialogResult.OK) { double customerPayment = Convert.ToDouble(form.Pay); double cash = Convert.ToDouble(form.Cash); if (customerPayment > 0.0) { DataTable acountsReceivable = customer.GetAcountsReceivable(); double change = cash <= customerPayment ? 0.0 : cash - customerPayment; for (int index = 0; index < acountsReceivable.Rows.Count; ++index) { DataRow row = acountsReceivable.Rows[index]; if (customerPayment > 0.0) { double cash1 = customerPayment - Convert.ToDouble(row["Resto"]) <= 0.0 ? customerPayment : Convert.ToDouble(row["Resto"]); customer.RegisterPayment(Convert.ToInt64(row["id_ventas"]), DateTime.Now, cash1, this.User_employeeID); customer.Pay(cash1, Convert.ToInt64(row["id_ventas"])); customerPayment -= cash1; } } FormCambio formCambio = new FormCambio(change); this.customerPaymentDocument = new PrintDocument(); customerPaymentDocument.PrintController = new StandardPrintController(); this.customerPaymentDocument.PrintPage += (PrintPageEventHandler)((ss, ee) => { Graphics graphics = ee.Graphics; var ticket = new PrinterTicket(); this.customerPaymentDocument.PrinterSettings.PrinterName = ticket.printerName; this.customerPaymentDocument.DefaultPageSettings.PaperSize = new PaperSize("Custom", 200, 200); int width = (int)this.printDialog1.PrinterSettings.DefaultPageSettings.PrintableArea.Width; int y1 = 0; Size stringSize = ticket.printLogo(graphics, y1); y1 = stringSize.Height == 0 ? y1 : y1 + stringSize.Height + 10; stringSize = ticket.printHeader(graphics, y1); y1 = stringSize.Height == 0 ? y1 : y1 + stringSize.Height + 10; stringSize = ticket.printAddress(graphics, y1); y1 = stringSize.Height == 0 ? y1 : y1 + stringSize.Height + 10; stringSize = ticket.printPhone(graphics, y1); y1 = stringSize.Height == 0 ? y1 : y1 + stringSize.Height + 10; y1 += printingClass.drawLine(10, width - 10, graphics, y1) + 5; string str = "Pago de Cliente"; Font font = new Font("times new roman", 17f, FontStyle.Bold);//this.getFont(str1, width, FontStyle.Regular); y1 += printingClass.printLine(str, font, width, StringAlignment.Center, ee.Graphics, y1) + 1; font = width > 200 ? new Font("Times new Roman", 9.9f) : new Font("Times new Roman", 7f); if (customer.ID != 0) { str = "Cliente: " + customer.Name; y1 += printingClass.printLine(str, font, width, StringAlignment.Near, ee.Graphics, y1) + 1; } str = string.Format("Fecha: {0} {1}", DateTime.Now.Date.ToShortDateString(), DateTime.Now.ToShortTimeString()); y1 += printingClass.printLine(str, font, width, StringAlignment.Near, graphics, y1); y1 += printingClass.drawLine(10, width - 10, graphics, y1) + 3; customerPayment = Convert.ToDouble(form.Pay); str = string.Format("Adeudo Previo: ${0}", (customer.Debt + customerPayment).ToString("n2")); y1 += printingClass.printLine(str, font, width, StringAlignment.Near, graphics, y1) + 1; str = string.Format("Monto a pagar: ${0}", customerPayment.ToString("n2")); y1 += printingClass.printLine(str, font, width, StringAlignment.Near, graphics, y1) + 1; str = string.Format("Adeudo Actualizado: ${0}", customer.Debt.ToString("n2")); y1 += printingClass.printLine(str, new Font("times new roman", 10f, FontStyle.Bold), width, StringAlignment.Near, graphics, y1); y1 += printingClass.drawLine(10, width - 10, graphics, y1) + 3; str = string.Format("Efectivo: ${0}", cash.ToString("n2")); y1 += printingClass.printLine(str, font, width, StringAlignment.Far, graphics, y1) + 1; str = string.Format("Cambio: ${0}", change.ToString("n2")); y1 += printingClass.printLine(str, font, width, StringAlignment.Far, graphics, y1) + 1; if (ticket.footerDisplay) { printingClass.printLine(ticket.footer, ticket.footerFont, width, StringAlignment.Center, graphics, y1); } }); try { this.customerPaymentDocument.PrinterSettings.PrinterName = this.printDialog1.PrinterSettings.PrinterName; this.printDialog1.Document = this.customerPaymentDocument; this.customerPaymentDocument.Print(); } catch (InvalidPrinterException ex) { int num = (int)MessageBox.Show("Registre una impresora para poder utilizar esta opción", "No se ha registrado impresora"); } int num10 = (int)formCambio.ShowDialog(); customer.RefreshInfo(); this.debtLbl.Text = "$" + customer.Debt.ToString("n2"); } else { int num11 = (int)MessageBox.Show("El Cliente no genera ningun adeudo"); } } paymentDebtBtn.Enabled = true; //darkForm.Close(); }
private async void endShiftBtn_Click(object sender, EventArgs e) { if (MessageBox.Show("¿Desea hacer el corte de caja?", "Corte de caja", MessageBoxButtons.YesNo) != DialogResult.Yes) { return; } endShiftBtn.Enabled = false; button1.Enabled = false; this.Cursor = Cursors.WaitCursor; DataTable dt = await Task.Run(() => Turno.endShift(this.employeeID)); this.printDocument1 = new PrintDocument(); printDocument1.PrintController = new StandardPrintController(); this.printDocument1.PrintPage += (ss, ee) => { DataRow row = dt.Rows[0]; PrinterTicket printerTicket = new PrinterTicket(); this.printDocument1.PrinterSettings.PrinterName = printerTicket.printerName; Graphics graphics = ee.Graphics; graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; int width = (int)this.printDialog1.PrinterSettings.DefaultPageSettings.PrintableArea.Width; //this.printDocument1.DefaultPageSettings.PaperSize.Width; int y = 0; if (printerTicket.logoDisplay && printerTicket.logo != null) { Bitmap bitmap = printerTicket.logo != null ? new Bitmap(printerTicket.logo, width, printerTicket.logoHeight) : (Bitmap)null; bitmap.SetResolution((float)width, (float)printerTicket.logoHeight); graphics.DrawImage((Image)bitmap, 0, y, width, printerTicket.logoHeight); y += printerTicket.logoHeight + 10; } if (printerTicket.headderDisplay) { y += printingClass.printLine(printerTicket.header, printerTicket.headerFont, width, StringAlignment.Center, graphics, y) + 1; } string str = "Corte de Caja"; Font font = new Font("times new roman", 18f, FontStyle.Bold); y += printingClass.printLine(str, font, width, StringAlignment.Center, graphics, y) + 1; var startingTime = Turno.startingDate; str = string.Format("Periodo del Turno: {0} {1} - {2} {3}", startingTime.Date.ToShortDateString(), startingTime.ToShortTimeString(), DateTime.Now.Date.ToShortDateString(), DateTime.Now.ToShortTimeString()); font = width > 200 ? new Font("Times new Roman", 9.9f, FontStyle.Bold) : new Font("Times new Roman", 7f, FontStyle.Bold); y += printingClass.printLine(str, font, width, StringAlignment.Near, graphics, y) + 3; str = "Comenzó el turno: " + new Empleado(Convert.ToInt32(row["Empleado que Inició"])).name; y += printingClass.printLine(str, font, width, StringAlignment.Near, graphics, y) + 1; str = "Realizó corte de caja: " + new Empleado(this.employeeID).name; y += printingClass.printLine(str, font, width, StringAlignment.Near, graphics, y) + 15; for (int index = 0; index < 9; ++index) { font = width > 200 ? new Font("Times new Roman", 9.9f) : new Font("Times new Roman", 7f); str = dt.Columns[index].ColumnName; y += printingClass.printLine(str, font, width, StringAlignment.Near, graphics, y) + 1; font = width > 200 ? new Font("Times new Roman", 9.9f, FontStyle.Bold) : new Font("Times new Roman", 7f, FontStyle.Bold); str = row[index].ToString(); str = index > 0 ? str.Substring(1) : str; str = Convert.ToDouble(str) > 0.0 ? string.Format("{0}", row[index]) : string.Format("{0}", row[index]); y += printingClass.printLine(str, font, width, StringAlignment.Near, graphics, y) + 5; } }; this.endShiftBtn.Hide(); this.button2.Show(); DarkForm darkForm = new DarkForm(); panelInicio_finDeTurno inicioFinDeTurno = new panelInicio_finDeTurno(Convert.ToDouble(dt.Rows[0]["Efectivo a Entregar"].ToString().Substring(1))); darkForm.Show(); try { this.printDocument1.PrinterSettings.PrinterName = this.printDialog1.PrinterSettings.PrinterName; this.printDialog1.Document = this.printDocument1; this.printDocument1.Print(); } catch (InvalidPrinterException) { MessageBox.Show("Registre una impresora para poder utilizar esta opción", "No se ha registrado impresora"); } inicioFinDeTurno.ShowDialog(); darkForm.Close(); this.Cursor = Cursors.Default; }
private void centerToTicket(Control control) { Control parent = control.Parent; control.Location = new Point((parent.Width - PrinterTicket.getStringSize(control.Text, control.Font).Width) / 2, control.Location.Y); }