From e82d249e1407d85f575eeabe66b8ba371f3199b4 Mon Sep 17 00:00:00 2001
From: ch <37327@LLOOCCY>
Date: 星期三, 30 十一月 2022 12:41:26 +0800
Subject: [PATCH] 合并

---
 WebAPI/Controllers/生产管理/生产任务单/Sc_ICMOBillController.cs |  516 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 493 insertions(+), 23 deletions(-)

diff --git "a/WebAPI/Controllers/\347\224\237\344\272\247\347\256\241\347\220\206/\347\224\237\344\272\247\344\273\273\345\212\241\345\215\225/Sc_ICMOBillController.cs" "b/WebAPI/Controllers/\347\224\237\344\272\247\347\256\241\347\220\206/\347\224\237\344\272\247\344\273\273\345\212\241\345\215\225/Sc_ICMOBillController.cs"
index f207523..76faf2a 100644
--- "a/WebAPI/Controllers/\347\224\237\344\272\247\347\256\241\347\220\206/\347\224\237\344\272\247\344\273\273\345\212\241\345\215\225/Sc_ICMOBillController.cs"
+++ "b/WebAPI/Controllers/\347\224\237\344\272\247\347\256\241\347\220\206/\347\224\237\344\272\247\344\273\273\345\212\241\345\215\225/Sc_ICMOBillController.cs"
@@ -1,4 +1,6 @@
-锘縰sing Newtonsoft.Json.Linq;
+锘縰sing Model;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
 using Pub_Class;
 using System;
 using System.Collections;
@@ -19,6 +21,472 @@
         private json objJsonResult = new json();
         SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
         DataSet ds;
