From 9aa338ff1828efdeedf43af5aa77392586517147 Mon Sep 17 00:00:00 2001 From: Pairat Sangprasert Date: Wed, 14 Jul 2021 18:54:07 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=97=E0=B8=B3=E0=B8=AB=E0=B8=99=E0=B9=89?= =?UTF-8?q?=E0=B8=B2=20font=20=E0=B9=83=E0=B8=AB=E0=B9=89=E0=B9=81?= =?UTF-8?q?=E0=B8=AA=E0=B8=94=E0=B8=87=20report=20jasper=20=E0=B9=81?= =?UTF-8?q?=E0=B8=A5=E0=B8=B0=20=E0=B9=80=E0=B8=82=E0=B8=B5=E0=B8=A2?= =?UTF-8?q?=E0=B8=99=20api=20controller=20=E0=B9=83=E0=B8=AB=E0=B9=89?= =?UTF-8?q?=E0=B9=81=E0=B8=AA=E0=B8=94=E0=B8=87=20report=20=E0=B9=81?= =?UTF-8?q?=E0=B8=A5=E0=B8=B0=20=E0=B8=97=E0=B8=B3=20class=20model=20?= =?UTF-8?q?=E0=B8=A3=E0=B8=B1=E0=B8=9A=20parameter=20=E0=B8=88=E0=B8=B2?= =?UTF-8?q?=E0=B8=81=20font?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...va_adjust_postponement_quotaControllers.cs | 39 +++++++++++++++++++ .../rep_eva_savemessageReportRequestModel.cs | 21 ++++++++++ .../eva_adjust_postponement_quota_d.cshtml | 24 ++++++++++++ tb320eva.xml | 10 +++++ .../eva_adjust_postponement_quota_d.js | 30 ++++++++++++++ 5 files changed, 124 insertions(+) create mode 100644 Models/rep_eva_savemessage/rep_eva_savemessageReportRequestModel.cs diff --git a/ApiControllers/eva_adjust_postponement_quotaControllers.cs b/ApiControllers/eva_adjust_postponement_quotaControllers.cs index 0d161fd..f9c0ca6 100644 --- a/ApiControllers/eva_adjust_postponement_quotaControllers.cs +++ b/ApiControllers/eva_adjust_postponement_quotaControllers.cs @@ -15,6 +15,7 @@ using TodoAPI2.Models; using System.Data; using Microsoft.Extensions.Configuration; using System.IO; +using System.Net; namespace TodoAPI2.Controllers { @@ -315,6 +316,44 @@ namespace TodoAPI2.Controllers return BadRequest(ModelState); } + /// + /// Download Report + /// + /// + /// + /// Return list of items by specifced keyword + /// Returns the item + /// Error Occurred + [HttpGet("rep_eva_savemessage")] + [ProducesResponseType(typeof(FileStreamResult), 200)] + [ProducesResponseType(400)] + [ProducesResponseType(500)] + //[ValidateAntiForgeryToken] + public IActionResult rep_eva_savemessage(rep_eva_savemessageReportRequestModel model) + { + try + { + if (!MyHelper.checkAuth(Configuration, HttpContext)) return Unauthorized(); + //var httpclient = MyHelper.getHttpClient(Configuration); + 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"); + string url = $"{mainurl}{reportsite}/rep_eva_savemessage.{model.filetype}?{MyHelper.GetParameterForJasperReport(model)}&j_username={username}&j_password={password}"; + + var data = httpclient.DownloadData(url); + var stream = new MemoryStream(data); + + return File(stream, model.contentType); + } + catch (Exception ex) + { + _logger.LogCritical($"Exception while GetReport.", ex); + return StatusCode(500, $"Exception while GetReport. {ex.Message}"); + } + } + } } diff --git a/Models/rep_eva_savemessage/rep_eva_savemessageReportRequestModel.cs b/Models/rep_eva_savemessage/rep_eva_savemessageReportRequestModel.cs new file mode 100644 index 0000000..de95e7d --- /dev/null +++ b/Models/rep_eva_savemessage/rep_eva_savemessageReportRequestModel.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_savemessageReportRequestModel + { + public int? quota_id { get; set; } + public string filetype { get; set; } + public string contentType { get { return MyHelper.GetContentType(filetype); } } + } +} + diff --git a/Views/eva_adjust_postponement_quotaView/eva_adjust_postponement_quota_d.cshtml b/Views/eva_adjust_postponement_quotaView/eva_adjust_postponement_quota_d.cshtml index d449432..7b64946 100644 --- a/Views/eva_adjust_postponement_quotaView/eva_adjust_postponement_quota_d.cshtml +++ b/Views/eva_adjust_postponement_quotaView/eva_adjust_postponement_quota_d.cshtml @@ -5,6 +5,29 @@ Layout = "_LayoutDirect"; } + +
@@ -103,6 +126,7 @@
+
diff --git a/tb320eva.xml b/tb320eva.xml index d6cf165..498212c 100644 --- a/tb320eva.xml +++ b/tb320eva.xml @@ -886,6 +886,16 @@ If the model is invalid Error Occurred + + + Download Report + + + + Return list of items by specifced keyword + Returns the item + Error Occurred + Default constructure for dependency injection diff --git a/wwwroot/js/eva_adjust_postponement_quota/eva_adjust_postponement_quota_d.js b/wwwroot/js/eva_adjust_postponement_quota/eva_adjust_postponement_quota_d.js index f2b94e3..1131ed5 100644 --- a/wwwroot/js/eva_adjust_postponement_quota/eva_adjust_postponement_quota_d.js +++ b/wwwroot/js/eva_adjust_postponement_quota/eva_adjust_postponement_quota_d.js @@ -180,3 +180,33 @@ function CalculateRemainQuota(m) { } +// ================================================= report rep_eva_savemessage ================================================== + +function rep_eva_savemessage_GetSearchParameter(fileType) { + var eva_adjust_postponement_quotaObject = new Object(); + eva_adjust_postponement_quotaObject.quota_id = $("#eva_adjust_postponement_quota_id").val(); + + eva_adjust_postponement_quotaObject.fileType = fileType; + + return eva_adjust_postponement_quotaObject; +} + +function rep_eva_savemessage_DoSearch(fileType) { + if (!ValidateForm('eva_adjust_postponement_quota', eva_adjust_postponement_quota_customValidation)) { + return; + } + + var p = $.param(rep_eva_savemessage_GetSearchParameter(fileType)); + + var report_url = apisite + eva_adjust_postponement_quota_API + "rep_eva_savemessage?" + p; + + if (fileType === "pdf") { + $("#report_result").attr("src", report_url); + $("#report_result").show(); + $("#report_xModel").modal("show"); + } else { + $("#report_result").hide(); + window.open(report_url); + } + +}