diff --git a/AMESCoreStudio.Web/Controllers/REPController.cs b/AMESCoreStudio.Web/Controllers/REPController.cs index d25050e9..8d3c80bc 100644 --- a/AMESCoreStudio.Web/Controllers/REPController.cs +++ b/AMESCoreStudio.Web/Controllers/REPController.cs @@ -459,6 +459,319 @@ namespace AMESCoreStudio.Web.Controllers return View(); } + public async Task REP002V(int id) + { + REP001ViewModel model = new REP001ViewModel(); + var result = await _repApi.GetNgInfo(id); + if (result.Count != 0) + { + model.ngInfo = result[0]; + } + return View(model); + } + + public async Task REP002C(int id) + { + + await GetRMAReasonList(); + await GetRepairTypeList(); + await GetNGReasonList(); + await GetRepairResponsibleUnitList(); + + REP001ViewModel model = new REP001ViewModel(); + + var ng_info = await _repApi.GetNgInfo(id); + if (ng_info.Count != 0) + { + model.ngInfo = ng_info[0]; + } + + return View(model); + + } + + public async Task REP002R(int id) + { + await GetRMAReasonList(); + await GetRepairTypeList(); + await GetNGReasonList(); + await GetRepairResponsibleUnitList(); + + REP001ViewModel model = new REP001ViewModel(); + var result1 = await _repApi.GetNgComponent(id); + if (result1.Count != 0) + { + model.ngComponent = result1[0]; + + var result2 = await _repApi.GetNgInfo((int)result1[0].NgID); + if (result2.Count != 0) + { + model.ngInfo = result2[0]; + } + + var result3 = await _repApi.GetRepairRecord((int)result1[0].ComponentID); + if (result3.Count != 0) + { + model.repairRecord = result3[0]; + } + + var result4 = await _repApi.GetNgRepairByComponent((int)result1[0].ComponentID); + if (result4.Count != 0) + { + model.ngRepair = result4[0]; + + + var result5 = await _repApi.GetNgRepairBlob(result4[0].RepairID); + if (result5.Count != 0) + { + model.ngRepairBlob = result5[0]; + + //if (result5[0].ImageName1 != "" && result5[0].ImageName1 != null) + //{ + // ViewBag.Image1Url = $"\\REPImage\\" + result5[0].ImageName1; + //} + //else + //{ + // ViewBag.Image1Url = $"\\REPImage\\" + "noimage.jfif"; + //} + //if (result5[0].ImageName2 != "" && result5[0].ImageName2 != null) + //{ + // ViewBag.Image2Url = $"\\REPImage\\" + result5[0].ImageName2; + //} + //else + //{ + // ViewBag.Image2Url = $"\\REPImage\\" + "noimage.jfif"; + //} + //if (result5[0].ImageName3 != "" && result5[0].ImageName3 != null) + //{ + // ViewBag.Image3Url = $"\\REPImage\\" + result5[0].ImageName3; + //} + //else + //{ + // ViewBag.Image3Url = $"\\REPImage\\" + "noimage.jfif"; + //} + } + else + { + ViewBag.Image1Url = $"\\REPImage\\" + "noimage.jfif"; + ViewBag.Image2Url = $"\\REPImage\\" + "noimage.jfif"; + ViewBag.Image3Url = $"\\REPImage\\" + "noimage.jfif"; + } + } + else + { + ViewBag.Image1Url = $"\\REPImage\\" + "noimage.jfif"; + ViewBag.Image2Url = $"\\REPImage\\" + "noimage.jfif"; + ViewBag.Image3Url = $"\\REPImage\\" + "noimage.jfif"; + } + } + + return View(model); + } + + [HttpPost] + public async Task REP002CSaveAsync(REP001ViewModel model, IFormFile formFile) + { + IResultModel result; + var userID = ""; + HttpContext.Request.Cookies.TryGetValue("UserID", out userID); + int user_id = 0; + if (userID != null) + { + if (int.Parse(userID.ToString()) >= 0) + { + user_id = int.Parse(userID.ToString()); + } + } + + + model.ngComponent.ReplyUserID = user_id; + model.ngComponent.ReplyDate = System.DateTime.Now; + model.ngComponent.Status = 1; + model.ngComponent.NgID = model.ngInfo.NgID; + + string FileName = string.Empty; + string NewName = string.Empty; + string FilePath = string.Empty; + + if (formFile != null) + { + if (formFile.Length > 0) + { + //取得使用者上傳檔案的原始檔名 + FileName = Path.GetFileName(formFile.FileName); + //取原始檔名中的副檔名 + var fileExt = Path.GetExtension(FileName); + //為避免使用者上傳的檔案名稱發生重複,重新給一個亂數名稱 + NewName = Path.GetRandomFileName() + fileExt; + //指定要寫入的路徑、檔名和副檔名 + FilePath = $"\\REPImage\\";//本機目錄 + using (var stream = new FileStream(_env.WebRootPath + FilePath + NewName, FileMode.Create)) + { + await formFile.CopyToAsync(stream); + } + } + } + else + { + ModelState.AddModelError("error", "請選擇要上傳檔案"); + } + + if (model.ngRepair.Missing == "Y") + { + model.ngRepair.RepairNo = "N/A"; + model.ngComponent.Status = 2; + } + + result = await _repApi.PostNgComponent(JsonConvert.SerializeObject(model.ngComponent)); + + if (result.Success) + { + int component_id = int.Parse(result.Msg.ToString().Replace("OK-", "")); + model.repairRecord.ComponentID = component_id; + + model.repairRecord.NgID = model.ngInfo.NgID; + result = await _repApi.PostRepairRecord(JsonConvert.SerializeObject(model.repairRecord)); + + model.ngRepair.NgID = model.ngInfo.NgID; + model.ngRepair.ComponentID = component_id; + result = await _repApi.PostNgRepair(JsonConvert.SerializeObject(model.ngRepair)); + + if (result.Success) + { + int repair_id = int.Parse(result.Msg.ToString().Replace("OK-", "")); + if (NewName == string.Empty) + { } + else + { + decimal repairID = 0; + if (model.ngRepair.RepairID == 0) + { + var ng_repair = await _repApi.GetNgRepairByComponent(model.ngRepair.ComponentID); + repairID = ng_repair[0].RepairID; + } + else + { + repairID = model.ngRepair.RepairID; + } + + if (model.ngRepairBlob == null) + { + NgRepairBlob ng_repair_blob = new NgRepairBlob(); + ng_repair_blob.ImageName = NewName; + ng_repair_blob.RepairID = repair_id; + + model.ngRepairBlob = ng_repair_blob; + } + else + { + model.ngRepairBlob.ImageName = NewName; + model.ngRepairBlob.RepairID = repair_id; + } + + result = await _repApi.PostNgRepairBlob(JsonConvert.SerializeObject(model.ngRepairBlob)); + } + } + + } + + bool repairComplete = true; + + var ng_component = await _repApi.GetNgComponentByNGID(model.ngInfo.NgID); + for (int i = 0; i < ng_component.Count; i++) + { + if (ng_component[i].Status == 0) + { + repairComplete = false; + break; + } + } + + List items = new List(); + //判斷組件是否更換 + for (int i = 0; i < ng_component.Count; i++) + { + if (ng_component[i].NewPartNo != "") + { + items.Add(new BarCodeCheckDto.inputItem + { + inputType = "KP", + inputData = ng_component[i].NewPartNo, + oldInputData = ng_component[i].OldPartNo + }); + } + } + + if (repairComplete) + { + //判断全部维修完成过站 + int repairStationID = -1; + var rules = await _basApi.GetRules(model.ngInfo.Barcode.RuleStationID); + if (rules.Count > 0) + { + for (int i = 0; i < rules.Count; i++) + { + if (rules[i].RuleStatus == model.ngInfo.Barcode.RuleStatus) + { + repairStationID = rules[i].NextStationID; + break; + } + } + } + + int lineID = -1; + if (model.ngInfo.Wip.LineID != null) + { + lineID = model.ngInfo.Wip.LineID.Value; + } + + //准备资料 + var barCode = new BarCodeCheckDto + { + wipNo = model.ngInfo.Wip.WipNO, + barcode = model.ngInfo.Barcode.BarcodeNo, + barcodeType = "S", + station = repairStationID, + line = lineID, + unitNo = model.ngInfo.Wip.UnitNO, + inputItems = items + }; + + try + { + var barcode_result = await _pcsApi.PassIngByCheck(JsonConvert.SerializeObject(barCode)); + } + catch { } + + //更新NG_INFO + //var ng_info = await _repApi.GetNgInfo((int)model.ngInfo.NgID); + //ng_info[0].Status = 1; + model.ngInfo.Status = 1; + result = await _repApi.PutNgInfo(JsonConvert.SerializeObject(model.ngInfo)); + } + + if (result.Success) + { + var _msg = "保存成功!"; + //return RedirectToAction("REP001V", "REP", new { id = model.ngComponent.NgID, msg = _msg }); + return RedirectToAction("Refresh", "Home", new { id = model.ngComponent.NgID, 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("REP001R", model); + //return RedirectToAction("REP001V", "REP", new { id = model.ngComponent.NgID }); + } #endregion } } diff --git a/AMESCoreStudio.Web/HttpApis/AMES/IREP.cs b/AMESCoreStudio.Web/HttpApis/AMES/IREP.cs index ca15f9c8..a82a2683 100644 --- a/AMESCoreStudio.Web/HttpApis/AMES/IREP.cs +++ b/AMESCoreStudio.Web/HttpApis/AMES/IREP.cs @@ -50,6 +50,13 @@ namespace AMESCoreStudio.Web [WebApiClient.Attributes.HttpPut("api/NgComponents/{id}")] ITask> PutNgComponent(int id, [FromBody, RawJsonContent] string model); + /// + /// 新增不良零件資料 + /// + /// + [WebApiClient.Attributes.HttpPost("api/NgComponents")] + ITask> PostNgComponent([FromBody, RawJsonContent] string model); + /// /// 根據COMPONENT_ID獲取指定維修過程資料 /// diff --git a/AMESCoreStudio.Web/Views/REP/REP002C.cshtml b/AMESCoreStudio.Web/Views/REP/REP002C.cshtml new file mode 100644 index 00000000..8eb117f9 --- /dev/null +++ b/AMESCoreStudio.Web/Views/REP/REP002C.cshtml @@ -0,0 +1,360 @@ +@model AMESCoreStudio.Web.ViewModels.REP001ViewModel + + +@{ ViewData["Title"] = "REP002C"; + Layout = "~/Views/Shared/_AMESLayout.cshtml"; } + + + +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+
+
+
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+
+
+
+ +
+ + +
+ +
+ + +
+ +
+ + +
+
+
+
+
+ +
+ + +
+ +
+ + +
+
+
+
+
+ +
+
+
+
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+
+
+
+ +
+ + +
+ +
+ + +
+
+
+
+
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+
+
+
+ +
+
+
+
+ +
+ + +
+
+
+
+
+ +
+
+
+
+ +
+ + + + +
+ +
+
+
+
+ +
+ + +
+ +
+ + +
+ +
+ + +
+
+
+
+
+ +
+ + +
+ +
+ + +
+ +
+ + +
+
+
+
+
+ +
+ + +
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+ @Html.ValidationMessage("error") + +
+
+
+
+
+ +@section Scripts { + @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); + await Html.RenderPartialAsync("_FileinputScriptsPartial"); } + + + + +} + diff --git a/AMESCoreStudio.Web/Views/REP/REP002R.cshtml b/AMESCoreStudio.Web/Views/REP/REP002R.cshtml new file mode 100644 index 00000000..e8103e3c --- /dev/null +++ b/AMESCoreStudio.Web/Views/REP/REP002R.cshtml @@ -0,0 +1,435 @@ +@model AMESCoreStudio.Web.ViewModels.REP001ViewModel + + +@{ ViewData["Title"] = "REP002R"; + Layout = "~/Views/Shared/_AMESLayout.cshtml"; } + + + +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+
+
+
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+
+
+
+ +
+ + +
+ +
+ + +
+ +
+ + +
+
+
+
+
+ +
+ + +
+ +
+ + +
+
+
+
+
+ +
+
+
+
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+
+
+
+ +
+ + +
+ +
+ + +
+
+
+
+
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+
+
+
+ +
+
+
+
+ +
+ + +
+
+
+
+
+ +
+
+
+
+ +
+ + + + +
+ +
+
+
+
+ +
+ + +
+ +
+ + +
+ +
+ + +
+
+
+
+
+ +
+ + +
+ +
+ + +
+ +
+ + +
+
+
+
+
+ +
+ + +
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+ @Html.ValidationMessage("error") + +
+
+
+
+ +
+ +@section Scripts { + @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); + await Html.RenderPartialAsync("_FileinputScriptsPartial"); } + + + + +} + diff --git a/AMESCoreStudio.Web/Views/REP/REP002V.cshtml b/AMESCoreStudio.Web/Views/REP/REP002V.cshtml index 8d237f07..b305ac81 100644 --- a/AMESCoreStudio.Web/Views/REP/REP002V.cshtml +++ b/AMESCoreStudio.Web/Views/REP/REP002V.cshtml @@ -75,8 +75,13 @@ +
+
+ +
+
-
+
@@ -88,7 +93,7 @@ //监听表单提交事件 hg.form.onsubmit('querysubmit', function (data) { table && table.reload(data); - + }); var tableCols = [[ @@ -139,19 +144,24 @@ align: 'center', fixed: 'right', templet: function (d) { - return ' 維修 ' + return ' 維修變更 ' } }] ]; + $('#btnAdd').click(function () { + hg.open('新增不良零件資料', '/REP/REP002C/' +@Model.ngInfo.NgID, 1080, 640); + }); + //通过行tool编辑,lay-event="edit" function repair(obj) { if (obj.data.componentID) { - hg.open('維修輸入', '/REP/REP001R/' + obj.data.componentID, 1080, 640); + hg.open('維修變更', '/REP/REP002R/' + obj.data.componentID, 1080, 640); } } //基本数据表格 + //var table = hg.table.datatable('test', '測試不良零件維護', '/REP/GetNgComponentByNGID/' + @Model.ngInfo.NgID, {}, tableCols, toolbar, false, 'full-100', ['filter', 'print', 'exports']); var table = hg.table.datatable('test', '測試不良零件維護', '/REP/GetNgComponentByNGID/' + @Model.ngInfo.NgID, {}, tableCols, false, false, 'full-100'); diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/NgComponentsController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/NgComponentsController.cs index 3a0fa741..da129c25 100644 --- a/AMESCoreStudio.WebApi/Controllers/AMES/NgComponentsController.cs +++ b/AMESCoreStudio.WebApi/Controllers/AMES/NgComponentsController.cs @@ -173,7 +173,7 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES } result.Success = true; - result.Msg = "OK"; + result.Msg = "OK"+"-"+ngComponent.ComponentID; return result; } diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/NgRepairsController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/NgRepairsController.cs index 274211f1..b9c2f044 100644 --- a/AMESCoreStudio.WebApi/Controllers/AMES/NgRepairsController.cs +++ b/AMESCoreStudio.WebApi/Controllers/AMES/NgRepairsController.cs @@ -166,7 +166,7 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES } result.Success = true; - result.Msg = "OK"; + result.Msg = "OK" + "-" + ngRepair.RepairID; return result; }