+
+        #region 鐢熶骇浠诲姟鍗� 淇濆瓨/缂栬緫鍔熻兘
+        [Route("Sc_ICMOBill/ICMOBillEdit")]
+        [HttpPost]
+        public object ICMOBillEdit([FromBody] JObject sMainSub)
+        {
+            try
+            {
+                var _value = sMainSub["sMainSub"].ToString();
+                string msg1 = _value.ToString();
+                oCN.BeginTran();
+                //淇濆瓨涓昏〃
+                objJsonResult = AddBillMain(msg1);
+                if (objJsonResult.code == "0")
+                {
+                    oCN.RollBack();
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = objJsonResult.Message;
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+                oCN.Commit();
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "鍗曟嵁淇濆瓨鎴愬姛锛�";
+                objJsonResult.data = null;
+                return objJsonResult;
+
+            }
+            catch (Exception e)
+            {
+                oCN.RollBack();
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "淇濆瓨澶辫触锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+
+        public json AddBillMain(string msg1)
+        {
+            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
+            string msg2 = sArray[0].ToString(); //涓昏〃鏁版嵁
+            string msg3 = sArray[1].ToString(); //瀛愯〃鏁版嵁
+            int OperationType = int.Parse(sArray[2].ToString()); // 鏁版嵁绫诲瀷 1娣诲姞 3淇敼
+            string user = sArray[3].ToString();
+
+            try
+            {
+                if (!DBUtility.ClsPub.Security_Log("Sc_ICMOBill_Edit", 1, false, user))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鏃犱繚瀛樻潈闄愶紒";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                msg2 = "[" + msg2.ToString() + "]";
+                List<ClsSc_ICMOBillMain> mainList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsSc_ICMOBillMain>>(msg2);
+
+                long HInterID = mainList[0].HInterID;//閫掑叆type寰楀埌鐨勫崟鎹甀D
+                string HBillNo = mainList[0].HBillNo;//閫掑叆type寰楀埌鐨勫崟鎹彿
+                long HPRDORGID = mainList[0].HPRDORGID;//缁勭粐
+                DateTime HDate = mainList[0].HDate;//鏃ユ湡
+                string HRemark = mainList[0].HRemark;//澶囨敞
+                string HSeOrderBillNo = mainList[0].HSeOrderBillNo;//閿�鍞鍗曞彿
+                long HSeOrderInterID = mainList[0].HSeOrderInterID;//閿�鍞涓籭d
+                long HSeOrderEntryID = mainList[0].HSeOrderEntryID;//閿�鍞瀛恑d
+                long HEmpID = mainList[0].HEmpID;//涓氬姟鍛�
+                long HCusID = mainList[0].HCusID;//瀹㈡埛
+                long HCenterID = mainList[0].HCenterID;//宸ヤ綔涓績
+                double? HPlanQty = mainList[0].HPlanQty == null ? 0 : mainList[0].HPlanQty;//璁″垝鏁伴噺
+                string HMaker = user;//鍒跺崟浜�
+
+                ds = oCN.RunProcReturn("select * from h_v_IF_ICMOBillList where hmainid=" + HInterID + " and 鍗曟嵁鍙�='" + HBillNo + "'", "h_v_IF_ICMOBillList");
+
+                if ((OperationType == 1 || OperationType == 2) && ds.Tables[0].Rows.Count == 0)//鏂板
+                {
+                    //涓昏〃
+                    oCN.RunProc(@"Insert Into Sc_ICMOBillMain   
+                        (HBillType,HInterID,HBillNo,HDate,HPRDORGID
+                        ,HYear,HPeriod,HRemark,HMaker,HMakeDate
+                        ,HSeOrderBillNo,HSeOrderInterID,HSeOrderEntryID,HEmpID,HCusID
+                        ,HCenterID,HPlanQty,HDeptID,HMaterID,HUnitID,HBomID,HPlanBeginDate,HPlanEndDate)
+                        values('3710'," + HInterID + ",'" + HBillNo + "','" + HDate + "'," + HPRDORGID +
+                    "," + DateTime.Now.Year + "," + DateTime.Now.Month + ",'" + HRemark + "','" + HMaker + "',getdate()" +
+                    ",'" + HSeOrderBillNo + "'," + HSeOrderInterID + "," + HSeOrderEntryID + "," + HEmpID + "," + HCusID +
+                    "," + HCenterID + "," + HPlanQty + ",0,0,0,0,'','') ");
+                }
+                else if (OperationType == 3 || ds.Tables[0].Rows.Count != 0)
+                { //淇敼
+                    oCN.RunProc("update Sc_ICMOBillMain  set " +
+                                "HRemark='" + HRemark + "', HChecker='" + HMaker + "', HCheckDate=getdate()" +
+                                ", HSeOrderBillNo='" + HSeOrderBillNo + "', HSeOrderInterID=" + HSeOrderInterID + ", HSeOrderEntryID=" + HSeOrderEntryID + ", HEmpID=" + HEmpID + ", HCusID=" + HCusID + "" +
+                                ", HCenterID=" + HCenterID + ", HPlanQty=" + HPlanQty + " where HInterID=" + HInterID);
+
+                    //鍒犻櫎瀛愯〃
+                    oCN.RunProc("delete from Sc_ICMOBillSub where HInterID='" + HInterID + "'");
+                }
+                //淇濆瓨瀛愯〃
+                objJsonResult = AddBillSub(msg3, HInterID, OperationType);
+
+                if (objJsonResult.code == "0")
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = objJsonResult.Message;
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = null;
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+
+        public json AddBillSub(string msg3, long HInterID, int OperationType)
+        {
+            List<ClsSc_ICMOBillSub> DetailColl = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsSc_ICMOBillSub>>(msg3);
+            int i = 0;
+            foreach (ClsSc_ICMOBillSub oSub in DetailColl)
+            {
+                i++;
+                if (oSub.HQty <= 0 || oSub.HQty == null)
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "绗�" + i + "琛岋紝鏁伴噺涓嶈兘涓�0鎴栬�呭皬浜�0";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                if (oSub.HMaterID == 0)
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "绗�" + i + "琛岋紝鐗╂枡涓嶈兘涓虹┖";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                //if (oSub.HSourceID == 0)
+                //{
+                //    objJsonResult.code = "0";
+                //    objJsonResult.count = 0;
+                //    objJsonResult.Message = "绗�" + i + "琛岋紝鐢熶骇璧勬簮涓嶈兘涓虹┖";
+                //    objJsonResult.data = null;
+                //    return objJsonResult;
+                //}
+
+                if (oSub.HDeptID == 0)
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "绗�" + i + "琛�,鐢熶骇杞﹂棿涓嶈兘涓虹┖";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                if (oSub.HUnitID == 0)
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "绗�" + i + "琛岋紝璁¢噺鍗曚綅涓嶈兘涓虹┖";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                oCN.RunProc($@"Insert into Sc_ICMOBillSub 
+                (HInterID,HENTRYID,HQty
+                ,HPlanBeginDate,HPlanEndDate
+	            ,HBeginDate,HEndDate
+                ,HMaterID,HUnitID,HRemark,HSourceID,HDeptID,HSTATUS
+				,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney) 
+                 values({HInterID},{i},{(oSub.HQty == null ? 0 : oSub.HQty)}
+                ,'{(oSub.HPlanBeginDate == null ? DateTime.Now.ToString("yyyy-MM-dd") : oSub.HPlanBeginDate.ToString())}','{(oSub.HPlanEndDate == null ? DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") : oSub.HPlanEndDate.ToString())}'
+                ,'{(oSub.HPlanBeginDate == null ? DateTime.Now.ToString("yyyy-MM-dd") : oSub.HPlanBeginDate.ToString())}','{(oSub.HPlanEndDate == null ? DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") : oSub.HPlanEndDate.ToString())}'
+                ,{oSub.HMaterID},{oSub.HUnitID},'{oSub.HRemark}',{oSub.HSourceID},{oSub.HDeptID},{oSub.HSTATUS}
+	                    ,0,0,'','',0,0)");
+            }
+
+            objJsonResult.code = "1";
+            objJsonResult.count = 1;
+            objJsonResult.Message = null;
+            objJsonResult.data = null;
+            return objJsonResult;
+        }
+        #endregion
+
+        [Route("Sc_ICMOBill/ICMOBillSaveApi")]
+        [HttpPost]
+        public object ICMOBillSaveApi([FromBody] JObject sMainSub)
+        {
+            try
+            {
+                var model = sMainSub["model"].ToString();
+                var entry = sMainSub["model"]["HENTRY"].ToString();
+
+                model = "[" + model.ToString() + "]";
+                List<ClsSc_ICMOBillMain> mainList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsSc_ICMOBillMain>>(model);
+                List<ClsSc_ICMOBillSub> subList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsSc_ICMOBillSub>>(entry);
+                string sql = string.Empty;
+                oCN.BeginTran();
+                sql = $"delete Sc_ICMOBillMain where HinterID = {mainList[0].HInterID}";
+                oCN.RunProc(sql);
+                sql = $"delete Sc_ICMOBillSub where HinterID = {mainList[0].HInterID}";
+                oCN.RunProc(sql);
+                //涓昏〃
+                oCN.RunProc(@"Insert Into Sc_ICMOBillMain   
+                        (HBillType,HInterID,HBillNo,HDate,HPRDORGID
+                        ,HYear,HPeriod,HRemark,HMaker,HMakeDate
+                        ,HSeOrderBillNo,HSeOrderInterID,HSeOrderEntryID,HEmpID,HCusID
+                        ,HCenterID,HPlanQty,HDeptID,HMaterID,HUnitID,HBomID,HPlanBeginDate,HPlanEndDate)
+                        values('3710'," + mainList[0].HInterID + ",'" + mainList[0].HBillNo + "','" + mainList[0].HDate + "'," + mainList[0].HPRDORGID +
+                "," + DateTime.Now.Year + "," + DateTime.Now.Month + ",'" + mainList[0].HRemark + "','" + mainList[0].HMaker + "',getdate()" +
+                ",'" + mainList[0].HSeOrderBillNo + "'," + mainList[0].HSeOrderInterID + "," + mainList[0].HSeOrderEntryID + "," + mainList[0].HEmpID + "," + mainList[0].HCusID +
+                "," + mainList[0].HCenterID + "," + mainList[0].HPlanQty + ",0,0,0,0,'','') ");
+                //淇濆瓨涓昏〃
+                foreach (var oSub in subList)
+                {
+                    oCN.RunProc($@"Insert into Sc_ICMOBillSub 
+                (HInterID,HENTRYID,HQty
+                ,HPlanBeginDate,HPlanEndDate
+	            ,HBeginDate,HEndDate
+                ,HMaterID,HUnitID,HRemark,HSourceID,HDeptID,HSTATUS
+				,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney) 
+                 values({oSub.HInterID},{oSub.HEntryID},{(oSub.HQty == null ? 0 : oSub.HQty)}
+                ,'{(oSub.HPlanBeginDate == null ? DateTime.Now.ToString("yyyy-MM-dd") : oSub.HPlanBeginDate.ToString())}','{(oSub.HPlanEndDate == null ? DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") : oSub.HPlanEndDate.ToString())}'
+                ,'{(oSub.HPlanBeginDate == null ? DateTime.Now.ToString("yyyy-MM-dd") : oSub.HPlanBeginDate.ToString())}','{(oSub.HPlanEndDate == null ? DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") : oSub.HPlanEndDate.ToString())}'
+                ,{oSub.HMaterID},{oSub.HUnitID},'{oSub.HRemark}',{oSub.HSourceID},{oSub.HDeptID},{oSub.HSTATUS}
+	                    ,0,0,'','',0,0)");
+                }
+                oCN.Commit();
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "鍗曟嵁淇濆瓨鎴愬姛锛�";
+                objJsonResult.data = null;
+                return objJsonResult;
+
+            }
+            catch (Exception e)
+            {
+                oCN.RollBack();
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "淇濆瓨澶辫触锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+
+
+        #region 鐢熶骇浠诲姟鍗�(鏃犲垪琛�) 淇濆瓨/缂栬緫鍔熻兘
+        [Route("Sc_ICMOBill/ICMOBillEdit_NoTable")]
+        [HttpPost]
+        public object ICMOBillEdit_NoTable([FromBody] JObject sMainSub)
+        {
+            try
+            {
+                var _value = sMainSub["sMainSub"].ToString();
+                string msg1 = _value.ToString();
+                oCN.BeginTran();
+                //淇濆瓨涓昏〃
+                objJsonResult = AddBillMain_NoTable(msg1);
+                if (objJsonResult.code == "0")
+                {
+                    oCN.RollBack();
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = objJsonResult.Message;
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+                oCN.Commit();
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "鍗曟嵁淇濆瓨鎴愬姛锛�";
+                objJsonResult.data = null;
+                return objJsonResult;
+
+            }
+            catch (Exception e)
+            {
+                oCN.RollBack();
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "淇濆瓨澶辫触锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+
+        public json AddBillMain_NoTable(string msg1)
+        {
+            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
+            string msg2 = sArray[0].ToString(); //涓昏〃鏁版嵁
+            int OperationType = int.Parse(sArray[1].ToString()); // 鏁版嵁绫诲瀷 1娣诲姞 3淇敼
+            string user = sArray[2].ToString();
+
+            try
+            {
+                if (!DBUtility.ClsPub.Security_Log("Sc_ICMOBill_Edit", 1, false, user))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鏃犱繚瀛樻潈闄愶紒";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                var msg3 = msg2.ToString();
+                msg2 = "[" + msg2.ToString() + "]";
+                List<ClsSc_ICMOBillMain> mainList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsSc_ICMOBillMain>>(msg2);
+
+                long HInterID = mainList[0].HInterID;//閫掑叆type寰楀埌鐨勫崟鎹甀D
+                string HBillNo = mainList[0].HBillNo;//閫掑叆type寰楀埌鐨勫崟鎹彿
+                long HPRDORGID = mainList[0].HPRDORGID;//缁勭粐
+                DateTime HDate = mainList[0].HDate;//鏃ユ湡
+                string HRemark = mainList[0].HRemark;//澶囨敞
+                string HSeOrderBillNo = mainList[0].HSeOrderBillNo;//閿�鍞鍗曞彿
+                long HSeOrderInterID = mainList[0].HSeOrderInterID;//閿�鍞涓籭d
+                long HSeOrderEntryID = mainList[0].HSeOrderEntryID;//閿�鍞瀛恑d
+                long HEmpID = mainList[0].HEmpID;//涓氬姟鍛�
+                long HCusID = mainList[0].HCusID;//瀹㈡埛
+                long HCenterID = mainList[0].HCenterID;//宸ヤ綔涓績
+                long HBomID = mainList[0].HBomID;//bom
+                //double? HPlanQty = mainList[0].HPlanQty == null ? 0 : mainList[0].HPlanQty;//璁″垝鏁伴噺
+                string HMaker = user;//鍒跺崟浜�
+
+                ds = oCN.RunProcReturn("select * from h_v_IF_ICMOBillList where hmainid=" + HInterID + " and 鍗曟嵁鍙�='" + HBillNo + "'", "h_v_IF_ICMOBillList");
+
+                if ((OperationType == 1 || OperationType == 2) && ds.Tables[0].Rows.Count == 0)//鏂板
+                {
+                    //涓昏〃
+                    oCN.RunProc(@"Insert Into Sc_ICMOBillMain   
+                        (HBillType,HInterID,HBillNo,HDate,HPRDORGID
+                        ,HYear,HPeriod,HRemark,HMaker,HMakeDate
+                        ,HSeOrderBillNo,HSeOrderInterID,HSeOrderEntryID,HEmpID,HCusID
+                        ,HCenterID,HPlanQty,HDeptID,HMaterID,HUnitID,HBomID,HPlanBeginDate,HPlanEndDate)
+                        values('3710'," + HInterID + ",'" + HBillNo + "','" + HDate + "'," + HPRDORGID +
+                    "," + DateTime.Now.Year + "," + DateTime.Now.Month + ",'" + HRemark + "','" + HMaker + "',getdate()" +
+                    ",'" + HSeOrderBillNo + "'," + HSeOrderInterID + "," + HSeOrderEntryID + "," + HEmpID + "," + HCusID +
+                    "," + HCenterID + ",0,0,0,0," + HBomID + ",'','') ");
+                }
+                else if (OperationType == 3 || ds.Tables[0].Rows.Count != 0)
+                { //淇敼
+                    oCN.RunProc("update Sc_ICMOBillMain  set " +
+                                "HRemark='" + HRemark + "', HChecker='" + HMaker + "', HCheckDate=getdate()" +
+                                ", HSeOrderBillNo='" + HSeOrderBillNo + "', HSeOrderInterID=" + HSeOrderInterID + ", HSeOrderEntryID=" + HSeOrderEntryID + ", HEmpID=" + HEmpID + ", HCusID=" + HCusID + "" +
+                                ", HCenterID=" + HCenterID + ",HBomID=" + HBomID + " where HInterID=" + HInterID);
+
+                    //鍒犻櫎瀛愯〃
+                    oCN.RunProc("delete from Sc_ICMOBillSub where HInterID='" + HInterID + "'");
+                }
+                //淇濆瓨瀛愯〃
+                objJsonResult = AddBillSub_NoTable(msg3, HInterID, OperationType);
+
+                if (objJsonResult.code == "0")
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = objJsonResult.Message;
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = null;
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+
+        public json AddBillSub_NoTable(string msg3, long HInterID, int OperationType)
+        {
+            ClsSc_ICMOBillSub oSub = Newtonsoft.Json.JsonConvert.DeserializeObject<ClsSc_ICMOBillSub>(msg3);
+            if (oSub.HQty <= 0 || oSub.HQty == null)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "鏁伴噺涓嶈兘涓�0鎴栬�呭皬浜�0";
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+
+            if (oSub.HMaterID == 0)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "鐗╂枡涓嶈兘涓虹┖";
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+
+            if (oSub.HDeptID == 0)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "鐢熶骇杞﹂棿涓嶈兘涓虹┖";
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+
+            if (oSub.HUnitID == 0)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "璁¢噺鍗曚綅涓嶈兘涓虹┖";
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+
+            if (oSub.HBomID == 0)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "BOM涓嶈兘涓虹┖";
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+
+            oCN.RunProc($@"Insert into Sc_ICMOBillSub 
+                (HInterID,HENTRYID,HQty
+                ,HPlanBeginDate,HPlanEndDate
+	            ,HBeginDate,HEndDate
+                ,HMaterID,HUnitID,HRemark,HSourceID,HDeptID,HSTATUS
+                ,HBomID,HEntryCusID
+				,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney) 
+                 values({HInterID},1,{(oSub.HQty == null ? 0 : oSub.HQty)}
+                ,'{(oSub.HPlanBeginDate == null ? DateTime.Now.ToString("yyyy-MM-dd") : oSub.HPlanBeginDate.ToString())}','{(oSub.HPlanEndDate == null ? DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") : oSub.HPlanEndDate.ToString())}'
+                ,'{(oSub.HBeginDate == null ? DateTime.Now.ToString("yyyy-MM-dd") : oSub.HBeginDate.ToString())}','{(oSub.HEndDate == null ? DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") : oSub.HEndDate.ToString())}'
+                ,{oSub.HMaterID},{oSub.HUnitID},'{oSub.HRemark}',{oSub.HSourceID},{oSub.HDeptID},{oSub.HSTATUS}
+                 ,{oSub.HBomID}  ,{oSub.HCusID} 
+	                    ,0,0,'','',0,0)");
+
+
+            objJsonResult.code = "1";
+            objJsonResult.count = 1;
+            objJsonResult.Message = null;
+            objJsonResult.data = null;
+            return objJsonResult;
+        }
+        #endregion
 
         #region 鐢熶骇浠诲姟鍗曞垹闄ゅ姛鑳�
         [Route("Sc_ICMOBill/DeltetSc_ICMOReportBill")]
@@ -56,6 +524,7 @@
                     return objJsonResult; ;
                 }
                 oCN.RunProc("delete from Sc_ICMOBillMain  where HInterID=" + HInterID);
+                oCN.RunProc("delete from Sc_ICMOBillSub  where HInterID=" + HInterID);
                 oCN.Commit();//鎻愪氦浜嬪姟
                 objJsonResult.code = "0";
                 objJsonResult.count = 1;
@@ -106,7 +575,10 @@
         [Route("Sc_ICMOBill/QK_PackingBillByXSBill")]
         [HttpGet]
         public object QK_PackingBillByXSBill(string HBillNo)
-        {                //string sql = string.Format(@"select a.HInterID,a.HBillNo,b.HEntryID,b.HMaterID,m.HNumber HMaterNumber,m.HName HMaterName, b.HUnitID,u.HName HUnitName,b.HQty HPlanQty,
+        {
+            try
+            {
+                //string sql = string.Format(@"select a.HInterID,a.HBillNo,b.HEntryID,b.HMaterID,m.HNumber HMaterNumber,m.HName HMaterName, b.HUnitID,u.HName HUnitName,b.HQty HPlanQty,b.HQty HSPlanQty,
                 //                            a.HCusID, c.HName HCusName,a.HEmpID,e.HName HEmpName,b.HDeptID,d.HName HDeptName,a.HPlanEndDate,0 HMinQty,0 HTotalQty,0 HSpsQty,a.HSeOrderBillNo,a.HRemark
                 //                            from Sc_ICMOBillMain a 
                 //                            left join Sc_ICMOBillSub b on a.HInterID=b.HInterID
@@ -116,14 +588,10 @@
                 //                            left join Gy_Employee e on a.HEmpID=e.HItemID
                 //                            left join Gy_Department d on a.HDeptID=d.HItemID
                 //                            where b.HInterID=(select HICMOInterID from Sc_PPBomBillMain where HBillNo='" + HBillNo + "')");
-            try
-            {
-
-
-                string sql = string.Format(@"select a.HInterID,a.HBillNo,b.HMaterID,b.HEntryID, m.HNumber HMaterNumber, m.HName HMaterName, b.HUnitID,u.HName HUnitName,b.HQty HPlanQty,a.HCusID, c.HName HCusName,
+                string sql = string.Format(@"select a.HInterID,a.HBillNo,b.HMaterID,b.HEntryID, m.HNumber HMaterNumber, m.HName HMaterName, b.HUnitID,u.HName HUnitName,b.HQty HPlanQty,b.HQty HSPlanQty,a.HCusID, c.HName HCusName,
                     a.HEmpID,e.HName HEmpName,b.HDeptID,d.HName HDeptName,a.HPlanEndDate,0 HMinQty,0 HTotalQty,0 HSpsQty,a.HSeOrderBillNo,a.HRemark,
-                     fo.FBILLNO FBillNo,fo.F_ZZZZ_TEXT7 FLXName,fo.FRECEIVEADDRESS FInAddress,fmn.FNAME FMaterName,fo.F_ZZZZ_TEXT FBZFS,fu.FDATAVALUE FHX,
-                    fu1.FDATAVALUE FQK,fo.F_ZZZZ_WBBZ FWBBZ
+                     fo.FBILLNO FBillNo,fo.F_ZZZZ_TEXT7 FLXName,fo.FRECEIVEADDRESS FInAddress,fmn.FNAME FMaterName,fo1.F_ZZZZ_TEXT FBZFS,fu.FDATAVALUE FHX,
+                    fu1.FDATAVALUE FQK,fo1.F_ZZZZ_WBBZ1 FWBBZ
                     from Sc_ICMOBillMain a 
                     left join Sc_ICMOBillSub b on a.HInterID=b.HInterID
                     left join Gy_Material m on b.HMaterID=m.HItemID
@@ -210,7 +678,7 @@
                 int LSH;
                 string LSH2;
                 string TM = "";
-                int XH = Convert.ToInt32(d.Tables[0].Rows[0]["HRemark"].ToString() == ""? 0 : Convert.ToInt32(d.Tables[0].Rows[0]["HRemark"].ToString()));
+                int XH = Convert.ToInt32(d.Tables[0].Rows[0]["HRemark"].ToString() == "" ? 0 : Convert.ToInt32(d.Tables[0].Rows[0]["HRemark"].ToString()));
 
                 foreach (Models.ClsQK_PackingBill oItemSub in ls)
                 {
@@ -231,9 +699,9 @@
 
                         if (msg6 == "ZZ")
                         {
-                            XH = XH +1;
+                            XH = XH + 1;
                         }
-                        else if (msg6 == "PZ"&& ls.IndexOf(oItemSub) == 0)
+                        else if (msg6 == "PZ" && ls.IndexOf(oItemSub) == 0)
                         {
                             XH = XH + 1;
                         }
@@ -247,21 +715,21 @@
                                     ",HSTOCKORGID,HOWNERID,HSeOrderBillNo,HInterID " +
                                     ",HGiveAwayFlag " +
                                     ",HMaterName,HMaterModel,HPinfan,HAuxPropID,HMTONo,HInnerBillNo " +
-                                    ") values ("+i
+                                    ") values (" + i
                                     + ",'" + TM + "','鍞竴鏉$爜'," + oItemSub.HMaterID.ToString() + "," + oItemSub.HUnitID.ToString() + "," + oItemSub.HMinQty.ToString()
                                     + ",'',0,0,'" + msg3 + "',getdate(),0," + oItemSub.HMinQty.ToString()
                                     + ", " + oItemSub.HInterID.ToString() + "," + oItemSub.HEntryID.ToString() + ",'" + oItemSub.HBillNo + "','3710',''"
-                                    + ",1,1," + oItemSub.HDeptID.ToString() + ",0,0,'"+ XH + "'"
+                                    + ",1,1," + oItemSub.HDeptID.ToString() + ",0,0,'" + XH + "'"
                                     + ", " + oItemSub.HCusID.ToString() + ",'',getdate(),'',getdate()"
                                     + ", " + msg5.ToString() + "," + OrgNum.ToString() + ",'" + oItemSub.HSeOrderBillNo.ToString() + "'," + HInterID.ToString()
                                     + ",0"
                                     + ",'" + oItemSub.HMaterName + "','','',0,'','')");
-                        
+
                         oCN.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
-                        
+
                     }
-                    oCN.RunProc("update Sc_ICMOBillSub set HQty=" + oItemSub.HSpsQty  + " where HEntryID=" + oItemSub.HEntryID);
-                    oCN.RunProc("update Sc_PPBomBillMain set HRemark=" +XH+ " where HBillNo='" + msg7+"'");
+                    oCN.RunProc("update Sc_ICMOBillSub set HQty=" + oItemSub.HSpsQty + " where HEntryID=" + oItemSub.HEntryID);
+                    oCN.RunProc("update Sc_PPBomBillMain set HRemark=" + XH + " where HBillNo='" + msg7 + "'");
                     DataSet Dsn = oCN.RunProcReturn("select top " + oItemSub.HTotalQty + " HItemID from Gy_BarCodeBill order by HItemID desc", "Gy_BarCodeBill");    //鑾峰彇鏈�澶ф祦姘村彿
                     for (int i = 0; i < oItemSub.HTotalQty; i++)
                     {
@@ -486,6 +954,8 @@
         /// <summary>
         /// 澧欏挃瑁呯鍒楄〃-鍒犻櫎
         /// </summary>
+        /// <param name="HInterID">鏉$爜妗f涓昏〃涓籌D锛堝敮涓�锛�</param>
+        /// <param name="Flag">鏍囪瘑</param>
         /// <returns></returns>
         [Route("Sc_ICMOBillController/DeleteQK_GetPackingBillList")]
         [HttpGet]
@@ -500,14 +970,14 @@
                     ds = oCN.RunProcReturn("select * from Gy_BarCodeBill where HItemID=" + HInterID, "Gy_BarCodeBill");
                     DataRow dr = ds.Tables[0].Rows[0];
                     string sql = string.Format(@"delete from Gy_BarCodeBill where HItemID=" + HInterID);
-                    string sql1 = string.Format(@"update Sc_ICMOBillSub set HQty=HPlanQty+" + dr["HQty"] + " where HInterID=(select HSourceInterID from Gy_BarCodeBill where HItemID=" + HInterID + ")");
-                    oCN.RunProc(sql);
+                    string sql1 = string.Format(@"update Sc_ICMOBillSub set HQty=HQty+" + dr["HQty"] + " where HEntryID=(select HSourceEntryID from Gy_BarCodeBill where HItemID=" + HInterID + ")");
                     oCN.RunProc(sql1);
+                    oCN.RunProc(sql);
                 }
                 else
                 {
                     //閫氳繃鏉$爜id鎵惧埌鎵樻潯鐮侊紝閫氳繃鎵樻潯鐮佹壘鍒扮粍鎵樺崟瀛愯〃涓殑鍞竴鐮�
-                    string sql2 = "select HBarCode from Sc_PackUnionBillSub where HInterID=(select HBarcodeNo from Gy_BarCodeBill where HItemID=" + HInterID;
+                    string sql2 = "select HBarCode from Sc_PackUnionBillSub where HInterID=(select HBarcodeNo from Gy_BarCodeBill where HItemID=" + HInterID + ")";
                     //string sql2 = "select HBarCode from Sc_PackUnionBillSub where HInterID=(select HBarcodeNo from Gy_BarCodeBill where HItemID=3250)";
                     DataSet ds1 = oCN.RunProcReturn(sql2, "Sc_PackUnionBillSub");
                     DataTable dt = ds1.Tables[0];
@@ -521,9 +991,9 @@
                             DataRow dr1 = ds.Tables[0].Rows[0];
 
                             string sql = string.Format(@"delete from Gy_BarCodeBill where HBarCode='" + dr["HBarCode"].ToString() + "'");
-                            string sql1 = string.Format(@"update Sc_ICMOBillSub set HQty=HPlanQty+" + dr1["HQty"] + " where HInterID=(select HSourceInterID from Gy_BarCodeBill where HBarCode='" + dr["HBarCode"].ToString() + "')");
-                            oCN.RunProc(sql);
+                            string sql1 = string.Format(@"update Sc_ICMOBillSub set HQty=HQty+" + dr1["HQty"] + " where HEntryID=(select HSourceEntryID from Gy_BarCodeBill where HBarCode='" + dr["HBarCode"].ToString() + "')");
                             oCN.RunProc(sql1);
+                            oCN.RunProc(sql);
                         }
                     }
 

--
Gitblit v1.9.1