• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

报表源代码 winform c# -基于DexExpressXtraReport的打印报表,后台生成报表,winform ...

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
/
// =================================================
//   基于DevExpress通用表格打印
//   
//    设计: 陈炎和 2011.02
//==================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using System.Data;


namespace com.CYH.TableXtraReport
{
   
   
/// <summary>
   
/// 报表每个单元打印前事件
   
/// </summary>
   
/// <param name="sender">发生事件的对象</param>
   
/// <param name="source">来源:1:页头 2:表头 3:表格 4:表脚 5:页脚 6:条码</param>
   
/// <param name="PageIndex">当前页号</param>
   
/// <param name="RowIndex">当前行号</param>
   
/// <param name="Caption">标题</param>
   
/// <param name="Field">绑定字段</param>
   
/// <param name="Value">打印前值</param>
   
/// <param name="e"></param>
    public delegate void XReportUnitAfterPrint(object sender,int source,int PageIndex,int RowIndex,string Caption,string Field,ref string Value,EventArgs e);
   
   
   
/// <summary>
   
/// 通用报表
   
/// </summary>
    public class TableXReport : DevExpress.XtraReports.UI.XtraReport
    {

       
/// <summary>
       
/// 报表主体设置
       
/// </summary>
        private  struct ReportMain
        {
           
/// <summary>
           
/// 打印机名
           
/// </summary>
            public string printerName;
           
/// <summary>
           
/// 纸张大小
           
/// </summary>
            public Size pageSize;
           
/// <summary>
           
/// 页边距
           
/// </summary>
            public System.Drawing.Printing.Margins Margins;
           
/// <summary>
           
/// 获取或设置纸张类型
           
/// </summary>
            public System.Drawing.Printing.PaperKind PaperKind;
           
/// <summary>
           
/// 获取或设置每行高度(以0.1毫米为单位)
           
/// </summary>
            public int DetailHeight;
           
/// <summary>
           
/// 获取或设置每页行数
           
/// </summary>
            public int DetailRows;
           
/// <summary>
           
/// 获取或设置打印开始页
           
/// </summary>
            public int BeginPage;
           
/// <summary>
           
/// 获取或设置打印结束页
           
/// </summary>
            public int EndPage;
           
/// <summary>
           
/// 获取或设置打印方向
           
/// </summary>
            public bool Landscape;
           
/// <summary>
           
/// 获取或设置表格线的类型
           
///   1:三栏表,2:有边框的三栏,4:完全网格
           
/// </summary>
            public int GridLine;
           
/// <summary>
           
/// 表格对齐方式
           
/// </summary>
            public System.Drawing.ContentAlignment Align;
        }
       
/// <summary>
       
/// 报表标题
       
/// </summary>
        private struct ReportTitle
        {
           
/// <summary>
           
/// 标题内空
           
/// </summary>
            public string Caption;
           
/// <summary>
           
/// 页头或页脚
           
/// </summary>
            public bool Header;
           
/// <summary>
           
/// 字体(宋体加粗四号)
           
/// </summary>
            public Font Font;
           
/// <summary>
           
/// 对齐方式
           
/// </summary>
            public DevExpress.XtraPrinting.TextAlignment TextAlignment;
           
/// <summary>
           
///  标题的高度和宽度,若不定义便检测Caption,否则自换行
           
/// </summary>
            public System.Drawing.Size size;
        }
       
/// <summary>
       
/// 报表各字段格式
       
/// </summary>
        private  struct ReportField
        {
           
/// <summary>
           
/// 名称
           
/// </summary>
            public string Name;
           
/// <summary>
           
/// 表格头标题
           
/// </summary>
            public string Caption;
           
/// <summary>
           
/// 标题字体(宋体、小四)
           
/// </summary>
            public Font HeaderFont;
           
/// <summary>
           
/// 绑定字段
           
/// </summary>
            public string Field;
           
/// <summary>
           
/// 对齐方式
           
/// </summary>
            public DevExpress.XtraPrinting.TextAlignment TextAlignment;
           
/// <summary>
           
/// 表格字体(宋体、小四)
           
/// </summary>
            public Font DetailFont;
           
/// <summary>
           
/// 自动换行
           
/// </summary>
            public bool WordWrap;
           
/// <summary>
           
/// 表格脚内容
           
/// </summary>
            public string Bottom;
           
/// <summary>
           
/// 是否合计
           
/// </summary>
            public bool Sum;
           
/// <summary>
           
/// 格式化字符串
           
/// </summary>
            public string FormatString;
           
/// <summary>
           
/// 标题的高度和宽度,若不定义便检测Caption,否则自换行并居中
           
/// </summary>
            public Size HeaderSize;
        }

       
private struct ReportBarcode
        {  
           
/// <summary>
           
/// 条码内容(A-Z,0-9)
           
/// </summary>
            public string Text;
           
/// <summary>
           
/// 起点
           
/// </summary>
            public Point pint;
           
/// <summary>
           
/// 大小
           
/// </summary>
            public Size size;
           
/// <summary>
           
/// 编码格式
           
/// </summary>
            public DevExpress.XtraPrinting.BarCode.BarCodeGeneratorBase Symbology;
           
/// <summary>
           
/// 是否显示文字
           
/// </summary>
            public bool showText;
        }


       
private ReportMain m_rpm = new ReportMain();
       
private ArrayList m_rpt = new ArrayList();
       
private ArrayList m_rpf = new ArrayList();
       
private ReportBarcode m_rpb = new ReportBarcode();
       
private int m_rowindex;
       
/// <summary>
       
/// 定义报表主体同时创建报表(必须先定义SetReportTitle和SetReportFiled)
       
/// </summary>
       
/// <param name="DetailHeight">明细每行高度</param>
       
/// <param name="DetailRows">每页行数</param>
       
/// <param name="GridLine">表格线的类型 1:三栏表,2:有边框的三栏,4:完全网格</param>
       
/// <param name="Align">表格对齐方向</param>
       
/// <param name="Landscape">横向还是纵向打印</param>
       
/// <param name="Margins">页的边距尺寸</param>
       
/// <param name="PaperKind">标准的纸张大小</param>
       
/// <param name="pageSize">纸张大小</param>
       
/// <param name="FromPage">起始页</param>
       
/// <param name="ToPage">结束页</param>
       
/// <param name="printerName">打印机名</param>       
        public void SetReportMain(int DetailHeight, int DetailRows, int GridLine, System.Drawing.ContentAlignment Align, bool Landscape, System.Drawing.Printing.Margins Margins,
            System.Drawing.Printing.PaperKind PaperKind, Size pageSize,
int FromPage, int ToPage, string printerName)
        {
            m_rpm.DetailHeight
= DetailHeight;
            m_rpm.DetailRows
= DetailRows;
            m_rpm.Align
= Align;
            m_rpm.Landscape
= Landscape;
            m_rpm.Margins
= Margins;
            m_rpm.PaperKind
= PaperKind;
            m_rpm.pageSize
= pageSize;
            m_rpm.BeginPage
= FromPage;
            m_rpm.EndPage
= ToPage;
            m_rpm.printerName
= printerName;
            m_rpm.GridLine
= GridLine;
           
base.Bands.Clear();
           
this.SetReport(m_rpm, (ReportTitle[])m_rpt.ToArray(typeof(ReportTitle)), (ReportField[])m_rpf.ToArray(typeof(ReportField)),m_rpb);
        }
       
/// <summary>
       
/// 定义报表标题
       
/// </summary>
       
/// <param name="Caption">标题内容</param>
       
/// <param name="Header">页头或页脚</param>
       
/// <param name="Font">字体(宋体加粗四号)</param>
       
/// <param name="TextAlignment">对齐方式</param>
       
/// <param name="size"> 标题的高度和宽度,若不定义便检测Caption,否则自换行</param>
        public void SetReportTitle(string Caption, bool Header, Font Font, DevExpress.XtraPrinting.TextAlignment TextAlignment, System.Drawing.Size size)
        {
            ReportTitle rpt
= new ReportTitle();
            rpt.Caption
= Caption;
            rpt.Header
= Header;
            rpt.TextAlignment
= TextAlignment == 0 ? DevExpress.XtraPrinting.TextAlignment.TopCenter : TextAlignment;
            rpt.Font
= Font == null ? new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))) : Font;
            rpt.size
