报表打印

摘要:

      这部分功能主要通过fastreport实现。系统实现了对FastReport的再次封装,只需调用简单方法就可实现打印。

方法实现:

方法一

BusinessTool.Print("ZW_KeHuTKJZPZ.frx", dtPrint);

上面这个方法要求传入一张FastReport报表,以及对应的DataTable数据。这个方法的缺点是,报表修改后必须重新发布报表,发布比较麻烦,所以不推荐使用。

方法二

                report = new Common.Print.MyReport(LoginInfo.CurrentUser, 281, ReportExecMethod.Preview, dsXJ);
                report.Start();

上述方法需要构造一个MyReport对象,并传入一个报表ID,报表ID是在报表管理模块中添加管理的。并将对应的信息存放在数据库中。这样就省去了再次发布的麻烦。

 

FastReport代码:

        public static void Print(string ReportName, DataTable dtPrintInfo)
        {
            //创建报告实例
            Report report = new Report();
            //加载现有报告
            report.Load(Application.StartupPath + "\\DaYinMB\\" + ReportName);
            //获取要打印的数据 
            
// DataSet ds = new DataSet();//(DataSet)_dtInfo.DataSet; 
            
//ds.Tables.Add(_dtInfo);

            string[] dr = new string[3];
            dr = BusinessTool.GetReportName(ReportName);
            foreach (object o in report.AllObjects)
            {
                if (o.GetType() == typeof(TextObject))
                {
                    TextObject txt = o as TextObject;
                    txt.Left = txt.Left + Factory.Utility.GetObject().ToInt(dr[2]).Value;
                    txt.Top = txt.Top + Factory.Utility.GetObject().ToInt(dr[1]).Value;
                }
                if (o.GetType() == typeof(FastReport.Barcode.BarcodeObject))
                {
                    FastReport.Barcode.BarcodeObject bar = o as FastReport.Barcode.BarcodeObject;
                    bar.Left = bar.Left + Factory.Utility.GetObject().ToInt(dr[2]).Value;
                    bar.Top = bar.Top + Factory.Utility.GetObject().ToInt(dr[1]).Value;
                }
            }



            //注册数据集
            report.RegisterData(dtPrintInfo, "Table");
            report.GetDataSource("Table").Enabled = true;
            //运行报告
#if DEBUG
            report.Design();
            report.Show();
#else
            report.Show();
#endif
            //报告所使用的免费资源
            report.Dispose();
        }

从代码中我们不难发现,主要就是加载一个报表路径,然后注册数据,最后显示。中间有一个对偏移量的设置。使用FastReport,编程还是比较方便的。最终选用它主要是基于如下3方面原因:

1.支持Oracle数据源

2.支持C#

3.编程方便,支持行转列、偏移量设置等功能

posted on 2012-09-03 13:33  zyi  阅读(795)  评论(0编辑  收藏  举报

导航