From 78af839e2e3dbe15283db12a816d54d31acb79c9 Mon Sep 17 00:00:00 2001
From: yusijie <ysj@hz-kingdee.com>
Date: 星期六, 13 九月 2025 22:15:45 +0800
Subject: [PATCH] 更新启用物料信息状态添加供应商过滤;新增送货物料信息物料id加组织过滤;条码档案数据信息处理;

---
 WebAPI/Controllers/MaterialHandingController.cs         |  153 ++++++++++++++++++++++++++++++++++++++++++++++++--
 WebAPI/Models/ClsGy_MaterialBarCodeBillModel.cs         |    1 
 WebAPI/Controllers/SRM_MaterialBarCodeBillController.cs |   26 ++++++--
 3 files changed, 164 insertions(+), 16 deletions(-)

diff --git a/WebAPI/Controllers/MaterialHandingController.cs b/WebAPI/Controllers/MaterialHandingController.cs
index c51e3cc..044dc29 100644
--- a/WebAPI/Controllers/MaterialHandingController.cs
+++ b/WebAPI/Controllers/MaterialHandingController.cs
@@ -278,7 +278,7 @@
             try
             {
                 //ds1鑾峰彇鐨剆ql鍚庢湡璁板緱鏀瑰洖渚涘簲鍟嗭紝淇敼浜�->渚涘簲鍟�
-                var ds1 = oCN.RunProcReturn("select * from h_v_Gy_UserMaterRelationEdit where 鐗╂枡浠g爜='" + HMaterID + "'" + "and 渚涘簲鍟嗕唬鐮�='" + SupID + "'", "h_v_Gy_UserMaterRelationEdit");
+                var ds1 = oCN.RunProcReturn("select * from h_v_Gy_UserMaterRelationEdit where 鐗╂枡浠g爜='" + HMaterID + "'" + "and HSupID ='" + SupID + "'", "h_v_Gy_UserMaterRelationEdit");
                 var ds = oCN.RunProcReturn("select * from Gy_Material where HNumber='" + HMaterID+ "'"+ " and HUSEORGID="+"'"+ OrganizationID+"'", "Gy_Material");
                 if(ds.Tables[0].Rows.Count == 0)
                 {
@@ -299,7 +299,8 @@
                 else
                 {
                     oCN.BeginTran();
-                    string sqlUpd = "UPDATE Gy_UserMaterRelation set HUseFlag=0 where HItemID=" + ds1.Tables[0].Rows[0]["HItemID"];
+                    string sqlUpd = "UPDATE a set a.HUseFlag=0 from Gy_UserMaterRelation a with(nolock) left join Gy_Material m with(nolock) " +
+                        "on a.HMaterID = m.HItemID  where a.HSupID=" + SupID + " and m.HNumber = '" + HMaterID + "'";
                     oCN.RunProc(sqlUpd);
                     oCN.Commit();
 
@@ -374,19 +375,25 @@
         {
             try
             {
+                //var _value = msg["msg"].ToString();
+                //string msg3 = _value.ToString();
+                ////string[] sArray = msg3.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
+                ////string msg1 = sArray[0].ToString();
+                ////string msg2 = sArray[1].ToString();
+                //string msg2 = msg3.ToString();
+
                 var _value = msg["msg"].ToString();
-                string msg3 = _value.ToString();
-                //string[] sArray = msg3.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
-                //string msg1 = sArray[0].ToString();
-                //string msg2 = sArray[1].ToString();
-                string msg2 = msg3.ToString();
+                string msg1 = _value.ToString();
+                string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
+                string msg2 = sArray[0].ToString();//
+                string OrganizationID = sArray[1].ToString();// 
 
                 //鍙嶅簭鍒楀寲
                 msg2 = "[" + msg2.ToString() + "]";
 
                 List<Model.Cls_MaterialHandingModel> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Model.Cls_MaterialHandingModel>>(msg2);
                 
-                var ds = oCN.RunProcReturn("select * from Gy_Material where HNumber='" + list[0].HMaterNumber + "'", "Gy_Material");
+                var ds = oCN.RunProcReturn("select * from Gy_Material where HNumber='" + list[0].HMaterNumber + "' and HUSEORGID = " + OrganizationID, "Gy_Material");
  
                 int HItemID =Convert.ToInt32(list[0].HItemID);
                 string HMaterNumber = list[0].HMaterNumber;
@@ -597,7 +604,137 @@
 
         }
         //#endregion
+        #region 涓婚〉闈㈠惎鐢�
+        [Route("MaterialHandingController/CheckMaterialCount")]
+        [HttpGet]
+        public object CheckMaterialCount(string HMaterID, string HSupID, int HInterID)
+        {
+            try
+            {
+                //妫�鏌ュ悓渚涘簲鍟嗕笅鏄惁鏈夊叾浠栫墿鏂�
+                string sql = "SELECT COUNT(*) as Count FROM Gy_UserMaterRelation " +
+                             "WHERE HMaterID = '" + HMaterID + "' AND HSupID = " + HSupID +
+                             " AND HItemID != " + HInterID;
+                var ds = oCN.RunProcReturn(sql, "Gy_UserMaterRelation");
+                int count = Convert.ToInt32(ds.Tables[0].Rows[0]["Count"]);
 
+                objJsonResult.code = "1";
+                objJsonResult.count = count;
+                objJsonResult.Message = "鏌ヨ鎴愬姛";
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "鏌ヨ澶辫触: " + e.Message;
+                return objJsonResult;
+            }
+        }
+
+        [Route("MaterialHandingController/OpenMaterial")]
+        [HttpGet]
+        public object OpenMaterial(int HInterID, int IsUse, string CurUserName, string HMaterID, string HSupID, int disableOthers)
+        {
+            try
+            {
+                var ds = oCN.RunProcReturn("SELECT * FROM Gy_UserMaterRelation WHERE HItemID=" + HInterID, "Gy_UserMaterRelation");
+
+                if (ds.Tables[0].Rows.Count == 0)
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鍗曟嵁涓嶅瓨鍦�!";
+                    return objJsonResult;
+                }
+
+                int currentUseFlag = Convert.ToInt32(ds.Tables[0].Rows[0]["HUseFlag"]);
+
+                // 妫�鏌ユ槸鍚﹀凡鍚敤
+                if (currentUseFlag == 1)
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鍗曟嵁宸插惎鐢�!涓嶈兘鍐嶆鍚敤锛�";
+                    return objJsonResult;
+                }
+
+                oCN.BeginTran();
+
+                // 濡傛灉鐢ㄦ埛閫夋嫨绂佺敤
+                if (disableOthers == 1)
+                {
+                    string disableSql = "UPDATE Gy_UserMaterRelation SET HUseFlag=0 " +
+                                       "WHERE HMaterID='" + HMaterID + "' AND HSupID=" + HSupID +
+                                       " AND HItemID!=" + HInterID;
+                    oCN.RunProc(disableSql);
+                }
+
+                // 鍚敤鍓嶆帶鍒�
+                string sql1 = "EXEC h_p_Gy_MaterPrice_BeforeStopCtrl " + HInterID + ",'" + CurUserName + "'";
+                ds = oCN.RunProcReturn(sql1, "h_p_Gy_MaterPrice_BeforeStopCtrl");
+
+                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鍚敤澶辫触!鍘熷洜:鍚敤鍓嶅垽鏂け璐ワ紝璇蜂笌缃戠粶绠$悊浜哄憳鑱旂郴";
+                    oCN.RollBack();
+                    return objJsonResult;
+                }
+
+                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鍚敤澶辫触!鍘熷洜:" + ds.Tables[0].Rows[0]["HRemark"].ToString();
+                    oCN.RollBack();
+                    return objJsonResult;
+                }
+
+                // 鍚敤褰撳墠璁板綍
+                oCN.RunProc("UPDATE Gy_UserMaterRelation SET HUpDater='" + CurUserName +
+                           "', HUpDateDate=GETDATE(), HUseFlag=1 WHERE HItemID=" + HInterID);
+
+                // 鍚敤鍚庢帶鍒�
+                string sql2 = "EXEC h_p_Gy_MaterPrice_AfterStopCtrl " + HInterID + ",'" + CurUserName + "'";
+                ds = oCN.RunProcReturn(sql2, "h_p_Gy_MaterPrice_AfterStopCtrl");
+
+                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鍚敤澶辫触!鍘熷洜:鍚敤鍚庡垽鏂け璐ワ紝璇蜂笌缃戠粶绠$悊浜哄憳鑱旂郴";
+                    oCN.RollBack();
+                    return objJsonResult;
+                }
+
+                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鍚敤澶辫触!鍘熷洜:" + ds.Tables[0].Rows[0]["HRemark"].ToString();
+                    oCN.RollBack();
+                    return objJsonResult;
+                }
+
+                oCN.Commit();
+
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "鍚敤鎴愬姛";
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                oCN.RollBack();
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "鍚敤澶辫触!" + e.Message;
+                return objJsonResult;
+            }
+        }
+        #endregion
 
     }
 }
