From 63be464a9bfbfa9412fa7809612418c150eab478 Mon Sep 17 00:00:00 2001
From: wtt <1985833171@qq.com>
Date: 星期五, 24 十月 2025 13:36:15 +0800
Subject: [PATCH] 1

---
 WebAPI/Controllers/仓存管理/条码生成/Sc_BarCodeController.cs |  159 ++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 120 insertions(+), 39 deletions(-)

diff --git "a/WebAPI/Controllers/\344\273\223\345\255\230\347\256\241\347\220\206/\346\235\241\347\240\201\347\224\237\346\210\220/Sc_BarCodeController.cs" "b/WebAPI/Controllers/\344\273\223\345\255\230\347\256\241\347\220\206/\346\235\241\347\240\201\347\224\237\346\210\220/Sc_BarCodeController.cs"
index c0346c1..e4ad3e2 100644
--- "a/WebAPI/Controllers/\344\273\223\345\255\230\347\256\241\347\220\206/\346\235\241\347\240\201\347\224\237\346\210\220/Sc_BarCodeController.cs"
+++ "b/WebAPI/Controllers/\344\273\223\345\255\230\347\256\241\347\220\206/\346\235\241\347\240\201\347\224\237\346\210\220/Sc_BarCodeController.cs"
@@ -25,6 +25,7 @@
         public WebServer webserver = new WebServer();
         SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
         private WebS.WebService1 oWebs = new WebS.WebService1();
+        public WebS.ClsKf_ICStockBill_WMS WebSoBar = new WebS.ClsKf_ICStockBill_WMS();
         //鑾峰彇绯荤粺鍙傛暟
         Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
         public Int64 HInterID = 0;      //鍐呯爜
@@ -909,6 +910,8 @@
             string HSupNumber = ""; // 渚涘簲鍟嗙紪鐮�
             string HPOInStockBillNo = ""; // 鏀舵枡閫氱煡鍗曞彿
 
+            string HPOOrderBillNo = ""; // 閲囪喘璁㈠崟鍙�
+
             DataSet Ds;
             msg2 = msg2.Replace("\\", "");
             msg2 = msg2.Replace("\n", "");  //\n
@@ -959,6 +962,8 @@
                     
                     HPOInStockBillNo = DBUtility.ClsPub.isStrNull(ordrlist[j].HBillNo); // 鏀舵枡閫氱煡鍗曞彿 鍏磋揪鏉$爜
                     HSupNumber = DBUtility.ClsPub.isStrNull(ordrlist[j].HSupNumber);// 渚涘簲鍟嗙紪鍙� 鍏磋揪鏉$爜
+
+                    HPOOrderBillNo = DBUtility.ClsPub.isStrNull(ordrlist[j].HBillNo); // 閲囪喘璁㈠崟鍙� 灏忓崼鐢靛櫒
                     //
                     sYear = ClsPub.isDate(sDate).Year.ToString().Substring(2, 2);
                     sPeriod = "0" + ClsPub.isDate(sDate).Month.ToString();
@@ -1069,6 +1074,14 @@
                             Ds = oCN.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //鑾峰彇鏈�澶ф祦姘村彿
                             LSH = ClsPub.isLong(Ds.Tables[0].Rows[0][0]);
                             LSHlen = 3; // 涓変綅娴佹按鍙�
