From 3ccda0b845508affa14f4ad0ea7986900ce4d5f4 Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 15 Mar 2022 11:33:31 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E5=86=8D=E6=AC=A1=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=E6=A2=9D=E7=A2=BC=E9=8E=96=E5=AE=9A=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/PCSController.cs | 194 ++++++++++++++++-- AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs | 9 +- AMESCoreStudio.Web/Views/PCS/PCS014.cshtml | 34 +-- AMESCoreStudio.Web/Views/PCS/PCS015.cshtml | 2 +- .../AMES/BarcodeInfoesController.cs | 8 +- .../Controllers/AMES/BarcodeLockController.cs | 24 +-- .../Models/AMES/BarcodeLock.cs | 3 +- 7 files changed, 221 insertions(+), 53 deletions(-) diff --git a/AMESCoreStudio.Web/Controllers/PCSController.cs b/AMESCoreStudio.Web/Controllers/PCSController.cs index 54abc820..2db0c11c 100644 --- a/AMESCoreStudio.Web/Controllers/PCSController.cs +++ b/AMESCoreStudio.Web/Controllers/PCSController.cs @@ -2359,12 +2359,12 @@ namespace AMESCoreStudio.Web.Controllers result = await _pcsApi.PostBarcodeLock(JsonConvert.SerializeObject(barcodeLock)); if (result.Success) { - _msg += "目前內部序號【" + model.BarCodeNo + "】條碼鎖定成功!
"; + _msg += "目前內部序號【" + item.BarcodeNo + "】條碼鎖定成功!
"; } else { - _msg += "目前內部序號【" + model.BarCodeNo + "】條碼鎖定失敗!
"; + _msg += "目前內部序號【" + item.BarcodeNo + "】條碼鎖定失敗!
"; } } } @@ -2471,33 +2471,199 @@ namespace AMESCoreStudio.Web.Controllers /// /// WipLockID /// - public async Task PCS014(int id) + public IActionResult PCS014(string id) { - - var q = await _pcsApi.GetWipLock(id); - q = q.Where(w => w.UnLockReason == null).ToList(); + PCS014ViewModel model = new PCS014ViewModel(); + model.BarCodeNo = id; //var result = new WipAllViewModel(); //return View(result); - return View(q.FirstOrDefault()); + return View(model); } //頁面提交,id=0 添加,id>0 修改 [HttpPost] - public async Task PCS014Async(WipLock model) + public async Task PCS014Async(PCS014ViewModel model, string select) { IResultModel result; + var _msg = string.Empty; + // 內部條碼 + if (select == "0") + { + if (string.IsNullOrWhiteSpace(model.BarCodeNo)) + { + ModelState.AddModelError("error", "請輸入內部條碼"); + return View(model); + } - result = await _pcsApi.PutWipLock(JsonConvert.SerializeObject(model)); - if (result.Success) + var q = await _pcsApi.GetBarcodeInfoesByNo(model.BarCodeNo); + if (q.Count == 0) + { + ModelState.AddModelError("error", "內部序號【" + model.BarCodeNo + "】,找不到"); + return View(model); + } + + // 判斷是否有鎖定中 + var q1 = await _pcsApi.GetBarcodeLockByBarCodeID(q.FirstOrDefault().BarcodeID); + if (q1.Where(w => w.LockStatus == 0).Count() == 0) + { + ModelState.AddModelError("error", "目前內部序號【" + model.BarCodeNo + "】尚未鎖定"); + return View(model); + } + + BarcodeLock barcodeLock = q1.Where(w => w.LockStatus == 0).FirstOrDefault(); + barcodeLock.LockStatus = 1; + barcodeLock.UnLockReason = model.UnLockReason; + barcodeLock.UnLockUserID = 0; + barcodeLock.UnLockDate = System.DateTime.Now; + var aaa = JsonConvert.SerializeObject(barcodeLock); + result = await _pcsApi.PutBarcodeLock(JsonConvert.SerializeObject(barcodeLock)); + if (result.Success) + { + _msg = "條碼解鎖成功!"; + return RedirectToAction("Refresh", "Home", new { msg = _msg }); + } + else + { + ModelState.AddModelError("error", "條碼解鎖失敗!"); + return View(model); + } + } + + + // 工單號碼 + if (select == "1") { - var _msg = "解鎖成功!"; + if (string.IsNullOrWhiteSpace(model.WipNo)) + { + ModelState.AddModelError("error", "請輸入工單號碼"); + return View(model); + } + + var q = await _pcsApi.GetWipBarcode(model.WipNo); + if (q.Count() == 0) + { + ModelState.AddModelError("error", "工單號碼【" + model.WipNo + "】,找不到內部序號"); + return View(model); + } + + var q1 = await _pcsApi.GetBarcodeInfoesByWipNo(model.WipNo); + + foreach (var item in q1) + { + // 判斷是否有鎖定中 + var q2 = await _pcsApi.GetBarcodeLockByBarCodeID(item.BarcodeID); + if (q2.Where(w => w.LockStatus == 0).Count() == 0) + { + _msg += "目前內部序號【" + item.BarcodeNo + "】尚未鎖定
"; + } + else + { + BarcodeLock barcodeLock = q2.Where(w => w.LockStatus == 0).FirstOrDefault(); + barcodeLock.LockStatus = 1; + barcodeLock.UnLockReason = model.UnLockReason; + barcodeLock.UnLockUserID = 0; + barcodeLock.UnLockDate = System.DateTime.Now; + result = await _pcsApi.PutBarcodeLock(JsonConvert.SerializeObject(barcodeLock)); + if (result.Success) + { + _msg += "目前內部序號【" + item.BarcodeNo + "】條碼解鎖成功!
"; + + } + else + { + _msg += "目前內部序號【" + item.BarcodeNo + "】條碼解鎖失敗!
"; + } + } + } + return RedirectToAction("Refresh", "Home", new { msg = _msg }); } - else + + + // 條碼區間 + if (select == "2") { - ModelState.AddModelError("error", result.Msg); - } + if (string.IsNullOrWhiteSpace(model.BarCodeNoStr) || string.IsNullOrWhiteSpace(model.BarCodeNoEnd)) + { + ModelState.AddModelError("error", "請確定都有輸入條碼區間"); + return View(model); + } + + if (model.BarCodeNoStr.Length != model.BarCodeNoEnd.Length) + { + ModelState.AddModelError("error", "條碼區間起訖長度不相同"); + return View(model); + } + + // 流水碼預設長度 + int NoLength = 4; + if (model.BarCodeNoStr.Length <= NoLength || model.BarCodeNoEnd.Length <= NoLength) + { + ModelState.AddModelError("error", "條碼區間號碼長度不能小於" + NoLength + 1); + return View(model); + } + + if (model.BarCodeNoStr.Substring(0, model.BarCodeNoStr.Length - NoLength) != + model.BarCodeNoEnd.Substring(0, model.BarCodeNoEnd.Length - NoLength)) + { + ModelState.AddModelError("error", "條碼區間前置號碼不一樣"); + return View(model); + } + + + if (!int.TryParse(model.BarCodeNoStr.Substring(model.BarCodeNoStr.Length - NoLength, NoLength), out _) || + !int.TryParse(model.BarCodeNoEnd.Substring(model.BarCodeNoEnd.Length - NoLength, NoLength), out _)) + { + ModelState.AddModelError("error", "條碼區間流水碼格式錯誤"); + return View(model); + } + + var NoStr = int.Parse(model.BarCodeNoStr.Substring(model.BarCodeNoStr.Length - NoLength, NoLength)); + var NoEnd = int.Parse(model.BarCodeNoEnd.Substring(model.BarCodeNoEnd.Length - NoLength, NoLength)); + if (NoStr > NoEnd) + { + ModelState.AddModelError("error", "條碼區間結束流水碼不可以小於條碼區間起始流水碼"); + return View(model); + } + + var BarCode = model.BarCodeNoEnd.Substring(0, model.BarCodeNoEnd.Length - NoLength); + + for (int i = NoStr; i <= NoEnd; i++) + { + var itemBarcodeNo = BarCode + i.ToString().PadLeft(NoLength, '0'); + var q_BarcodeInfo = await _pcsApi.GetBarcodeInfoesByNo(itemBarcodeNo); + + if (q_BarcodeInfo.Count != 0) + { + // 判斷是否有鎖定中 + var q2 = await _pcsApi.GetBarcodeLockByBarCodeID(q_BarcodeInfo.FirstOrDefault().BarcodeID); + if (q2.Where(w => w.LockStatus == 0).Count() == 0) + { + _msg += "目前內部序號【" + itemBarcodeNo + "】尚未鎖定
"; + } + else + { + BarcodeLock barcodeLock = q2.Where(w => w.LockStatus == 0).FirstOrDefault(); + barcodeLock.LockStatus = 1; + barcodeLock.UnLockReason = model.UnLockReason; + barcodeLock.UnLockUserID = 0; + barcodeLock.UnLockDate = System.DateTime.Now; + result = await _pcsApi.PutBarcodeLock(JsonConvert.SerializeObject(barcodeLock)); + if (result.Success) + { + _msg += "目前內部序號【" + itemBarcodeNo + "】條碼解鎖成功!
"; + } + else + { + _msg += "目前內部序號【" + itemBarcodeNo + "】條碼解鎖失敗!
"; + } + + } + } + } + return RedirectToAction("Refresh", "Home", new { msg = _msg }); + } return View(); } #endregion diff --git a/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs b/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs index c54d782a..4ee026bf 100644 --- a/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs +++ b/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs @@ -238,13 +238,6 @@ namespace AMESCoreStudio.Web [WebApiClient.Attributes.HttpGet("api/WipBarcode/{id}")] ITask> GetWipBarcode(string id); - /// - /// 查詢工單資料Barcode By 條碼前置碼 - /// - /// - [WebApiClient.Attributes.HttpGet("api/WipBarcode/BarcodeNo/{id}")] - ITask> GetWipBarcodeBarcodeNo(string id); - /// /// 刪除工單內部條碼區間 /// @@ -269,7 +262,7 @@ namespace AMESCoreStudio.Web ITask> GetBarcodeInfoes(int id); [WebApiClient.Attributes.HttpGet("api/BarcodeInfoes/ByWipNo/{id}")] - ITask> GetBarcodeInfoesByWipNo(string wipNo); + ITask> GetBarcodeInfoesByWipNo(string id); [WebApiClient.Attributes.HttpPost("api/BarcodeInfoes")] ITask> PostBarcodeInfoes([FromBody, RawJsonContent] string model); diff --git a/AMESCoreStudio.Web/Views/PCS/PCS014.cshtml b/AMESCoreStudio.Web/Views/PCS/PCS014.cshtml index 1a253dd6..0b9bb4fc 100644 --- a/AMESCoreStudio.Web/Views/PCS/PCS014.cshtml +++ b/AMESCoreStudio.Web/Views/PCS/PCS014.cshtml @@ -1,7 +1,7 @@ -@model AMESCoreStudio.WebApi.Models.AMES.WipLock +@model AMESCoreStudio.Web.ViewModels.PCS.PCS014ViewModel -@{ ViewData["Title"] = "PCS011"; +@{ ViewData["Title"] = "PCS014"; Layout = "~/Views/Shared/_AMESLayout.cshtml"; } @@ -13,41 +13,51 @@
-
+
-
- +
+ +
- - +
- +
+ +
- +
- +
+ +
- + +
+
+
+
- +
+ +
diff --git a/AMESCoreStudio.Web/Views/PCS/PCS015.cshtml b/AMESCoreStudio.Web/Views/PCS/PCS015.cshtml index 4c3ca3e0..013a4212 100644 --- a/AMESCoreStudio.Web/Views/PCS/PCS015.cshtml +++ b/AMESCoreStudio.Web/Views/PCS/PCS015.cshtml @@ -227,7 +227,7 @@ //通过行tool编辑,lay-event="edit" function edit(obj) { if (obj.data.wipNO) { - hg.open('條碼解鎖', '/PCS/PCS014/' + obj.data.wipLockID, 480, 480,false); + hg.open('條碼解鎖', '/PCS/PCS014/' + obj.data.barCodeNo, 700, 480,false); } } var toolbar = [{ diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/BarcodeInfoesController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/BarcodeInfoesController.cs index e68db1c9..6631d088 100644 --- a/AMESCoreStudio.WebApi/Controllers/AMES/BarcodeInfoesController.cs +++ b/AMESCoreStudio.WebApi/Controllers/AMES/BarcodeInfoesController.cs @@ -144,17 +144,17 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES /// /// 用工單號碼获取该條碼资料 /// - /// 工單號碼 + /// 工單號碼 /// // GET: api/BarcodeInfoes/5 - [HttpGet("ByWipNo/{WipNo}")] - public async Task>> GetBarcodeInfoesByWipNo(string WipNo) + [HttpGet("ByWipNo/{id}")] + public async Task>> GetBarcodeInfoesByWipNo(string id) { var barcodeInfo = new List(); WipInfosController wipInfosController = new WipInfosController(_context); - var q1 = await wipInfosController.GetWipInfoByWipNo(WipNo); + var q1 = await wipInfosController.GetWipInfoByWipNo(id); if (q1.Value.Count() != 0) { diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/BarcodeLockController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/BarcodeLockController.cs index c1d122c4..54ced7e5 100644 --- a/AMESCoreStudio.WebApi/Controllers/AMES/BarcodeLockController.cs +++ b/AMESCoreStudio.WebApi/Controllers/AMES/BarcodeLockController.cs @@ -134,20 +134,20 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES return result; } - // PUT: api/BarcodeLock/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}")] + + [HttpPut] public async Task> PutBarcodeLock(BarcodeLock barcodeLock) { ResultModel result = new ResultModel(); - _context.Attach(barcodeLock); - // 指定更新某個欄位 - _context.Entry(barcodeLock).Property(p => p.LockStatus).IsModified = true; - _context.Entry(barcodeLock).Property(p => p.UnLockDate).IsModified = true; - _context.Entry(barcodeLock).Property(p => p.UnLockReason).IsModified = true; - _context.Entry(barcodeLock).Property(p => p.UnLockUserID).IsModified = true; + _context.Entry(barcodeLock).State = EntityState.Modified; + + //_context.Attach(barcodeLock); + //// 指定更新某個欄位 + //_context.Entry(barcodeLock).Property(p => p.LockStatus).IsModified = true; + //_context.Entry(barcodeLock).Property(p => p.UnLockDate).IsModified = true; + //_context.Entry(barcodeLock).Property(p => p.UnLockReason).IsModified = true; + //_context.Entry(barcodeLock).Property(p => p.UnLockUserID).IsModified = true; try { @@ -163,9 +163,7 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES return result; } - // POST: api/BarcodeLock - // 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> PostBarcodeLock(BarcodeLock barcodeLock) { diff --git a/AMESCoreStudio.WebApi/Models/AMES/BarcodeLock.cs b/AMESCoreStudio.WebApi/Models/AMES/BarcodeLock.cs index 28a355c2..5193733d 100644 --- a/AMESCoreStudio.WebApi/Models/AMES/BarcodeLock.cs +++ b/AMESCoreStudio.WebApi/Models/AMES/BarcodeLock.cs @@ -93,7 +93,7 @@ namespace AMESCoreStudio.WebApi.Models.AMES /// [Column("UNLOCK_USERID")] [DataMember] - [NotMapped] + public int? UnLockUserID { get; set; } /// @@ -108,6 +108,7 @@ namespace AMESCoreStudio.WebApi.Models.AMES /// [ForeignKey("BarcodeID")] [DataMember] + [NotMapped] public virtual BarcodeInfo GetBarcodeInfo { get; set; } }