\ No newline at end of file
diff --git a/WebAPI/Controllers/SRM_MaterialBarCodeBillController.cs b/WebAPI/Controllers/SRM_MaterialBarCodeBillController.cs
index f9a7003..e75a97c 100644
--- a/WebAPI/Controllers/SRM_MaterialBarCodeBillController.cs
+++ b/WebAPI/Controllers/SRM_MaterialBarCodeBillController.cs
@@ -94,7 +94,8 @@
             string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
             string msg2 = sArray[0].ToString();//
             string msg3 = sArray[1].ToString();// 
-            string UserName = "";
+            string UserName = sArray[2].ToString();
+            string OrganizationID = sArray[3].ToString();
             ListModels oListModels = new ListModels();
             try
             {
@@ -104,10 +105,11 @@
                 msg2 = msg2.Replace("\n", "");  //\n
                 lsmain = oListModels.getObjectByJson_MaterialHanding(msg2);
                 int get_BarCodecount = 0;
+                
                 foreach (Model.Cls_MaterialHandingModel oItem in lsmain)
                 {
                     get_BarCodecount++;
-                    UserName = oItem.HMaker;
+                    //UserName = oItem.HMaker;
                 }
                 DAL.ClsWeb_BarCodeBill oBill = new DAL.ClsWeb_BarCodeBill();
                 msg3 = msg3.Substring(1, msg3.Length - 2);
@@ -118,6 +120,14 @@
 
                 ls = oListModels.getObjectByJson_BarCodeBill(msg3);//鍒楄〃鏁版嵁model
 
+                if (ls.Count > 1)
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "姣忔鍙厑璁搁�夋嫨涓�涓墿鏂欑敓鎴愭潯鐮侊紝璇烽��鍑洪噸鏂伴�夋嫨涓�琛岀墿鏂欙紝涓嶅厑璁搁�夋嫨澶氳鐗╂枡锛�";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
 
                 #region 鏁版嵁鍑嗗
                 long linterid = Pub_Class.ClsPub.CreateBillID_SRMProd("8888", ref DBUtility.ClsPub.sExeReturnInfo);
@@ -213,7 +223,7 @@
                               : HMinQty;
                             ///渚涘簲鍟嗗悕绉�+@+鐗╂枡浠g爜+@+鐗╂枡绠�绉�+@+鏁伴噺+@鏉$爜鏁�+@+鏃ユ湡+@+娴佹按鍙�  
                             LSH += 1;
-                            TM = $"{oItemSub.HSupName}@{oItemSub.HMaterID}@{oItemSub.HMaterName}@{currentQty}@{HBarCodeDate_1}@{LSH}";
+                            TM = $"{oItemSub.HSupName}@{oItemSub.HMaterNumber}@{oItemSub.HSubjoin}@{currentQty}@{HBarCodeDate_1}@{LSH.ToString("D7")}";
                             //TM = $"{oItemSub.HSupName}@{oItemSub.HMaterID}@{oItemSub.HMaterName}@{oItemSub.biaoqianzhangshu}@{HKFDate_1}@{LSH}";
                             // 娣诲姞鍒扮敓鎴愮殑鏉$爜鍒楄〃
                             generatedBarcodes.Add(TM);
@@ -243,12 +253,12 @@
                             //               + HKFDate + "','" + HKFDQDate + "'," + HISKFPERIOD + ")";
                             sql = "INSERT INTO Gy_BarCodeBill (HInterID, HBarCode, HBarCodeType, HMaterID, HUnitID, HQty, HKFDate, HKFPeriod, HKFDQDate, " +
        "HBatchNo, HBarcodeQtys, HBarcodeNo, HSupID, HGroupID, HMaker, HMakeDate, HPrintQty, HEndQty, HSupflag, " +
-       "HSourceInterID, HSourceEntryID, HSourceBillNo, HSourceBillType, HMTONO, HProduceDate, HExpiryDate, HISKFPERIOD,HStatusMan,HBarCodeDate,HinitQty) " +
+       "HSourceInterID, HSourceEntryID, HSourceBillNo, HSourceBillType, HMTONO, HProduceDate, HExpiryDate, HISKFPERIOD,HStatusMan,HBarCodeDate,HinitQty,HSTOCKORGID,HOWNERID) " +
       "VALUES (" +
-       linterid.ToString() + ", '" + TM + "', '" + HBarCodeType + "', " + HMaterID + ", " + "0" + ", " + currentQty + ", '" + HKFDate + "', " + HKFPeriod + ", '" + HKFDQDate + "', " +
-       "'" + HBatchNo + "', " + get_BarCodecount + ", '" + virtualCount + "', " + HSupID + ", " + "0" + ", '" + ClsPub.CurUserName + "', '" + DateTime.Today.ToString("yyyy-MM-dd") + "', " + "1" + ", " + "0" + ", 1, " +
-       "1, 1, '1', '" + HSourceBillType + "', '1', '" +
-       HKFDate + "', '" + HKFDQDate + "', " + HISKFPERIOD + ",'" + HStatusMan + "','" + HBarCodeDate + "','" + currentQty + "'" + ")";
+       linterid.ToString() + ", '" + TM + "', '" + HBarCodeType + "', " + HMaterID + ", " + "0" + ", " + currentQty + ", '" + null + "', " + HKFPeriod + ", '" + null + "', " +
+       "'" + HBatchNo + "', " + get_BarCodecount + ", '" + virtualCount + "', " + HSupID + ", " + "0" + ", '" + UserName + "',getdate()" + "," + "0" + ", " + "0" + ", 1, " +
+       "0, 0, '', '" + HSourceBillType + "', '', '" +
+       null + "', '" + null + "', " + HISKFPERIOD + ",'" + HStatusMan + "','" + HBarCodeDate + "','" + currentQty + "'," + OrganizationID + "," + OrganizationID + "," + null + ")";
                             LogService.Write("鐢熸垚鏉$爜锛� " + sql);
                             oCn.RunProc(sql); 
                             oCn.RunProc("exec h_p_WMS_SetMaxNo '" + HSupID + "_" + HMaterID + "_" + HBarCodeDate + "'");
diff --git a/WebAPI/Models/ClsGy_MaterialBarCodeBillModel.cs b/WebAPI/Models/ClsGy_MaterialBarCodeBillModel.cs
index 5713504..d0d9dcc 100644
--- a/WebAPI/Models/ClsGy_MaterialBarCodeBillModel.cs
+++ b/WebAPI/Models/ClsGy_MaterialBarCodeBillModel.cs
@@ -52,6 +52,7 @@
         public string HRemark;
         public string HStatusMan; //鎯犲悍宸ュ彿
         public string HBarCodeDate; //鏉$爜鏃ユ湡       
+        public string HSubjoin; //鏉$爜鏃ユ湡       
         // public ClsGy_MaterialBarCodeBillModel();
     }
 }
\ No newline at end of file

--
Gitblit v1.9.1