如何在一个应用程序中使用多个.rpt文件(水晶报告)?

时间:2011-11-10 06:57:20

标签: c# crystal-reports

有人知道如何在一个应用程序中使用多个.rpt文件(水晶报告)吗?我需要生成报告并直接保存到.pdf,但我不知道该怎么做。我设法在使用单个.rpt文件时执行此操作,但我不确定如何使用多个.rpt文件生成报告。有人可以帮助我吗?

我的编码:

ReportDocument cryRpt = new ReportDocument();
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables CrTables;

cryRpt.Load("C:\\rptBilling.rpt");

crConnectionInfo.ServerName = "ServerName";
crConnectionInfo.DatabaseName = "DatabaseName";
crConnectionInfo.UserID = "userID";
crConnectionInfo.Password = "Password";

CrTables = cryRpt.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
    crtableLogoninfo = CrTable.LogOnInfo;
    crtableLogoninfo.ConnectionInfo = crConnectionInfo;
    CrTable.ApplyLogOnInfo(crtableLogoninfo);
}

cryRpt.SetParameterValue("@CollectionStartDate", "2011/09/14");
cryRpt.SetParameterValue("@CollectionEndDate", "2011/09/29");
cryRpt.SetParameterValue("@SpokeCode", "14");//country code
cryRpt.SetParameterValue("@UseCollectionDate", "1");//value can be set 0 or 1
cryRpt.SetParameterValue("@UseUploadDate", "0");//value can be set 0 or 1
cryRpt.SetParameterValue("@UploadStartDate", "2011/09/23");
cryRpt.SetParameterValue("@UploadEndDate", "2011/09/23");

cryRpt.ExportToDisk(ExportFormatType.PortableDocFormat, "e:\\1.pdf");

1 个答案:

答案 0 :(得分:0)

如果你的意思是单独的pdf文件,那么你可以使用cryRpt.Load()重新加载新的rpt。确保清除参数和新的SetParameterValue。

编辑:我无法发表评论,因为我没有足够的积分,但我从未使用过Crystal Reports功能,但我假设您可以保留相同的变量cryRpt并且一旦加载了第一个pdf您可以通过再次调用Load()重复使用cryRpt并执行与您已经执行的相同的步骤,但如果需要则使用新变量。如果它不允许多个cryRpts,你可以只处理并初始化一个新的。我可能会误解你在寻找什么,因为我假设你想要两个单独的pdf文件。