Exemple #1
0
        /// <summary>
        /// 创建报表处理控件
        /// </summary>
        /// <param name="reportConfigs"></param>
        /// <param name="reprotParams"></param>
        /// <returns></returns>
        private static ReportViewer CreateReportViewer(NameValueCollection reportConfigs, Dictionary <string, string> reprotParams)
        {
            //获取报表配置信息
            string reportUrl  = reportConfigs[Constant.REPORT_CONFIG_SERVICE_URL];
            string reportPath = reportConfigs[Constant.REPORT_CONFIG_REPORT_PATH];
            string userName   = reportConfigs[Constant.REPORT_CONFIG_USER_NAME];
            string password   = reportConfigs[Constant.REPORT_CONFIG_PASSWORD];
            string domain     = reportConfigs[Constant.REPORT_CONFIG_DOMAIN];

            Log.Info("*****************报表详细********************");
            Log.Info(string.Format("报表服务: {0}", reportUrl));
            Log.Info(string.Format("报表路径: {0}", reportPath));
            Log.Info(string.Format("报表用户: {0}", userName));
            Log.Info(string.Format("用户密码: {0}", password));
            Log.Info(string.Format("用户域: {0}\n\r", domain));

            try
            {
                //创建报表控件
                ReportViewer reportViewer = new ReportViewer();
                reportViewer.PromptAreaCollapsed                  = true;
                reportViewer.ProcessingMode                       = ProcessingMode.Remote; //远程报表
                reportViewer.ServerReport.ReportServerUrl         = new Uri(reportUrl);
                reportViewer.ServerReport.ReportPath              = (reportPath.StartsWith("/") ? reportPath : string.Format("/{0}", reportPath));
                reportViewer.ServerReport.ReportServerCredentials = new SSRSReportServerCredentials(userName, password,
                                                                                                    domain); //报表用户信证

                //生成报表参数
                IList <ReportParameter>       reportParams = new List <ReportParameter>();
                ReportParameterInfoCollection paramsInfo   = default(ReportParameterInfoCollection);
                paramsInfo = reportViewer.ServerReport.GetParameters();
                paramsInfo.ToList().ForEach(it =>
                {
                    string paramValue = string.Empty;

                    #region 参数转换
                    switch (it.DataType)
                    {
                    case ParameterDataType.DateTime:
                        var dateTime = DateTime.Now;

                        if (reprotParams[it.Name] != null)
                        {
                            DateTime.TryParse(reprotParams[it.Name], out dateTime);
                        }

                        paramValue = dateTime.ToLongDateString();
                        break;

                    case ParameterDataType.Boolean:
                        var boolean = true;

                        if (reprotParams[it.Name] != null)
                        {
                            Boolean.TryParse(reprotParams[it.Name], out boolean);
                        }

                        paramValue = boolean ? "1" : "0";
                        break;

                    case ParameterDataType.Integer:
                        var int32 = 0;

                        if (reprotParams[it.Name] != null)
                        {
                            Int32.TryParse(reprotParams[it.Name], out int32);
                        }

                        paramValue = int32.ToString();
                        break;

                    case ParameterDataType.Float:
                        var vFloat = 0.0;

                        if (reprotParams[it.Name] != null)
                        {
                            Double.TryParse(reprotParams[it.Name], out vFloat);
                        }

                        paramValue = vFloat.ToString();
                        break;

                    case ParameterDataType.String:
                    default:
                        if (reprotParams[it.Name] != null)
                        {
                            paramValue = reprotParams[it.Name].ToString();
                        }
                        break;
                    }
                    #endregion

                    reportParams.Add(new ReportParameter(it.Name, paramValue, true));
                });

                reportViewer.ServerReport.SetParameters(reportParams);

                return(reportViewer);
            }
            catch (Exception e)
            {
                Log.Error(e);
                throw new InvalidOperationException("匹配报表参数异常。");
            }
        }
