From 58b890d6a51c361543dec2c02800a6b373c3dfae Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Tue, 23 May 2023 11:08:57 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=87=E0=B8=B2?= =?UTF-8?q?=E0=B8=99=E0=B8=AA=E0=B8=AD=E0=B8=9A=E0=B8=84=E0=B8=B1=E0=B8=94?= =?UTF-8?q?=E0=B9=80=E0=B8=A5=E0=B8=B7=E0=B8=AD=E0=B8=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Controllers/ExamReportController.cs | 126 +++++++++++++++++++++++++ Controllers/RecruitReportController.cs | 4 + 2 files changed, 130 insertions(+) diff --git a/Controllers/ExamReportController.cs b/Controllers/ExamReportController.cs index dea1ebd..65ef477 100644 --- a/Controllers/ExamReportController.cs +++ b/Controllers/ExamReportController.cs @@ -298,6 +298,58 @@ namespace BMA.EHR.Report.Service.Controllers } } + [HttpGet("candidate-exam/{id:length(36)}")] + [AllowAnonymous] + public async Task> GetCandidateExamListReportAsync(Guid id) + { + try + { + var data = await _context.Candidates.AsQueryable() + .Include(x => x.PeriodExam) + .Where(x => x.PeriodExam.Id == id) + .Where(x => x.SeatNumber != null || x.SeatNumber != "") + .OrderBy(x => x.SeatNumber) + .Select(p => new + { + ExamId = p.SeatNumber, + FullName = $"{p.FirstName} {p.LastName}", + PositionName = "", + ExamName = + $"{p.PeriodExam.Name} ครั้งที่ {p.PeriodExam.Round}/{p.PeriodExam.Year.Value.ToThaiYear()}", + }).ToListAsync(); + + if (data.Count == 0) return Success(); + + 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; + System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); + + 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"); + + } + catch (Exception ex) + { + return Error(ex); + } + } + [HttpGet("pass/{id:length(36)}")] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] @@ -360,6 +412,80 @@ namespace BMA.EHR.Report.Service.Controllers .Where(x => x.ExamResult == "ผ่าน") .ToListAsync(); + if (data.Count == 0) return Success(); + + 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; + System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); + + 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"); + } + catch (Exception ex) + { + return Error(ex, "เกิดข้อผิดพลาดในการแสดงรายงาน"); + } + } + + [HttpGet("pass-exam/{id:length(36)}")] + [AllowAnonymous] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> GetPassExam2ListReportAsync(Guid id) + { + try + { + var data = await _context.Candidates.AsQueryable() + .Include(x => x.PeriodExam) + .ThenInclude(x => x.ScoreImport) + + .Select(p => new + { + Id = p.PeriodExam.Id, + ExamId = p.SeatNumber, + CitizenId = p.CitizenId, + FullName = $"{p.FirstName} {p.LastName}", + DateOfBirth = p.DateOfBirth.Value.ToThaiShortDate(), + + ExamName = $"{p.PeriodExam.Name} ครั้งที่ {p.PeriodExam.Round}/{p.PeriodExam.Year.Value.ToThaiYear()}", + + Number = p.Number, + + FullA = 0, + SumA =0, + FullB = p.PointTotalB, + SumB = p.PointB, + FullC = p.PointTotalC, + SumC = p.PointC, + SumScore = p.PointB + p.PointC, + ExamResult = p.Pass + + }) + .OrderBy(x => x.Number) + .Where(x => x.Id == id) + .Where(x => x.ExamResult == "ผ่าน") + .ToListAsync(); + + if (data.Count == 0) return Success(); + var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Recruit", $"rptPassExamList.trdp"); ReportPackager reportPackager = new ReportPackager(); Telerik.Reporting.Report report = null; diff --git a/Controllers/RecruitReportController.cs b/Controllers/RecruitReportController.cs index e64517d..497ceb4 100644 --- a/Controllers/RecruitReportController.cs +++ b/Controllers/RecruitReportController.cs @@ -236,6 +236,8 @@ namespace BMA.EHR.Report.Service.Controllers $"{p.RecruitImport.Name} ครั้งที่ {p.RecruitImport.Order}/{p.RecruitImport.Year.ToThaiYear()}", }).ToListAsync(); + if (data.Count == 0) return Success(); + var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Recruit", $"rptCandidateList.trdp"); ReportPackager reportPackager = new ReportPackager(); Telerik.Reporting.Report report = null; @@ -329,6 +331,8 @@ namespace BMA.EHR.Report.Service.Controllers .Where(x => x.ExamResult == "ผ่าน") .ToListAsync(); + if (data.Count == 0) return Success(); + var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Recruit", $"rptPassExamList.trdp"); ReportPackager reportPackager = new ReportPackager(); Telerik.Reporting.Report report = null;