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 button1_Click(object sender, EventArgs e) { if (!Turno.shiftActive) { return; } DarkForm darkForm = new DarkForm(); Form_Login formLogin = new Form_Login(string.Format("Verificación De\nUsuario")); FormShiftAddMoney formShiftAddMoney = new FormShiftAddMoney(); darkForm.Show(); formLogin.ShowDialog(); Empleado empleado = new Empleado(formLogin.ID); if (formLogin.DialogResult == DialogResult.OK && empleado.isAdmin) { if (formShiftAddMoney.ShowDialog() == DialogResult.OK) { //<<< step1 >>> --Start //When outputting to a printer,a mouse cursor becomes like a hourglass. try { if (m_Drawer != null) { //Open the device //Use a Logical Device Name which has been set on the SetupPOS. m_Drawer.Open(); //Get the exclusive control right for the opened device. //Then the device is disable from other application. m_Drawer.Claim(1000); //Enable the device. m_Drawer.DeviceEnabled = true; //Open the drawer by using the "OpenDrawer" method. m_Drawer.OpenDrawer(); m_Drawer.DeviceEnabled = false; m_Drawer.Release(); m_Drawer.Close(); } else { useDefaultPrinter(); } } catch (Exception) { if (m_Drawer != null) { m_Drawer.Release(); m_Drawer.Close(); } useDefaultPrinter(); } //<<<step1>>>--End Turno.AddCashToDrawer(empleado.ID, formShiftAddMoney.cash, formShiftAddMoney.reason); MessageBox.Show("Se realizó correctamente"); this.setGroupBoxInfo(); } } else if (formLogin.DialogResult == DialogResult.OK && !empleado.isAdmin && formLogin.ID > -1) { MessageBox.Show("No tiene los permisos necesarios para realizar esta acción"); } darkForm.Close(); }
private void setGroupBoxInfo() { this.groupBox1.Visible = Turno.shiftActive; this.groupBox1.Text = "Inicio de Turno: " + Turno.startingDate.ToString(); this.dataGridView1.DataSource = (object)Turno.MoneyAddedToDrawer(); }