From 3ad506074f9d467bc2ba2904d69d9209c43b7787 Mon Sep 17 00:00:00 2001 From: marvinhong Date: Mon, 22 Nov 2021 20:32:31 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=96=B0=E5=A2=9E=E7=BB=84=E4=BB=B6=E7=B1=BB?= =?UTF-8?q?=E5=88=AB=E7=BB=B4=E6=8A=A4PPS015=202.=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E6=8E=A7=E7=AE=A1=E6=A8=A1=E7=BB=84KCS=203.?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=BA=8F=E5=8F=B7=E6=96=99=E5=8F=B7=E7=BB=B4?= =?UTF-8?q?=E6=8A=A4KCS002?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/KCSController.cs | 131 ++++++++++++ .../Controllers/PPSController.cs | 106 ++++++++++ AMESCoreStudio.Web/HttpApis/AMES/IKCS.cs | 54 +++++ AMESCoreStudio.Web/HttpApis/AMES/IPPS.cs | 39 ++++ .../Views/Home/Framework.cshtml | 13 ++ AMESCoreStudio.Web/Views/KCS/KCS002.cshtml | 90 +++++++++ AMESCoreStudio.Web/Views/KCS/KCS002C.cshtml | 53 +++++ AMESCoreStudio.Web/Views/KCS/KCS002U.cshtml | 53 +++++ AMESCoreStudio.Web/Views/PPS/PPS014U.cshtml | 2 +- AMESCoreStudio.Web/Views/PPS/PPS015.cshtml | 90 +++++++++ AMESCoreStudio.Web/Views/PPS/PPS015C.cshtml | 53 +++++ AMESCoreStudio.Web/Views/PPS/PPS015U.cshtml | 53 +++++ .../Controllers/AMES/PartMapsController.cs | 191 ++++++++++++++++++ .../Controllers/AMES/RepairItemsController.cs | 189 +++++++++++++++++ AMESCoreStudio.WebApi/Models/AMES/PartMap.cs | 72 +++++++ .../Models/AMES/RepairItem.cs | 37 ++++ AMESCoreStudio.WebApi/Models/AMESContext.cs | 11 + AMESCoreStudio.WebApi/appsettings.json | 2 +- 18 files changed, 1237 insertions(+), 2 deletions(-) create mode 100644 AMESCoreStudio.Web/Controllers/KCSController.cs create mode 100644 AMESCoreStudio.Web/HttpApis/AMES/IKCS.cs create mode 100644 AMESCoreStudio.Web/Views/KCS/KCS002.cshtml create mode 100644 AMESCoreStudio.Web/Views/KCS/KCS002C.cshtml create mode 100644 AMESCoreStudio.Web/Views/KCS/KCS002U.cshtml create mode 100644 AMESCoreStudio.Web/Views/PPS/PPS015.cshtml create mode 100644 AMESCoreStudio.Web/Views/PPS/PPS015C.cshtml create mode 100644 AMESCoreStudio.Web/Views/PPS/PPS015U.cshtml create mode 100644 AMESCoreStudio.WebApi/Controllers/AMES/PartMapsController.cs create mode 100644 AMESCoreStudio.WebApi/Controllers/AMES/RepairItemsController.cs create mode 100644 AMESCoreStudio.WebApi/Models/AMES/PartMap.cs create mode 100644 AMESCoreStudio.WebApi/Models/AMES/RepairItem.cs diff --git a/AMESCoreStudio.Web/Controllers/KCSController.cs b/AMESCoreStudio.Web/Controllers/KCSController.cs new file mode 100644 index 00000000..c60eb324 --- /dev/null +++ b/AMESCoreStudio.Web/Controllers/KCSController.cs @@ -0,0 +1,131 @@ +using Microsoft.AspNetCore.Mvc; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using AMESCoreStudio.Web.Models; +using Newtonsoft.Json; +using AMESCoreStudio.WebApi.Models.AMES; +using AMESCoreStudio.CommonTools.Result; + +namespace AMESCoreStudio.Web.Controllers +{ + public class KCSController : Controller + { + private readonly ILogger _logger; + public readonly IKCS _kcsApi; + + public KCSController(ILogger logger, IKCS kcsApi) + { + _logger = logger; + _kcsApi = kcsApi; + } + + #region KCS002序號料號維護相關 + + public IActionResult KCS002() + { + return View(); + } + + //新增頁面 + public IActionResult KCS002C() + { + return View(); + } + + //修改页面 + [HttpGet] + public async Task KCS002UAsync(string id) + { + var result = await _kcsApi.GetPartMap(id); + + if (result.Count == 0) + { + return View(); + } + return View(result[0]); + } + + public async Task KCS002DAsync(string id) + { + var result = await _kcsApi.DeletePartMap(id); + return Json(new Result() { success = true, msg = "" }); + } + + //頁面提交,id=0 添加,id>0 修改 + [HttpPost] + public async Task KCS002CSaveAsync(PartMap model) + { + if (ModelState.IsValid) + { + IResultModel result; + + result = await _kcsApi.PostPartMap(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("KCS002C", model); + } + + public async Task KCS002USaveAsync(PartMap model) + { + if (ModelState.IsValid) + { + IResultModel result; + + result = await _kcsApi.PutPartMap(model.CorpSN, 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("PPS002U", model); + } + + [ResponseCache(Duration = 0)] + [HttpGet] + public async Task GetPartMapsAsync(int page = 1, int limit = 10) + { + var result_total = await _kcsApi.GetPartMaps(0, limit); + var result = await _kcsApi.GetPartMaps(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/Controllers/PPSController.cs b/AMESCoreStudio.Web/Controllers/PPSController.cs index 211460b6..4bdcf0f5 100644 --- a/AMESCoreStudio.Web/Controllers/PPSController.cs +++ b/AMESCoreStudio.Web/Controllers/PPSController.cs @@ -1771,6 +1771,112 @@ namespace AMESCoreStudio.Web.Controllers #endregion + #region PPS015組件類別維護相關 + + public IActionResult PPS015() + { + return View(); + } + + //新增頁面 + public IActionResult PPS015C() + { + return View(); + } + + //修改页面 + [HttpGet] + public async Task PPS015UAsync(string id) + { + var result = await _ppsApi.GetRepairItem(id); + + if (result.Count == 0) + { + return View(); + } + return View(result[0]); + } + + public async Task PPS015DAsync(string id) + { + var result = await _ppsApi.DeleteRepairItem(id); + return Json(new Result() { success = true, msg = "" }); + } + + //頁面提交,id=0 添加,id>0 修改 + [HttpPost] + public async Task PPS015CSaveAsync(RepairItem model) + { + if (ModelState.IsValid) + { + IResultModel result; + + result = await _ppsApi.PostRepairItem(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("PPS015C", model); + } + + public async Task PPS015USaveAsync(RepairItem model) + { + if (ModelState.IsValid) + { + IResultModel result; + + result = await _ppsApi.PutRepairItem(model.ItemNo, 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("PPS015U", model); + } + + [ResponseCache(Duration = 0)] + [HttpGet] + public async Task GetRepairItemsAsync(int page = 1, int limit = 10) + { + var result_total = await _ppsApi.GetRepairItems(0, limit); + var result = await _ppsApi.GetRepairItems(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 #region PPS016 問題類別維護相關 diff --git a/AMESCoreStudio.Web/HttpApis/AMES/IKCS.cs b/AMESCoreStudio.Web/HttpApis/AMES/IKCS.cs new file mode 100644 index 00000000..4745b76e --- /dev/null +++ b/AMESCoreStudio.Web/HttpApis/AMES/IKCS.cs @@ -0,0 +1,54 @@ +using System.Collections.Generic; +using WebApiClient; +using WebApiClient.Attributes; +using AMESCoreStudio.WebApi; +using Microsoft.AspNetCore.Mvc; +using AMESCoreStudio.WebApi.Models.AMES; +using AMESCoreStudio.WebApi.Models.BAS; +using AMESCoreStudio.CommonTools.Result; + +namespace AMESCoreStudio.Web +{ + [JsonReturn] + public interface IKCS:IHttpApi + { + #region KCS002 序號料號維護 + + /// + /// 新增序號料號 + /// + /// + [WebApiClient.Attributes.HttpPost("api/PartMaps")] + ITask> PostPartMap([FromBody, RawJsonContent] string model); + + /// + /// 更新序號料號 + /// + /// + [WebApiClient.Attributes.HttpPut("api/PartMaps/{id}")] + ITask> PutPartMap(string id, [FromBody, RawJsonContent] string model); + + /// + /// 刪除序號料號 + /// + /// + [WebApiClient.Attributes.HttpDelete("api/PartMaps/{id}")] + ITask> DeletePartMap(string id); + + /// + /// 根據ID獲取指定序號料號資料 + /// + /// + [WebApiClient.Attributes.HttpGet("api/PartMaps/{id}")] + ITask> GetPartMap(string id); + + /// + /// 獲取序號料號資料 + /// + /// + [WebApiClient.Attributes.HttpGet("api/PartMaps")] + ITask> GetPartMaps(int page = 1, int limit = 10); + + #endregion + } +} diff --git a/AMESCoreStudio.Web/HttpApis/AMES/IPPS.cs b/AMESCoreStudio.Web/HttpApis/AMES/IPPS.cs index 6e8144b2..4ff35eac 100644 --- a/AMESCoreStudio.Web/HttpApis/AMES/IPPS.cs +++ b/AMESCoreStudio.Web/HttpApis/AMES/IPPS.cs @@ -561,6 +561,45 @@ namespace AMESCoreStudio.Web #endregion + #region PPS015 組件類別維護 + + /// + /// 新增組件類別 + /// + /// + [WebApiClient.Attributes.HttpPost("api/RepairItems")] + ITask> PostRepairItem([FromBody, RawJsonContent] string model); + + /// + /// 更新組件類別 + /// + /// + [WebApiClient.Attributes.HttpPut("api/RepairItems/{id}")] + ITask> PutRepairItem(string id, [FromBody, RawJsonContent] string model); + + /// + /// 刪除組件類別 + /// + /// + [WebApiClient.Attributes.HttpDelete("api/RepairItems/{id}")] + ITask> DeleteRepairItem(string id); + + /// + /// 根據ID獲取指定組件類別資料 + /// + /// + [WebApiClient.Attributes.HttpGet("api/RepairItems/{id}")] + ITask> GetRepairItem(string id); + + /// + /// 獲取組件類別資料 + /// + /// + [WebApiClient.Attributes.HttpGet("api/RepairItems")] + ITask> GetRepairItems(int page = 1, int limit = 10); + + #endregion + #region PPS016 問題類別維護 /// diff --git a/AMESCoreStudio.Web/Views/Home/Framework.cshtml b/AMESCoreStudio.Web/Views/Home/Framework.cshtml index fb51c365..5efddf7d 100644 --- a/AMESCoreStudio.Web/Views/Home/Framework.cshtml +++ b/AMESCoreStudio.Web/Views/Home/Framework.cshtml @@ -204,11 +204,24 @@
  • 維修方式維護
  • +
  • + 組件類別維護 +
  • 問題類別維護
  • +
  • + + 組件控管模組 + + +
  • 製程控管模組 diff --git a/AMESCoreStudio.Web/Views/KCS/KCS002.cshtml b/AMESCoreStudio.Web/Views/KCS/KCS002.cshtml new file mode 100644 index 00000000..ce3f32f0 --- /dev/null +++ b/AMESCoreStudio.Web/Views/KCS/KCS002.cshtml @@ -0,0 +1,90 @@ +@{ + ViewData["Title"] = "序號料號維護"; + Layout = "~/Views/Shared/_AMESLayout.cshtml"; +} + +
    +
    +
    +
    +
    @ViewBag.Title
    +
    +
    +
    +
    +
    +
    +
    + +@section Scripts{ + +} \ No newline at end of file diff --git a/AMESCoreStudio.Web/Views/KCS/KCS002C.cshtml b/AMESCoreStudio.Web/Views/KCS/KCS002C.cshtml new file mode 100644 index 00000000..47529712 --- /dev/null +++ b/AMESCoreStudio.Web/Views/KCS/KCS002C.cshtml @@ -0,0 +1,53 @@ +@model AMESCoreStudio.WebApi.Models.AMES.PartMap + + +@{ ViewData["Title"] = "KCS002C"; + 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/KCS002U.cshtml b/AMESCoreStudio.Web/Views/KCS/KCS002U.cshtml new file mode 100644 index 00000000..a62f4242 --- /dev/null +++ b/AMESCoreStudio.Web/Views/KCS/KCS002U.cshtml @@ -0,0 +1,53 @@ +@model AMESCoreStudio.WebApi.Models.AMES.PartMap + + +@{ ViewData["Title"] = "KCS002U"; + Layout = "~/Views/Shared/_FormLayout.cshtml"; } + + + + +
    +
    +
    +
    + +
    + + + +
    +
    + + + +
    + @Html.ValidationMessage("error") +
    + +
    + +
    +
    +
    + +@section Scripts { + @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); + await Html.RenderPartialAsync("_FileinputScriptsPartial"); } + + + + +} + diff --git a/AMESCoreStudio.Web/Views/PPS/PPS014U.cshtml b/AMESCoreStudio.Web/Views/PPS/PPS014U.cshtml index 704a2055..ea0a0456 100644 --- a/AMESCoreStudio.Web/Views/PPS/PPS014U.cshtml +++ b/AMESCoreStudio.Web/Views/PPS/PPS014U.cshtml @@ -18,7 +18,7 @@
    - +
    diff --git a/AMESCoreStudio.Web/Views/PPS/PPS015.cshtml b/AMESCoreStudio.Web/Views/PPS/PPS015.cshtml new file mode 100644 index 00000000..7e5a9158 --- /dev/null +++ b/AMESCoreStudio.Web/Views/PPS/PPS015.cshtml @@ -0,0 +1,90 @@ +@{ + ViewData["Title"] = "組件類別維護"; + Layout = "~/Views/Shared/_AMESLayout.cshtml"; +} + +
    +
    +
    +
    +
    @ViewBag.Title
    +
    +
    +
    +
    +
    +
    +
    + +@section Scripts{ + +} \ No newline at end of file diff --git a/AMESCoreStudio.Web/Views/PPS/PPS015C.cshtml b/AMESCoreStudio.Web/Views/PPS/PPS015C.cshtml new file mode 100644 index 00000000..2df2b7d8 --- /dev/null +++ b/AMESCoreStudio.Web/Views/PPS/PPS015C.cshtml @@ -0,0 +1,53 @@ +@model AMESCoreStudio.WebApi.Models.AMES.RepairItem + + +@{ ViewData["Title"] = "PPS015C"; + Layout = "~/Views/Shared/_FormLayout.cshtml"; } + + + + +
    +
    +
    +
    + +
    + + + +
    +
    + + + +
    + @Html.ValidationMessage("error") +
    + +
    + +
    +
    +
    + +@section Scripts { + @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); + await Html.RenderPartialAsync("_FileinputScriptsPartial"); } + + + + +} + diff --git a/AMESCoreStudio.Web/Views/PPS/PPS015U.cshtml b/AMESCoreStudio.Web/Views/PPS/PPS015U.cshtml new file mode 100644 index 00000000..0f0e1b0f --- /dev/null +++ b/AMESCoreStudio.Web/Views/PPS/PPS015U.cshtml @@ -0,0 +1,53 @@ +@model AMESCoreStudio.WebApi.Models.AMES.RepairItem + + +@{ ViewData["Title"] = "PPS015U"; + 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/PartMapsController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/PartMapsController.cs new file mode 100644 index 00000000..fd541deb --- /dev/null +++ b/AMESCoreStudio.WebApi/Controllers/AMES/PartMapsController.cs @@ -0,0 +1,191 @@ +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 PartMapsController : ControllerBase + { + private readonly AMESContext _context; + + /// + /// + /// + /// + public PartMapsController(AMESContext context) + { + _context = context; + } + + /// + /// + /// + /// + // GET: api/PartMaps + [HttpGet] + public async Task>> GetPartMap(int page = 1, int limit = 10) + { + IQueryable q = _context.PartMaps; + if (page > 0) + { + q = q.OrderBy(p => p.CorpSN).Skip((page - 1) * limit).Take(limit); + } + else + { + q = q.OrderBy(p => p.CorpSN); + } + + var partMap = await q.ToListAsync(); + return partMap; + } + + /// + /// + /// + /// + /// + // GET: api/PartMaps/5 + [HttpGet("{id}")] + public async Task>> GetPartMap(string id) + { + IQueryable q = _context.PartMaps; + q = q.Where(p => p.CorpSN == id); + + var partMap = await q.ToListAsync(); + + if (partMap == null) + { + return NotFound(); + } + + return partMap; + } + + /// + /// + /// + /// + /// + /// + // PUT: api/PartMaps/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> PutPartMap(string id, [FromBody] PartMap partMap) + { + ResultModel result = new ResultModel(); + + if (id != partMap.CorpSN) + { + result.Success = false; + result.Msg = "序號錯誤"; + return result; + } + + _context.Entry(partMap).State = EntityState.Modified; + + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!PartMapExists(id)) + { + result.Success = false; + result.Msg = "序號不存在"; + return result; + } + else + { + throw; + } + } + + result.Success = true; + result.Msg = "OK"; + return result; + } + + /// + /// + /// + /// + /// + // POST: api/PartMaps + // 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> PostPartMap([FromBody]PartMap partMap) + { + ResultModel result = new ResultModel(); + + _context.PartMaps.Add(partMap); + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateException) + { + if (PartMapExists(partMap.CorpSN)) + { + result.Success = false; + result.Msg = "序號重複"; + return result; + } + else + { + throw; + } + } + + result.Success = true; + result.Msg = "OK"; + return result; + } + + /// + /// + /// + /// + /// + // DELETE: api/PartMaps/5 + [HttpDelete("{id}")] + public async Task> DeletePartMap(string id) + { + ResultModel result = new ResultModel(); + + var partMap = await _context.PartMaps.FindAsync(id); + if (partMap == null) + { + result.Success = false; + result.Msg = "序號不存在"; + return result; + } + + _context.PartMaps.Remove(partMap); + await _context.SaveChangesAsync(); + + result.Success = true; + result.Msg = "OK"; + return result; + } + + private bool PartMapExists(string id) + { + return _context.PartMaps.Any(e => e.CorpSN == id); + } + } +} diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/RepairItemsController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/RepairItemsController.cs new file mode 100644 index 00000000..ff0bc35b --- /dev/null +++ b/AMESCoreStudio.WebApi/Controllers/AMES/RepairItemsController.cs @@ -0,0 +1,189 @@ +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 RepairItemsController : ControllerBase + { + private readonly AMESContext _context; + + /// + /// + /// + /// + public RepairItemsController(AMESContext context) + { + _context = context; + } + + /// + /// + /// + /// + // GET: api/RepairItems + [HttpGet] + public async Task>> GetRepairItem(int page = 1, int limit = 10) + { + IQueryable q = _context.RepairItems; + if (page > 0) + { + q = q.OrderBy(p => p.ItemNo).Skip((page - 1) * limit).Take(limit); + } + else + { + q = q.OrderBy(p => p.ItemNo); + } + + var repairItem = await q.ToListAsync(); + return repairItem; + } + + /// + /// + /// + /// + /// + // GET: api/RepairItems/5 + [HttpGet("{id}")] + public async Task>> GetRepairItem(string id) + { + IQueryable q = _context.RepairItems; + q = q.Where(p => p.ItemNo.Equals(id)); + + var repairItem = await q.ToListAsync(); + + if (repairItem == null) + { + return NotFound(); + } + + return repairItem; + } + + /// + /// + /// + /// + /// + /// + // PUT: api/RepairItems/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> PutRepairItem(string id, [FromBody] RepairItem repairItem) + { + ResultModel result = new ResultModel(); + + if (id != repairItem.ItemNo) + { + result.Success = false; + result.Msg = "組件類別代碼錯誤"; + return result; + } + + _context.Entry(repairItem).State = EntityState.Modified; + + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!RepairItemExists(id)) + { + result.Success = false; + result.Msg = "組件類別代碼不存在"; + return result; + } + else + { + throw; + } + } + + result.Success = true; + result.Msg = "OK"; + return result; + } + + /// + /// + /// + /// + /// + // POST: api/RepairItems + // 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> PostRepairItem([FromBody] RepairItem repairItem) + { + ResultModel result = new ResultModel(); + _context.RepairItems.Add(repairItem); + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateException) + { + if (RepairItemExists(repairItem.ItemNo)) + { + result.Success = false; + result.Msg = "組件類別代碼重複"; + return result; + } + else + { + throw; + } + } + + result.Success = true; + result.Msg = "OK"; + return result; + } + + /// + /// + /// + /// + /// + // DELETE: api/RepairItems/5 + [HttpDelete("{id}")] + public async Task> DeleteRepairItem(string id) + { + ResultModel result = new ResultModel(); + var repairItem = await _context.RepairItems.FindAsync(id); + if (repairItem == null) + { + result.Success = false; + result.Msg = "組件類別不存在"; + return result; + } + + _context.RepairItems.Remove(repairItem); + await _context.SaveChangesAsync(); + + result.Success = true; + result.Msg = "OK"; + return result; + } + + private bool RepairItemExists(string id) + { + return _context.RepairItems.Any(e => e.ItemNo == id); + } + } +} diff --git a/AMESCoreStudio.WebApi/Models/AMES/PartMap.cs b/AMESCoreStudio.WebApi/Models/AMES/PartMap.cs new file mode 100644 index 00000000..4512e105 --- /dev/null +++ b/AMESCoreStudio.WebApi/Models/AMES/PartMap.cs @@ -0,0 +1,72 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; + +namespace AMESCoreStudio.WebApi.Models.AMES +{ + /// + /// 序號料號資料表 + /// + [Table("PART_MAP", Schema = "JHAMES")] + public class PartMap + { + /// + /// 序號 + /// + [Key] + [Column("CORP_SN")] + [Required(ErrorMessage = "{0},不能空白")] + [Display(Name = "序號")] + [StringLength(40, ErrorMessage = "{0},不能大于{1}")] + [DataMember] + public string CorpSN { get; set; } + + + /// + /// 料號 + /// + [Column("CORP_PN")] + [DataMember] + [Required(ErrorMessage = "{0},不能空白")] + [Display(Name = "料號")] + [StringLength(30, ErrorMessage = "{0},不能大于{1}")] + public string CorpPN { get; set; } + + /// + /// 序號狀態 + /// + [Column("SN_STATUS")] + [DataMember] + [Required(ErrorMessage = "{0},不能空白")] + [Display(Name = "序號狀態")] + public int SNStatus { get; set; } = 0; + + /// + /// 建立者 + /// + [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_DATE")] + [DataMember] + [Required(ErrorMessage = "{0},不能空白")] + [Display(Name = "修改時間")] + public DateTime UpdateDate { get; set; } = DateTime.Now; + } +} diff --git a/AMESCoreStudio.WebApi/Models/AMES/RepairItem.cs b/AMESCoreStudio.WebApi/Models/AMES/RepairItem.cs new file mode 100644 index 00000000..f92b1562 --- /dev/null +++ b/AMESCoreStudio.WebApi/Models/AMES/RepairItem.cs @@ -0,0 +1,37 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; + +namespace AMESCoreStudio.WebApi.Models.AMES +{ + /// + /// 組件類別資料表 + /// + [Table("REPAIR_ITEM", Schema = "JHAMES")] + [DataContract] + public class RepairItem + { + /// + /// 組件類別代碼 + /// + [Key] + [Column("ITEM_NO")] + [Required(ErrorMessage = "{0},不能空白")] + [Display(Name = "組件類別代碼")] + [StringLength(6, ErrorMessage = "{0},不能大于{1}")] + [DataMember] + public string ItemNo { get; set; } + + + /// + /// 組件類別名稱 + /// + [Column("ITEM_NAME")] + [DataMember] + [Required(ErrorMessage = "{0},不能空白")] + [Display(Name = "組件類別名稱")] + [StringLength(50, ErrorMessage = "{0},不能大于{1}")] + public string ItemName { get; set; } + } +} diff --git a/AMESCoreStudio.WebApi/Models/AMESContext.cs b/AMESCoreStudio.WebApi/Models/AMESContext.cs index 91111c19..733fa40d 100644 --- a/AMESCoreStudio.WebApi/Models/AMESContext.cs +++ b/AMESCoreStudio.WebApi/Models/AMESContext.cs @@ -84,6 +84,7 @@ namespace AMESCoreStudio.WebApi modelBuilder.Entity().HasKey(c => new { c.RuleStationID, c.RuleStatus }); modelBuilder.Entity().HasKey(c => new { c.WipNO, c.StartNO, c.EndNO }); modelBuilder.Entity().HasKey(c => new { c.WipID, c.CreateDate}); + modelBuilder.Entity().HasKey(c => new { c.CorpSN }); modelBuilder.Entity().HasKey(c => new { c.ItemNo, c.LineID }); modelBuilder.Entity().HasOne(r => r.Unit).WithMany().HasForeignKey(r => r.SectionNo).IsRequired(); @@ -292,6 +293,16 @@ namespace AMESCoreStudio.WebApi /// 維修方式資料 ///
  • public DbSet RepairTypes { get; set; } + + /// + /// 組件類別資料 + /// + public DbSet RepairItems { get; set; } + + /// + /// 序號料號資料 + /// + public DbSet PartMaps { get; set; } } } diff --git a/AMESCoreStudio.WebApi/appsettings.json b/AMESCoreStudio.WebApi/appsettings.json index 49af1140..76785a47 100644 --- a/AMESCoreStudio.WebApi/appsettings.json +++ b/AMESCoreStudio.WebApi/appsettings.json @@ -8,7 +8,7 @@ }, "ConnectionStrings": { "AMESContext2": "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.5)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=gdb)));User Id=JHSYS;Password=12345;", - "AMESContext": "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=61.216.68.18)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=cpadb)));User Id=JHSYS;Password=ASYS666;" + "AMESContext": "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=61.216.68.18)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=jhdb)));User Id=JHSYS;Password=ASYS666;" }, "AllowedHosts": "*" }