From 5555b76b6f0d802cd041cb81c670a5cd27b218d9 Mon Sep 17 00:00:00 2001
From: yangle <admin@YINMOU>
Date: 星期一, 18 十二月 2023 13:33:05 +0800
Subject: [PATCH] 单品过站优化

---
 WebAPI/Controllers/CJGL/Cj_SingleStationController.cs |   41 ++++++++++++++++++++++++++---------------
 1 files changed, 26 insertions(+), 15 deletions(-)

diff --git a/WebAPI/Controllers/CJGL/Cj_SingleStationController.cs b/WebAPI/Controllers/CJGL/Cj_SingleStationController.cs
index 5346ce3..f568446 100644
--- a/WebAPI/Controllers/CJGL/Cj_SingleStationController.cs
+++ b/WebAPI/Controllers/CJGL/Cj_SingleStationController.cs
@@ -204,30 +204,34 @@
 
                 ds = oCN.RunProcReturn("exec h_p_Gy_BarCodeBillBomList '" + mainList[0].HProcExchBillNo + "'," + mainList[0].HProcID, "h_p_Gy_BarCodeBillBomList");
 
-                string jsonstr = JsonConvert.SerializeObject(ds.Tables[0]);
+                if (ds.Tables[0].Rows.Count > 0) {
 
-                //淇濆瓨鐢熶骇缁勮鍗曚富琛�
-                string sql = $@"Insert Into Sc_AssemblyBillMain(HYear,HPeriod,HBillType,HBillSubType,HInterID,HDate
+                    string jsonstr = JsonConvert.SerializeObject(ds.Tables[0]);
+
+                    //淇濆瓨鐢熶骇缁勮鍗曚富琛�
+                    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(),{mainList[0].HProcExchInterID.ToString()},{mainList[0].HProcExchEntryID.ToString()},'{mainList[0].HProcExchBillNo.ToString()}'
 ,{mainList[0].HICMOInterID.ToString()},'{mainList[0].HICMOBillNo.ToString()}','{mainList[0].HBarCode.ToString()}',{mainList[0].HMaterID},0,'姹囨姤',{mainList[0].HProdOrgID})";
-                oCN.RunProc(sql);
+                    oCN.RunProc(sql);
 
-                List<Model.ClsSc_AssemblyBillSub> sub = new List<Model.ClsSc_AssemblyBillSub>();
-                sub = JsonConvert.DeserializeObject<List<Model.ClsSc_AssemblyBillSub>>(jsonstr);
+                    List<Model.ClsSc_AssemblyBillSub> sub = new List<Model.ClsSc_AssemblyBillSub>();
+                    sub = JsonConvert.DeserializeObject<List<Model.ClsSc_AssemblyBillSub>>(jsonstr);
 
-                for (int i = 0; i < sub.Count; i++)
-                {
-                    //瀛愯〃瀛樺偍
-                    string sq2 = $@"Insert Into Sc_AssemblyBillSub(HInterID,HBillNo_bak,HEntryID,HSourceInterID,HSourceEntryID,HSourceBillNo
+                    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}','{mainList[0].HBarCode}','') ";
-                    oCN.RunProc(sq2);
+                        oCN.RunProc(sq2);
+                    }
+
                 }
 
 
@@ -466,6 +470,7 @@
                 }
 
                 oCN.BeginTran();
+                string sExeReturnInfo = "";
 
                 ClsSc_AssemblyBillMain omodel = new ClsSc_AssemblyBillMain();
                 omodel = JsonConvert.DeserializeObject<ClsSc_AssemblyBillMain>(sMainStr);
@@ -475,6 +480,7 @@
 
 
                 ds = oCN.RunProcReturn("select  * from h_v_Gy_QualifiedRecordsList where 浜у搧鏉$爜='" + omodel.HBarCode_P + "' and HProcExchInterID="+ omodel .HProcExchInterID+ " and HProcExchEntryID="+ omodel.HProcExchEntryID + " and HProcID="+ omodel.HProcID, "h_v_Gy_QualifiedRecordsList");
