报表——Fast Report
来源:互联网 发布:java工程师评等级 编辑:程序博客网 时间:2024/04/30 03:00
一套软件,应该是离不开报表的,以前一直是接触的是水晶报表、Grid Report报表等,这篇博客说一下Fast Report报表。
1、 初步了解:
引用Fast Report.dll
整体上,他的界面风格还是比较好看的,他的右边是数据源,通过访问数据库即可得到,可以对数据直接拖拽放在显示区域,很是方便,同时他还提供了强大的第三方类库,假如你觉得这个方法不好,可以对方法进行覆盖或者是重写。
具体的模板操作,详见链接:Fast Report操作手册
2 、比较常用的代码,如下:
<span style="font-family:FangSong_GB2312;font-size:24px;"> public class AutoPrintFastReport { private FastReport.Report freport; private EnvironmentSettings ES; private ORG.DataUtility.BLL.AutoPrintReport bll; private string sysdescription = string.Empty; private string report = string.Empty; private string funcName=string.Empty; private string styleid=string.Empty; public void Dispose() { this.freport.Dispose(); this.freport.Clear(); this.ES.Dispose(); } public AutoPrintFastReport() { Init(); } /// <summary> /// 初始化报表风格 /// </summary> private void Init() { this.freport = new FastReport.Report(); this.bll = new BLL.AutoPrintReport(); //report //风格 this.ES = new EnvironmentSettings(); //窗体logo if (File.Exists(@"images/fr.png")) { Image image = Image.FromFile(@"images/fr.png"); this.ES.DesignerSettings.Icon = System.Drawing.Icon.FromHandle(((Bitmap)image).GetHicon()); this.ES.PreviewSettings.Icon = System.Drawing.Icon.FromHandle(((Bitmap)image).GetHicon()); } //窗体title this.ES.DesignerSettings.Text = ""; //界面风格 ES.UIStyle = FastReport.Utils.UIStyle.Office2007Blue; //语言导入 FastReport.Utils.Res.LoadLocale(@"Chinese (Simplified).frl"); } /// <summary> /// 获取模版信息 /// </summary> private void GetTempInf() { if (!string.IsNullOrEmpty(this.funcName)&& !string.IsNullOrEmpty(this.styleid)) { DataSet ds = this.bll.GetReport(this.funcName,this.styleid); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { this.report = ds.Tables[0].Rows[0]["report"].ToString(); this.sysdescription = ds.Tables[0].Rows[0]["reportDesc"].ToString(); } } //设置模版名称 this.freport.FileName = this.sysdescription; } /// <summary> /// 开启设计报表 /// </summary> /// <param name="dt"></param> /// <param name="name"></param> /// <param name="TempID"></param> public void Design(DataTable dt,string name,string funcName,string styleid) { //重做“保存”和“另存为”事件 this.ES.DesignerSettings.CustomSaveDialog += new OpenSaveDialogEventHandler(CustomSaveDialog_Handler); this.ES.DesignerSettings.CustomSaveReport += new OpenSaveReportEventHandler(CustomSaveReport_Handler); //禁用“新建”菜单 this.ES.DesignerSettings.Restrictions.DontCreateReport = true; //禁用“打开”菜单 this.ES.DesignerSettings.Restrictions.DontLoadReport = true; //禁用"最近打开的文档"列表 this.ES.DesignerSettings.Restrictions.DontShowRecentFiles = true; // 注册报表数据 this.freport.RegisterData(dt, name); //加载可用的数据源 this.freport.GetDataSource(name).Enabled = true; //数据库对应的模版 this.funcName = funcName; this.styleid = styleid; this.sysdescription = name; //设置模版数据 this.GetTempInf(); //report为空时不导入 if (!string.IsNullOrEmpty(this.report)) { //导入模版数据 this.freport.LoadFromString(this.report); } this.freport.Design(); // 释放使用的资源 this.ES.DesignerSettings.CustomSaveDialog -= new OpenSaveDialogEventHandler(CustomSaveDialog_Handler); this.ES.DesignerSettings.CustomSaveReport -= new OpenSaveReportEventHandler(CustomSaveReport_Handler); this.freport.Dispose(); this.freport.Clear(); this.ES.Dispose(); } /// <summary> /// FastReport的“保存”功能重载 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CustomSaveReport_Handler(object sender, OpenSaveReportEventArgs e) { try { this.report = e.Report.SaveToString(); bool ch = this.bll.UpdateReport(this.funcName, this.styleid, this.report); if (ch) { MessageBox.Show(FRLang.MSG0004, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(FRLang.MSG0005, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } /// <summary> /// FastReport的“另存为”功能重载 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CustomSaveDialog_Handler(object sender, OpenSaveDialogEventArgs e) { if (MessageBox.Show(FRLang.MSG0003, AppMessage.MSG0000, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { e.Cancel = false; //e.FileName = @"saleProofdetail.frx"; } else { e.Cancel = true; } } /// <summary> /// 打印报表 /// </summary> /// <param name="dt">数据源</param> /// <param name="name">数据源别名</param> /// <param name="TempID">模版ID</param> public void Print(DataTable dt, string name, string funcName,string styleid) { //数据库对应的模版 this.funcName = funcName; this.styleid = styleid; //设置模版数据 this.GetTempInf(); //report为空时报错 if (!string.IsNullOrEmpty(this.report)) { //导入模版数据 this.freport.LoadFromString(this.report); } //注册数据源 this.freport.RegisterData(dt, name); //启用数据源 this.freport.GetDataSource(name).Enabled = true; // 运行报表打印 this.freport.Print(); // 释放使用的资源 this.freport.Dispose(); this.freport.Clear(); } /// <summary> /// 预览报表 /// </summary> /// <param name="dt">数据源</param> /// <param name="name">数据源别名</param> /// <param name="TempID">模版ID</param> public void Preview(DataTable dt, string name, string funcName, string styleid) { //数据库对应的模版 this.funcName = funcName; this.styleid = styleid; //设置模版数据 this.GetTempInf(); //report为空时报错 if (!string.IsNullOrEmpty(this.report)) { //导入模版数据 this.freport.LoadFromString(this.report); } //注册数据源 this.freport.RegisterData(dt, name); //启用数据源 this.freport.GetDataSource(name).Enabled = true; // 运行报表预览 this.freport.Show(); // 释放使用的资源 this.freport.Dispose(); this.freport.Clear(); } }</span>
假如遇到报表乱码的问题,应该是语言的原因,可以在代码中设置语言为中文,或者是在报表中设置为中文哦。
假如报表在保存后,里面的一些信息是我们想要的,或者是我们需要修改的。我们可以在报表保存的时候,截获他保存的信息,这样可以在上面加以改动,我是通过截取保存的XML文件来进行修改,变成自己想要的样子。
0 0
- 报表——Fast Report
- 用Fast Report建立跨栏报表
- 用Fast Report建立跨栏报表
- fast report 报表列中跨行合并功能解决办法
- Fast Report
- Java开发报表——Grid++Report 报表设计器
- Java开发报表——Grid++Report 报表设计器
- 报表示例——用Jasper report实现MongoDB join
- Grid+report报表设计——关于结账
- 我的开发履历:FAST-REPORT 报表工具接口封装.2006.8
- Fast Report 4.X——Delphi 2009的中文解决方法
- Fast Report 问题集
- fast report for delphi
- fast report 的使用说明
- fast report 的预览
- Fast Report使用
- fast report 的使用说明
- Fast Report 增加自定义变量
- APK 的编译流程
- 1 快速实现空页面展示
- 【英语】十一期间的英语学习
- python 学习笔记(1)--numpy数组转置
- UVa 11082 Matrix Decompressing (最大流问题)
- 报表——Fast Report
- 接下来两周的计划
- Rectangles 简单几何计算
- Java基础(接口与抽象类)
- android之as自动化删除无用资源为apk瘦身
- 即时通信原理
- 第三章,jsp内置对象的文字乱码处理
- Mac OS X下利用MPI进行并行计算
- 微信小程序