水晶报表(crystal report)添加参数及连接字符串

     在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();

}

转载于:https://www.cnblogs.com/host-2008/archive/2011/04/09/2010200.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值