在项目C#客户端应用通过hessian访问j2ee服务中,报表需要统一展示,类似于报表系统,及根据报表格式和数据源参数在一个报表展示窗口统一展示,并具有导出、打印等基本功能。打算使用水晶报表来实现,下述为具体细节,遗憾的是经过仔细的分析,不能很好地满足我们的要求,最后通过微软的rdlc来实现。
1. 报表系统设计
1) 整体架构(基于水晶报表)
重点:
·所有报表都集成、转移到报表系统中;
·报表系统最好是基于网页;
2) 具体实现
·利用水晶报表工作制作水晶报表文件(RPT文件);
·将RPT文件,通过发布程序发布到服务器上去;
·给报表授权,只有可浏览和不可浏览2个权限;
·通过IE或C#客户端“报表展示中心”显示报表,期间会再一次验证用户权限。
2. 相应的实现方案
针对上文中提到的系统设计,我们前期做了2种不同实现方案,结果都不能满足我们的要求,或参数传递有问题,或性能、安全有问题。下述为2种实现方案具体内容。
1) 通过Java API调用RAS实现报表的JSP页面浏览,核心代码如下:
CrystalReportViewer viewer = new CrystalReportViewer();
ReportAppSession ra = new ReportAppSession();
ra.createService("com.crystaldecisions.sdk.occa.report.application.ReportClientDocument");
ra.setReportAppServer("localhost");
ra.initialize();
//
ReportClientDocument clientDoc = new ReportClientDocument();
clientDoc.setReportAppServer(ra.getReportAppServer());
clientDoc.open(reportName, OpenReportOptions._openAsReadOnly);
//
viewer.setReportSource(clientDoc.getReportSource());
//
if(session.getAttribute("refresh")==null){
viewer.refresh();
session.setAttribute("refresh","true");
}
viewer.processHttpRequest(request, response,
getServletConfig().getServletContext(), out);
viewer.dispose();
该方案缺点:开发人员不能接管数据库连接,参数处理麻烦,尤其是多个参数、关联参数需要定制JSP页面实现。
2) 通过C# windows Form嵌入CrystalReportViewer实现水晶报表浏览,核心代码如下:
CrystalReportViewer crystalReportViewer1 = new CrystalReportViewer();
ReportDocument document = new ReportDocument();
document.Load(@"d:\Report2p.rpt");
this.crystalReportViewer1.ReportSource = document;
//
该方案缺点:开发人员不能接管数据库连接,rpt文件暴露在客户端有安全风险,crystalReportViewer1控件渲染数据很慢性能不高;
3) 通过C# windows Form嵌入CrystalReportViewer,利用InfoObjects访问CRS2008,没实现(原因是执行到SessionMgr sessionMgr = new SessionMgr();出错,目前处于无解状态).