C/S开发框架支持加载数据库的FastReport.NET报表模板文件 - 功能升级


应多个用户要求,将本地FastReport报表模板文件改为存储到数据库,现已开发完成,请看详细介绍:
1. 系统管理模板增加【报表管理】功能按钮。

2. 点击【报表管理】按钮打开功能界面

3. 【报表管理】资料编辑界面

4. 【报表管理】功能界面 - 上传、设计报表功能

5. 加载本地报表模板文件的使用方法
以前使用的加载本地报表文件的写法,报表模板文件在debug\reports子目录下
C# Code:
#region 方法1:加载本地报表文件写法
//打印主从表数据
string file = Application.StartupPath + @"\Reports\rptSO.frx";
Report rptSO = new Report();
rptSO.Load(file);//加载报表模板文件
#endregion
//来源:C/S框架网 | www.csframework.com | QQ:23404761
//打印主从表数据
string file = Application.StartupPath + @"\Reports\rptSO.frx";
Report rptSO = new Report();
rptSO.Load(file);//加载报表模板文件
#endregion
//来源:C/S框架网 | www.csframework.com | QQ:23404761
6. 加载数据库存储的报表模板文件的使用方法
C# Code:
#region 方法2:加载数据库的报表模板
CSFrameworkV5.Business.bllReports rpt = new bllReports();
byte[] bs = rpt.GetReportData("rptSO.frx");
if (bs == null || bs.Length == 0) throw new Exception("没有报表模板数据!");
//写入到临时文件
string tmpfile = Path.Combine(Application.StartupPath + "\\Reports", DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".frx");
File.WriteAllBytes(tmpfile, bs);
Report rptSO = new Report();
rptSO.Load(tmpfile);//加载报表模板文件
File.Delete(tmpfile);//删除临时文件
#endregion
//来源:C/S框架网 | www.csframework.com | QQ:23404761
CSFrameworkV5.Business.bllReports rpt = new bllReports();
byte[] bs = rpt.GetReportData("rptSO.frx");
if (bs == null || bs.Length == 0) throw new Exception("没有报表模板数据!");
//写入到临时文件
string tmpfile = Path.Combine(Application.StartupPath + "\\Reports", DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".frx");
File.WriteAllBytes(tmpfile, bs);
Report rptSO = new Report();
rptSO.Load(tmpfile);//加载报表模板文件
File.Delete(tmpfile);//删除临时文件
#endregion
//来源:C/S框架网 | www.csframework.com | QQ:23404761
7. 测试

7. 本次改动及升级步骤
7.1 系统数据库增加 sys_Reports表
7.2 frm, bll, dal, model 源码
7.3 CSFrameworkV5.Library.ReportLib.cs文件添加一个类
C# Code:
public class ReportLib
{
public static void DesignReport(string file, bool isCreateNew)
{
Report rpt = new Report();
if (isCreateNew)
rpt.Design(true);
else
{
rpt.Load(file);
rpt.Design(true);
}
}
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
{
public static void DesignReport(string file, bool isCreateNew)
{
Report rpt = new Report();
if (isCreateNew)
rpt.Design(true);
else
{
rpt.Load(file);
rpt.Design(true);
}
}
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
8. Bug修改记录 - 20201022
8.1 报表目录下产生过多的临时文件;
8.2 修改报表后没有更新报表数据;
设计报表按钮的Click事件的源码:
C# Code:
//设计报表
private void btnDesign_Click(object sender, EventArgs e)
{
string tmpFile = "";
try
{
byte[] bs = (byte[])_BLLInstance.DataBinderRow[sys_Reports.Data];
if (bs == null) bs = new byte[] { };
//写入到临时文件
tmpFile = Path.Combine(Application.StartupPath + "\\Reports", DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".frx");
File.WriteAllBytes(tmpFile, bs);
//打开报表设计器
ReportLib.DesignReport(tmpFile, bs.Length == 0);
//保存报表数据
_BLLInstance.DataBinderRow[sys_Reports.Data] = File.ReadAllBytes(tmpFile);
}
catch (Exception ex)
{
Msg.Warning(ex.Message);
}
//删除临时文件
if (File.Exists(tmpFile)) File.Delete(tmpFile);
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
private void btnDesign_Click(object sender, EventArgs e)
{
string tmpFile = "";
try
{
byte[] bs = (byte[])_BLLInstance.DataBinderRow[sys_Reports.Data];
if (bs == null) bs = new byte[] { };
//写入到临时文件
tmpFile = Path.Combine(Application.StartupPath + "\\Reports", DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".frx");
File.WriteAllBytes(tmpFile, bs);
//打开报表设计器
ReportLib.DesignReport(tmpFile, bs.Length == 0);
//保存报表数据
_BLLInstance.DataBinderRow[sys_Reports.Data] = File.ReadAllBytes(tmpFile);
}
catch (Exception ex)
{
Msg.Warning(ex.Message);
}
//删除临时文件
if (File.Exists(tmpFile)) File.Delete(tmpFile);
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
注:本次升级仅适用企业版v4.x、旗舰版v5.x用户!!!

扫一扫加微信


VIP用户下载源码:
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网