From aa6c2ce07e6a8a99d3d861ce5fae8fa76f62d36f Mon Sep 17 00:00:00 2001
From: kyy <3283105747@qq.com>
Date: 星期四, 04 十二月 2025 09:31:26 +0800
Subject: [PATCH] 1、期初入库库位判断

---
 service/Warehouse/InventoryManager.cs |  126 ++++++++++++++++++++++++++++++-----------
 1 files changed, 91 insertions(+), 35 deletions(-)

diff --git a/service/Warehouse/InventoryManager.cs b/service/Warehouse/InventoryManager.cs
index 7fab709..cdf59e8 100644
--- a/service/Warehouse/InventoryManager.cs
+++ b/service/Warehouse/InventoryManager.cs
@@ -8,6 +8,7 @@
 using System.Data;
 using System.Data.SqlClient;
 using System.Dynamic;
+ 
 using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
 
 namespace NewPdaSqlServer.service.Warehouse;
@@ -52,53 +53,108 @@
         var p_bill_type_id = 100;
         var p_transction_no = 601;
 
-        // 妫�鏌ュ簱浣嶄唬鐮佹槸鍚︿负绌�
-        // if (string.IsNullOrEmpty(p_section_code))
-        //     throw new Exception("002[璇锋壂搴撲綅鏉$爜锛�");
+
+
 
         // 鏌ヨ搴撳尯搴撲綅淇℃伅
-        var depotSection = Db.Queryable<MesDepotSections, MesDepots>((a, b) =>
-                new JoinQueryInfos(
-                    JoinType.Inner, a.DepotGuid == b.Guid
-                ))
-            .Where((a, b) => a.DepotSectionCode == p_section_code)
-            .Select((a, b) => new
-                { a.DepotSectionName, b.DepotCode, b.DepotName, b.DepotId,b.FSubsidiary })
-            .Single();
+        /* var depotSection = Db.Queryable<MesDepotSections, MesDepots>((a, b) =>
+                 new JoinQueryInfos(
+                     JoinType.Inner, a.DepotGuid == b.Guid
+                 ))
+             .Where((a, b) => a.DepotSectionCode == p_section_code)
+             .Select((a, b) => new
+             {
+                 a.DepotSectionName,
+                 b.DepotCode,
+                 b.DepotName,
+                 b.DepotId,
+                 b.FSubsidiary
+             })
+             .Single();*/
 
-        // 濡傛灉搴撲綅浠g爜涓嶅瓨鍦紝鍒欒繑鍥為敊璇俊鎭�
-        // if (depotSection == null)
-        //     throw new Exception("搴撲綅缂栫爜 " + p_section_code + " 涓嶅瓨鍦紝璇风‘璁わ紒");
+        // ============================
+        // 鏇挎崲锛氫娇鐢ㄥ師鐢� SqlConnection + SqlCommand 璋冪敤瀛樺偍杩囩▼锛堝弬鑰� SaveBarCodes 鏂规硶椋庢牸锛�
+        // ============================
+        string connectionString = DbHelperSQL.strConn; // 澶嶇敤鍙傝�冧唬鐮佷腑鐨勮繛鎺ュ瓧绗︿覆鑾峰彇鏂瑰紡
+        int po_depotId = 0;
+        string po_depotNo = string.Empty;
+        string po_depotName = string.Empty;
+        string po_fSubsidiary = string.Empty;
+        string po_outMsg = string.Empty;
+        int po_outSum = -1;
 
-        // 妫�鏌ユ槸鍚﹀凡缁忔敹璐�
-        // var c_num = Db.Queryable<MesInvItemIns, MesInvItemInCDetails>((a, b) =>
-        //         new JoinQueryInfos(
-        //             JoinType.Inner, a.Guid == b.ItemInId
-        //         ))
-        //     .Where((a, b) => b.ItemBarcode == p_item_barcode)
-        //     .Count();
-
-        // if (c_num > 0) throw new Exception("002[鏉$爜閲嶅鎵弿锛岃鏍稿锛�");
-
-        // 鏌ヨ鏉$爜淇℃伅
-        // c_num = Db.Queryable<MesInvItemStocks>()
-        //     .Where(t => t.ItemBarcode == p_item_barcode)
-        //     .Count();
-
-        // if (c_num > 0) throw new Exception("002[鏉$爜宸插湪搴撳瓨涓紝璇锋牳瀵癸紒");
+ 
+   
 
         // 鏌ヨ鏉$爜璇︾粏淇℃伅
         var c_mes_inv_item_barcodes = Db.Queryable<MesInvItemBarcodes>()
             .Where(t => t.ItemBarcode == p_item_barcode)
             .Single();
 
-        // if (c_mes_inv_item_barcodes == null)
-        //     throw new Exception("002[鏉$爜涓嶅瓨鍦紝璇锋牳瀵癸紒");
-
         if (c_mes_inv_item_barcodes.Memo != "鍒濇湡鐗╂枡")
             throw new Exception("002[鏉$爜涓嶆槸鏈熷垵鏉$爜锛屾棤娉曠敤鏈熷垵鍏ュ簱锛�");
 
