在aspx 页面中,通过设置connectionstring 和 parameters 输入报表中,并通过 CrystalreportViewer 使用方法ExportToHttpResponse 输出为PDF 文件 供下载。

 private void ExportPdfReport()

{

            if (File.Exists(MapPath("~/Reports/DropshipInvoice.rpt")))
            {


                ReportDocument rptDropshipInvoice = new ReportDocument();

               //获取报表位置,并装载
                rptDropshipInvoice.Load(MapPath("~/Reports/DropshipInvoice.rpt"));
                rptDropshipInvoice.ReportOptions.EnableSaveDataWithReport = false;

                // initialize database connection information.设置连接字符串
                var connectionString =
                    new SqlConnectionStringBuilder(DbUtils.ActualConnectionString);

               //为 报表中的每个报表 或者子报表设置连接字符串
                foreach (IConnectionInfo connection in rptDropshipInvoice.DataSourceConnections)
                {
                    if (connectionString.IntegratedSecurity)
                    {
                        connection.SetConnection(connectionString.DataSource, connectionString.InitialCatalog,
                                                 connectionString.IntegratedSecurity);
                    }
                    else
                    {
                        connection.SetConnection(connectionString.DataSource, connectionString.InitialCatalog,
                                                 connectionString.UserID, connectionString.Password);
                    }
                }

                 //输入参数到报表中

                rptDropshipInvoice.SetParameterValue("beginDate", calandarShipDay.SelectedDate);
                rptDropshipInvoice.SetParameterValue("endDate", calandarShipDay.SelectedDate.AddDays(1));
                rptDropshipInvoice.SetParameterValue("CustomerUserID", CurrentLoginUser.UserID.ToString());
                rptDropshipInvoice.SetParameterValue("MainsiteApplicationID", SystemConfiguration.MainSiteApplicationId.ToString());

                 //导出报表

                ExportReport(rptDropshipInvoice, "DropshipInvoice" + calandarShipDay.SelectedDate.ToString("yyyyMMdd"), ExportFormatType.PortableDocFormat);
            }

//ExportReport 方法,在aspx页面中 导出report 模板中的数据,并生成一个pdf 文件

Private void ExportReport(对应参数)

{

 HttpContext.Current.Response.Buffer = false;
        
            // Clear the response content and headers
            HttpContext.Current.Response.ClearContent();
            HttpContext.Current.Response.ClearHeaders();

            rptDropshipInvoice.ExportToHttpResponse(formatType, HttpContext.Current.Response, true, strExportFileName);
            HttpContext.Current.Response.Flush();
            HttpContext.Current.Response.End();

}

相关文章:

  • 2021-08-12
  • 2022-12-23
  • 2022-12-23
  • 2021-07-01
  • 2022-02-20
  • 2022-12-23
  • 2021-11-18
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-15
  • 2021-09-16
  • 2021-05-31
  • 2021-09-20
  • 2022-12-23
相关资源
相似解决方案