+
                 if (ds.Tables[0].Rows.Count > 0)
                 {
                     objJsonResult.code = "0";
@@ -578,10 +584,13 @@
                 double HProcPriceRate = 0;//宸ヤ环绯绘暟
                 int HTemporaryAreaID = 0;//鏆傛斁鍖�
 
-                ds = oCN.RunProcReturn("select  * from Sc_StationOutBillMain a left join  Sc_StationOutBillSub_SN sn on a.HInterID=sn.HInterID where a.HInterID=" + HInterID + " and HBillNo='" + HBillNo + "'", "Sc_StationOutBillMain");
+                ds = oCN.RunProcReturn("select  * from Sc_StationOutBillMain a left join  Sc_StationOutBillSub_SN sn on a.HInterID=sn.HInterID where a.HInterID=" + HInterID + " and HBillNo='" + HBillNo + "' and CONVERT(varchar(10),HDate,20) ='" + DateTime.Now.ToString("yyyy-MM-dd") + "' ", "Sc_StationOutBillMain");
 
                 if (ds.Tables[0].Rows.Count == 0)
                 {
+                    HInterID = DBUtility.ClsPub.CreateBillID("3791", ref sExeReturnInfo);//閫掑叆type寰楀埌鐨勫崟鎹甀D
+                    HBillNo = DBUtility.ClsPub.CreateBillCode_Prod("3791", ref sExeReturnInfo, true);//閫掑叆type寰楀埌鐨勫崟鎹彿
+
                     oCN.RunProc("Insert Into Sc_StationOutBillMain " +
                     "(HBillType,HBillSubType,HInterID,HBillNo,HBillStatus,HDate,HMaker,HMakeDate,HMouldNum" +
                     ",HYear,HPeriod,HRemark,HSourceName,HPieceQty,HWasterQty,HPlanPieceQty,HBadPNL" +
@@ -609,7 +618,7 @@
                 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 == 0 ? 1 : int.Parse(ds.Tables[0].Rows[0]["HEntryID"].ToString()) + 1)}, '{omodel.HBarCode_P}', 1, GETDATE(), '', " + HProcExchInterID + ","+ HProcExchEntryID + ", '"+ HProcExchBillNo + "', '', 0, 0)");
+values({HInterID}, '{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);
@@ -1039,7 +1048,7 @@
                 string HProcExchInterID = ds.Tables[0].Rows[0]["HProcExchInterID"].ToString();
                 string HProcExchEntryID = ds.Tables[0].Rows[0]["HProcExchEntryID"].ToString();
                 string HBarCode = ds.Tables[0].Rows[0]["HBarCode"].ToString();
-
+                string HDate = ds.Tables[0].Rows[0]["鏃ユ湡"].ToString();
 
                 oCN.BeginTran();
 
@@ -1055,7 +1064,9 @@
                 oCN.RunProc(sql);
 
                 //鍙嶅啓宸ュ簭鍑虹珯鍗曠殑涓嶈壇鏁伴噺
-                oCN.RunProc("update Sc_StationOutBillMain set HBadCount-=1  where HProcExchInterID='" + HProcExchInterID + "' and HProcExchEntryID=" + HProcExchEntryID);
+                oCN.RunProc(@"update Sc_StationOutBillMain set HBadCount-=1 where HProcExchInterID='" + HProcExchInterID + "' and HProcExchEntryID='" + HProcExchEntryID + "' " +
+                    "and HBillNo = (select HBillNo from Sc_StationOutBillMain " +
+                    "where HProcExchInterID = '" + HProcExchInterID + "' and HProcExchEntryID = '" + HProcExchEntryID + "'  and convert(varchar(10), HDate, 20) = '" + DateTime.Parse(HDate).ToString("yyyy-MM-dd") + "' and HBadCount > 0)");
                 //鍙嶅啓娴佽浆鍗$姸鎬�
                 oCN.RunProc("update Gy_BarCodeBill set HStatus=''  where HBarCode='" + HBarCode + "'");
 

--
Gitblit v1.9.1