From 2cdcaeae26ebd1b0be98b4dbb73662bb241877d3 Mon Sep 17 00:00:00 2001
From: yangle <admin@YINMOU>
Date: 星期五, 07 四月 2023 14:53:48 +0800
Subject: [PATCH] Merge branch 'master' of http://101.37.171.70:10101/r/SRM-WEBAPI

---
 全部客户在运用.txt                                          |    0 
 WebAPI/Utility/HttpHelper.cs                         |  134 +++++++
 WebAPI/Controllers/WebAPIController.cs               |   24 +
 WebAPI/DLL/DAL.dll                                   |    0 
 WebAPI/Controllers/POInStockController.cs            |  357 ++++++++++----------
 WebAPI/Controllers/Xt_grdAlignment_WMESController.cs |    2 
 WebAPI/DLL/Model.dll                                 |    0 
 WebAPI/Controllers/BarCodeController.cs              |  433 ++++++++++++++++---------
 /dev/null                                            |    0 
 WebAPI/Models/JsonResult.cs                          |    2 
 WebAPI/Controllers/POOrderController.cs              |   15 
 WebAPI/WebAPI.csproj                                 |    5 
 WebAPI/Models/json.cs                                |    2 
 13 files changed, 637 insertions(+), 337 deletions(-)

diff --git a/WebAPI/Controllers/BarCodeController.cs b/WebAPI/Controllers/BarCodeController.cs
index 53f2a0a..381d0f1 100644
--- a/WebAPI/Controllers/BarCodeController.cs
+++ b/WebAPI/Controllers/BarCodeController.cs
@@ -13,6 +13,8 @@
 using System.Web.Script.Serialization;
 using WebAPI.Code;
 using WebAPI.Models;
+using WebAPI.Utility;
+
 namespace WebAPI.Controllers
 {
 
@@ -21,7 +23,8 @@
         private JsonResult objJsonResult = new JsonResult();
         private json objjson = new json();
         public new ClsCNSRM oCn = new ClsCNSRM();
-
+        //鑾峰彇绯荤粺鍙傛暟
+        Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
         public T ScriptDeserialize<T>(string strJson)
         {
             JavaScriptSerializer js = new JavaScriptSerializer();
@@ -494,6 +497,7 @@
         /// <returns></returns>
         public object GetBarcodeSaveBill_Box([FromBody] JObject msg)
         {
+            string FCusName = oSystemParameter.GetSingleSystemParameter("WMS_CampanyName", ref DBUtility.ClsPub.sExeReturnInfo);
             var _value = msg["msg"].ToString();
             string msg1 = _value.ToString();
             string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
@@ -525,33 +529,9 @@
 
                 foreach (Model.ClsGy_MaterialList_WMS_Model oItemSub in ls)
                 {
-                    //if (oBill.CheckBarCode(oItemSub.HSourceInterID, oItemSub.HSourceEntryID) == false)
-                    //{
-                    //    objJsonResult.code = "0";
-                    //    objJsonResult.count = 0;
-                    //    objJsonResult.Message = "宸插瓨鍦ㄦ潯鐮侊紝涓嶅厑璁搁噸澶嶇敓鎴愶紒";
-                    //    objJsonResult.data = null;
-                    //    return objJsonResult;
-                    //}
-                    if (msg2 != string.Empty)
-                    {
-                        if (oItemSub.HBQty == 0 || oItemSub.HMinQty == 0)
-                        {
-                            objJsonResult.code = "0";
-                            objJsonResult.count = 0;
-                            objJsonResult.Message = "鍐呯鍖呰鏁颁笉鑳戒负0锛�";
-                            objJsonResult.data = null;
-                            return objJsonResult;
-                        }
-                        if (oItemSub.HWBQty == 0 || oItemSub.HWXQty == 0)
-                        {
-                            objJsonResult.code = "0";
-                            objJsonResult.count = 0;
-                            objJsonResult.Message = "澶栫鍖呰鏁颁笉鑳戒负0锛�";
-                            objJsonResult.data = null;
-                            return objJsonResult;
-                        }
-                    }
+                    //鏁伴噺涓�0 璺宠繃
+                    if (oItemSub.HQty == 0 || oItemSub.HMinQty == 0 || oItemSub.HWXQty == 0)
+                        continue;
                 }
                 long linterid = Pub_Class.ClsPub.CreateBillID_SRMProd("8888", ref DBUtility.ClsPub.sExeReturnInfo);
                 int LSHlen = 6;             //娴佹按鍙烽暱搴�
@@ -733,6 +713,7 @@
                         }
                     }
                 }
+
                 string HBarCode = "";
                 string HBarCodeType = "";
                 Int64 HMaterID = 0;
@@ -752,6 +733,11 @@
                 string HWei = "";
                 string HMTONO = "";
                 oCn.BeginTran();