-        var wmsManager = new WmsBaseMangeer();
+        using (var conn = new SqlConnection(connectionString))
+        {
+            using (var cmd = new SqlCommand("prc_pda_select_depot", conn))
+            {
+                try
+                {
+                    conn.Open();
+                    cmd.CommandType = CommandType.StoredProcedure;
+
+                    // 璁剧疆瀛樺偍杩囩▼鍙傛暟锛堣緭鍏�+杈撳嚭锛�
+                    SqlParameter[] parameters =
+                    {
+                    // 杈撳叆鍙傛暟
+                    new SqlParameter("@pi_code", SqlDbType.NVarChar, 100) { Value = p_item_barcode },
+                    new SqlParameter("@pi_sectionCode", SqlDbType.NVarChar, 100) { Value = p_section_code },
+                    // 杈撳嚭鍙傛暟
+                    new SqlParameter("@po_depotId", SqlDbType.Int) { Direction = ParameterDirection.Output },
+                    new SqlParameter("@po_depotNo", SqlDbType.NVarChar, 80) { Direction = ParameterDirection.Output },
+                    new SqlParameter("@po_depotName", SqlDbType.NVarChar, 80) { Direction = ParameterDirection.Output },
+                    new SqlParameter("@po_fSubsidiary", SqlDbType.NVarChar, 80) { Direction = ParameterDirection.Output },
+                    new SqlParameter("@po_outMsg", SqlDbType.NVarChar, 2000) { Direction = ParameterDirection.Output },
+                    new SqlParameter("@po_outSum", SqlDbType.Int) { Direction = ParameterDirection.Output }
+                };
+
+                    cmd.Parameters.AddRange(parameters);
+                    cmd.ExecuteNonQuery();
+
+                    // 鑾峰彇杈撳嚭鍙傛暟鍊硷紙娉ㄦ剰锛氶渶鍒ゆ柇 DBNull锛岄伩鍏嶇┖寮曠敤寮傚父锛�
+                    po_depotId = parameters[2].Value != DBNull.Value ? Convert.ToInt32(parameters[2].Value) : 0;
+                    po_depotNo = parameters[3].Value != DBNull.Value ? parameters[3].Value.ToString() : string.Empty;
+                    po_depotName = parameters[4].Value != DBNull.Value ? parameters[4].Value.ToString() : string.Empty;
+                    po_fSubsidiary = parameters[5].Value != DBNull.Value ? parameters[5].Value.ToString() : string.Empty;
+                    po_outMsg = parameters[6].Value != DBNull.Value ? parameters[6].Value.ToString() : string.Empty;
+                    po_outSum = parameters[7].Value != DBNull.Value ? Convert.ToInt32(parameters[7].Value) : -1;
+                }
+                catch (Exception ex)
+                {
+                    throw new Exception($"璋冪敤瀛樺偍杩囩▼ prc_pda_select_depot 澶辫触锛歿ex.Message}");
+                }
+            }
+        }
+
+        // 楠岃瘉瀛樺偍杩囩▼鎵ц缁撴灉
+        if (po_outSum < 0 || string.IsNullOrEmpty(po_depotNo) || po_depotId <= 0)
+        {
+            throw new Exception(string.IsNullOrEmpty(po_outMsg) ? "鑾峰彇浠撳簱淇℃伅澶辫触锛岃妫�鏌ユ潯鐮佸拰搴撲綅鏄惁姝g‘" : po_outMsg);
+        }
+
+        // 鏋勯�犱笌鍘� depotSection 缁撴瀯涓�鑷寸殑瀵硅薄锛岀‘淇濆悗缁唬鐮佸吋瀹�
+        var depotSection = new
+        {
+            // DepotSectionName = string.Empty, // 瀛樺偍杩囩▼鏈繑鍥炲簱浣嶅悕绉帮紝濡傞渶浣跨敤鍙悗缁ˉ鍏�
+            DepotCode = po_depotNo,          // 瀵瑰簲瀛樺偍杩囩▼鐨� po_depotNo锛堜粨搴撶紪鐮侊級
+            DepotName = po_depotName,        // 瀵瑰簲瀛樺偍杩囩▼鐨� po_depotName锛堜粨搴撳悕绉帮級
+            DepotId = po_depotId,            // 瀵瑰簲瀛樺偍杩囩▼鐨� po_depotId锛堜粨搴揑D锛�
+            FSubsidiary = po_fSubsidiary     // 瀵瑰簲瀛樺偍杩囩▼鐨� po_fSubsidiary锛堢粍缁囷級
+        };
+
+
+        //鐢变簬榫欏穽鍏ュ簱鍙笉鎸変粨浣嶅搴斾粨搴撴潵鎵�浠ョ壒姝ゅ彇娑堟鏍¢獙
+/*        var wmsManager = new WmsBaseMangeer();
         // 鏂板鍏ュ簱鏍¢獙锛堣皟鐢ㄥ瓨鍌ㄨ繃绋嬶級
         var checkResult = wmsManager.pdaInvJY(
             db: Db,
@@ -112,7 +168,7 @@
         );
         
         if ( Convert.ToInt32(checkResult.result) < 1) 
-            throw new Exception($"鍏ュ簱鏍¢獙澶辫触锛歿checkResult.strMsg}");
+            throw new Exception($"鍏ュ簱鏍¢獙澶辫触锛歿checkResult.strMsg}");*/
 
         UseTransaction(db =>
         {

--
Gitblit v1.9.3