[英]How to stop printing error pages in ReportViewer using C#
我有一個主報告文件和一個子報告文件。
主報告文件將調用子報告文件。
讓我們先看一下代碼。
private void CreatePDF(string fileName)
{
try
{
// Variables
Warning[] warnings;
string[] streamIds;
string mimeType = string.Empty;
string encoding = string.Empty;
string extension = string.Empty;
string _strGijunMonth = DateTime.Parse(GijunMonth).ToString("yyyyMM");
byte[] bytes = null;
// Setup the report viewer object and get the array of bytes
ReportViewer viewer = new ReportViewer();
viewer.LocalReport.DataSources.Clear();
viewer.ProcessingMode = ProcessingMode.Local;
viewer.LocalReport.ReportEmbeddedResource = "MasterReport.rdlc";
viewer.LocalReport.EnableExternalImages = true;
DataTable _dt = base.GetDataTable(
"my_procedure"
, _strMainNo
);
_intTotalPage = _dt.Rows.Count * 2;
ReportDataSource _ds = new ReportDataSource();
_ds.Value = _dt;
_ds.Name = "SetData";
viewer.LocalReport.DataSources.Add(_ds);
// sub report event
viewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(LocalReport_SubreportProcessing);
// print
viewer.RefreshReport();
bytes = viewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);
System.IO.FileStream newFile1 = new System.IO.FileStream(fileName, System.IO.FileMode.Create);
newFile1.Write(bytes, 0, bytes.Length);
newFile1.Close();
}
catch
{
throw;
}
}
void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
{
try
{
string MAINT_NO = e.Parameters["MAINT_NO"].Values[0];
string _strGijunMonth = DateTime.Parse(GijunMonth).ToString("yyyyMM");
// get sub report procedure
DataSet _dsCust_Info = base.GetDataSet(
"my_sub_procedure"
, MAINT_NO
, _strGijunMonth
);
----> by somehow, it should throw error. If so, I should not print error page to pdf.
}
catch (Exception err)
{
}
}
我的應用程序使用文件名參數調用“ CreatePDF”方法。
假設我必須打印到PDF 5頁。
在調用LocalReport_SubreportProcessing事件時,某些子報表在數據中具有錯誤值。 因此,我在LocalReport_SubreportProcessing事件中引發了錯誤。
例如,當我說有5頁並且只有1、2、3和5頁可以,並且第4頁不應打印為PDF。
我不知道如何刪除已經由ReportViewer創建的PDF頁面。 如您所見,LocalReport_SubreportProcessing事件是在創建PDF文件之后發生的。
任何人都有解決此問題的想法嗎?
也許reportViewer.CancelRendering(0); 當您檢測到錯誤時?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.