From f9b2dd1af58b74d9b3b2f17216f0d01b5a094335 Mon Sep 17 00:00:00 2001
From: ray <newkyonew@hotmail.com>
Date: Mon, 9 Jan 2023 23:46:55 +0800
Subject: [PATCH] =?UTF-8?q?1.=20PCS003=E5=B7=A5=E5=96=AE=E4=BF=AE=E6=94=B9?=
 =?UTF-8?q?=20=E5=8F=AF=E4=BB=A5=E4=BF=AE=E6=94=B9=E5=87=BA=E8=B2=A8?=
 =?UTF-8?q?=E5=BA=8F=E8=99=9F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../Controllers/PCSController.cs              | 34 +++++---
 AMESCoreStudio.Web/Views/PCS/PCS003.cshtml    | 85 +++++++++++++------
 2 files changed, 83 insertions(+), 36 deletions(-)

diff --git a/AMESCoreStudio.Web/Controllers/PCSController.cs b/AMESCoreStudio.Web/Controllers/PCSController.cs
index 4724ed6d..1427d37e 100644
--- a/AMESCoreStudio.Web/Controllers/PCSController.cs
+++ b/AMESCoreStudio.Web/Controllers/PCSController.cs
@@ -1428,20 +1428,32 @@ namespace AMESCoreStudio.Web.Controllers
                     var type_no = await _pcsApi.GetBarcodeTypeByTypeName("客戶條碼區間");
                     if (type_no != null)
                     {
-                        WipBarcodeOther wipBarcodeOther = new WipBarcodeOther
+                        var wipBarcodeOther = await _pcsApi.GetWipBarcodeOther(wipNo);
+                        if (wipBarcodeOther != null)
                         {
-                            WipNO = wipNo,
-                            TypeNO = type_no.TypeNo,
-                            StartNO = StartNO,
-                            EndNO = EndNO,
-                            CreateUserID = GetLogInUserID(),
-                            UpdateUserID = GetLogInUserID()
-                        };
-                        await _pcsApi.PostWipBarcodeOther(JsonConvert.SerializeObject(wipBarcodeOther));
+                            wipBarcodeOther.StartNO = StartNO;
+                            wipBarcodeOther.EndNO = EndNO;
+                            wipBarcodeOther.UpdateDate = DateTime.Now;
+                            wipBarcodeOther.UpdateUserID = GetLogInUserID();
+                            await _pcsApi.PutWipBarcodeOther(JsonConvert.SerializeObject(wipBarcodeOther));
+                        }
+                        else
+                        {
+                            wipBarcodeOther = new WipBarcodeOther();
+                            wipBarcodeOther.WipNO = wipNo;
+                            wipBarcodeOther.TypeNO = type_no.TypeNo;
+                            wipBarcodeOther.StartNO = StartNO;
+                            wipBarcodeOther.EndNO = EndNO;
+                            wipBarcodeOther.CreateUserID = GetLogInUserID();
+                            wipBarcodeOther.UpdateUserID = GetLogInUserID();
+                            await _pcsApi.PostWipBarcodeOther(JsonConvert.SerializeObject(wipBarcodeOther));
+                        }
                     }
+
                 }
             }
 
+
             return Json(new Result() { success = result.Success, msg = result.Msg, data = new { StartNO, EndNO } });
         }
         #endregion
@@ -2334,7 +2346,7 @@ namespace AMESCoreStudio.Web.Controllers
                     if (!string.IsNullOrWhiteSpace(model.wipSystem.Fw2))
                     {
                         var Fw2_Desc = _pcsApi.GetPlmMeterialInfo(model.wipSystem.Fw2).InvokeAsync().Result;
-                        model.wipSystem.Fw2_Desc = Fw2_Desc.Count() == 0  ? "" : Fw2_Desc.FirstOrDefault().MeterialDesc;
+                        model.wipSystem.Fw2_Desc = Fw2_Desc.Count() == 0 ? "" : Fw2_Desc.FirstOrDefault().MeterialDesc;
                     }
 
                     if (!string.IsNullOrWhiteSpace(model.wipSystem.Bios))
@@ -3798,7 +3810,7 @@ namespace AMESCoreStudio.Web.Controllers
                                                     UnitNo = wipKpDto.UnitNo,
                                                     UnitNoName = wipKpDto.UnitNoName,
                                                     KpSeq = Seq
-                                                }) ;
+                                                });
                                                 Seq += 1;
                                             }
                                         }
