2011-11-10 33 views
0

有谁知道如何在一个应用程序中使用多个.rpt文件(水晶报告)?我需要生成报告并直接保存到.pdf,但我不知道如何去做。当我使用单个.rpt文件时,我设法做到这一点,但我不确定如何生成具有多个.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"); 

回答

0

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

编辑:我不能作出评论,因为我不具备足够的点,但我从未使用过的水晶报表功能,但我假设你可以保持相同的变量cryRpt,一旦你加载你的第一个pdf你可以通过再次调用Load()再次使用cryRpt,并按照你已经做过的相同的步骤,但如果需要使用新的变量。如果它不允许多个cryRpts,你可以处理并初始化一个新的。我可能会误解你在找什么,因为我假设你想要两个独立的pdf文件。

+0

没有ü意味着,我需要为每个RPT文件的另一个功能?例如:public static void BillingReport(),public static void AgingReport() – srahifah

相关问题