·ÖÀà

  • Èí¼þÌìµØ

  • ʹÓÃ.NET×Ô´øµÄÀàʵÏÖDataGrid±¨±íµÄ´òÓ¡¡¬
    ¡¡¡¡namespace ControlLibrary                              
    ¡¡¡¡{                                                                            
    ¡¡¡¡ ///

    ¡¡¡¡ /// DataGrid´òÓ¡                                                
    ¡¡¡¡ ///

    ¡¡¡¡ public class DataGridPrinter                    
    ¡¡¡¡ {                                                                          

    ¡¡¡¡¡¡private PrintDocum
    ent ThePrintDocument;
    ¡¡¡¡¡¡private DataTable TheTable;                      
    ¡¡¡¡¡¡private DataGrid¡¡TheDataGrid;                  
    ¡¡¡¡¡¡public int RowCount = 0;                            

    ¡¡¡¡¡¡private const int
    kVerticalCellLeeway = 10;
    ¡¡¡¡¡¡public int PageNumber = 1;                        

    ¡¡¡¡¡¡public ArrayList L
    ines = new ArrayList();
    ¡¡¡¡¡¡public int header=0;                                    
    ¡¡¡¡¡¡public int footer=0;                                    
    ¡¡¡¡¡¡DataCatena DataCatena1;                              
    ¡¡¡¡¡¡public int PageWidth;                                  
    ¡¡¡¡¡¡public int PageHeight;                                
    ¡¡¡¡¡¡public int TopMargin;                                  
    ¡¡¡¡¡¡public int BottomMargin;                            
    ¡¡¡¡¡¡int GridWidth = 0;                                        
    ¡¡¡¡¡¡public int LeftMargin;                                
    ¡¡¡¡¡¡public int RightMargin;                              
    ¡¡¡¡¡¡public string PaperName;                            
    ¡¡¡¡¡¡public int pagecount;                                  
    ¡¡¡¡¡¡private int rows_page;                                
    ¡¡¡¡¡¡public bool showfooter;                              

    ¡¡¡¡¡¡public int bodylength                                  
    ¡¡¡¡¡¡{                                                                          
    ¡¡¡¡¡¡ get                                                                    
    ¡¡¡¡¡¡ {                                                                        
    ¡¡¡¡¡¡¡¡if(this.PageNumber

    ¡¡¡¡¡¡¡¡ return (1+this.rows_page) *
    kVerticalCellLeeway);
    ((int)(TheDataGrid.Font.SizeInPoints)¡¡+

    ¡¡¡¡¡¡¡¡else                                                                  
    ¡¡¡¡¡¡¡¡ return (this.TheTable.Rows.
    ge*(this.PageNumber-1))) * ( (int)
    Count + 1 -(this.rows_pa

    ¡¡¡¡¡¡¡¡(TheDataGrid.Fon
    t.SizeInPoints)¡¡+ kVertical
    CellLeeway);
    ¡¡¡¡¡¡ }                                                                        
    ¡¡¡¡¡¡}                                                                          

    ¡¡¡¡¡¡public DataGridPrinter(DataGri
    theform,int Header,int Footer)
    d aGrid, PrintDocument aPrintDocument,string

    ¡¡¡¡¡¡{                                                                          
    ¡¡¡¡¡¡ //                                                                      
    ¡¡¡¡¡¡ // 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=Da
    bm='"+theform +"'");
    taCatena1.GetDataView("selec

    t * from yh_bbdy where



    ¡¡¡¡¡¡¡¡this.PaperName=m
    yDV[0]["zm"].ToString();

    ¡¡¡¡¡¡¡¡PaperSize pkSize;                                        

    ¡¡¡¡¡¡¡¡if(myDV[0]["fx"].ToString()=="True")  
    ¡¡¡¡¡¡¡¡ this.ThePrintDo
    cument.DefaultPageSettings.L
    andscape=true;
    ¡¡¡¡¡¡¡¡else                                                                  
    ¡¡¡¡¡¡¡¡ this.ThePrintDocument.Defau
    ltPageSettings.Landscape=false;

    ¡¡¡¡¡¡¡¡int found=0;                                                  
    ¡¡¡¡¡¡¡¡for (int i = 0; i < this.ThePrintDocument.PrinterSettings.PaperSizes.Count; i++)

    ¡¡¡¡¡¡¡¡{                                                                        
    ¡¡¡¡¡¡¡¡ pkSize = this.ThePrintDocum
    ent.PrinterSettings.PaperSizes[i];
    ¡¡¡¡¡¡¡¡ if(pkSize.PaperName==this.PaperName)
    ¡¡¡¡¡¡¡¡ {                                                                      
    ¡¡¡¡¡¡¡¡¡¡this.ThePrintD
    ocument.DefaultPageSettings.
    PaperSize=pkSize;
    ¡¡¡¡¡¡¡¡¡¡found=1;                                                        
    ¡¡¡¡¡¡¡¡¡¡i=this.ThePrin
    tDocument.PrinterSettings.Pa
    perSizes.Count;
    ¡¡¡¡¡¡¡¡¡¡if(this.ThePrintDocument.D
    efaultPageSettings.Landscape)
    ¡¡¡¡¡¡¡¡¡¡{                                                                      
    ¡¡¡¡¡¡¡¡¡¡ PageHeight = pkSize.Width;                  
    ¡¡¡¡¡¡¡¡¡¡ PageWidth = pkSize.Height;                  
    ¡¡¡¡¡¡¡¡¡¡}                                                                      
    ¡¡¡¡¡¡¡¡¡¡else                                                                
    ¡¡¡¡¡¡¡¡¡¡{                                                                      
    ¡¡¡¡¡¡¡¡¡¡ PageWidth = pkSize.Width;                    
    ¡¡¡¡¡¡¡¡¡¡ PageHeight = pkSize.Height;                
    ¡¡¡¡¡¡¡¡¡¡}                                                                      
    ¡¡¡¡¡¡¡¡ }                                                                      
    ¡¡¡¡¡¡¡¡}                                                                        

    ¡¡¡¡¡¡¡¡if(found==0)                                                  
    ¡¡¡¡¡¡¡¡{                                                                        
    ¡¡¡¡¡¡¡¡ if(this.ThePrin
    tDocument.DefaultPageSetting
    s.Landscape)
    ¡¡¡¡¡¡¡¡ {                                                                      
    ¡¡¡¡¡¡¡¡¡¡PageHeight = I
    nt32.Parse(myDV[0]["zk"].ToS
    tring());
    ¡¡¡¡¡¡¡¡¡¡PageWidth = Int32.Parse(my
    DV[0]["zc"].ToString());
    ¡¡¡¡¡¡¡¡ }                                                                      
    ¡¡¡¡¡¡¡¡ else                                                                
    ¡¡¡¡¡¡¡¡ {                                                                      
    ¡¡¡¡¡¡¡¡¡¡PageWidth = In
    t32.Parse(myDV[0]["zk"].ToSt
    ring());
    ¡¡¡¡¡¡¡¡¡¡PageHeight = Int32.Parse(m
    yDV[0]["zc"].ToString());
    ¡¡¡¡¡¡¡¡ }                                                                      
    ¡¡¡¡¡¡¡¡}                                                                        

    ¡¡¡¡¡¡¡¡TopMargin = Int3
    2.Parse(myDV[0]["sk"].ToStri
    ng());
    ¡¡¡¡¡¡¡¡BottomMargin = I
    nt32.Parse(myDV[0]["xk"].ToS
    tring());
    ¡¡¡¡¡¡¡¡RightMargin = Int32.Parse(my
    DV[0]["rightk"].ToString());
    ¡¡¡¡¡¡¡¡LeftMargin = Int
    32.Parse(myDV[0]["leftk"].To
    String());
    ¡¡¡¡¡¡ }                                                                        
    ¡¡¡¡¡¡ else                                                                  
    ¡¡¡¡¡¡ {                                                                        
    ¡¡¡¡¡¡¡¡PageWidth = ThePrintDocument
    .DefaultPageSettings.PaperSize.Width;
    ¡¡¡¡¡¡¡¡PageHeight = ThePrintDocumen
    t.DefaultPageSettings.PaperSize.Height;
    ¡¡¡¡¡¡¡¡TopMargin = TheP
    rintDocument.DefaultPageSett
    ings.Margins.Top;
    ¡¡¡¡¡¡¡¡BottomMargin = T
    hePrintDocument.DefaultPageS
    ettings.Margins.Bottom;
    ¡¡¡¡¡¡¡¡RightMargin = ThePrintDocume
    nt.DefaultPageSettings.Margins.Right;
    ¡¡¡¡¡¡¡¡LeftMargin = ThePrintDocumen
    t.DefaultPageSettings.Margins.Left;
    ¡¡¡¡¡¡ }                                                                        

    ¡¡¡¡¡¡ PageWidth -= this.LeftMargin ;              
    ¡¡¡¡¡¡ PageWidth -= this.RightMargin;              

    ¡¡¡¡¡¡ this.rows_page=(i
    his.BottomMargin-this.fo
    nt)((float)(this.PageHeight-
    oter-this.header)
    this.TopMargin-t

    ¡¡¡¡¡¡ /(TheDataGrid.Fon
    t.SizeInPoints + kVerticalCe
    llLeeway));

    ¡¡¡¡¡¡ for (int k = 0; k < TheDataGrid.TableStyles[0].GridColumnStyles.Count; k++)

    ¡¡¡¡¡¡ {                                                                        
    ¡¡¡¡¡¡¡¡GridWidth += The
    TheTable.Columns[k].ToSt
    DataGrid.TableStyles[0].Grid
    ring();
    ColumnStyles[k].Width;¡¡//¡¡

    ¡¡¡¡¡¡ }                                                                        

    ¡¡¡¡¡¡}                                                                          

    ¡¡¡¡¡¡public void DrawHeader(Graphics g)        
    ¡¡¡¡¡¡{                                                                          
    ¡¡¡¡¡¡ SolidBrush ForeBr
    ush = new SolidBrush(TheData
    Grid.HeaderForeColor);
    ¡¡¡¡¡¡ SolidBrush BackBr
    ataGrid.HeaderBackColor)
    ush = new SolidBrush(Color.W
    ;
    hite);¡¡ //(TheD

    ¡¡¡¡¡¡ Pen TheLinePen = new Pen(TheD
    ataGrid.GridLineColor, 1);

    ¡¡¡¡¡¡ StringFormat cell
    format = new StringFormat();
    ¡¡¡¡¡¡ cellformat.Trimmi
    ng = StringTrimming.Ellipsis
    Character;
    ¡¡¡¡¡¡ cellformat.FormatFlags = Stri
    tringFormatFlags.LineLimit;
    ngFormatFlags.NoWrap | S


    ¡¡¡¡¡¡ cellformat.Alignm
    ent= StringAlignment.Center;


    ¡¡¡¡¡¡ int columnwidth = 0;                                  

    ¡¡¡¡¡¡ int initialRowCount = RowCount;            

    ¡¡¡¡¡¡ // draw the table header                          
    ¡¡¡¡¡¡ float startxposition = this.L
    //TheDataGrid.Location.X;
    eftMargin;¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡

    ¡¡¡¡¡¡ RectangleF nextce
    llbounds = new RectangleF(0,
    0, 0, 0);

    ¡¡¡¡¡¡ /*                                                                     
    ¡¡¡¡¡¡¡¡¡¡ÕâÒ»¶ÎÊÇ»­±íÍ·µ×É«µÄ´úÂë                                                

    ¡¡¡¡¡¡¡¡¡¡RectangleF Hea
    derBounds¡¡= new RectangleF(
    0, 0, 0, 0);

    ¡¡¡¡¡¡¡¡¡¡HeaderBounds.X = this.Left
    Margin;¡¡¡¡¡¡ //TheDataGrid.Location.X;
    ¡¡¡¡¡¡¡¡¡¡HeaderBounds.Y
    aGrid.Font.SizeInPoints
    =¡¡+ (RowCount - initialRow
    ¡¡+ kVerticalCellLeeway);
    Count) * (TheDat

    ¡¡¡¡¡¡¡¡¡¡HeaderBounds.Height = TheD
    kVerticalCellLeeway;
    ataGrid.Font.SizeInPoints +

    ¡¡¡¡¡¡¡¡¡¡HeaderBounds.Width = PageWidth;          
    ¡¡¡¡¡¡ */                                                                      
    ¡¡¡¡¡¡ float y1=(float)(header+this.
    TopMargin);

    ¡¡¡¡¡¡ g.DrawLine(TheLin
    this.PageWidth, y1);
    ePen, this.LeftMargin, y1, t

    his.LeftMargin +

    ¡¡¡¡¡¡ y1=y1+ (float)(TheDataGrid.Fo
    nt.SizeInPoints + kVerticalCellLeeway);
    ¡¡¡¡¡¡ g.DrawLine(TheLinePen, this.L
    this.PageWidth, y1);
    eftMargin, y1, this.LeftMargin +


    ¡¡¡¡¡¡ //¡¡ g.FillRectangle(BackBrus
    h, HeaderBounds);

    ¡¡¡¡¡¡ for (int k = 0; k < this.TheDataGrid.TableStyles[0].GridColumnStyles.Count; k++)

    ¡¡¡¡¡¡ {                                                                        
    ¡¡¡¡¡¡¡¡columnwidth = TheDataGrid.Ta
    PageWidth / this.GridWidth;
    bleStyles[0].GridColumnStyles[k].Width *


    ¡¡¡¡¡¡¡¡string nextcolumn = TheDataG
    olumnStyles[k].HeaderText;¡¡
    rid.TableStyles[0].GridC

    ¡¡¡¡¡¡¡¡//¡¡TheTable.Col
    (TheDataGrid.Font.SizeIn
    umns[k].ToString(); + (RowCo
    Points¡¡
    unt - initialRowCount) *

    ¡¡¡¡¡¡¡¡+ kVerticalCellLeeway)                              
    ¡¡¡¡¡¡¡¡RectangleF cellb
    TopMargin+2 ,
    ounds = new RectangleF(start

    xposition, header +

    ¡¡¡¡¡¡¡¡ columnwidth,                                               
    ¡¡¡¡¡¡¡¡ TheDataGrid.HeaderFont.Size
    InPoints + kVerticalCellLeeway-2);
    ¡¡¡¡¡¡¡¡nextcellbounds = cellbounds;                  

    ¡¡¡¡¡¡¡¡if (startxposition + columnwidth <= PageWidth+this.LeftMargin)

    ¡¡¡¡¡¡¡¡{                                                                        
    ¡¡¡¡¡¡¡¡ g.DrawString(nextcolumn, Th
    cellformat);
    eDataGrid.HeaderFont, ForeBrush, cellbounds,

    ¡¡¡¡¡¡¡¡}                                                                        

    ¡¡¡¡¡¡¡¡startxposition = startxposit
    ion + columnwidth;

    ¡¡¡¡¡¡ }                                                                        
    ¡¡¡¡¡¡ y1=y1+ (float)(TheDataGrid.Fo
    nt.SizeInPoints + kVerticalCellLeeway);
    ¡¡¡¡¡¡ g.DrawLine(TheLin
    this.PageWidth, y1);
    ePen, this.LeftMargin, y1, t

    his.LeftMargin +

    ¡¡¡¡                                                                             
    ¡¡¡¡¡¡ //if (TheDataGrid.GridLineSty
    le != DataGridLineStyle.None)
    ¡¡¡¡¡¡ // g.DrawLine(TheLinePen, The
    PageWidth,
    DataGrid.Location.X, nextcellbounds.Bottom,

    ¡¡¡¡¡¡¡¡¡¡ nextcellbounds.Bottom);                        
    ¡¡¡¡¡¡}                                                                          


    ¡¡¡¡¡¡public void SetDat
    aSource(DataTable aTable)
    ¡¡¡¡¡¡{                                                                          
    ¡¡¡¡¡¡ TheTable = aTable;                                      
    ¡¡¡¡¡¡ this.pagecount=(int)Math.Ceil
    ws.Count)/(double)(this.rows_page));
    ing((double)(TheTable.Ro

    ¡¡¡¡¡¡ // MessageBox.Sho
    rows_page:"+rows_page.To
    w("rows_count:"+TheTable.Row
    String()
    s.Count.ToString()+"

    ¡¡¡¡¡¡¡¡+ "page_count:" +this.pageco
    unt.ToString());
    ¡¡¡¡¡¡ // this.ThePrintDocument                          
    ¡¡¡¡¡¡}                                                                          

    ¡¡¡¡¡¡public bool DrawRows(Graphics g)            
    ¡¡¡¡¡¡{                                                                          
    ¡¡¡¡¡¡ int lastRowBottom = TopMargin;              
    ¡¡¡¡¡¡ Lines.Clear();                                              

    ¡¡¡¡¡¡ try                                                                    
    ¡¡¡¡¡¡ {                                                                        
    ¡¡¡¡¡¡¡¡SolidBrush ForeBrush = new S
    olidBrush(TheDataGrid.ForeColor);
    ¡¡¡¡¡¡¡¡SolidBrush BackB
    rush = new SolidBrush(TheDat
    aGrid.BackColor);
    ¡¡¡¡¡¡¡¡SolidBrush AlternatingBackBr
    DataGrid.AlternatingBackColor);
    ush = new SolidBrush(The

    ¡¡¡¡¡¡¡¡Pen TheLinePen = new Pen(The
    DataGrid.GridLineColor, 1);
    ¡¡¡¡¡¡¡¡StringFormat cel
    lformat = new StringFormat()
    ;
    ¡¡¡¡¡¡¡¡cellformat.Trimming = String
    Trimming.EllipsisCharacter;
    ¡¡¡¡¡¡¡¡cellformat.Forma
    rmatFlags.LineLimit;
    tFlags = StringFormatFlags.N

    oWrap | StringFo

    ¡¡¡¡¡¡¡¡int columnwidth = PageWidth/
    0].GridColumnStyles.Count;
    TheDataGrid.TableStyles[


    ¡¡¡¡¡¡¡¡int initialRowCount = (this.
    PageNumber-1)*this.rows_page;

    ¡¡¡¡¡¡¡¡int endrow=initi
    alRowCount+this.rows_page;

    ¡¡¡¡¡¡¡¡RectangleF RowBo
    unds¡¡= new RectangleF(0, 0,
    0, 0);

    ¡¡¡¡¡¡¡¡// draw vertical lines                              

    ¡¡¡¡¡¡¡¡// draw the rows of the table                
    ¡¡¡¡¡¡¡¡for (int i = initialRowCount; i < TheTable.Rows.Count && i< endrow; i++)

    ¡¡¡¡¡¡¡¡{                                                                        
    ¡¡¡¡¡¡¡¡ DataRow dr = TheTable.Rows[i];            
    ¡¡¡¡¡¡¡¡ int startxposit
    ion = this.LeftMargin+2;¡¡¡¡
    ¡¡//TheDataGrid.Location.X;

    ¡¡¡¡¡¡¡¡ RowBounds.X = 0;                                        
    ¡¡¡¡¡¡¡¡ RowBounds.Y = header + TopM
    argin + ((RowCount - initialRowCount)+1) *
    ¡¡¡¡¡¡¡¡ (TheDataGrid.Font.SizeInPoi
    nts¡¡+ kVerticalCellLeeway);
    ¡¡¡¡¡¡¡¡ RowBounds.Heigh
    t = TheDataGrid.Font.SizeInP
    oints + kVerticalCellLeeway;
    ¡¡¡¡¡¡¡¡ RowBounds.Width = PageWidth;                

    ¡¡¡¡¡¡¡¡                                                                         
    ¡¡¡¡¡¡¡¡ /*¡¡///ÕâÒ»¶ÎÊÇ»­±í¸ñµ×É«µÄ´úÂë                                    
    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡if (i%2 == 0)                                          
    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡{                                                                  
    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡ g.FillRec
    tangle(BackBrush, RowBounds)
    ;
    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡}                                                                  
    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡else                                                            
    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡{                                                                  
    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡ g.FillRec
    tangle(AlternatingBackBrush,
    RowBounds);
    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡}                                                                  
    ¡¡¡¡¡¡¡¡ */                                                                    

    ¡¡¡¡¡¡¡¡ for (int j = 0; j < TheDataGrid.TableStyles[0].GridColumnStyles.Count; j++)

    ¡¡¡¡¡¡¡¡ {                                                                      
    ¡¡¡¡¡¡¡¡¡¡columnwidth =
    PageWidth / this.GridWid
    TheDataGrid.TableStyles[0].G
    th -2;
    ridColumnStyles[j].Width*

    ¡¡¡¡¡¡¡¡¡¡RectangleF cellbounds = ne
    w RectangleF(startxposition,
    ¡¡¡¡¡¡¡¡¡¡ header + TopMargin + 2 +                      
    ¡¡¡¡¡¡¡¡¡¡ ((RowCount -
    kVerticalCellLeeway),
    initialRowCount) + 1) * (The

    DataGrid.Font.SizeInPoints¡¡+

    ¡¡¡¡¡¡¡¡¡¡ columnwidth,                                             
    ¡¡¡¡¡¡¡¡¡¡ TheDataGrid.F
    ont.SizeInPoints + kVertical
    CellLeeway);
    ¡¡¡¡¡¡¡¡¡¡¡¡                                                                     

    ¡¡¡¡¡¡¡¡¡¡if (startxposition + columnwidth <= PageWidth)

    ¡¡¡¡¡¡¡¡¡¡{                                                                      
    ¡¡¡¡¡¡¡¡¡¡ g.DrawString(dr[(TheDataG
    olumnStyles[j].MappingName)].ToStrin
    rid.TableStyles[0].GridC
    g(),
    ¡¡¡¡¡¡¡¡¡¡ TheDataGrid.F
    ont, ForeBrush, cellbounds,
    cellformat);
    ¡¡¡¡¡¡¡¡¡¡}                                                                      

    ¡¡¡¡¡¡¡¡¡¡startxposition
    = startxposition + columnwi
    dth+2;
    ¡¡¡¡¡¡¡¡ }                                                                      

    ¡¡¡¡¡¡¡¡ Lines.Add(RowBounds.Bottom);                

    ¡¡¡¡¡¡¡¡ lastRowBottom =
    (int)RowBounds.Bottom;

    ¡¡¡¡¡¡¡¡ RowCount++;                                                  
    ¡¡¡¡¡¡¡¡}                                                                        

    ¡¡¡¡¡¡¡¡DrawHorizontalLines(g, Lines);              
    ¡¡¡¡¡¡¡¡DrawVerticalGridLines(g, The
    LinePen,lastRowBottom);
    ¡¡¡¡¡¡¡¡                                                                          
    ¡¡¡¡¡¡¡¡if(this.showfooter==true)                        
    ¡¡¡¡¡¡¡¡ DrawFooter(g);                                            

    ¡¡¡¡¡¡¡¡if (this.PageNumber

    ¡¡¡¡¡¡¡¡{                                                                        
    ¡¡¡¡¡¡¡¡ return true;                                                
    ¡¡¡¡¡¡¡¡}                                                                        
    ¡¡¡¡¡¡¡¡else                                                                  
    ¡¡¡¡¡¡¡¡{                                                                        
    ¡¡¡¡¡¡¡¡ return false;                                              
    ¡¡¡¡¡¡¡¡}                                                                        

    ¡¡¡¡¡¡ }                                                                        
    ¡¡¡¡¡¡ catch (Exception ex)                                  
    ¡¡¡¡¡¡ {                                                                        
    ¡¡¡¡¡¡¡¡MessageBox.Show(ex.Message.T
    oString());

    ¡¡¡¡¡¡¡¡return false;                                                
    ¡¡¡¡¡¡ }                                                                        

    ¡¡¡¡¡¡}                                                                          

    ¡¡¡¡¡¡void DrawFooter(Graphics g)                      
    ¡¡¡¡¡¡{                                                                          
    ¡¡¡¡¡¡ FontFamily fontFamily = new F
    ontFamily("ËÎÌå");

    ¡¡¡¡¡¡ string text="µÚ"+this.PageNum
    ber.ToString()+"Ò³ ¹²"
    ¡¡¡¡¡¡¡¡+this.pagecount.ToString()+"Ò³";            

    ¡¡¡¡¡¡ Font font = new Font(                                
    ¡¡¡¡¡¡¡¡fontFamily, 10,                                            
    ¡¡¡¡¡¡¡¡FontStyle.Regular,                                      
    ¡¡¡¡¡¡¡¡GraphicsUnit.Point);                                  

    ¡¡¡¡¡¡ SizeF size= g.MeasureString(t
    ext,font);

    ¡¡¡¡¡¡ int startpos = this.PageHeight              
    ¡¡¡¡¡¡¡¡-this.BottomMargin;                                    

    ¡¡¡¡¡¡ SolidBrush ForeBrush = new So
    lidBrush(Color.Black);


    ¡¡¡¡¡¡ StringFormat cell
    format = 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.LeftMa
    rgin - size.Width-3,
    ¡¡¡¡¡¡¡¡startpos, cellformat);                              

    ¡¡¡¡¡¡}                                                                          

    ¡¡¡¡                                                                             

    ¡¡¡¡¡¡void DrawHorizontalLines(Graph
    ics g, ArrayList lines)
    ¡¡¡¡¡¡{                                                                          
    ¡¡¡¡¡¡ Pen TheLinePen = new Pen(TheD
    ataGrid.GridLineColor, 1);

    ¡¡¡¡¡¡ if (TheDataGrid.GridLineStyle
    == DataGridLineStyle.None)
    ¡¡¡¡¡¡¡¡return;                                                            

    ¡¡¡¡¡¡ int i;                                                              

    ¡¡¡¡¡¡ for (i = 0;¡¡i < lines.Count; i++)

    ¡¡¡¡¡¡ {                                                                        
    ¡¡¡¡¡¡¡¡g.DrawLine(TheLinePen, this.
    LeftMargin, (float)lines[i], this.LeftMargin +
    ¡¡¡¡¡¡¡¡this.PageWidth, (float)lines[i]);        
    ¡¡¡¡¡¡ }                                                                        

    ¡¡¡¡¡¡}                                                                          

    ¡¡¡¡¡¡void DrawVerticalGridLines(Gra
    phics g, Pen TheLinePen, int bottom)
    ¡¡¡¡¡¡{                                                                          
    ¡¡¡¡¡¡ if (TheDataGrid.G
    ridLineStyle == DataGridLine
    Style.None)
    ¡¡¡¡¡¡¡¡return;                                                            

    ¡¡¡¡¡¡ int posx=0;                                                    

    ¡¡¡¡¡¡ //»­×î×ó±ßµÄÊúÏß                                                        

    ¡¡¡¡¡¡ g.DrawLine(TheLin
    ePen, this.LeftMargin + posx
    ,
    ¡¡¡¡¡¡¡¡header + TopMargin,                                    
    ¡¡¡¡¡¡¡¡this.LeftMargin + posx,                            
    ¡¡¡¡¡¡¡¡bottom);                                                          

    ¡¡¡¡¡¡ //»­×îÓұߵÄÊúÏß                                                        
    ¡¡¡¡¡¡ g.DrawLine(TheLinePen, this.L
    eftMargin + this.PageWidth,
    ¡¡¡¡¡¡¡¡header + TopMargin,                                    
    ¡¡¡¡¡¡¡¡this.LeftMargin + this.PageWidth,        
    ¡¡¡¡¡¡¡¡bottom);                                                          

    ¡¡¡¡¡¡ int total=TheData
    Grid.TableStyles[0].GridColu
    mnStyles.Count -1;
    ¡¡¡¡¡¡ for (int k = 0; k < total; k++)

    ¡¡¡¡¡¡ {                                                                        
    ¡¡¡¡¡¡¡¡posx+=(TheDataGr
    id.TableStyles[0].GridColumn
    Styles[k].Width) *
    ¡¡¡¡¡¡ this.PageWidth / this.GridWidth;          
    ¡¡¡¡¡¡¡¡g.DrawLine(TheLi
    nePen, this.LeftMargin + pos
    x,
    ¡¡¡¡¡¡¡¡ header + TopMargin,                                  
    ¡¡¡¡¡¡¡¡ this.LeftMargin + posx,                          
    ¡¡¡¡¡¡¡¡ bottom);                                                        
    ¡¡¡¡¡¡ }                                                                        
    ¡¡¡¡¡¡}                                                                          


    ¡¡¡¡¡¡public bool DrawDataGrid(Graphics g)    
    ¡¡¡¡¡¡{                                                                          

    ¡¡¡¡¡¡ try                                                                    
    ¡¡¡¡¡¡ {                                                                        
    ¡¡¡¡¡¡¡¡DrawHeader(g);                                              
    ¡¡¡¡¡¡¡¡bool bContinue = DrawRows(g);                
    ¡¡¡¡¡¡¡¡return bContinue;                                        
    ¡¡¡¡¡¡ }                                                                        
    ¡¡¡¡¡¡ catch (Exception ex)                                  
    ¡¡¡¡¡¡ {                                                                        
    ¡¡¡¡¡¡¡¡MessageBox.Show(ex.Message.T
    oString());
    ¡¡¡¡¡¡¡¡return false;                                                
    ¡¡¡¡¡¡ }                                                                        

    ¡¡¡¡¡¡}                                                                          

    ¡¡¡¡ }                                                                          

    ¡¡¡¡}                                                                            




    ÉÏÒ»Ò³ ÏÂÒ»Ò³




    map