diff --git a/AMESCoreStudio.Web/Views/PCS/PCS003.cshtml b/AMESCoreStudio.Web/Views/PCS/PCS003.cshtml
index 700586ad..789afbd3 100644
--- a/AMESCoreStudio.Web/Views/PCS/PCS003.cshtml
+++ b/AMESCoreStudio.Web/Views/PCS/PCS003.cshtml
@@ -1130,18 +1130,18 @@
             }
 
             // DIV 出貨序號
-            if ($('#wipBarcodeOther_StartNO').val() != "" && $('#wipBarcodeOther_EndNO').val() != "") {
-                $("#barcodeOtherDiv").hide();
-            }
+            //if ($('#wipBarcodeOther_StartNO').val() != "" && $('#wipBarcodeOther_EndNO').val() != "") {
+            //    $("#barcodeOtherDiv").hide();
+            //}
 
             // DIV MAC
             if ($('#wipMAC_StartNO').val() != "" && $('#wipMAC_EndNO').val() != "") {
                 $("#GetMAC").hide();
             }
 
-            // DIV keyPartsExcel 
+            // DIV keyPartsExcel
             @if(Model.wipInfo.WipNO.StartsWith("981"))
-            {   
+            {
                 <text>$("#keyPartExcel").show();</text>
             }
             else
@@ -1173,6 +1173,7 @@
                 var itemNo = $('#wipAtt_ItemNO').val();
                 var planQTY = $('#wipInfo_PlanQTY').val();
                 var lotNo = $('#lotNo').val();
+
                 if (itemNo == '' || !itemNo) {
                     parent.hg.msg("請輸入料號");
                     return;
@@ -1186,27 +1187,61 @@
                     lotNo = getLotNo();
                 }
 
-                $.ajax({
-                    url: '@Url.Action("GetBarcodeOther", "PCS")',
-                    dataType: 'json',
-                    data: { "itemNo": itemNo, "lotNo": lotNo, "num": planQTY ,"wipNo":'@Model.wipInfo.WipNO'},
-                    cache: false,
-                    type: "POST",
-                    success: function (result) {
-                        // 錯誤訊息
-                        if (!result.success) {
-                            parent.hg.msg(result.msg);
-                        }
-                        else {
-                            $("#wipBarcodeOther_StartNO").val(result.data.startNO);
-                            $("#wipBarcodeOther_EndNO").val(result.data.endNO);
-                            $("#barcodeOtherDiv").hide();
+
+                var StartNO = $("#wipBarcodeOther_StartNO").val();
+                var EndNO = $("#wipBarcodeOther_EndNO").val();
+
+                if (StartNO != '' && EndNO != '') {
+                    layer.confirm('已有出貨序號起訖,要重新取得新的出貨序號起訖?', {
+                        btn: ['確定', '取消']
+                    }, function () {
+                        layer.closeAll('dialog');
+                        $.ajax({
+                            url: '@Url.Action("GetBarcodeOther", "PCS")',
+                            dataType: 'json',
+                            data: { "itemNo": itemNo, "lotNo": lotNo, "num": planQTY, "wipNo": '@Model.wipInfo.WipNO' },
+                            cache: false,
+                            type: "POST",
+                            success: function (result) {
+                                // 錯誤訊息
+                                if (!result.success) {
+                                    parent.hg.msg(result.msg);
+                                }
+                                else {
+                                    $("#wipBarcodeOther_StartNO").val(result.data.startNO);
+                                    $("#wipBarcodeOther_EndNO").val(result.data.endNO);
+                                }
+                            },
+                            error: function (jqXHR, textStatus, errorThrown) {
+                                alert("Found error when using Ajax!!");
+                            }
+                        });
+                        return;
+                    })
+                }
+                else {
+                   $.ajax({
+                        url: '@Url.Action("GetBarcodeOther", "PCS")',
+                        dataType: 'json',
+                        data: { "itemNo": itemNo, "lotNo": lotNo, "num": planQTY, "wipNo": '@Model.wipInfo.WipNO' },
+                        cache: false,
+                        type: "POST",
+                        success: function (result) {
+                            // 錯誤訊息
+                            if (!result.success) {
+                                parent.hg.msg(result.msg);
+                            }
+                            else {
+                                $("#wipBarcodeOther_StartNO").val(result.data.startNO);
+                                $("#wipBarcodeOther_EndNO").val(result.data.endNO);
+                            }
+                        },
+                        error: function (jqXHR, textStatus, errorThrown) {
+                            alert("Found error when using Ajax!!");
                         }
-                    },
-                    error: function (jqXHR, textStatus, errorThrown) {
-                        alert("Found error when using Ajax!!");
-                    }
-                });
+                   });
+                    return;
+                }
             });
 
             // 產生MAC