= size;
            m_rpt.Add(rpt);
        }
       
/// <summary>
       
/// 定义报表字段
       
/// </summary>
       
/// <param name="Caption">表格头标题</param>
       
/// <param name="HeaderFont">标题字体(宋体、小四)</param>
       
/// <param name="Field">绑定字段</param>
       
/// <param name="TextAlignment">对齐方式</param>
       
/// <param name="DetailFont"> 表格字体(宋体、小四)</param>
       
/// <param name="WordWrap">自动换行</param>
       
/// <param name="Bottom">表格脚内容</param>
       
/// <param name="Sum">是否合计</param>
       
/// <param name="FormatString">格式化字符串</param>
       
/// <param name="HeaderSize">标题的高度和宽度,若不定义便检测Caption,否则自换行并居中</param>
        public void SetReportField(string Caption, Font HeaderFont, string Field, DevExpress.XtraPrinting.TextAlignment TextAlignment, Font DetailFont
                        ,
bool WordWrap, string Bottom, bool Sum, string FormatString, Size HeaderSize)
        {
            ReportField rpf
= new ReportField();
            rpf.Caption
= Caption;
            rpf.HeaderFont
= HeaderFont;
            rpf.Field
= Field;
            rpf.TextAlignment
= TextAlignment;
            rpf.DetailFont
= DetailFont;
            rpf.WordWrap
= WordWrap;
            rpf.Bottom
= Bottom;
            rpf.Sum
= Sum;
            rpf.FormatString
= FormatString;
            rpf.HeaderSize
= HeaderSize;
            m_rpf.Add(rpf);
        }
       
/// <summary>
       
/// 定义条码
       
/// </summary>
       
/// <param name="Text">条码内容(A-Z,0-9)</param>
       
/// <param name="pint">起点</param>
       
/// <param name="size">大小</param>
       
/// <param name="Symbology">编码格式</param>
       
/// <param name="showText">是否显示文字</param>
        public void SetReportBarCode(string Text, Point pint, Size size, DevExpress.XtraPrinting.BarCode.BarCodeGeneratorBase Symbology, bool showText)
        {
            m_rpb.Text
= Text;
            m_rpb.pint
= pint;
            m_rpb.size
= size;
            m_rpb.Symbology
=  Symbology

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Levenshtein计算字符串的相似度发布时间:2022-07-13
下一篇:
c#中的静态类发布时间:2022-07-13
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap