private void btnPrint_Click(object sender, EventArgs e) { gcOptions.Visible = false; using (System.Drawing.Printing.PrintDocument printDocument = new System.Drawing.Printing.PrintDocument()) { printDocument.PrintPage += printDocument_PrintPage; printDocument.DefaultPageSettings.Landscape = true; printDocument.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("FalseX", 500, 1000); //Resize Size = new Size(974, 507); CaptureScreen(); try { //printDocument.Print(); PrintPreviewDialog PPdlg = new PrintPreviewDialog() { Document = printDocument }; PPdlg.Show(); } catch (Exception ex) { Program.ShowMsg(ex.Message, true, this); Program.Logger.LogThis(null, Text, FXFW.Logger.OpType.fail, ex, null, this); } } Size = new Size(974, 589); gcOptions.Visible = true; }
/// <summary> /// Shows a PrintPreview dialog displaying the Tree control passed in. /// </summary> /// <param name="tree">TreeView to print preview</param> /// <param name="reportTitle"></param> public void PrintPreviewTree(TreeView tree, string reportTitle) { this.title = reportTitle; this.PrepareTreeImage(tree); var pp = new PrintPreviewDialog { Document = this.printDoc }; pp.Show(); }
public void PrintReport(DataGridView dGrid) { this.dGrid = dGrid; pDoc = new PrintDocument(); pDoc.PrintPage += new PrintPageEventHandler(pDoc_PrintPage); pPreviewDialog = new PrintPreviewDialog(); pPreviewDialog.Document = pDoc; pPreviewDialog.Show(); pDoc.Print(); }
// Um para imprimir aqui estou usando o sistema de impressão basico do .Net private void btnImprimir_Click(object sender, EventArgs e) { // criando um documento de impressão // para que eu mande os objeto serem renderizados neste. PrintDocument pDoc = new PrintDocument(); PrintPreviewDialog ppw = new PrintPreviewDialog(); pDoc.PrintPage += new PrintPageEventHandler(pDoc_PrintPage); ppw.Document = pDoc; ppw.MdiParent = this.MdiParent; ppw.WindowState = FormWindowState.Maximized; ppw.Show(); }
public static void PrintPreview(IPrintable printable) { using (PrintDocument pdoc = printable.PrintDocument) { if (pdoc != null) { PrintPreviewDialog ppd = new PrintPreviewDialog(); ppd.TopMost = true; ppd.Document = pdoc; ppd.Show(WorkbenchSingleton.MainWin32Window); } else { MessageService.ShowError("${res:ICSharpCode.SharpDevelop.Commands.Print.CreatePrintDocumentError}"); } } }
/*------------------------------------------*/ void Button1Click(object sender, EventArgs e) { _dataSet.Clear(); _dataSet.DataSetName = "journal"; _mySQL.SelectSqlCommand = "SELECT * FROM journal WHERE (journal_date BETWEEN '" + dateTimePicker1.Text + "' AND '" + dateTimePicker2.Text + "' AND journal_firm_seller = '" + textBox3.Text + "' AND journal_type = 'Приходная Накладная' AND journal_delete = 0)"; if(_mySQL.ExecuteFill(_dataSet, "journal")){ // ФОРМИРУЕМ ОТЧЁТ PrintPreviewDialog ppd = new PrintPreviewDialog(); ppd.Document = printDocument1; ppd.MdiParent = ClassForms.Rapid_Client; ppd.Show(); }else ClassForms.Rapid_Client.MessageConsole("Отчёт Оборотная ведомость по торг. представителю: Ошибка вывода информации.", true); }
void Button1Click(object sender, EventArgs e) { _dataSet.Clear(); _dataSet.DataSetName = "operations"; _mySQL.SelectSqlCommand = "SELECT operations.*, journal.* FROM operations, journal WHERE (operations_date BETWEEN '" + dateTimePicker1.Text + "' AND '" + dateTimePicker2.Text + "' AND (operations_DT = " + textBox3.Text + " OR operations_KT = " + textBox3.Text + ") AND (journal.journal_id_doc = operations.operations_id_doc)) ORDER BY operations_date ASC"; if(_mySQL.ExecuteFill(_dataSet, "operations")){ // ФОРМИРУЕМ ОТЧЁТ PrintPreviewDialog ppd = new PrintPreviewDialog(); ppd.Document = printDocument1; ppd.MdiParent = ClassForms.Rapid_Client; ppd.Show(); }else ClassForms.Rapid_Client.MessageConsole("Отчёт Оборотная ведомость по счёту: Ошибка вывода информации.", true); }
void Button1Click(object sender, EventArgs e) { _dataSet.Clear(); _dataSet.DataSetName = "balance"; if(checkBox1.Checked){ _mySQL.SelectSqlCommand = "SELECT * FROM balance ORDER BY balance_tmc ASC"; }else _mySQL.SelectSqlCommand = "SELECT * FROM balance WHERE (balance_date BETWEEN '" + dateTimePicker1.Text + "' AND '" + dateTimePicker2.Text + "') ORDER BY balance_tmc ASC"; if(_mySQL.ExecuteFill(_dataSet, "balance")){ // ФОРМИРУЕМ ОТЧЁТ PrintPreviewDialog ppd = new PrintPreviewDialog(); ppd.Document = printDocument1; ppd.MdiParent = ClassForms.Rapid_Client; ppd.Show(); }else ClassForms.Rapid_Client.MessageConsole("Отчёт Остатки ТМЦ: Ошибка вывода информации.", true); }
public override void Run() { try { IWorkbenchWindow window = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow; if (window != null) { if (window.ViewContent is IPrintable) { using (PrintDocument pdoc = ((IPrintable)window.ViewContent).PrintDocument) { if (pdoc != null) { PrintPreviewDialog ppd = new PrintPreviewDialog(); ppd.Owner = (Form)WorkbenchSingleton.Workbench; ppd.TopMost = true; ppd.Document = pdoc; ppd.Show(); } else { MessageService.ShowError("${res:ICSharpCode.SharpDevelop.Commands.Print.CreatePrintDocumentError}"); } } } } } catch (InvalidPrinterException) {} }
private void toolStripPrintLittleEnv_Click(object sender, EventArgs e) { print_doc = new PrintDocument(); print_doc.PrintPage += delegate(object o, PrintPageEventArgs pe) { using (SolidBrush brush = new SolidBrush(Color.Black)) { using (Font font = new Font("Tahoma", 12f)) { int line_start = 140; int line_height = (font.Height * 2) - 5; int line_multi = 0; pe.Graphics.DrawString("กรุณาส่ง", font, brush, new Point(190, line_start)); pe.Graphics.DrawString(this.dealer.contact, font, brush, new Point(280, line_start + (line_height * ++line_multi))); pe.Graphics.DrawString((this.dealer.prenam.Length > 0 ? this.dealer.prenam + " " + this.dealer.compnam : this.dealer.compnam), font, brush, new Point(280, line_start + (line_height * ++line_multi))); pe.Graphics.DrawString(this.dealer.addr01, font, brush, new Point(280, line_start + (line_height * ++line_multi))); pe.Graphics.DrawString(this.dealer.addr02 + " " + this.dealer.addr03, font, brush, new Point(280, line_start + (line_height * ++line_multi))); pe.Graphics.DrawString(this.dealer.zipcod, font, brush, new Point(280, line_start + (line_height * ++line_multi))); } } }; PageSetupDialog page_setup = new PageSetupDialog(); page_setup.Document = this.print_doc; page_setup.PageSettings.PaperSize = new PaperSize("Little Envelope", 910, 425); PrintOutputSelection wind = new PrintOutputSelection(); if (wind.ShowDialog() == DialogResult.OK) { if (wind.output == PrintOutputSelection.OUTPUT.PRINTER) { PrintDialog print_dialog = new PrintDialog(); print_dialog.Document = this.print_doc; print_dialog.AllowSelection = false; print_dialog.AllowSomePages = false; print_dialog.AllowPrintToFile = false; print_dialog.AllowCurrentPage = false; print_dialog.UseEXDialog = true; if (print_dialog.ShowDialog() == DialogResult.OK) { print_doc.Print(); } } if (wind.output == PrintOutputSelection.OUTPUT.SCREEN) { PrintPreviewDialog preview_dialog = new PrintPreviewDialog(); preview_dialog.Document = this.print_doc; preview_dialog.MdiParent = this.main_form; preview_dialog.Show(); } if (wind.output == PrintOutputSelection.OUTPUT.FILE) { } } else { print_doc = null; page_setup = null; } }
private void toolStripPrintLabel3Col_Click(object sender, EventArgs e) { print_doc = new PrintDocument(); PageSetupDialog page_setup = new PageSetupDialog(); page_setup.Document = this.print_doc; //page_setup.PageSettings.PaperSize = new PaperSize("Sticker 2 column", 825, 1165); page_setup.PageSettings.PaperSize = new PaperSize("Sticker 3 column", 1250, 1195); page_setup.PageSettings.Margins = new Margins(0, 0, 0, 0); PrintDealerLabelOutputSelection wind = new PrintDealerLabelOutputSelection(this.main_form); wind.txtFrom.Text = this.dealer.dealer; wind.txtTo.Text = this.dealer.dealer; if (wind.ShowDialog() == DialogResult.OK) { int row_num = 0; int page_count = 0; List<Dealer> list_dealer = new List<Dealer>(); print_doc.BeginPrint += delegate(object o, PrintEventArgs pe) { string json_data = "{\"dealer_from\":\"" + wind.dealer_from + "\","; json_data += "\"dealer_to\":\"" + wind.dealer_to + "\","; json_data += "\"condition\":\"" + wind.condition + "\"}"; CRUDResult get = ApiActions.POST(PreferenceForm.API_MAIN_URL() + "dealer/get_for_print_label", json_data); ServerResult sr = JsonConvert.DeserializeObject<ServerResult>(get.data); if (sr.result == ServerResult.SERVER_RESULT_SUCCESS) { if (sr.dealer.Count > 0) { list_dealer = sr.dealer; } else { MessageAlert.Show(StringResource.NO_DATA_IN_RANGE, "Error", MessageAlertButtons.OK, MessageAlertIcons.ERROR); return; } } else { MessageAlert.Show(sr.message, "Error", MessageAlertButtons.OK, MessageAlertIcons.ERROR); return; } row_num = 0; page_count = 0; }; print_doc.PrintPage += delegate(object o, PrintPageEventArgs pe) { using (Font font = new Font("Tahoma", 9.75f)) { using (SolidBrush brush = new SolidBrush(Color.Black)) { //int max_col = 2; // for sticker 2 column int max_col = 3; // for sticker 3 column int col_count = 0; int col_width = 413; int line_count = 0; int line_height = 25; int block_count = 1; // store row number of sticker int block_height = line_height * 4; int block_margin_top = 25; int block_margin_bottom = 25; page_count++; int page_row_count = 0; for (int i = row_num; i < list_dealer.Count; i++) { row_num++; col_count++; page_row_count++; if (page_row_count > 1 && i % max_col == 0) { col_count = 1; ++block_count; } int contact_x = 30 + (col_count * col_width) - col_width; int contact_y = ((block_count == 1 ? block_margin_top : (block_margin_top + block_margin_bottom) * (block_count - 1))) + ((block_count * block_height) - block_height) + (++line_count * line_height) - line_height; if (col_count == 1 && Math.Ceiling(Convert.ToDouble(page_row_count / max_col)) * block_height + (block_count * (block_margin_top + block_margin_bottom)) > pe.MarginBounds.Bottom) { pe.HasMorePages = true; page_row_count = 0; block_count = 1; row_num--; return; } else { pe.HasMorePages = false; } pe.Graphics.DrawString("ส่ง", font, brush, new Point(contact_x - 30, contact_y)); pe.Graphics.DrawString(list_dealer[i].contact, font, brush, new Point(contact_x, contact_y)); int name_x = 30 + (col_count * col_width) - col_width; int name_y = ((block_count == 1 ? block_margin_top : (block_margin_top + block_margin_bottom) * (block_count - 1))) + ((block_count * block_height) - block_height) + (++line_count * line_height) - line_height; pe.Graphics.DrawString(list_dealer[i].prenam + " " + list_dealer[i].compnam, font, brush, new Point(name_x, name_y)); int addr01_x = 30 + (col_count * col_width) - col_width; int addr01_y = ((block_count == 1 ? block_margin_top : (block_margin_top + block_margin_bottom) * (block_count - 1))) + ((block_count * block_height) - block_height) + (++line_count * line_height) - line_height; pe.Graphics.DrawString(list_dealer[i].addr01, font, brush, new Point(addr01_x, addr01_y)); int addr02_x = 30 + (col_count * col_width) - col_width; int addr02_y = ((block_count == 1 ? block_margin_top : (block_margin_top + block_margin_bottom) * (block_count - 1))) + ((block_count * block_height) - block_height) + (++line_count * line_height) - line_height; pe.Graphics.DrawString(list_dealer[i].addr02 + " " + list_dealer[i].addr03 + " " + list_dealer[i].zipcod, font, brush, new Point(addr02_x, addr02_y)); line_count = 0; } } } }; if (wind.output == PrintDealerLabelOutputSelection.OUTPUT.PRINTER) { PrintDialog print_dialog = new PrintDialog(); print_dialog.Document = this.print_doc; print_dialog.AllowSelection = false; print_dialog.AllowSomePages = false; print_dialog.AllowPrintToFile = false; print_dialog.AllowCurrentPage = false; print_dialog.UseEXDialog = true; if (print_dialog.ShowDialog() == DialogResult.OK) { print_doc.Print(); } } if (wind.output == PrintDealerLabelOutputSelection.OUTPUT.SCREEN) { PrintPreviewDialog preview_dialog = new PrintPreviewDialog(); preview_dialog.Document = this.print_doc; preview_dialog.MdiParent = this.main_form; preview_dialog.Show(); } if (wind.output == PrintDealerLabelOutputSelection.OUTPUT.FILE) { } } else { print_doc = null; page_setup = null; } }
private void toolStripPrint_Click(object sender, EventArgs e) { this.GetNote(); PrintDocument print_doc = new PrintDocument(); PageSetupDialog page_setup = new PageSetupDialog(); page_setup.Document = print_doc; page_setup.PageSettings.PaperSize = new PaperSize("A4", 825, 1165); page_setup.PageSettings.Landscape = true; page_setup.PageSettings.Margins = new Margins(20, 20, 10, 25); PrintOutputSelection print_out = new PrintOutputSelection(); if (print_out.ShowDialog() == DialogResult.OK) { int row_num = 0; int page_num = 0; int x = 0; print_doc.BeginPrint += delegate(object s, PrintEventArgs pe) { row_num = 0; page_num = 0; }; print_doc.PrintPage += delegate(object s, PrintPageEventArgs pe) { int x_pos = pe.MarginBounds.Left; int y_pos = pe.MarginBounds.Top; #region declare column width & cell padding int cell_padding = 3; int col1 = 30; // seq. int col2 = 55; // start_time int col3 = 55; // end_time int col4 = 55; // duration int col5 = 80; // S/N int col6 = 90; // name int col7 = 30; // map drive int col8 = 30; // ins./up int col9 = 30; // error int col10 = 30; // ins. fonts int col11 = 30; // printer int col12 = 30; // training int col13 = 30; // stock int col14 = 30; // form int col15 = 30; // report -> excel int col16 = 30; // balance sheet/statement int col17 = 30; // assets int col18 = 30; // secure int col19 = 30; // year end int col20 = 30; // period int col21 = 30; // mail/wait int col22 = 30; // transfer -> mkt. int col23 = 280; // other/remark #endregion declare column width bool is_new_page = true; page_num++; if (is_new_page) // print report header { #region Print report header StringFormat str_format_center = new StringFormat() { //FormatFlags = StringFormatFlags.LineLimit | StringFormatFlags.NoWrap, //Trimming = StringTrimming.None, Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }; StringFormat str_format_right = new StringFormat() { //FormatFlags = StringFormatFlags.LineLimit | StringFormatFlags.NoWrap, //Trimming = StringTrimming.None, Alignment = StringAlignment.Far, LineAlignment = StringAlignment.Center }; StringFormat str_format_left = new StringFormat() { //FormatFlags = StringFormatFlags.LineLimit | StringFormatFlags.NoWrap, //Trimming = StringTrimming.None, Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center }; // Report header using (Font font = new Font("tahoma", 15f)) { using (SolidBrush brush = new SolidBrush(Color.Black)) { SizeF box_size = pe.Graphics.MeasureString("บันทึกการปฏิบัติงาน", font); pe.Graphics.DrawString("บันทึกการปฏิบัติงาน", font, brush, new RectangleF(x_pos, y_pos, x_pos + pe.MarginBounds.Right - x_pos, box_size.Height), str_format_center); } } using (Font font = new Font("tahoma", 12f)) { using (SolidBrush brush = new SolidBrush(Color.Black)) { SizeF box_date = pe.Graphics.MeasureString("วันที่ " + this.dtWorkDate.Texts, font); pe.Graphics.DrawString("วันที่ " + this.dtWorkDate.Texts, font, brush, new RectangleF(x_pos, y_pos, box_date.Width, box_date.Height)); pe.Graphics.DrawLine(new Pen(Color.Black), x_pos + pe.Graphics.MeasureString("วันที่ ", font).Width, y_pos + box_date.Height, x_pos + box_date.Width, y_pos + box_date.Height); SizeF box_user = pe.Graphics.MeasureString("รหัสพนักงาน : " + ((Users)((ComboboxItem)this.cbUsersCode.SelectedItem).Tag).username, font); pe.Graphics.DrawString("รหัสพนักงาน : " + ((Users)((ComboboxItem)this.cbUsersCode.SelectedItem).Tag).username, font, brush, new RectangleF(pe.MarginBounds.Right - box_user.Width, y_pos, box_user.Width, box_user.Height)); pe.Graphics.DrawLine(new Pen(Color.Black), (pe.MarginBounds.Right - box_user.Width) + pe.Graphics.MeasureString("รหัสพนักงาน : ", font).Width, y_pos + box_user.Height, pe.MarginBounds.Right, y_pos + box_user.Height); } } y_pos += 30; using (Font font = new Font("tahoma", 8f)) { using (SolidBrush brush = new SolidBrush(Color.Black)) { SizeF box_size = pe.Graphics.MeasureString("หน้า " + page_num.ToString(), font); pe.Graphics.DrawString("หน้า " + page_num.ToString(), font, brush, new RectangleF(pe.MarginBounds.Right - box_size.Width, y_pos, box_size.Width, box_size.Height)); } } y_pos += 20; // Column header using (SolidBrush brush_bg = new SolidBrush(Color.LightBlue)) { int column_header_height = 35; pe.Graphics.FillRectangle(brush_bg, new Rectangle(x_pos, y_pos, pe.MarginBounds.Right - x_pos, column_header_height)); using (Pen p = new Pen(Color.DarkGray)) { pe.Graphics.DrawLine(p, x_pos, y_pos, pe.MarginBounds.Right, y_pos); // horizontal upper line pe.Graphics.DrawLine(p, x_pos, y_pos, x_pos, y_pos + column_header_height); pe.Graphics.DrawLine(p, x_pos += col1, y_pos, x_pos, y_pos + column_header_height); pe.Graphics.DrawLine(p, x_pos += col2, y_pos, x_pos, y_pos + column_header_height); pe.Graphics.DrawLine(p, x_pos += col3, y_pos, x_pos, y_pos + column_header_height); pe.Graphics.DrawLine(p, x_pos += col4, y_pos, x_pos, y_pos + column_header_height); pe.Graphics.DrawLine(p, x_pos += col5, y_pos, x_pos, y_pos + column_header_height); pe.Graphics.DrawLine(p, x_pos += col6, y_pos, x_pos, y_pos + column_header_height); pe.Graphics.DrawLine(p, x_pos += col7, y_pos, x_pos, y_pos + column_header_height); pe.Graphics.DrawLine(p, x_pos += col8, y_pos, x_pos, y_pos + column_header_height); pe.Graphics.DrawLine(p, x_pos += col9, y_pos, x_pos, y_pos + column_header_height); pe.Graphics.DrawLine(p, x_pos += col10, y_pos, x_pos, y_pos + column_header_height); pe.Graphics.DrawLine(p, x_pos += col11, y_pos, x_pos, y_pos + column_header_height); pe.Graphics.DrawLine(p, x_pos += col12, y_pos, x_pos, y_pos + column_header_height); pe.Graphics.DrawLine(p, x_pos += col13, y_pos, x_pos, y_pos + column_header_height); pe.Graphics.DrawLine(p, x_pos += col14, y_pos, x_pos, y_pos + column_header_height); pe.Graphics.DrawLine(p, x_pos += col15, y_pos, x_pos, y_pos + column_header_height); pe.Graphics.DrawLine(p, x_pos += col16, y_pos, x_pos, y_pos + column_header_height); pe.Graphics.DrawLine(p, x_pos += col17, y_pos, x_pos, y_pos + column_header_height); pe.Graphics.DrawLine(p, x_pos += col18, y_pos, x_pos, y_pos + column_header_height); pe.Graphics.DrawLine(p, x_pos += col19, y_pos, x_pos, y_pos + column_header_height); pe.Graphics.DrawLine(p, x_pos += col20, y_pos, x_pos, y_pos + column_header_height); pe.Graphics.DrawLine(p, x_pos += col21, y_pos, x_pos, y_pos + column_header_height); pe.Graphics.DrawLine(p, x_pos += col22, y_pos, x_pos, y_pos + column_header_height); pe.Graphics.DrawLine(p, x_pos += col23, y_pos, x_pos, y_pos + column_header_height); x_pos = pe.MarginBounds.Left; pe.Graphics.DrawLine(p, x_pos, y_pos + column_header_height, pe.MarginBounds.Right, y_pos + column_header_height); // horizontal lower line using (Font font = new Font("tahoma", 6f)) { using (SolidBrush brush = new SolidBrush(Color.Black)) { pe.Graphics.DrawString("ลำดับ", font, brush, new RectangleF(x_pos, y_pos, col1, column_header_height), str_format_center); pe.Graphics.DrawString("รับสาย", font, brush, new RectangleF(x_pos += col1, y_pos, col2, column_header_height), str_format_center); pe.Graphics.DrawString("วางสาย", font, brush, new RectangleF(x_pos += col2, y_pos, col3, column_header_height), str_format_center); pe.Graphics.DrawString("ระยะเวลา", font, brush, new RectangleF(x_pos += col3, y_pos, col4, column_header_height), str_format_center); pe.Graphics.DrawString("S/N", font, brush, new RectangleF(x_pos += col4, y_pos, col5, column_header_height), str_format_center); pe.Graphics.DrawString("ชื่อลูกค้า", font, brush, new RectangleF(x_pos += col5, y_pos, col6, column_header_height), str_format_center); pe.Graphics.DrawString("Map Drive", font, brush, new RectangleF(x_pos += col6, y_pos, col7, column_header_height), str_format_center); pe.Graphics.DrawString("Ins./ Up", font, brush, new RectangleF(x_pos += col7, y_pos, col8, column_header_height), str_format_center); pe.Graphics.DrawString("Error", font, brush, new RectangleF(x_pos += col8, y_pos, col9, column_header_height), str_format_center); pe.Graphics.DrawString("Ins. Fonts", font, brush, new RectangleF(x_pos += col9, y_pos, col10, column_header_height), str_format_center); pe.Graphics.DrawString("Print", font, brush, new RectangleF(x_pos += col10, y_pos, col11, column_header_height), str_format_center); pe.Graphics.DrawString("อบรม", font, brush, new RectangleF(x_pos += col11, y_pos, col12, column_header_height), str_format_center); pe.Graphics.DrawString("สินค้า", font, brush, new RectangleF(x_pos += col12, y_pos, col13, column_header_height), str_format_center); pe.Graphics.DrawString("Form/Rep.", font, brush, new RectangleF(x_pos += col13, y_pos, col14, column_header_height), str_format_center); pe.Graphics.DrawString("Report ->XLS", font, brush, new RectangleF(x_pos += col14, y_pos, col15, column_header_height), str_format_center); pe.Graphics.DrawString("สร้างงบฯ", font, brush, new RectangleF(x_pos += col15, y_pos, col16, column_header_height), str_format_center); pe.Graphics.DrawString("ท/ส ค่าเสื่อม", font, brush, new RectangleF(x_pos += col16, y_pos, col17, column_header_height), str_format_center); pe.Graphics.DrawString("Secure", font, brush, new RectangleF(x_pos += col17, y_pos, col18, column_header_height), str_format_center); pe.Graphics.DrawString("Year End", font, brush, new RectangleF(x_pos += col18, y_pos, col19, column_header_height), str_format_center); pe.Graphics.DrawString("วันที่ไม่อยู่ในงวด", font, brush, new RectangleF(x_pos += col19, y_pos, col20, column_header_height), str_format_center); pe.Graphics.DrawString("Mail/รอสาย", font, brush, new RectangleF(x_pos += col20, y_pos, col21, column_header_height), str_format_center); pe.Graphics.DrawString("โอนฝ่ายขาย", font, brush, new RectangleF(x_pos += col21, y_pos, col22, column_header_height), str_format_center); pe.Graphics.DrawString("ปัญหาอื่น ๆ", font, brush, new RectangleF(x_pos += col22, y_pos, col23, column_header_height), str_format_center); } } } } y_pos += 15; #endregion Print report header } #region Print data row using (StringFormat str_center = new StringFormat() { FormatFlags = StringFormatFlags.LineLimit | StringFormatFlags.NoWrap, Trimming = StringTrimming.None, Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center, }) { using (StringFormat str_left = new StringFormat(){ FormatFlags = StringFormatFlags.LineLimit | StringFormatFlags.NoWrap, Trimming = StringTrimming.None, Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center }) { using (StringFormat str_right = new StringFormat(){ FormatFlags = StringFormatFlags.LineLimit | StringFormatFlags.NoWrap, Trimming = StringTrimming.None, Alignment = StringAlignment.Far, LineAlignment = StringAlignment.Center }) { int line_height = 20; for (int i = row_num; i < this.dgvNote.Rows.Count; i++) { DataGridViewRow row = this.dgvNote.Rows[i]; x_pos = pe.MarginBounds.Left; y_pos += line_height; if (y_pos > pe.MarginBounds.Bottom - line_height) { pe.Graphics.DrawLine(new Pen(Color.LightGray), x_pos, y_pos, pe.MarginBounds.Right, y_pos); pe.HasMorePages = true; return; } else { pe.HasMorePages = false; } if (row_num % 2 != 0) { using (SolidBrush brush = new SolidBrush(Color.Lavender)) { pe.Graphics.FillRectangle(brush, x_pos, y_pos, pe.MarginBounds.Right - x_pos, line_height); } } using (Font font = new Font("tahoma", 8f)) { using (SolidBrush brush = new SolidBrush(Color.Black)) { using (Pen p = new Pen(Color.DarkGray)) { pe.Graphics.DrawLine(p, x_pos, y_pos - 10, x_pos, y_pos + 20); pe.Graphics.DrawString((string)row.Cells[1].Value, font, brush, new RectangleF(x_pos, y_pos, col1 - cell_padding, line_height), str_right); x_pos += col1; pe.Graphics.DrawLine(p, x_pos, y_pos - 10, x_pos, y_pos + 20); pe.Graphics.DrawString((string)row.Cells[4].Value, font, brush, new RectangleF(x_pos, y_pos, col2, line_height), str_center); x_pos += col2; pe.Graphics.DrawLine(p, x_pos, y_pos - 10, x_pos, y_pos + 20); pe.Graphics.DrawString((string)row.Cells[5].Value, font, brush, new RectangleF(x_pos, y_pos, col3, line_height), str_center); x_pos += col3; pe.Graphics.DrawLine(p, x_pos, y_pos - 10, x_pos, y_pos + 20); pe.Graphics.DrawString((string)row.Cells[6].Value, font, brush, new RectangleF(x_pos, y_pos, col4, line_height), str_center); x_pos += col4; pe.Graphics.DrawLine(p, x_pos, y_pos - 10, x_pos, y_pos + 20); pe.Graphics.DrawString((string)row.Cells[7].Value, font, brush, new RectangleF(x_pos + cell_padding, y_pos, col5 - cell_padding, line_height), str_left); x_pos += col5; pe.Graphics.DrawLine(p, x_pos, y_pos - 10, x_pos, y_pos + 20); pe.Graphics.DrawString((string)row.Cells[8].Value, font, brush, new RectangleF(x_pos + cell_padding, y_pos, col6 - cell_padding, line_height), str_left); x_pos += col6; using (Font wingdings_font = new Font("wingdings", 8f)) { for (int c = 9; c <= 24; c++) { pe.Graphics.DrawLine(p, x_pos, y_pos - 10, x_pos, y_pos + 20); if (((string)row.Cells[c].Value).Length > 0) { pe.Graphics.DrawString(((char)(byte)0xFC).ToString(), wingdings_font, brush, new RectangleF(x_pos, y_pos, col7, line_height), str_center); } x_pos += col7; } } pe.Graphics.DrawLine(p, x_pos, y_pos - 10, x_pos, y_pos + 20); pe.Graphics.DrawString((string)row.Cells[25].Value, font, brush, new RectangleF(x_pos + cell_padding, y_pos, col23 - cell_padding, line_height), str_left); x_pos += col23; pe.Graphics.DrawLine(p, x_pos, y_pos - 10, x_pos, y_pos + 20); } } } row_num++; } x_pos = pe.MarginBounds.Left; y_pos += line_height; pe.Graphics.DrawLine(new Pen(Color.LightGray), x_pos, y_pos, pe.MarginBounds.Right, y_pos); } } } #endregion Print data row }; if (print_out.output == PrintOutputSelection.OUTPUT.SCREEN) { PrintPreviewDialog preview_dialog = new PrintPreviewDialog(); preview_dialog.SetBounds(this.ClientRectangle.X + 5, this.ClientRectangle.Y + 5, this.ClientRectangle.Width - 10, this.ClientRectangle.Height - 10); preview_dialog.Document = print_doc; preview_dialog.MdiParent = this.main_form; preview_dialog.Show(); } if (print_out.output == PrintOutputSelection.OUTPUT.PRINTER) { PrintDialog print_dialog = new PrintDialog(); print_dialog.Document = print_doc; print_dialog.AllowSelection = false; print_dialog.AllowSomePages = false; print_dialog.AllowPrintToFile = false; print_dialog.AllowCurrentPage = false; print_dialog.UseEXDialog = true; if (print_dialog.ShowDialog() == DialogResult.OK) { print_doc.Print(); } } print_doc = null; page_setup = null; } else { print_doc = null; page_setup = null; } }
private void PreviewProc(object state) { try { PrintDocument document = (PrintDocument)state; _previewDialog = new PrintPreviewDialog(); _previewDialog.Text = "DICOM Print Preview"; _previewDialog.ShowInTaskbar = true; _previewDialog.WindowState = FormWindowState.Maximized; _previewDialog.Document = document; _previewDialog.FormClosed += delegate(object sender, FormClosedEventArgs e) { _previewDialog = null; }; _previewDialog.Show(Application.OpenForms[0]); _previewDialog.BringToFront(); _previewDialog.Focus(); } catch (Exception ex) { #if DEBUG Dicom.Debug.Log.Error("DICOM Print Error: " + ex.ToString()); #else Dicom.Debug.Log.Error("DICOM Print Error: " + ex.Message); #endif } }
private void choiButton1_Click(object sender, EventArgs e) { try { this.CaptureScreen(); PrintPreviewDialog printPreviewDialog1 = new PrintPreviewDialog(); PrintDocument printDocumnet1 = new PrintDocument(); printDocumnet1.PrintPage += new PrintPageEventHandler(this.printDocument1_PrintPage); printPreviewDialog1.Document = printDocumnet1; printPreviewDialog1.Show(this); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void printPreviewToolStripMenuItem_Click(object sender, EventArgs e) { hashesToPrint = new Queue<string>(duplicateHashes); conflictNumber = 0; this.firstPage = true; PrintPreviewDialog printPreviewDialog = new PrintPreviewDialog(); printPreviewDialog.Document = printDocument1; printPreviewDialog.Show(); }
private void PrintPreview() { PrintPreviewDialog previewDialog = new PrintPreviewDialog(); PrintDocument doc = new PrintDocument(); doc.PrintPage += new PrintPageEventHandler(CreatePage); previewDialog.Document = doc; previewDialog.Show(); }
private void toolStripPrint_Click(object sender, EventArgs e) { // Creating a List of print content List<object> content = new List<object>(); foreach (Note n in this.note_list) { content.Add(n); foreach (SupportNoteComment cm in this.supportnotecomment_list.Where(c => c.note_id == n.id && c.type == (int)CommentWindow.COMMENT_TYPE.COMPLAIN).ToList<SupportNoteComment>()) { content.Add(cm); } foreach (SupportNoteComment cm in this.supportnotecomment_list.Where(c => c.note_id == n.id && c.type == (int)CommentWindow.COMMENT_TYPE.COMMENT).ToList<SupportNoteComment>()) { content.Add(cm); } } string print_time = "( " + DateTime.Now.ToString() + " )"; PrintDocument print_doc = new PrintDocument(); PageSetupDialog page_setup = new PageSetupDialog(); page_setup.Document = print_doc; page_setup.PageSettings.PaperSize = new PaperSize("A4", 825, 1165); page_setup.PageSettings.Landscape = true; page_setup.PageSettings.Margins = new Margins(0, 20, 0, 40); PrintOutputSelection wind = new PrintOutputSelection(); if (wind.ShowDialog() == DialogResult.OK) { int row_num = 0; int page_no = 0; bool is_comment = false; bool is_complain = false; print_doc.BeginPrint += delegate(object obj_sender, PrintEventArgs pe) { row_num = 0; page_no = 0; is_comment = false; is_complain = false; }; print_doc.PrintPage += delegate(object obj_sender, PrintPageEventArgs pe) { bool is_new_page = true; page_no++; using(Font font = new Font("tahoma", 7f)){ using(SolidBrush brush = new SolidBrush(Color.Black)){ using (Pen p = new Pen(Color.LightGray)) { int y_pos = 5; #region declare column width int col0_width = 30; // seq int col1_width = 50; // support# int col2_width = 60; // date int col3_width = 45; // start time int col4_width = 45; // end time int col5_width = 45; // duration int col6_width = 75; // s/n int col7_width = 80; // contact int col8_width = 25; // map drive int col9_width = 25; // install,update int col10_width = 25; // error int col11_width = 25; // install fonts int col12_width = 25; // print int col13_width = 25; // training int col14_width = 25; // stock int col15_width = 25; // edit form int col16_width = 25; // report->excel int col17_width = 25; // statement int col18_width = 25; // asset int col19_width = 25; // secure int col20_width = 25; // year end int col21_width = 25; // period int col22_width = 25; // mail int col23_width = 25; // transfer -> mkt int col24_width = 305; // remark #endregion declare column width StringFormat str_format_left = new StringFormat(); str_format_left.Alignment = StringAlignment.Near; str_format_left.LineAlignment = StringAlignment.Center; StringFormat str_format_center = new StringFormat(); str_format_center.Alignment = StringAlignment.Center; str_format_center.LineAlignment = StringAlignment.Center; StringFormat str_format_right = new StringFormat(); str_format_right.Alignment = StringAlignment.Far; str_format_right.LineAlignment = StringAlignment.Center; Font fontsmall = new Font("tahoma", 5f); // for some column header //for (int i = row_num; i < this.note_list.Count; i++) for (int i = row_num; i < content.Count; i++) { int x_pos = 10; if (y_pos > pe.MarginBounds.Bottom) { pe.HasMorePages = true; return; } else { pe.HasMorePages = false; } #region draw column header if (is_new_page) // column header { using (Pen pen_darkgray = new Pen(Color.DarkGray)) { y_pos += 5; pe.Graphics.DrawString("รายละเอียดการปฏิบัติงาน", new Font("tahoma", 11f, FontStyle.Bold), brush, new Rectangle(x_pos, y_pos, 300, 20)); pe.Graphics.DrawString(print_time, font, brush, new Rectangle(x_pos + 1000, y_pos, 130, 13), str_format_right); y_pos += 20; pe.Graphics.DrawString("พนักงาน จาก", font, brush, new Rectangle(10, y_pos, 80, 25), str_format_left); using (Font font_bold = new Font("tahoma", 8f, FontStyle.Bold)) { pe.Graphics.DrawString(this.lblUserFrom.Text, font_bold, brush, new Rectangle(90, y_pos, 100, 25), str_format_left); } pe.Graphics.DrawString("ถึง", font, brush, new Rectangle(190, y_pos, 30, 25), str_format_center); using (Font font_bold = new Font("tahoma", 8f, FontStyle.Bold)) { pe.Graphics.DrawString(this.lblUserTo.Text, font_bold, brush, new Rectangle(220, y_pos, 100, 25), str_format_left); } y_pos += 20; pe.Graphics.DrawString("วันที่ จาก", font, brush, new Rectangle(10, y_pos, 80, 25), str_format_left); using (Font font_bold = new Font("tahoma", 8f, FontStyle.Bold)) { pe.Graphics.DrawString(this.lblDateFrom.Text, font_bold, brush, new Rectangle(90, y_pos, 100, 25), str_format_left); } pe.Graphics.DrawString("ถึง", font, brush, new Rectangle(190, y_pos, 30, 25), str_format_center); using (Font font_bold = new Font("tahoma", 8f, FontStyle.Bold)) { pe.Graphics.DrawString(this.lblDateTo.Text, font_bold, brush, new Rectangle(220, y_pos, 100, 25), str_format_left); } pe.Graphics.DrawString("หน้า : " + page_no.ToString(), font, brush, new Rectangle(x_pos + 1000, y_pos, 130, 13), str_format_right); // draw page no. y_pos += 25; pe.Graphics.FillRectangle(new SolidBrush(Color.LightBlue), new RectangleF(x_pos, y_pos, 1135, 25)); pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos + 1135, y_pos); // horizontal line upper pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator Rectangle header_rect0 = new Rectangle(x_pos, y_pos, col0_width, 25); pe.Graphics.DrawString("ลำดับ", font, brush, header_rect0, str_format_center); x_pos += col0_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator Rectangle header_rect1 = new Rectangle(x_pos, y_pos, col1_width, 25); pe.Graphics.DrawString("Support#", font, brush, header_rect1, str_format_center); x_pos += col1_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator Rectangle header_rect2 = new Rectangle(x_pos, y_pos, col2_width, 25); pe.Graphics.DrawString("วันที่", font, brush, header_rect2, str_format_center); x_pos += col2_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator Rectangle header_rect3 = new Rectangle(x_pos, y_pos, col3_width, 25); pe.Graphics.DrawString("รับสาย", font, brush, header_rect3, str_format_center); x_pos += col3_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator Rectangle header_rect4 = new Rectangle(x_pos, y_pos, col4_width, 25); pe.Graphics.DrawString("วางสาย", font, brush, header_rect4, str_format_center); x_pos += col4_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator Rectangle header_rect5 = new Rectangle(x_pos, y_pos, col5_width, 25); pe.Graphics.DrawString("ระยะเวลา", font, brush, header_rect5, str_format_center); x_pos += col5_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator Rectangle header_rect6 = new Rectangle(x_pos, y_pos, col6_width, 25); pe.Graphics.DrawString("S/N", font, brush, header_rect6, str_format_center); x_pos += col6_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator Rectangle header_rect7 = new Rectangle(x_pos, y_pos, col7_width, 25); pe.Graphics.DrawString("ชื่อลูกค้า", font, brush, header_rect7, str_format_center); x_pos += col7_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator Rectangle header_rect8 = new Rectangle(x_pos, y_pos, col8_width, 25); pe.Graphics.DrawString("Map Drive", fontsmall, brush, header_rect8, str_format_center); x_pos += col8_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator Rectangle header_rect9 = new Rectangle(x_pos, y_pos, col9_width, 25); pe.Graphics.DrawString("Ins. /Up", fontsmall, brush, header_rect9, str_format_center); x_pos += col9_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator Rectangle header_rect10 = new Rectangle(x_pos, y_pos, col10_width, 25); pe.Graphics.DrawString("Error", fontsmall, brush, header_rect10, str_format_center); x_pos += col10_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator Rectangle header_rect11 = new Rectangle(x_pos, y_pos, col11_width, 25); pe.Graphics.DrawString("Ins. Fonts", fontsmall, brush, header_rect11, str_format_center); x_pos += col11_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator Rectangle header_rect12 = new Rectangle(x_pos, y_pos, col12_width, 25); pe.Graphics.DrawString("Print", fontsmall, brush, header_rect12, str_format_center); x_pos += col12_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator Rectangle header_rect13 = new Rectangle(x_pos, y_pos, col13_width, 25); pe.Graphics.DrawString("อบรม", fontsmall, brush, header_rect13, str_format_center); x_pos += col13_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator Rectangle header_rect14 = new Rectangle(x_pos, y_pos, col14_width, 25); pe.Graphics.DrawString("สินค้า", fontsmall, brush, header_rect14, str_format_center); x_pos += col14_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator Rectangle header_rect15 = new Rectangle(x_pos, y_pos, col15_width, 25); pe.Graphics.DrawString("Form Rep.", fontsmall, brush, header_rect15, str_format_center); x_pos += col15_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator Rectangle header_rect16 = new Rectangle(x_pos, y_pos, col16_width, 25); pe.Graphics.DrawString("Rep>Excel", fontsmall, brush, header_rect16, str_format_center); x_pos += col16_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator Rectangle header_rect17 = new Rectangle(x_pos, y_pos, col17_width, 25); pe.Graphics.DrawString("สร้างงบ", fontsmall, brush, header_rect17, str_format_center); x_pos += col17_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator Rectangle header_rect18 = new Rectangle(x_pos, y_pos, col18_width, 25); pe.Graphics.DrawString("สินทรัพย์ ค่าเสื่อม", fontsmall, brush, header_rect18, str_format_center); x_pos += col18_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator Rectangle header_rect19 = new Rectangle(x_pos, y_pos, col19_width, 25); pe.Graphics.DrawString("Secure", fontsmall, brush, header_rect19, str_format_center); x_pos += col19_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator Rectangle header_rect20 = new Rectangle(x_pos, y_pos, col20_width, 25); pe.Graphics.DrawString("Year End", fontsmall, brush, header_rect20, str_format_center); x_pos += col20_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator Rectangle header_rect21 = new Rectangle(x_pos, y_pos, col21_width, 25); pe.Graphics.DrawString("วันที่ไม่อยู่ในงวด", fontsmall, brush, header_rect21, str_format_center); x_pos += col21_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator Rectangle header_rect22 = new Rectangle(x_pos, y_pos, col22_width, 25); pe.Graphics.DrawString("Mail,รอสาย", fontsmall, brush, header_rect22, str_format_center); x_pos += col22_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator Rectangle header_rect23 = new Rectangle(x_pos, y_pos, col23_width, 25); pe.Graphics.DrawString("โอนฝ่ายขาย", fontsmall, brush, header_rect23, str_format_center); x_pos += col23_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator Rectangle header_rect24 = new Rectangle(x_pos, y_pos, col24_width, 25); pe.Graphics.DrawString("ปัญหาอื่น ๆ", font, brush, header_rect24, str_format_center); x_pos += col24_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator x_pos = 10; // set x_pos again after use in header y_pos += 25; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos + 1135, y_pos); // horizontal line below } y_pos += 7; is_new_page = false; } #endregion draw column header #region draw row data if (content[i] is Note) { // Paint odd/even background if (row_num % 2 != 0 && content[i] is Note) { using (SolidBrush brush_bg = new SolidBrush(Color.Lavender)) { pe.Graphics.FillRectangle(brush_bg, x_pos, y_pos - 6, pe.MarginBounds.Right - x_pos, 21); } } pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 15); Rectangle rect0 = new Rectangle(x_pos, y_pos, col0_width, 13); pe.Graphics.DrawString(((Note)content[i]).seq, font, brush, rect0, str_format_right); x_pos += col0_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 15); // column separator Rectangle rect1 = new Rectangle(x_pos, y_pos, col1_width, 13); pe.Graphics.DrawString(((Note)content[i]).users_name, font, brush, rect1, str_format_center); x_pos += col1_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 15); // column separator Rectangle rect2 = new Rectangle(x_pos, y_pos, col2_width, 13); pe.Graphics.DrawString(((Note)content[i]).date, font, brush, rect2, str_format_center); x_pos += col2_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 15); // column separator Rectangle rect3 = new Rectangle(x_pos, y_pos, col3_width, 13); pe.Graphics.DrawString(((Note)content[i]).start_time, font, brush, rect3, str_format_center); x_pos += col3_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 15); // column separator Rectangle rect4 = new Rectangle(x_pos, y_pos, col4_width, 13); pe.Graphics.DrawString(((Note)content[i]).end_time, font, brush, rect4, str_format_center); x_pos += col4_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 15); // column separator Rectangle rect5 = new Rectangle(x_pos, y_pos, col5_width, 13); pe.Graphics.DrawString(((Note)content[i]).duration, font, brush, rect5, str_format_center); x_pos += col5_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 15); // column separator Rectangle rect6 = new Rectangle(x_pos, y_pos, col6_width, 13); pe.Graphics.DrawString(((Note)content[i]).sernum, font, brush, rect6); x_pos += col6_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 15); // column separator Rectangle rect7 = new Rectangle(x_pos, y_pos, col7_width, 13); pe.Graphics.DrawString(((Note)content[i]).contact, font, brush, rect7); x_pos += col7_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 15); // column separator using (Font font_wingdings = new Font("wingdings", 7f)) { Rectangle rect8 = new Rectangle(x_pos, y_pos, col8_width, 13); if (((Note)content[i]).map_drive.Length > 0) pe.Graphics.DrawString(((char)(byte)0xFC).ToString(), font_wingdings, brush, rect8, str_format_center); x_pos += col8_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 15); // column separator Rectangle rect9 = new Rectangle(x_pos, y_pos, col9_width, 13); if (((Note)content[i]).install.Length > 0) pe.Graphics.DrawString(((char)(byte)0xFC).ToString(), font_wingdings, brush, rect9, str_format_center); x_pos += col9_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 15); // column separator Rectangle rect10 = new Rectangle(x_pos, y_pos, col10_width, 13); if (((Note)content[i]).error.Length > 0) pe.Graphics.DrawString(((char)(byte)0xFC).ToString(), font_wingdings, brush, rect10, str_format_center); x_pos += col10_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 15); // column separator Rectangle rect11 = new Rectangle(x_pos, y_pos, col11_width, 13); if (((Note)content[i]).fonts.Length > 0) pe.Graphics.DrawString(((char)(byte)0xFC).ToString(), font_wingdings, brush, rect11, str_format_center); x_pos += col11_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 15); // column separator Rectangle rect12 = new Rectangle(x_pos, y_pos, col12_width, 13); if (((Note)content[i]).print.Length > 0) pe.Graphics.DrawString(((char)(byte)0xFC).ToString(), font_wingdings, brush, rect12, str_format_center); x_pos += col12_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 15); // column separator Rectangle rect13 = new Rectangle(x_pos, y_pos, col13_width, 13); if (((Note)content[i]).training.Length > 0) pe.Graphics.DrawString(((char)(byte)0xFC).ToString(), font_wingdings, brush, rect13, str_format_center); x_pos += col13_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 15); // column separator Rectangle rect14 = new Rectangle(x_pos, y_pos, col14_width, 13); if (((Note)content[i]).stock.Length > 0) pe.Graphics.DrawString(((char)(byte)0xFC).ToString(), font_wingdings, brush, rect14, str_format_center); x_pos += col14_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 15); // column separator Rectangle rect15 = new Rectangle(x_pos, y_pos, col15_width, 13); if (((Note)content[i]).form.Length > 0) pe.Graphics.DrawString(((char)(byte)0xFC).ToString(), font_wingdings, brush, rect15, str_format_center); x_pos += col15_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 15); // column separator Rectangle rect16 = new Rectangle(x_pos, y_pos, col16_width, 13); if (((Note)content[i]).rep_excel.Length > 0) pe.Graphics.DrawString(((char)(byte)0xFC).ToString(), font_wingdings, brush, rect16, str_format_center); x_pos += col16_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 15); // column separator Rectangle rect17 = new Rectangle(x_pos, y_pos, col17_width, 13); if (((Note)content[i]).statement.Length > 0) pe.Graphics.DrawString(((char)(byte)0xFC).ToString(), font_wingdings, brush, rect17, str_format_center); x_pos += col17_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 15); // column separator Rectangle rect18 = new Rectangle(x_pos, y_pos, col18_width, 13); if (((Note)content[i]).asset.Length > 0) pe.Graphics.DrawString(((char)(byte)0xFC).ToString(), font_wingdings, brush, rect18, str_format_center); x_pos += col18_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 15); // column separator Rectangle rect19 = new Rectangle(x_pos, y_pos, col19_width, 13); if (((Note)content[i]).secure.Length > 0) pe.Graphics.DrawString(((char)(byte)0xFC).ToString(), font_wingdings, brush, rect19, str_format_center); x_pos += col19_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 15); // column separator Rectangle rect20 = new Rectangle(x_pos, y_pos, col20_width, 13); if (((Note)content[i]).year_end.Length > 0) pe.Graphics.DrawString(((char)(byte)0xFC).ToString(), font_wingdings, brush, rect20, str_format_center); x_pos += col20_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 15); // column separator Rectangle rect21 = new Rectangle(x_pos, y_pos, col21_width, 13); if (((Note)content[i]).period.Length > 0) pe.Graphics.DrawString(((char)(byte)0xFC).ToString(), font_wingdings, brush, rect21, str_format_center); x_pos += col21_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 15); // column separator Rectangle rect22 = new Rectangle(x_pos, y_pos, col22_width, 13); if (((Note)content[i]).mail_wait.Length > 0) pe.Graphics.DrawString(((char)(byte)0xFC).ToString(), font_wingdings, brush, rect22, str_format_center); x_pos += col22_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 15); // column separator Rectangle rect23 = new Rectangle(x_pos, y_pos, col23_width, 13); if (((Note)content[i]).transfer_mkt.Length > 0) pe.Graphics.DrawString(((char)(byte)0xFC).ToString(), font_wingdings, brush, rect23, str_format_center); x_pos += col23_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 15); // column separator } Rectangle rect24 = new Rectangle(x_pos, y_pos, col24_width, 13); pe.Graphics.DrawString(((Note)content[i]).remark, font, brush, rect24); x_pos += col24_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 15); // column separator is_comment = false; is_complain = false; } if (content[i] is SupportNoteComment) { using (SolidBrush brush_red = new SolidBrush(Color.Red)) { using (SolidBrush brush_blue = new SolidBrush(Color.Blue)) { pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 15); // open row separator if (((SupportNoteComment)content[i]).type == (int)CommentWindow.COMMENT_TYPE.COMMENT) { if (!is_comment) pe.Graphics.DrawString("Comment : ", font, brush_blue, new Rectangle(x_pos + 30, y_pos, 100, 13)); pe.Graphics.DrawString(((SupportNoteComment)content[i]).description, font, brush_blue, new Rectangle(x_pos + 90, y_pos, pe.MarginBounds.Right - (x_pos + 90) - pe.MarginBounds.Left, 13)); is_comment = true; } if (((SupportNoteComment)content[i]).type == (int)CommentWindow.COMMENT_TYPE.COMPLAIN) { if (!is_complain) pe.Graphics.DrawString("Complain : ", font, brush_red, new Rectangle(x_pos + 30, y_pos, 100, 13)); pe.Graphics.DrawString(((SupportNoteComment)content[i]).description, font, brush_red, new Rectangle(x_pos + 90, y_pos, pe.MarginBounds.Right - (x_pos + 90) - pe.MarginBounds.Left, 13)); is_complain = true; } pe.Graphics.DrawLine(p, pe.MarginBounds.Right, y_pos - 6, pe.MarginBounds.Right, y_pos + 15); // close row separator } } } // Horizontal line x_pos = 10; pe.Graphics.DrawLine(p, x_pos, y_pos + 15, x_pos + 1135, y_pos + 15); #endregion draw row data row_num++; y_pos += 20; } #region draw summary data // draw separate column line pe.Graphics.DrawLine(p, 440, y_pos - 12, 440, y_pos + 15); pe.Graphics.DrawLine(p, 465, y_pos - 12, 465, y_pos + 15); pe.Graphics.DrawLine(p, 490, y_pos - 12, 490, y_pos + 15); pe.Graphics.DrawLine(p, 515, y_pos - 12, 515, y_pos + 15); pe.Graphics.DrawLine(p, 540, y_pos - 12, 540, y_pos + 15); pe.Graphics.DrawLine(p, 565, y_pos - 12, 565, y_pos + 15); pe.Graphics.DrawLine(p, 590, y_pos - 12, 590, y_pos + 15); pe.Graphics.DrawLine(p, 615, y_pos - 12, 615, y_pos + 15); pe.Graphics.DrawLine(p, 640, y_pos - 12, 640, y_pos + 15); pe.Graphics.DrawLine(p, 665, y_pos - 12, 665, y_pos + 15); pe.Graphics.DrawLine(p, 690, y_pos - 12, 690, y_pos + 15); pe.Graphics.DrawLine(p, 715, y_pos - 12, 715, y_pos + 15); pe.Graphics.DrawLine(p, 740, y_pos - 12, 740, y_pos + 15); pe.Graphics.DrawLine(p, 765, y_pos - 12, 765, y_pos + 15); pe.Graphics.DrawLine(p, 790, y_pos - 12, 790, y_pos + 15); pe.Graphics.DrawLine(p, 815, y_pos - 12, 815, y_pos + 15); pe.Graphics.DrawLine(p, 840, y_pos - 12, 840, y_pos + 15); // draw double horizontal line pe.Graphics.DrawLine(p, 440, y_pos + 13, 840, y_pos + 13); pe.Graphics.DrawLine(p, 440, y_pos + 15, 840, y_pos + 15); pe.Graphics.DrawString("รวม", font, brush, new RectangleF(350, y_pos, 80, 15), str_format_right); pe.Graphics.DrawString(this.note_list.Where(n => n.map_drive.Length > 0).Count<Note>().ToString(), font, brush, new RectangleF(440, y_pos, 25, 15), str_format_right); pe.Graphics.DrawString(this.note_list.Where(n => n.install.Length > 0).Count<Note>().ToString(), font, brush, new RectangleF(465, y_pos, 25, 15), str_format_right); pe.Graphics.DrawString(this.note_list.Where(n => n.error.Length > 0).Count<Note>().ToString(), font, brush, new RectangleF(490, y_pos, 25, 15), str_format_right); pe.Graphics.DrawString(this.note_list.Where(n => n.fonts.Length > 0).Count<Note>().ToString(), font, brush, new RectangleF(515, y_pos, 25, 15), str_format_right); pe.Graphics.DrawString(this.note_list.Where(n => n.print.Length > 0).Count<Note>().ToString(), font, brush, new RectangleF(540, y_pos, 25, 15), str_format_right); pe.Graphics.DrawString(this.note_list.Where(n => n.training.Length > 0).Count<Note>().ToString(), font, brush, new RectangleF(565, y_pos, 25, 15), str_format_right); pe.Graphics.DrawString(this.note_list.Where(n => n.stock.Length > 0).Count<Note>().ToString(), font, brush, new RectangleF(590, y_pos, 25, 15), str_format_right); pe.Graphics.DrawString(this.note_list.Where(n => n.form.Length > 0).Count<Note>().ToString(), font, brush, new RectangleF(615, y_pos, 25, 15), str_format_right); pe.Graphics.DrawString(this.note_list.Where(n => n.rep_excel.Length > 0).Count<Note>().ToString(), font, brush, new RectangleF(640, y_pos, 25, 15), str_format_right); pe.Graphics.DrawString(this.note_list.Where(n => n.statement.Length > 0).Count<Note>().ToString(), font, brush, new RectangleF(665, y_pos, 25, 15), str_format_right); pe.Graphics.DrawString(this.note_list.Where(n => n.asset.Length > 0).Count<Note>().ToString(), font, brush, new RectangleF(690, y_pos, 25, 15), str_format_right); pe.Graphics.DrawString(this.note_list.Where(n => n.secure.Length > 0).Count<Note>().ToString(), font, brush, new RectangleF(715, y_pos, 25, 15), str_format_right); pe.Graphics.DrawString(this.note_list.Where(n => n.year_end.Length > 0).Count<Note>().ToString(), font, brush, new RectangleF(740, y_pos, 25, 15), str_format_right); pe.Graphics.DrawString(this.note_list.Where(n => n.period.Length > 0).Count<Note>().ToString(), font, brush, new RectangleF(765, y_pos, 25, 15), str_format_right); pe.Graphics.DrawString(this.note_list.Where(n => n.mail_wait.Length > 0).Count<Note>().ToString(), font, brush, new RectangleF(790, y_pos, 25, 15), str_format_right); pe.Graphics.DrawString(this.note_list.Where(n => n.transfer_mkt.Length > 0).Count<Note>().ToString(), font, brush, new RectangleF(815, y_pos, 25, 15), str_format_right); #endregion draw summary data y_pos += 20; if (y_pos > pe.MarginBounds.Bottom) { pe.HasMorePages = true; return; } else { pe.HasMorePages = false; } pe.Graphics.DrawString("(เวลารับสาย : " + this.lblWorkTime.Text + ") + (เวลาพักสาย : " + this.lblBreakTime.Text + ") = (เวลารวม : " + this.lblTotalTime.Text + ")" , font, brush, new Rectangle(10, y_pos, 800, 15)); y_pos += 20; if (y_pos > pe.MarginBounds.Bottom) { pe.HasMorePages = true; return; } else { pe.HasMorePages = false; } pe.Graphics.DrawString("จำนวนวันลา/ออกพบลูกค้า : " + this.lblPeriodAbsent.Text, font, brush, new Rectangle(10, y_pos, 400, 15)); } } } }; if (wind.output == PrintOutputSelection.OUTPUT.PRINTER) { PrintDialog print_dialog = new PrintDialog(); print_dialog.Document = print_doc; print_dialog.AllowSelection = false; print_dialog.AllowSomePages = true; print_dialog.AllowPrintToFile = false; print_dialog.AllowCurrentPage = false; print_dialog.UseEXDialog = true; if (print_dialog.ShowDialog() == DialogResult.OK) { print_doc.Print(); } } if (wind.output == PrintOutputSelection.OUTPUT.SCREEN) { PrintPreviewDialog preview_dialog = new PrintPreviewDialog(); preview_dialog.SetBounds(this.ClientRectangle.X + 5, this.ClientRectangle.Y + 5, this.ClientRectangle.Width - 10, this.ClientRectangle.Height - 10); preview_dialog.Document = print_doc; preview_dialog.MdiParent = this.main_form; preview_dialog.Show(); } if (wind.output == PrintOutputSelection.OUTPUT.FILE) { } } else { print_doc = null; page_setup = null; } }
private void DoPrintPreview() { PrintDocument pd = new PrintDocument(); PrintPreviewDialog ppd = new PrintPreviewDialog(); pd.PrintPage += new PrintPageEventHandler( Graph_PrintPage ); ppd.Document = pd; ppd.Show(); }
private void btnImprimir_Click(object sender, EventArgs e) { PrintDocument pDoc = new PrintDocument(); Button btn = (Button)sender; if (btn.Name == "btnImprimir") pDoc.PrintPage += new PrintPageEventHandler(pDoc_PrintPageUnico); else { // Para imprimir dados vindo de uma tabela de um banco de dados // é preciso definir conexões ao banco, com senhas, executar SELECTs. // Neste exemplo abaixo estou criando 5 registros em memoria e // recalculando o boleto para cada página impressa // Customize de acordo com suas necessidades, pois este é apenas um exemplo // basico por isso serão utilizados apenas poucos campos. tbDados = new DataTable(); // Cria atabela em memoria // Cria as colunas nos respectivos tipos tbDados.Columns.Add("Nome", typeof(string)); tbDados.Columns.Add("Vencimento", typeof(DateTime)); tbDados.Columns.Add("Valor", typeof(double)); tbDados.Columns.Add("NossoNumero", typeof(int)); // insere os dados tbDados.Rows.Add("Fabio", new DateTime(2008, 12, 30), 123.45, 345678); tbDados.Rows.Add("Érika", new DateTime(2008, 7, 25), 60, 12332); tbDados.Rows.Add("Milena", new DateTime(2008, 10, 20), 10.30, 234); tbDados.Rows.Add("Cliente", DateTime.MinValue, 200.55, 456445); tbDados.Rows.Add("qualquer um", new DateTime(2008, 2, 12), 7890.5, 56756); // posiciona o registro atual pDoc.PrintPage += new PrintPageEventHandler(pDoc_PrintPageTabela); } nReg = 0; pDoc.DefaultPageSettings.Landscape = chkCarne.Checked; if (chkPreview.Checked) { PrintDialog dlgPrinter = new PrintDialog(); PrintPreviewDialog ppw = new PrintPreviewDialog(); ppw.Document = pDoc; ppw.MdiParent = this.MdiParent; ppw.WindowState = FormWindowState.Maximized; ppw.Show(); } else pDoc.Print(); }
public override void Run() { try { IPrintable printable = WorkbenchSingleton.Workbench.ActiveViewContent as IPrintable; if (printable != null) { using (PrintDocument pdoc = printable.PrintDocument) { if (pdoc != null) { PrintPreviewDialog ppd = new PrintPreviewDialog(); ppd.Owner = WorkbenchSingleton.MainForm; ppd.TopMost = true; ppd.Document = pdoc; ppd.Show(); } else { MessageService.ShowError("${res:ICSharpCode.SharpDevelop.Commands.Print.CreatePrintDocumentError}"); } } } } catch (InvalidPrinterException) {} }
public void PreviewAndPrint() { //ExStart //ExFor:AsposeWordsPrintDocument //ExSummary:Shows the Print dialog that allows selecting the printer and page range to print with. Then brings up the print preview from which you can preview the document and choose to print or close. Document doc = new Document(MyDir + "Rendering.doc"); PrintPreviewDialog previewDlg = new PrintPreviewDialog(); // Show non-modal first is a hack for the print preview form to show on top. previewDlg.Show(); // Initialize the Print Dialog with the number of pages in the document. PrintDialog printDlg = new PrintDialog(); printDlg.AllowSomePages = true; printDlg.PrinterSettings.MinimumPage = 1; printDlg.PrinterSettings.MaximumPage = doc.PageCount; printDlg.PrinterSettings.FromPage = 1; printDlg.PrinterSettings.ToPage = doc.PageCount; if (!printDlg.ShowDialog().Equals(DialogResult.OK)) return; // Create the Aspose.Words' implementation of the .NET print document // and pass the printer settings from the dialog to the print document. AsposeWordsPrintDocument awPrintDoc = new AsposeWordsPrintDocument(doc); awPrintDoc.PrinterSettings = printDlg.PrinterSettings; // Hide and invalidate preview is a hack for print preview to show on top. previewDlg.Hide(); previewDlg.PrintPreviewControl.InvalidatePreview(); // Pass the Aspose.Words' print document to the .NET Print Preview dialog. previewDlg.Document = awPrintDoc; previewDlg.ShowDialog(); //ExEnd }
private void vistaPreviaToolStripMenuItem_Click(object sender, EventArgs e) { contador = 0; listaFacturas2.setPaginado(1, tabControlPaginas.TabPages.Count); //Create a PrintPreviewDialog object previewDlg = new PrintPreviewDialog(); //Create a PrintDocument object PrintDocument pd = new PrintDocument(); //Si se imprime el formato de Cobranzas en en horizontal if (tabControlPaginas.TabCount == 1) { pd.DefaultPageSettings.Landscape = true; } else { pd.DefaultPageSettings.Landscape = false; } //Add print-page event handler pd.PrintPage += new PrintPageEventHandler(pd_PrintPage); //Set Document property of PrintPreviewDialog previewDlg.Document = pd; //Display dialog previewDlg.Show(); }
/// <summary> /// Display a <see cref="PrintPreviewDialog" />, allowing the user to preview and /// subsequently print the <see cref="MasterPane" /> contained in this /// <see cref="ZedGraphControl" />. /// </summary> public void DoPrintPreview() { // Add a try/catch pair since the users of the control can't catch this one try { PrintDocument pd = PrintDocument; if ( pd != null ) { PrintPreviewDialog ppd = new PrintPreviewDialog(); //pd.PrintPage += new PrintPageEventHandler( Graph_PrintPage ); ppd.Document = pd; ppd.Show( this ); } } catch ( Exception exception ) { MessageBox.Show( exception.Message ); } }
private void toolStripPrint_Click(object sender, EventArgs e) { PrintDocument print_doc = new PrintDocument(); PageSetupDialog page_setup = new PageSetupDialog(); page_setup.Document = print_doc; page_setup.PageSettings.PaperSize = new PaperSize("A4", 825, 1165); page_setup.PageSettings.Landscape = true; page_setup.PageSettings.Margins = new Margins(0, 0, 10, 40); PrintOutputSelection wind = new PrintOutputSelection(); if (wind.ShowDialog() == DialogResult.OK) { int row_num = 0; int page_no = 0; print_doc.BeginPrint += delegate(object obj_sender, PrintEventArgs pe) { row_num = 0; page_no = 0; }; print_doc.PrintPage += delegate(object obj_sender, PrintPageEventArgs pe) { bool is_new_page = true; page_no++; using (Font font = new Font("tahoma", 8f)) { using (SolidBrush brush = new SolidBrush(Color.Black)) { using (Pen p = new Pen(Color.LightGray)) { int y_pos = pe.MarginBounds.Top; #region declare column width int col0_width = 40; // seq int col1_width = 70; // users_name int col2_width = 70; // date int col3_width = 50; // from_time int col4_width = 50; // to_time int col5_width = 110; // duration int col6_width = 155; // event_code int col7_width = 80; // status int col8_width = 270; // customer int col9_width = 100; // med_cert int col10_width = 80; // fine int col11_width = 70; // rec_by #endregion declare column width StringFormat str_format_center = new StringFormat(); str_format_center.Alignment = StringAlignment.Center; str_format_center.LineAlignment = StringAlignment.Center; StringFormat str_format_right = new StringFormat(); str_format_right.Alignment = StringAlignment.Far; str_format_right.LineAlignment = StringAlignment.Center; StringFormat str_format_left = new StringFormat(); str_format_left.Alignment = StringAlignment.Near; str_format_left.LineAlignment = StringAlignment.Center; y_pos += 5; #region Report Header using (Font h_font = new Font("tahoma", 11f, FontStyle.Bold)) { pe.Graphics.DrawString("รายละเอียดวันลา/ออกพบลูกค้า", h_font, brush, new Rectangle(10, y_pos, 300, 20)); } using (Font p_font = new Font("tahoma", 7f)) { pe.Graphics.DrawString("หน้า : " + page_no.ToString(), p_font, brush, new Rectangle(1000, y_pos, 150, 20), str_format_right); } y_pos += 25; pe.Graphics.DrawString("รหัสพนักงาน จาก ", font, brush, new Rectangle(10, y_pos, 100, 20)); pe.Graphics.DrawString(" : " + this.lblUserFrom.Text, font, brush, new Rectangle(110, y_pos, 100, 20)); pe.Graphics.DrawString(" ถึง ", font, brush, new Rectangle(210, y_pos, 30, 20)); pe.Graphics.DrawString(" : " + this.lblUserTo.Text, font, brush, new Rectangle(240, y_pos, 100, 20)); y_pos += 20; pe.Graphics.DrawString("วันที่ จาก ", font, brush, new Rectangle(10, y_pos, 100, 20)); pe.Graphics.DrawString(" : " + this.lblDateFrom.Text, font, brush, new Rectangle(110, y_pos, 100, 20)); pe.Graphics.DrawString(" ถึง ", font, brush, new Rectangle(210, y_pos, 30, 20)); pe.Graphics.DrawString(" : " + this.lblDateTo.Text, font, brush, new Rectangle(240, y_pos, 100, 20)); y_pos += 20; #endregion Report Header for (int i = row_num; i < this.sorted_list.Count; i++) { int x_pos = 10; if (y_pos > pe.MarginBounds.Bottom) { pe.HasMorePages = true; return; } else { pe.HasMorePages = false; } #region draw column header if (is_new_page) // column header { using (Pen pen_darkgray = new Pen(Color.DarkGray)) { pe.Graphics.FillRectangle(new SolidBrush(Color.LightBlue), new RectangleF(x_pos, y_pos, /*790*/ 1145, 25)); pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos + /*790*/ 1145, y_pos); // horizontal line upper pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator Rectangle header_rect0 = new Rectangle(x_pos, y_pos, col0_width, 25); pe.Graphics.DrawString("ลำดับ", font, brush, header_rect0, str_format_center); x_pos += col0_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator pe.Graphics.DrawString("รหัสพนักงาน", font, brush, new Rectangle(x_pos, y_pos, col1_width, 25), str_format_center); x_pos += col1_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator Rectangle header_rect1 = new Rectangle(x_pos, y_pos, col2_width, 25); pe.Graphics.DrawString("วันที่", font, brush, header_rect1, str_format_center); x_pos += col2_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator Rectangle header_rect2 = new Rectangle(x_pos, y_pos, col3_width, 25); pe.Graphics.DrawString("จาก", font, brush, header_rect2, str_format_center); x_pos += col3_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator Rectangle header_rect3 = new Rectangle(x_pos, y_pos, col4_width, 25); pe.Graphics.DrawString("ถึง", font, brush, header_rect3, str_format_center); x_pos += col4_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator Rectangle header_rect4 = new Rectangle(x_pos, y_pos, col5_width, 25); pe.Graphics.DrawString("รวมเวลา", font, brush, header_rect4, str_format_center); x_pos += col5_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator Rectangle header_rect5 = new Rectangle(x_pos, y_pos, col6_width, 25); pe.Graphics.DrawString("เหตุผล", font, brush, header_rect5, str_format_center); x_pos += col6_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator Rectangle header_rect6 = new Rectangle(x_pos, y_pos, col7_width, 25); pe.Graphics.DrawString("สถานะ", font, brush, header_rect6, str_format_center); x_pos += col7_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator Rectangle header_rect7 = new Rectangle(x_pos, y_pos, col8_width, 25); pe.Graphics.DrawString("ชื่อลูกค้า", font, brush, header_rect7, str_format_center); x_pos += col8_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator pe.Graphics.DrawString("ใบรับรองแพทย์", font, brush, new Rectangle(x_pos, y_pos, col9_width, 25), str_format_center); x_pos += col9_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator pe.Graphics.DrawString("หักค่าคอมฯ", font, brush, new Rectangle(x_pos, y_pos, col10_width, 25), str_format_center); x_pos += col10_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator Rectangle header_rect8 = new Rectangle(x_pos, y_pos, col11_width, 25); pe.Graphics.DrawString("บันทึกโดย", font, brush, header_rect8, str_format_center); x_pos += col11_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator x_pos = 10; // set x_pos again after use in header y_pos += 25; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos + /*790*/ 1145, y_pos); // horizontal line below } y_pos += 7; is_new_page = false; } #endregion draw column header #region draw row data pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 20); Rectangle rect0 = new Rectangle(x_pos, y_pos, col0_width - 5, 18); pe.Graphics.DrawString((row_num + 1).ToString(), font, brush, rect0, str_format_right); x_pos += col0_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 20); // column separator pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 20); pe.Graphics.DrawString(this.sorted_list[i].users_name, font, brush, new Rectangle(x_pos + 5, y_pos, col1_width - 5, 18), str_format_left); x_pos += col1_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 20); // column separator pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 20); Rectangle rect1 = new Rectangle(x_pos, y_pos, col2_width, 18); pe.Graphics.DrawString(DateTime.Parse(this.sorted_list[i].date).ToString("dd/MM/yy", cinfo_th), font, brush, rect1, str_format_center); x_pos += col2_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 20); // column separator Rectangle rect2 = new Rectangle(x_pos, y_pos, col3_width, 18); pe.Graphics.DrawString(this.sorted_list[i].from_time.Substring(0, 5), font, brush, rect2, str_format_center); x_pos += col3_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 20); // column separator Rectangle rect3 = new Rectangle(x_pos, y_pos, col4_width, 18); pe.Graphics.DrawString(this.sorted_list[i].to_time.Substring(0, 5), font, brush, rect3, str_format_center); x_pos += col4_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 20); // column separator Rectangle rect4 = new Rectangle(x_pos, y_pos, col5_width, 18); string time_duration = this.sorted_list.Where(t => t.id == this.sorted_list[i].id).ToList<EventCalendar>().GetSummaryLeaveDayString(); pe.Graphics.DrawString(time_duration, font, brush, rect4, str_format_center); x_pos += col5_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 20); // column separator Rectangle rect5 = new Rectangle(x_pos, y_pos, col6_width, 18); string leave_cause = (this.leave_cause.Find(t => t.tabtyp == this.sorted_list[i].event_type && t.typcod == this.sorted_list[i].event_code) != null ? this.leave_cause.Find(t => t.tabtyp == this.sorted_list[i].event_type && t.typcod == this.sorted_list[i].event_code).typdes_th : ""); pe.Graphics.DrawString(leave_cause, font, brush, rect5, str_format_left); x_pos += col6_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 20); // column separator Rectangle rect6 = new Rectangle(x_pos, y_pos, col7_width, 18); string status = (this.sorted_list[i].status == (int)CustomDateEvent.EVENT_STATUS.WAIT_FOR_CONFIRM ? "WAIT" : (this.sorted_list[i].status == (int)CustomDateEvent.EVENT_STATUS.CANCELED ? "CANCELED" : "CONFIRMED")); using (SolidBrush status_brush = (this.sorted_list[i].status == (int)CustomDateEvent.EVENT_STATUS.WAIT_FOR_CONFIRM ? new SolidBrush(Color.Blue) : (this.sorted_list[i].status == (int)CustomDateEvent.EVENT_STATUS.CANCELED ? new SolidBrush(Color.Red) : new SolidBrush(Color.Black)))) { pe.Graphics.DrawString(status, font, status_brush, rect6, str_format_left); } x_pos += col7_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 20); // column separator Rectangle rect7 = new Rectangle(x_pos, y_pos, col8_width, 18); pe.Graphics.DrawString(this.sorted_list[i].customer, font, brush, rect7, str_format_left); x_pos += col8_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 20); // column separator pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 20); string med_cert = (this.sorted_list[i].med_cert == "Y" ? "มีใบรับรองแพทย์" : ""); pe.Graphics.DrawString(med_cert, font, brush, new Rectangle(x_pos + 5, y_pos, col9_width - 5, 18), str_format_left); x_pos += col9_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 20); // column separator pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 20); string fine = (this.sorted_list[i].fine > 0 ? this.sorted_list[i].fine.ToString() : ""); pe.Graphics.DrawString(fine, font, brush, new Rectangle(x_pos + 5, y_pos, col10_width - 5, 18), str_format_right); x_pos += col10_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 20); // column separator Rectangle rect8 = new Rectangle(x_pos, y_pos, col11_width, 18); pe.Graphics.DrawString(this.sorted_list[i].rec_by, font, brush, rect8, str_format_left); x_pos += col11_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 20); // column separator // Horizontal line x_pos = 10; pe.Graphics.DrawLine(p, x_pos, y_pos + 20, x_pos + /*790*/ 1145, y_pos + 20); #endregion draw row data row_num++; y_pos += 25; } if (y_pos > pe.MarginBounds.Bottom) { pe.HasMorePages = true; return; } else { pe.HasMorePages = false; } pe.Graphics.DrawString(this.toolStripInfo.Text, font, brush, new Rectangle(10, y_pos, 400, 15)); y_pos += 10; if (y_pos > pe.MarginBounds.Bottom) { pe.HasMorePages = true; return; } else { pe.HasMorePages = false; } using (Font bold_font = new Font("tahoma", 8f, FontStyle.Bold)) { pe.Graphics.DrawString(this.groupPeriod.Text.Trim(), bold_font, brush, new Rectangle(10, y_pos, 400, 15)); pe.Graphics.DrawString(this.groupTotal.Text.Trim(), bold_font, brush, new Rectangle(420, y_pos, 400, 15)); } y_pos += 20; if (y_pos > pe.MarginBounds.Bottom) { pe.HasMorePages = true; return; } else { pe.HasMorePages = false; } pe.Graphics.DrawString("ลางาน", font, brush, new Rectangle(10, y_pos, 80, 15)); pe.Graphics.DrawString(" : " + this.lblPeriodAbsent.Text, font, brush, new Rectangle(90, y_pos, 320, 15)); pe.Graphics.DrawString("ลางาน", font, brush, new Rectangle(420, y_pos, 80, 15)); pe.Graphics.DrawString(" : " + this.lblTotalAbsent.Text, font, brush, new Rectangle(500, y_pos, 320, 15)); y_pos += 20; if (y_pos > pe.MarginBounds.Bottom) { pe.HasMorePages = true; return; } else { pe.HasMorePages = false; } pe.Graphics.DrawString("ออกพบลูกค้า", font, brush, new Rectangle(10, y_pos, 80, 15)); pe.Graphics.DrawString(" : " + this.lblPeriodServ.Text, font, brush, new Rectangle(90, y_pos, 320, 15)); pe.Graphics.DrawString("ออกพบลูกค้า", font, brush, new Rectangle(420, y_pos, 80, 15)); pe.Graphics.DrawString(" : " + this.lblTotalServ.Text, font, brush, new Rectangle(500, y_pos, 320, 15)); } } } }; if (wind.output == PrintOutputSelection.OUTPUT.PRINTER) { PrintDialog print_dialog = new PrintDialog(); print_dialog.Document = print_doc; print_dialog.AllowSelection = false; print_dialog.AllowSomePages = true; print_dialog.AllowPrintToFile = false; print_dialog.AllowCurrentPage = false; print_dialog.UseEXDialog = true; if (print_dialog.ShowDialog() == DialogResult.OK) { print_doc.Print(); } } if (wind.output == PrintOutputSelection.OUTPUT.SCREEN) { PrintPreviewDialog preview_dialog = new PrintPreviewDialog(); preview_dialog.SetBounds(this.ClientRectangle.X + 5, this.ClientRectangle.Y + 5, this.ClientRectangle.Width - 10, this.ClientRectangle.Height - 10); preview_dialog.Document = print_doc; preview_dialog.MdiParent = this.main_form; preview_dialog.Show(); } if (wind.output == PrintOutputSelection.OUTPUT.FILE) { } } else { print_doc = null; page_setup = null; } }
void Button17Click(object sender, EventArgs e) { // просмотр бланка отчета PrintPreviewDialog ppd = new PrintPreviewDialog(); ppd.Document = printDocument1; ppd.MdiParent = ClassForms.Rapid_Client; ppd.Show(); }
private void toolStripPrintSummary_Click(object sender, EventArgs e) { string print_time = "( " + DateTime.Now.ToString() + " )"; PrintDocument print_doc = new PrintDocument(); PageSetupDialog page_setup = new PageSetupDialog(); page_setup.Document = print_doc; page_setup.PageSettings.PaperSize = new PaperSize("A4", 825, 1165); page_setup.PageSettings.Landscape = false; page_setup.PageSettings.Margins = new Margins(0, 0, 0, 40); PrintOutputSelection wind = new PrintOutputSelection(); if (wind.ShowDialog() == DialogResult.OK) { int row_num = 0; int page_no = 0; print_doc.BeginPrint += delegate(object obj_sender, PrintEventArgs pe) { row_num = 0; page_no = 0; }; print_doc.PrintPage += delegate(object obj_sender, PrintPageEventArgs pe) { bool is_new_page = true; page_no++; using (Font font = new Font("tahoma", 8f)) { using (SolidBrush brush = new SolidBrush(Color.Black)) { using (Pen p = new Pen(Color.LightGray)) { int y_pos = 5; #region declare column width int col0_width = 40; // seq int col1_width = 60; // support# int col2_width = 80; // name int col3_width = 110; // talk_line_count int col4_width = 110; // talk_time int col5_width = 150; // talk_time/line_count int col6_width = 110; // break_time int col7_width = 130; // leave_time //int col10_width = 25; // #endregion declare column width StringFormat str_format_left = new StringFormat(); str_format_left.Alignment = StringAlignment.Near; str_format_left.LineAlignment = StringAlignment.Center; StringFormat str_format_center = new StringFormat(); str_format_center.Alignment = StringAlignment.Center; str_format_center.LineAlignment = StringAlignment.Center; StringFormat str_format_right = new StringFormat(); str_format_right.Alignment = StringAlignment.Far; str_format_right.LineAlignment = StringAlignment.Center; List<Note> note_list = this.JustConvertToNoteList(); List<Users> supports = this.list_support_users.Where(s => (s.username.CompareTo(this.current_user_from.username) == 0 || s.username.CompareTo(this.current_user_from.username) > 0) && (s.username.CompareTo(this.current_user_to.username) == 0 || s.username.CompareTo(this.current_user_to.username) < 0)).ToList<Users>(); for (int i = row_num; i < supports.Count; i++) { int x_pos = 10; if (y_pos > pe.MarginBounds.Bottom) { pe.HasMorePages = true; return; } else { pe.HasMorePages = false; } #region draw column header if (is_new_page) { using (Pen pen_darkgray = new Pen(Color.DarkGray)) { y_pos += 5; pe.Graphics.DrawString("สรุปการปฏิบัติงาน(Support)", new Font("tahoma", 11f, FontStyle.Bold), brush, new Rectangle(x_pos, y_pos, 300, 20)); pe.Graphics.DrawString(print_time, font, brush, new Rectangle(x_pos + 650, y_pos, 130, 13), str_format_right); y_pos += 20; pe.Graphics.DrawString("พนักงาน จาก", font, brush, new Rectangle(10, y_pos, 80, 25), str_format_left); using (Font font_bold = new Font("tahoma", 8f, FontStyle.Bold)) { pe.Graphics.DrawString(this.lblUserFrom.Text, font_bold, brush, new Rectangle(90, y_pos, 100, 25), str_format_left); } pe.Graphics.DrawString("ถึง", font, brush, new Rectangle(190, y_pos, 30, 25), str_format_center); using (Font font_bold = new Font("tahoma", 8f, FontStyle.Bold)) { pe.Graphics.DrawString(this.lblUserTo.Text, font_bold, brush, new Rectangle(220, y_pos, 100, 25), str_format_left); } y_pos += 20; pe.Graphics.DrawString("วันที่ จาก", font, brush, new Rectangle(10, y_pos, 80, 25), str_format_left); using (Font font_bold = new Font("tahoma", 8f, FontStyle.Bold)) { pe.Graphics.DrawString(this.lblDateFrom.Text, font_bold, brush, new Rectangle(90, y_pos, 100, 25), str_format_left); } pe.Graphics.DrawString("ถึง", font, brush, new Rectangle(190, y_pos, 30, 25), str_format_center); using (Font font_bold = new Font("tahoma", 8f, FontStyle.Bold)) { pe.Graphics.DrawString(this.lblDateTo.Text, font_bold, brush, new Rectangle(220, y_pos, 100, 25), str_format_left); } pe.Graphics.DrawString("หน้า : " + page_no.ToString(), font, brush, new Rectangle(x_pos + 630, y_pos, 130, 13), str_format_right); // draw page no. y_pos += 25; pe.Graphics.FillRectangle(new SolidBrush(Color.LightBlue), new RectangleF(x_pos, y_pos, 790, 25)); pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos + 790, y_pos); // horizontal line upper pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator pe.Graphics.DrawString("ลำดับ", font, brush, new Rectangle(x_pos, y_pos, col0_width, 25), str_format_center); x_pos += col0_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator pe.Graphics.DrawString("Support#", font, brush, new Rectangle(x_pos, y_pos, col1_width, 25), str_format_center); x_pos += col1_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator pe.Graphics.DrawString("ชื่อ", font, brush, new Rectangle(x_pos, y_pos, col2_width, 25), str_format_center); x_pos += col2_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator pe.Graphics.DrawString("จำนวนสายที่รับ", font, brush, new Rectangle(x_pos, y_pos, col3_width, 25), str_format_center); x_pos += col3_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator pe.Graphics.DrawString("รวมเวลารับสาย", font, brush, new Rectangle(x_pos, y_pos, col4_width, 25), str_format_center); x_pos += col4_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator pe.Graphics.DrawString("เวลาเฉลี่ย/สาย", font, brush, new Rectangle(x_pos, y_pos, col5_width, 25), str_format_center); x_pos += col5_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator pe.Graphics.DrawString("รวมเวลาพักสาย", font, brush, new Rectangle(x_pos, y_pos, col6_width, 25), str_format_center); x_pos += col6_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator pe.Graphics.DrawString("รวมวันลา/ออกพบลูกค้า", font, brush, new Rectangle(x_pos, y_pos, col7_width, 25), str_format_center); x_pos += col7_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator x_pos = 10; // set x_pos again after use in header y_pos += 25; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos + 790, y_pos); // horizontal line below } y_pos += 7; is_new_page = false; } #endregion draw column header #region draw row data pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 15); using (SolidBrush brush_gray = new SolidBrush(Color.Gray)) { pe.Graphics.DrawString((i + 1).ToString(), font, brush_gray, new Rectangle(x_pos, y_pos, col0_width - 5, 13), str_format_right); } x_pos += col0_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 15); // column separator using (Font font_bold = new Font("tahoma", 8f, FontStyle.Bold)) { pe.Graphics.DrawString(supports[i].username, font_bold, brush, new Rectangle(x_pos + 5, y_pos, col1_width - 5, 13), str_format_left); } x_pos += col1_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 15); // column separator pe.Graphics.DrawString(supports[i].name, font, brush, new Rectangle(x_pos + 5, y_pos, col2_width - 5, 13), str_format_left); x_pos += col2_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 15); // column separator pe.Graphics.DrawString(note_list.Where(n => n.users_name == supports[i].username && n.is_break != "Y").Count<Note>().ToString(), font, brush, new Rectangle(x_pos, y_pos, col3_width - 5, 13), str_format_right); x_pos += col3_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 15); // column separator string talk_time = (note_list.Where(n => n.users_name == supports[i].username && n.is_break != "Y").Count<Note>() > 0 ? Math.Ceiling(note_list.Where(n => n.users_name == supports[i].username).ToList<Note>().GetSummaryTalkTime().TotalMinutes).ToString() + " นาที" : "-"); pe.Graphics.DrawString(talk_time, font, brush, new Rectangle(x_pos, y_pos, col4_width, 13), str_format_center); x_pos += col4_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 15); // column separator double min_per_line = Math.Floor(Math.Floor(note_list.Where(n => n.users_name == supports[i].username).ToList<Note>().GetSummaryTalkTime().TotalMinutes) / note_list.Where(n => n.users_name == supports[i].username && n.is_break != "Y").Count<Note>()); double sec_per_line = Math.Floor((Math.Floor(note_list.Where(n => n.users_name == supports[i].username).ToList<Note>().GetSummaryTalkTime().TotalSeconds) - (min_per_line * note_list.Where(n => n.users_name == supports[i].username && n.is_break != "Y").Count<Note>() * 60)) / note_list.Where(n => n.users_name == supports[i].username && n.is_break != "Y").Count<Note>()); string time_per_line = (note_list.Where(n => n.users_name == supports[i].username && n.is_break != "Y").Count<Note>() > 0 ? min_per_line.ToString() + " นาที " + sec_per_line.ToString() + " วินาที / 1 สาย" : "-"); pe.Graphics.DrawString(time_per_line, font, brush, new Rectangle(x_pos, y_pos, col5_width, 13), str_format_center); x_pos += col5_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 15); // column separator string break_time = (note_list.Where(n => n.users_name == supports[i].username && n.is_break != "Y").Count<Note>() > 0 ? Math.Ceiling(note_list.Where(n => n.users_name == supports[i].username).ToList<Note>().GetSummaryBreakTime().TotalMinutes).ToString() + " นาที" : "-"); pe.Graphics.DrawString(break_time, font, brush, new Rectangle(x_pos, y_pos, col6_width, 13), str_format_center); x_pos += col6_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 15); // column separator pe.Graphics.DrawString(this.event_calendar.Where(c => c.users_name == supports[i].username).ToList<EventCalendar>().GetSummaryHoursMinutesString(), font, brush, new Rectangle(x_pos, y_pos, col7_width, 13), str_format_center); x_pos += col7_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 15); // column separator // Horizontal line x_pos = 10; pe.Graphics.DrawLine(p, x_pos, y_pos + 15, x_pos + 790, y_pos + 15); #endregion draw row data row_num++; y_pos += 20; } } } } }; if (wind.output == PrintOutputSelection.OUTPUT.PRINTER) { PrintDialog print_dialog = new PrintDialog(); print_dialog.Document = print_doc; print_dialog.AllowSelection = false; print_dialog.AllowSomePages = true; print_dialog.AllowPrintToFile = false; print_dialog.AllowCurrentPage = false; print_dialog.UseEXDialog = true; if (print_dialog.ShowDialog() == DialogResult.OK) { print_doc.Print(); } } if (wind.output == PrintOutputSelection.OUTPUT.SCREEN) { PrintPreviewDialog preview_dialog = new PrintPreviewDialog(); preview_dialog.SetBounds(this.ClientRectangle.X + 5, this.ClientRectangle.Y + 5, this.ClientRectangle.Width - 10, this.ClientRectangle.Height - 10); preview_dialog.Document = print_doc; preview_dialog.MdiParent = this.main_form; preview_dialog.Show(); } if (wind.output == PrintOutputSelection.OUTPUT.FILE) { } } else { print_doc = null; page_setup = null; } }
public void PrintResult() { try { if (listViewEvent.SelectedItems.Count > 0) { PrintPreviewDialog printPreviewDialog1 = new PrintPreviewDialog(); PrintDocument pd = new PrintDocument(); printPreviewDialog1.Document = pd; printPreviewDialog1.Size = new System.Drawing.Size(350, 550); printPreviewDialog1.Show(); pd.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.pd_PrintPage); pd.DefaultPageSettings.PaperSize = new PaperSize("A4", 827, 1170); pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage); } else { MessageBox.Show("Välj ett event, försök igen", "Fel format", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } catch (Exception ex) { } }
public override void Run() { try { IViewContent content = WorkbenchSingleton.Workbench.ActiveViewContent; if (content != null) { if (content is IPrintable) { using (PrintDocument pdoc = ((IPrintable)content).PrintDocument) { if (pdoc != null) { PrintPreviewDialog ppd = new PrintPreviewDialog(); ppd.Owner = (Form)WorkbenchSingleton.Workbench; ppd.TopMost = true; ppd.Document = pdoc; ppd.Show(); } else { MessageBox.Show("Couldn't create PrintDocument", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } } catch (System.Drawing.Printing.InvalidPrinterException) { } }
/// <summary> /// Display a <see cref="PrintPreviewDialog" />, allowing the user to preview and /// subsequently print the <see cref="MasterPane" /> contained in this /// <see cref="ZedGraphControl" />. /// </summary> public void DoPrintPreview() { // Add a try/catch pair since the users of the control can't catch this one try { PrintDocument pd = PrintDocument; if (pd != null) { PrintPreviewDialog ppd = new PrintPreviewDialog(); //pd.PrintPage += new PrintPageEventHandler( Graph_PrintPage ); ppd.Document = pd; ppd.Show(this); } } catch (Exception exception) { //messageBox Arguments are (Text, Title, No Button Visible, Cancel Button Visible) MessageBoxForm.msgIcon = SystemIcons.Warning; //this is used if you want to add a system icon to the message form. var messageBox = new MessageBoxForm(exception.Message, "", false, false); messageBox.Show(); } }
private void toolStripPrintSummary_Click(object sender, EventArgs e) { PrintDocument print_doc = new PrintDocument(); PageSetupDialog page_setup = new PageSetupDialog(); page_setup.Document = print_doc; page_setup.PageSettings.PaperSize = new PaperSize("A4", 825, 1165); page_setup.PageSettings.Landscape = false; page_setup.PageSettings.Margins = new Margins(0, 0, 10, 40); PrintOutputSelection wind = new PrintOutputSelection(); if (wind.ShowDialog() == DialogResult.OK) { int row_num = 0; int page_no = 0; print_doc.BeginPrint += delegate(object obj_sender, PrintEventArgs pe) { row_num = 0; page_no = 0; }; print_doc.PrintPage += delegate(object obj_sender, PrintPageEventArgs pe) { bool is_new_page = true; page_no++; using (Font font = new Font("tahoma", 8f)) { using (SolidBrush brush = new SolidBrush(Color.Black)) { using (Pen p = new Pen(Color.LightGray)) { int y_pos = pe.MarginBounds.Top; #region declare column width int col0_width = 40; // seq int col1_width = 70; // users_name int col2_width = 100; // real_name //int col3_width = 50; // from_time //int col4_width = 50; // to_time int col3_width = 160; // actual leave duration int col4_width = 160; // comm_deduct leave duration //int col6_width = 155; // event_code //int col7_width = 80; // status //int col8_width = 270; // customer //int col4_width = 100; // med_cert int col5_width = 100; // fine int col6_width = 160; // remark #endregion declare column width StringFormat str_format_center = new StringFormat(); str_format_center.Alignment = StringAlignment.Center; str_format_center.LineAlignment = StringAlignment.Center; StringFormat str_format_right = new StringFormat(); str_format_right.Alignment = StringAlignment.Far; str_format_right.LineAlignment = StringAlignment.Center; StringFormat str_format_left = new StringFormat(); str_format_left.Alignment = StringAlignment.Near; str_format_left.LineAlignment = StringAlignment.Center; y_pos += 5; #region Report Header using (Font h_font = new Font("tahoma", 11f, FontStyle.Bold)) { pe.Graphics.DrawString("สรุปวันลา (สำหรับคิดค่าคอมฯ)", h_font, brush, new Rectangle(10, y_pos, 300, 20)); } using (Font p_font = new Font("tahoma", 7f)) { pe.Graphics.DrawString("หน้า : " + page_no.ToString(), p_font, brush, new Rectangle(640, y_pos, 150, 20), str_format_right); } y_pos += 25; pe.Graphics.DrawString("รหัสพนักงาน จาก ", font, brush, new Rectangle(10, y_pos, 100, 20)); pe.Graphics.DrawString(" : " + this.lblUserFrom.Text, font, brush, new Rectangle(110, y_pos, 100, 20)); pe.Graphics.DrawString(" ถึง ", font, brush, new Rectangle(210, y_pos, 30, 20)); pe.Graphics.DrawString(" : " + this.lblUserTo.Text, font, brush, new Rectangle(240, y_pos, 100, 20)); y_pos += 20; pe.Graphics.DrawString("วันที่ จาก ", font, brush, new Rectangle(10, y_pos, 100, 20)); pe.Graphics.DrawString(" : " + this.lblDateFrom.Text, font, brush, new Rectangle(110, y_pos, 100, 20)); pe.Graphics.DrawString(" ถึง ", font, brush, new Rectangle(210, y_pos, 30, 20)); pe.Graphics.DrawString(" : " + this.lblDateTo.Text, font, brush, new Rectangle(240, y_pos, 100, 20)); y_pos += 20; #endregion Report Header for (int i = row_num; i < this.users_list.Count; i++) { int x_pos = 10; if (y_pos > pe.MarginBounds.Bottom) { pe.HasMorePages = true; return; } else { pe.HasMorePages = false; } #region draw column header if (is_new_page) // column header { using (Pen pen_darkgray = new Pen(Color.DarkGray)) { pe.Graphics.FillRectangle(new SolidBrush(Color.LightBlue), new RectangleF(x_pos, y_pos, 790, 25)); pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos + 790, y_pos); // horizontal line upper pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator pe.Graphics.DrawString("ลำดับ", font, brush, new Rectangle(x_pos, y_pos, col0_width, 25), str_format_center); x_pos += col0_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator pe.Graphics.DrawString("รหัสพนักงาน", font, brush, new Rectangle(x_pos, y_pos, col1_width, 25), str_format_center); x_pos += col1_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator pe.Graphics.DrawString("ชื่อ", font, brush, new Rectangle(x_pos, y_pos, col2_width, 25), str_format_center); x_pos += col2_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator pe.Graphics.DrawString("จำนวนวันลา (จริง)", font, brush, new Rectangle(x_pos, y_pos, col3_width, 25), str_format_center); x_pos += col3_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator pe.Graphics.DrawString("จำนวนวันลา (คิดค่าคอมฯ)", font, brush, new Rectangle(x_pos, y_pos, col4_width, 25), str_format_center); x_pos += col4_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator pe.Graphics.DrawString("หักค่าคอมฯ (บาท)", font, brush, new Rectangle(x_pos, y_pos, col5_width, 25), str_format_center); x_pos += col5_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator pe.Graphics.DrawString("หมายเหตุ", font, brush, new Rectangle(x_pos, y_pos, col6_width, 25), str_format_center); x_pos += col6_width; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos, y_pos + 25); // column separator x_pos = 10; // set x_pos again after use in header y_pos += 25; pe.Graphics.DrawLine(pen_darkgray, x_pos, y_pos, x_pos + 790, y_pos); // horizontal line below } y_pos += 7; is_new_page = false; } #endregion draw column header #region draw row data pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 20); // column separator using (SolidBrush brush_gray = new SolidBrush(Color.Gray)) { pe.Graphics.DrawString((row_num + 1).ToString(), font, brush_gray, new Rectangle(x_pos, y_pos, col0_width - 5, 18), str_format_right); x_pos += col0_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 20); // column separator } using (Font font_bold = new Font("tahoma", 8f, FontStyle.Bold)) { pe.Graphics.DrawString(this.users_list[i].username, font_bold, brush, new Rectangle(x_pos + 5, y_pos, col1_width - 5, 18), str_format_left); x_pos += col1_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 20); // column separator } pe.Graphics.DrawString(this.users_list[i].name, font, brush, new Rectangle(x_pos + 5, y_pos, col2_width - 5, 18), str_format_left); x_pos += col2_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 20); // column separator //using (SolidBrush brush_gray = new SolidBrush(Color.Gray)) //{ pe.Graphics.DrawString(this.sorted_list.Where(s => s.users_name == this.users_list[i].username).Where(s => s.event_type == EventCalendar.EVENT_TYPE_ABSENT_CAUSE).ToList<EventCalendar>().GetSummaryLeaveDayString(), font, brush, new Rectangle(x_pos, y_pos, col3_width, 18), str_format_center); x_pos += col3_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 20); // column separator //} using (Font font_bold = new Font("tahoma", 8f, FontStyle.Bold)) { pe.Graphics.DrawString(this.sorted_list.Where(s => s.users_name == this.users_list[i].username).Where(s => s.event_type == EventCalendar.EVENT_TYPE_ABSENT_CAUSE).ToList<EventCalendar>().GetSummaryLeaveDayStringForCommission(), font_bold, brush, new Rectangle(x_pos, y_pos, col4_width, 18), str_format_center); x_pos += col4_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 20); // column separator } string fine = (this.sorted_list.Where(s => s.users_name == this.users_list[i].username).Where(s => s.event_type == EventCalendar.EVENT_TYPE_ABSENT_CAUSE).ToList<EventCalendar>().GetSummaryFine() == 0 ? "" : this.sorted_list.Where(s => s.users_name == this.users_list[i].username).Where(s => s.event_type == EventCalendar.EVENT_TYPE_ABSENT_CAUSE).ToList<EventCalendar>().GetSummaryFine().ToString()); pe.Graphics.DrawString(fine, font, brush, new Rectangle(x_pos, y_pos, col5_width - 5, 18), str_format_right); x_pos += col5_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 20); // column separator pe.Graphics.DrawString(this.sorted_list.Where(s => s.users_name == this.users_list[i].username).Where(s => s.event_type == EventCalendar.EVENT_TYPE_ABSENT_CAUSE).ToList<EventCalendar>().GetSummaryMedCertRemark(), font, brush, new Rectangle(x_pos + 5, y_pos, col6_width - 5, 18), str_format_left); x_pos += col6_width; pe.Graphics.DrawLine(p, x_pos, y_pos - 6, x_pos, y_pos + 20); // column separator // Horizontal line x_pos = 10; pe.Graphics.DrawLine(p, x_pos, y_pos + 20, x_pos + 790, y_pos + 20); #endregion draw row data row_num++; y_pos += 25; } } } } }; if (wind.output == PrintOutputSelection.OUTPUT.PRINTER) { PrintDialog print_dialog = new PrintDialog(); print_dialog.Document = print_doc; print_dialog.AllowSelection = false; print_dialog.AllowSomePages = true; print_dialog.AllowPrintToFile = false; print_dialog.AllowCurrentPage = false; print_dialog.UseEXDialog = true; if (print_dialog.ShowDialog() == DialogResult.OK) { print_doc.Print(); } } if (wind.output == PrintOutputSelection.OUTPUT.SCREEN) { PrintPreviewDialog preview_dialog = new PrintPreviewDialog(); preview_dialog.SetBounds(this.ClientRectangle.X + 5, this.ClientRectangle.Y + 5, this.ClientRectangle.Width - 10, this.ClientRectangle.Height - 10); preview_dialog.Document = print_doc; preview_dialog.MdiParent = this.main_form; preview_dialog.Show(); } if (wind.output == PrintOutputSelection.OUTPUT.FILE) { } } else { print_doc = null; page_setup = null; } }