目前我使用以下方法将连接信息分配给所有报告部分。但是由于我在报告中有许多部分,因此报告会在近 10 秒后显示。看起来真的很慢。有没有其他方法可以在客户端安装每个CR时一劳永逸地设置登录信息。
JFYI:所有 CR 都使用相同的登录凭据连接到同一个数据库。提前谢谢你。
readDiamondBillReport = new RealDiamondBill();
crConnectionInfo.ServerName = db.Connection.DataSource;
crConnectionInfo.DatabaseName = db.Connection.Database;
crConnectionInfo.UserID = "client";
crConnectionInfo.Password = "client";
crConnectionInfo.IntegratedSecurity = false;
CrTables = readDiamondBillReport.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}
Sections crSections2 = readDiamondBillReport.ReportDefinition.Sections;
// loop through all the sections to find all the report objects
foreach (Section crSection in crSections2)
{
ReportObjects crReportObjects = crSection.ReportObjects;
//loop through all the report objects in there to find all subreports
foreach (ReportObject crReportObject in crReportObjects)
{
if (crReportObject.Kind == ReportObjectKind.SubreportObject)
{
SubreportObject crSubreportObject = (SubreportObject)crReportObject;
//open the subreport object and logon as for the general report
ReportDocument crSubreportDocument = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName);
Tables SubCrTables = crSubreportDocument.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table SubCrTable in SubCrTables)
{
crtableLogoninfo = SubCrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
SubCrTable.ApplyLogOnInfo(crtableLogoninfo);
}
}
}
}
readDiamondBillReport.Refresh();
我终于发现,应用登录信息既不是问题,刷新报告也不是问题。但它是我的大图片对象,我用它来在水晶报告中设置水印。
我有 10 份报告使用此图像作为水印。我删除了带水印的图像,现在解决了以下问题:
-
项目构建非常非常快。以前需要大约 1 分钟才能完成构建,现在已大幅减少到 8-10 秒。
对 项目的任何更改,尤其是对报表所做的任何更改都会更快地保存。
我曾经在一两次构建后得到"没有足够的存储空间来完成此操作"。我不得不重新启动 VS 并为每个构建交叉手指。
Crystal Reports在CrystalReportViewer上的显示速度更快,
objrpt.PrintToPrinter
工作速度也快500倍。
我希望这些要点能帮助其他程序员。
虽然你已经回答了你自己的问题,但我会指出一种可以与水晶报告一起使用的替代方法。 通常,人们使用"拉取"方法,在 Crystal 报表上设置连接,并根据报表中嵌入的查询"拉取"数据集。
但是,也可以使用"推送"方法。 在此方案中,您只需将 Crystal 报表数据源绑定到 XSD 架构,并在 Crystal 报表上设置数据集。 在 .NET 中,您可以轻松地从数据集生成 XSD,因此此方法非常简单。 因此,您可以将任何子报表绑定到传递的数据集中所需的特定表。
这样做的优点是数据可以来自任何 DBMS(与数据库无关),并且可以在传递到报表之前根据需要进行操作(实现自定义安全性、联接等)。
需要注意的是,您不会为具有大量数据的报表实现此方法,因为 .NET 数据集可能会占用大量内存。
但是,由于性能问题与图像有关,因此此方法无济于事。
每个报表都有一个子报表集合。
您可以将登录信息应用于每个子报表的表,而不是在每个部分中搜索子报表。
这是一些代码
private void showrep(string repName)
{
rd = new ReportDocument();
rd.Load(pth+"\"+repName);
LogInInfo();
crv.ReportSource = rd; // crv is the reportviewer
crv.Show();
}
private void LogInInfo()
{
MyApp.Properties.Settings s = new MyApp.Properties.Settings();
TableLogOnInfo linfo = new TableLogOnInfo();
linfo.ConnectionInfo.DatabaseName = s.dbname;
linfo.ConnectionInfo.UserID = s.usr;
linfo.ConnectionInfo.Password = s.pw;
linfo.ConnectionInfo.ServerName = s.svr;
foreach (Table t in rd.Database.Tables)
{
t.ApplyLogOnInfo(linfo);
}
foreach (ReportDocument sr in rd.Subreports)
{
foreach (Table t in sr.Database.Tables )
{
t.ApplyLogOnInfo(linfo);
}
}
}
希望对您有所帮助。