【发布时间】:2014-02-25 06:15:12
【问题描述】:
我在使用水晶报表自动打印报表时遇到问题。下面是我的代码sn-p
它正在打印,但问题是它忽略了 ReportView.SelectionFormula(仅包含第 1 页到第 10 页)但打印数据源中的所有记录。
ConnectionInfo ConInfo;
try
{
this.Cursor = Cursors.WaitCursor;
ConInfo = ConfigureCrystalReportsRD();
ReportDocument.Load(reportToLoad);
ReportView.ReportSource = ReportDocument;
SetDBLogonForReportRD(ConInfo, ReportDocument);
SetReserveFormulaValue();
string strReportFilter = "";
strReportFilter = ReportDocument.DataDefinition.RecordSelectionFormula;
if (strReportFilter != "" && formulaFields != "")
{
ReportView.SelectionFormula = strReportFilter + " and " + formulaFields;
}
else
{
ReportView.SelectionFormula = formulaFields;
}
if (isPint == true)
{
this.Cursor = Cursors.WaitCursor;
System.Drawing.Printing.PrinterSettings printer = new System.Drawing.Printing.PrinterSettings();
System.Drawing.Printing.PageSettings page = new System.Drawing.Printing.PageSettings();
ReportDocument.PrintToPrinter(printer,page,true);
MessageBox.Show("Printing at " + printer.PrinterName + " .....");
this.Cursor = Cursors.Default;
}
this.Cursor = Cursors.Default;
}
catch (Exception e)
{
oGenMethod.ErrorMessage(e.Message, FORMID, "PreviewReport");
}
注意:
ReportView.PrintReport() 成功完成这项工作,但它会弹出打印机设置
提前谢谢你!
编辑:
我的代码中的错误是我只在 ReportViewer 对象上设置了 RecordSelectionFormula,而不是在报告文档上。
ConnectionInfo ConInfo;
string strReportFilter = "";
try
{
this.Cursor = Cursors.WaitCursor;
ConInfo = ConfigureCrystalReportsRD();
ReportDocument.Load(reportToLoad);
ReportView.ReportSource = ReportDocument;
SetDBLogonForReportRD(ConInfo, ReportDocument);
SetReserveFormulaValue();
strReportFilter = ReportDocument.DataDefinition.RecordSelectionFormula;
if (strReportFilter != "" && formulaFields != "")
ReportView.SelectionFormula = strReportFilter + " and " + formulaFields;
else
ReportView.SelectionFormula = formulaFields;
ReportDocument.DataDefinition.RecordSelectionFormula = ReportView.SelectionFormula;
if (isPint == true)
{
this.Cursor = Cursors.WaitCursor;
ReportDocument.PrintToPrinter(1, true, 0, 0);
this.Cursor = Cursors.Default;
}
【问题讨论】:
标签: c# winforms crystal-reports ado.net