+                foreach (Model.ClsGy_MaterialList_WMS_Model oItemSub in ls)
+                {
+                    //鏇存柊鏉$爜妗f 璇ユ簮鍗曞叾瀹冩潯鐮侀粯璁ゅ凡缁忔墦鍗拌繃涓�娆�
+                    oCn.RunProc($"update Gy_BarCodeBill set  HPrintQty += 1   where HPrintQty = 0 and  HSourceInterID={oItemSub.HSourceInterID} and HSourceEntryID = {oItemSub.HSourceEntryID}");
+                }
                 foreach (Model.ClsGy_BarCodeBill_WMS_Model oItemSub in ls2)
                 {
                     //LogService.Write("寰幆绗簩娆�:" + oItemSub.HSupID);
@@ -774,6 +760,11 @@
                         HSourceBillNo = ClsPub.isStrNull(oItemSub.HSourceBillNo);
                         HSourceBillType = ClsPub.isStrNull(oItemSub.HSourceBillType);
                         HWei = ClsPub.isStrNull(oItemSub.HEndQty);
+                        if (FCusName.Contains("澶忓疂"))
+                        {
+                            HBarCode = $"{oItemSub.HMaterID}";
+                            HBarCodeType = "鍝佺鐮乢澶栫";
+                        }
                         string sql = "insert into Gy_BarCodeBill (HInterID,HBarCode,HBarCodeType,HMaterID,HUnitID,HQty,HKFDate,HKFPeriod,HKFDQDate" +
                                     ",HBatchNo,HSupID,HGroupID,HMaker,HMakeDate,HPrintQty,HEndQty,HSupflag" +
                                     ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HMTONO " +
@@ -809,6 +800,11 @@
                         HSourceBillNo = ClsPub.isStrNull(oItemSub.HSourceBillNo);
                         HSourceBillType = ClsPub.isStrNull(oItemSub.HSourceBillType);
                         HWei = ClsPub.isStrNull(oItemSub.HEndQty);
+                        if (FCusName.Contains("澶忓疂"))
+                        {
+                            HBarCode = $"{oItemSub.HMaterID}";
+                            HBarCodeType = "鍝佺鐮�";
+                        }
                         string sql = "insert into Gy_BarCodeBill (HInterID,HBarCode,HBarCodeType,HMaterID,HUnitID,HQty,HKFDate,HKFPeriod,HKFDQDate" +
                                     ",HBatchNo,HSupID,HGroupID,HMaker,HMakeDate,HPrintQty,HEndQty,HSupflag" +
                                     ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HMTONO " +
@@ -873,6 +869,7 @@
         /// <returns></returns>
         public object GetBarcodeSaveBillOnlyInnerBox([FromBody] JObject msg)
         {
+            string FCusName = oSystemParameter.GetSingleSystemParameter("WMS_CampanyName", ref DBUtility.ClsPub.sExeReturnInfo);
             var _value = msg["msg"].ToString();
             string msg1 = _value.ToString();
             string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
@@ -900,30 +897,6 @@
                 List<Model.ClsGy_MaterialList_WMS_Model> ls = new List<Model.ClsGy_MaterialList_WMS_Model>();
                 List<Model.ClsGy_BarCodeBill_WMS_Model> ls2 = new List<Model.ClsGy_BarCodeBill_WMS_Model>();
                 ls = oListModels.getObjectByJson_MaterialList(msg3);
-
-                foreach (Model.ClsGy_MaterialList_WMS_Model oItemSub in ls)
-                {
-                    if (CheckBarCode(oItemSub.HSourceInterID, oItemSub.HSourceEntryID) == false)
-                    {
-                        objJsonResult.code = "0";
-                        objJsonResult.count = 0;
-                        objJsonResult.Message = "宸插瓨鍦ㄦ潯鐮侊紝涓嶅厑璁搁噸澶嶇敓鎴愶紒";
-                        objJsonResult.data = null;
-                        return objJsonResult;
-                    }
-                    if (msg2 != string.Empty)
-                    {
-                        if (oItemSub.HBQty == 0 || oItemSub.HMinQty == 0)
-                        {
-                            objJsonResult.code = "0";
-                            objJsonResult.count = 0;
-                            objJsonResult.Message = "鍐呯鍖呰鏁颁笉鑳戒负0锛�";
-                            objJsonResult.data = null;
-                            return objJsonResult;
-                        }
-
-                    }
-                }
                 long linterid = Pub_Class.ClsPub.CreateBillID_SRMProd("8888", ref DBUtility.ClsPub.sExeReturnInfo);
                 int LSHlen = 6;             //娴佹按鍙烽暱搴�
                 int SumLen = 10;            //鎬婚暱搴�
@@ -940,6 +913,20 @@
                 LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                 foreach (Model.ClsGy_MaterialList_WMS_Model oItemSub in ls)
                 {
+                    //鏁伴噺涓�0 璺宠繃
+                    if (oItemSub.HQty == 0)
+                        continue;
+                    //妫�楠屾墦鍗版暟閲忥紙HQTY锛夊拰鏈墦鍗版暟閲�
+                    string sql = $"select HQty -HBarcodeCount as HNotBarcodeCount ,* from Cg_POOrderBillSub where HEntryID = {oItemSub.HSourceEntryID}";
+                    DataSet ds = oCn.RunProcReturn(sql, "tables");
+                    if (ds.Tables[0].Rows.Count > 0 && Convert.ToInt32(ds.Tables[0].Rows[0][0]) < oItemSub.HQty)
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = $"鐗╂枡缂栫爜{oItemSub.HMaterNumber}锛屾湰娆$敓鎴愭潯鐮佹暟閲忎笉鑳借秴鍑烘湭鐢熸垚鏉$爜鏁伴噺";
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
                     //鍐呯
                     if (ClsPub.isLong(oItemSub.HMaterID) != 0)
                     {
@@ -999,6 +986,11 @@
                 oCn.BeginTran();
                 foreach (Model.ClsGy_BarCodeBill_WMS_Model oItemSub in ls2)
                 {
+                    //鏇存柊鏉$爜妗f 璇ユ簮鍗曞叾瀹冩潯鐮侀粯璁ゅ凡缁忔墦鍗拌繃涓�娆�
+                    oCn.RunProc($"update Gy_BarCodeBill set  HPrintQty += 1   where HPrintQty = 0 and  HSourceInterID={oItemSub.HSourceInterID} and HSourceEntryID = {oItemSub.HSourceEntryID}");
+                }
+                foreach (Model.ClsGy_BarCodeBill_WMS_Model oItemSub in ls2)
+                {
                     if (ClsPub.isLong(oItemSub.HMaterID) != 0)
                     {
                         HBarCode = oItemSub.HBarCode.ToString();
@@ -1031,8 +1023,27 @@
                     }
                 }
                 //鏆傛椂鍙洖濉叧鑱旀暟閲�
-                string _sql = "exec H_p_SRM_BarCodeBill_Update_UpdateBillRelateData " + linterid.ToString();
-                oCn.RunProc(_sql);
+                foreach (Model.ClsGy_MaterialList_WMS_Model oItemSub in ls)
+                {
+                    if (oItemSub.HQty == 0)
+                        continue;
+                    //鏇存柊鏉$爜妗f 璇ユ簮鍗曞叾瀹冩潯鐮侀粯璁ゅ凡缁忔墦鍗拌繃涓�娆�
+                    //鏇存柊 宸叉墦鍗版暟閲�
+                    if (oItemSub.HSourceBillType == "1102")
+                    {
+                        string _HBarCodeType = "绠卞彿鏉$爜";
+                        if (FCusName.Contains("澶忓疂"))
+                            _HBarCodeType = "鍝佺鐮�";
+                        string sql = string.Empty;
+                        sql = string.Format(@"
+update t1 set  
+t1.HBarcodeCount = 
+isnull((select sum(HQty)from Gy_BarCodeBill where HSourceInterID = t1.HInterID and HSourceEntryID = t1.HEntryID and HBarCodeType ='{2}'),0)
+from Cg_POOrderBillSub t1 
+where t1.HInterID = {0} and t1.HEntryID ={1}", oItemSub.HSourceInterID, oItemSub.HSourceEntryID, _HBarCodeType);
+                        oCn.RunProc(sql);
+                    }
+                }
                 oCn.Commit();
             }
             catch (Exception e)
@@ -1447,15 +1458,12 @@
         /// <summary>
         /// 鏉$爜鐢熸垚琛ㄤ綋锛堥噰璐鍗曪級
         /// </summary>
-        /// <param name="sMsg"></param>
+        /// <param name="sMsg">閲囪喘璁㈠崟HinterID</param>
         /// <returns></returns>
         public object GetHBarCodeShowBillSubBycg(string sMsg)
         {
             try
             {
-                DataSet ds;
-                string s = "";
-                string ShowItem = " * ";//鏄剧ず鐨勫瓧娈�
                 if (DBUtility.ClsPub.isLong(sMsg) == 0)
                 {
                     objjson.code = "0";
@@ -1464,9 +1472,18 @@
                     objjson.data = null;
                     return objjson;
                 }
+                //棰勫鐞� 淇敼閲囪喘璁㈠崟鐨勯��鏂欐暟閲�
+                var kdTbaleName = Util.GetConfigKey(AppDomain.CurrentDomain.BaseDirectory + "/Config/kdapi.config", "DataBaseName");
+                string sql = $@"update t1 set 
+ t1.HMrbQty = t2.FMRBQTY
+ from Cg_POOrderBillSub t1 
+ join {kdTbaleName}..T_PUR_POORDERENTRY_R t2 
+ on t1.HEntryID = t2.FENTRYID
+ where t1.HInterID = {sMsg} ";//sMsg 閲囪喘璁㈠崟hinterid
+                oCn.RunProc(sql);
                 DAL.ClsWeb_BarCodeBill oClsWeb_BarCodeBill = new DAL.ClsWeb_BarCodeBill();
-                string sql = string.Format(@"select * from h_v_Cg_POOrderBillSub_ForWeb2 where HInterID = " + sMsg);
-                ds = oCn.RunProcReturn(sql, "h_v_Cg_POOrderBillSub_ForWeb2");
+                sql = string.Format(@"select * from h_v_Cg_POOrderBillSub_ForWeb2 where HInterID = " + sMsg);
+                DataSet ds = oCn.RunProcReturn(sql, "h_v_Cg_POOrderBillSub_ForWeb2");
                 //ds = oClsWeb_BarCodeBill.ShowBillSub(DBUtility.ClsPub.isLong(sMsg), ShowItem, ref DBUtility.ClsPub.sExeReturnInfo);
                 if (ds == null || ds.Tables[0].Rows.Count == 0)
                 {
@@ -1505,11 +1522,12 @@
         /// <returns></returns>
         public object GetBarcodeSaveBillBoxBycg([FromBody] JObject msg)
         {
+            string FCusName = oSystemParameter.GetSingleSystemParameter("WMS_CampanyName", ref DBUtility.ClsPub.sExeReturnInfo);
             var _value = msg["msg"].ToString();
             string msg1 = _value.ToString();
             string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
-            string msg2 = sArray[0].ToString();
-            string msg3 = sArray[1].ToString();
+            string msg2 = sArray[0].ToString();//
+            string msg3 = sArray[1].ToString();// 
             string UserName = "";
             ListModels oListModels = new ListModels();
             try
@@ -1523,46 +1541,15 @@
                     UserName = oItem.HMaker;
                 }
                 DAL.ClsWeb_BarCodeBill oBill = new DAL.ClsWeb_BarCodeBill();
-
                 msg3 = msg3.Substring(1, msg3.Length - 2);
                 msg3 = msg3.Replace("\\", "");
                 msg3 = msg3.Replace("\n", "");  //\n
-
                 List<Model.ClsGy_MaterialList_WMS_Model> ls = new List<Model.ClsGy_MaterialList_WMS_Model>();
-                List<Model.ClsGy_BarCodeBill_WMS_Model> ls2 = new List<Model.ClsGy_BarCodeBill_WMS_Model>();
-                List<Model.ClsGy_BarCodeBill_WMS_Model> ls3 = new List<Model.ClsGy_BarCodeBill_WMS_Model>();
-                ls = oListModels.getObjectByJson_MaterialList(msg3);
+                List<Model.ClsGy_BarCodeBill_WMS_Model> ls2 = new List<Model.ClsGy_BarCodeBill_WMS_Model>();//澶栫model
+                List<Model.ClsGy_BarCodeBill_WMS_Model> ls3 = new List<Model.ClsGy_BarCodeBill_WMS_Model>();//鍐呯model
 
-                foreach (Model.ClsGy_MaterialList_WMS_Model oItemSub in ls)
-                {
-                    if (oBill.CheckBarCode(oItemSub.HSourceInterID, oItemSub.HSourceEntryID) == false)
-                    {
-                        objJsonResult.code = "0";
-                        objJsonResult.count = 0;
-                        objJsonResult.Message = "宸插瓨鍦ㄦ潯鐮侊紝涓嶅厑璁搁噸澶嶇敓鎴愶紒";
-                        objJsonResult.data = null;
-                        return objJsonResult;
-                    }
-                    if (msg2 != string.Empty)
-                    {
-                        if (oItemSub.HBQty == 0 || oItemSub.HMinQty == 0)
-                        {
-                            objJsonResult.code = "0";
-                            objJsonResult.count = 0;
-                            objJsonResult.Message = "鍐呯鍖呰鏁颁笉鑳戒负0锛�";
-                            objJsonResult.data = null;
-                            return objJsonResult;
-                        }
-                        if (oItemSub.HWBQty == 0 || oItemSub.HWXQty == 0)
-                        {
-                            objJsonResult.code = "0";
-                            objJsonResult.count = 0;
-                            objJsonResult.Message = "澶栫鍖呰鏁颁笉鑳戒负0锛�";
-                            objJsonResult.data = null;
-                            return objJsonResult;
-                        }
-                    }
-                }
+                ls = oListModels.getObjectByJson_MaterialList(msg3);//鍒楄〃鏁版嵁model
+
                 long linterid = Pub_Class.ClsPub.CreateBillID_SRMProd("8888", ref DBUtility.ClsPub.sExeReturnInfo);
                 int LSHlen = 6;             //娴佹按鍙烽暱搴�
                 int SumLen = 10;            //鎬婚暱搴�
@@ -1581,12 +1568,47 @@
                 string WeiShu = ""; //灏炬暟
                 DataSet Ds;
                 SQLHelper.ClsCNSRM oCn = new SQLHelper.ClsCNSRM();
+                oCn.BeginTran();
                 Ds = oCn.RunProcReturn("exec GetLSH '" + DateTime.Today + "'", "GetLSH");
                 LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                 foreach (Model.ClsGy_MaterialList_WMS_Model oItemSub in ls)
                 {
+                    //鏁伴噺涓�0 璺宠繃
+                    if (oItemSub.HQty == 0 || oItemSub.HMinQty == 0 || oItemSub.HWXQty == 0)
+                        continue;
+                    //妫�楠屾墦鍗版暟閲忥紙HQTY锛夊拰鏈墦鍗版暟閲�
+                    string sql = $"select HQty + isnull(HMrbQty,0) - HBarcodeCount as HNotBarcodeCount ,* from Cg_POOrderBillSub where HEntryID = {oItemSub.HSourceEntryID}";
+                    DataSet ds = oCn.RunProcReturn(sql, "tables");
+                    if (ds.Tables[0].Rows.Count > 0 && Convert.ToInt32(ds.Tables[0].Rows[0][0]) < oItemSub.HQty)
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = $"鐗╂枡缂栫爜{oItemSub.HMaterNumber}锛屾湰娆$敓鎴愭潯鐮佹暟閲忎笉鑳借秴鍑烘湭鐢熸垚鏉$爜鏁伴噺";
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                    //鏍¢獙鎵瑰彿 鍜� 鐢熶骇鏃ユ湡
+                    sql = $"select top 1 HKFDate from Gy_BarCodeBill where HSupID = '{oItemSub.HSupID}' and HBatchNo = '{oItemSub.HBatchNo.TrimStart().TrimEnd()}' and HMaterID ={oItemSub.HMaterID} and isnull(HKFDate, '') <> ''";
+                    LogService.Write($"sql:{sql}");
+                    DataTable dt = oCn.RunProcReturn(sql, "tables").Tables[0];
+                    if (dt.Rows.Count > 0)
+                    {
+                        LogService.Write($"HKFDate:{dt.Rows[0][0]}");
+                        sql = $"select DATEDIFF(D,{dt.Rows[0][0]},{oItemSub.HKFDate})";
+                        ds = oCn.RunProcReturn(sql, "tables2");
+                        LogService.Write($"DATEDIFF:{Convert.ToInt32(ds.Tables[0].Rows[0][0])}");
+                        if (ds.Tables[0].Rows.Count > 0 && Convert.ToInt32(ds.Tables[0].Rows[0][0]) != 0)
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = $"鐗╂枡缂栫爜{oItemSub.HMaterNumber}锛屾壒鍙穥oItemSub.HBatchNo.TrimStart().TrimEnd()},鐢熶骇鏃ユ湡涓簕dt.Rows[0][0]},璇锋牳瀵�";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                    }
                     if (ClsPub.isLong(oItemSub.HMaterID) != 0)
                     {
+
                         HNumber = oItemSub.HMaterID.ToString();
                         //HNumber = HNumber.Replace(".", "");
                         //HQty = Math.Ceiling(HBQty + ClsPub.isDoule(oItemSub.HWBQty));
@@ -1596,8 +1618,8 @@
                         HSumQty = ClsPub.isDoule(oItemSub.HQty);  //浜у搧鏁伴噺
                         for (int i = 0; i < HBQty; i++)
                         {
-                            //  瀹夌憺鏉$爜瑙勫垯锛氱墿鏂欑紪鐮侊紙绯荤粺浠e叆锛堾鐗╂枡鍚嶇О锛堢郴缁熶唬鍏ワ級@瑙勬牸鍨嬪彿锛堢郴缁熶唬鍏ワ級@鐢熶骇鏃ユ湡锛堟墜宸ヨ緭鍏ワ級@鏁伴噺锛堟墜宸ヨ緭鍏ワ級@澶辨晥鏃ユ湡锛堟墜宸ヨ緭鍏ワ級@鎵规鍙凤紙鎵嬪伐浠e叆锛堾渚涘簲鍟嗗悕绉帮紙绯荤粺浠e叆锛堾閲囪喘璁㈠崟鍙凤紙绯荤粺浠e叆锛�
-                            TM = $"{oItemSub.HMaterNumber}@{oItemSub.HMaterName}@{oItemSub.HMaterModel}@{oItemSub.HKFDate}@{oItemSub.HQty}@{oItemSub.HKFDQDate}@{oItemSub.HBatchNo}@{oItemSub.HSupName}@{oItemSub.HSourceBillNo}";
+                            ////  瀹夌憺鏉$爜瑙勫垯锛氱墿鏂欑紪鐮侊紙绯荤粺浠e叆锛堾鐗╂枡鍚嶇О锛堢郴缁熶唬鍏ワ級@瑙勬牸鍨嬪彿锛堢郴缁熶唬鍏ワ級@鐢熶骇鏃ユ湡锛堟墜宸ヨ緭鍏ワ級@鏁伴噺锛堟墜宸ヨ緭鍏ワ級@澶辨晥鏃ユ湡锛堟墜宸ヨ緭鍏ワ級@鎵规鍙凤紙鎵嬪伐浠e叆锛堾渚涘簲鍟嗗悕绉帮紙绯荤粺浠e叆锛堾閲囪喘璁㈠崟鍙凤紙绯荤粺浠e叆锛�
+                            //TM = $"{oItemSub.HMaterNumber}@{oItemSub.HMaterName}@{oItemSub.HMaterModel}@{oItemSub.HKFDate}@{oItemSub.HQty}@{oItemSub.HKFDQDate}@{oItemSub.HBatchNo}@{oItemSub.HSupName}@{oItemSub.HSourceBillNo}";
 
                             if (HSumQty - HMinQty > 0)
                             {
@@ -1617,7 +1639,36 @@
                                 HMinQty = HSumQty;
                             }
 
+                            //瀹夌憺鏉$爜瑙勫垯锛氱墿鏂欑紪鐮侊紙绯荤粺浠e叆锛堾鐗╂枡鍚嶇О锛堢郴缁熶唬鍏ワ級@瑙勬牸鍨嬪彿锛堢郴缁熶唬鍏ワ級@鐢熶骇鏃ユ湡锛堟墜宸ヨ緭鍏ワ級@鏁伴噺锛堟墜宸ヨ緭鍏ワ級@澶辨晥鏃ユ湡锛堟墜宸ヨ緭鍏ワ級@鎵规鍙凤紙鎵嬪伐浠e叆锛堾渚涘簲鍟嗗悕绉帮紙绯荤粺浠e叆锛堾閲囪喘璁㈠崟鍙凤紙绯荤粺浠e叆锛�
+                            TM = $"{oItemSub.HMaterNumber}@{oItemSub.HMaterName}@{oItemSub.HMaterModel}@{oItemSub.HKFDate}@{HMinQty}@{oItemSub.HKFDQDate}@{oItemSub.HBatchNo.TrimStart().TrimEnd()}@{oItemSub.HSupName}@{oItemSub.HSourceBillNo}";
                             Model.ClsGy_BarCodeBill_WMS_Model bar = new Model.ClsGy_BarCodeBill_WMS_Model();
+
+                            var HBarCode_verify = TM.Split('@'); //鏍¢獙鏉$爜淇℃伅
+                            var HMaterNumber_verify = HBarCode_verify[0]; //鏍¢獙鐗╂枡缂栫爜
+                            var HMaterName_verify = HBarCode_verify[1]; //鏍¢獙鐗╂枡鍚嶇О
+                            var HMaterModel_verify = HBarCode_verify[2]; //鏍¢獙瑙勬牸鍨嬪彿
+                            var HSupName_verify = HBarCode_verify[7]; //鏍¢獙渚涘簲鍟�
+                            var HSourceBillNo_verify = HBarCode_verify[8]; //鏍¢獙閲囪喘璁㈠崟鍙�
+
+                            sql = $"select * from Gy_Material where HNumber = '{HMaterNumber_verify}' and HName = '{HMaterName_verify}' and HModel = '{HMaterModel_verify}'";
+                            DataSet verifyMatInfo = oCn.RunProcReturn(sql, "tables");
+
+                            sql = $"select * from Cg_POOrderBillMain where HBillNo = '{HSourceBillNo_verify}'";
+                            DataSet verifyBillInfo = oCn.RunProcReturn(sql, "tables");
+
+                            sql = $"select * from Gy_Supplier where HName = '{HSupName_verify}'";
+                            DataSet verifySupInfo = oCn.RunProcReturn(sql, "tables");
+
+                            if (verifyMatInfo.Tables[0].Rows.Count <= 0 || verifyBillInfo.Tables[0].Rows.Count <= 0 || verifySupInfo.Tables[0].Rows.Count <= 0)
+                            {
+                                oCn.RollBack();
+                                objJsonResult.code = "0";
+                                objJsonResult.count = 0;
+                                objJsonResult.Message = $"鏉$爜淇℃伅鏍¢獙鍑洪敊锛岃閲嶆柊鐢熸垚鏉$爜";
+                                objJsonResult.data = null;
+                                return objJsonResult;
+                            }
+
                             bar.HBarCode = TM;
                             bar.HMaterID = oItemSub.HMaterID;
                             //bar.HMaterNumber = oItemSub.HMaterNumber;
@@ -1644,6 +1695,7 @@
                         }
                     }
                 }
+                oCn.Commit();
                 foreach (Model.ClsGy_BarCodeBill_WMS_Model oItemSub2 in ls2)
                 {
                     if (ClsPub.isLong(oItemSub2.HMaterID) != 0)
@@ -1654,6 +1706,7 @@
                         int SumLen2 = 4;
                         string TM2 = "";
                         double HWXQty = 0;
+                        double HBarcodeQty = ClsPub.isDoule(oItemSub2.HQty);
 
                         LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]) + 1;
                         //
@@ -1705,10 +1758,7 @@
                                 TM2 = "0" + TM2;
                             }
                             bar2.HMaterID = oItemSub2.HMaterID;
-
-
-                            bar2.HBarCode = oItemSub2.HBarCode + "-" + TM2;
-
+                            bar2.HBarCode = oItemSub2.HBarCode.Replace(HBarcodeQty.ToString(), HWXQty.ToString());
                             bar2.HUnitID = oItemSub2.HUnitID;
                             bar2.HQty = HWXQty;
                             bar2.HBatchNo = DBUtility.ClsPub.isStrNull(oItemSub2.HBatchNo);
@@ -1745,68 +1795,122 @@
                 string HWei = "";
                 string HMTONO = "";
                 oCn.BeginTran();
-                foreach (Model.ClsGy_BarCodeBill_WMS_Model oItemSub in ls2)
+                foreach (Model.ClsGy_MaterialList_WMS_Model oItemSub in ls)
                 {
-                    if (ClsPub.isLong(oItemSub.HMaterID) != 0)
+                    //鏇存柊鏉$爜妗f 璇ユ簮鍗曞叾瀹冩潯鐮侀粯璁ゅ凡缁忔墦鍗拌繃涓�娆�
+                    oCn.RunProc($"update Gy_BarCodeBill set  HPrintQty += 1   where HPrintQty = 0 and  HSourceInterID={oItemSub.HSourceInterID} and HSourceEntryID = {oItemSub.HSourceEntryID}");
+                }
+                //澶栫
+                var oItemSubGroup = ls2.GroupBy(x => new { x.HSourceEntryID }).Select(y => new Model.ClsGy_BarCodeBill_WMS_Model { HSourceEntryID = y.Key.HSourceEntryID });
+                foreach (var oitem in oItemSubGroup)
+                {
+                    var SubModel = ls2.Where(x => x.HSourceEntryID == oitem.HSourceEntryID).ToList();
+                    int count = 1;
+                    foreach (var oItemSub in SubModel)
                     {
-                        HBarCode = oItemSub.HBarCode.ToString();
-                        HMTONO = ClsPub.isStrNull(oItemSub.HMTONO);
-                        HBarCodeType = "绠卞彿鏉$爜";
-                        HMaterID = ClsPub.isLong(oItemSub.HMaterID);
-                        HUnitID = ClsPub.isLong(oItemSub.HUnitID);
-                        HQty2 = ClsPub.isDoule(oItemSub.HQty);
-                        HBatchNo = ClsPub.isStrNull(oItemSub.HBatchNo);
-                        HSupID = oItemSub.HSupID;
-                        HKFPeriod = ClsPub.isInt(oItemSub.HKFPeriod);
-                        HKFDate = ClsPub.isStrNull(oItemSub.HKFDate);
-                        HKFDQDate = ClsPub.isStrNull(oItemSub.HKFDQDate);
-                        HSourceInterID = ClsPub.isLong(oItemSub.HSourceInterID);
-                        HSourceEntryID = ClsPub.isLong(oItemSub.HSourceEntryID);
-                        HSourceBillNo = ClsPub.isStrNull(oItemSub.HSourceBillNo);
-                        HSourceBillType = ClsPub.isStrNull(oItemSub.HSourceBillType);
-                        HWei = ClsPub.isStrNull(oItemSub.HEndQty);
-                        oCn.RunProc("insert into Gy_BarCodeBill (HInterID,HBarCode,HBarCodeType,HMaterID,HUnitID,HQty,HKFDate,HKFPeriod,HKFDQDate" +
-                                    ",HBatchNo,HSupID,HGroupID,HMaker,HMakeDate,HPrintQty,HEndQty,HSupflag" +
-                                    ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HMTONO " +
-                                    ") values ("
-                                    + linterid.ToString() + ",'" + HBarCode + "','" + HBarCodeType + "'," + HMaterID + "," + HUnitID + "," + HQty2 + ",'" + HKFDate + "'," + HKFPeriod + ",'" + HKFDQDate
-                                    + "','" + HBatchNo + "'," + HSupID + "," + HGroupID + ",'" + ClsPub.CurUserName + "','" + DateTime.Today + "'," + HPrintQty + ",'" + HWei + "',1"
-                                    + "," + HSourceInterID + "," + HSourceEntryID + ",'" + HSourceBillNo + "','" + HSourceBillType + "','" + HMTONO + "')");
-                        oCn.RunProc("exec setLSH '" + DateTime.Today + "'");
+                        if (ClsPub.isLong(oItemSub.HMaterID) != 0)
+                        {
+                            HBarCode = oItemSub.HBarCode.ToString();
+                            HMTONO = ClsPub.isStrNull(oItemSub.HMTONO);
+                            HBarCodeType = "绠卞彿鏉$爜";
+                            HMaterID = ClsPub.isLong(oItemSub.HMaterID);
+                            HUnitID = ClsPub.isLong(oItemSub.HUnitID);
+                            HQty2 = ClsPub.isDoule(oItemSub.HQty);
+                            HBatchNo = ClsPub.isStrNull(oItemSub.HBatchNo);
+                            HSupID = oItemSub.HSupID;
+                            HKFPeriod = ClsPub.isInt(oItemSub.HKFPeriod);
+                            HKFDate = ClsPub.isStrNull(oItemSub.HKFDate);
+                            HKFDQDate = ClsPub.isStrNull(oItemSub.HKFDQDate);
+                            HSourceInterID = ClsPub.isLong(oItemSub.HSourceInterID);
+                            HSourceEntryID = ClsPub.isLong(oItemSub.HSourceEntryID);
+                            HSourceBillNo = ClsPub.isStrNull(oItemSub.HSourceBillNo);
+                            HSourceBillType = ClsPub.isStrNull(oItemSub.HSourceBillType);
+                            HWei = ClsPub.isStrNull(oItemSub.HEndQty);
+                            if (FCusName.Contains("澶忓疂"))
+                            {
+                                HBarCode = $"{oItemSub.HMaterID}";
+                                HBarCodeType = "鍝佺鐮乢澶栫";
+                            }
+                            string 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 " +
+                                        ") values ("
+                                        + linterid.ToString() + ",'" + HBarCode + "','" + HBarCodeType + "'," + HMaterID + "," + HUnitID + "," + HQty2 + ",'" + HKFDate + "'," + HKFPeriod + ",'" + HKFDQDate
+                                        + "','" + HBatchNo + "','" + SubModel.Count + "','" + count + "'," + HSupID + "," + HGroupID + ",'" + ClsPub.CurUserName + "','" + DateTime.Today + "'," + HPrintQty + ",'" + HWei + "',1"
+                                        + "," + HSourceInterID + "," + HSourceEntryID + ",'" + HSourceBillNo + "','" + HSourceBillType + "','" + HMTONO + "')";
+                            oCn.RunProc(sql);
+                            oCn.RunProc("exec setLSH '" + DateTime.Today + "'");
+                            count++;
+                        }
                     }
                 }
-                foreach (Model.ClsGy_BarCodeBill_WMS_Model oItemSub in ls3)
+                //鍐呯
+                var _oItemSubGroup = ls3.GroupBy(x => new { x.HSourceEntryID }).Select(y => new Model.ClsGy_BarCodeBill_WMS_Model { HSourceEntryID = y.Key.HSourceEntryID });
+                foreach (var oitem in _oItemSubGroup)
                 {
-                    if (ClsPub.isLong(oItemSub.HMaterID) != 0)
+                    var SubModel = ls3.Where(x => x.HSourceEntryID == oitem.HSourceEntryID).ToList();
+                    int _count = 1;
+                    foreach (var oItemSub in SubModel)
                     {
-                        HBarCode = oItemSub.HBarCode.ToString();
-                        HMTONO = ClsPub.isStrNull(oItemSub.HMTONO);
-                        HBarCodeType = "绠卞彿鍐呮潯鐮�";
-                        HMaterID = ClsPub.isLong(oItemSub.HMaterID);
-                        HUnitID = ClsPub.isLong(oItemSub.HUnitID);
-                        HQty2 = ClsPub.isDoule(oItemSub.HQty);
-                        HBatchNo = ClsPub.isStrNull(oItemSub.HBatchNo);
-                        HSupID = oItemSub.HSupID;
-                        HKFPeriod = ClsPub.isInt(oItemSub.HKFPeriod);
-                        HKFDate = ClsPub.isStrNull(oItemSub.HKFDate);
-                        HKFDQDate = ClsPub.isStrNull(oItemSub.HKFDQDate);
-                        HSourceInterID = ClsPub.isLong(oItemSub.HSourceInterID);
-                        HSourceEntryID = ClsPub.isLong(oItemSub.HSourceEntryID);
-                        HSourceBillNo = ClsPub.isStrNull(oItemSub.HSourceBillNo);
-                        HSourceBillType = ClsPub.isStrNull(oItemSub.HSourceBillType);
-                        HWei = ClsPub.isStrNull(oItemSub.HEndQty);
-                        oCn.RunProc("insert into Gy_BarCodeBill (HInterID,HBarCode,HBarCodeType,HMaterID,HUnitID,HQty,HKFDate,HKFPeriod,HKFDQDate" +
-                                    ",HBatchNo,HSupID,HGroupID,HMaker,HMakeDate,HPrintQty,HEndQty,HSupflag" +
-                                    ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HMTONO " +
-                                    ") values ("
-                                    + linterid.ToString() + ",'" + HBarCode + "','" + HBarCodeType + "'," + HMaterID + "," + HUnitID + "," + HQty2 + ",'" + HKFDate + "'," + HKFPeriod + ",'" + HKFDQDate
-                                    + "','" + HBatchNo + "'," + HSupID + "," + HGroupID + ",'" + ClsPub.CurUserName + "','" + DateTime.Today + "'," + HPrintQty + ",'" + HWei + "',1"
-                                    + "," + HSourceInterID + "," + HSourceEntryID + ",'" + HSourceBillNo + "','" + HSourceBillType + "','" + HMTONO + "')");
+                        if (ClsPub.isLong(oItemSub.HMaterID) != 0)
+                        {
+                            HBarCode = oItemSub.HBarCode.ToString();
+                            HMTONO = ClsPub.isStrNull(oItemSub.HMTONO);
+                            HBarCodeType = "绠卞彿鍐呮潯鐮�";
+                            HMaterID = ClsPub.isLong(oItemSub.HMaterID);
+                            HUnitID = ClsPub.isLong(oItemSub.HUnitID);
+                            HQty2 = ClsPub.isDoule(oItemSub.HQty);
+                            HBatchNo = ClsPub.isStrNull(oItemSub.HBatchNo);
+                            HSupID = oItemSub.HSupID;
+                            HKFPeriod = ClsPub.isInt(oItemSub.HKFPeriod);
+                            HKFDate = ClsPub.isStrNull(oItemSub.HKFDate);
+                            HKFDQDate = ClsPub.isStrNull(oItemSub.HKFDQDate);
+                            HSourceInterID = ClsPub.isLong(oItemSub.HSourceInterID);
+                            HSourceEntryID = ClsPub.isLong(oItemSub.HSourceEntryID);
+                            HSourceBillNo = ClsPub.isStrNull(oItemSub.HSourceBillNo);
+                            HSourceBillType = ClsPub.isStrNull(oItemSub.HSourceBillType);
+                            HWei = ClsPub.isStrNull(oItemSub.HEndQty);
+                            if (FCusName.Contains("澶忓疂"))
+                            {
+                                HBarCode = $"{oItemSub.HMaterID}";
+                                HBarCodeType = "鍝佺鐮�";
+                            }
+                            string 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 " +
+                                      ") values ("
+                                      + linterid.ToString() + ",'" + HBarCode + "','" + HBarCodeType + "'," + HMaterID + "," + HUnitID + "," + HQty2 + ",'" + HKFDate + "'," + HKFPeriod + ",'" + HKFDQDate
+                                      + "','" + HBatchNo + "','" + SubModel.Count + "','" + _count + "'," + HSupID + "," + HGroupID + ",'" + ClsPub.CurUserName + "','" + DateTime.Today + "'," + HPrintQty + ",'" + HWei + "',1"
+                                      + "," + HSourceInterID + "," + HSourceEntryID + ",'" + HSourceBillNo + "','" + HSourceBillType + "','" + HMTONO + "')";
+                            oCn.RunProc(sql);
+                            _count++;
+                        }
                     }
                 }
                 //鏆傛椂鍙洖濉叧鑱旀暟閲�
-                oCn.RunProc("exec H_p_SRM_BarCodeBill_Update_UpdateBillRelateData " + linterid.ToString());
+                foreach (Model.ClsGy_MaterialList_WMS_Model oItemSub in ls)
+                {
+                    if (oItemSub.HQty == 0)
+                        continue;
+                    //鏇存柊鏉$爜妗f 璇ユ簮鍗曞叾瀹冩潯鐮侀粯璁ゅ凡缁忔墦鍗拌繃涓�娆�
+                    //鏇存柊 宸叉墦鍗版暟閲�
+                    if (oItemSub.HSourceBillType == "1102")
+                    {
+                        string _HBarCodeType = "绠卞彿鏉$爜";
+                        if (FCusName.Contains("澶忓疂"))
+                            _HBarCodeType = "鍝佺鐮�";
+                        string sql = string.Empty;
+                        sql = string.Format(@"
+update t1 set  
+t1.HBarcodeCount = 
+isnull((select sum(HQty)from Gy_BarCodeBill where HSourceInterID = t1.HInterID and HSourceEntryID = t1.HEntryID and HBarCodeType ='{2}'),0)
+from Cg_POOrderBillSub t1 
+where t1.HInterID = {0} and t1.HEntryID ={1}", oItemSub.HSourceInterID, oItemSub.HSourceEntryID, _HBarCodeType);
+                        oCn.RunProc(sql);
+                    }
+                }
                 oCn.Commit();
+
             }
             catch (Exception e)
             {
@@ -1933,12 +2037,20 @@
         }
 
         [Route("DeltetBarCodeBill")]
-        [HttpGet]
-        public object DeltetBarCodeBill(string HInterID, string HUserName)
+        [HttpPost]
+        public object DeltetBarCodeBill([FromBody] JObject oData)
         {
             SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
             try
             {
+                var _value = oData["oData"].ToString();
+                string msg1 = _value.ToString();
+                string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
+                string HInter = sArray[0].ToString();
+                string HInterID = HInter.Replace("\"", "");
+                string HUserName = sArray[1].ToString();
+
+                string FCusName = oSystemParameter.GetSingleSystemParameter("WMS_CampanyName", ref DBUtility.ClsPub.sExeReturnInfo);
                 string sql = "select HItemID,HBarCode,HSourceInterID,HSourceEntryID,HQty,HBarCodeType,HSourceBillType from Gy_BarCodeBill where  HItemID in(" + HInterID + ") ";
                 //LogService.Write("鍒犻櫎sql:" + sql);
                 oCN.BeginTran();
@@ -1947,9 +2059,12 @@
                 {
                     foreach (DataRow dr in dt.Rows)
                     {
+                        string _HBarCodeType = "绠卞彿鏉$爜";
+                        if (FCusName.Contains("澶忓疂"))
+                            _HBarCodeType = "鍝佺鐮�";
                         WebAPIController.Add_Log("鏉$爜妗f鍒犻櫎", HUserName, "鍗曞彿" + dr["HBarCode"].ToString());
                         //鍙嶅啓鎵撳嵃鏁伴噺鍒伴噰璐鍗曞瓙琛�
-                        if (dr["HBarCodeType"].ToString() == "绠卞彿鍐呮潯鐮�" && dr["HSourceBillType"].ToString() == "1102")
+                        if (dr["HBarCodeType"].ToString() == _HBarCodeType && dr["HSourceBillType"].ToString() == "1102")
                             oCN.RunProc($"update Cg_POOrderBillSub set HBarcodeCount -= {dr["HQty"]} where  HInterID ={dr["HSourceInterID"]} and  HEntryID ={dr["HSourceEntryID"]}");
                         //鍙嶅啓鎵撳嵃鏁伴噺鍒板澶栬鍗�
                         if (dr["HBarCodeType"].ToString() == "绠卞彿鍐呮潯鐮�" && dr["HSourceBillType"].ToString() == "1601")
@@ -1960,7 +2075,7 @@
                         //oCN.RunProc($"update WW_EntrustOrderBillSub set HBarcodeCount -= {dr["HQty"]} where  HInterID ={dr["HSourceInterID"]} and  HEntryID ={dr["HSourceEntryID"]}");
                     }
                 }
-                //oCN.RunProc("Delete From Gy_BarCodeBill where HItemID in(" + HInterID + ") ");
+                oCN.RunProc("Delete From Gy_BarCodeBill where HItemID in(" + HInterID + ") ");
                 oCN.Commit();
                 objJsonResult.code = "1";
                 objJsonResult.count = 1;
diff --git a/WebAPI/Controllers/POInStockController.cs b/WebAPI/Controllers/POInStockController.cs
index 6b5d253..02e9962 100644
--- a/WebAPI/Controllers/POInStockController.cs
+++ b/WebAPI/Controllers/POInStockController.cs
@@ -5,6 +5,7 @@
 using System;
 using System.Collections.Generic;
 using System.Data;
+using System.Diagnostics;
 using System.IO;
 using System.Linq;
 using System.Net;
@@ -323,7 +324,7 @@
                     oItem.HMainSourceInterID = oItem.HInterID;
                     oItem.HInterID = 0;
                     //oItem.HInterID = DBUtility.ClsPub.CreateBillID_SRMProd("1103", ref DBUtility.ClsPub.sExeReturnInfo);
-                    if (FCusName == "瀹夌憺鍖荤枟") //绯荤粺鍙傛暟  瀹㈡埛瀹氬埗鍖栧悕绉�     绌虹櫧涓洪�氱敤
+                    if (FCusName.Contains("瀹夌憺")) //绯荤粺鍙傛暟  瀹㈡埛瀹氬埗鍖栧悕绉�     绌虹櫧涓洪�氱敤
                     {
                         if (DBUtility.ClsPub.isStrNull(oItem.HDHDate) == "")
                         {
@@ -425,6 +426,7 @@
                 return objJsonResult;
             }
         }
+
         /// <summary>
         /// 閫佽揣鍗曞垪琛�
         /// </summary>
@@ -440,13 +442,14 @@
             string HSupNo = msg["HSupNo"].ToString(); string sqlWhere = msg["sqlWhere"].ToString();
             try
             {
+                Stopwatch sw = new Stopwatch();
+                sw.Start();//寮�濮嬭鏃�
                 string VsWhere = "";
                 string PcWhere = "";
                 SQLHelper.ClsCNSRM oCn = new SQLHelper.ClsCNSRM();
                 DataSet ds;
                 //鍏朵粬杩囨护
                 string sql = " Where hsupid in (select HSupID from h_v_Gy_UserSupplierList where 鐢ㄦ埛 =^^" + HSupNo.Trim() + "^^) " + sqlWhere;
-
                 //杞崲鐗规畩瀛楃
                 if (Common.SQLtoChange(sql, ref VsWhere, ref PcWhere) == false)
                 {
@@ -461,13 +464,13 @@
                 //鑾峰彇杩斿洖鏁版嵁
                 ds = oCn.RunProcReturn("exec H_p_SRM_POInStockBillList '" + PcWhere + "'", "H_p_SRM_POInStockBillList");
                 LogService.Write("閫佽揣鍗曞垪琛ㄥ姞杞絪ql:exec H_p_SRM_POInStockBillList '" + PcWhere + "'");
-
+                LogService.Write("鏁版嵁鏌ヨ杩斿洖" + sw.Elapsed);
+                sw.Stop();//缁撴潫璁℃椂
                 objjson.code = "0";
                 objjson.count = 10000;
                 objjson.Message = "鑾峰彇鎴愬姛";
                 objjson.data = ds.Tables[0];
                 return objjson;
-
             }
             catch (Exception e)
             {
@@ -614,170 +617,7 @@
                 string HValue = "Y";
                 if (HValue == "Y")
                 {
-                    if (FCusName == "鐟炰笌绁�" || FCusName == "" || FCusName.Contains("鍥涚淮灏�") || FCusName.Contains("鍑礉濂堢壒"))
-                    {
-                        sql = string.Format(@"
-SELECT T3.FNAME AS FTYPENAME,M.HBILLNO,B.HINTERID,B.HENTRYID,C.FID,C.FENTRYID, D.FBILLNO,B.HQTY,CD.FRECEIVEORGID,CDOO.FNUMBER AS FRECEIVENUMBER
-,D.FSUPPLIERID,DS.FNUMBER AS FSUPPLIERNUMBER,D.FPURCHASEORGID,DOO.FNUMBER AS FPURCHASEORGNUMBER,CROO.FNUMBER  AS FSETTLEORGNUMBER,
-E.FPRICETIMEPOINT,E.FSETTLECURRID,EC.FNUMBER AS FSETTLECURRNUMBER,C.FMATERIALID,CM.FNUMBER AS FMATERIALNUMBER ,C.FUNITID 
-,CU.FNUMBER AS FUNITNUMBER,CR.FPRICE,CR.FTAXPRICE,CR.FTAXRATE,D.FPURCHASERID,isnull(T4.FNUMBER,'') AS FPURCHASERNUMBER
-FROM CG_POINSTOCKBILLSUB B  
-JOIN CG_POINSTOCKBILLMAIN M ON B.HINTERID = M.HINTERID
-JOIN {0}..T_PUR_POORDERENTRY C ON B.HSOURCEINTERID = C.FID AND B.HSOURCEENTRYID = C.FENTRYID
-LEFT JOIN {0}..T_BD_MATERIAL CM ON C.FMATERIALID =CM.FMATERIALID
-LEFT JOIN {0}..T_BD_UNIT CU ON C.FUNITID =CU.FUNITID
-JOIN {0}..T_PUR_POORDERENTRY_D CD ON    C.FENTRYID = CD.FENTRYID
-LEFT JOIN {0}..T_ORG_ORGANIZATIONS CDOO ON CD.FRECEIVEORGID = CDOO.FORGID
-JOIN {0}..T_PUR_POORDERENTRY_F CR ON    C.FENTRYID = CR.FENTRYID
-LEFT JOIN {0}..T_ORG_ORGANIZATIONS CROO ON CR.FSETTLEORGID = CROO.FORGID
-LEFT JOIN {0}..T_PUR_POORDER D ON C.FID =D.FID
-LEFT JOIN {0}..T_BAS_BILLTYPE T2 ON D.FBILLTYPEID = T2.FBILLTYPEID
-LEFT JOIN {0}..T_BAS_BILLTYPE_L T3 ON T2.FBILLTYPEID = T3.FBILLTYPEID and FLOCALEID = 2052
-LEFT JOIN  {0}..V_BD_BUYER T4 ON D.FPURCHASERID =T4.FID
-LEFT JOIN {0}..T_BD_SUPPLIER DS ON D.FSUPPLIERID = DS.FSUPPLIERID
-LEFT JOIN {0}..T_ORG_ORGANIZATIONS DOO ON D.FPURCHASEORGID = DOO.FORGID
-JOIN {0}..T_PUR_POORDERFIN E ON C.FID =E.FID
-LEFT JOIN {0}..T_BD_CURRENCY EC ON E. FSETTLECURRID =EC.FCURRENCYID  
- WHERE b.hinterid in ({1}) and M.HERPInterID = 0
-", kdTbaleName, HInterID);
-                        dt = oCn.RunProcReturn(sql, "sltz").Tables[0];
-                        if (dt.Rows.Count > 0)
-                        {
-                            foreach (DataRow dr in dt.Rows)
-                            {
-                                //閲囪喘璁㈠崟涓嬫帹鐢熸垚閫佽揣鍗� 鏃跺�� 鍒ゆ柇鏄惁鏈夌敓鎴愰噰璐鍗曞彉鏇村崟 濡傛灉鏈変笖鍙樻洿鍗曠姸鎬佷笉涓哄凡瀹℃牳 闄愬埗涓嬫帹
-                                objJsonResult = TestPOOrder(dr["FEntryID"].ToString());
-                                if (objJsonResult.code == "0")
-                                    return objJsonResult;
-                            }
-                            foreach (DataRow dr in dt.Rows)
-                            {
-                                if (fidList.Contains(dr["HINTERID"].ToString()))
-                                    continue;
-                                else
-                                    fidList.Add(dr["HINTERID"].ToString());
-                                DataRow[] drs = dt.Select("HINTERID = " + dr["HINTERID"].ToString());
-                                JObject model = new JObject();
-                                string fTypeName = "SLD01_SYS";//鏍囧噯閲囪喘璁㈠崟绫诲瀷
-                                string ywTypeName = "CG";//鏍囧噯涓氬姟绫诲瀷
-                                if (dr["FTYPENAME"].ToString().Contains("濮斿"))
-                                {
-                                    fTypeName = "SLD03_SYS";
-                                    ywTypeName = "WW";
-                                }
-                                if (dr["FTYPENAME"].ToString().Contains("璧勪骇"))
-                                {
-                                    fTypeName = "SLD04_SYS";
-                                    ywTypeName = "ZCCG";
-                                }
-                                model.Add("FBILLTYPEID", new JObject() { ["Fnumber"] = fTypeName }); //鍗曟嵁绫诲瀷
-                                model.Add("FBusinessType", ywTypeName); //涓氬姟绫诲瀷
-                                model.Add("FBILLNO", dr["HBillNo"].ToString()); //鍗曟嵁缂栧彿
-                                model.Add("FDate", DateTime.Now.ToString("yyyy-MM-dd")); //閫氱煡鏃ユ湡
-                                model.Add("FStockOrgId", new JObject() { ["Fnumber"] = dr["FRECEIVENUMBER"].ToString() }); // 鏀舵枡缁勭粐 
-                                model.Add("FPurOrgId", new JObject() { ["Fnumber"] = dr["FPURCHASEORGNUMBER"].ToString() }); //閲囪喘缁勭粐
-                                model.Add("FSupplierId", new JObject() { ["Fnumber"] = dr["FSUPPLIERNUMBER"].ToString() }); //渚涘簲鍟�
-                                model.Add("FPURCHASERID", new JObject() { ["Fnumber"] = dr["FPURCHASERNUMBER"].ToString() }); //閲囪喘鍛�
-                                model.Add("FOwnerTypeIdHead", "BD_Supplier");//  璐т富绫诲瀷
-                                model.Add("FOwnerIdHead", new JObject() { ["Fnumber"] = dr["FSUPPLIERNUMBER"].ToString() });//璐т富 渚涘簲鍟� 
-                                JArray Fentity = new JArray();
-                                foreach (var item in drs)
-                                {
-                                    JObject FentityModel = new JObject();
-                                    FentityModel.Add("FMaterialId", new JObject() { ["Fnumber"] = item["FMATERIALNUMBER"].ToString() }); // 鐗╂枡缂栫爜   
-                                    FentityModel.Add("FUnitID", new JObject() { ["Fnumber"] = item["FUNITNUMBER"].ToString() }); // 鍗曚綅   
-                                    FentityModel.Add("FPreDeliveryDate", DateTime.Now.ToString("yyyy-MM-dd")); //棰勮鍒拌揣鏃ユ湡   
-                                    FentityModel.Add("FPriceUnitId", new JObject() { ["Fnumber"] = item["FUNITNUMBER"].ToString() }); // 璁′环鍗曚綅   
-                                    FentityModel.Add("FStockUnitID", new JObject() { ["Fnumber"] = item["FUNITNUMBER"].ToString() }); //  搴撳瓨鍗曚綅   
-                                    FentityModel.Add("FStockID", new JObject() { ["Fnumber"] = "BJCK-SH.01.005" }); //  搴撳瓨鍗曚綅   
-                                    FentityModel.Add("FActReceiveQty", Convert.ToDecimal(item["HQTY"])); // 渚涘簲鍟嗛�佽揣鏁伴噺锛堟彁鏂欒鍒掓暟閲� - 宸茬敓鎴愰�佽揣鍗曟暟閲忥級
-                                    FentityModel.Add("FOwnerTypeId", "BD_OwnerOrg");//璐т富绫诲瀷
-                                    FentityModel.Add("FOwnerID", new JObject() { ["Fnumber"] = dr["FPURCHASEORGNUMBER"].ToString() });//璐т富 
-                                    FentityModel.Add("FSrcId", item["FID"].ToString());//婧愬崟鍐呯爜
-                                    FentityModel.Add("FSRCFORMID", "PUR_PurchaseOrder");//婧愬崟绫诲瀷
-                                    FentityModel.Add("FSrcBillNo", item["FBILLNO"].ToString());//婧愬崟鍗曞彿
-                                    FentityModel.Add("FSRCENTRYID", item["FENTRYID"].ToString());//婧愬崟鍒嗗綍鍐呯爜
-                                    FentityModel.Add("FORDERBILLNO", item["FBILLNO"].ToString());//婧愬崟鍗曞彿
-                                    FentityModel.Add("FPOORDERENTRYID", item["FENTRYID"].ToString());//婧愬崟鍒嗗綍鍐呯爜
-                                    FentityModel.Add("FSRMENTRYID", item["HENTRYID"].ToString());//SRM hentryid
-                                    FentityModel.Add("FPrice", item["FPRICE"].ToString());//鍗曚环
-                                    FentityModel.Add("FTaxPrice", item["FTAXPRICE"].ToString());//鍚◣鍗曚环
-                                    FentityModel.Add("FEntryTaxRate", item["FTAXRATE"].ToString());//绋庣巼
-
-                                    JArray Fentity2 = new JArray();
-                                    JObject FentityModel2 = new JObject();
-                                    FentityModel2.Add("FDetailEntity_Link_FRULEID", "PUR_PurchaseOrder-PUR_ReceiveBill");
-                                    FentityModel2.Add("FDetailEntity_Link_FSTableName", "t_PUR_POOrderEntry");
-                                    FentityModel2.Add("FDetailEntity_Link_FSBillId", item["FID"].ToString());
-                                    FentityModel2.Add("FDetailEntity_Link_FSId", item["FEntryID"].ToString());
-                                    Fentity2.Add(FentityModel2);
-                                    FentityModel.Add("FDetailEntity_Link", Fentity2);
-                                    Fentity.Add(FentityModel);
-                                }
-                                model.Add("FDetailEntity", Fentity); //鏄庣粏淇℃伅
-
-                                JObject _FentityModel = new JObject();
-                                _FentityModel.Add("FSettleOrgId", new JObject() { ["Fnumber"] = dr["FSETTLEORGNUMBER"].ToString() }); //  缁撶畻缁勭粐  
-                                _FentityModel.Add("FSettleCurrId", new JObject() { ["Fnumber"] = dr["FSETTLECURRNUMBER"].ToString() }); //  缁撶畻甯佸埆
-                                _FentityModel.Add("FPricePoint", 0); //  瀹氫环鏃剁偣
-                                model.Add("FinanceEntity ", _FentityModel);//璐㈠姟淇℃伅
-                                JObject jsonRoot = new JObject()
-                                {
-                                    ["Creator"] = "",
-                                    ["NeedUpDateFields"] = new JArray(),
-                                    ["NeedReturnFields"] = new JArray(),
-                                    ["IsDeleteEntry"] = "false",
-                                    ["SubSystemId"] = "",
-                                    ["IsVerifyBaseDataField"] = "false",
-                                    ["Model"] = model
-                                };
-                                var loginRet = InvokeHelper.Login();
-                                var isSuccess = JObject.Parse(loginRet)["LoginResultType"].Value<int>();
-                                if (isSuccess == 0)
-                                {
-                                    objjson.code = "0";
-                                    objjson.count = 0;
-                                    objjson.Message = loginRet;
-                                    objjson.data = null;
-                                    return objjson;
-                                }
-                                //LogService.Write("jsonRoot:" + jsonRoot.ToString());
-                                var result = InvokeHelper.Save("PUR_ReceiveBill", jsonRoot.ToString());
-                                //LogService.Write(result);
-                                if (JObject.Parse(result)["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper() == "TRUE")
-                                {
-                                    //鏇存柊閫佽揣鍗� 涓昏〃 ERP鍗曟嵁鍙� 浠ュ強 ERP涓诲唴鐜�
-                                    string FBillNo = JObject.Parse(result)["Result"]["Number"].ToString();
-                                    string FID = JObject.Parse(result)["Result"]["Id"].ToString();
-                                    string updateSql = string.Format(@"
-                                                      update a set 
-                                                      a.HERPInterID = {0} ,
-                                                      a.HERPBillNO   ='{1}'
-                                                      from Cg_POInStockBillMain a
-                                                      join Cg_POInStockBillSub b on a.hinterid = b.hinterid
-                                                      where b.HInterID = ({2})
-                                                      and b. HSOURCEINTERID = {3}
-                                                      and a.HERPInterID = 0
-                                                     ", FID, FBillNo, dr["HINTERID"].ToString(), dr["FID"].ToString());
-                                    oCn.RunProc(updateSql);
-                                }
-                                else
-                                {
-                                    objjson.code = "0";
-                                    objjson.count = 0;
-                                    objjson.Message = result;
-                                    objjson.data = null;
-                                    return objjson;
-                                }
-
-                            }
-                        }
-                        else
-                        {
-                            LogService.Write("鏀舵枡閫氱煡鍗曞鏍告棤鏁版嵁锛�" + sql);
-                        }
-                    }
-                    else if (FCusName == "澶忓疂鐢靛櫒")
+                    if (FCusName == "澶忓疂鐢靛櫒")
                     {
                         sql = string.Format(@"
 SELECT T3.FNAME AS FTYPENAME,M.HBILLNO,B.HINTERID,B.HENTRYID,C.FID,C.FENTRYID, D.FBILLNO,B.HQTY,CD.FRECEIVEORGID,CDOO.FNUMBER AS FRECEIVENUMBER
@@ -932,7 +772,176 @@
                             }
                         }
                     }
+                    else
+                    {
+                        sql = string.Format(@"
+SELECT T3.FNAME AS FTYPENAME,M.HBILLNO,B.HINTERID,B.HENTRYID,C.FID,C.FENTRYID, D.FBILLNO,B.HQTY,CD.FRECEIVEORGID,CDOO.FNUMBER AS FRECEIVENUMBER
+,D.FSUPPLIERID,DS.FNUMBER AS FSUPPLIERNUMBER,D.FPURCHASEORGID,DOO.FNUMBER AS FPURCHASEORGNUMBER,CROO.FNUMBER  AS FSETTLEORGNUMBER,
+E.FPRICETIMEPOINT,E.FSETTLECURRID,EC.FNUMBER AS FSETTLECURRNUMBER,C.FMATERIALID,CM.FNUMBER AS FMATERIALNUMBER ,C.FUNITID 
+,CU.FNUMBER AS FUNITNUMBER,CR.FPRICE,CR.FTAXPRICE,CR.FTAXRATE,D.FPURCHASERID,isnull(T4.FNUMBER,'') AS FPURCHASERNUMBER
+FROM CG_POINSTOCKBILLSUB B  
+JOIN CG_POINSTOCKBILLMAIN M ON B.HINTERID = M.HINTERID
+JOIN {0}..T_PUR_POORDERENTRY C ON B.HSOURCEINTERID = C.FID AND B.HSOURCEENTRYID = C.FENTRYID
+LEFT JOIN {0}..T_BD_MATERIAL CM ON C.FMATERIALID =CM.FMATERIALID
+LEFT JOIN {0}..T_BD_UNIT CU ON C.FUNITID =CU.FUNITID
+JOIN {0}..T_PUR_POORDERENTRY_D CD ON    C.FENTRYID = CD.FENTRYID
+LEFT JOIN {0}..T_ORG_ORGANIZATIONS CDOO ON CD.FRECEIVEORGID = CDOO.FORGID
+JOIN {0}..T_PUR_POORDERENTRY_F CR ON    C.FENTRYID = CR.FENTRYID
+LEFT JOIN {0}..T_ORG_ORGANIZATIONS CROO ON CR.FSETTLEORGID = CROO.FORGID
+LEFT JOIN {0}..T_PUR_POORDER D ON C.FID =D.FID
+LEFT JOIN {0}..T_BAS_BILLTYPE T2 ON D.FBILLTYPEID = T2.FBILLTYPEID
+LEFT JOIN {0}..T_BAS_BILLTYPE_L T3 ON T2.FBILLTYPEID = T3.FBILLTYPEID and FLOCALEID = 2052
+LEFT JOIN  {0}..V_BD_BUYER T4 ON D.FPURCHASERID =T4.FID
+LEFT JOIN {0}..T_BD_SUPPLIER DS ON D.FSUPPLIERID = DS.FSUPPLIERID
+LEFT JOIN {0}..T_ORG_ORGANIZATIONS DOO ON D.FPURCHASEORGID = DOO.FORGID
+JOIN {0}..T_PUR_POORDERFIN E ON C.FID =E.FID
+LEFT JOIN {0}..T_BD_CURRENCY EC ON E. FSETTLECURRID =EC.FCURRENCYID  
+ WHERE b.hinterid in ({1}) and M.HERPInterID = 0
+", kdTbaleName, HInterID);
+                        dt = oCn.RunProcReturn(sql, "sltz").Tables[0];
+                        if (dt.Rows.Count > 0)
+                        {
+                            foreach (DataRow dr in dt.Rows)
+                            {
+                                //閲囪喘璁㈠崟涓嬫帹鐢熸垚閫佽揣鍗� 鏃跺�� 鍒ゆ柇鏄惁鏈夌敓鎴愰噰璐鍗曞彉鏇村崟 濡傛灉鏈変笖鍙樻洿鍗曠姸鎬佷笉涓哄凡瀹℃牳 闄愬埗涓嬫帹
+                                objJsonResult = TestPOOrder(dr["FEntryID"].ToString());
+                                if (objJsonResult.code == "0")
+                                    return objJsonResult;
+                            }
+                            foreach (DataRow dr in dt.Rows)
+                            {
+                                if (fidList.Contains(dr["HINTERID"].ToString()))
+                                    continue;
+                                else
+                                    fidList.Add(dr["HINTERID"].ToString());
+                                DataRow[] drs = dt.Select("HINTERID = " + dr["HINTERID"].ToString());
+                                JObject model = new JObject();
+                                string fTypeName = "SLD01_SYS";//鏍囧噯閲囪喘璁㈠崟绫诲瀷
+                                string ywTypeName = "CG";//鏍囧噯涓氬姟绫诲瀷
+                                if (dr["FTYPENAME"].ToString().Contains("濮斿"))
+                                {
+                                    fTypeName = "SLD03_SYS";
+                                    ywTypeName = "WW";
+                                }
+                                if (dr["FTYPENAME"].ToString().Contains("璧勪骇"))
+                                {
+                                    fTypeName = "SLD04_SYS";
+                                    ywTypeName = "ZCCG";
+                                }
+                                model.Add("FBILLTYPEID", new JObject() { ["Fnumber"] = fTypeName }); //鍗曟嵁绫诲瀷
+                                model.Add("FBusinessType", ywTypeName); //涓氬姟绫诲瀷
+                                model.Add("FBILLNO", dr["HBillNo"].ToString()); //鍗曟嵁缂栧彿
+                                model.Add("FDate", DateTime.Now.ToString("yyyy-MM-dd")); //閫氱煡鏃ユ湡
+                                model.Add("FStockOrgId", new JObject() { ["Fnumber"] = dr["FRECEIVENUMBER"].ToString() }); // 鏀舵枡缁勭粐 
+                                model.Add("FPurOrgId", new JObject() { ["Fnumber"] = dr["FPURCHASEORGNUMBER"].ToString() }); //閲囪喘缁勭粐
+                                model.Add("FSupplierId", new JObject() { ["Fnumber"] = dr["FSUPPLIERNUMBER"].ToString() }); //渚涘簲鍟�
+                                model.Add("FPURCHASERID", new JObject() { ["Fnumber"] = dr["FPURCHASERNUMBER"].ToString() }); //閲囪喘鍛�
+                                model.Add("FOwnerTypeIdHead", "BD_Supplier");//  璐т富绫诲瀷
+                                model.Add("FOwnerIdHead", new JObject() { ["Fnumber"] = dr["FSUPPLIERNUMBER"].ToString() });//璐т富 渚涘簲鍟� 
+                                JArray Fentity = new JArray();
+                                foreach (var item in drs)
+                                {
+                                    JObject FentityModel = new JObject();
+                                    FentityModel.Add("FMaterialId", new JObject() { ["Fnumber"] = item["FMATERIALNUMBER"].ToString() }); // 鐗╂枡缂栫爜   
+                                    FentityModel.Add("FUnitID", new JObject() { ["Fnumber"] = item["FUNITNUMBER"].ToString() }); // 鍗曚綅   
+                                    FentityModel.Add("FPreDeliveryDate", DateTime.Now.ToString("yyyy-MM-dd")); //棰勮鍒拌揣鏃ユ湡   
+                                    FentityModel.Add("FPriceUnitId", new JObject() { ["Fnumber"] = item["FUNITNUMBER"].ToString() }); // 璁′环鍗曚綅   
+                                    FentityModel.Add("FStockUnitID", new JObject() { ["Fnumber"] = item["FUNITNUMBER"].ToString() }); //  搴撳瓨鍗曚綅   
+                                    FentityModel.Add("FStockID", new JObject() { ["Fnumber"] = "BJCK-SH.01.005" }); //  搴撳瓨鍗曚綅   
+                                    FentityModel.Add("FActReceiveQty", Convert.ToDecimal(item["HQTY"])); // 渚涘簲鍟嗛�佽揣鏁伴噺锛堟彁鏂欒鍒掓暟閲� - 宸茬敓鎴愰�佽揣鍗曟暟閲忥級
+                                    FentityModel.Add("FOwnerTypeId", "BD_OwnerOrg");//璐т富绫诲瀷
+                                    FentityModel.Add("FOwnerID", new JObject() { ["Fnumber"] = dr["FPURCHASEORGNUMBER"].ToString() });//璐т富 
+                                    FentityModel.Add("FSrcId", item["FID"].ToString());//婧愬崟鍐呯爜
+                                    FentityModel.Add("FSRCFORMID", "PUR_PurchaseOrder");//婧愬崟绫诲瀷
+                                    FentityModel.Add("FSrcBillNo", item["FBILLNO"].ToString());//婧愬崟鍗曞彿
+                                    FentityModel.Add("FSRCENTRYID", item["FENTRYID"].ToString());//婧愬崟鍒嗗綍鍐呯爜
+                                    FentityModel.Add("FORDERBILLNO", item["FBILLNO"].ToString());//婧愬崟鍗曞彿
+                                    FentityModel.Add("FPOORDERENTRYID", item["FENTRYID"].ToString());//婧愬崟鍒嗗綍鍐呯爜
+                                    FentityModel.Add("FSRMENTRYID", item["HENTRYID"].ToString());//SRM hentryid
+                                    FentityModel.Add("FPrice", item["FPRICE"].ToString());//鍗曚环
+                                    FentityModel.Add("FTaxPrice", item["FTAXPRICE"].ToString());//鍚◣鍗曚环
+                                    FentityModel.Add("FEntryTaxRate", item["FTAXRATE"].ToString());//绋庣巼
+
+                                    JArray Fentity2 = new JArray();
+                                    JObject FentityModel2 = new JObject();
+                                    FentityModel2.Add("FDetailEntity_Link_FRULEID", "PUR_PurchaseOrder-PUR_ReceiveBill");
+                                    FentityModel2.Add("FDetailEntity_Link_FSTableName", "t_PUR_POOrderEntry");
+                                    FentityModel2.Add("FDetailEntity_Link_FSBillId", item["FID"].ToString());
+                                    FentityModel2.Add("FDetailEntity_Link_FSId", item["FEntryID"].ToString());
+                                    Fentity2.Add(FentityModel2);
+                                    FentityModel.Add("FDetailEntity_Link", Fentity2);
+                                    Fentity.Add(FentityModel);
+                                }
+                                model.Add("FDetailEntity", Fentity); //鏄庣粏淇℃伅
+
+                                JObject _FentityModel = new JObject();
+                                _FentityModel.Add("FSettleOrgId", new JObject() { ["Fnumber"] = dr["FSETTLEORGNUMBER"].ToString() }); //  缁撶畻缁勭粐  
+                                _FentityModel.Add("FSettleCurrId", new JObject() { ["Fnumber"] = dr["FSETTLECURRNUMBER"].ToString() }); //  缁撶畻甯佸埆
+                                _FentityModel.Add("FPricePoint", 0); //  瀹氫环鏃剁偣
+                                model.Add("FinanceEntity ", _FentityModel);//璐㈠姟淇℃伅
+                                JObject jsonRoot = new JObject()
+                                {
+                                    ["Creator"] = "",
+                                    ["NeedUpDateFields"] = new JArray(),
+                                    ["NeedReturnFields"] = new JArray(),
+                                    ["IsDeleteEntry"] = "false",
+                                    ["SubSystemId"] = "",
+                                    ["IsVerifyBaseDataField"] = "false",
+                                    ["Model"] = model
+                                };
+                                var loginRet = InvokeHelper.Login();
+                                var isSuccess = JObject.Parse(loginRet)["LoginResultType"].Value<int>();
+                                if (isSuccess == 0)
+                                {
+                                    objjson.code = "0";
+                                    objjson.count = 0;
+                                    objjson.Message = loginRet;
+                                    objjson.data = null;
+                                    return objjson;
+                                }
+                                //LogService.Write("jsonRoot:" + jsonRoot.ToString());
+                                var result = InvokeHelper.Save("PUR_ReceiveBill", jsonRoot.ToString());                               
+
+                                //LogService.Write(result);
+                                if (JObject.Parse(result)["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper() == "TRUE")
+                                {
+                                    //鏇存柊閫佽揣鍗� 涓昏〃 ERP鍗曟嵁鍙� 浠ュ強 ERP涓诲唴鐜�
+                                    string FBillNo = JObject.Parse(result)["Result"]["Number"].ToString();
+                                    string FID = JObject.Parse(result)["Result"]["Id"].ToString();
+                                    string updateSql = string.Format(@"
+                                                      update a set 
+                                                      a.HERPInterID = {0} ,
+                                                      a.HERPBillNO   ='{1}'
+                                                      from Cg_POInStockBillMain a
+                                                      join Cg_POInStockBillSub b on a.hinterid = b.hinterid
+                                                      where b.HInterID = ({2})
+                                                      and b. HSOURCEINTERID = {3}
+                                                      and a.HERPInterID = 0
+                                                     ", FID, FBillNo, dr["HINTERID"].ToString(), dr["FID"].ToString());
+                                    oCn.RunProc(updateSql);
+                                }
+                                else
+                                {
+                                    objjson.code = "0";
+                                    objjson.count = 0;
+                                    objjson.Message = result;
+                                    objjson.data = null;
+                                    return objjson;
+                                }
+
+                            }
+                        }
+                        else
+                        {
+                            LogService.Write("鏀舵枡閫氱煡鍗曞鏍告棤鏁版嵁锛�" + sql);
+                        }
+                    }
+
                 }
+
+                ////鏇存柊鐗╂祦瀛楁 锛堢憺涓庣惇锛�
+                //oCn.RunProc("exec h_p_Cg_LocalToKingDee_POInStock " + HBillNo + "," + HInterID);
+
                 //鏇存柊涓昏〃鐘舵�� 瀹℃牳
                 sql = string.Format(@"update Cg_POInStockBillMain set 
 HBillStatus = 2 ,
@@ -981,8 +990,8 @@
             SQLHelper.ClsCNSRM oCn = new SQLHelper.ClsCNSRM();
             int HInterID = 0;
             string sql = "select HInterID from CG_POINSTOCKBILLMAIN where HBILLNO = '" + HBillNo + "'";
-            if (type == "Print")
-                sql += " and HBillStatus = '2' ";//鎵撳嵃鍒ゆ柇鏄惁瀹℃牳
+            //if (type == "Print")
+            //    sql += " and HBillStatus = '2' ";//鎵撳嵃鍒ゆ柇鏄惁瀹℃牳
             DataTable dt = oCn.RunProcReturn(sql, "HInterID").Tables[0];
             if (dt.Rows.Count > 0)
                 HInterID = Convert.ToInt32(dt.Rows[0]["HInterID"]);
@@ -1189,17 +1198,19 @@
                     var HinterID = mylist[i].ToString();
                     oCn.RunProc($"exec h_p_SRM_UpDatePPBomRelationQty {HinterID}");
                 }
+
                 //鍒ゆ柇鏈叧鑱旀暟閲忔槸鍚︿负0
-                DataSet ds = oCn.RunProcReturn($"select * from H_v_SRM_POOrderBillList where hsubid in ({string.Join(", ", entryList)}) ", "H_v_SRM_POOrderBillList");
+                //瀹夌憺锛欰IS20220914133941   鐟炰笌鐞細AIS20220308151944
+                DataSet ds = oCn.RunProcReturn($"select T1.hqty-T1.hrelationqty+q.FMRBQTY as hqty,鍗曟嵁鍙�,鐗╂枡缂栫爜 from H_v_SRM_POOrderBillList t1 left join AIS20220914133941..T_PUR_POORDERENTRY_R q on q.FENTRYID=t1.HEntryID  where hentryid in ({string.Join(", ", entryList)}) ", "H_v_SRM_POOrderBillList");
                 DataTable dt = ds.Tables[0];
                 if (dt.Rows.Count > 0)
                 {
-                    DataRow[] dr = dt.Select("鏈叧鑱旀暟閲� = " + 0);
+                    DataRow[] dr = dt.Select("hqty  <=" + 0);
                     if (dr.Count() > 0)
                     {
                         objJsonResult.code = "0";
                         objJsonResult.count = 0;
-                        objJsonResult.Message = $"璇锋鏌ユ暟鎹紝鍗曟嵁鍙凤細{dr[0]["鍗曟嵁鍙�"]},鐗╂枡浠g爜锛歿dr[0]["鐗╂枡浠g爜"]},鏈叧鑱旀暟閲忎负0锛屽凡鍏ㄩ儴鐢熸垚閫佽揣鍗曪紒";
+                        objJsonResult.Message = $"璇锋鏌ユ暟鎹紝鍗曟嵁鍙凤細{dr[0]["鍗曟嵁鍙�"]},鐗╂枡缂栫爜锛歿dr[0]["鐗╂枡缂栫爜"]},鍙互鍙戣揣鏁伴噺涓�0锛屽凡鍏ㄩ儴鐢熸垚閫佽揣鍗曪紒";
                         objJsonResult.data = null;
                         return objJsonResult;
                     }
diff --git a/WebAPI/Controllers/POOrderController.cs b/WebAPI/Controllers/POOrderController.cs
index 3578cf7..e8f676e 100644
--- a/WebAPI/Controllers/POOrderController.cs
+++ b/WebAPI/Controllers/POOrderController.cs
@@ -1,4 +1,5 @@
 锘縰sing DBUtility;
+using Newtonsoft.Json;
 using Newtonsoft.Json.Linq;
 using SQLHelper;
 using System;
@@ -53,15 +54,25 @@
                 //鑾峰彇鎬昏鏁�
                 //Int64 RowTotal = Common.GetRowTotal("H_v_SRM_POOrderBillList", VsWhere, ref DBUtility.ClsPub.sExeReturnInfo);
                 //鑾峰彇杩斿洖鏁版嵁
+                //sql = "exec H_P_REALESEPOORDER";
+                //sql = "exec H_P_REALESEPOORDER";
+                //oCn.RunProc(sql);
                 sql = "exec H_p_SRM_POOrderBillList '" + PcWhere + "'";
                 //LogService.WriteAsync(sql);
-
                 ds = oCn.RunProcReturn("exec H_p_SRM_POOrderBillList '" + PcWhere + "'", "H_p_SRM_POOrderBillList");
-
+                //娣诲姞鍒楀悕
+                List<object> columnNameList = new List<object>();
+                foreach (DataColumn col in ds.Tables[0].Columns)
+                {
+                    Type dataType = col.DataType;
+                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
+                    columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//鑾峰彇鍒癉ataColumn鍒楀璞$殑鍒楀悕
+                }
                 objjson.code = "0";
                 objjson.count = 10000;
                 objjson.Message = "鑾峰彇鎴愬姛";
                 objjson.data = ds.Tables[0];
+                objjson.list = columnNameList;
                 return objjson;
 
             }
diff --git a/WebAPI/Controllers/WebAPIController.cs b/WebAPI/Controllers/WebAPIController.cs
index 222cebe..c4fde65 100644
--- a/WebAPI/Controllers/WebAPIController.cs
+++ b/WebAPI/Controllers/WebAPIController.cs
@@ -15,6 +15,7 @@
 using System.Web.Http;
 using WebAPI.BLL;
 using WebAPI.Models;
+using WebAPI.Utility;
 
 namespace WebAPI.Controllers
 {
@@ -845,6 +846,29 @@
             return objjson; ;
         }
         #endregion
+        #region[鎵撳嵃idSession]
+        [Route("linteridSession")]
+        [HttpPost]
+        public object linteridSession([FromBody] JObject linterid)
+        {
+            var _linterid = linterid["linterid"].ToString();
+            var _huserName = linterid["HUserName"].ToString();
+            var postMesseege = _linterid + ";" + _huserName;
+            //HttpHelper.PostData("http://localhost:8082/ZYMES/layuiAdmin.std-v1.2.1/src/views/SRM/Api/SRM_Web_PoBarCodeBillApi.ashx", postMesseege);
+            HttpHelper.PostData("http://60.191.21.115:9090/layuiAdmin.std-v1.2.1/src/views/SRM/Api/SRM_Web_PoBarCodeBillApi.ashx", postMesseege);
+            SQLHelper.ClsCNSRM oCn = new SQLHelper.ClsCNSRM();
+            string sql = $"Update Gy_BarCodeBill set HPrintQty=isnull(HPrintQty,0) + 1  where HItemID in ({_linterid})";
+            oCn.RunProc(sql);
+            objJsonResult.code = "0";
+            objJsonResult.count = 0;
+            objJsonResult.Message = "";
+            objJsonResult.data = 1;
+            return objJsonResult;
+
+            //HttpContext.Current.Session["linterid"];
+
+        }
+        #endregion
 
 
     }
diff --git a/WebAPI/Controllers/Xt_grdAlignment_WMESController.cs b/WebAPI/Controllers/Xt_grdAlignment_WMESController.cs
index c0f49ba..86b7e5e 100644
--- a/WebAPI/Controllers/Xt_grdAlignment_WMESController.cs
+++ b/WebAPI/Controllers/Xt_grdAlignment_WMESController.cs
@@ -108,7 +108,7 @@
                 {
                     var width = omdelsub[i].ColumnWidth;
                     if (string.IsNullOrEmpty(width) || DBUtility.ClsPub.isLong(width) == 0)
-                        width = "120";
+                        width = "80";
                     HGridString += $"{(i+1)}|{(omdelsub[i].IsHide == true ? 1 : 0)}|{omdelsub[i].Alignment}|{width},";
                 }
                 HGridString = HGridString.Substring(0, HGridString.Length - 1);
diff --git a/WebAPI/DLL/DAL.dll b/WebAPI/DLL/DAL.dll
index f689d9a..a60eec5 100644
--- a/WebAPI/DLL/DAL.dll
+++ b/WebAPI/DLL/DAL.dll
Binary files differ
diff --git a/WebAPI/DLL/Model.dll b/WebAPI/DLL/Model.dll
index 4937121..cdeff4a 100644
--- a/WebAPI/DLL/Model.dll
+++ b/WebAPI/DLL/Model.dll
Binary files differ
diff --git a/WebAPI/Models/JsonResult.cs b/WebAPI/Models/JsonResult.cs
index 411f417..60b3982 100644
--- a/WebAPI/Models/JsonResult.cs
+++ b/WebAPI/Models/JsonResult.cs
@@ -11,5 +11,7 @@
         public int count { get; set; }
         public string Message { get; set; }
         public object data { get; set; }
+        public List<object> list { get; set; }
+
     }
 }
\ No newline at end of file
diff --git a/WebAPI/Models/json.cs b/WebAPI/Models/json.cs
index 3a10890..4c72226 100644
--- a/WebAPI/Models/json.cs
+++ b/WebAPI/Models/json.cs
@@ -11,5 +11,7 @@
         public int count { get; set; }
         public string Message { get; set; }
         public object data { get; set; }
+        public List<object> list { get; set; }
+
     }
 }
diff --git a/WebAPI/Utility/HttpHelper.cs b/WebAPI/Utility/HttpHelper.cs
new file mode 100644
index 0000000..1a09b27
--- /dev/null
+++ b/WebAPI/Utility/HttpHelper.cs
@@ -0,0 +1,134 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Net;
+using System.Net.Http;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WebAPI.Utility
+{
+    public class HttpHelper
+    {
+        public static string PostData(string url, string postData)
+        {
+            ASCIIEncoding encoding = new ASCIIEncoding();
+            byte[] data = Encoding.UTF8.GetBytes(postData);
+            HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
+
+            myRequest.Method = "POST";
+            myRequest.ContentType = "application/x-www-form-urlencoded";
+            myRequest.ContentLength = data.Length;
+            Stream newStream = myRequest.GetRequestStream();
+
+            newStream.Write(data, 0, data.Length);
+            newStream.Close();
+
+            HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
+            StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
+            string content = reader.ReadToEnd();
+            reader.Close();
+            return content;
+        }
+
+        public static string GetData(string url)
+        {
+            HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
+            myRequest.Method = "GET";
+            HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
+            StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
+            string content = reader.ReadToEnd();
+            reader.Close();
+            return content;
+        }
+
+        /// <summary>
+        /// FORM琛ㄥ崟POST鏂瑰紡涓婁紶涓�涓濯掍綋鏂囦欢
+        /// </summary>
+        /// <param name="url">API URL</param>
+        /// <param name="typeName"></param>
+        /// <param name="fileName"></param>
+        /// <param name="fs"></param>
+        /// <param name="encoding"></param>
+        /// <returns></returns>
+        public static string HttpRequestPost(string url, string typeName, string fileName, Stream fs, string encoding = "UTF-8")
+        {
+            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
+            request.Method = "POST";
+            request.Timeout = 10000;
+            var postStream = new MemoryStream();
+            #region 澶勭悊Form琛ㄥ崟鏂囦欢涓婁紶
+            //閫氳繃琛ㄥ崟涓婁紶鏂囦欢
+            string boundary = "----" + DateTime.Now.Ticks.ToString("x");
+            string formdataTemplate = "\r\n--" + boundary + "\r\nContent-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\nContent-Type: application/octet-stream\r\n\r\n";
+            try
+            {
+                var formdata = string.Format(formdataTemplate, typeName, fileName);
+                var formdataBytes = Encoding.ASCII.GetBytes(postStream.Length == 0 ? formdata.Substring(2, formdata.Length - 2) : formdata);//绗竴琛屼笉闇�瑕佹崲琛�
+                postStream.Write(formdataBytes, 0, formdataBytes.Length);
+
+                //鍐欏叆鏂囦欢
+                byte[] buffer = new byte[1024];
+                int bytesRead = 0;
+                while ((bytesRead = fs.Read(buffer, 0, buffer.Length)) != 0)
+                {
+                    postStream.Write(buffer, 0, bytesRead);
+                }
+            }
+            catch (Exception ex)
+            {
+                throw ex;
+            }
+
+            //缁撳熬
+            var footer = Encoding.ASCII.GetBytes("\r\n--" + boundary + "--\r\n");
+            postStream.Write(footer, 0, footer.Length);
+            request.ContentType = string.Format("multipart/form-data; boundary={0}", boundary);
+            #endregion
+
+            request.ContentLength = postStream != null ? postStream.Length : 0;
+            request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
+            request.KeepAlive = true;
+            request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36";
+
+            #region 杈撳叆浜岃繘鍒舵祦
+            if (postStream != null)
+            {
+                postStream.Position = 0;
+
+                //鐩存帴鍐欏叆娴�
+                Stream requestStream = request.GetRequestStream();
+
+                byte[] buffer = new byte[1024];
+                int bytesRead = 0;
+                while ((bytesRead = postStream.Read(buffer, 0, buffer.Length)) != 0)
+                {
+                    requestStream.Write(buffer, 0, bytesRead);
+                }
+
+                postStream.Close();//鍏抽棴鏂囦欢璁块棶
+            }
+            #endregion
+
+            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
+            using (Stream responseStream = response.GetResponseStream())
+            {
+                using (StreamReader myStreamReader = new StreamReader(responseStream, Encoding.GetEncoding(encoding)))
+                {
+                    string retString = myStreamReader.ReadToEnd();
+                    return retString;
+                }
+            }
+        }
+
+        //public static string PostDataV2(string data, string url)
+        //{
+        //    WebClient wc = new WebClient();
+        //    wc.Headers.Add("Content-Type", "application/json");
+        //    byte[] postData = Encoding.ASCII.GetBytes(data);
+        //    byte[] responseData = wc.UploadData(url, "POST", postData);
+        //    return Encoding.UTF8.GetString(responseData);
+        //}
+    }
+}
diff --git a/WebAPI/WebAPI.csproj b/WebAPI/WebAPI.csproj
index b82c721..a6dc916 100644
--- a/WebAPI/WebAPI.csproj
+++ b/WebAPI/WebAPI.csproj
@@ -46,9 +46,9 @@
     <Reference Include="BouncyCastle.Crypto, Version=1.8.9.0, Culture=neutral, PublicKeyToken=0e99375e54769942, processorArchitecture=MSIL">
       <HintPath>..\packages\Portable.BouncyCastle.1.8.9\lib\net40\BouncyCastle.Crypto.dll</HintPath>
     </Reference>
-    <Reference Include="DAL, Version=1.0.0.0, Culture=neutral, processorArchitecture=x86">
+    <Reference Include="DAL, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>
-      <HintPath>..\..\SRM-MES\SRM-MES\DAL\bin\Debug\DAL.dll</HintPath>
+      <HintPath>..\..\..\SRM-MES\SRM-MES\DAL\bin\Debug\DAL.dll</HintPath>
     </Reference>
     <Reference Include="DBUtility, Version=1.0.0.0, Culture=neutral, processorArchitecture=x86">
       <SpecificVersion>False</SpecificVersion>
@@ -240,6 +240,7 @@
     <Compile Include="MyHub.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Startup.cs" />
+    <Compile Include="Utility\HttpHelper.cs" />
     <Compile Include="Utility\Util.cs" />
   </ItemGroup>
   <ItemGroup>
diff --git a/WebAPI/bin.7z b/WebAPI/bin.7z
deleted file mode 100644
index 0c62827..0000000
--- a/WebAPI/bin.7z
+++ /dev/null
Binary files differ
diff --git "a/\345\205\250\351\203\250\345\256\242\346\210\267\345\234\250\350\277\220\347\224\250.txt" "b/\345\205\250\351\203\250\345\256\242\346\210\267\345\234\250\350\277\220\347\224\250.txt"
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ "b/\345\205\250\351\203\250\345\256\242\346\210\267\345\234\250\350\277\220\347\224\250.txt"

--
Gitblit v1.9.1