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 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 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 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; } }
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; } }
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; } }