Beispiel #1
0
        public ActionResult PdfView()
        {
            int.TryParse(Request.QueryString["ReportId"], out int reportId);

            var reportEntity = _reportSuiteRepository.Find(reportId);

            Guard.Against.NullEntity(reportId, reportEntity);

            string reportPath = string.Format("{0}{1}", reportEntity.ReportPathName, reportEntity.ReportName);

            if (!System.IO.File.Exists(reportPath))
            {
                throw new Exception("Can't load report file.");
            }

            var filterSetList = JsonConvert.DeserializeObject <List <FilterSets> >(Request.QueryString["FilterSetList"]);

            _reportDocument.SetFields(UserId.ToString(), reportEntity.NodeText, reportEntity.ReportPathName);
            _reportDocument.Load(reportPath);
            _reportDocument.FilterSetList = filterSetList;
            _reportDocument.LoadSourceDataSet();
            _reportDocument.SetFilterValue();

            byte[] pdfByte = RDLReportExporter.GetExportedByte(ExportType.PDF, _reportDocument.DsSource, _reportDocument.ReportPath, _reportDocument.Parameters, _reportDocument.SubReportList);
            Response.Clear();
            Response.ContentType = "Application/pdf";
            string FileName = "";

            if (Request.QueryString["FileName"] != "" && Request.QueryString["FileName"] != null)
            {
                FileName = Request.QueryString["FileName"].Trim();
                Response.AddHeader("Content-Disposition", "inline; filename=" + FileName + ".pdf;");
            }

            Response.Buffer = false;
            Response.OutputStream.Write(pdfByte, 0, pdfByte.Length);
            Response.Flush();
            Response.End();
            return(View());
        }
Beispiel #2
0
        public async Task <ActionResult> InlinePdfView()
        {
            int.TryParse(Request.QueryString["ReportId"], out int reportId);
            var reportEntity = await _reportSuiteRepository.FindAsync(reportId);

            Guard.Against.NullEntity(reportId, reportEntity);

            var reportName     = reportEntity.ReportName;
            var reportPathName = reportEntity.ReportPathName;

            bool.TryParse(Request.QueryString["HasExternalReport"], out bool hasExternalReport);

            if (hasExternalReport)
            {
                int.TryParse(Request.QueryString["ExternalId"], out int externalId);

                var reportSuiteExternalSetup = _reportSuiteExternalSetupRepository.Find(x => x.Reportid == reportId && x.ExternalId == externalId);
                if (reportSuiteExternalSetup != null)
                {
                    reportName     = reportSuiteExternalSetup.ReportName;
                    reportPathName = reportSuiteExternalSetup.ReportPathName;
                }
            }

            string reportPath = string.Format("{0}{1}", reportPathName, reportName);

            if (!System.IO.File.Exists(reportPath))
            {
                throw new Exception("Can't load report file.");
            }

            var parameters = new List <CustomeParameter>();

            foreach (var key in Request.QueryString.AllKeys)
            {
                if (key.Equals("ReportId", StringComparison.OrdinalIgnoreCase) || key.Equals("HasExternalReport", StringComparison.OrdinalIgnoreCase) || key.Equals("ExternalId", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                var param = new CustomeParameter {
                    ParameterName = key, ParameterValue = Request.QueryString[key]
                };
                parameters.Add(param);
            }

            var parameterValues = await _reportSuiteSqlRepository.LoadReportParameterInfoAsync(reportEntity.Id);

            parameterValues.Tables[0].TableName = "ParameterValues";

            var reportColumnList = new List <ReportSuiteColumnValueViewModel>();

            _reportDocument.SetFields(UserId.ToString(), reportEntity.NodeText, reportEntity.ReportPathName);
            _reportDocument.Load(reportPath);
            _reportDocument.LoadFilterTable(parameterValues.Tables["ParameterValues"].Columns, reportColumnList);
            _reportDocument.SetParameterValue(parameters);
            _reportDocument.LoadSourceDataSet();
            _reportDocument.SetFilterValue();

            byte[] pdfByte = RDLReportExporter.GetExportedByte(ExportType.PDF, _reportDocument.DsSource, _reportDocument.ReportPath, _reportDocument.Parameters, _reportDocument.SubReportList);
            Response.Clear();
            Response.ContentType = "Application/pdf";
            string FileName = "";

            if (Request.QueryString["FileName"] != "" && Request.QueryString["FileName"] != null)
            {
                FileName = Request.QueryString["FileName"].Trim();
                Response.AddHeader("Content-Disposition", "inline; filename=" + FileName + ".pdf;");
            }

            Response.Buffer = false;
            Response.OutputStream.Write(pdfByte, 0, pdfByte.Length);
            Response.Flush();
            Response.End();
            return(View());
        }