亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? 使用.net自帶的類實現datagrid報表的打印.txt

?? c# 大量的學習資料。包括ado.net學習筆記
?? TXT
字號:
使用.NET自帶的類實現DataGrid報表的打印。
www.chinacs.net  2004-12-1  中文C#技術站 



 
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Printing;
using System.Data;
using System.Collections;
using DataLibrary;

namespace ControlLibrary
{
 /// <summary>
 /// DataGrid打印
 /// </summary>
 public class DataGridPrinter
 {
  private PrintDocument ThePrintDocument;
  private DataTable TheTable;
  private DataGrid  TheDataGrid;
  public int RowCount = 0;
  private const int kVerticalCellLeeway = 10;
  public int PageNumber = 1;
  public ArrayList Lines = 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<this.pagecount)
     return (1+this.rows_page) * ((int)(TheDataGrid.Font.SizeInPoints)  + kVerticalCellLeeway);
    else
     return (this.TheTable.Rows.Count + 1 -(this.rows_page*(this.PageNumber-1))) * ( (int)(TheDataGrid.Font.SizeInPoints)  + kVerticalCellLeeway);
   }
  }

  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 < this.ThePrintDocument.PrinterSettings.PaperSizes.Count; i++)
    {
     pkSize = this.ThePrintDocument.PrinterSettings.PaperSizes[i];
     if(pkSize.PaperName==this.PaperName)
     {
      this.ThePrintDocument.DefaultPageSettings.PaperSize=pkSize;
      found=1;
      i=this.ThePrintDocument.PrinterSettings.PaperSizes.Count;
      if(this.ThePrintDocument.DefaultPageSettings.Landscape)
      {
       PageHeight = pkSize.Width;
       PageWidth = pkSize.Height;
      }
      else
      {
       PageWidth = pkSize.Width;
       PageHeight = pkSize.Height;
      }
     }
    }

    if(found==0)
    {
     if(this.ThePrintDocument.DefaultPageSettings.Landscape)
     {
      PageHeight = Int32.Parse(myDV[0]["zk"].ToString());
      PageWidth = Int32.Parse(myDV[0]["zc"].ToString());
     }
     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());
    RightMargin = 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=(int)((float)(this.PageHeight-this.TopMargin-this.BottomMargin-this.footer-this.header)/(TheDataGrid.Font.SizeInPoints + kVerticalCellLeeway));

   for (int k = 0; k < TheDataGrid.TableStyles[0].GridColumnStyles.Count; k++)
   {
    GridWidth += TheDataGrid.TableStyles[0].GridColumnStyles[k].Width;  //  TheTable.Columns[k].ToString();
   }

  }

  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;                      //TheDataGrid.Location.X;
   RectangleF nextcellbounds = new RectangleF(0,0, 0, 0);

   /* 
      這一段是畫表頭底色的代碼

      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 < this.TheDataGrid.TableStyles[0].GridColumnStyles.Count; k++)
   {
    columnwidth = TheDataGrid.TableStyles[0].GridColumnStyles[k].Width * PageWidth / this.GridWidth;

    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.SizeInPoints + kVerticalCellLeeway-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)
  {
   TheTable = aTable;
   this.pagecount=(int)Math.Ceiling((double)(TheTable.Rows.Count)/(double)(this.rows_page));
   // MessageBox.Show("rows_count:"+TheTable.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 (int i = initialRowCount; i < TheTable.Rows.Count && i< endrow; i++)
    {
     DataRow dr = TheTable.Rows[i];
     int startxposition = this.LeftMargin+2;      //TheDataGrid.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;

     
     /*  ///這一段是畫表格底色的代碼
          if (i%2 == 0)
          {
           g.FillRectangle(BackBrush, RowBounds);
          }
          else
          {
           g.FillRectangle(AlternatingBackBrush, RowBounds);
          }
     */

     for (int j = 0; j < TheDataGrid.TableStyles[0].GridColumnStyles.Count; j++)
     {
      columnwidth = TheDataGrid.TableStyles[0].GridColumnStyles[j].Width* PageWidth / this.GridWidth -2;
      RectangleF cellbounds = new RectangleF(startxposition, 
       header + TopMargin + 2 +
       ((RowCount - initialRowCount) + 1) * (TheDataGrid.Font.SizeInPoints  + kVerticalCellLeeway),
       columnwidth, 
       TheDataGrid.Font.SizeInPoints + kVerticalCellLeeway);
         

      if (startxposition + columnwidth <= PageWidth)
      {
       g.DrawString(dr[(TheDataGrid.TableStyles[0].GridColumnStyles[j].MappingName)].ToString(), TheDataGrid.Font, ForeBrush, cellbounds, cellformat);
      }

      startxposition = startxposition + columnwidth+2;
     }

     Lines.Add(RowBounds.Bottom);
     lastRowBottom = (int)RowBounds.Bottom;

     RowCount++;
    }

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

    if (this.PageNumber<this.pagecount)
    {
     return true;
    }
    else
    {
     return false;
    }

   }
   catch (Exception ex)
   {
    MessageBox.Show(ex.Message.ToString());

    return false;
   }

  }

  void DrawFooter(Graphics g)
  {
   FontFamily fontFamily = new FontFamily("宋體");

   string text="第"+this.PageNumber.ToString()+"頁 共"
    +this.pagecount.ToString()+"頁";

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

   SizeF size= g.MeasureString(text,font);

   int startpos = this.PageHeight
    -this.BottomMargin;

   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 < lines.Count; i++)
   {
    g.DrawLine(TheLinePen, this.LeftMargin, (float)lines[i], this.LeftMargin + this.PageWidth, (float)lines[i]);
   }

  }

  void DrawVerticalGridLines(Graphics g, Pen TheLinePen, int bottom)
  {
   if (TheDataGrid.GridLineStyle == DataGridLineStyle.None)
    return;

   int posx=0;

   //畫最左邊的豎線

   g.DrawLine(TheLinePen, this.LeftMargin + posx, 
    header + TopMargin,
    this.LeftMargin + posx,
    bottom);

   //畫最右邊的豎線
   g.DrawLine(TheLinePen, this.LeftMargin + this.PageWidth, 
    header + TopMargin,
    this.LeftMargin + this.PageWidth,
    bottom);

   int total=TheDataGrid.TableStyles[0].GridColumnStyles.Count -1;
   for (int k = 0; k < total; k++)
   {
    posx+=(TheDataGrid.TableStyles[0].GridColumnStyles[k].Width) * this.PageWidth / this.GridWidth;
    g.DrawLine(TheLinePen, this.LeftMargin + posx, 
     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.ToString());
    return false;
   }

  }

 }

}


