From f6a1a8dac65577d2ad619fe8cedaa8783dfaed4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=98=89=E7=A5=A5=20=E8=A9=B9?= Date: Sat, 20 Jan 2024 02:34:33 +0800 Subject: [PATCH] updates --- Controllers/ApiController.cs | 204 +++++++- Models/DbTableClass.cs | 25 + Views/Home/ProjectList.cshtml | 85 +++- Views/Shared/_LooperLayout.cshtml | 4 + appsettings.json | 3 +- .../assets/javascript/custom/projectlist.js | 452 +++++++++++++++++- 6 files changed, 766 insertions(+), 7 deletions(-) diff --git a/Controllers/ApiController.cs b/Controllers/ApiController.cs index c96a0d6..277831c 100644 --- a/Controllers/ApiController.cs +++ b/Controllers/ApiController.cs @@ -41,7 +41,7 @@ using static Journeys_WantHome.Controllers.AuthApiController; namespace Journeys_WantHome.Controllers { [Route("Api")] - + public class ApiController : ControllerBase { private readonly IHttpContextAccessor _httpContextAccessor; @@ -49,13 +49,188 @@ namespace Journeys_WantHome.Controllers DbConn dbConn = new DbConn(); SqlConnection conn = new SqlConnection(GlobalClass.appsettings("ConnectionStrings:SQLConnectionString")); SqlConnection elabConn = new SqlConnection(GlobalClass.appsettings("ConnectionStrings:ElabConnectionString")); - + SqlConnection prmConn = new SqlConnection(GlobalClass.appsettings("ConnectionStrings:DBConnectionString")); public ApiController(IHttpContextAccessor httpContextAccessor) { this._httpContextAccessor = httpContextAccessor; } + [Route("queryPrm")] + public ActionResult QueryPrm(IFormCollection obj) { + prmResult ret = new prmResult(); + + string search = obj["search"].ToString(); + + string quotation_serial = search + "%"; + string quotation_name = "%" + search + "%"; + + List quotations = prmConn.Query("select * from quotation where quotation_del = 'N' and quotation_invalid = 'N' and (quotation_serial like @quotation_serial or quotation_name like @quotation_name) order by quotation_serial desc ", new { quotation_serial = quotation_serial, quotation_name = quotation_name }).ToList(); + + foreach (quotation proj in quotations) + { + optionData item = new optionData(); + + item.id = proj.quotation_serial; + item.text = "(" + proj.quotation_serial + ") " + proj.quotation_name; + + ret.data.Add(item); + } + + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + [Route("projectAddEditDelGet")] + public ActionResult ProjectAddEditDelGet(IFormCollection obj) + { + projectResult ret = new projectResult(); + + 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 method = obj["method"].ToString(); + string project_uid = obj["project_uid"].ToString(); + + string project_isPrm = obj["project_isPrm"].ToString(); + string project_prmSerial = obj["project_prmSerial"].ToString(); + string project_name = obj["project_name"].ToString(); + string project_year = obj["project_year"].ToString(); + string project_month = obj["project_month"].ToString(); + string project_isExec = project_isPrm; + + if (method == "del") { + project newProj = conn.QueryFirstOrDefault("select * from project where project_uid = @project_uid", new { project_uid = project_uid }); + + if (newProj == null) + { + ret.ret = "no"; + ret.err_code = "2001"; + ret.message = "找不到此專案資料!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + conn.Delete(newProj); + ret.ret = "yes"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + if (method == "get") { + project newProj = conn.QueryFirstOrDefault("select * from project where project_uid = @project_uid", new { project_uid = project_uid }); + + if (newProj == null) + { + ret.ret = "no"; + ret.err_code = "2001"; + ret.message = "找不到此專案資料!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + ret.ret = "yes"; + ret.data = newProj; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + if (method == "edit") { + project newProj = conn.QueryFirstOrDefault("select * from project where project_uid = @project_uid", new { project_uid = project_uid }); + + if (newProj == null) { + ret.ret = "no"; + ret.err_code = "2001"; + ret.message = "找不到此專案資料!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + newProj.project_name = project_name; + newProj.project_isPrm = project_isPrm; + newProj.project_year = int.Parse(project_year); + newProj.project_month = int.Parse(project_month); + newProj.project_modifydate = DateTime.Now; + newProj.project_modify_id = token.user_id; + newProj.project_prmSerial = project_prmSerial; + newProj.project_isExec = project_isExec; + + conn.Update(newProj); + ret.ret = "yes"; + ret.data = newProj; + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + if (method == "add") { + project_uid = GlobalClass.CreateRandomCode(12); + + if (project_isPrm == "Y") + { + project findProje = conn.QueryFirstOrDefault("select * from project where project_prmSerial = @project_prmSerial", new { project_prmSerial = project_prmSerial }); + if (findProje != null) + { + ret.ret = "no"; + ret.err_code = "1001"; + ret.message = "此PRM專案已經存在於KOL系統之中!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + } + else { + project findProje = conn.QueryFirstOrDefault("select * from project where project_name = @project_name and project_year = @project_year and project_month = @project_month ", new { project_name = project_name, project_year = project_year, project_month = project_month }); + if (findProje != null) + { + ret.ret = "no"; + ret.err_code = "1002"; + ret.message = "此專案名稱已經存在於KOL系統之中!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + } + + project newProj = new project(); + + newProj.project_uid = project_uid; + newProj.project_name = project_name; + newProj.project_isPrm = project_isPrm; + newProj.project_year = int.Parse(project_year); + newProj.project_month = int.Parse(project_month); + newProj.project_create_id = token.user_id; + newProj.project_modify_id = token.user_id; + newProj.project_prmSerial = project_prmSerial; + newProj.project_isExec = project_isExec; + + conn.Insert(newProj); + ret.ret = "yes"; + ret.data = newProj; + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + [Route("projectList")] + public ActionResult ProjectList(IFormCollection obj) { + projectListResult ret = new projectListResult(); + + 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"); + } + + List projects = conn.Query("select * from project order by project_modifydate desc ").ToList(); + + ret.ret = "yes"; + ret.projectList = projects; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + [Route("kolList")] public ActionResult KolList(IFormCollection obj) { kolListResult ret = new kolListResult(); @@ -581,6 +756,31 @@ namespace Journeys_WantHome.Controllers } + public class prmResult { + public List data = new List(); + } + + public class optionData { + public string id { get; set; } = ""; + public string text { get; set; } = ""; + } + + public class projectResult { + public string ret { get; set; } = "no"; + public string err_code { get; set; } = "0000"; + public string message { get; set; } = ""; + + public project data { get; set; } = new project(); + } + + public class projectListResult { + public string ret { get; set; } = "no"; + public string err_code { get; set; } = "0000"; + public string message { get; set; } = ""; + + public List projectList { get; set; } = new List(); + } + public class kolListResult { public string ret { get; set; } = ""; public string err_code { get; set; } = ""; diff --git a/Models/DbTableClass.cs b/Models/DbTableClass.cs index 8bdf348..bc92057 100644 --- a/Models/DbTableClass.cs +++ b/Models/DbTableClass.cs @@ -8,6 +8,29 @@ using Newtonsoft.Json.Linq; public class DbTableClass { + [Table("quotation")] + public class quotation + { + [JsonIgnore] + [Key] + public int quotation_sn { get; set; } + public string quotation_serial { get; set; } + public string quotation_name { get; set; } + public int quotation_year { get; set; } + public string dept_uid { get; set; } + public int quotation_budget { get; set; } + public string company_uid { get; set; } + public string company_serial { get; set; } + public string quotation_ps { get; set; } + public string quotation_paperfile { get; set; } + public int quotation_version { get; set; } + public string quotation_del { get; set; } + public string quotation_invalid { get; set; } + public string quotation_create_user_uid { get; set; } + public DateTime quotation_createdate { get; set; } + public DateTime quotation_modifydate { get; set; } + } + [Table("project")] public class project { @@ -29,6 +52,8 @@ public class DbTableClass public string project_isExec { get; set; } = "N"; + public string project_reason { 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 e74baa2..52164ac 100644 --- a/Views/Home/ProjectList.cshtml +++ b/Views/Home/ProjectList.cshtml @@ -30,7 +30,7 @@
- +
@@ -44,6 +44,7 @@ 專案名稱 狀態 合作對象 + 資料異動時間 @@ -52,4 +53,84 @@
- \ No newline at end of file + + + +
+ +
\ No newline at end of file diff --git a/Views/Shared/_LooperLayout.cshtml b/Views/Shared/_LooperLayout.cshtml index 617df9e..6516aaa 100644 --- a/Views/Shared/_LooperLayout.cshtml +++ b/Views/Shared/_LooperLayout.cshtml @@ -134,6 +134,10 @@ KOL 清單 + +