From 34a87cbf4034b6187fde5e2c962000766ade8feb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=98=89=E7=A5=A5=20=E8=A9=B9?= Date: Fri, 30 Aug 2024 18:51:07 +0800 Subject: [PATCH] updates --- Controllers/ApiController.cs | 170 +++++++++++++++++- Modals/DbTableClass.cs | 4 + Views/Home/ProjectList.cshtml | 2 +- .../assets/javascript/custom/projectlist.js | 124 ++++++++++++- 4 files changed, 295 insertions(+), 5 deletions(-) diff --git a/Controllers/ApiController.cs b/Controllers/ApiController.cs index f7f1297d..45b360fe 100644 --- a/Controllers/ApiController.cs +++ b/Controllers/ApiController.cs @@ -8,6 +8,7 @@ using Dapper; using Newtonsoft.Json; using Org.BouncyCastle.Bcpg.OpenPgp; using NPOI.OpenXmlFormats.Shared; +using NPOI.SS.Formula.PTG; namespace QuotationMaker.Controllers { @@ -56,6 +57,171 @@ namespace QuotationMaker.Controllers return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); } + [Route("addEditDelGetProject")] + public ActionResult AddEditDelGetProject(IFormCollection obj) { + projectViewResult ret = new projectViewResult(); + 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"); + } + + string user_uid = token.user_uid; + string user_perm = token.user_perm; + string dept_uid = obj["dept_uid"].ToString(); + string method = obj["method"].ToString(); + string project_uid = obj["project_uid"].ToString(); + string project_name = obj["project_name"].ToString(); + string company_uid = obj["company_uid"].ToString(); + string project_ps = obj["project_ps"].ToString(); + + if (token.user_id != GlobalClass.appsettings("Admin:id")) { + groupUser gpUser = conn.QueryFirstOrDefault("select * from groupUser where dept_uid = @dept_uid and user_uid = @user_uid ", new { dept_uid = dept_uid, user_uid = user_uid }); + + if (gpUser == null) { + ret.ret = "no"; + ret.err_code = "99991"; + ret.message = "新增的專案資料其部門不屬於目前登入的使用者!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + } + + if (method == "") + { + ret.ret = "no"; + ret.err_code = "0001"; + ret.message = "沒有method!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + if (method == "add") { + string errmsg = ""; + + if (project_name == "") + { + errmsg += "無專案名稱!\n"; + } + + if (company_uid == "") + { + errmsg += "請選擇客戶公司!\n"; + } + + if (errmsg != "") { + ret.ret = "no"; + ret.err_code = "0002"; + ret.message = errmsg; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + project_uid = GlobalClass.CreateRandomCode(24); + + project newProject = new project(); + newProject.project_uid = project_uid; + newProject.dept_uid = dept_uid; + newProject.company_uid = company_uid; + newProject.project_ps = project_ps; + newProject.project_lastmodify_uid = token.user_uid; + newProject.project_name = project_name; + newProject.project_datetime = DateTime.Now.ToString("yyyy/MM/dd"); + + conn.Insert(newProject); + + projectView objView = conn.QueryFirstOrDefault("select * from projectView where project_isdel = 'N' and project_uid = @project_uid", new { project_uid = project_uid}); + + if (objView != null) + { + ret.projectViews.Add(objView); + } + + + ret.ret = "yes"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + + } + + project editProject = conn.QueryFirstOrDefault("select * from project where project_isdel = 'N' and project_uid = @project_uid ", new { project_uid = project_uid }); + + if (editProject == null) { + ret.ret = "no"; + ret.err_code = "0004"; + ret.message = "無此project_uid資料!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + if (method == "get") { + projectView objView = conn.QueryFirstOrDefault("select * from projectView where project_isdel = 'N' and project_uid = @project_uid", new { project_uid = project_uid }); + + if (objView != null) + { + ret.projectViews.Add(objView); + } + + + ret.ret = "yes"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + if (method == "edit") { + string errmsg = ""; + + if (project_name == "") + { + errmsg += "無專案名稱!\n"; + } + + if (company_uid == "") + { + errmsg += "請選擇客戶公司!\n"; + } + + if (errmsg != "") + { + ret.ret = "no"; + ret.err_code = "0002"; + ret.message = errmsg; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + editProject.dept_uid = dept_uid; + editProject.company_uid = company_uid; + editProject.project_ps = project_ps; + editProject.project_lastmodify_uid = token.user_uid; + editProject.project_name = project_name; + editProject.project_modifydate = DateTime.Now; + + conn.Update(editProject); + + projectView objView = conn.QueryFirstOrDefault("select * from projectView where project_isdel = 'N' and project_uid = @project_uid", new { project_uid = project_uid }); + + if (objView != null) + { + ret.projectViews.Add(objView); + } + + + ret.ret = "yes"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + if (method == "del") { + editProject.project_lastmodify_uid = token.user_uid; + editProject.project_isdel = "Y"; + editProject.project_modifydate = DateTime.Now; + + conn.Update(editProject); + + ret.ret = "yes"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + [Route("projectViewList")] public ActionResult ProjectViewList(IFormCollection obj) { projectViewResult ret = new projectViewResult(); @@ -105,7 +271,9 @@ namespace QuotationMaker.Controllers } } - ret.projectViews = conn.Query("select * from projectView where project_lastmodify_uid in (@user_list) and project_createdate >= @start_date and project_createdate <= @end_date", new { user_list = user_uid_list, start_date = startDateTime.ToString("yyyy/MM/dd"), end_date = endDateTime.ToString("yyyy/MM/dd 23:59:59") } ).ToList(); + string sqlString = "select * from projectView where project_isdel = 'N' and project_lastmodify_uid in (" + user_uid_list + ") and project_createdate >= '" + startDateTime.ToString("yyyy/MM/dd") + "' and project_createdate <= '" + endDateTime.ToString("yyyy/MM/dd 23:59:59") + "'"; + + ret.projectViews = conn.Query(sqlString).ToList(); ret.ret = "yes"; return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); diff --git a/Modals/DbTableClass.cs b/Modals/DbTableClass.cs index 76578868..f578a6c1 100644 --- a/Modals/DbTableClass.cs +++ b/Modals/DbTableClass.cs @@ -24,6 +24,8 @@ public class DbTableClass public string project_lastmodify_uid { get; set; } = ""; public DateTime project_createdate { get; set; } = DateTime.Now; public DateTime project_modifydate { get; set; } = DateTime.Now; + + public string project_isdel { get; set; } = "N"; public string company_name { get; set; } = ""; public string company_serialNo { get; set; } = ""; public string company_address { get; set; } = ""; @@ -46,6 +48,8 @@ public class DbTableClass public string project_datetime { get; set; } = ""; public string company_uid { get; set; } = ""; public string project_ps { get; set; } = ""; + + public string project_isdel { get; set; } = "N"; public string project_lastmodify_uid { get; set; } = ""; public DateTime project_createdate { get; set; } = DateTime.Now; public DateTime project_modifydate { get; set; } = DateTime.Now; diff --git a/Views/Home/ProjectList.cshtml b/Views/Home/ProjectList.cshtml index 4b234721..9468cf42 100644 --- a/Views/Home/ProjectList.cshtml +++ b/Views/Home/ProjectList.cshtml @@ -173,7 +173,7 @@