动态网站制作指南 [  QQ表情  ]
[ 投票调查 ]
[ 企业邮箱 ]
[ 网站空间 ]
网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
ASP源码 | .Net源码 | PHP源码 | JSP源码 | JAVA源码 | CGI源码 | VB源码 | C++源码 | Delphi源码 | PB源码 | VF源码 | 汇编 | 服务器
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > Java教程
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
文章搜索服务
邮件订阅
输入你的邮件地址,
你将不会错过任何关于:
[ Java教程 ]的信息

本月文章推荐
.Eclipse 平台入门.
.JAR进阶(下).
.浅谈MDA技术未来发展方向.
.xmlhttp和Java session监听改善消.
.JBuilder7+Weblogic7+mysql开发E.
.用JAVA实现MSN Messager的功能.
.全面解析JDBC(3).
.Grails + EJB Domain Models.
.技术分析:使用Eclipse进行SWT编程.
.幸福的联姻:Java和Python.
.EMF编程使用.
.CORBA对象生命周期之生命周期的评.
.创建 JSF Web 项目和页面模板(4.
.Java运行时多态性的实现.
.Java 程序初始化过程详解.
.Apache的完全安装转载.
.Pattens In Java(中文).
.使用 WebSphere V5 工具和技术来.
.Java技巧:Hello World Ant.
.SpringAOP在DWR安全上的应用.

使用.NET自带的类实现DataGrid报表的打印

发表日期:2008-1-5 |



  using System;
  using System.Windows.Forms;
  using System.Drawing;
  using System.Drawing.Printing;
  using System.Data;
  using System.Collections;
  using DataLibrary;
  
  namespace ControlLibrary
  {
   ///
   /// DataGrid打印
   ///

   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     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.Locatio
上一篇:Java Bean实现航空预定机票功能应用 人气:431
下一篇:自己写的一个未成熟的数据库连接池(二) 人气:371
浏览全部Java的内容 Dreamweaver插件下载 常用网页广告代码全集
  最新网站源码 最新软件下载
2008-9-4 LPLY CMS 网站管理系统 v5.0
2008-9-4 缤纷互动视频交友 v3.01.902
2008-9-4 ADN视频收藏专家 v3.0 bulid 080
2008-9-4 天空网络电影系统SKYUC v2.5.6 简
2008-9-4 Web Wiz Rich Text Editor(文本编
2008-9-4 幻影动漫网视频系统(Ppdong) v1.
2008-9-4 乐维电脑在线DIY配置系统
2008-9-4 老樊文章管理系统SQL版
2008-9-4 ASP.NET 2.53 缩略图水印组件源码
2008-8-23 Mini WinMount V0.4
2008-8-23 Vista优化大师3.11正式版
2008-8-23 Wine 1.13
2008-8-23 KlipFolio 5.0 Build 5899-80
2008-8-23 Windows Sysinternals Desktops
2008-8-23 OneTap Movies1.2破解版
2008-8-23 AnnotaterPDF阅读1.1.503 破解版
2008-8-23 SoundMeter分贝测量仪 v1.0汉化破
2008-8-23 iDrum音乐节拍1.0破解版
  发表评论
姓 名: 验证码:
内 容:
站长工具:网站收录查询 | Google PR查询 | ALEXA排名查询 | CSS在线编辑器 | 广告代码 | Html转换js | js/vbs加密 | md5加密 | 进制转换
实用工具:汉字翻译拼音 | 符号对照表 | 个税计算 | 经典小工具 | 汉字简繁转换 | 普通单位换算 | 公制单位换算 | 生辰老黄历 | 国内电话区号 国家代码与域名缩写 | 文字加密解密 | 健康查询 | 万年历 | 汉字横竖排版 | 手机号码查询 | 计算器 | ip搜索
业务联系 | 广告刊登 | 频道合作 | 投稿荐稿 | 联系方式 | 加入收藏 | RSS订阅
Copyright © 2000-2008 www.knowsky.com All rights reserved | 网络实名:动态网站制作指南 | 沪ICP备05001343号
ホームページ制作 不動産検索システム 求人情報
防水工事·改修工事 フットサル大会 探偵