Exemple #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //prevent caching of reports - fixes issues of 'reports execution has expired or cannot be found' error
            this.Response.CacheControl = "no-cache";

            // Ensure SSRSQueryParameter exist
            if (_sessionManager.SSRSQueryParameter == null)
            {
                _sessionManager.SSRSQueryParameter = new List <string> {
                    "", "", "", ""
                };
            }

            // Add to session user Query from SSRS/RDL
            if (this.OperationalReportViewer != null && this.OperationalReportViewer.ServerReport != null && this.OperationalReportViewer.ServerReport.ReportServerCredentials != null)
            {
                // Query parameter assumed to be 3rd paramter
                ReportParameterInfoCollection reportParm = this.OperationalReportViewer.ServerReport.GetParameters();
                if (reportParm.Count() > 2 && reportParm.ToList <ReportParameterInfo>()[2].Values.Count() > 0)
                {
                    switch (reportParm.ToList <ReportParameterInfo>()[2].Name)
                    {
                    case "LastName":
                        _sessionManager.SSRSQueryParameter[QUERY_LASTNAME] = reportParm.ToList <ReportParameterInfo>()[2].Values[0].ToString();
                        break;

                    case "NINO":
                        _sessionManager.SSRSQueryParameter[QUERY_NINO] = reportParm.ToList <ReportParameterInfo>()[2].Values[0].ToString();
                        break;

                    case "Postcode":
                        _sessionManager.SSRSQueryParameter[QUERY_POSTCODE] = reportParm.ToList <ReportParameterInfo>()[2].Values[0].ToString();
                        break;

                    case "IncidentID":
                        _sessionManager.SSRSQueryParameter[QUERY_INCIDENTID] = reportParm.ToList <ReportParameterInfo>()[2].Values[0].ToString();
                        break;

                    default:
                        break;
                    }
                }
            }


            if (!Page.IsPostBack)
            {
                AuthorisationManager authManager = new AuthorisationManager();
                authManager.GetUserAuthorisationInfo(new HttpContextWrapper(HttpContext.Current), "UCB");

                // Check authorised user
                var httpContextBase = new HttpContextWrapper(HttpContext.Current);
                if (!httpContextBase.User.IsInRole(AppRoles.APPLICATION))
                {
                    Response.Redirect("~/Home/UnAuthorized");
                }

                if (!string.IsNullOrEmpty(_sessionManager.MessageFromPageFrom))
                {
                    this.Message.InnerText = _sessionManager.MessageFromPageFrom;
                    _sessionManager.MessageFromPageFrom = null;
                }
                else
                {
                    this.Message.InnerText = "";
                }
                // Get report server and location information
                string        reportpath;
                string        ReportServer    = ConfigurationManager.AppSettings["ReportServer"];
                string        ReportLocation  = ConfigurationManager.AppSettings["ReportLocation"];
                ScriptManager MyScriptManager = ScriptManager.GetCurrent(this);
                MyScriptManager.AsyncPostBackTimeout = 600;

                this.OperationalReportViewer.ServerReport.ReportServerUrl         = new Uri(ReportServer);
                this.OperationalReportViewer.ServerReport.ReportServerCredentials = new ReportCredentials();
                this.OperationalReportViewer.InteractiveDeviceInfos.Add("AccessibleTablix", "true");

                if (_sessionManager.PageFrom != "MIMenu")
                {
                    reportpath = ConfigurationManager.AppSettings["ReportLocation"] + _sessionManager.IsExpected(_sessionManager.RequestedReport);//.Request.QueryString.Get("report");
                    switch (_sessionManager.IsExpected(_sessionManager.RequestedReport))
                    {
                    case "MyForwardLookReport":
                    case "MyNewReportsReport":
                    case "MyReviewsReport":
                    case "SPLByAllCases":
                    case "SPLByArchived":
                    case "SPLByBusinessUnit":
                    case "SPLByControlMeasure":
                    case "SPLByDistrict":
                    case "SPLByName":
                    case "SPLByNino":
                    case "SPLByPostcode":
                    case "SPLByIncidentID":
                    case "SPLBy3rdPartyReferrals":
                    case "SPLBySite":
                        this.OperationalReportViewer.ShowPrintButton    = false;
                        this.OperationalReportViewer.ShowExportControls = false;
                        break;

                    default:
                        this.OperationalReportViewer.ShowPrintButton    = true;
                        this.OperationalReportViewer.ShowExportControls = true;
                        break;
                    }
                }
                else
                {
                    reportpath = ConfigurationManager.AppSettings["PublishedLocation"] + _sessionManager.RequestedReport;
                    StandardReportModel Report = _sessionManager.CurrentStandardReport;
                    if (Report != null)
                    {
                        if (Report.IsPrintable)
                        {
                            this.OperationalReportViewer.ShowPrintButton = true;
                        }
                        else
                        {
                            this.OperationalReportViewer.ShowPrintButton = false;
                        }
                        if (Report.IsExportable)
                        {
                            this.OperationalReportViewer.ShowExportControls = true;
                        }
                        else
                        {
                            this.OperationalReportViewer.ShowExportControls = false;
                        }
                        reportpath = ConfigurationManager.AppSettings["PublishedLocation"] + Report.ReportName;
                    }
                }
                this.OperationalReportViewer.ServerReport.ReportPath = reportpath;


                try
                {
                    /*
                     * //Need to pass these
                     * SessionManager.UserIdentity;
                     * then call stored proc in report (have as Look in repositories for further info)
                     * (Guid,Guid,"AccuracyMonitoring",string.Empty) (ConfigurationAllowDefinition NetPipeStyleUriParser
                     */


                    int    startOfBaseUrl = HttpContext.Current.Request.Url.ToString().IndexOf("/Reports/Reports.aspx");
                    string baseUrl        = HttpContext.Current.Request.Url.ToString().Substring(0, startOfBaseUrl);

                    List <ReportParameter> ParameterList = new List <ReportParameter>();
                    if (_sessionManager.PageFrom != "MIMenu")
                    {
                        ParameterList.Add(new ReportParameter("BaseUrl", baseUrl));
                        ParameterList.Add(new ReportParameter("UserID", _sessionManager.UserID));

                        // Add Query from session, which was saved when RDL executed
                        switch (_sessionManager.IsExpected(_sessionManager.RequestedReport))
                        {
                        case "SPLByName":
                            ParameterList.Add(new ReportParameter("LastName", _sessionManager.SSRSQueryParameter[QUERY_LASTNAME]));
                            break;

                        case "SPLByNino":
                            ParameterList.Add(new ReportParameter("NINO", _sessionManager.SSRSQueryParameter[QUERY_NINO]));
                            break;

                        case "SPLByPostcode":
                            ParameterList.Add(new ReportParameter("Postcode", _sessionManager.SSRSQueryParameter[QUERY_POSTCODE]));
                            break;

                        case "SPLByIncidentID":
                            ParameterList.Add(new ReportParameter("IncidentID", _sessionManager.SSRSQueryParameter[QUERY_INCIDENTID]));
                            break;

                        default:
                            break;
                        }
                    }
                    else
                    {
                        ParameterList.Add(new ReportParameter("ReportUserName", _sessionManager.UserName));
                        ParameterList.Add(new ReportParameter("ReportUserCode", _sessionManager.UserID));
                    }
                    this.OperationalReportViewer.ShowParameterPrompts = true;
                    this.OperationalReportViewer.ShowPromptAreaButton = true;
                    this.OperationalReportViewer.PromptAreaCollapsed  = false;
                    this.OperationalReportViewer.ServerReport.SetParameters(ParameterList);
                }
                catch
                {
                    //If ReportUser parameter doesn't exist ignore it.
                }
            }
        }