From 4c7cb8434be52f1de8557c069ebf82dfbfd8d6ee Mon Sep 17 00:00:00 2001
From: zrg <z1873@LAPTOP-EAVL132E>
Date: 星期三, 05 十一月 2025 15:29:46 +0800
Subject: [PATCH] 增加凯贝装箱单

---
 WebAPI/Controllers/XSGL/Kf_SellOutBillController.cs |  534 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 524 insertions(+), 10 deletions(-)

diff --git a/WebAPI/Controllers/XSGL/Kf_SellOutBillController.cs b/WebAPI/Controllers/XSGL/Kf_SellOutBillController.cs
index 5b4aaee..fc32f70 100644
--- a/WebAPI/Controllers/XSGL/Kf_SellOutBillController.cs
+++ b/WebAPI/Controllers/XSGL/Kf_SellOutBillController.cs
@@ -1257,7 +1257,7 @@
             {
                 List<object> columnNameListSum = new List<object>();
                 List<object> columnNameList0 = new List<object>();
-                //List<object> columnNameList1 = new List<object>();
+                List<object> columnNameList1 = new List<object>();
                 //List<object> columnNameList2 = new List<object>();
                 //List<object> columnNameList3 = new List<object>();
                 //List<object> columnNameList4 = new List<object>();
@@ -1273,13 +1273,13 @@
                     columnNameList0.Add(JsonConvert.DeserializeObject(ColmString));//鑾峰彇鍒癉ataColumn鍒楀璞$殑鍒楀悕
                 }
 
-                ////娣诲姞 鐢熶骇璁㈠崟 鍒楀悕
-                //foreach (DataColumn col in ds.Tables[1].Columns)
-                //{
-                //    Type dataType = col.DataType;
-                //    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
-                //    columnNameList1.Add(JsonConvert.DeserializeObject(ColmString));//鑾峰彇鍒癉ataColumn鍒楀璞$殑鍒楀悕
-                //}
+                //娣诲姞 鐢熶骇璁㈠崟 鍒楀悕
+                foreach (DataColumn col in ds.Tables[1].Columns)
+                {
+                    Type dataType = col.DataType;
+                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
+                    columnNameList1.Add(JsonConvert.DeserializeObject(ColmString));//鑾峰彇鍒癉ataColumn鍒楀璞$殑鍒楀悕
+                }
 
                 ////娣诲姞 鐗规壒鐢宠鍗� 鍒楀悕
                 //foreach (DataColumn col in ds.Tables[2].Columns)
@@ -1306,7 +1306,7 @@
                 //}
 
                 columnNameListSum.Add(columnNameList0);
-                //columnNameListSum.Add(columnNameList1);
+                columnNameListSum.Add(columnNameList1);
                 //columnNameListSum.Add(columnNameList2);
                 //columnNameListSum.Add(columnNameList3);
                 //columnNameListSum.Add(columnNameList4);
@@ -1971,7 +1971,7 @@
                 }
                 string sql = "select * from h_v_Kf_SellOutBillQuerySub where hmainid =  " + hmainid;
 
-                ds = oCN.RunProcReturn(sql + " order by hsubid desc", "h_v_Kf_SellOutBillQuerySub");
+                ds = oCN.RunProcReturn(sql + " order by hsubid ASC", "h_v_Kf_SellOutBillQuerySub");
 
 
                 foreach (DataColumn col in ds.Tables[0].Columns)
@@ -1999,5 +1999,519 @@
         }
         #endregion
 
