报表查看器导出按钮再次加载数据

时间:2019-07-10 03:52:51

标签: c# asp.net telerik

我在reportviewer.aspx中有一个报告查看器。生成报告后,选择Excel格式,然后单击“导出”。我发现在后端,当我按导出按钮时,它将再次加载数据,这会使导出花费20分钟或更长时间。我怀疑导出是否只是转储已经生成的报告内容,还是会加载函数并再次进行计算。如何避免导出再次进行计算,而只是转储已生成的报告?

这是我在reportviewer.aspx后面的代码。

public partial class ReportViewer : CustomPage
    {
        private string _reportSourceFolder = ConfigurationManager.AppSettings["ReportSourceFolder"];

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                EW_REPORTS, true); // added by HC on 2014-10-21, for permission checking

                string reportFileName = Request.QueryString["ReportFileName"];
                if (string.IsNullOrEmpty(reportFileName))
                {
                }
                else
                {
                    int? yearInt = null;
                    string year = Request.QueryString["Year"];
                    if (string.IsNullOrEmpty(year))
                    {
                        yearInt = DateTime.Now.Year;
                    }
                    else
                    {
                        try
                        {
                            yearInt = Convert.ToInt32(year);
                        }
                        catch { }
                    }


                    string reportFullPath = Path.Combine(_reportSourceFolder, reportFileName);

                    Telerik.Reporting.UriReportSource uriReportSource = new Telerik.Reporting.UriReportSource();

                    uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter("lang", WebUtil.GetLanguage()));

                    uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter("companyID", WebUtil.GetCompanyID()));
                    if (yearInt != null)
                    {
                        uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter("year", yearInt));
                    }

                    if (
                        !"AuditReport.trdx".Equals(reportFileName, StringComparison.OrdinalIgnoreCase)
                        //"Report1.trdx".Equals(reportFileName, StringComparison.OrdinalIgnoreCase)
                        //|| "ESGSummaryReport.trdx".Equals(reportFileName, StringComparison.OrdinalIgnoreCase)
                        )
                    {
                        int? fromYear = Common.Util.TryToConvertToInt32(Request.QueryString["fromYear"]);
                        int? fromMonth = Common.Util.TryToConvertToInt32(Request.QueryString["fromMonth"]);
                        int? toYear = Common.Util.TryToConvertToInt32(Request.QueryString["toYear"]);
                        int? toMonth = Common.Util.TryToConvertToInt32(Request.QueryString["toMonth"]);
                        string indicatorIDs = Request.QueryString["indicatorIDs"];
                        string locationIDs = Request.QueryString["locationIDs"];
                        if (fromYear == null ||  fromMonth == null || toYear== null || toMonth == null)
                        {
                            try
                            {
                                DateTime? fiscalYearStartDate = Util.GetCorporateFiscalYearStartDate();
                                if (fiscalYearStartDate != null)
                                {
                                    DateTime now = DateTime.Now;
                                    DateTime startDate = new DateTime(now.Year, fiscalYearStartDate.Value.Month, 1);
                                    if (now < startDate)
                                    {
                                        startDate = startDate.AddYears(-1);
                                    }
                                    DateTime endDate = startDate.AddYears(1).AddMilliseconds(-1d);

                                    if (fromYear == null)
                                    {
                                        fromYear = startDate.Year;
                                    }
                                    if (fromMonth == null)
                                    {
                                        fromMonth = startDate.Month;
                                    }
                                    if (toYear == null)
                                    {
                                        toYear = endDate.Year;
                                    }
                                    if (toMonth == null)
                                    {
                                        toMonth = endDate.Month;
                                    }
                                }
                            }
                            catch { }
                        }

                        // prevent incorrect numbers
                        List<int> indicatorIDsList = new List<int>(1024);
                        string[] indicatorIDsArr = new string[] { };
                        if (indicatorIDs != null)
                        {
                            indicatorIDsArr = indicatorIDs.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                        }
                        foreach(string indicatorID in indicatorIDsArr)
                        {
                            int? temp = Common.Util.TryToConvertToInt32(indicatorID);
                            if (temp != null && !indicatorIDsList.Contains(temp.Value))
                            {
                                indicatorIDsList.Add(temp.Value);
                            }
                        }
                        if (indicatorIDsList.Count > 0)
                        {
                            indicatorIDs = string.Join(",", indicatorIDsList);
                        }
                        else
                        {
                            indicatorIDs = "0";
                        }

                        List<int> locationIDsList = new List<int>(1024);
                        string[] locationIDsArr = new string[] { };
                        if (locationIDs != null)
                        {
                            locationIDsArr = locationIDs.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                        }
                        foreach (string locationID in locationIDsArr)
                        {
                            int? temp = Common.Util.TryToConvertToInt32(locationID);
                            if (temp != null && !locationIDsList.Contains(temp.Value))
                            {
                                locationIDsList.Add(temp.Value);
                            }
                        }
                        if (locationIDsList.Count > 0)
                        {
                            locationIDs = string.Join(",", locationIDsList);
                        }
                        else
                        {
                            locationIDs = "0";
                        }


                        uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter("fromYear", fromYear));
                        uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter("toYear", toYear));
                        uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter("fromMonth", fromMonth));
                        uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter("toMonth", toMonth));
                        //uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter("indicatorIDs", indicatorIDs));
                        uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter("locationIDs", locationIDs));
                    }

                    if ("AuditReport.trdx".Equals(reportFileName, StringComparison.OrdinalIgnoreCase))
                    {
                        uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter("performedDateFrom", DateTime.Now.AddDays(-1d)));
                        uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter("performedDateTo", DateTime.Now));
                    }

                    uriReportSource.Uri = reportFullPath;

                    if (IsPrintPreviewMode())
                    {
                        uiReportViewer.ViewMode = Telerik.ReportViewer.WebForms.ViewMode.PrintPreview;
                    }

                    uiReportViewer.ReportSource = uriReportSource;


                } // end if
            }
            catch (Exception ex)
            {
                uiPanel.Alert(Convert.ToString(HttpContext.GetGlobalResourceObject("Resource", "Message_Error_Occurs")));
                Logger.Log(string.Format("Error occurs in the '{0}.{1}' method.{2}{3}"
                    , System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString()
                    , System.Reflection.MethodBase.GetCurrentMethod().Name
                    , Environment.NewLine
                    , ex.ToString()));
            }
        } // end method

        private bool IsPrintPreviewMode()
        {
            bool val = false;
            string temp = Request.QueryString["IsPrintPreviewMode"];
            if (!string.IsNullOrEmpty(temp))
            {
                try
                {
                    val = Convert.ToBoolean(temp);
                }
                catch { }
            }
            return val;
        }

        protected void uiBack_Click(object sender, EventArgs e)
        {
            string reportFileName = Request.QueryString["ReportFileName"];
            Response.Redirect(string.Format("~/ReportCriteria.aspx?ReportFileName={0}", reportFileName), false);
            Context.ApplicationInstance.CompleteRequest();
        }
    }

0 个答案:

没有答案