using BMA.EHR.Domain.Common; using BMA.EHR.Domain.Extensions; using BMA.EHR.Domain.Shared; using BMA.EHR.Application.Repositories.Reports; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ModelBinding.Binders; using Swashbuckle.AspNetCore.Annotations; using DocumentFormat.OpenXml.Drawing; using Telerik.Reporting; using Telerik.Reporting.Processing; using System.IO; using BMA.EHR.Application.Common.Interfaces; namespace BMA.EHR.Report.Service.Controllers { [Route("api/v{version:apiVersion}/report/transfer")] [ApiVersion("2.0")] [ApiController] [Produces("application/json")] [Authorize] [SwaggerTag("API รายงานรายการขอโอน")] public class TransferReportController : BaseController { #region " Fields " private readonly IWebHostEnvironment _hostingEnvironment; private readonly IConfiguration _configuration; private readonly GenericReportGenerator _reportGenerator; private readonly TransferReportRepository _service; #endregion #region " Constuctor and Destructor " public TransferReportController(IWebHostEnvironment hostingEnvironment, IConfiguration configuration, GenericReportGenerator reportGenerator, TransferReportRepository service) { _hostingEnvironment = hostingEnvironment; _configuration = configuration; _reportGenerator = reportGenerator; _service = service; } #endregion #region " Methods " #region คําร้องขอโอนไปถึงส่วนราชการอื่นนอก กรุงเทพมหานครที่ข้าราชการประสงค์ขอโอน /// /// คําร้องขอโอนไปถึงส่วนราชการอื่นนอก กรุงเทพมหานครที่ข้าราชการประสงค์ขอโอน /// /// id /// pdf, docx หรือ xlsx /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpGet("21/{exportType}/{id}")] public async Task > GetTransfer1ConvertReportAsync(Guid id, string exportType = "pdf") { try { var data = await _service.GetData1Transfer(id); //var mimeType = ""; //switch (exportType.Trim().ToLower()) //{ // case "pdf": mimeType = "application/pdf"; break; // case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break; // case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break; //} //var rptFile = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"21-คำร้องขอโอน-1.trdp"); //var rptFile2 = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"21-คำร้องขอโอน-2.trdp"); //var rptFile3 = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"21-คำร้องขอโอน-3.trdp"); //var rptFile4 = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"21-คำร้องขอโอน-4.trdp"); //ReportPackager reportPacker = new ReportPackager(); //Telerik.Reporting.Report? report = null; //Telerik.Reporting.Report? report2 = null; //Telerik.Reporting.Report? report3 = null; //Telerik.Reporting.Report? report4 = null; //using (var sourceStream = System.IO.File.OpenRead(rptFile)) //using (var sourceStream2 = System.IO.File.OpenRead(rptFile2)) //using (var sourceStream3 = System.IO.File.OpenRead(rptFile3)) //using (var sourceStream4 = System.IO.File.OpenRead(rptFile4)) //{ // report = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream); // report2 = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream2); // report3 = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream3); // report4 = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream4); //} //report.DataSource = data; //var reportBook = new ReportBook(); //reportBook.Reports.Add(report); //reportBook.Reports.Add(report2); //reportBook.Reports.Add(report3); //reportBook.Reports.Add(report4); //System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); //InstanceReportSource instanceReportSource = new InstanceReportSource() //{ // ReportDocument = reportBook, //}; //ReportProcessor reportProcessor = new ReportProcessor(_configuration); //RenderingResult result = reportProcessor.RenderReport($"{exportType}", instanceReportSource, deviceInfo); //var content = result.DocumentBytes; //return File(content, mimeType, $"แบบคำร้องขอโอน.{exportType.Trim().ToLower()}"); var result = new { template = "transfer1", reportName = "docx-report", data = data }; return Success(result); } catch { throw; } } #endregion #region หนังสือแจ้งสํานักงานการเจ้าหน้าที่ สํานักปลัดกรุงเทพมหานคร ให้ทราบตําแหน่งและตําแหน่งเลขที่ที่ดําเนินการให้โอน /// /// หนังสือแจ้งสํานักงานการเจ้าหน้าที่ สํานักปลัดกรุงเทพมหานคร ให้ทราบตําแหน่งและตําแหน่งเลขที่ที่ดําเนินการให้โอน /// /// id /// pdf, docx หรือ xlsx /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpGet("22/{exportType}/{id}")] public async Task> GetTransfer2ConvertReportAsync(Guid id, string exportType = "pdf") { try { var data = await _service.GetData2Transfer(id); //var mimeType = ""; //switch (exportType.Trim().ToLower()) //{ // case "pdf": mimeType = "application/pdf"; break; // case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break; // case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break; //} //var rptFile = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"22-หนังสือแจ้งสำนักงานการเจ้าหน้าที่-1.trdp"); //var rptFile2 = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"22-หนังสือแจ้งสำนักงานการเจ้าหน้าที่-2.trdp"); //ReportPackager reportPacker = new ReportPackager(); //Telerik.Reporting.Report? report = null; //Telerik.Reporting.Report? report2 = null; //using (var sourceStream = System.IO.File.OpenRead(rptFile)) //using (var sourceStream2 = System.IO.File.OpenRead(rptFile2)) //{ // report = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream); // report2 = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream2); //} //report.DataSource = data; //report2.DataSource = data; //var reportBook = new ReportBook(); //reportBook.Reports.Add(report); //reportBook.Reports.Add(report2); //System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); //InstanceReportSource instanceReportSource = new InstanceReportSource() //{ // ReportDocument = reportBook, //}; //ReportProcessor reportProcessor = new ReportProcessor(_configuration); //RenderingResult result = reportProcessor.RenderReport($"{exportType}", instanceReportSource, deviceInfo); //var content = result.DocumentBytes; //return File(content, mimeType, $"หนังสือแจ้งสำนักงานการเจ้าหน้าที่.{exportType.Trim().ToLower()}"); var result = new { template = "transfer2", reportName = "docx-report", data = data }; return Success(result); } catch { throw; } } #endregion #region หนังสือยินยอมให้โอนและวันที่พร้อมจะให้โอนไปยัง หน่วยงานที่รับโอน /// /// หนังสือยินยอมให้โอนและวันที่พร้อมจะให้โอนไปยัง หน่วยงานที่รับโอน /// /// id /// pdf, docx หรือ xlsx /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpGet("23/{exportType}/{id}")] public async Task> GetTransfer3ConvertReportAsync(Guid id, string exportType = "pdf") { try { var data = await _service.GetData3Transfer(id); //var mimeType = ""; //switch (exportType.Trim().ToLower()) //{ // case "pdf": mimeType = "application/pdf"; break; // case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break; // case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break; //} //var rptFile = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"23-หนังสือยินยอมให้โอน-1.trdp"); //var rptFile2 = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"23-หนังสือยินยอมให้โอน-2.trdp"); //ReportPackager reportPacker = new ReportPackager(); //Telerik.Reporting.Report? report = null; //Telerik.Reporting.Report? report2 = null; //using (var sourceStream = System.IO.File.OpenRead(rptFile)) //using (var sourceStream2 = System.IO.File.OpenRead(rptFile2)) //{ // report = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream); // report2 = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream2); //} //report.DataSource = data; //report2.DataSource = data; //var reportBook = new ReportBook(); //reportBook.Reports.Add(report); //reportBook.Reports.Add(report2); //System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); //InstanceReportSource instanceReportSource = new InstanceReportSource() //{ // ReportDocument = reportBook, //}; //ReportProcessor reportProcessor = new ReportProcessor(_configuration); //RenderingResult result = reportProcessor.RenderReport($"{exportType}", instanceReportSource, deviceInfo); //var content = result.DocumentBytes; //return File(content, mimeType, $"หนังสือยินยอมให้โอน.{exportType.Trim().ToLower()}"); var result = new { template = "transfer3", reportName = "docx-report", data = data }; return Success(result); } catch { throw; } } #endregion #region หนังสือแจ้งสหกรณ์ออมทรัพย์กรุงเทพมหานครเพื่อขอ ตรวจสอบภาระหนี้สินสหกรณ์ออมทรัพย์ /// /// หนังสือแจ้งสหกรณ์ออมทรัพย์กรุงเทพมหานครเพื่อขอ ตรวจสอบภาระหนี้สินสหกรณ์ออมทรัพย์ /// /// id /// pdf, docx หรือ xlsx /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpGet("24/{exportType}/{id}")] public async Task > GetTransfer4ConvertReportAsync(Guid id, string exportType = "pdf") { try { var data = await _service.GetData4Transfer(id); //var mimeType = ""; //switch (exportType.Trim().ToLower()) //{ // case "pdf": mimeType = "application/pdf"; break; // case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break; // case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break; //} //var rptFile = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"24-หนังสือแจ้งสหกรณ์ออมทรัพย์-1.trdp"); //var rptFile2 = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"24-หนังสือแจ้งสหกรณ์ออมทรัพย์-2.trdp"); //var rptFile3 = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"24-หนังสือแจ้งสหกรณ์ออมทรัพย์-3.trdp"); //ReportPackager reportPacker = new ReportPackager(); //Telerik.Reporting.Report? report = null; //Telerik.Reporting.Report? report2 = null; //Telerik.Reporting.Report? report3 = null; //using (var sourceStream = System.IO.File.OpenRead(rptFile)) //using (var sourceStream2 = System.IO.File.OpenRead(rptFile2)) //using (var sourceStream3 = System.IO.File.OpenRead(rptFile3)) //{ // report = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream); // report2 = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream2); // report3 = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream3); //} //report.DataSource = data; //report2.DataSource = data; //report3.DataSource = data; //var reportBook = new ReportBook(); //reportBook.Reports.Add(report); //reportBook.Reports.Add(report2); //reportBook.Reports.Add(report3); //System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); //InstanceReportSource instanceReportSource = new InstanceReportSource() //{ // ReportDocument = reportBook, //}; //ReportProcessor reportProcessor = new ReportProcessor(_configuration); //RenderingResult result = reportProcessor.RenderReport($"{exportType}", instanceReportSource, deviceInfo); //var content = result.DocumentBytes; //return File(content, mimeType, $"หนังสือแจ้งสหกรณ์ออมทรัพย์.{exportType.Trim().ToLower()}"); var result = new { template = "transfer4", reportName = "docx-report", data = data }; return Success(result); } catch { throw; } } #endregion #region หนังสือถึงสํานักงานการเจ้าหน้าที่ สํานักปลัดกรุงเทพมหานครเพื่อขอตรวจสอบพฤติการณ์ทางวินัย และภาระหนี้สินสวัสดิการ /// /// หนังสือถึงสํานักงานการเจ้าหน้าที่ สํานักปลัดกรุงเทพมหานครเพื่อขอตรวจสอบพฤติการณ์ทางวินัย และภาระหนี้สินสวัสดิการ /// /// id /// pdf, docx หรือ xlsx /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpGet("25/{exportType}/{id}")] public async Task> GetTransfer5ConvertReportAsync(Guid id, string exportType = "pdf") { try { var data = await _service.GetData5Transfer(id); //var mimeType = ""; //switch (exportType.Trim().ToLower()) //{ // case "pdf": mimeType = "application/pdf"; break; // case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break; // case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break; //} //var rptFile = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"25-หนังสือถึงสํานักงานการเจ้าหน้าที่-1.trdp"); //var rptFile2 = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"25-หนังสือถึงสํานักงานการเจ้าหน้าที่-2.trdp"); //var rptFile3 = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"25-หนังสือถึงสํานักงานการเจ้าหน้าที่-3.trdp"); //ReportPackager reportPacker = new ReportPackager(); //Telerik.Reporting.Report? report = null; //Telerik.Reporting.Report? report2 = null; //Telerik.Reporting.Report? report3 = null; //using (var sourceStream = System.IO.File.OpenRead(rptFile)) //using (var sourceStream2 = System.IO.File.OpenRead(rptFile2)) //using (var sourceStream3 = System.IO.File.OpenRead(rptFile3)) //{ // report = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream); // report2 = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream2); // report3 = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream3); //} //report.DataSource = data; //report2.DataSource = data; //report3.DataSource = data; //var reportBook = new ReportBook(); //reportBook.Reports.Add(report); //reportBook.Reports.Add(report2); //reportBook.Reports.Add(report3); //System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); //InstanceReportSource instanceReportSource = new InstanceReportSource() //{ // ReportDocument = reportBook, //}; //ReportProcessor reportProcessor = new ReportProcessor(_configuration); //RenderingResult result = reportProcessor.RenderReport($"{exportType}", instanceReportSource, deviceInfo); //var content = result.DocumentBytes; //return File(content, mimeType, $"หนังสือถึงสํานักงานการเจ้าหน้าที่.{exportType.Trim().ToLower()}"); var result = new { template = "transfer5", reportName = "docx-report", data = data }; return Success(result); } catch { throw; } } #endregion #region หนังสือถึงสถาบันพัฒนาข้าราชการกรุงเทพมหานครเพื่อขอตรวจสอบเรื่องภาระผูกพันการรับทุนและการลา ศึกษาต่อกับทางกรุงเทพมหานคร /// /// หนังสือถึงสถาบันพัฒนาข้าราชการกรุงเทพมหานครเพื่อขอตรวจสอบเรื่องภาระผูกพันการรับทุนและการลา ศึกษาต่อกับทางกรุงเทพมหานคร /// /// id /// pdf, docx หรือ xlsx /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpGet("26/{exportType}/{id}")] public async Task> GetTransfer6ConvertReportAsync(Guid id, string exportType = "pdf") { try { var data = await _service.GetData6Transfer(id); //var mimeType = ""; //switch (exportType.Trim().ToLower()) //{ // case "pdf": mimeType = "application/pdf"; break; // case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break; // case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break; //} //var rptFile = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"26-หนังสือถึงสถาบันพัฒนาข้าราชการ-1.trdp"); //var rptFile2 = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"26-หนังสือถึงสถาบันพัฒนาข้าราชการ-2.trdp"); //var rptFile3 = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"26-หนังสือถึงสถาบันพัฒนาข้าราชการ-3.trdp"); //var rptFile4 = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"26-หนังสือถึงสถาบันพัฒนาข้าราชการ-4.trdp"); //var rptFile5 = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"26-หนังสือถึงสถาบันพัฒนาข้าราชการ-5.trdp"); //ReportPackager reportPacker = new ReportPackager(); //Telerik.Reporting.Report? report = null; //Telerik.Reporting.Report? report2 = null; //Telerik.Reporting.Report? report3 = null; //Telerik.Reporting.Report? report4 = null; //Telerik.Reporting.Report? report5 = null; //using (var sourceStream = System.IO.File.OpenRead(rptFile)) //using (var sourceStream2 = System.IO.File.OpenRead(rptFile2)) //using (var sourceStream3 = System.IO.File.OpenRead(rptFile3)) //using (var sourceStream4 = System.IO.File.OpenRead(rptFile4)) //using (var sourceStream5 = System.IO.File.OpenRead(rptFile5)) //{ // report = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream); // report2 = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream2); // report3 = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream3); // report4 = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream4); // report5 = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream5); //} //report.DataSource = data; //report2.DataSource = data; //report3.DataSource = data; //report4.DataSource = data; //report5.DataSource = data; //var reportBook = new ReportBook(); //reportBook.Reports.Add(report); //reportBook.Reports.Add(report2); //reportBook.Reports.Add(report3); //reportBook.Reports.Add(report4); //reportBook.Reports.Add(report5); //System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); //InstanceReportSource instanceReportSource = new InstanceReportSource() //{ // ReportDocument = reportBook, //}; //ReportProcessor reportProcessor = new ReportProcessor(_configuration); //RenderingResult result = reportProcessor.RenderReport($"{exportType}", instanceReportSource, deviceInfo); //var content = result.DocumentBytes; //return File(content, mimeType, $"หนังสือถึงสถาบันพัฒนาข้าราชการ.{exportType.Trim().ToLower()}"); var result = new { template = "transfer6", reportName = "docx-report", data = data }; return Success(result); } catch { throw; } } #endregion #endregion } }