1

Gurus 我们正在.NET 4.0 中开发一个win forms 应用程序,它使用RDLC 控件生成PDF 报告。由于报告生成需要大量时间,我们决定为每个文件实现 Parallel.. 使用以下代码,它会为第一条记录生成 PDF,然后系统就会挂起.. 请帮助我们...

 public void generatereport()
        {
            button1.Enabled = false;
            button4.Enabled = false;
            DataTable dtBranch = new DataTable();
            dtBranch = getBranchNo(); -- we might get around 300 rows here

            try
            {
                Parallel.ForEach(dtBranch.AsEnumerable(), drow =>
                   {
                       // Shows the ReportData along with the branch code
                        reportdate = drow["reportdate"].ToString();
                       string branchName = drow["BranchNo"].ToString();
                        ProcessReport(branchName);
                   });
                  reportViewer2.Visible = false;
            button1.Enabled = true;
            button4.Enabled = true;
            lblMsg.Text = "Branch Summary Generated at '" + @fullpath + "'";
            }
            catch (AggregateException e)
            {
                //Console.Write(e.Data + e.Message);
                //Console.ReadLine();
            }

        }

        private void ProcessReport(string branName)
        {
            if (reportViewer2.InvokeRequired)
            {
                ProcessReportCallBack d = new ProcessReportCallBack(ProcessReport);
                Invoke(d, new object[] { branName });
            }
            else
            {
                log.Debug("branch" + DateTime.Now.ToString());
                DataTable dt = new DataTable();
                dt = getReportOrderNoBasedonBranchID(branName);//Get all the report order no as per the branch id

                    this.sp_getReportOrderNoTableAdapter.Fill(this.getRptNo.sp_getReportOrderNo, branName);
                    this.reportViewer2.LocalReport.SubreportProcessing += new Microsoft.Reporting.WinForms.SubreportProcessingEventHandler(this.reportViewer2_Subreport1);
                    this.reportViewer2.Clear();
                    this.reportViewer2.ProcessingMode = ProcessingMode.Local;
                    this.reportViewer2.LocalReport.ReportPath = @"Master.rdlc";
                    this.reportViewer2.Refresh();

                    Savepdf("reportViewer2", branName + "_" + reportdate);

            }
    }

在保存 PDF 中,我们正在生成 PDF 报告..

byte[] bytes = null;

                bytes = reportViewer2.LocalReport.Render(
                "PDF", null, out mimeType, out encoding,
                 out extension,
                out streamids, out warnings);
                filename = BranchName + '_' + "Summary" + ".pdf";

                using (FileStream fs = new FileStream(@fullpath + '\\' + filename, FileMode.Create))
                {
                    fs.Write(bytes, 0, bytes.Length);
                    fs.Close();
                }
                bytes = null;

请提供您的反馈

4

1 回答 1

0

您不需要示例代码来导出到 PDF,当RDLC已经呈现到ReportViewer尝试从以下位置找到此图标时ToolBars of ReportViewer Control

在此处输入图像描述

编辑

以编程方式将 RDLC 报告另存为 PDF

public void Save(ReportViewer viewer, string savePath)
{
    byte[] Bytes = viewer.LocalReport.Render("PDF", "", null, null, null, null, null);

    using (FileStream Stream = new FileStream(savePath, FileMode.Create)) {
        Stream.Write(Bytes, 0, Bytes.Length);
    }
}
于 2013-01-03T14:50:29.877 回答