+                        }
+                        else if (CampanyName.Contains("灏忓崼"))
+                        {
+                            // 灏忓崼鐢靛櫒
+                            // 鏉$爜鍓嶇紑 = 鍗曟嵁鍙� + 鐗╂枡缂栫爜 + 鎵规鍙�
+                            sTMNumber = HPOOrderBillNo + "@" + HMaterNumber + "@" + HBatchNo;
+                            Ds = oCN.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //鑾峰彇鏈�澶ф祦姘村彿
+                            LSH = ClsPub.isLong(Ds.Tables[0].Rows[0][0]);
                         }
                         else  //閫氱敤鏂规硶
                         {
@@ -1892,12 +1905,12 @@
         #region [鑾峰彇鏍囩鎵撳嵃鎸囦护 CPCL鎸囦护]
         [Route("Sc_BarCode/Get_BarCodePrintCode_CPCL")]
         [HttpGet]
-        public object Get_BarCodePrintCode_CPCL(string HOrginationName, string HViewName, string HBillSubType, int HInterID, int HItemID)
+        public object Get_BarCodePrintCode_CPCL(string HOrginationName, string HBillSubType, int HInterID, int HItemID)
         {
             try
             {
                 ds = oCN.RunProcReturn("exec h_p_getHBarCodePrintCode_CPCL N'" + HOrginationName + "'" +
-                   ",N'" + HViewName + "',N'" + HBillSubType + "'," + HInterID + "," + HItemID, "h_p_getHBarCodePrintCode_CPCL");
+                   ",N'" + HBillSubType + "'," + HInterID + "," + HItemID, "h_p_getHBarCodePrintCode_CPCL");
                 if((int)ds.Tables[0].Rows[0]["resultType"] == 1)
                 {
                     string resultMesg = ds.Tables[0].Rows[0]["payload"].ToString().Replace("\\r\\n", "\r\n");
@@ -2525,64 +2538,86 @@
         {
             try
             {
-                SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
-                //鏌ヨ鏉$爜淇℃伅
-                if (HBarCodeNo != null)
+                if (string.IsNullOrWhiteSpace(HBarCodeNo))
                 {
-                    string prefix = HBarCodeNo.Trim() + "-";
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "璇疯緭鍏ユ潯鐮佺紪鍙�";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
 
-                    ds = oCn.RunProcReturn("SELECT * FROM h_v_Gy_SplitBarCode WITH(NOLOCK) WHERE HBarCode LIKE '" + prefix + "' + '%' AND HBarCode NOT LIKE  '" + prefix + "'  + '%-%' AND ISNUMERIC(RIGHT(HBarCode, LEN(HBarCode) - LEN( '" + prefix + "' ))) = 1  AND TRY_CAST(RIGHT(HBarCode, LEN(HBarCode) - LEN( '" + prefix + "' )) AS INT) IS NOT NULL ", "Gy_BarCodeBill");
-                    if (ds != null || ds.Tables[0].Rows.Count >= 0) 
+                // 鍘荤┖鏍�
+                string cleanBarCode = HBarCodeNo.Trim();
+                string prefix = cleanBarCode + "-"; // 鐢ㄤ簬鏌ュ瓙鐮�
+
+                SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
+
+                // 1. 鍏堟煡鐩存帴瀛愮爜锛堜竴绾у瓙鐮侊細xxx-1, xxx-2, ...锛�
+                string sqlSub = @"SELECT * FROM h_v_Gy_SplitBarCode WITH(NOLOCK) WHERE HBarCode LIKE '" + prefix + @"%' 
+                AND HBarCode NOT LIKE '" + prefix + @"%-%'
+                AND ISNUMERIC(RIGHT(HBarCode, LEN(HBarCode) - LEN('" + prefix + @"'))) = 1
+                AND TRY_CAST(RIGHT(HBarCode, LEN(HBarCode) - LEN('" + prefix + @"')) AS INT) IS NOT NULL";
+
+                DataSet ds = oCn.RunProcReturn(sqlSub, "Gy_BarCodeBill");
+
+                // 2. 濡傛灉鏈夊瓙鐮� 鈫� 杩斿洖瀛愮爜 + 涓嬩竴涓紪鍙�
+                if (ds != null && ds.Tables[0].Rows.Count > 0)
+                {
+                    int maxSuffix = 0;
+                    foreach (DataRow row in ds.Tables[0].Rows)
                     {
-                        // 鎵惧嚭鏈�澶у悗缂�鏁板瓧锛岀敤浜庣敓鎴愪笅涓�涓紪鍙�
-                        int maxSuffix = 0;
-                        foreach (DataRow row in ds.Tables[0].Rows)
-                        {
-                            string barCode = row["HBarCode"].ToString();
-                            string suffixPart = barCode.Substring(prefix.Length); // 鍙� - 鍚庣殑閮ㄥ垎
-                            if (int.TryParse(suffixPart, out int num))
-                            {
-                                if (num > maxSuffix) maxSuffix = num;
-                            }
-                        }
+                        string barCode = row["HBarCode"].ToString();
+                        string suffix = barCode.Substring(prefix.Length);
+                        if (int.TryParse(suffix, out int num) && num > maxSuffix)
+                            maxSuffix = num;
+                    }
 
-                        // 鐢熸垚涓嬩竴涓瓙鐮佺紪鍙�
-                        string nextBarCode = $"{HBarCodeNo}-{maxSuffix + 1}";
+                    string nextBarCode = $"{cleanBarCode}-{maxSuffix + 1}";
 
+                    objJsonResult.code = "1";
+                    objJsonResult.count = ds.Tables[0].Rows.Count;
+                    objJsonResult.Message = "鏌ヨ鎴愬姛锛岃繑鍥炵洿鎺ュ瓙鐮�";
+                    objJsonResult.data = new
+                    {
+                        SubBarCodes = ds.Tables[0],
+                        NextBarCode = nextBarCode
+                    };
+                }
+                else
+                {
+                    // 3. 娌℃湁瀛愮爜 鈫� 鏌ヨ嚜宸�
+                    string sqlSelf = @"SELECT * FROM h_v_Gy_SplitBarCode WITH(NOLOCK)  WHERE HBarCode = '" + cleanBarCode.Replace("'", "''") + "'";
+
+                    DataSet dsSelf = oCn.RunProcReturn(sqlSelf, "Gy_BarCodeBill");
+
+                    if (dsSelf != null && dsSelf.Tables[0].Rows.Count > 0)
+                    {
                         objJsonResult.code = "1";
                         objJsonResult.count = 1;
-                        objJsonResult.Message = "Sucess锛�";
+                        objJsonResult.Message = "璇ユ潯鐮佹棤瀛愮爜锛岃繑鍥炶嚜韬�";
                         objJsonResult.data = new
                         {
-                            SubBarCodes = ds.Tables[0],        // 鏉$爜鍩虹淇℃伅
-                            NextBarCode = nextBarCode          // 涓嬩竴涓敓鎴愮殑鏉$爜
+                            SubBarCodes = dsSelf.Tables[0],
+                            NextBarCode = $"{cleanBarCode}-1"  // 寤鸿浠� -1 寮�濮�
                         };
-                        return objJsonResult;
                     }
                     else
                     {
                         objJsonResult.code = "0";
                         objJsonResult.count = 0;
-                        objJsonResult.Message = "鏉$爜缂栧彿涓嶅瓨鍦�, 鎻愮ず";
+                        objJsonResult.Message = "鏉$爜涓嶅瓨鍦紝璇锋鏌�";
                         objJsonResult.data = null;
-                        return objJsonResult;
-                    }                                       
+                    }
                 }
-                else
-                {
-                    objJsonResult.code = "0";
-                    objJsonResult.count = 0;
-                    objJsonResult.Message = "璇疯緭鍏ユ潯鐮佺紪鍙锋垨鎷嗗垎鏉$爜鏁�";
-                    objJsonResult.data = null;
-                    return objJsonResult;
-                }
-               
+
+                return objJsonResult;
             }
-            catch (Exception e) //鎶涘嚭寮傚父
+            catch (Exception ex)
             {
                 objJsonResult.code = "0";
                 objJsonResult.count = 0;
-                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.Message = "寮傚父锛�" + ex.Message;
                 objJsonResult.data = null;
                 return objJsonResult;
             }
@@ -2715,6 +2750,52 @@
         }
         #endregion
 
+        #region [鏉$爜鐢熸垚鎺ュ彛_灏忓崼闀洉鐮乚
+        [Route("Sc_BarCode/SaveSNByICMO_XW")]
+        [HttpGet]
+        public object SaveSNByICMO_XW(String HBillNo,string HSN, int HBeginNo, int HEndNo, int HCount)
+        {
+            try
+            {
+                WebSoBar = oWebs.GetWebAPIToLocal_ICMO(HBillNo,'3710','admin', ref DBUtility.ClsPub.sErrInfo);
+                //ds = oCN.RunProcReturn("exec h_p_WMS_GetSNByICMO_XW '" + HCount + "', "+ HSeq, "h_p_WMS_GetSNByICMO_XW");
+
+                //if (ds == null)
+                //{
+                //    objJsonResult.code = "0";
+                //    objJsonResult.count = 0;
+                //    objJsonResult.Message = "[0000-2-020]娌℃湁杩斿洖浠讳綍缁撴灉,鏉$爜淇濆瓨澶辫触锛�";
+                //    objJsonResult.data = null;
+                //    return objJsonResult;
+                //}
+                //if (DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBack"]) != "0")
+                //{
+                //    objJsonResult.code = "0";
+                //    objJsonResult.count = 0;
+                //    objJsonResult.Message = ds.Tables[0].Rows[0]["HRemark"].ToString();
+                //    objJsonResult.data = null;
+                //    return objJsonResult;
+                //}
+
+
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "[0000-1-037]鏉$爜鐢熸垚鎴愬姛锛�";
+                objJsonResult.data = null;
+                return objJsonResult;
+                
+                
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "[3899-2-006]鏉$爜鐢熸垚澶辫触!" + e.Message;
+                return objJsonResult;
+            }
+        }
+        #endregion        
+
         #endregion
     }
 }
\ No newline at end of file

--
Gitblit v1.9.1