Using system.windows.forms; using system.drawing; using system.data; using system.collections; using datalibrary;
namespace ControlLibrary {///
public int bodylength {get {if (this.PageNumber public DataGridPrinter (DataGrid aGrid, PrintDocument aPrintDocument, string theform, int Header, int Footer) {// // TODO: Add constructor logic here // this.header = Header; this.footer = Footer; this.showfooter = true; TheDataGrid = aGrid; ThePrintDocument = aPrintDocument; if (theform = "!") {DataCatena1 = new DataCatena (); DataView myDV = DataCatena1.GetDataView ( "select * from yh_bbdy where bm = '" theform "'"); THIS.PAPERNAME = MYDV [0] ["zm"]. TOSTRING (); PAPERSIZE PKSIZE; IF (MYDV [0] ["fx"]. TOSTRING () == "true") this.TheprintDocument.defaultpagesettings.landscape = true; else this.theprintDocument.defaultpagesettings.landscape = false; int found = 0; for (int i = 0; i IF (true (this.theprintDocument.defaultpagesettings.landscape) {pageheight = int32.parse (MyDV [0] ["zk"]. TOSTRING ()); PageWidth = Int32.Parse (MyDV [0] [ZC "].} else {pagewidth = int32.parse (MyDV [0] [" zk "]. Tostring ()); PageHeight = Int32.Parse (MyDV [0] [" zc "] .Tostring ());}} TopMargin = int32.parse (MyDV [0] ["SK"]. TOSTRING ()); bottommargin = int32.parse (MyDV [0] ["xk"]. TOSTRING ()); Right Margin = Int32.Parse (MyDV [ 0] [ "rightk"] ToString ());. LeftMargin = Int32.Parse (myDV [0] [ "leftk"] ToString (.));} else {PageWidth = ThePrintDocument.DefaultPageSettings.PaperSize.Width; PageHeight = ThePrintDocument .DefaultPageSettings.PaperSize.Height; TopMargin = ThePrintDocument.DefaultPageSettings.Margins.Top; BottomMargin = ThePrintDocument.DefaultPageSettings.Margins.Bottom; RightMargin = ThePrintDocument.DefaultPageSettings.Margins.Right; LeftMargin = ThePrintDocument.DefaultPageSettings.Margins.Left;} PageWidth - = this.Leftmargin; pageWidth - = this.rightmargin; THIS.ROWS_PAGE = ("this.pageheight-this.topmargin-this.bottommargin-this.footer-this.header) / (theDataGrid.font.sizeinpoints kverticalcellleeway); for (int k = 0; k } public void DrawHeader (Graphics g) {SolidBrush ForeBrush = new SolidBrush (TheDataGrid.HeaderForeColor); SolidBrush BackBrush = new SolidBrush (Color.White); //(TheDataGrid.HeaderBackColor); Pen TheLinePen = new Pen (TheDataGrid.GridLineColor, 1) ; StringFormat cellformat = new StringFormat (); cellformat.Trimming = StringTrimming.EllipsisCharacter; cellformat.FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.LineLimit; cellformat.Alignment = StringAlignment.Center; INT columnWidth = 0; INT INITIALROWCOUNT = ROWCOUNT; // Draw the table header float startXposition = this.leftmargin; //tagetaGrid.location.x; Rectanglef nextcellbounds = new Rectanglef (0, 0, 0, 0); / * This section is the code for drawing the top color Rectanglef HeaderBounds = New Rectanglef (0, 0, 0, 0); HeaderBounds.X = this.LeftMargin; //TheDataGrid.Location.X; HeaderBounds.Y = (RowCount - initialRowCount) * (TheDataGrid.Font.SizeInPoints kVerticalCellLeeway); HeaderBounds.Height = TheDataGrid.Font.SizeInPoints kVerticalCellLeeway; HeaderBounds .Width = PageWidth; * / float y1 = (float) (Header this.topmargin); g.DrawLine (TheLinePen, this.LeftMargin, y1, this.LeftMargin this.PageWidth, y1); y1 = y1 (float) (TheDataGrid.Font.SizeInPoints kVerticalCellLeeway); g.DrawLine (TheLinePen, this.LeftMargin, y1 , this.Leftmargin this.pageWidth, Y1); // g.FillRectangle (Backbrush, HeaderBounds); for (int k = 0; k string nextcolumn = TheDataGrid.TableStyles [0] .GridColumnStyles [k] .HeaderText; // TheTable.Columns [k] .ToString (); (RowCount - initialRowCount) * (TheDataGrid.Font.SizeInPoints kVerticalCellLeeway) RectangleF cellbounds = new Rectanglef (StartXposition, Header TopMargin 2, ColumnWidth, THEDATAGRID.HEADERFONT.SIIZEINPOINTS KVERTICALLLLEWAY-2); Nextcellbounds = Cellbounds; if (startxposition columnwidth <= PageWidth this.LeftMargin) {g.DrawString (nextcolumn, TheDataGrid.HeaderFont, ForeBrush, cellbounds, cellformat);} startxposition = startxposition columnwidth; } Y1 = y1 (float) (TheDataGrid.Font.SizeInPoints kVerticalCellLeeway); g.DrawLine (TheLinePen, this.LeftMargin, y1, this.LeftMargin this.PageWidth, y1);! // if (TheDataGrid.GridLineStyle = DataGridLineStyle .None) // g.drawline (theLinepen, THEDATAGRID.LOCATION.X, NextCellbounds.bottom, PageWidth, Nextcellbounds.Bottom); Public void setDataSource (DataTable Atable) {THHISABLE = ATABLE; this.pageCount = (int) Math.ceiling (THIS.ROWS.COUNT) / (THIS.ROWS_PAGE)); // MessageBox.show "ROWS_COUNT:" THHETABLE.ROWS.COUNT.TOSTRING () "ROWS_PAGE:" ROWS_PAGE.TOSTRING () "Page_count:" this.pagecount.tostring ()); // this.theprintDocument} Public Bool DrawROWS (GRAPHICS G) {INT LASTROWBOTTOM = TopMargin; LINES.CLEAR (); try {SolidBrush ForeBrush = new SolidBrush (TheDataGrid.ForeColor); SolidBrush BackBrush = new SolidBrush (TheDataGrid.BackColor); SolidBrush AlternatingBackBrush = new SolidBrush (TheDataGrid.AlternatingBackColor); Pen TheLinePen = new Pen (TheDataGrid.GridLineColor, 1); StringFormat cellformat = new StringFormat (); cellformat.Trimming = StringTrimming.EllipsisCharacter; cellformat.FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.LineLimit; int columnwidth = PageWidth / TheDataGrid.TableStyles [0] .GridColumnStyles.Count; INT INITIALROWCOUNT = (this.pagenumber-1) * this.rows_page; int endrow = initialrowcount this.rows_page; Rectanglef Rowbounds = New Rectanglef (0, 0, 0, 0); // DRAW VERTICAL LINES // Draw the rows of the table for for (INT i = I ) {DATAROW DR = THETABLE.ROWS [I]; int startXposition = this.leftmargin 2; / / The-etiTAGrid.location.x; RowBounds.X = 0; RowBounds.Y = header TopMargin ((RowCount - initialRowCount) 1) * (TheDataGrid.Font.SizeInPoints kVerticalCellLeeway); RowBounds.Height = TheDataGrid.Font.SizeInPoints kVerticalCellLeeway; RowBounds.Width = PageWidth; / * /// This section is the code IF (I% 2 == 0) of the drawing table, {g.fillRectangle (backbrush, rowbounds);} else {g.fillRectangle (alternatingbackbrush, rowbounds);} * / for (int j = 0; j if (startxposition columnwidth <= PageWidth) {g.DrawString (dr [(TheDataGrid.TableStyles [0] .GridColumnStyles [j] .MappingName)] ToString (), TheDataGrid.Font, ForeBrush, cellbounds, cellformat.);} STARTXPSITION = StartXPosition ColumnWidth 2; Lines.Add (Rowbounds.Bottom); Lastrowbottom = (int) Rowbounds.bottom; Rowcount ;} Drawhorzontallines (G, Lines); DrawvertageGridLines (G, THELINEPEN, LASTROWBOTTOM); if (this.showfooter == true) DrawFooter (G); IF (THIS.PAGENUMBER } Catch (exception ex) {messagebox.show (ex.Message.toString ()); Return false;} } Void Drawfooter (Graphics G) {FontFamily Fontfamily = New FontFamily ("Song"); String text = "第" this.pagenumber.tostring () "page total" this.pageCount.toString () "page"; Font font = new font (FontFamily, 10, FontStyle.Regular, GraphicsUnit.Point); Sizef size = g.MeasureString (Text, font); Int Startpos = this.pageheight - height - height - height - height - height - height - height - height - height - height; Solidbrush Forebrush = New Solidbrush (Color.Black); StringFormat CellFormat = new stringFormat (); g.drawstring (TEXT, FONT, Forebrush, (this.PageWidth-size.width) / 2 this.Leftmargin, StartPos, CellFormat; Text = "[cobainsoft]"; Size = g.measureString (Text, Font); g.drawstring (Text, Font, Forebrush, this.pagewidth this.leftmargin - size.width-3, startpos, cellformat); } Void Drawhorizontallines (Graphics G, ArrayList Lines) {Pen Thelinepen = New Pen (TheDataGrid.gridlineColor, 1); IF (theDataGrid.gridLinesTyle == DataGridLineStyle.none) return; INT I; For (i = 0; i } Void DrawVerticalGridLines (graphics g, pen thelinepen, int bottom) {if (theDataGrid.gridLineStyle == DataGridLineStyle.none) Return; int posx = 0; / / Draw the leftmost vertical line G. Drawline (TheLinepen, this.Leftmargin POSX, Header TopMargin, this.Left Margin POSX, BOTTOM); // Pain the rightmost vertical line g.drawline (TheLinepen, this.Leftmargin this.Pagewidth, Header TopMargin, this.pageWidth, Bottom); INT TOTAL = theseDataGrid.tablesTyles [0] .gridColumnStyles.count -1; for (int K = 0; k Public Bool DrawDataGrid (Graphics G) { Try {DrawHeader (G); Bool BContinue = DrawROWROWS (G); Return BContinue;} catch (Exception EX) {MessageBox.Show (EXMESSAGE.TOSTRING ()); Return False;} } } }