From 95277cedeadd493702dc5a3606d059c2af8dedc3 Mon Sep 17 00:00:00 2001 From: Nakorn Rientrakrunchai Date: Tue, 2 Feb 2021 04:41:08 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=80=E0=B8=95=E0=B8=A3=E0=B8=B5=E0=B8=A2?= =?UTF-8?q?=E0=B8=A1=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=87=E0=B8=B2=E0=B8=99?= =?UTF-8?q?=20=E0=B9=81=E0=B8=9A=E0=B8=9A=E0=B8=82=E0=B9=89=E0=B8=AD?= =?UTF-8?q?=E0=B8=95=E0=B8=81=E0=B8=A5=E0=B8=87=E0=B8=81=E0=B8=B2=E0=B8=A3?= =?UTF-8?q?=E0=B8=9B=E0=B8=8F=E0=B8=B4=E0=B8=9A=E0=B8=B1=E0=B8=95=E0=B8=B4?= =?UTF-8?q?=E0=B8=87=E0=B8=B2=E0=B8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ApiControllers/rep_eva_xControllers.cs | 92 ++++++++++++++- .../rep_eva_p01ReportRequestModel.cs | 21 ++++ Models/rep_eva_x/rep_eva_p01SearchModel.cs | 23 ++++ .../eva_create_evaluation_d_summary.cshtml | 2 +- ...reate_evaluation_detail_agreement_d.cshtml | 110 +++++++++++------- tb320eva.xml | 10 ++ wwwroot/js/rep_eva_x/rep_eva_p01_report.js | 58 +++++++++ 7 files changed, 272 insertions(+), 44 deletions(-) create mode 100644 Models/rep_eva_x/rep_eva_p01ReportRequestModel.cs create mode 100644 Models/rep_eva_x/rep_eva_p01SearchModel.cs create mode 100644 wwwroot/js/rep_eva_x/rep_eva_p01_report.js diff --git a/ApiControllers/rep_eva_xControllers.cs b/ApiControllers/rep_eva_xControllers.cs index 277c228..e678458 100644 --- a/ApiControllers/rep_eva_xControllers.cs +++ b/ApiControllers/rep_eva_xControllers.cs @@ -88,7 +88,97 @@ namespace TodoAPI2.Controllers } } - /// + /// + /// Download Report + /// + /// + /// + /// Return list of items by specifced keyword + /// Returns the item + /// Error Occurred + [HttpGet("rep_eva_p01_report")] + [ProducesResponseType(typeof(FileStreamResult), 200)] + [ProducesResponseType(400)] + [ProducesResponseType(500)] + //[ValidateAntiForgeryToken] + public IActionResult rep_eva_p01_report(rep_eva_p01ReportRequestModel model) + { + try + { + if (!MyHelper.checkAuth(Configuration, HttpContext)) return Unauthorized(); + + var stream = new MemoryStream(); + Document document = new Document(); + PdfCopy writer = new PdfCopy(document, stream); + document.Open(); + + var data = GetReportP01(model); + + PdfReader reader = new PdfReader(data); + reader.ConsolidateNamedDestinations(); + + for (int i = 1; i <= reader.NumberOfPages; i++) + { + PdfImportedPage page = writer.GetImportedPage(reader, i); + writer.AddPage(page); + } + + reader.Close(); + + writer.Close(); + document.Close(); + + var data2 = stream.ToArray(); + var stream2 = new MemoryStream(data2); + + return File(stream2, model.contentType); + } + catch (Exception ex) + { + _logger.LogCritical($"Exception while GetReport.", ex); + return StatusCode(500, $"{ex.Message}"); + } + } + + private byte[] GetReportP01(rep_eva_p01ReportRequestModel model) + { + var httpclient = new WebClient(); + + string mainurl = MyHelper.GetConfig(Configuration, "JasperReportServer:MainURL"); + string reportsite = MyHelper.GetConfig(Configuration, "JasperReportServer:reportsite"); + string username = MyHelper.GetConfig(Configuration, "JasperReportServer:username"); + string password = MyHelper.GetConfig(Configuration, "JasperReportServer:password"); + + var p1 = GetParameter(model.detail_id); + + var stream = new MemoryStream(); + Document document = new Document(); + PdfCopy writer = new PdfCopy(document, stream); + document.Open(); + + string url = $"{mainurl}{reportsite}/rep_eva_p01.{model.filetype}?{MyHelper.GetParameterForJasperReport(p1)}&j_username={username}&j_password={password}"; + + var data = httpclient.DownloadData(url); + + PdfReader reader = new PdfReader(data); + reader.ConsolidateNamedDestinations(); + + for (int i = 1; i <= reader.NumberOfPages; i++) + { + PdfImportedPage page = writer.GetImportedPage(reader, i); + writer.AddPage(page); + } + + reader.Close(); + + writer.Close(); + document.Close(); + + var data2 = stream.ToArray(); + return data2; + } + + /// /// Download Report /// /// diff --git a/Models/rep_eva_x/rep_eva_p01ReportRequestModel.cs b/Models/rep_eva_x/rep_eva_p01ReportRequestModel.cs new file mode 100644 index 0000000..b515ad8 --- /dev/null +++ b/Models/rep_eva_x/rep_eva_p01ReportRequestModel.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Threading.Tasks; +using TTSW.EF; +using TTSW.Utils; +using TTSW.Constant; +using TTSW.Common; + +namespace TodoAPI2.Models +{ + public class rep_eva_p01ReportRequestModel : rep_eva_p01SearchModel + { + public string filetype { get; set; } + + public string contentType { get { return MyHelper.GetContentType(filetype); } } + } +} + diff --git a/Models/rep_eva_x/rep_eva_p01SearchModel.cs b/Models/rep_eva_x/rep_eva_p01SearchModel.cs new file mode 100644 index 0000000..67207cb --- /dev/null +++ b/Models/rep_eva_x/rep_eva_p01SearchModel.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Threading.Tasks; +using TTSW.EF; +using TTSW.Utils; +using TTSW.Constant; +using TTSW.Common; + +namespace TodoAPI2.Models +{ + public class rep_eva_p01SearchModel + { + + public Guid id { get; set; } + + public int detail_id { get; set; } + + } +} + diff --git a/Views/eva_create_evaluationView/eva_create_evaluation_d_summary.cshtml b/Views/eva_create_evaluationView/eva_create_evaluation_d_summary.cshtml index 26cb410..5530285 100644 --- a/Views/eva_create_evaluationView/eva_create_evaluation_d_summary.cshtml +++ b/Views/eva_create_evaluationView/eva_create_evaluation_d_summary.cshtml @@ -179,7 +179,7 @@ @section FooterPlaceHolder{ - + + } diff --git a/tb320eva.xml b/tb320eva.xml index 7802db4..3e682bc 100644 --- a/tb320eva.xml +++ b/tb320eva.xml @@ -3759,6 +3759,16 @@ Returns the item Error Occurred + + + Download Report + + + + Return list of items by specifced keyword + Returns the item + Error Occurred + Download Report diff --git a/wwwroot/js/rep_eva_x/rep_eva_p01_report.js b/wwwroot/js/rep_eva_x/rep_eva_p01_report.js new file mode 100644 index 0000000..513804b --- /dev/null +++ b/wwwroot/js/rep_eva_x/rep_eva_p01_report.js @@ -0,0 +1,58 @@ +var rep_eva_x_API = "/api/rep_eva_x/"; + +//================= Search Customizaiton ========================================= + +function rep_eva_x_GetSearchParameter(fileType) { + var rep_eva_xSearchObject = new Object(); + rep_eva_xSearchObject.detail_id = getUrlParameter("id"); + + + rep_eva_xSearchObject.fileType = fileType; + + console.log(rep_eva_xSearchObject); + + return rep_eva_xSearchObject; +} + +function rep_eva_x_FeedDataToSearchForm(data) { + $("#s_rep_eva_x_detail_id").val(data.detail_id); + +} + +//================= Form Data Customizaiton ========================================= + +function rep_eva_x_InitialForm(s) { + var successFunc = function (result) { + rep_eva_x_FeedDataToSearchForm(result); + endLoad(); + }; + startLoad(); + AjaxGetRequest(apisite + rep_eva_x_API + "GetBlankItem", successFunc, AlertDanger); +} + +//================= Data Table ========================================= + +var s_rep_eva_x_customValidation = function (group) { + return ""; +}; + + +function rep_eva_p01_DoSearch(fileType) { + + var p = $.param(rep_eva_x_GetSearchParameter(fileType)); + //console.log(p); + + var report_url = apisite + "/api/rep_eva_x/rep_eva_p01_report?" + p; + + if (fileType === "pdf") { + $("#report_result").attr("src", ""); + $("#report_result").attr("src", report_url); + $("#report_result").show(); + //window.open(report_url); + $("#report_xModel").modal("show"); + } else { + $("#report_result").hide(); + window.open(report_url); + } +} +