绑定到已加载到缓存管理实用程序类的非嵌入式报表
此报表绑定方案类似于以下报表绑定方案“绑定到缓存的嵌入式报表类”。此方案的不同之处在于报表示嵌入。
Crystal Reports for Vistual Studio 提供下列两种有助于用ASP.NET Cache对象缓存报表的功能:
1.一个内置报表缓存管理框架。当相同报表具有唯一参数或者具有要求每个被缓存的实例都要有唯一的密钥的登录凭据时,该框架对此进行识别。
2.ICachedReport接口,该接口向报表缓存管理框架标识缓存管理实用程序类。
缓存非嵌入式报表然后将其绑定到CrystalReportViewer控件。
1.在General Business子目录中找到World Sales Report.rpt文件。
2.将完整的文件目录路径(包括World Sales Report.rpt)复制到剪贴板。
3.在ConfigureCrystalReports()方法中,声明reportPath字符串变量,并将一个包含在上一步复制的World Sales Report文修的目录路径的字符串赋给该变量。
string reportPath = "D:\\Program Files\\Microsoft Visual Studio 9.0\\"+ "Crystal Reports\\Samples\\En\\Reports\\General Business\\"+ "World Sales Report.rpt";
4.声明并实例化NonEmbededReportCacher类,然后向该类传递reportFile字符串变量。
NonEmbeddedReportCacher nonEmbeddedReportCacher = new NonEmbeddedReportCacher(reportFile);
5.将报表缓存管理实用程序类实例赋给CrystalReportViewer控件的ReportSource属性。
crystalReportViewer.ReportSource=nonEmbeddedReportCacher;
创建NonEmbeddedReportCacher缓存箮理实用程序类。
1.在项目中创建一个各为NonEmbeddedReportCacher的新类。
using System;
namespace MyWebApplication
{
public class NonEmbeddedReportCacher
{
public NonEmbeddedReportCacher()
{
}
}
}
2.将ICachedReport接口附加到类签名。
public class NonEmbeddedReportCacher:ICachedReport
3.将三个using[C#]语句添加到类的 顶部。
using CrystalDecisions.Shared;
using CrystalDecisions.ReportSource;
using CrystalDecisions.CrystalReports.Engine;
4.在该类中,声明两个类级实例:一个名为reportFileName的字符串实例和一个名为nonEmbeddedReportDocument的ReportDocument实例。
private string reportFileName;
private ReportDocument nonEmbeddedReportDocument;
5.设置构造函数接受reportFileName字符串,在该构造函数中,将字符串赋给reportFileName类变量。
public NonEmbeddedReportCacher(string reportFileName)
{
this.reportFileName=reportFileName;
}
剩余的步骤将完全实现接口所必需的属性和方法。
IsCacheable
ShareDBLogonInfo
CacheTimeOut
CreateReport()
GetCustomizedCacheKey(RequestContext request)
6.创建IsCacheable属性,它应该返回True.
public virtual boolean IsCacheable
{
get
{
return true;
}
set
{
}
}
7.创建ShareDBLogonInfo属性,它应 该返回False.
public virtual Boolean ShareDBLogonInfo
{
get
{
return false;
}
set
{
}
}
8.创建CacheTimeOut属性,它从CachedReportConstants类返回一个常量。
public virtual TimeSpan CacheTimeOut
{
get
{
return CachedReportConstants.DEFAULT_TIMEOUT;
}
set
{
}
}
9.创建CreateReport()方法,该方法返回已加载到类级ReportDocument实例中的非嵌入式报表。
public virtual ReportDocument CreateReport()
{
if(nonEmbeddedReportDocument==null)
{
nonEmbeddedReportDocument=new ReportDocument();
nonEmbeddedReportDocument.Load(reportFileName);
}
return nonEmbeddedReportDocument;
}
10.创建GetCustomerizedCacheKey()方法并返回空值。
public virtual string GetCustomizedCacheKey(RequestContext request)
{
return null;
}

浙公网安备 33010602011771号