C# “报表查看器导出”按钮再次加载数据

C# “报表查看器导出”按钮再次加载数据,c#,asp.net,telerik,C#,Asp.net,Telerik,我在reportviewer.aspx中有一个报表查看器。生成报告后,我选择Excel格式并单击导出。我发现在后端,当我按下导出按钮时,它会再次加载数据,并使导出花费20分钟或更长时间。我怀疑导出是否只是转储已生成的报告内容,还是将加载函数并再次进行计算。我如何避免再次导出进行计算,而只是转储已生成的报告 这是我在reportviewer.aspx后面的代码 public partial class ReportViewer : CustomPage { private

我在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();
        }
    }
公共部分类ReportViewer:CustomPage
{
私有字符串_reportSourceFolder=ConfigurationManager.AppSettings[“reportSourceFolder”];
受保护的无效页面加载(对象发送方、事件参数e)
{
尝试
{
EW_报告,正确);//由HC于2014年10月21日添加,用于权限检查
string reportFileName=Request.QueryString[“reportFileName”];
if(string.IsNullOrEmpty(reportFileName))
{
}
其他的
{
int?yearInt=null;
字符串year=Request.QueryString[“year”];
if(string.IsNullOrEmpty(年))
{
yearInt=DateTime.Now.Year;
}
其他的
{
尝试
{
yearInt=转换为32(年);
}
捕获{}
}
string reportFullPath=Path.Combine(_reportSourceFolder,reportFileName);
Telerik.Reporting.UriReportSource=新Telerik.Reporting.UriReportSource();
uriReportSource.Parameters.Add(新的Telerik.Reporting.Parameter(“lang”,WebUtil.GetLanguage());
uriReportSource.Parameters.Add(新的Telerik.Reporting.Parameter(“companyID”,WebUtil.GetCompanyID());
如果(yearInt!=null)
{
uriReportSource.Parameters.Add(新的Telerik.Reporting.Parameter(“年”,yearInt));
}
如果(
!“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”]);
字符串指示符=Request.QueryString[“指示符”];
string locationIDs=Request.QueryString[“locationIDs”];
如果(fromYear==null | | | fromMonth==null | | toYear==null | | toMonth==null)
{
尝试
{
DateTime?fiscalYearStartDate=Util.GetCorporateFiscalYearStartDate();
如果(fiscalYearStartDate!=null)
{
DateTime now=DateTime.now;
DateTime startDate=新的日期时间(now.Year,fiscalYearStartDate.Value.Month,1);
如果(现在<开始日期)
{
startDate=startDate.AddYears(-1);
}
DateTime endDate=startDate.AddYears(1.addMillimes(-1d);
if(fromYear==null)
{
fromYear=起始日期。年份;
}
if(fromMonth==null)
{
fromMonth=开始日期。月份;
}
如果(toYear==null)
{
toYear=endDate.Year;
}
if(toMonth==null)
{
toMonth=结束日期。月份;
}
}
}
捕获{}
}
//防止错误号码
列表指示符列表=新列表(1024);
字符串[]指示符sarr=新字符串[]{};
如果(指示符号!=null)
{
IndicationsArr=indications.Split(“,”.tocharray(),StringSplitOptions.RemoveEmptyEntries);
}
foreach(指示符号ARR中的字符串指示符号)
{
int?temp=通用工具TRYTOCONVERTOINT32(指示符号);
if(temp!=null&&!指示符列表包含(temp.Value))
{
指示符号列表添加(温度值);
}
}
如果(指示符列表计数>0)
{