diff --git a/Controllers/ApiController.cs b/Controllers/ApiController.cs new file mode 100644 index 00000000..dd2f5b96 --- /dev/null +++ b/Controllers/ApiController.cs @@ -0,0 +1,195 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using static DbTableClass; +using static resultClass; +using System.Data.SqlClient; +using Dapper.Contrib.Extensions; +using Dapper; +using Newtonsoft.Json; + +namespace QuotationMaker.Controllers +{ + [Route("Api")] + public class ApiController : ControllerBase + { + private readonly IHttpContextAccessor _httpContextAccessor; + + DbConn dbConn = new DbConn(); + SqlConnection conn = new SqlConnection(GlobalClass.appsettings("ConnectionStrings:SQLConnectionString")); + SqlConnection elabConn = new SqlConnection(GlobalClass.appsettings("ConnectionStrings:ElabConnectionString")); + + public ApiController(IHttpContextAccessor httpContextAccessor) + { + this._httpContextAccessor = httpContextAccessor; + + + } + + [Route("addEditDelGetCompany")] + public ActionResult AddEditDelSubItem(IFormCollection obj) + { + companyListResult ret = new companyListResult(); + + 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 company_uid = obj["company_uid"].ToString(); + string company_name = obj["company_name"].ToString(); + string company_serialNo = obj["company_serialNo"].ToString(); + string company_address = obj["company_address"].ToString(); + string company_tel = obj["company_tel"].ToString(); + string company_fax = obj["company_fax"].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 (method == "add") + { + if (company_name.Trim() == "") + { + ret.ret = "no"; + ret.err_code = "0003"; + ret.message = "沒有company_name!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + company_uid = GlobalClass.CreateRandomCode(24); + company newItem = new company(); + newItem.company_name = company_name; + newItem.company_uid = company_uid; + newItem.company_serialNo = company_serialNo; + newItem.company_address = company_address; + newItem.company_tel = company_tel; + newItem.company_fax = company_fax; + + newItem.company_lastmodify_uid = token.user_uid; + newItem.company_createdate = DateTime.Now; + newItem.company_modifydate = DateTime.Now; + + conn.Insert(newItem); + ret.companys.Add(newItem); + ret.ret = "yes"; + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + if (company_uid.Trim() == "") + { + ret.ret = "no"; + ret.err_code = "0002"; + ret.message = "沒有company_uid!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + + + company editItem = conn.QueryFirstOrDefault("select * from company where company_isdel = 'N' and company_uid = @company_uid ", new { company_uid = company_uid }); + + if (editItem == null) + { + ret.ret = "no"; + ret.err_code = "0004"; + ret.message = "沒有company_uid此筆資料!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + if (method == "edit") + { + + + if (company_name.Trim() == "") + { + ret.ret = "no"; + ret.err_code = "0002"; + ret.message = "沒有company_name!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + editItem.company_name = company_name; + + editItem.company_serialNo = company_serialNo; + editItem.company_address = company_address; + editItem.company_tel = company_tel; + editItem.company_fax = company_fax; + + editItem.company_lastmodify_uid = token.user_uid; + editItem.company_modifydate = DateTime.Now; + + conn.Update(editItem); + ret.companys.Add(editItem); + ret.ret = "yes"; + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + if (method == "get") + { + ret.companys.Add(editItem); + ret.ret = "yes"; + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + if (method == "del") + { + editItem.company_isdel = "Y"; + editItem.company_lastmodify_uid = token.user_uid; + editItem.company_modifydate = DateTime.Now; + + conn.Execute("update contactPerson set contactPerson_isdel = 'Y' where company_uid = @company_uid ", new { company_uid = company_uid }); + + conn.Update(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("companyList")] + public ActionResult AuthSubItemList(IFormCollection obj) + { + companyListResult ret = new companyListResult(); + + 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"); + } + + + + ret.companys = conn.Query("select * from company where company_isdel = 'N' ").ToList(); + ret.ret = "yes"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + } +} diff --git a/Controllers/AuthApiController.cs b/Controllers/AuthApiController.cs index d5c3bfe8..ed6f0ae6 100644 --- a/Controllers/AuthApiController.cs +++ b/Controllers/AuthApiController.cs @@ -21,10 +21,10 @@ namespace QuotationMaker.Controllers public AuthApiController(IHttpContextAccessor httpContextAccessor) { this._httpContextAccessor = httpContextAccessor; - - } + + [Route("addEditDelGetSubItem")] public ActionResult AddEditDelSubItem(IFormCollection obj) { authSubItemResult ret = new authSubItemResult(); diff --git a/Controllers/HomeController.cs b/Controllers/HomeController.cs index 9f94bdea..24dc0aae 100644 --- a/Controllers/HomeController.cs +++ b/Controllers/HomeController.cs @@ -22,6 +22,18 @@ namespace QuotationMaker.Controllers return View(); } + public IActionResult CompanyList() + { + if (checkToken() == false) + { + HttpContext.Response.Cookies.Delete("token_key"); + return Redirect("~/Home/Login"); + } + + + return View(); + } + public IActionResult RateList() { if (checkToken() == false) diff --git a/Modals/DbTableClass.cs b/Modals/DbTableClass.cs index 62748cc7..0fdae608 100644 --- a/Modals/DbTableClass.cs +++ b/Modals/DbTableClass.cs @@ -8,6 +8,44 @@ using Newtonsoft.Json.Linq; public class DbTableClass { + [Table("contactPerson")] + public class contactPerson + { + [JsonIgnore] + [Key] + public int contactPerson_sn { get; set; } + public string company_uid { get; set; } = ""; + public string contactPerson_uid { get; set; } = ""; + public string contactPerson_name { get; set; } = ""; + public string contactPerson_email { get; set; } = ""; + public string contactPerson_tel { get; set; } = ""; + public string contactPerson_isdel { get; set; } = "N"; + public DateTime contactPerson_createdate { get; set; } = DateTime.Now; + public DateTime contactPerson_modifydate { get; set; } = DateTime.Now; + public string contactPerson_lastmodify_uid { get; set; } = ""; + } + + + + [Table("company")] + public class company + { + [JsonIgnore] + [Key] + public int company_sn { get; set; } + public string company_uid { get; set; } = ""; + public string company_name { get; set; } = ""; + public string company_serialNo { get; set; } = ""; + public string company_address { get; set; } = ""; + public string company_tel { get; set; } = ""; + public string company_fax { get; set; } = ""; + public string company_isdel { get; set; } = "N"; + public DateTime company_createdate { get; set; } = DateTime.Now; + public DateTime company_modifydate { get; set; } = DateTime.Now; + public string company_lastmodify_uid { get; set; } = ""; + } + + [Table("subItem")] public class subItem { diff --git a/Modals/resultClass.cs b/Modals/resultClass.cs index 77f413ff..422f7fa2 100644 --- a/Modals/resultClass.cs +++ b/Modals/resultClass.cs @@ -4,6 +4,21 @@ using Dapper; using static DbTableClass; public class resultClass { + public class contactPersonListResult + { + public string ret = "no"; + public string err_code = "0000"; + public string message = ""; + public List contactPersons = new List(); + } + + public class companyListResult + { + public string ret = "no"; + public string err_code = "0000"; + public string message = ""; + public List companys = new List(); + } public class authMainItemResult { public string ret = "no"; diff --git a/Views/Home/CompanyList.cshtml b/Views/Home/CompanyList.cshtml new file mode 100644 index 00000000..1201d2fd --- /dev/null +++ b/Views/Home/CompanyList.cshtml @@ -0,0 +1,116 @@ +@* + 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 363a507a..f608262b 100644 --- a/Views/Shared/_LooperLayout.cshtml +++ b/Views/Shared/_LooperLayout.cshtml @@ -132,6 +132,10 @@ 報價單清單 + +