+        #region 閿�鍞嚭搴撳崟 鍒ゆ柇鏄惁鍏峰鏌ョ湅閲戦鏉冮檺
+        [Route("Kf_SellOutBill/CheckRight_Money")]
+        [HttpGet]
+        public object CheckRight_Money(string user)
+        {
+            try
+            {
+                //鍒ゆ柇鏌ヨ鏉冮檺
+                if (!DBUtility.ClsPub.Security_Log("Kf_SellOutBill_Money", 1, false, user))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鏃犳潈闄愭煡璇�!";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "Sucess锛�";
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
+        #region 閿�鍞嚭搴撳崟 浠锋牸鏌ヨ
+        [Route("Kf_SellOutBill/GetKf_CheckSellOutBill_BalanceQuery")]
+        [HttpGet]
+        public object GetKf_CheckSellOutBill_BalanceQuery(string HInterID, string user)
+        {
+            try
+            {
+                //鍒ゆ柇鏌ヨ鏉冮檺
+                if (!DBUtility.ClsPub.Security_Log("Kf_SellOutBill_Money", 1, false, user))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鏃犳潈闄愭煡璇�!";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                DataSet ds2 = oCN.RunProcReturn("exec h_p_Kf_CheckSellOutBill_CrediControl " + HInterID, "h_p_Kf_CheckSellOutBill_BalanceQuery");
+
+                if (ds2 == null)
+                {
+                    throw new Exception("鏃犺繑鍥炲��!");
+                }else
+                {
+                    objJsonResult.code = "1";
+                    objJsonResult.count = 1;
+                    objJsonResult.Message = "Sucess锛�";
+                    objJsonResult.data = ds2.Tables[0];
+                    return objJsonResult;
+                }
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
+        #region 鏍峰搧閿�鍞嚭搴� 瀹℃牳/鍙嶅鏍�
+        /// <summary>
+        /// </summary>
+        /// <param name="HInterID">鍗曟嵁ID</param>
+        /// <param name="IsAudit">瀹℃牳(0),鍙嶅鏍�(1)</param>
+        /// <param name="CurUserName">瀹℃牳浜�</param>
+        /// <returns></returns>
+        [Route("Kf_SellOutBill/AuditKf_SellOutBill_YP")]
+        [HttpGet]
+        public object AuditKf_SellOutBill_YP(int HInterID, int IsAudit, string CurUserName)
+        {
+            string ModRightNameCheck = "Kf_SellOutBill_Check_YP";
+            DBUtility.ClsPub.CurUserName = CurUserName;
+            try
+            {
+                //瀹℃牳鏉冮檺
+                if (!DBUtility.ClsPub.Security_Log_second(ModRightNameCheck, 1, false, CurUserName))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "瀹℃牳澶辫触锛佹棤鏉冮檺锛�";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+                //HInterID鏁版嵁鍒ゆ柇
+                if (HInterID <= 0)
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "HInterID灏忎簬0锛�";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+
+                Int64 lngBillKey = 0;
+                lngBillKey = DBUtility.ClsPub.isLong(HInterID);                                         //瀵笻InterID杩涜绫诲瀷鐨勮浆鎹�
+                DAL.ClsKf_SellOutBill oBill = new DAL.ClsKf_SellOutBill();                              //瀹炰緥鍖栧崟鎹搷浣滅被锛岀敤浜庤繘琛岀浉鍏虫搷浣�
+
+                //閽堝闇�瑕佽繘琛岀殑鎿嶄綔锛屾楠屽綋鍓嶅崟鎹殑鐘舵�佹槸鍚︽敮鎸侀渶瑕佽繘琛岀殑鎿嶄綔
+                if (oBill.ShowBill(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo))                    //鏍规嵁HInterID鑾峰彇璇ュ崟鎹殑鏁版嵁
+                {
+                    if (oBill.omodel.HCloseMan.Trim() != "")
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = "鍗曟嵁宸插叧闂�!涓嶈兘鍐嶆瀹℃牳锛�";
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                    if (oBill.omodel.HDeleteMan.Trim() != "")
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = "鍗曟嵁宸蹭綔搴�!涓嶈兘鍐嶆瀹℃牳锛�";
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                    if (IsAudit == 0)  //瀹℃牳鍒ゆ柇
+                    {
+                        if (oBill.omodel.HChecker.Trim() != "")
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "鍗曟嵁宸插鏍�!涓嶈兘鍐嶆瀹℃牳锛�";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                    }
+                    if (IsAudit == 1) //鍙嶅鏍稿垽鏂�
+                    {
+                        if (oBill.omodel.HChecker.Trim() == "")
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "鍗曟嵁鏈鏍�!涓嶉渶瑕佸弽瀹℃牳!";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                    }
+                }
+                else
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鍗曟嵁涓嶅瓨鍦�!鍘熷洜:" + DBUtility.ClsPub.sExeReturnInfo;
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+                //杩涜 浼氳鏈熼棿 缁撹处 鐨勫垽鏂拰鎺у埗
+                string s = "";
+                int sYear = 0;
+                int sPeriod = 0;
+                DateTime HDate = DateTime.Now;
+                if (DBUtility.Xt_BaseBillFun.Fun_AllowYearPeriod(HDate, ref sYear, ref sPeriod, ref s) == false)
+                {
+                    objJsonResult.Message = s;
+                    return objJsonResult;
+                }
+
+                //杩涜闇�瑕佽繘琛岀殑瀹℃牳/鍙嶅鏍告搷浣�
+                if (IsAudit == 0) //瀹℃牳鎻愪氦
+                {
+                    ds = oCN.RunProcReturn("exec h_p_Kf_CheckSellOutBill_CrediControl " + oBill.omodel.HInterID, "h_p_Kf_CheckSellOutBill_CrediControl");
+                    if (ds.Tables[0].Rows[0]["HBack"].ToString() == "1")
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = "瀹℃牳澶辫触!鍘熷洜:" + ds.Tables[0].Rows[0]["HRemark"].ToString();
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+
+                    //瀹℃牳鍓嶆帶鍒�=========================================      
+                    string sql1 = "exec h_p_Kf_SellOutBill_BeforeCheckCtrl " + oBill.omodel.HInterID + ",'" + oBill.omodel.HBillNo + "','" + CurUserName + "'";
+                    ds = oCN.RunProcReturn(sql1, "h_p_Kf_SellOutBill_BeforeCheckCtrl");
+                    if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 1;
+                        objJsonResult.Message = "瀹℃牳澶辫触!鍘熷洜:瀹℃牳鍓嶅垽鏂け璐ワ紝璇蜂笌缃戠粶绠$悊浜哄憳鑱旂郴";
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+
+                    if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 1;
+                        objJsonResult.Message = "瀹℃牳澶辫触!鍘熷洜:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                    //==================================================================================      
+
+                    //瀹℃牳鎻愪氦
+                    oCN.BeginTran();
+                    //澧炲姞鍏宠仈
+                    oCN.RunProc("exec h_p_Kf_SellOutBill_Check " + HInterID + ",'" + oBill.BillType + "','" + CurUserName + "'");
+                    //瀹℃牳鏇存柊 鍙婃椂搴撳瓨琛� 鍑忓皯搴撳瓨
+                    ds = oCN.RunProcReturn("exec h_KF_UPDateICinventory  '" + HInterID + "','" + oBill.BillType + "','1'", "h_KF_UPDateICinventory");
+                    //=========================瀹℃牳鍙嶅鏍稿悗璐熷簱瀛樻帶鍒�  
+                    DataSet ds2 = oCN.RunProcReturn("Exec h_p_KF_ICinventoryStockCtrl '" + HInterID + "', '" + oBill.BillType + "'", "h_p_KF_ICinventoryStockCtrl");
+                    if (ds2 == null)
+                    {
+                        oCN.RollBack();
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 1;
+                        objJsonResult.Message = "瀹℃牳澶辫触!鍘熷洜:" + "搴撳瓨鏇存柊鍚庢帶鍒跺垽鏂け璐�";
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                    if (DBUtility.ClsPub.isStrNull(ds2.Tables[0].Rows[0]["HBack"]) != "0")
+                    {
+                        oCN.RollBack();
+                        string sReturn = "搴撳瓨鏇存柊澶辫触锛�" + DBUtility.ClsPub.isStrNull(ds2.Tables[0].Rows[0]["HBackRemark"]);
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 1;
+                        objJsonResult.Message = "瀹℃牳澶辫触!鍘熷洜:" + sReturn;
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                    //============================
+                    //鍐欏叆鏃ュ織
+                    string WorkList = "瀹℃牳鍗曟嵁锛屽崟鎹彿锛�" + oBill.omodel.HBillNo;
+                    string SystemName = "LMES-閿�鍞嚭搴撳崟妯″潡";
+                    oCN.RunProc("Insert into  System_Log(GeginDate,userid,WorkstationName,WorkList,SystemName,NetUserName,State) values " +
+                        "(getdate(),'" + CurUserName + "','" + SystemInformation.ComputerName + "','" + WorkList + "','" + SystemName + "','','瀹℃牳')"
+                        );
+
+
+                    //瀹℃牳鍚庢帶鍒�=========================================      
+                    string sql = "exec h_p_Kf_SellOutBill_AfterCheckCtrl " + oBill.omodel.HInterID + ",'" + oBill.omodel.HBillNo + "','" + CurUserName + "'";
+                    ds = oCN.RunProcReturn(sql, "h_p_Kf_SellOutBill_AfterCheckCtrl");
+                    if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
+                    {
+                        oCN.RollBack();
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = "瀹℃牳澶辫触!鍘熷洜:瀹℃牳杩囩▼涓嚭閿欙紝璇蜂笌缃戠粶绠$悊浜哄憳鑱旂郴";
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                    if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
+                    {
+                        oCN.RollBack();
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = "瀹℃牳澶辫触!鍘熷洜:" + ds.Tables[0].Rows[0]["HRemark"].ToString();
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                    //=========================================      
+
+                    oCN.Commit();
+                    objJsonResult.code = "1";
+                    objJsonResult.count = 1;
+                    objJsonResult.Message = "瀹℃牳鎴愬姛";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+
+                    //if (oBill.CheckBill(oBill.omodel.HInterID, oBill.omodel.HBillNo, "h_p_Kf_SellOutBill_AfterCheckCtrl", CurUserName, ref DBUtility.ClsPub.sExeReturnInfo) == true)
+                    //{
+                    //    objJsonResult.code = "1";
+                    //    objJsonResult.count = 1;
+                    //    objJsonResult.Message = "瀹℃牳鎴愬姛";
+                    //    objJsonResult.data = null;
+                    //    return objJsonResult;
+                    //}
+                    //else
+                    //{
+                    //    objJsonResult.code = "0";
+                    //    objJsonResult.count = 0;
+                    //    objJsonResult.Message = "瀹℃牳澶辫触!鍘熷洜:" + DBUtility.ClsPub.sExeReturnInfo;
+                    //    objJsonResult.data = null;
+                    //    return objJsonResult;
+                    //}
+                }
+                if (IsAudit == 1) //鍙嶅鏍告彁浜�
+                {
+                    //鍙嶅鏍稿墠鎺у埗=========================================        
+                    string sql1 = "exec h_p_Kf_SellOutBill_BeforeUnCheckCtrl " + oBill.omodel.HInterID + ",'" + oBill.omodel.HBillNo + "','" + CurUserName + "'";
+                    ds = oCN.RunProcReturn(sql1, "h_p_Kf_SellOutBill_BeforeUnCheckCtrl");
+                    if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 1;
+                        objJsonResult.Message = "鍙嶅鏍稿け璐�!鍘熷洜:鍙嶅鏍稿墠鍒ゆ柇澶辫触锛岃涓庣綉缁滅鐞嗕汉鍛樿仈绯�";
+                        objJsonResult.data = null;
+                        return objJsonResult;
+
+                    }
+                    if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 1;
+                        objJsonResult.Message = "鍙嶅鏍稿け璐�!鍘熷洜:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                    //===========================================================         
+
+                    //鍙嶅鏍告彁浜bandonCheck
+                    //鍒犻櫎鍏宠仈
+                    oCN.BeginTran();
+                    oCN.RunProc("exec h_p_Xs_UpDateRelation_SeOrderToSellOut_UnCheck " + HInterID + ",'" + CurUserName + "'");
+                    if (oBill.AbandonCheck(oBill.omodel.HInterID, oBill.omodel.HBillNo, "h_p_Kf_SellOutBill_AfterUnCheckCtrl", CurUserName, ref DBUtility.ClsPub.sExeReturnInfo) == true)
+                    {
+                        oCN.Commit();
+                        objJsonResult.code = "1";
+                        objJsonResult.count = 1;
+                        objJsonResult.Message = "鍙嶅鏍告垚鍔�";
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                    else
+                    {
+                        oCN.RollBack();
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = "鍙嶅鏍稿け璐�!鍘熷洜:" + DBUtility.ClsPub.sExeReturnInfo;
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                }
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                oCN.RollBack();
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "瀹℃牳澶辫触鎴栬�呭弽瀹℃牳澶辫触锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
+
+        #region 閿�鍞嚭搴� 鏍规嵁閿�鍞鍗曚富id鏌ヨ鏉$爜鏄庣粏
+        /// <summary>
+        /// </summary>
+        /// <param name="HInterID">鍗曟嵁ID</param>
+        /// <returns></returns>
+        [Route("Kf_SellOutBill/GetBarCode_Detail")]
+        [HttpGet]
+        public object GetBarCode_Detail(string HInterID)
+        {
+            try
+            {
+                List<object> columnNameListSum = new List<object>();
+                List<object> columnNameList0 = new List<object>();
+                List<object> columnNameList1 = new List<object>();
+
+                string sql = "exec h_p_Kf_SellOutBillBarCodeNote_Detail  '" + HInterID+"'";
+                ds = oCN.RunProcReturn(sql, "h_p_Kf_SellOutBillBarCodeNote_Detail");
+
+                //娣诲姞 姹囨�讳俊鎭� 鍒楀悕
+                foreach (DataColumn col in ds.Tables[0].Columns)
+                {
+                    Type dataType = col.DataType;
+                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
+                    columnNameList0.Add(JsonConvert.DeserializeObject(ColmString));//鑾峰彇鍒癉ataColumn鍒楀璞$殑鍒楀悕
+                }
+
+                //娣诲姞 鏉$爜鏄庣粏 鍒楀悕
+                foreach (DataColumn col in ds.Tables[1].Columns)
+                {
+                    Type dataType = col.DataType;
+                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
+                    columnNameList1.Add(JsonConvert.DeserializeObject(ColmString));//鑾峰彇鍒癉ataColumn鍒楀璞$殑鍒楀悕
+                }
+                columnNameListSum.Add(columnNameList0);
+                columnNameListSum.Add(columnNameList1);
+
+                List<DataTable> tableList = new List<DataTable>();
+                tableList.Add(ds.Tables[0]);
+                tableList.Add(ds.Tables[1]);
+
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "Sucess锛�";
+                objJsonResult.data = tableList;
+                objJsonResult.list = columnNameListSum;
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
+
+        #region [閿�鍞嚭搴撳崟鍚屾鎻掍欢]
+        [Route("Kf_SellOutBill/SaveKf_SellOutBillApi")]
+        [HttpPost]
+        public object SaveKf_SellOutBillApi([FromBody] JObject sMainSub)
+        {
+            try
+            {
+                LogService.Write("閿�鍞嚭搴撳崟鍚屾锛�" + sMainSub.ToString());
+                var model = sMainSub["model"].ToString();
+                var entry = sMainSub["model"]["HENTRY"].ToString();
+
+                model = "[" + model.ToString() + "]";
+                List<Model.ClsKf_SellOutBillMain> mainList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Model.ClsKf_SellOutBillMain>>(model);
+                List< Model.ClsKf_SellOutBillSub> subList = Newtonsoft.Json.JsonConvert.DeserializeObject<List< Model.ClsKf_SellOutBillSub>> (entry);
+                string sql = string.Empty;
+
+                oCN.BeginTran();
+                // 鍒ゆ柇 鏁版嵁搴撲腑鏄惁瀛樺湪id鍜屽崟鎹彿鐩哥瓑鐨勬墦鍗曟嵁锛屽瓨鍦紝鍒欓噸寤猴紝鍙湁id鍙风浉绛夛紝鍒欑敵璇锋柊鐨刬d鍙�
+                var ds1 = oCN.RunProcReturn($@"select HInterID,HBillNO from Kf_ICStockBillMain where HInterID= {mainList[0].HInterID}", "Kf_ICStockBillMain");
+                var HInterID_Old = mainList[0].HInterID;
+                if (ds1.Tables[0].Rows.Count > 0 && ds1.Tables[0].Rows[0]["HInterID"] != null)
+                {
+                    if (string.Equals(ds1.Tables[0].Rows[0]["HBillNo"].ToString(), mainList[0].HBillNo, StringComparison.OrdinalIgnoreCase))
+                    {                      
+                        sql = $"delete Kf_ICStockBillMain where HinterID = {mainList[0].HInterID}";
+                        oCN.RunProc(sql);
+                        sql = $"delete Kf_ICStockBillSub where HinterID = {mainList[0].HInterID}";
+                        oCN.RunProc(sql);
+                    }
+                    else
+                    {
+                        // 閲嶆柊鐢宠HInterID
+                        var HInterID_Exch = DBUtility.ClsPub.CreateBillID("1205", ref DBUtility.ClsPub.sExeReturnInfo);
+                        mainList[0].HInterID = HInterID_Exch;
+
+                        foreach (var oSub in subList)
+                        {
+                            oSub.HInterID = HInterID_Exch;
+                        }
+
+                    }
+                }
+                //涓昏〃          
+                sql = @"insert into Kf_ICStockBillMain
+              (HInterID, HYear, HPeriod, HBillNo, HBillType, HBillSubType, HMainSourceBillType, HDate,
+               HSupID, HWHID, HSCWHID, HEmpID, HManagerID, HSecManagerID, HKeeperID, HDeptID,
+               HCurID, HSeOrderBillNo, HExplanation, HRemark, HInnerBillNo, HRedBlueFlag, HBillStatus, HMaker,
+               HMakeDate, HChecker, HCheckDate, HUpDater, HUpDateDate, HDeleteMan, HDeleteDate, HOWNERID,
+               HOWNERTYPEID, HERPInterID, HERPBillType, HERPBillNo, HPRDORGID, HSTOCKORGID)
+               values(" + mainList[0].HInterID + ", " + mainList[0].HYear + ", " + mainList[0].HPeriod + ", '" + mainList[0].HBillNo + "', '" + mainList[0].HBillType + "', '" + mainList[0].HBillSubType + "', '" + mainList[0].HMainSourceBillType + "', '" + mainList[0].HDate + "'" +
+               "," + mainList[0].HSupID + ", " + mainList[0].HWHID + ", " + mainList[0].HSCWHID + ", " + mainList[0].HEmpID + ", " + mainList[0].HManagerID + ", " + mainList[0].HSecManagerID + ", " + mainList[0].HKeeperID + ", " + mainList[0].HDeptID + "" +
+               "," + mainList[0].HCurID + ", '" + mainList[0].HSeOrderBillNo + "', '" + mainList[0].HExplanation + "', '" + mainList[0].HRemark + "', '" + mainList[0].HInnerBillNo + "', '" + mainList[0].HRedBlueFlag + "', " + mainList[0].HBillStatus + ", '" + mainList[0].HMaker + "'" +
+               ",'" + mainList[0].HMakeDate + "', '" + mainList[0].HChecker + "', '" + mainList[0].HCheckDate + "', '" + mainList[0].HUpDater + "', '" + mainList[0].HUpDateDate + "', '" + mainList[0].HDeleteMan + "', '" + mainList[0].HDeleteDate + "', " + mainList[0].HOWNERID + "" +
+               ",'" + mainList[0].HOWNERTYPEID + "', " + mainList[0].HERPInterID + ", '" + mainList[0].HERPBillType + "', '" + mainList[0].HERPBillNo + "', " + mainList[0].HPRDORGID + ", " + mainList[0].HSTOCKORGID + ")";
+                LogService.Write("閿�鍞嚭搴撳崟涓昏〃鍚屾锛�" + sql);
+                oCN.RunProc(sql);           
+                //淇濆瓨瀛愯〃
+                foreach (var oSub in subList)
+                {
+                    sql = $@"insert into Kf_ICStockBillSub
+                  (HInterID, HEntryID, HMTONo, HPlanMode, HRemark, HExpressNumber, HMaterID, HUnitID,
+                   HBatchNo, HPropertyID, HWHID, HSPID, HSCWHID, HSCSPID, HQtyMust, HQty,
+                   HPrice, HMoney, HTaxPrice, HTaxRate, HTaxMoney, HRelationQty, HRelationMoney, HSourceInterID,
+                   HSourceEntryID, HSourceBillNo, HSourceBillType, HERPInterID, HERPEntryID, HERPBillNo_Sub, HPOOrderInterID, HPOOrderEntryID,
+                   HPOOrderBillNo, HSeOrderInterID, HSeOrderEntryID, HSeOrderBillNo, HICMOInterID, HICMOEntryID,
+                   HICMOBillNo, HWWOrderInterID, HWWOrderEntryID, HWWOrderBillNo, HProduceDate, HExpiryDate, HOWNERID, HOWNERTYPEID,
+                   HKEEPERID, HKEEPERTYPEID)
+                    values('{mainList[0].HInterID }', '{oSub.HEntryID}', '{oSub.HMTONo}', '{oSub.HPlanMode}', '{oSub.HRemark}', '{oSub.HExpressNumber}', '{oSub.HMaterID}', '{oSub.HUnitID}',
+                           '{oSub.HBatchNo}', '{oSub.HPropertyID}', '{oSub.HWHID}', '{oSub.HSPID}', '{oSub.HSCWHID}', '{oSub.HSCSPID}', '{oSub.HQtyMust}', '{oSub.HQty}',
+                           '{oSub.HPrice}', '{oSub.HMoney}', '{oSub.HTaxPrice}', '{oSub.HTaxRate}', '{oSub.HTaxMoney}', '{oSub.HRelationQty}', '{oSub.HRelationMoney}', '{oSub.HSourceInterID}',
+                           '{oSub.HSourceEntryID}', '{oSub.HSourceBillNo}', '{oSub.HSourceBillType}', '{oSub.HERPInterID}', '{oSub.HERPEntryID}', '{oSub.HERPBillNo_Sub}', '{oSub.HPOOrderInterID}', '{oSub.HPOOrderEntryID}',
+                           '{oSub.HPOOrderBillNo}', '{oSub.HSeOrderInterID}', '{oSub.HSeOrderEntryID}', '{oSub.HSeOrderBillNo}', '{oSub.HICMOInterID}', '{oSub.HICMOEntryID}',
+                           '{oSub.HICMOBillNo}', '{oSub.HWWOrderInterID}', '{oSub.HWWOrderEntryID}', '{oSub.HWWOrderBillNo}', '{oSub.HProduceDate}', '{oSub.HExpiryDate}', '{oSub.HOWNERID}', '{oSub.HOWNERTYPEID}',
+                           '{oSub.HKEEPERID}', '{oSub.HKEEPERTYPEID}')";
+                    LogService.Write("閿�鍞嚭搴撳崟瀛愯〃鍚屾锛�" + sql);
+                    oCN.RunProc(sql);
+                }
+                oCN.Commit();
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "鍗曟嵁淇濆瓨鎴愬姛锛�";
+                objJsonResult.data = null;
+                return objJsonResult;
+
+            }
+            catch (Exception e)
+            {
+                LogService.Write("閿�鍞嚭搴撳崟鍚屾寮傚父,淇濆瓨鏂规硶鎵ц瀹屾垚寮傚父锛�" + e.Message.ToString());
+
+                oCN.RollBack();
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "淇濆瓨澶辫触锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
     }
 }
\ No newline at end of file

--
Gitblit v1.9.1