当前位置:首页 > Windows程序 > 正文

含有打印、统计DataGridView(1)

2021-03-19 Windows程序

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing.Printing;
using System.Drawing;
using System.Windows.Forms;
using System.Windows;
using System.Data;
using Microsoft.Office;
namespace KingBoy
{
    class MyDataGrid:DataGridView
    {
        #region var
        //用户可自定义 
        private Font tableFont=new Font("宋体", 9);  // ‘当前要打印文本的字体及字号 
        private Font headFont=new Font("黑体", 12, FontStyle.Regular);//表头字体 
        private Font subHeadFont=new Font("楷体_GB2312", 10, FontStyle.Regular); //副表头字体 
        private String headText="" ; //表头文字 
        private String subHeadLeftText="";  //副表头左文字
        private String subHeadRightText="";  //副表头右文字 
        private int headHeight=40;  //表头高度 
        private int subHeadHeight=30;  //副表头高度 
        private Font footFont=new Font("黑体", 12, FontStyle.Underline); //表脚字体
        private Font subFootFont=new Font("楷体_GB2312", 10, FontStyle.Regular);//副表脚字体 
        private String footText=""; ////表脚文字 
        private String subFootLeftText="" ;  //副表脚左文字 
        private String subFootRightText="" ;  //副表脚右文字
        private int footHeight=40; //表脚高度
        private int subFootHeight=30;  //副表脚高度 
        private String worker="";  //‘制表人
        private double sum=0; //汇总数据
        private int x_unit=0; //表的基本单位
        private int y_unit= 24;

//以下为模块内部使用      
        private PrintDocument printDocument1;     
        private DataRow dataGridRow;
        private DataTable dataTable1;
        private int Cols; //                          ‘当前要打印的列                          
        private int ColsCount; //                    ‘当前DATAGRID共有多少列       
        private int pageRecordNumber; //                 ‘当前要所要打印的记录行数,由计算得到. 
        private int printingPageNumber=0;//           ‘正要打印的页号 
        private int pageNumber;//                       ‘共需要打印的页数
        private int printRecordLeave;//                 ‘当前还有多少页没有打印 
        private int printRecordComplete=0;  //        ‘已经打印完的记录数 
        private int pLeft,pTop,pRight,pBottom,pWidth,pHeight;
        private SolidBrush drawBrush = new SolidBrush(System.Drawing.Color.Black);//   ‘当前画笔颜色 
        private int pRecordNumber=0  ;//‘每页打印的记录条数 
        private int totalPage;  //总共应该打印的页数        
        #endregion
        #region property
         
        /// <summary>
        ///用户自定义字体及字号
        /// </summary>
        public Font setTableFont
        {
         set{tableFont=value;}
        }
        /// <summary>
        /// 设置表头字体
        /// </summary>
       public Font setHeadFont
       {
        set{headFont =value;}
       }
        public Font setFootFont
        {
         set{footFont=value;}
        }
       public Font setSubFootFont
       {
        set{subFootFont =value;}
       }
      public string setHeadText
      {
       set{headText =value;}
      }
      public string setSubHeadLeftText
      {
        set{subHeadLeftText =value;}
      }
        public string setSubHeadRightText
        {
         set{subHeadRightText =value;}
        }
       public string setFootText
       {
         set{footText =value;}
       }

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/63629.html