Exemplo n.º 1
0
        public void RunReport()
        {
            var    crcRepDef   = GetReportDefinition(this.ReportPath);
            string paramString = uxHiddenParamString.Text;

            SetReportViewerSize();
            var choiceFactory    = new CrcParameterChoiceFactory();
            var choiceCollection = choiceFactory.Create(paramString);
            var mapResult        = crcRepDef.MapParameterChoices(choiceCollection);

            if (mapResult.MappingValid)
            {
                InitialiseReportViewer(this.ReportPath);

                logger.DebugFormat("RunReport: ReportPath: {0} User {1}", uxReportViewer.ServerReport.ReportPath, User.Identity.Name);
                var converter     = new CrcParameterConverter();
                var ssrsParamList = converter.GetReportParametersForSsrsReportViewer(crcRepDef);
                var userParamList = converter.GetReportParametersForUser(crcRepDef, 15);
                try
                {
                    uxReportViewer.ServerReport.SetParameters(ssrsParamList);
                }
                catch (ReportServerException rse)
                {
                    // check for problem with fixed user
                    if (rse.ErrorCode == "rsAccessDenied" && !this.GetImpersonateLoggedOnUser())
                    {
                        throw new ApplicationException(string.Format("ReportViewer is running as fixed user {0} but was passed a report {1} that it could not open",
                                                                     GetFixedSsrsUsername(), this.ReportPath));
                    }
                    else
                    {
                        throw rse;
                    }
                }
                string executionId = uxReportViewer.ServerReport.GetExecutionId();
                logger.DebugFormat("RunReport: running report, executionId is {0}", executionId);
                if (StoreCrissCrossHistory)
                {
                    // log executionid, logged in user and param description
                    var historyLogger = new CrissCrossLib.History.CrcHistoryLogger();
                    historyLogger.LogToCrissCrossHistory(crcRepDef, User.Identity.Name, executionId);
                }
                uxParamUserDescription.Text = string.Join("<br/>", userParamList.ToArray());
                uxResultsPanel.Visible      = true;
                uxParamSummaryPanel.Visible = true;
                this.RunningReport          = true;
            }
            else
            {
                // todo - friendly message back to ui
                throw new ApplicationException(string.Format("invalid params - could not map supplied values to definitions for report {0}. complaints: {1}",
                                                             crcRepDef.DisplayName, string.Join(", ", mapResult.Complaints.ToArray())));
            }
        }
        public void GetReportParametersForSsrsReportViewer_CanReturnNullDate()
        {
            var repDefn   = MakeTestReportDefn(null, "S1");
            var converter = new CrcParameterConverter();

            var result = converter.GetReportParametersForSsrsReportViewer(repDefn);

            Assert.AreEqual(2, result.Count());
            viewer.ReportParameter param1 = result.FirstOrDefault(p => p.Name == "PretendDateParam");
            Assert.IsNotNull(param1);
            Assert.AreEqual(1, param1.Values.Count);
            Assert.AreEqual(null, param1.Values[0]);
            viewer.ReportParameter param2 = result.FirstOrDefault(p => p.Name == "PretendSingleSelect");
            Assert.IsNotNull(param2);
            Assert.AreEqual(1, param2.Values.Count);
            Assert.AreEqual("S1", param2.Values[0]);
        }