From 75104a82cca0e5d8d869eae1ba76b47ccbe4e173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=98=89=E7=A5=A5=20=E8=A9=B9?= Date: Fri, 26 Jul 2024 18:48:06 +0800 Subject: [PATCH] updates --- Controllers/AuthApiController.cs | 62 +++++- Controllers/HomeController.cs | 17 +- Modals/DbTableClass.cs | 3 + Modals/resultClass.cs | 15 +- Views/Home/GroupList.cshtml | 195 ++++++++++++++++++ wwwroot/assets/javascript/custom/grouplist.js | 128 +++++++++++- wwwroot/assets/javascript/custom/userlist.js | 2 +- 7 files changed, 413 insertions(+), 9 deletions(-) diff --git a/Controllers/AuthApiController.cs b/Controllers/AuthApiController.cs index 0e03cad5..6288fbc9 100644 --- a/Controllers/AuthApiController.cs +++ b/Controllers/AuthApiController.cs @@ -25,8 +25,48 @@ namespace QuotationMaker.Controllers } - [Route("deptList")] - public ActionResult DeptList(IFormCollection obj) + [Route("noGroupUserList")] + public ActionResult NoGroupUserList(IFormCollection obj) { + userListResult ret = new userListResult(); + + authToken token = new authToken(this._httpContextAccessor); + if (token.user_isLogin == false) + { + HttpContext.Response.Cookies.Delete("token_key"); + ret.ret = "no"; + ret.err_code = "99999"; + ret.message = "非登入狀態!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + if (token.user_perm != "system") + { + ret.ret = "no"; + ret.err_code = "90001"; + ret.message = "此帳號無此api使用權限!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + string dept_uid = obj["dept_uid"].ToString(); + + if (dept_uid == "") + { + ret.ret = "no"; + ret.err_code = "00002"; + ret.message = "無dept_uid參數!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + List userList = conn.Query("select A.* from users A, userDept B where A.user_uid = B.user_uid and A.user_ishidden = 'N' and A.user_onjob= 'Y' and B.dept_uid = @dept_uid and A.user_uid not in (select user_uid from groupUser) ", new { dept_uid = dept_uid }).ToList(); + + ret.userList = userList; + ret.ret = "yes"; + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + [Route("authDeptList")] + public ActionResult AuthDeptList(IFormCollection obj) { deptListResult ret = new deptListResult(); @@ -76,6 +116,24 @@ namespace QuotationMaker.Controllers return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); } + string dept_uid = obj["dept_uid"].ToString(); + + if (dept_uid == "") { + ret.ret = "no"; + ret.err_code = "00002"; + ret.message = "無dept_uid參數!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + List groupList = conn.Query("select * from group where dept_uid = @dept_uid", new { dept_uid = dept_uid}).ToList(); + + foreach (group objGroup in groupList) + { + ret.groups.Add(new groupDetail(objGroup)); + } + + ret.ret = "yes"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); } diff --git a/Controllers/HomeController.cs b/Controllers/HomeController.cs index 058ba7a5..27f15ffe 100644 --- a/Controllers/HomeController.cs +++ b/Controllers/HomeController.cs @@ -21,7 +21,22 @@ namespace QuotationMaker.Controllers { return View(); } - + + public IActionResult GroupList() + { + if (checkToken() == false) + { + HttpContext.Response.Cookies.Delete("token_key"); + return Redirect("~/Home/Login"); + } + + if (this._objToken.user_perm != "system") + { + return Redirect("~/"); + } + + return View(); + } public IActionResult UserList() { diff --git a/Modals/DbTableClass.cs b/Modals/DbTableClass.cs index 539ab29d..03aff8e1 100644 --- a/Modals/DbTableClass.cs +++ b/Modals/DbTableClass.cs @@ -50,8 +50,11 @@ public class DbTableClass [JsonIgnore] [Key] public int group_sn { get; set; } + + public string dept_uid { get; set; } = ""; public string group_uid { get; set; } = ""; public string group_name { get; set; } = ""; + public DateTime group_createdate { get; set; } = DateTime.Now; } diff --git a/Modals/resultClass.cs b/Modals/resultClass.cs index 7a52a80b..e3a5164a 100644 --- a/Modals/resultClass.cs +++ b/Modals/resultClass.cs @@ -4,8 +4,7 @@ using Dapper; using static DbTableClass; public class resultClass { - - public class deptListResult + public class deptListResult { public string ret = "no"; public string err_code = "0000"; @@ -22,8 +21,18 @@ public class resultClass } public class groupDetail : group - { + { + + SqlConnection conn = new SqlConnection(GlobalClass.appsettings("ConnectionStrings:SQLConnectionString")); + + public List users = new List(); + + public groupDetail() { } + + public groupDetail(group group) { + users = conn.Query("select B.* from groupUser A, users B where A.user_uid = B.user_uid and A.group_uid = @group_uid", new {group_uid = group.group_uid}).ToList(); + } } public class userWithDept : user diff --git a/Views/Home/GroupList.cshtml b/Views/Home/GroupList.cshtml index 12868260..49255bf5 100644 --- a/Views/Home/GroupList.cshtml +++ b/Views/Home/GroupList.cshtml @@ -14,3 +14,198 @@ } + +
+ +
+ + + +

群組清單

+

+
+ +
+ + +
+ +
+
+
+
+ + +
+
+
+
+ + +
+
+
+ +
+
+ +
+ +
+ +
+ +
+
Footer Menus
+
+ +
+
+
+ +
    +
  1. +
    + +
    Tracking Order
    +
    + +
    +
    +
  2. +
+
+ + +
+
+
+
+
+ + +
+ +
+ + + +
+ +
\ No newline at end of file diff --git a/wwwroot/assets/javascript/custom/grouplist.js b/wwwroot/assets/javascript/custom/grouplist.js index bbdb84aa..f8d36406 100644 --- a/wwwroot/assets/javascript/custom/grouplist.js +++ b/wwwroot/assets/javascript/custom/grouplist.js @@ -1,5 +1,129 @@  -$(document).on('load', function () { -}); \ No newline at end of file +$(document).ready(function () { + deptList(); + + $('#groupNewModal').on('click', function () { + $('#groupModal').modal('toggle'); + }); + + +}); + +function newMemberClick(dept_uid) { + var formData = { + dept_uid: dept_uid + } + + $.ajax({ + url: "/AuthApi/noGroupUserList", + type: "post", + data: formData, + success: function (data, textStatus, jqXHR) { + if (data.ret == "yes") { + $('#nogroup_memberlist').html('
勾選要加入群組的成員
'); + + var obj = data.userList; + var items = ""; + $.each(obj, function (i, item) { + var isExist = 'N'; + + $.each($('#nestableMember .dd-list li'), function () { + var tmp_uid = $(this).attr('data-user-uid'); + if (tmp_uid == item.user_uid) { + isExist = 'Y'; + } + }); + + if (isExist == 'N') { + items += ''; + } + + + }); + + $('#nogroup_memberlist').append(items); + + $('#memberModal').modal('toggle'); + } else { + alert(data.message); + + if (data.err_code == "99999") { + location.href = "/Root/Login"; + } + } + }, + error: function (jqXHR, textStatus, errorThrown) { + alert('網路或伺服器發生錯誤,請稍後重試!'); + } + }); +} + +function groupList() { + var dept_uid = $('#dept_select').val(); + var formData = { + dept_uid: dept_uid + } + $.ajax({ + url: "/AuthApi/groupList", + type: "post", + data: formData, + success: function (data, textStatus, jqXHR) { + if (data.ret == "yes") { + $('#group_div').html(''); + + var obj = data.groups; + var items = ""; + $.each(obj, function (i, item) { + + + + + + }); + } else { + alert(data.message); + + if (data.err_code == "99999") { + location.href = "/Root/Login"; + } + } + }, + error: function (jqXHR, textStatus, errorThrown) { + alert('網路或伺服器發生錯誤,請稍後重試!'); + } + }); +} +function deptList() { + $.ajax({ + url: "/AuthApi/authDeptList", + type: "post", + data: null, + success: function (data, textStatus, jqXHR) { + if (data.ret == "yes") { + var obj = data.depts; + var items = ""; + $.each(obj, function (i, item) { + + + $("#dept_select").append($("