From a35cc0bdefe676023fd8f54925293de037f7137b Mon Sep 17 00:00:00 2001 From: Kittapath Date: Tue, 25 Jun 2024 09:46:08 +0700 Subject: [PATCH] no message --- .../Controllers/CommandReportController.cs | 61 ++++++++----------- 1 file changed, 24 insertions(+), 37 deletions(-) diff --git a/BMA.EHR.Report.Service/Controllers/CommandReportController.cs b/BMA.EHR.Report.Service/Controllers/CommandReportController.cs index 59fa2d7b..99245de5 100644 --- a/BMA.EHR.Report.Service/Controllers/CommandReportController.cs +++ b/BMA.EHR.Report.Service/Controllers/CommandReportController.cs @@ -54,7 +54,7 @@ namespace BMA.EHR.Report.Service.Controllers #region " C-PM-01 " - private async Task GenerateCommandReportType01_Cover(Guid commandId, string exportType) + private async Task GenerateCommandReportType01_Cover(Guid commandId, string exportType) { try { @@ -83,40 +83,34 @@ namespace BMA.EHR.Report.Service.Controllers AuthorizedPosition = raw_data.AuthorizedPosition, Subject = $"เรื่อง {raw_data.CommandSubject}", }; - var content = new + + var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"01-คำสั่งบรรจุและแต่งตั้งผู้สอบแข่งขันได้-1.trdp"); + + ReportPackager reportPackager = new ReportPackager(); + Telerik.Reporting.Report? report = null; + using (var sourceStream = System.IO.File.OpenRead(rptFile)) { - template = "01-คำสั่งบรรจุและแต่งตั้งผู้สอบแข่งขันได้-1", - reportName = "01-คำสั่งบรรจุและแต่งตั้งผู้สอบแข่งขันได้-1", - data = command + report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream); + } + + report.DataSource = command; + + System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); + if (exportType == "docx") + deviceInfo["OutputFormat"] = "DOCX"; + + InstanceReportSource instanceReportSource = new InstanceReportSource() + { + ReportDocument = report }; - // var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"01-คำสั่งบรรจุและแต่งตั้งผู้สอบแข่งขันได้-1.trdp"); - // ReportPackager reportPackager = new ReportPackager(); - // Telerik.Reporting.Report? report = null; - // using (var sourceStream = System.IO.File.OpenRead(rptFile)) - // { - // report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream); - // } + ReportProcessor reportProcessor = new ReportProcessor(_configuration); + RenderingResult result = reportProcessor.RenderReport(exportType.ToUpper(), instanceReportSource, deviceInfo); - // report.DataSource = command; + var content = result.DocumentBytes; - // System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); - // if (exportType == "docx") - // deviceInfo["OutputFormat"] = "DOCX"; - - // InstanceReportSource instanceReportSource = new InstanceReportSource() - // { - // ReportDocument = report - // }; - - - // ReportProcessor reportProcessor = new ReportProcessor(_configuration); - // RenderingResult result = reportProcessor.RenderReport(exportType.ToUpper(), instanceReportSource, deviceInfo); - - // var content = result.DocumentBytes; - - return command; + return content; } catch { @@ -2646,14 +2640,7 @@ namespace BMA.EHR.Report.Service.Controllers throw new Exception(GlobalMessages.CommandNotFound); var contentData = await GenerateCommandReportType01_Cover(id, exportType); - var data = new - { - template = "Type01_Cover", - reportName = "Type01_Cover", - data = contentData - }; - return Success(data); - // return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}"); + return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}"); } catch {