diff --git a/AMESCoreStudio.Web/Controllers/KCSController.cs b/AMESCoreStudio.Web/Controllers/KCSController.cs index c60eb324..a0caf4b7 100644 --- a/AMESCoreStudio.Web/Controllers/KCSController.cs +++ b/AMESCoreStudio.Web/Controllers/KCSController.cs @@ -127,5 +127,112 @@ namespace AMESCoreStudio.Web.Controllers #endregion + #region KCS004組件料號序號維護相關 + + public IActionResult KCS004() + { + return View(); + } + + //新增頁面 + public IActionResult KCS004C() + { + return View(); + } + + //修改页面 + [HttpGet] + public async Task KCS004UAsync(string id) + { + var result = await _kcsApi.GetKPLink(id); + + if (result.Count == 0) + { + return View(); + } + return View(result[0]); + } + + public async Task KCS004DAsync(string id) + { + var result = await _kcsApi.DeleteKPLink(id); + return Json(new Result() { success = true, msg = "" }); + } + + //頁面提交,id=0 添加,id>0 修改 + [HttpPost] + public async Task KCS004CSaveAsync(KPLink model) + { + if (ModelState.IsValid) + { + IResultModel result; + + result = await _kcsApi.PostKPLink(JsonConvert.SerializeObject(model)); + + + if (result.Success) + { + var _msg = "添加成功!"; + return RedirectToAction("Refresh", "Home", new { msg = _msg }); + } + else + { + if (result.Errors.Count > 0) + { + ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg); + } + else + { + ModelState.AddModelError("error", result.Msg); + } + } + } + return View("KCS004C", model); + } + + public async Task KCS004USaveAsync(KPLink model) + { + if (ModelState.IsValid) + { + IResultModel result; + + result = await _kcsApi.PutKPLink(model.KeyPartSn, JsonConvert.SerializeObject(model)); + + if (result.Success) + { + var _msg = "修改成功!"; + return RedirectToAction("Refresh", "Home", new { msg = _msg }); + } + else + { + if (result.Errors.Count > 0) + { + ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg); + } + else + { + ModelState.AddModelError("error", result.Msg); + } + } + } + return View("PPS004U", model); + } + + [ResponseCache(Duration = 0)] + [HttpGet] + public async Task GetKPLinksAsync(int page = 1, int limit = 10) + { + var result_total = await _kcsApi.GetKPLinks(0, limit); + var result = await _kcsApi.GetKPLinks(page, limit); + + if (result.Count > 0) + { + return Json(new Table() { code = 0, msg = "", data = result, count = result_total.Count }); + } + + return Json(new Table() { count = 0, data = null }); + } + + #endregion } } diff --git a/AMESCoreStudio.Web/HttpApis/AMES/IKCS.cs b/AMESCoreStudio.Web/HttpApis/AMES/IKCS.cs index 4745b76e..3c1ebbaf 100644 --- a/AMESCoreStudio.Web/HttpApis/AMES/IKCS.cs +++ b/AMESCoreStudio.Web/HttpApis/AMES/IKCS.cs @@ -50,5 +50,44 @@ namespace AMESCoreStudio.Web ITask> GetPartMaps(int page = 1, int limit = 10); #endregion + + #region KCS004 組件料號序號維護 + + /// + /// 新增組件料號序號 + /// + /// + [WebApiClient.Attributes.HttpPost("api/KPLinks")] + ITask> PostKPLink([FromBody, RawJsonContent] string model); + + /// + /// 更新組件料號序號 + /// + /// + [WebApiClient.Attributes.HttpPut("api/KPLinks/{id}")] + ITask> PutKPLink(string id, [FromBody, RawJsonContent] string model); + + /// + /// 刪除組件料號序號 + /// + /// + [WebApiClient.Attributes.HttpDelete("api/KPLinks/{id}")] + ITask> DeleteKPLink(string id); + + /// + /// 根據ID獲取指定組件料號序號資料 + /// + /// + [WebApiClient.Attributes.HttpGet("api/KPLinks/{id}")] + ITask> GetKPLink(string id); + + /// + /// 獲取組件料號序號資料 + /// + /// + [WebApiClient.Attributes.HttpGet("api/KPLinks")] + ITask> GetKPLinks(int page = 1, int limit = 10); + + #endregion } } diff --git a/AMESCoreStudio.Web/Views/Home/Framework.cshtml b/AMESCoreStudio.Web/Views/Home/Framework.cshtml index 5efddf7d..5369889d 100644 --- a/AMESCoreStudio.Web/Views/Home/Framework.cshtml +++ b/AMESCoreStudio.Web/Views/Home/Framework.cshtml @@ -220,6 +220,9 @@
  • 序號-料號維護
  • +
  • + 組件料號序號維護 +
  • diff --git a/AMESCoreStudio.Web/Views/KCS/KCS004.cshtml b/AMESCoreStudio.Web/Views/KCS/KCS004.cshtml new file mode 100644 index 00000000..2b212a37 --- /dev/null +++ b/AMESCoreStudio.Web/Views/KCS/KCS004.cshtml @@ -0,0 +1,95 @@ +@{ + ViewData["Title"] = "組件料號序號維護"; + Layout = "~/Views/Shared/_AMESLayout.cshtml"; +} + +
    +
    +
    +
    +
    @ViewBag.Title
    +
    +
    +
    +
    +
    +
    +
    + +@section Scripts{ + +} \ No newline at end of file diff --git a/AMESCoreStudio.Web/Views/KCS/KCS004C.cshtml b/AMESCoreStudio.Web/Views/KCS/KCS004C.cshtml new file mode 100644 index 00000000..e2d719e4 --- /dev/null +++ b/AMESCoreStudio.Web/Views/KCS/KCS004C.cshtml @@ -0,0 +1,58 @@ +@model AMESCoreStudio.WebApi.Models.AMES.KPLink + + +@{ ViewData["Title"] = "KCS004C"; + Layout = "~/Views/Shared/_FormLayout.cshtml"; } + + + + +
    +
    +
    +
    + +
    + + + +
    +
    + + + +
    +
    + + + +
    + @Html.ValidationMessage("error") +
    + +
    + +
    +
    +
    + +@section Scripts { + @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); + await Html.RenderPartialAsync("_FileinputScriptsPartial"); } + + + + +} + diff --git a/AMESCoreStudio.Web/Views/KCS/KCS004U.cshtml b/AMESCoreStudio.Web/Views/KCS/KCS004U.cshtml new file mode 100644 index 00000000..efc633f3 --- /dev/null +++ b/AMESCoreStudio.Web/Views/KCS/KCS004U.cshtml @@ -0,0 +1,58 @@ +@model AMESCoreStudio.WebApi.Models.AMES.KPLink + + +@{ ViewData["Title"] = "KCS004U"; + Layout = "~/Views/Shared/_FormLayout.cshtml"; } + + + + +
    +
    +
    +
    + +
    + + + +
    +
    + + + +
    +
    + + + +
    + @Html.ValidationMessage("error") +
    + +
    + +
    +
    +
    + +@section Scripts { + @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); + await Html.RenderPartialAsync("_FileinputScriptsPartial"); } + + + + +} + diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/KPLinksController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/KPLinksController.cs new file mode 100644 index 00000000..9e5706d4 --- /dev/null +++ b/AMESCoreStudio.WebApi/Controllers/AMES/KPLinksController.cs @@ -0,0 +1,190 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using AMESCoreStudio.WebApi; +using AMESCoreStudio.WebApi.Models.AMES; +using AMESCoreStudio.CommonTools.Result; + +namespace AMESCoreStudio.WebApi.Controllers.AMES +{ + /// + /// + /// + [Route("api/[controller]")] + [ApiController] + public class KPLinksController : ControllerBase + { + private readonly AMESContext _context; + + /// + /// + /// + /// + public KPLinksController(AMESContext context) + { + _context = context; + } + + /// + /// + /// + /// + // GET: api/KPLinks + [HttpGet] + public async Task>> GetKPLink(int page = 1, int limit = 10) + { + IQueryable q = _context.KPLinks; + if (page > 0) + { + q = q.OrderBy(p => p.KeyPartNo + p.KeyPartSn).Skip((page - 1) * limit).Take(limit); + } + else + { + q = q.OrderBy(p => p.KeyPartNo + p.KeyPartSn); + } + + var kpLink = await q.ToListAsync(); + return kpLink; + } + + /// + /// + /// + /// + /// + // GET: api/KPLinks/5 + [HttpGet("{id}")] + public async Task>> GetKPLink(string id) + { + IQueryable q = _context.KPLinks; + q = q.Where(p => p.KeyPartSn.Equals(id)); + + var kpLink = await q.ToListAsync(); + + if (kpLink == null) + { + return NotFound(); + } + + return kpLink; + } + + /// + /// + /// + /// + /// + /// + // PUT: api/KPLinks/5 + // To protect from overposting attacks, enable the specific properties you want to bind to, for + // more details, see https://go.microsoft.com/fwlink/?linkid=2123754. + [HttpPut("{id}")] + public async Task> PutKPLink(string id, [FromBody]KPLink kPLink) + { + ResultModel result = new ResultModel(); + + if (id != kPLink.KeyPartSn) + { + result.Success = false; + result.Msg = "序號錯誤"; + return result; + } + + _context.Entry(kPLink).State = EntityState.Modified; + + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!KPLinkExists(id)) + { + result.Success = false; + result.Msg = "序號不存在"; + return result; + } + else + { + throw; + } + } + + result.Success = true; + result.Msg = "OK"; + return result; + } + + /// + /// + /// + /// + /// + // POST: api/KPLinks + // To protect from overposting attacks, enable the specific properties you want to bind to, for + // more details, see https://go.microsoft.com/fwlink/?linkid=2123754. + [HttpPost] + public async Task> PostKPLink([FromBody]KPLink kPLink) + { + ResultModel result = new ResultModel(); + _context.KPLinks.Add(kPLink); + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateException) + { + if (KPLinkExists(kPLink.KeyPartSn)) + { + result.Success = false; + result.Msg = "序號重複"; + return result; + } + else + { + throw; + } + } + + result.Success = true; + result.Msg = "OK"; + return result; + } + + /// + /// + /// + /// + /// + // DELETE: api/KPLinks/5 + [HttpDelete("{id}")] + public async Task> DeleteKPLink(string id) + { + ResultModel result = new ResultModel(); + + var kPLink = await _context.KPLinks.FindAsync(id); + if (kPLink == null) + { + result.Success = false; + result.Msg = "序號不存在"; + return result; + } + + _context.KPLinks.Remove(kPLink); + await _context.SaveChangesAsync(); + + result.Success = true; + result.Msg = "OK"; + return result; + } + + private bool KPLinkExists(string id) + { + return _context.KPLinks.Any(e => e.KeyPartSn == id); + } + } +} diff --git a/AMESCoreStudio.WebApi/Models/AMES/KPLink.cs b/AMESCoreStudio.WebApi/Models/AMES/KPLink.cs new file mode 100644 index 00000000..4558f33d --- /dev/null +++ b/AMESCoreStudio.WebApi/Models/AMES/KPLink.cs @@ -0,0 +1,83 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; + +namespace AMESCoreStudio.WebApi.Models.AMES +{ + /// + /// 組件料號序號資料表 + /// + [Table("KP_LINK", Schema = "JHAMES")] + public class KPLink + { + /// + /// 組件料號 + /// + + [Column("KEY_PART_NO")] + [Required(ErrorMessage = "{0},不能空白")] + [Display(Name = "組件料號")] + [StringLength(20, ErrorMessage = "{0},不能大于{1}")] + [DataMember] + public string KeyPartNo { get; set; } + + + /// + /// 組件序號 + /// + [Key] + [Column("KEY_PART_SN")] + [DataMember] + [Required(ErrorMessage = "{0},不能空白")] + [Display(Name = "組件序號")] + [StringLength(40, ErrorMessage = "{0},不能大于{1}")] + public string KeyPartSn { get; set; } + + /// + /// 訂單NO + /// + [Column("PO_NO")] + [DataMember] + [Required(ErrorMessage = "{0},不能空白")] + [Display(Name = "訂單NO")] + [StringLength(20, ErrorMessage = "{0},不能大于{1}")] + public string PoNo { get; set; } + + /// + /// 建立者 + /// + [Column("CREATE_USERID")] + [DataMember] + [Required(ErrorMessage = "{0},不能空白")] + [Display(Name = "建立者")] + public decimal CreateUserID { get; set; } = 0; + + /// + /// 建立時間 + /// + [Column("CREATE_DATE")] + [DataMember] + [Required(ErrorMessage = "{0},不能空白")] + [Display(Name = "建立時間")] + public DateTime CreateDate { get; set; } = DateTime.Now; + + /// + /// 更新者 + /// + [Column("UPDATE_USERID")] + [DataMember] + [Required(ErrorMessage = "{0},不能空白")] + [Display(Name = "建立者")] + public decimal UpdateUserID { get; set; } = 0; + + /// + /// 修改時間 + /// + [Column("UPDATE_DATE")] + [DataMember] + [Required(ErrorMessage = "{0},不能空白")] + [Display(Name = "修改時間")] + public DateTime UpdateDate { get; set; } = DateTime.Now; + } +} diff --git a/AMESCoreStudio.WebApi/Models/AMESContext.cs b/AMESCoreStudio.WebApi/Models/AMESContext.cs index 733fa40d..8d1d6da7 100644 --- a/AMESCoreStudio.WebApi/Models/AMESContext.cs +++ b/AMESCoreStudio.WebApi/Models/AMESContext.cs @@ -303,6 +303,11 @@ namespace AMESCoreStudio.WebApi /// 序號料號資料 /// public DbSet PartMaps { get; set; } + + /// + /// 組件料號序號資料 + /// + public DbSet KPLinks { get; set; } } }