From 62a125536867798e695acb5743598345540266d8 Mon Sep 17 00:00:00 2001
From: duhe <226547893@qq.com>
Date: 星期日, 05 五月 2024 19:36:03 +0800
Subject: [PATCH] 条码自动生成:根据产品当天的生产数获取产品条码的最大流水号

---
 LMES/bin/x86/Debug.zip                             |    0 
 WarM/条码打印/Gy_BarCodeBill_automaticallyByPLC_New.cs |   50 +++++++++++++++++++++++++++++++-------------------
 2 files changed, 31 insertions(+), 19 deletions(-)

diff --git a/LMES/bin/x86/Debug.zip b/LMES/bin/x86/Debug.zip
new file mode 100644
index 0000000..3cce815
--- /dev/null
+++ b/LMES/bin/x86/Debug.zip
Binary files differ
diff --git "a/WarM/\346\235\241\347\240\201\346\211\223\345\215\260/Gy_BarCodeBill_automaticallyByPLC_New.cs" "b/WarM/\346\235\241\347\240\201\346\211\223\345\215\260/Gy_BarCodeBill_automaticallyByPLC_New.cs"
index 5b895f1..6da5b7b 100644
--- "a/WarM/\346\235\241\347\240\201\346\211\223\345\215\260/Gy_BarCodeBill_automaticallyByPLC_New.cs"
+++ "b/WarM/\346\235\241\347\240\201\346\211\223\345\215\260/Gy_BarCodeBill_automaticallyByPLC_New.cs"
@@ -966,28 +966,40 @@
             string LIU = "";
             int LEN = 4;
 
-            //鑾峰彇褰撴棩鏈骇鍝佹潯鐮佺紪鍙锋渶澶х殑璁板綍
-            DataSet ds;
-            string sql = "select * from h_v_IF_BarCodeBillList Where HMaterID = " + grdMain.Rows[0].Cells[HMaterIDCol].Value + " and HSTOCKORGID = " + HOrgID + " and CONVERT(varchar(100),鏉$爜鏃ユ湡, 23) = '" + HDate + "' order by 鏉$爜缂栧彿 desc";
-            ds = oCn.RunProcReturn(sql, "h_v_IF_BarCodeBillList");
-            if (ds != null)
+            //鑾峰彇浜у搧鏉$爜澶囦唤琛ㄤ腑褰撴棩鏈骇鍝佹潯鐮佺紪鍙锋渶澶х殑璁板綍
+            long HMaxNo_Bak = 0;                //璁板綍浜у搧鏉$爜澶囦唤琛ㄤ腑褰撴棩鏈骇鍝佹潯鐮佺紪鍙锋渶澶х殑璁板綍鐨勬潯鐮佺紪鍙风殑娴佹按鍙�
+            DataSet ds1;
+            string sql1 = "select * from Gy_BarCodeBill_SWELL_SubBarCodeBill Where HMaterID = " + grdMain.Rows[0].Cells[HMaterIDCol].Value + " and HSTOCKORGID = " + HOrgID + " and CONVERT(varchar(100),HBarCodeDate, 23) = '" + HDate + "' and HInterID <>0 order by HBarCode desc";
+            ds1 = oCn.RunProcReturn(sql1, "Gy_BarCodeBill_SWELL_SubBarCodeBill");
+            if (ds1 != null && ds1.Tables[0].Rows.Count>0)
             {
-                long count = 0;
-                if (ds.Tables[0].Rows.Count > 0)
-                {
-                    string HBarCodeMaxNo = ds.Tables[0].Rows[0]["鏉$爜缂栧彿"].ToString();
-                    HBarCodeMaxNo = HBarCodeMaxNo.Substring(HBarCodeMaxNo.Length - LEN, LEN);
-                    count = ClsPub.isLong(HBarCodeMaxNo);
-                }
-                LIU += count + 1;
-                while (LIU.Length < LEN)  //濡傛灉娴佹按鍙峰皬浜�6浣嶆暟鍓嶉潰琛�0
-                {
-                    LIU = "0" + LIU;
-                }
+                string HBarCodeMaxNo = ds1.Tables[0].Rows[0]["HBarCode"].ToString();
+                HBarCodeMaxNo = HBarCodeMaxNo.Substring(HBarCodeMaxNo.Length - LEN, LEN);
+                HMaxNo_Bak = ClsPub.isLong(HBarCodeMaxNo);
             }
-            else
+
+            ////鑾峰彇鏉$爜妗f涓綋鏃ユ湰浜у搧鏉$爜缂栧彿鏈�澶х殑璁板綍
+            long HMaxNo = 0;                //璁板綍鏉$爜妗f涓綋鏃ユ湰浜у搧鏉$爜缂栧彿鏈�澶х殑璁板綍鐨勬潯鐮佺紪鍙风殑娴佹按鍙�
+            DataSet ds;
+            string sql = "select * from h_v_IF_BarCodeBillList Where HMaterID = " + grdMain.Rows[0].Cells[HMaterIDCol].Value + " and HSTOCKORGID = " + HOrgID + " and CONVERT(varchar(100),鏉$爜鏃ユ湡, 23) = '" + HDate + "' and HInterID <> 0 order by 鏉$爜缂栧彿 desc";
+            ds = oCn.RunProcReturn(sql, "h_v_IF_BarCodeBillList");
+            if (ds != null && ds.Tables[0].Rows.Count > 0)
             {
-                return "";
+                string HBarCodeMaxNo = ds.Tables[0].Rows[0]["鏉$爜缂栧彿"].ToString();
+                HBarCodeMaxNo = HBarCodeMaxNo.Substring(HBarCodeMaxNo.Length - LEN, LEN);
+                HMaxNo = ClsPub.isLong(HBarCodeMaxNo);
+            }
+
+
+            //鑾峰彇褰撴棩鏈骇鍝� 鍦ㄦ潯鐮佹。妗堝拰浜у搧鏉$爜澶囦唤琛ㄤ腑 鏈�澶х殑娴佹按鍙�
+            long count = 0;
+            count = HMaxNo >= HMaxNo_Bak ? HMaxNo : HMaxNo_Bak;
+
+            //涓烘祦姘村彿鍓嶉潰琛ラ浂
+            LIU += count + 1;
+            while (LIU.Length < LEN)  //濡傛灉娴佹按鍙峰皬浜�6浣嶆暟鍓嶉潰琛�0
+            {
+                LIU = "0" + LIU;
             }
 
             //鎷兼帴鎵瑰彿

--
Gitblit v1.9.1