?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产伦精品一区二区三区免费迷 | 久久综合色之久久综合| 北条麻妃一区二区三区| 成人免费视频视频在线观看免费 | 99久久精品国产网站| av在线不卡免费看| 色婷婷综合久久久中文字幕| 日本高清不卡视频| 欧美日韩高清一区二区不卡| 91麻豆精品国产91久久久久久 | 亚洲在线免费播放| 一区二区成人在线视频| 亚洲一卡二卡三卡四卡无卡久久| 亚洲激情自拍偷拍| 三级久久三级久久久| 精品一区二区在线观看| 国产老肥熟一区二区三区| 国产成人h网站| 一本大道久久a久久精二百| 欧美性猛交xxxx乱大交退制版| 91久久国产最好的精华液| 欧美色图片你懂的| 欧美一级夜夜爽| 国产亚洲欧美中文| 一区二区三区在线观看动漫| 天天av天天翘天天综合网| 精品一区二区三区在线观看国产 | 激情五月播播久久久精品| 国产不卡在线视频| 欧洲精品在线观看| 欧美一区国产二区| 国产精品久久夜| 亚洲小说春色综合另类电影| 久久99久久99精品免视看婷婷| 成人免费精品视频| 欧美精品国产精品| 国产午夜精品在线观看| 亚洲国产欧美在线| 成人app下载| 日韩一区二区三区电影| 亚洲毛片av在线| 国产裸体歌舞团一区二区| 欧美三级视频在线| 国产欧美一区二区精品秋霞影院| 亚洲午夜久久久久| www..com久久爱| 2023国产精品| 石原莉奈在线亚洲二区| 色婷婷精品大在线视频 | 风间由美一区二区av101| 欧美日韩国产在线观看| 欧美国产成人在线| 蜜桃精品在线观看| 欧美图区在线视频| 国产精品不卡在线| 国产a区久久久| 精品99一区二区三区| 天天色综合成人网| 欧美人狂配大交3d怪物一区| 一区二区三区蜜桃网| 成人精品国产免费网站| 久久久久久夜精品精品免费| 蜜臀精品一区二区三区在线观看| 欧美日本视频在线| 亚洲电影激情视频网站| 欧洲国内综合视频| 亚洲裸体在线观看| 99久久婷婷国产综合精品| 国产精品丝袜久久久久久app| 国产在线不卡一区| 欧美精品一区二区蜜臀亚洲| 久久精品国产77777蜜臀| 欧美日韩在线三级| 日韩av在线播放中文字幕| 欧美日韩国产首页在线观看| 亚洲色图20p| 欧美在线观看视频一区二区| 一区二区成人在线视频| 精品视频免费在线| 视频在线观看国产精品| 91麻豆精品国产91久久久久久久久| 午夜激情综合网| 日韩午夜精品视频| 激情久久久久久久久久久久久久久久| 日韩一级免费一区| 国产一区在线精品| 国产精品日日摸夜夜摸av| 91视频观看视频| 亚洲第一二三四区| 久久综合久久久久88| 成人免费高清视频在线观看| 中文字幕综合网| 欧美精品日韩综合在线| 久久国产欧美日韩精品| 国产日韩欧美电影| 色欧美日韩亚洲| 日韩av电影天堂| 国产人成亚洲第一网站在线播放| 成人激情图片网| 亚洲6080在线| 久久精品夜色噜噜亚洲a∨| 99re成人精品视频| 午夜国产精品影院在线观看| 久久精品视频一区| 91久久精品一区二区三| 麻豆精品一二三| 亚洲免费观看高清完整| 日韩你懂的在线观看| 成人av电影在线播放| 奇米精品一区二区三区四区| 国产欧美日韩精品在线| 欧美欧美欧美欧美| 成人免费电影视频| 日韩成人免费在线| 综合电影一区二区三区 | 成人网男人的天堂| 五月天欧美精品| 日韩毛片一二三区| 精品国内二区三区| 欧美日韩一区中文字幕| 成人精品国产福利| 激情综合色播五月| 亚洲电影在线免费观看| 国产精品私房写真福利视频| 日韩精品一区二区三区老鸭窝| 一本久道中文字幕精品亚洲嫩| 国产一区三区三区| 日产精品久久久久久久性色| 一区二区三区在线视频播放| 国产目拍亚洲精品99久久精品| 7777精品久久久大香线蕉| 色综合天天性综合| 成人性生交大片免费看中文 | 久久综合999| 3d成人h动漫网站入口| 色综合天天综合网天天看片| 国产精品一区二区男女羞羞无遮挡| 天堂在线亚洲视频| 亚洲18色成人| 亚洲成人免费av| 亚洲一本大道在线| 亚洲在线视频免费观看| 亚洲精品福利视频网站| 亚洲人成在线播放网站岛国| 国产精品国产三级国产aⅴ入口| 7777精品伊人久久久大香线蕉完整版 | 亚洲精选在线视频| 亚洲欧洲色图综合| 亚洲乱码国产乱码精品精的特点 | 亚洲另类春色国产| **性色生活片久久毛片| 丁香亚洲综合激情啪啪综合| 污片在线观看一区二区| 在线观看一区二区视频| 91麻豆国产精品久久| 精品粉嫩超白一线天av| 9191成人精品久久| 欧美大肚乱孕交hd孕妇| 精品精品欲导航| 精品久久久久一区二区国产| 另类小说图片综合网| yourporn久久国产精品| 91精品国模一区二区三区| 久久精品视频网| 日韩国产精品大片| 91伊人久久大香线蕉| 日韩午夜激情av| 一区二区三区在线观看视频| 国产一区二区三区免费看| 欧美性猛片aaaaaaa做受| 国产欧美精品一区| 麻豆国产精品官网| 欧美日精品一区视频| 国产精品国产a| 国产一区在线观看麻豆| 日韩一区二区在线看| 亚洲线精品一区二区三区八戒| 国产一区91精品张津瑜| 91精品国产综合久久香蕉的特点| 综合欧美亚洲日本| 成人av网址在线观看| 久久久国产综合精品女国产盗摄| 日韩中文字幕亚洲一区二区va在线| av网站免费线看精品| 久久综合九色综合欧美98 | 久久精品在线观看| 美女视频一区在线观看| 欧美肥胖老妇做爰| 亚洲韩国一区二区三区| 99久久99久久综合| 国产精品二区一区二区aⅴ污介绍| 精品亚洲欧美一区| 日韩免费高清视频| 久久狠狠亚洲综合| 2019国产精品| 麻豆免费精品视频| 精品盗摄一区二区三区| 久久99九九99精品| 久久午夜色播影院免费高清| 国产在线播放一区三区四|