From 633fa6d0b3f454f88060c5e4f886d9e748d114ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=98=89=E7=A5=A5=20=E8=A9=B9?= Date: Tue, 26 Mar 2024 15:45:50 +0800 Subject: [PATCH] update project filiter --- Controllers/ApiController.cs | 34 ++++++ Views/Home/ProjectList.cshtml | 56 +++++++++ .../assets/javascript/custom/projectlist.js | 107 ++++++++++++++++++ 3 files changed, 197 insertions(+) diff --git a/Controllers/ApiController.cs b/Controllers/ApiController.cs index 9600f56..b9094ae 100644 --- a/Controllers/ApiController.cs +++ b/Controllers/ApiController.cs @@ -866,6 +866,40 @@ namespace Journeys_WantHome.Controllers string project_year = obj["year"].ToString(); string project_month = obj["month"].ToString(); + string is_filiter = obj["is_filiter"].ToString(); + string start = obj["start"].ToString(); + string end = obj["end"].ToString(); + string isExec = obj["isExec"].ToString(); + + + if (is_filiter == "Y") { + string dateString = ""; + string exeString = ""; + + if (start != "" && end != "") { + start = start.Replace("/", ""); + end = end.Replace("/", ""); + + dateString = " and ((CONVERT(NVARCHAR, project_year) + RIGHT('00' + CONVERT(NVARCHAR, project_month), 2)) >= '" + start + "') and ((CONVERT(NVARCHAR, project_year) + RIGHT('00' + CONVERT(NVARCHAR, project_month), 2)) <= '" + end + "' ) "; + } + + if (isExec != "A") { + exeString = " and project_isExec = '" + isExec + "' "; + } + + string sqlString = "select * from project where 1=1 " + dateString + exeString + " order by project_modifydate desc "; + + List projects = conn.Query(sqlString).ToList(); + foreach (project item in projects) + { + ret.projectList.Add(new projectDetail(item)); + } + + ret.ret = "yes"; + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + if (project_year == "") { diff --git a/Views/Home/ProjectList.cshtml b/Views/Home/ProjectList.cshtml index cad305d..fd837d2 100644 --- a/Views/Home/ProjectList.cshtml +++ b/Views/Home/ProjectList.cshtml @@ -29,6 +29,62 @@

+
+
+
+ +
+ +
+
+ +
+
+
+
+ +
+
+
+ + +
+
+
+
+ + +
+
+
+
+ +
+ +
+
+ +
+
+ +
+
+
+
+
+ + +
+
+
+ +
+
+
+
+
+
+
diff --git a/wwwroot/assets/javascript/custom/projectlist.js b/wwwroot/assets/javascript/custom/projectlist.js index 6f22035..0cd7ac6 100644 --- a/wwwroot/assets/javascript/custom/projectlist.js +++ b/wwwroot/assets/javascript/custom/projectlist.js @@ -7,6 +7,113 @@ $(document).ready(function () { loadPrm(); loadyearmonth(); + flatpickr("#dateStart", { + "plugins": [ + new monthSelectPlugin({ + shorthand: true, //defaults to false + dateFormat: "Y/m", //defaults to "F Y" + altFormat: "Y M", //defaults to "F Y" + theme: "light" // defaults to "light" + }) + ] + }); + + flatpickr("#dateEnd", { + "plugins": [ + new monthSelectPlugin({ + shorthand: true, //defaults to false + dateFormat: "Y/m", //defaults to "F Y" + altFormat: "Y M", //defaults to "F Y" + theme: "light" // defaults to "light" + }) + ] + }); + + + $('#resetBtn').on('click', function () { + + + $.ajax({ + url: "/Api/projectList", + type: "post", + data: null, + success: function (data, textStatus, jqXHR) { + var obj = data.projectList; + if (data.ret == "yes") { + $('#adv-search-btn').trigger('click'); + + $('#dateStart').val(''); + $('#dateEnd').val(''); + + + + $('#dt-responsive').dataTable().fnClearTable(); + if (data.projectList.length > 0) { + + $('#dt-responsive').dataTable().fnAddData(data.projectList); + + + } + } else { + alert(data.message); + + if (data.err_code == "99999") { + location.href = "/Root/Login"; + } + } + }, + error: function (jqXHR, textStatus, errorThrown) { + alert('網路或伺服器發生錯誤,請稍後重試!'); + } + }); + }); + + $('#filiterBtn').on('click', function () { + var start = $('#dateStart').val(); + var end = $('#dateEnd').val(); + var isExec = $('input[name="rdGroup1[]"]:checked').val(); + + if (!((start == "" && end == "") || (start != "" && end != ""))) { + alert('起訖時間未輸入完全!'); + return; + } + + var formData = { + is_filiter: 'Y', + start: start, + end: end, + isExec: isExec + } + + $.ajax({ + url: "/Api/projectList", + type: "post", + data: formData, + success: function (data, textStatus, jqXHR) { + var obj = data.projectList; + if (data.ret == "yes") { + + $('#dt-responsive').dataTable().fnClearTable(); + if (data.projectList.length > 0) { + + $('#dt-responsive').dataTable().fnAddData(data.projectList); + + + } + } else { + alert(data.message); + + if (data.err_code == "99999") { + location.href = "/Root/Login"; + } + } + }, + error: function (jqXHR, textStatus, errorThrown) { + alert('網路或伺服器發生錯誤,請稍後重試!'); + } + }); + }); + $('#projectSaveBtn').on('click', function () { var method = $('#method').val(); var project_isPrm = $('input:radio[name="project_isExec[]"]:checked').val();