From 2ee2d1c8c05fce44e3e01ea8bcf8c81fab88afb0 Mon Sep 17 00:00:00 2001
From: zrg <z1873@LAPTOP-EAVL132E>
Date: 星期一, 02 二月 2026 14:10:40 +0800
Subject: [PATCH] 优化拆分条码

---
 WebAPI/Controllers/CJGL/Cj_StationOutBillController.cs |   29 ++++++++++-------------------
 1 files changed, 10 insertions(+), 19 deletions(-)

diff --git a/WebAPI/Controllers/CJGL/Cj_StationOutBillController.cs b/WebAPI/Controllers/CJGL/Cj_StationOutBillController.cs
index efaf7e6..ebb3e72 100644
--- a/WebAPI/Controllers/CJGL/Cj_StationOutBillController.cs
+++ b/WebAPI/Controllers/CJGL/Cj_StationOutBillController.cs
@@ -1402,20 +1402,17 @@
                     oCN.RollBack();
                     objJsonResult.code = "0";
                     objJsonResult.count = 0;
-                    objJsonResult.Message = "淇濆瓨澶辫触锛佸崟寮犳潯鐮佹暟閲忓繀椤诲ぇ浜�0";
+                    objJsonResult.Message = "淇濆瓨澶辫触锛佹潯鐮佸紶鏁板繀椤诲ぇ浜�0";
                     objJsonResult.data = 1;
                     return objJsonResult;
                 }
 
-                // 璁$畻闇�瑕佺敓鎴愮殑鏉$爜鏁伴噺
-                int fullBarcodeCount = (int)(HQty / HPieceQty); // 瀹屾暣绠辨暟
-                decimal remainder = HQty % HPieceQty; // 浣欐暟
+                // 鍥哄畾鐢熸垚鎸囧畾寮犳暟鐨勬潯鐮�
+                int barcodeCount = (int)HPieceQty;  // HPieceQty 浣滀负鏉$爜寮犳暟
 
-                int barcodeCount = fullBarcodeCount;
-                if (remainder > 0)
-                {
-                    barcodeCount += 1; // 鏈変綑鏁版椂澧炲姞涓�寮犳潯鐮�
-                }
+                // 璁$畻姣忓紶鏉$爜鐨勫钩鍧囨暟閲�
+                decimal baseQty = Math.Floor(HQty / HPieceQty);
+                decimal remainder = HQty % HPieceQty;
 
                 // 鏌ヨ鍘熷鍗曟嵁淇℃伅
                 ds = oCN.RunProcReturn("select * from Sc_StationOutBillMain where HInterID='" + HInterID + "'", "Sc_StationOutBillMain");
@@ -1428,19 +1425,13 @@
                     for (int i = 0; i < barcodeCount; i++)
                     {
                         // 璁$畻褰撳墠鏉$爜鐨勬暟閲�
-                        decimal currentQty;
-                        if (i < fullBarcodeCount)
+                        decimal currentQty = baseQty;
+                        if (i < remainder)  // 濡傛灉鏈変綑鏁帮紝鍓峃寮犳潯鐮佸悇鍔�1
                         {
-                            // 鍓� fullBarcodeCount 寮犳潯鐮侊紝姣忓紶鏁伴噺涓� HPieceQty
-                            currentQty = HPieceQty;
-                        }
-                        else
-                        {
-                            // 鏈�鍚庝竴寮犳潯鐮侊紝鏁伴噺涓轰綑鏁�
-                            currentQty = remainder;
+                            currentQty += 1;
                         }
 
-                        // 鐢熸垚鏉$爜鍙凤紙鍙互鍦ㄥ師濮嬫潯鐮佸彿鍚庨潰鍔犲簭鍙凤級
+                        // 鐢熸垚鏉$爜鍙�
                         string barcodeNumber = row["HBillNO"].ToString() + (barcodeCount > 1 ? "-" + (i + 1).ToString() : "");
 
                         string sql = "insert into Gy_BarCodeBill (HInterID, HEntryID, HBarCode, HBarCodeType, HBarCodeSubType, HMaterID, HUnitID, HQty, HBatchNo, HSupID, HGroupID, HMaker, HMakeDate, " +

--
Gitblit v1.9.1