From 129f59bafb9f67144720dcf6563401655f9e3aae Mon Sep 17 00:00:00 2001
From: yangle <admin@YINMOU>
Date: 星期二, 14 十一月 2023 17:51:17 +0800
Subject: [PATCH] 单品过站功能优化 生产订单下推 流转卡过滤

---
 WebAPI/Controllers/CJGL/Cj_SingleStationController.cs |  101 ++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 89 insertions(+), 12 deletions(-)

diff --git a/WebAPI/Controllers/CJGL/Cj_SingleStationController.cs b/WebAPI/Controllers/CJGL/Cj_SingleStationController.cs
index e8537aa..0038234 100644
--- a/WebAPI/Controllers/CJGL/Cj_SingleStationController.cs
+++ b/WebAPI/Controllers/CJGL/Cj_SingleStationController.cs
@@ -411,6 +411,16 @@
                 sub = JsonConvert.DeserializeObject<List<Model.ClsSc_AssemblyBillSub>>(sSubStr);
 
 
+                ds = oCN.RunProcReturn("select  * from h_v_Gy_QualifiedRecordsList where 浜у搧鏉$爜='" + omodel.HBarCode_P + "'", "h_v_Gy_QualifiedRecordsList");
+                if (ds.Tables[0].Rows.Count > 0)
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鏉$爜:" + omodel.HBarCode_P + ",宸插瓨鍦�!";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
                 Int64 HInterID1 = DBUtility.ClsPub.CreateBillID("3727", ref DBUtility.ClsPub.sExeReturnInfo);
                 string HBillNo1 = DBUtility.ClsPub.CreateBillCode("3727", ref DBUtility.ClsPub.sExeReturnInfo, true);
                 //淇濆瓨鐢熶骇缁勮鍗曚富琛�
@@ -531,8 +541,12 @@
                   "," + HmaterOutqty + "," + HProcPriceRate + "," + HTemporaryAreaID + ") ");
                 }
 
+              
+
+                ds = oCN.RunProcReturn("select  * from Sc_StationOutBillSub_SN where HInterID='" + omodel.HInterID + "' order by HEntryID desc", "Sc_StationOutBillSub_SN");
+
                 oCN.RunProc($@"insert into Sc_StationOutBillSub_SN(HInterID,HBillNo_bak,HEntryID,HBarCode,HBarCodeQty,HMakeTime,HRemark,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney)
-values({omodel.HInterID}, '{omodel.HBillNo}', {ds.Tables[0].Rows.Count + 1}, '{omodel.HBarCode_P}', 1, GETDATE(), '', 0, 0, '', '', 0, 0)");
+values({omodel.HInterID}, '{omodel.HBillNo}', {(ds.Tables[0].Rows.Count == 0 ? 1 : int.Parse(ds.Tables[0].Rows[0]["HEntryID"].ToString()) + 1)}, '{omodel.HBarCode_P}', 1, GETDATE(), '', " + HProcExchInterID + ","+ HProcExchEntryID + ", '"+ HProcExchBillNo + "', '', 0, 0)");
 
                 //鍙嶅啓宸ュ簭鍑虹珯鍗曠殑鍚堟牸鏁伴噺
                 oCN.RunProc("update Sc_StationOutBillMain set HQty+=1  where HProcExchInterID='" + HProcExchInterID + "' and HProcExchEntryID=" + HProcExchEntryID);
@@ -575,14 +589,20 @@
                     objJsonResult.data = null;
                     return objJsonResult;
                 }
-                else
+
+                if (ds.Tables[0].Rows[0]["HStatus"].ToString() !="")
                 {
-                    objJsonResult.code = "1";
-                    objJsonResult.count = 1;
-                    objJsonResult.Message = "";
-                    objJsonResult.data = ds.Tables[0];
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "褰撳墠鏉$爜鐨勭姸鎬佷负:"+ ds.Tables[0].Rows[0]["HStatus"].ToString() + "锛�";
+                    objJsonResult.data = null;
+                    return objJsonResult;
                 }
 
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "";
+                objJsonResult.data = ds.Tables[0];
                 return objJsonResult;
             }
             catch (Exception e)
