Пример #1
0
        public void ViewReport(Report report, Repository repository, bool render, string viewGUID, string outputGUID, string originalFilePath)
        {
            Show();
            Text = Path.GetFileNameWithoutExtension(originalFilePath) + " - " + Repository.SealRootProductName + " Report Viewer";
            BringToFront();

            Report previousReport = _report;

            _report = report;
            _report.ExecutionContext = ReportExecutionContext.DesignerReport;
            if (string.IsNullOrEmpty(_report.DisplayName)) _report.DisplayName = Path.GetFileNameWithoutExtension(originalFilePath);
            _report.CurrentViewGUID = _report.ViewGUID;

            //execute to output
            if (!string.IsNullOrEmpty(outputGUID))
            {
                _report.OutputToExecute = _report.Outputs.FirstOrDefault(i => i.GUID == outputGUID);
                _report.ExecutionContext = ReportExecutionContext.DesignerOutput;
                if (_report.OutputToExecute != null) _report.CurrentViewGUID = _report.OutputToExecute.ViewGUID;
            }

            //execute with custom view
            if (!string.IsNullOrEmpty(viewGUID)) _report.CurrentViewGUID = viewGUID;

            if (previousReport != null && render)
            {
                //force execution
                var parameter = _report.ExecutionView.Parameters.FirstOrDefault(i => i.Name == "force_execution");
                if (parameter != null) parameter.BoolValue = true;

                //set previous data tables and restrictions
                foreach (var model in _report.Models)
                {
                    ReportModel previousModel = previousReport.Models.FirstOrDefault(i => i.GUID == model.GUID);
                    if (previousModel != null)
                    {
                        model.ResultTable = previousModel.ResultTable;
                        model.Restrictions = previousModel.Restrictions;
                        model.RestrictionText = previousModel.RestrictionText;
                        model.Sql = previousModel.Sql;
                    }
                }
                _report.RenderOnly = true;
            }

            _execution = new ReportExecution() { Report = _report };
            _report.InitForExecution();
            _execution.RenderHTMLDisplayForViewer();
            _url = "file:///" + _report.HTMLDisplayFilePath;
            webBrowser.Navigate(_url);
        }
Пример #2
0
        public ActionResult InitExecuteReport(string path, string viewGUID, string outputGUID)
        {
            try
            {
                if (!CheckAuthentication()) return Content(_loginContent);

                string filePath = Repository.ReportsFolder + path;
                if (System.IO.File.Exists(filePath))
                {
                    SecurityFolder securityFolder = WebUser.FindSecurityFolder(Path.GetDirectoryName(filePath));
                    if (securityFolder == null) throw new Exception("Error: this folder is not published");
                    if (!string.IsNullOrEmpty(outputGUID) || !string.IsNullOrEmpty(viewGUID))
                    {
                        if (securityFolder.PublicationType != PublicationType.ExecuteOutput) throw new Exception("Error: outputs cannot be executed");
                    }

                    Repository repository = Repository.CreateFast();
                    Report reportToExecute = Report.LoadFromFile(filePath, repository);
                    reportToExecute.ExecutionContext = ReportExecutionContext.WebReport;
                    reportToExecute.SecurityContext = WebUser;
                    reportToExecute.CurrentViewGUID = reportToExecute.ViewGUID;

                    //execute to output
                    if (!string.IsNullOrEmpty(outputGUID))
                    {
                        reportToExecute.OutputToExecute = reportToExecute.Outputs.FirstOrDefault(i => i.GUID == outputGUID);
                        reportToExecute.ExecutionContext = ReportExecutionContext.WebOutput;
                        if (reportToExecute.OutputToExecute != null) reportToExecute.CurrentViewGUID = reportToExecute.OutputToExecute.ViewGUID;
                    }

                    //execute with custom view
                    if (!string.IsNullOrEmpty(viewGUID)) reportToExecute.CurrentViewGUID = viewGUID;

                    ReportExecution execution = new ReportExecution() { Report = reportToExecute };
                    Session[reportToExecute.ExecutionGUID] = execution;
                    int index = Request.Url.OriginalString.ToLower().IndexOf("initexecutereport");
                    if (index == -1) throw new Exception("Invalid URL");
                    reportToExecute.WebUrl = Request.Url.OriginalString.Substring(0, index);
                    repository.WebPublishFolder = Path.Combine(Request.PhysicalApplicationPath, "temp");
                    repository.WebApplicationPath = Path.Combine(Request.PhysicalApplicationPath, "bin");
                    if (!Directory.Exists(repository.WebPublishFolder)) Directory.CreateDirectory(repository.WebPublishFolder);
                    FileHelper.PurgeTempDirectory(repository.WebPublishFolder);

                    reportToExecute.InitForExecution();
                    execution.RenderHTMLDisplayForViewer();
                    return GetContentResult(reportToExecute.HTMLDisplayFilePath);
                }
            }
            catch (Exception ex)
            {
                return HandleException(ex);
            }
            return Content("Error: Report file not found.\r\n");
        }