diff --git a/Controllers/AuthApiController.cs b/Controllers/AuthApiController.cs index 9b4768b2..d5c3bfe8 100644 --- a/Controllers/AuthApiController.cs +++ b/Controllers/AuthApiController.cs @@ -25,6 +25,345 @@ namespace QuotationMaker.Controllers } + [Route("addEditDelGetSubItem")] + public ActionResult AddEditDelSubItem(IFormCollection obj) { + authSubItemResult ret = new authSubItemResult(); + + 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(); + string mainItem_uid = obj["mainItem_uid"].ToString(); + string subItem_uid = obj["subItem_uid"].ToString(); + string subItem_name = obj["subItem_name"].ToString(); + string subItem_descript = obj["subItem_descript"].ToString(); + string subItem_priceStr = obj["subItem_price"].ToString(); + string subItem_unitType = obj["subItem_unitType"].ToString(); + string method = obj["method"].ToString(); + + + + + if (method == "") { + ret.ret = "no"; + ret.err_code = "0001"; + ret.message = "沒有method!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + + + if (dept_uid.Trim() == "") + { + ret.ret = "no"; + ret.err_code = "0003"; + ret.message = "沒有dept_uid!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + if (method == "add") + { + double subItem_price = 0.0; + + try + { + subItem_price = Double.Parse(subItem_priceStr); + } + catch + { + ret.ret = "no"; + ret.err_code = "0005"; + ret.message = "subItem_price非數字!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + + subItem_uid = GlobalClass.CreateRandomCode(24); + subItem newItem = new subItem(); + newItem.subItem_name = subItem_name; + newItem.mainItem_uid = mainItem_uid; + newItem.subItem_uid = subItem_uid; + newItem.subItem_descript = subItem_descript; + newItem.subItem_price = subItem_price; + newItem.subItem_unitType = subItem_unitType; + + newItem.subItem_lastmodify_uid = token.user_uid; + newItem.subItem_createdate = DateTime.Now; + newItem.subItem_modifydate = DateTime.Now; + + conn.Insert(newItem); + ret.subItems.Add(newItem); + ret.ret = "yes"; + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + if (subItem_uid.Trim() == "") + { + ret.ret = "no"; + ret.err_code = "0002"; + ret.message = "沒有mainItem_uid!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + + + subItem editItem = conn.QueryFirstOrDefault("select * from subItem where subItem_uid = @subItem_uid ", new { subItem_uid = subItem_uid }); + + if (editItem == null) { + ret.ret = "no"; + ret.err_code = "0004"; + ret.message = "沒有subItem_uid此筆資料!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + if (method == "edit") { + double subItem_price = 0.0; + + try + { + subItem_price = Double.Parse(subItem_priceStr); + } + catch { + ret.ret = "no"; + ret.err_code = "0005"; + ret.message = "subItem_price非數字!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + if (subItem_name.Trim() == "") + { + ret.ret = "no"; + ret.err_code = "0002"; + ret.message = "沒有mainItem_name!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + editItem.subItem_name = subItem_name; + editItem.subItem_descript = subItem_descript; + editItem.subItem_price = subItem_price; + editItem.subItem_unitType = subItem_unitType; + + editItem.subItem_lastmodify_uid = token.user_uid; + editItem.subItem_modifydate = DateTime.Now; + + conn.Update(editItem); + ret.subItems.Add(editItem); + ret.ret = "yes"; + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + if (method == "get") { + ret.subItems.Add(editItem); + ret.ret = "yes"; + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + if (method == "del") { + conn.Delete(editItem); + ret.ret = "yes"; + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + [Route("authSubItemList")] + public ActionResult AuthSubItemList(IFormCollection obj) { + authSubItemResult ret = new authSubItemResult(); + + 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(); + string mainItem_uid = obj["mainItem_uid"].ToString(); + + ret.subItems = conn.Query("select * from subItem where mainItem_uid = @mainItem_uid", new { mainItem_uid = mainItem_uid }).ToList(); + ret.ret = "yes"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + [Route("addEditDelGetMainItem")] + public ActionResult AddEditDelMainItem(IFormCollection obj) { + authMainItemResult ret = new authMainItemResult(); + + 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(); + string mainItem_uid = obj["mainItem_uid"].ToString(); + string mainItem_name = obj["mainItem_name"].ToString(); + string method = obj["method"].ToString(); + + if (method == "") { + ret.ret = "no"; + ret.err_code = "0001"; + ret.message = "沒有method!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + + + if (dept_uid.Trim() == "") + { + ret.ret = "no"; + ret.err_code = "0003"; + ret.message = "沒有dept_uid!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + if (method == "add") + { + mainItem_uid = GlobalClass.CreateRandomCode(12); + mainItem newItem = new mainItem(); + newItem.mainItem_name = mainItem_name; + newItem.mainItem_uid = mainItem_uid; + newItem.dept_uid = dept_uid; + newItem.mainItem_lastmodify_uid = token.user_uid; + newItem.mainItem_createdate = DateTime.Now; + newItem.mainItem_modifydate = DateTime.Now; + + conn.Insert(newItem); + ret.mainItems.Add(newItem); + ret.ret = "yes"; + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + if (mainItem_uid.Trim() == "") + { + ret.ret = "no"; + ret.err_code = "0002"; + ret.message = "沒有mainItem_uid!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + + + mainItem editItem = conn.QueryFirstOrDefault("select * from mainItem where mainItem_uid = @mainItem_uid ", new { mainItem_uid = mainItem_uid }); + + if (editItem == null) { + ret.ret = "no"; + ret.err_code = "0004"; + ret.message = "沒有mainItem_uid此筆資料!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + if (method == "edit") { + if (mainItem_name.Trim() == "") + { + ret.ret = "no"; + ret.err_code = "0002"; + ret.message = "沒有mainItem_name!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + editItem.mainItem_name = mainItem_name; + editItem.mainItem_lastmodify_uid = token.user_uid; + editItem.mainItem_modifydate= DateTime.Now; + + conn.Update(editItem); + ret.mainItems.Add(editItem); + ret.ret = "yes"; + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + if (method == "get") { + ret.mainItems.Add(editItem); + ret.ret = "yes"; + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + if (method == "del") { + conn.Delete(editItem); + ret.ret = "yes"; + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + [Route("authMainItemList")] + public ActionResult AuthMainItemList(IFormCollection obj) { + authMainItemResult ret = new authMainItemResult(); + + 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(); + + ret.mainItems = conn.Query("select * from mainItem where dept_uid = @dept_uid", new { dept_uid = dept_uid }).ToList(); + ret.ret = "yes"; + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + [Route("addGroupUser")] public ActionResult AddGroupUser(IFormCollection obj) { groupUserListResult ret = new groupUserListResult(); @@ -524,7 +863,7 @@ namespace QuotationMaker.Controllers try { - elabUser = elabConn.QueryFirstOrDefault("select * from new_userdata where userid = @user_id", new { user_id = user_id }); + elabUser = elabConn.QueryFirstOrDefault("select * from new_userdata where userid = @user_id order by mail, userid", new { user_id = user_id }); } catch (Exception ex) { @@ -630,7 +969,7 @@ namespace QuotationMaker.Controllers return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); } - new_userdata elabUser = elabConn.QueryFirstOrDefault("select * from new_userdata where userid = @user_id", new { user_id = user_id }); + new_userdata elabUser = elabConn.QueryFirstOrDefault("select * from new_userdata where userid = @user_id order by mail", new { user_id = user_id }); if (elabUser != null) { @@ -849,7 +1188,7 @@ namespace QuotationMaker.Controllers return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); } - ret.userList = elabConn.Query("select * from new_userdata where onjob = 0 order by usersn desc ").ToList(); + ret.userList = elabConn.Query("select * from new_userdata where onjob = 0 order by mail ").ToList(); ret.ret = "yes"; return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); } @@ -1006,7 +1345,7 @@ namespace QuotationMaker.Controllers } else { - new_userdata elabUser = elabConn.QueryFirstOrDefault("select * from new_userdata where userid = @userid", new { userid = webUser.user_id }); + new_userdata elabUser = elabConn.QueryFirstOrDefault("select * from new_userdata where userid = @userid order by mail, userid", new { userid = webUser.user_id }); if (input_PWD != GlobalClass.Sha256(elabUser.userpw)) { diff --git a/Controllers/HomeController.cs b/Controllers/HomeController.cs index 27f15ffe..9f94bdea 100644 --- a/Controllers/HomeController.cs +++ b/Controllers/HomeController.cs @@ -22,6 +22,22 @@ namespace QuotationMaker.Controllers return View(); } + public IActionResult RateList() + { + 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 GroupList() { if (checkToken() == false) diff --git a/Modals/DbTableClass.cs b/Modals/DbTableClass.cs index 1f917430..62748cc7 100644 --- a/Modals/DbTableClass.cs +++ b/Modals/DbTableClass.cs @@ -8,6 +8,37 @@ using Newtonsoft.Json.Linq; public class DbTableClass { + [Table("subItem")] + public class subItem + { + [JsonIgnore] + [Key] + public int subItem_sn { get; set; } + public string subItem_uid { get; set; } = ""; + public string mainItem_uid { get; set; } = ""; + public string subItem_name { get; set; } = ""; + public string subItem_descript { get; set; } = ""; + public double subItem_price { get; set; } = 0.0; + public string subItem_unitType { get; set; } = ""; + public DateTime subItem_createdate { get; set; } = DateTime.Now; + public DateTime subItem_modifydate { get; set; } = DateTime.Now; + public string subItem_lastmodify_uid { get; set; } = ""; + } + + [Table("mainItem")] + public class mainItem + { + [JsonIgnore] + [Key] + public int mainItem_sn { get; set; } + public string mainItem_uid { get; set; } = ""; + public string dept_uid { get; set; } = ""; + public string mainItem_name { get; set; } = ""; + public DateTime mainItem_createdate { get; set; } = DateTime.Now; + public DateTime mainItem_modifydate { get; set; } = DateTime.Now; + public string mainItem_lastmodify_uid { get; set; } = ""; + } + [Table("userDept")] public class userDept { diff --git a/Modals/resultClass.cs b/Modals/resultClass.cs index 08269308..77f413ff 100644 --- a/Modals/resultClass.cs +++ b/Modals/resultClass.cs @@ -4,7 +4,23 @@ using Dapper; using static DbTableClass; public class resultClass { - public class deptListResult + public class authMainItemResult + { + public string ret = "no"; + public string err_code = "0000"; + public string message = ""; + public List mainItems = new List(); + } + + public class authSubItemResult + { + public string ret = "no"; + public string err_code = "0000"; + public string message = ""; + public List subItems = new List(); + } + + public class deptListResult { public string ret = "no"; public string err_code = "0000"; diff --git a/Views/Home/RateList.cshtml b/Views/Home/RateList.cshtml new file mode 100644 index 00000000..c3a2560f --- /dev/null +++ b/Views/Home/RateList.cshtml @@ -0,0 +1,167 @@ +@* + For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 +*@ +@{ + Layout = "_LooperLayout"; +} + +@section Style { + +} +@section Script { + + + + + +} + +
+ +
+ + + +

主項目清單

+

+
+ +
+ + +
+ +
+
+
+
+ + +
+
+
+
+ + +
+
+
+ +
+
+ +
+ +
+ + + + + + + + + + +
主項目名稱 功能
+
+
+
+
+ + + +
+ +
+ + + +
+ +
\ No newline at end of file diff --git a/Views/Shared/_LooperLayout.cshtml b/Views/Shared/_LooperLayout.cshtml index d6d0bb61..363a507a 100644 --- a/Views/Shared/_LooperLayout.cshtml +++ b/Views/Shared/_LooperLayout.cshtml @@ -135,6 +135,9 @@