@@ -769,6 +789,8 @@
             {
                 ds = oCN.RunProcReturn("select * from h_v_Gy_QualifiedRecordsList  where hmainid = " + HInterID, "h_v_Gy_QualifiedRecordsList");
 
+                string HProcExchInterID = ds.Tables[0].Rows[0]["HProcExchInterID"].ToString();
+                string HProcExchEntryID = ds.Tables[0].Rows[0]["HProcExchEntryID"].ToString();
                 if (ds.Tables[0].Rows.Count == 0)
                 {
                     objJsonResult.code = "0";
@@ -784,12 +806,18 @@
                     sql = "delete from Sc_StationOutBillMain where HInterID = " + HInterID;
                     oCN.RunProc(sql);
                 }
+                ds = oCN.RunProcReturn("select * from Sc_StationOutBillSub_SN where HInterID = " + HInterID + " and HEntryID = " + HEntryID, "Sc_StationOutBillSub_SN");
+                string HBarCode = ds.Tables[0].Rows[0]["HBarCode"].ToString();
+                string HBillNo_bak = ds.Tables[0].Rows[0]["HBillNo_bak"].ToString();
+
+                //鍒犻櫎缁勮杩芥函鍗�
+                oCN.RunProc("delete from Sc_AssemblyBillSub where HInterID in(select HInterID from Sc_AssemblyBillMain where HMainSourceInterID=" + HProcExchInterID + " and HMainSourceEntryID=" + HProcExchEntryID + " and HBarCode_P='" + HBarCode + "')");
+                oCN.RunProc("delete from   Sc_AssemblyBillMain where HMainSourceInterID=" + HProcExchInterID + " and HMainSourceEntryID=" + HProcExchEntryID + " and HBarCode_P='" + HBarCode + "'");
+
                 sql = "delete from Sc_StationOutBillSub_SN where HInterID = " + HInterID + " and HEntryID = " + HEntryID;
                 oCN.RunProc(sql);
-                string HProcExchInterID = ds.Tables[0].Rows[0]["HProcExchInterID"].ToString();
-                string HProcExchEntryID = ds.Tables[0].Rows[0]["HProcExchEntryID"].ToString();
                 //鍙嶅啓宸ュ簭鍑虹珯鍗曠殑鍚堟牸鏁伴噺
-                oCN.RunProc("update Sc_StationOutBillMain set HBadCount-=1  where HProcExchInterID='" + HProcExchInterID + "' and HProcExchEntryID=" + HProcExchEntryID);
+                oCN.RunProc("update Sc_StationOutBillMain set HQty-=1  where HProcExchInterID='" + HProcExchInterID + "' and HProcExchEntryID=" + HProcExchEntryID+ " and HBillNo='"+ HBillNo_bak + "'");
 
 
                 oCN.Commit();
@@ -920,8 +948,9 @@
                 string[] sArray = msg.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                 string sMainStr = sArray[0].ToString();
                 string sSubStr = sArray[1].ToString();
-                string user = sArray[2].ToString();
-                string HResult = sArray[3].ToString();
+                string sSubStr2 = sArray[2].ToString();
+                string user = sArray[3].ToString();
+                string HResult = sArray[4].ToString();
 
                 oCN.BeginTran();
                 if (HResult == "閰嶄欢")
@@ -941,8 +970,56 @@
 ({model.HInterID},{(ds.Tables[0].Rows.Count == 0 ? 1 : int.Parse(ds.Tables[0].Rows[0]["HEntryID"].ToString()) + 1)},'{model.HBillNo}','',{temp.HProcExchInterID}
 ,{temp.HProcExchEntryID},'{temp.HProcExchBillNo}','',{temp.HMaterID},0,'{temp.HBarCode}','{temp.HBatchNo}')");
 
+
+                    ds = oCN.RunProcReturn("select  * from Sc_SourceLineRepairBillSub where HInterID=" + model.HInterID, "Sc_SourceLineRepairBillSub");
+                    if (ds.Tables[0].Rows[0]["HRepairResult"].ToString() == "OK") {
+                        //鐢熸垚 浜х嚎缁勮杩芥函鍗�
+
+                        Int64 HInterID1 = DBUtility.ClsPub.CreateBillID("3727", ref DBUtility.ClsPub.sExeReturnInfo);
+                        string HBillNo1 = DBUtility.ClsPub.CreateBillCode("3727", ref DBUtility.ClsPub.sExeReturnInfo, true);
+
+                        ds = oCN.RunProcReturn("select  * from Sc_SourceLineRepairBillMain where HInterID=" + model.HInterID, "Sc_SourceLineRepairBillMain");
+                        string HMaterID = ds.Tables[0].Rows[0]["HMaterID"].ToString();
+                        //淇濆瓨鐢熶骇缁勮鍗曚富琛�
+                        string sql = $@"Insert Into Sc_AssemblyBillMain(HYear,HPeriod,HBillType,HBillSubType,HInterID,HDate
+,HBillNo,HBillStatus,HMaker,HMakeDate,HMainSourceInterID,HMainSourceEntryID,HMainSourceBillNo
+,HICMOInterID,HICMOBillNo,HBarCode_P,HMaterID,HUnitID,HAssemblyStatus,HProdOrgID)
+values('{DateTime.Now.Year}','{DateTime.Now.Month}','3727','3727',{HInterID1},getdate()
+,'{HBillNo1}','1','{user}',getdate(),{temp.HProcExchInterID.ToString()},{temp.HProcExchEntryID.ToString()},'{temp.HProcExchBillNo.ToString()}'
+,{model.HICMOInterID.ToString()},'{model.HICMOBillNo.ToString()}','{model.HBarCode.ToString()}',{HMaterID},0,'姹囨姤',{model.HProdOrgID})";
+                        oCN.RunProc(sql);
+
+                       List<Model.Sc_AssemblyBill_BindSourceTemp>  sub = new List<Model.Sc_AssemblyBill_BindSourceTemp>();
+                        sub = JsonConvert.DeserializeObject<List<Model.Sc_AssemblyBill_BindSourceTemp>>(sSubStr2);
+
+                        for (int i = 0; i < sub.Count; i++)
+                        {
+                            //瀛愯〃瀛樺偍
+                            string sq2 = $@"Insert Into Sc_AssemblyBillSub(HInterID,HBillNo_bak,HEntryID,HSourceInterID,HSourceEntryID,HSourceBillNo
+,HSourceBillType,HMaterID,HSourceID,HEquipID,HUnitID,HQty
+,HGroupID,HWorkerID,HScanDate,HBarCode,HBarCode_P,HSNNumber)
+values({HInterID1},'{HBillNo1}',{(i + 1)},0,0,''
+,'',{sub[i].HMaterID},0,0,0,{sub[i].HQty}
+,0,0,getdate(),'{sub[i].HBarCode}','{model.HBarCode}','') ";
+                            oCN.RunProc(sq2);
+                        }
+
+                        //鐢熶骇宸ュ簭鍑虹珯SN鏁版嵁
+                        ds = oCN.RunProcReturn("select top 1  HInterID,HBillNo from Sc_StationOutBillMain where HProcExchInterID=" + temp.HProcExchInterID + " and HProcExchEntryID=" + temp.HProcExchEntryID + " and HBadCount<>0  order by  HInterID desc", "Sc_StationOutBillMain");
+
+                        string HInterIDSN = ds.Tables[0].Rows[0]["HInterID"].ToString();
+                        string HBillNoSN = ds.Tables[0].Rows[0]["HBillNo"].ToString();
+
+                        ds = oCN.RunProcReturn("select *  from Sc_StationOutBillSub_SN where HInterID=" + HInterIDSN , "Sc_StationOutBillSub_SN");
+
+                        oCN.RunProc($@"insert into Sc_StationOutBillSub_SN(HInterID,HBillNo_bak,HEntryID,HBarCode,HBarCodeQty,HMakeTime,HRemark,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney)
+values({HInterIDSN}, '{HBillNoSN}', {ds.Tables[0].Rows.Count + 1}, '{model.HBarCode}', 1, GETDATE(), '', "+ temp.HProcExchInterID + ","+ temp.HProcExchEntryID+ ", '"+ temp.HProcExchBillNo+ "', '', 0, 0)");
+                        //鍙嶅啓宸ュ簭鍑虹珯鍗� 涓昏〃 涓嶈壇鏁伴噺 鍜� 鍚堟牸鏁伴噺
+                        oCN.RunProc("update Sc_StationOutBillMain set HQty+=1,HBadCount-=1  where HInterID='" + HInterIDSN + "'");
+
+                    }
                     //淇敼閰嶄欢缁戝畾娓呭崟缁戝畾鐨勬潯鐮佹壒鍙�
-                    oCN.RunProc("exec h_p_AssemblyBill_Temp '" + temp.HProcExchBillNo + "'," + model.HProcess + "," + temp.HMaterID + ",'" + temp.HBatchNo + "'");
+                    //oCN.RunProc("exec h_p_AssemblyBill_Temp '" + temp.HProcExchBillNo + "'," + model.HProcess + "," + temp.HMaterID + ",'" + temp.HBatchNo + "'");
                 }
                 else if (HResult == "NG"|| HResult == "OK") {
                     Model.ClsSc_SourceLineRepairBillMain model = new Model.ClsSc_SourceLineRepairBillMain();

--
Gitblit v1.9.1