diff --git a/Controllers/ExamReportController.cs b/Controllers/ExamReportController.cs index 90d9b34..83cbb56 100644 --- a/Controllers/ExamReportController.cs +++ b/Controllers/ExamReportController.cs @@ -294,31 +294,43 @@ namespace BMA.EHR.Report.Service.Controllers if (data.Count == 0) return Error("ไม่พบข้อมูลในระบบ"); - var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Recruit", $"rptCandidateList.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); - } + //var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Recruit", $"rptCandidateList.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); + //} - //report.DataSource = data; - report.ReportParameters["ExamName"].Value = data[0].ExamName.ToThaiNumber(); - var tbl = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["table1"]; - tbl.DataSource = data; - System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); + ////report.DataSource = data; + //report.ReportParameters["ExamName"].Value = data[0].ExamName.ToThaiNumber(); + //var tbl = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["table1"]; + //tbl.DataSource = data; + //System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); - InstanceReportSource instanceReportSource = new InstanceReportSource() + //InstanceReportSource instanceReportSource = new InstanceReportSource() + //{ + // ReportDocument = report + //}; + + + //ReportProcessor reportProcessor = new ReportProcessor(_configuration); + //RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo); + + //var content = result.DocumentBytes; + //return File(content, "application/pdf", $"รายชื่อผู้มีสิทธิ์สอบ_{data.First().ExamName}.pdf"); + var examName = data[0].ExamName; + var _data = new { - ReportDocument = report + template = "rptCandidateList", + reportName = $"รายชื่อผู้มีสิทธิ์สอบ_{data.First().ExamName}", + data = new + { + examName = examName, + data = data + } }; - - - ReportProcessor reportProcessor = new ReportProcessor(_configuration); - RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo); - - var content = result.DocumentBytes; - return File(content, "application/pdf", $"รายชื่อผู้มีสิทธิ์สอบ_{data.First().ExamName}.pdf"); + return Success(_data); } catch (Exception ex) @@ -352,31 +364,42 @@ namespace BMA.EHR.Report.Service.Controllers if (data.Count == 0) return Error("ไม่พบข้อมูลในระบบ"); - var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Recruit", $"rptCandidateList.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); - } - report.ReportParameters["ExamName"].Value = data[0].ExamName; - report.DataSource = data[0]; - var table = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["table1"]; - table.DataSource = data; - System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); + //var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Recruit", $"rptCandidateList.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); + //} + //report.ReportParameters["ExamName"].Value = data[0].ExamName; + //report.DataSource = data[0]; + //var table = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["table1"]; + //table.DataSource = data; + //System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); - InstanceReportSource instanceReportSource = new InstanceReportSource() + //InstanceReportSource instanceReportSource = new InstanceReportSource() + //{ + // ReportDocument = report + //}; + + + //ReportProcessor reportProcessor = new ReportProcessor(_configuration); + //RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo); + + //var content = result.DocumentBytes; + //return File(content, "application/pdf", $"รายชื่อผู้มีสิทธิ์สอบ_{data.First().ExamName}.pdf"); + var examName = data[0].ExamName; + var _data = new { - ReportDocument = report + template = "rptCandidateList", + reportName = $"รายชื่อผู้มีสิทธิ์สอบ_{data.First().ExamName}", + data = new + { + examName = examName, + data = data + } }; - - - ReportProcessor reportProcessor = new ReportProcessor(_configuration); - RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo); - - var content = result.DocumentBytes; - return File(content, "application/pdf", $"รายชื่อผู้มีสิทธิ์สอบ_{data.First().ExamName}.pdf"); - + return Success(_data); } catch (Exception ex) { @@ -444,31 +467,43 @@ namespace BMA.EHR.Report.Service.Controllers x.FullName, x.SumScore }).ToList(); - var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Recruit", $"rptPassExamList.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); - } + //var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Recruit", $"rptPassExamList.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); + //} - //report.DataSource = data; - report.ReportParameters["ExamName"].Value = data_[0].ExamName.ToThaiNumber(); - var tbl = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["table1"]; - tbl.DataSource = data_; - System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); + ////report.DataSource = data; + //report.ReportParameters["ExamName"].Value = data_[0].ExamName.ToThaiNumber(); + //var tbl = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["table1"]; + //tbl.DataSource = data_; + //System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); - InstanceReportSource instanceReportSource = new InstanceReportSource() + //InstanceReportSource instanceReportSource = new InstanceReportSource() + //{ + // ReportDocument = report + //}; + + + //ReportProcessor reportProcessor = new ReportProcessor(_configuration); + //RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo); + + //var content = result.DocumentBytes; + //return File(content, "application/pdf", $"รายชื่อผู้สอบแข่งขันได้_{data.First().ExamName}.pdf"); + var examName = data[0].ExamName; + var _data = new { - ReportDocument = report + template = "rptPassExamList", + reportName = $"รายชื่อผู้สอบแข่งขันได้_{data.First().ExamName}", + data = new + { + examName = examName, + data = data_ + } }; - - - ReportProcessor reportProcessor = new ReportProcessor(_configuration); - RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo); - - var content = result.DocumentBytes; - return File(content, "application/pdf", $"รายชื่อผู้สอบแข่งขันได้_{data.First().ExamName}.pdf"); + return Success(_data); } catch (Exception ex) { @@ -538,30 +573,42 @@ namespace BMA.EHR.Report.Service.Controllers if (data.Count == 0) return Error("ไม่พบข้อมูลในระบบ"); - var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Recruit", $"rptPassExamList.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); - } - report.ReportParameters["ExamName"].Value = data[0].ExamName; - report.DataSource = data[0]; - var table = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["table1"]; - table.DataSource = data; - System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); + //var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Recruit", $"rptPassExamList.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); + //} + //report.ReportParameters["ExamName"].Value = data[0].ExamName; + //report.DataSource = data[0]; + //var table = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["table1"]; + //table.DataSource = data; + //System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); - InstanceReportSource instanceReportSource = new InstanceReportSource() + //InstanceReportSource instanceReportSource = new InstanceReportSource() + //{ + // ReportDocument = report + //}; + + + //ReportProcessor reportProcessor = new ReportProcessor(_configuration); + //RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo); + + //var content = result.DocumentBytes; + //return File(content, "application/pdf", $"รายชื่อผู้สอบแข่งขันได้_{periodExam.Name} ครั้งที่ {periodExam.Round}/{periodExam.Year.Value.ToThaiYear()}.pdf"); + var examName = data[0].ExamName; + var _data = new { - ReportDocument = report + template = "rptPassExamList", + reportName = $"รายชื่อผู้สอบแข่งขันได้_{periodExam.Name} ครั้งที่ {periodExam.Round}/{periodExam.Year.Value.ToThaiYear()}", + data = new + { + examName = examName, + data = data + } }; - - - ReportProcessor reportProcessor = new ReportProcessor(_configuration); - RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo); - - var content = result.DocumentBytes; - return File(content, "application/pdf", $"รายชื่อผู้สอบแข่งขันได้_{periodExam.Name} ครั้งที่ {periodExam.Round}/{periodExam.Year.Value.ToThaiYear()}.pdf"); + return Success(_data); } catch (Exception ex) { diff --git a/Controllers/RecruitReportController.cs b/Controllers/RecruitReportController.cs index a0e2cbb..f2054ce 100644 --- a/Controllers/RecruitReportController.cs +++ b/Controllers/RecruitReportController.cs @@ -238,31 +238,43 @@ namespace BMA.EHR.Report.Service.Controllers if (data.Count == 0) return Error("ไม่พบข้อมูลในระบบ"); - var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Recruit", $"rptCandidateList.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); - } + //var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Recruit", $"rptCandidateList.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); + //} - //report.DataSource = data; - report.ReportParameters["ExamName"].Value = data[0].ExamName.ToThaiNumber(); - var tbl = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["table1"]; - tbl.DataSource = data; - System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); + ////report.DataSource = data; + //report.ReportParameters["ExamName"].Value = data[0].ExamName.ToThaiNumber(); + //var tbl = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["table1"]; + //tbl.DataSource = data; + //System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); - InstanceReportSource instanceReportSource = new InstanceReportSource() + //InstanceReportSource instanceReportSource = new InstanceReportSource() + //{ + // ReportDocument = report + //}; + + + //ReportProcessor reportProcessor = new ReportProcessor(_configuration); + //RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo); + + //var content = result.DocumentBytes; + //return File(content, "application/pdf", $"รายชื่อผู้มีสิทธิ์สอบ_{data.First().ExamName}.pdf"); + var examName = data[0].ExamName; + var _data = new { - ReportDocument = report + template = "rptCandidateList", + reportName = $"รายชื่อผู้มีสิทธิ์สอบ_{data.First().ExamName}", + data = new + { + examName = examName, + data = data + } }; - - - ReportProcessor reportProcessor = new ReportProcessor(_configuration); - RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo); - - var content = result.DocumentBytes; - return File(content, "application/pdf", $"รายชื่อผู้มีสิทธิ์สอบ_{data.First().ExamName}.pdf"); + return Success(_data); } catch (Exception ex) @@ -345,31 +357,43 @@ namespace BMA.EHR.Report.Service.Controllers x.SumScore }).ToList(); - var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Recruit", $"rptPassExamList.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); - } + //var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Recruit", $"rptPassExamList.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); + //} - //report.DataSource = data; - report.ReportParameters["ExamName"].Value = data_[0].ExamName.ToThaiNumber(); - var tbl = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["table1"]; - tbl.DataSource = data_; - System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); + ////report.DataSource = data; + //report.ReportParameters["ExamName"].Value = data_[0].ExamName.ToThaiNumber(); + //var tbl = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["table1"]; + //tbl.DataSource = data_; + //System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); - InstanceReportSource instanceReportSource = new InstanceReportSource() + //InstanceReportSource instanceReportSource = new InstanceReportSource() + //{ + // ReportDocument = report + //}; + + + //ReportProcessor reportProcessor = new ReportProcessor(_configuration); + //RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo); + + //var content = result.DocumentBytes; + //return File(content, "application/pdf", $"รายชื่อผู้สอบแข่งขันได้_{data.First().ExamName}.pdf"); + var examName = data[0].ExamName; + var _data = new { - ReportDocument = report + template = "rptPassExamList", + reportName = $"รายชื่อผู้สอบแข่งขันได้_{data.First().ExamName}", + data = new + { + examName = examName, + data = data_ + } }; - - - ReportProcessor reportProcessor = new ReportProcessor(_configuration); - RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo); - - var content = result.DocumentBytes; - return File(content, "application/pdf", $"รายชื่อผู้สอบแข่งขันได้_{data.First().ExamName}.pdf"); + return Success(_data); } catch (Exception ex) {