public static PrinterTable Build(DataTable dt, int rowHeight, int[] columnWidth) { int len = columnWidth.Length; PrinterTable table = new PrinterTable(); PrinterRow row = new PrinterRow(); row.Rectangle = new System.Drawing.Rectangle(0, 0, PrinterContent.PageMargin.Width, rowHeight); TextDraw text = null; int tmp = 0; for (int i = 0; i < len; i++) { text = new ColumnHeaderDraw(dt.Columns[i].ColumnName); text.Border = BordersEdgeStyle.All; text.Rectangle = new System.Drawing.Rectangle(tmp, 0, columnWidth[i], rowHeight); tmp += columnWidth[i]; row.Add(text); } table.Header = row; //table.Add(row); row = null; tmp = 0; foreach (DataRow dr in dt.Rows) { row = new PrinterRow(); row.Rectangle = new System.Drawing.Rectangle(0, 0, PrinterContent.PageMargin.Width, rowHeight); for (int i = 0; i < len; i++) { text = new TextDraw(Convert.IsDBNull(dr[i])?string.Empty:dr[i].ToString()); text.Border = BordersEdgeStyle.All; text.Rectangle = new System.Drawing.Rectangle(tmp, 0, columnWidth[i], rowHeight); tmp += columnWidth[i]; row.Add(text); } tmp = 0; table.Add(row); } return(table); }
public static PrinterTable Build(DataTable dt, int rowHeight,int[] columnWidth) { int len = columnWidth.Length; PrinterTable table = new PrinterTable(); PrinterRow row=new PrinterRow(); row.Rectangle = new System.Drawing.Rectangle(0, 0, PrinterContent.PageMargin.Width, rowHeight); TextDraw text=null; int tmp = 0; for(int i=0;i<len;i++) { text = new ColumnHeaderDraw(dt.Columns[i].ColumnName); text.Border = BordersEdgeStyle.All; text.Rectangle=new System.Drawing.Rectangle(tmp,0,columnWidth[i],rowHeight); tmp += columnWidth[i]; row.Add(text); } table.Header = row; //table.Add(row); row = null; tmp = 0; foreach (DataRow dr in dt.Rows) { row = new PrinterRow(); row.Rectangle = new System.Drawing.Rectangle(0, 0, PrinterContent.PageMargin.Width, rowHeight); for (int i = 0; i < len; i++) { text = new TextDraw(Convert.IsDBNull(dr[i])?string.Empty:dr[i].ToString()); text.Border = BordersEdgeStyle.All; text.Rectangle = new System.Drawing.Rectangle(tmp, 0, columnWidth[i], rowHeight); tmp += columnWidth[i]; row.Add(text); } tmp = 0; table.Add(row); } return table; }
public PrinterHint GetFooter(int pageWidth) { Font font = new Font("����",15); PrinterHint footer = new PrinterHint(); footer.Border = BordersEdgeStyle.None; footer.Rectangle = new Rectangle(-2, 0, pageWidth+2, 147); /*��ʱ���߳���*/ //RecetangleDraw outer = new RecetangleDraw(); TextDraw outer = new TextDraw(" "); outer.Font = font; outer.Border = BordersEdgeStyle.All; outer.Rectangle = new Rectangle(-1, 0, pageWidth +2, 3 * 34); TextDraw inner = new TextDraw(" "); inner.Font = font; inner.Border = BordersEdgeStyle.All; //RecetangleDraw inner = new RecetangleDraw(); inner.Rectangle = new Rectangle(2, 3, pageWidth -4, 3 * 34-5); /*��ʱ���߳���*/ footer.Add(outer); footer.Add(inner); StringFormat sf = new StringFormat(); sf.LineAlignment = StringAlignment.Center; sf.Alignment = StringAlignment.Center; TextDraw txt1 = new TextDraw("����Ա"); txt1.Font = font; txt1.Rectangle = new Rectangle(2, 3, footerWidth, footer1Height); txt1.Border = BordersEdgeStyle.Right; txt1.Formater = sf; footer.Add(txt1); TextDraw txt2 = new TextDraw("ǩ��"); txt2.Font = font; txt2.Rectangle = new Rectangle(2, footer1Height+3, footerWidth, footer1Height); txt2.Border = BordersEdgeStyle.Right; txt2.Formater = sf; footer.Add(txt2); RecetangleDraw space1 = new RecetangleDraw(); space1.Rectangle = new Rectangle(2 + footerWidth, 3, spaceWidth, 2 * footer1Height); space1.Border = BordersEdgeStyle.Right; footer.Add(space1); TextDraw txt3 = new TextDraw("����Ա"); txt3.Font = font; txt3.Rectangle = new Rectangle(2 + spaceWidth + footerWidth, 3, footerWidth, footer1Height); txt3.Border = BordersEdgeStyle.Right; txt3.Formater = sf; footer.Add(txt3); TextDraw txt4 = new TextDraw("ǩ��"); txt4.Font = font; txt4.Rectangle = new Rectangle(2 + spaceWidth + footerWidth, footer1Height + 3, footerWidth, footer1Height); txt4.Border = BordersEdgeStyle.Right; txt4.Formater = sf; footer.Add(txt4); RecetangleDraw space2 = new RecetangleDraw(); space2.Rectangle = new Rectangle(2 + 2 * footerWidth + spaceWidth, 3, spaceWidth, 2 * footer1Height); space2.Border = BordersEdgeStyle.Right; footer.Add(space2); TextDraw txt5 = new TextDraw("����Ա"); txt5.Font = font; txt5.Rectangle = new Rectangle(2 + 2 * (spaceWidth + footerWidth), 3, footerWidth, footer1Height); txt5.Border = BordersEdgeStyle.Right; txt5.Formater = sf; footer.Add(txt5); TextDraw txt6 = new TextDraw("ǩ��"); txt6.Font = font; txt6.Rectangle = new Rectangle(2 + 2 * (spaceWidth + footerWidth), footer1Height + 3, footerWidth, footer1Height); txt6.Border = BordersEdgeStyle.Right; txt6.Formater = sf; footer.Add(txt6); RecetangleDraw space3 = new RecetangleDraw(); space3.Rectangle = new Rectangle(2 + 3 * footerWidth + 2 * spaceWidth, 3, spaceWidth - 10, footer1Height*2); space3.Border = BordersEdgeStyle.Right; footer.Add(space3); TextDraw txt7 = new TextDraw("�����"); txt7.Font = font; txt7.Rectangle = new Rectangle(2 + 3 * (spaceWidth + footerWidth) - 10, 3, footerWidth - 6, footer1Height*2); txt7.Border = BordersEdgeStyle.Right; txt7.Formater = sf; footer.Add(txt7); TextDraw txt8 = new TextDraw("����������_______"); txt8.Font = font; txt8.Rectangle = new Rectangle(2, 3 + 2*footer1Height, footerWidth2, 45); footer.Add(txt8); TextDraw txt9 = new TextDraw("�ϸ�������_______"); txt9.Font = font; txt9.Rectangle = new Rectangle(2 + footerWidth2, 3 + 2 * footer1Height, footerWidth2, 45); footer.Add(txt9); TextDraw txt10 = new TextDraw("���ϸ�������_____"); txt10.Font = font; txt10.Rectangle = new Rectangle(2 + 2 * footerWidth2, 3 + 2 * footer1Height, footerWidth2, 45); footer.Add(txt10); TextDraw txt11 = new TextDraw("ȱ��������______"); txt11.Font = font; txt11.Rectangle = new Rectangle(2 + 3 * footerWidth2, 3 + 2 * footer1Height, pageWidth - 4 - 3 * footerWidth2, 45); footer.Add(txt11); TextDraw text = new TextDraw(" ע���˱���д��ȫ�������������д����Ϳ����Ч��"); text.Border = BordersEdgeStyle.None; text.Font = font; text.Rectangle = new Rectangle(0, 102, pageWidth, 40); footer.Add(text); footer.PrintInEveryPage = true; return footer; }
private void button1_Click(object sender, EventArgs e) { this.dataGridView1.EndEdit(); PrintCommonSetting.Default_Border_Style = BordersEdgeStyle.All; //if (this.dataGridView1.Rows.Count == 0) //{ //MessageBoxHelper.Show("���������Ҫ��ӡ��ѧԱ��"); //} StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; int rowHeight = 34; PageMargin margin = new PageMargin(); margin.Left = 35; margin.Right = 35; //margin.Bottom = 36; //margin.Top = 37; margin.Bottom = 40; margin.Top = 33; PrinterContent content = new PrinterContent(); content.CustomPageMargin = margin; PrinterHint header = this.GetHeader(content.CustomPageMargin.Width, this.comboBox1.Text); //header.Rectangle = new Rectangle((content.CustomPageMargin.Width - header.Rectangle.Width), 0, header.Rectangle.Width, header.Rectangle.Height); content.Header = header; content.IsPrinterPages = false; int[] columnWidth ={ 60, 90, 90,60, 184, 135,60, content.CustomPageMargin.Width - 679 }; string[] columnHeader ={ "���", "����", "����", "�Ա�", "���֤������", "��֤����", "�ɼ�", "��ע" }; int len = columnWidth.Length; PrinterTable table = new PrinterTable(); PrinterRow row = new PrinterRow(); row.Rectangle = new System.Drawing.Rectangle(0, 0, content.CustomPageMargin.Width, 43); TextDraw text = null; int tmp = 0; Font col = new Font("����",15); for (int i = 0; i < len; i++) { text = new TextDraw(columnHeader[i]); text.Formater = sf; text.Font = col; text.Border = BordersEdgeStyle.All; text.Rectangle = new System.Drawing.Rectangle(tmp, 0, columnWidth[i], 43); tmp += columnWidth[i]; row.Add(text); } table.Header = row; //table.Add(row); row = null; DataRow dr = null; string tmpCarType = string.Empty; // DataTable dt = this.MockData(); DataTable dt = this.GetDataFromGrid(); if (dt.Rows.Count == 0) { for (int i = 0; i < 24; i++) { dt.Rows.Add(new string[] { string.Empty, string.Empty, string.Empty, string.Empty, string.Empty }); } } else { int tmprowcount = dt.Rows.Count % 24; if (tmprowcount != 0) { tmprowcount = 24 - tmprowcount; for (int i = 0; i < tmprowcount; i++) { dt.Rows.Add(new string[] { string.Empty, string.Empty, string.Empty, string.Empty, string.Empty }); } } } for (int j = 0; j < dt.Rows.Count; j++) { dr = dt.Rows[j]; tmp = 0; row = new PrinterRow(); row.Rectangle = new System.Drawing.Rectangle(0, 0, content.CustomPageMargin.Width, rowHeight); text = new TextDraw(((j + 1)%24==0?24:(j+1)%24).ToString()); text.Formater = sf; text.Border = BordersEdgeStyle.All; text.Rectangle = new System.Drawing.Rectangle(tmp, 0, columnWidth[0], rowHeight); tmp += columnWidth[0]; row.Add(text); tmpCarType = dr[3].ToString(); for (int i = 1; i < len; i++) { text = new TextDraw(Convert.IsDBNull(dr[i - 1]) ? string.Empty : dr[i - 1].ToString()); text.Border = BordersEdgeStyle.All; text.Formater = sf; text.Rectangle = new System.Drawing.Rectangle(tmp, 0, columnWidth[i], rowHeight); tmp += columnWidth[i]; row.Add(text); } table.Add(row); } table.Border = BordersEdgeStyle.None; content.Body = table; PrinterHint footer = this.GetFooter(content.CustomPageMargin.Width); content.Footer = footer; content.PrinterSetting(); //content.Preview(); }
public PrinterHint GetHeader(int pagewidth,string text) { int captionHeight = 45; Font font = new Font("����",20); Graphics g=this.button1.CreateGraphics(); int height=(int)g.MeasureString(text, font).Height; int width = (int)g.MeasureString(text, font).Width; g.Dispose(); PrinterHint header = new PrinterHint(); header.Rectangle = new Rectangle(0, 0, pagewidth, height + captionHeight+12); header.PrintInEveryPage = true; header.Border = BordersEdgeStyle.None; TitleDraw title = new TitleDraw(text); title.Font = font; title.Rectangle = new Rectangle((pagewidth-width)/2, 0, width, height); title.Border = BordersEdgeStyle.Bottom; TitleDraw line = new TitleDraw(""); line.Rectangle = new Rectangle((pagewidth - width) / 2, 2, width, height); line.Border = BordersEdgeStyle.Bottom; header.Add(title); header.Add(line); StringFormat sf = new StringFormat(); sf.LineAlignment = StringAlignment.Far; Font cap = new Font("����", 14); TextDraw header2 = new TextDraw("��ѵ��λ�� �������ͣ� �������ڣ� �� �� ��"); header2.Formater = sf; header2.Font = cap; header2.Rectangle = new Rectangle(0, height + 7, pagewidth, captionHeight); header2.Border = BordersEdgeStyle.None; CompanyInfo compInfo = StaticCacheManager.GetConfig<CompanyInfo>(); TextDraw comp = new TextDraw(compInfo.NickName); comp.Formater = sf; comp.Font = cap; comp.Rectangle = new Rectangle(100, height + 7, 200, captionHeight); comp.Border = BordersEdgeStyle.None; header.Add(comp); header.Add(header2); return header; }
/// <summary> /// dt���б����widths�����ж�һ�У����һ���ɴ�ӡ�Լ�����ʣ��� /// </summary> /// <param name="dt"></param> /// <param name="widths"></param> /// <returns></returns> protected PrinterTable BuildContent(DataTable dt, int[] widths) { StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; int all = 0; int[] columnWidth=new int[widths.Length+1]; for (int i = 0; i < widths.Length; i++) { columnWidth[i]=widths[i]; all+=widths[i]; } columnWidth[widths.Length] = customMargin.Width - all; //string[] columnHeader ={ "���", "����", "����", "�Ա�", "���֤������", "��֤����", "�ɼ�", "��ע" }; int len = columnWidth.Length; PrinterTable table = new PrinterTable(); PrinterRow row = new PrinterRow(); int tmp = 0; TextDraw text = null; int rowHeight = 20; if (this.isPrintColName) { row.Rectangle = new System.Drawing.Rectangle(0, 0, customMargin.Width, 43); Font coltitle = new Font("����", 12, FontStyle.Bold); for (int i = 0; i < len; i++) { text = new TextDraw(dt.Columns[i].ColumnName); text.Formater = sf; text.Font = coltitle; text.Border = BordersEdgeStyle.All; text.Rectangle = new System.Drawing.Rectangle(tmp, 0, columnWidth[i], 43); tmp += columnWidth[i]; row.Add(text); } table.Header = row; } //table.Add(row); row = null; Font col = new Font("����", 10); DataRow dr = null; for (int j = 0; j < dt.Rows.Count; j++) { dr = dt.Rows[j]; tmp = 0; row = new PrinterRow(); row.Rectangle = new System.Drawing.Rectangle(0, 0, customMargin.Width, rowHeight); for (int i = 0; i < len; i++) { text = new TextDraw(Convert.IsDBNull(dr[i]) ? string.Empty : dr[i].ToString()); text.Border = BordersEdgeStyle.All; text.Font = col; text.Formater = sf; text.Rectangle = new System.Drawing.Rectangle(tmp, 0, columnWidth[i], rowHeight); tmp += columnWidth[i]; row.Add(text); } table.Add(row); } table.Border = BordersEdgeStyle.None; return table; }