From c27c6fbfd03ffd89a839e7aa4c2643e5ea7ab0dc Mon Sep 17 00:00:00 2001
From: yusijie <ysj@hz-kingdee.com>
Date: 星期五, 19 一月 2024 10:20:09 +0800
Subject: [PATCH] 是否做首件/工序 检验单控制;批量出站汇报;保存前后控制(生产订单保存方法,开工单保存方法,完工单保存方法,停工挂起单保存方法,产量汇报单保存方法,质量汇报单保存方法,生产汇报单保存方法)

---
 WebAPI/Controllers/生产管理/生产任务单/Sc_ICMOBillController.cs | 1185 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 1,137 insertions(+), 48 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 3caf227..0b1561a 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"
@@ -9,6 +9,7 @@
 using System.Data;
 using System.Data.SqlClient;
 using System.Web.Http;
+using System.Windows.Forms;
 using WebAPI.Models;
 
 namespace WebAPI.Controllers
@@ -22,6 +23,10 @@
         private json objJsonResult = new json();
         SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
         DataSet ds;
+
+        //鑾峰彇绯荤粺鍙傛暟
+        Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
+        public DAL.ClsSc_ICMOBill BillOld = new DAL.ClsSc_ICMOBill();
 
         #region 鐢熶骇浠诲姟鍗� 淇濆瓨/缂栬緫鍔熻兘
         [Route("Sc_ICMOBill/ICMOBillEdit")]
@@ -68,7 +73,7 @@
             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淇敼
+            int OperationType = int.Parse(sArray[2].ToString()); // 鏁版嵁绫诲瀷 1娣诲姞 2澶嶅埗 3淇敼 
             string user = sArray[3].ToString();
 
             try
@@ -106,19 +111,49 @@
 
                 if ((OperationType == 1 || OperationType == 2) && ds.Tables[0].Rows.Count == 0)//鏂板
                 {
+                    //淇濆瓨鍓嶆帶鍒�=========================================              
+                    ds = oCN.RunProcReturn("exec h_p_Sc_ICMOBill_BeforeSaveCtrl_New " + HInterID, "h_p_Sc_ICMOBill_BeforeSaveCtrl_New");
+
+                    if (ds == null || ds.Tables[0].Rows.Count == 0)
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = "淇濆瓨鍓嶅垽鏂け璐ワ紒";
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                    if (DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBack"]) != "0")
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = "淇濆瓨澶辫触锛�" + DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBackRemark"]);
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                    //=========================================================
                     //涓昏〃
                     oCN.RunProc(@"Insert Into Sc_ICMOBillMain   
-                        (HBillType,HInterID,HBillNo,HDate,HPRDORGID
+                        (HBillType,HBillStatus,HInterID,HBillNo,HDate,HPRDORGID
                         ,HYear,HPeriod,HRemark,HMaker,HMakeDate
                         ,HSeOrderBillNo,HSeOrderInterID,HSeOrderEntryID,HEmpID,HCusID
                         ,HCenterID,HPlanQty,HDeptID,HMaterID,HUnitID,HBomID,HPlanBeginDate,HPlanEndDate,HISENTRUST,HISREWORK)
-                        values('3710'," + HInterID + ",'" + HBillNo + "','" + HDate + "'," + HPRDORGID +
+                        values('3710',1," + HInterID + ",'" + HBillNo + "','" + HDate + "'," + HPRDORGID +
                     "," + DateTime.Now.Year + "," + DateTime.Now.Month + ",'" + HRemark + "','" + HMaker + "',getdate()" +
                     ",'" + HSeOrderBillNo + "'," + HSeOrderInterID + "," + HSeOrderEntryID + "," + HEmpID + "," + HCusID +
                     "," + HCenterID + "," + HPlanQty + ",0,0,0,0,'',''" + "," + HISENTRUST + "," + HISREWORK + ") ");
                 }
                 else if (OperationType == 3 || ds.Tables[0].Rows.Count != 0)
-                { //淇敼
+                {
+                    if (ds.Tables[0].Rows[0]["瀹℃牳浜�"].ToString() != "")
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = "鍗曟嵁宸插鏍�,涓嶅厑璁镐慨鏀�!";
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+
+                    //淇敼
                     oCN.RunProc("update Sc_ICMOBillMain  set " +
                                 "HRemark='" + HRemark + "', HChecker='" + HMaker + "', HCheckDate=getdate()" +
                                 ", HSeOrderBillNo='" + HSeOrderBillNo + "', HSeOrderInterID=" + HSeOrderInterID + ", HSeOrderEntryID=" + HSeOrderEntryID + ", HEmpID=" + HEmpID + ", HCusID=" + HCusID + "" +
@@ -138,6 +173,9 @@
                     objJsonResult.data = null;
                     return objJsonResult;
                 }
+
+                //淇敼瀛楁 HSTOCKINORGID
+                oCN.RunProc("update Sc_ICMOBillSub set HSTOCKINORGID=" + HPRDORGID + " where HInterID=" + HInterID);
 
                 objJsonResult.code = "1";
                 objJsonResult.count = 1;
@@ -168,7 +206,7 @@
             long HSeOrderEntrySEQ = DetailColl[0].HSeOrderEntrySEQ == null ? 0 : DetailColl[0].HSeOrderEntrySEQ;		//閿�鍞鍗曡鍙�,
             string HPROJECTNO = DetailColl[0].HPROJECTNO == null ? "''" : DetailColl[0].HPROJECTNO;   //椤圭洰缂栧彿,
             long HPRODUCTTYPE = DetailColl[0].HPRODUCTTYPE == null ? 0 : DetailColl[0].HPRODUCTTYPE;			//浜у搧绫诲瀷,
-            long HCOSTRATE = DetailColl[0].HCOSTRATE == null ? 0 : DetailColl[0].HCOSTRATE;			// 鏉冮噸,
+            double HCOSTRATE = DetailColl[0].HCOSTRATE == null ? 0 : DetailColl[0].HCOSTRATE;			// 鏉冮噸,
             long HBASEUNITID = DetailColl[0].HBASEUNITID == null ? 0 : DetailColl[0].HBASEUNITID;       //鍩烘湰璁¢噺鍗曚綅,
 
             int i = 0;
@@ -226,13 +264,35 @@
 	            ,HBeginDate,HEndDate
                 ,HMaterID,HUnitID,HRemark,HSourceID,HDeptID,HSTATUS
 				,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney
-                ,HINSTOCKTYPE,HCHECKPRODUCT,HQAIP,HISBACKFLUSH,HREQSRC,HSTOCKINQUASELAUXQTY,HSeOrderEntrySEQ,HPROJECTNO,HPRODUCTTYPE,HCOSTRATE,HBASEUNITID) 
+                ,HINSTOCKTYPE,HCHECKPRODUCT,HQAIP,HISBACKFLUSH,HREQSRC,HSTOCKINQUASELAUXQTY,HSeOrderEntrySEQ,HPROJECTNO,HPRODUCTTYPE,HCOSTRATE,HBASEUNITID
+                ,HSTOCKINORGID,HOrderLevID ) 
                  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,{HINSTOCKTYPE},{HCHECKPRODUCT},{HQAIP},{HISBACKFLUSH},{HREQSRC},{HSTOCKINQUASELAUXQTY},{HSeOrderEntrySEQ},{HPROJECTNO},{HPRODUCTTYPE},{HCOSTRATE},{HBASEUNITID})");
+	                    ,0,0,'','',0,0,{HINSTOCKTYPE},{HCHECKPRODUCT},{HQAIP},{HISBACKFLUSH},{HREQSRC},{HSTOCKINQUASELAUXQTY},{HSeOrderEntrySEQ},{HPROJECTNO},{HPRODUCTTYPE},{HCOSTRATE},{HBASEUNITID},{oSub.HSTOCKINORGID},{oSub.HOrderLevID})");
             }
+
+            //淇濆瓨鍚庢帶鍒�=========================================              
+            ds = oCN.RunProcReturn("exec h_p_Sc_ICMOBill_AfterSaveCtrl_New " + HInterID, "h_p_Sc_ICMOBill_AfterSaveCtrl_New");
+
+            if (ds == null || ds.Tables[0].Rows.Count == 0)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "淇濆瓨鍚庡垽鏂け璐ワ紒";
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+            if (DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBack"]) != "0")
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "淇濆瓨澶辫触锛�" + DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBackRemark"]);
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+            //=========================================================
 
             objJsonResult.code = "1";
             objJsonResult.count = 1;
@@ -248,6 +308,7 @@
         {
             try
             {
+                //LogService.Write(sMainSub.ToString());
                 var model = sMainSub["model"].ToString();
                 var entry = sMainSub["model"]["HENTRY"].ToString();
                 var _model = sMainSub["model"]["HPPBOMMAINENTRY"].ToString();
@@ -268,11 +329,13 @@
                         (HBillType,HInterID,HBillNo,HDate,HPRDORGID
                         ,HYear,HPeriod,HRemark,HMaker,HMakeDate
                         ,HSeOrderBillNo,HSeOrderInterID,HSeOrderEntryID,HEmpID,HCusID
-                        ,HCenterID,HPlanQty,HDeptID,HMaterID,HUnitID,HBomID,HPlanBeginDate,HPlanEndDate,HBillStatus)
+                        ,HCenterID,HPlanQty,HDeptID,HMaterID,HUnitID,HBomID,HPlanBeginDate,HPlanEndDate,HBillStatus
+                        ,HOWNERID,HOWNERTYPEID)
                         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,'','',2) ");
+                "," + mainList[0].HCenterID + "," + mainList[0].HPlanQty + ",0,0,0,0,'','',2" +
+                ","+ mainList[0].HOWNERID + ",'"+ mainList[0].HOWNERTYPEID + "') ");
                 //淇濆瓨涓昏〃
                 foreach (var oSub in subList)
                 {
@@ -281,12 +344,14 @@
                 ,HPlanBeginDate,HPlanEndDate
 	            ,HBeginDate,HEndDate
                 ,HMaterID,HUnitID,HRemark,HSourceID,HDeptID,HSTATUS
-				,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney) 
+				,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney
+                ,HCOSTRATE,HISBACKFLUSH,HBatchNo,HBomID,HCHECKPRODUCT,HSEQ,HSTOCKINORGID) 
                  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},4
-	                    ,0,0,'','',0,0)");
+                ,{oSub.HMaterID},{oSub.HUnitID},'{oSub.HRemark}',{oSub.HSourceID},{oSub.HDeptID},'{oSub.HSTATUS}'
+	                    ,0,0,'','',0,0
+                ,{oSub.HCOSTRATE},{oSub.HISBACKFLUSH},'{oSub.HBatchNo}',{oSub.HBomID},{oSub.HCHECKPRODUCT},{oSub.HSEQ},{oSub.HSTOCKINORGID})");
                 }
 
                 foreach (var _item in _mainList)
@@ -318,7 +383,7 @@
 	            ,HBackRelationQty,HNumerator,HDenominator,HBASEUNITID,HProcessID,HICMOENTRYSEQ,HPROJECTNO
                 ,HOPERID,HSEQ,HSTOCKSTATUSID,HLOT,HOPTQUEUE,HRESERVETYPE,HSelPickedQty,HSELPRCDRETURNQTY,HProcName) 
                  values('{oSub.HInterID}','{oSub.HEntryID}','{oSub.HMaterID}','{oSub.HMaterNumber}','{oSub.HUnitID}','{oSub.HUnitNumber}','{oSub.HSPID}','{oSub.HQty}'
-                ,'{oSub.HQtyMust}','{oSub.HWHID}','{oSub.HRemark}','{oSub.HSourceInterID}','{oSub.HSourceEntryID}','{oSub.HSourceBillNo}','{oSub.HSourceBillType}','{oSub.HICMOInterID}','{oSub.HICMOEntryID}','{oSub.HICMOBillNo}','{oSub.HCHILDSUPPLYORGID}','{oSub.HSUPPLYORGID}','{oSub.HENTRUSTPICKORGID}','{oSub.HSRCTRANSORGID}','{oSub.HGROUPBYOWNERID}','{oSub.HOWNERID}','{oSub.HOWNERTYPEID}','{oSub.HRelationQty}','{oSub.HMoveStockQty}','{oSub.HAuxPropID}','{oSub.HBatchNO}','{oSub.HMTONo}','{oSub.HQtyScrap}','{oSub.HERPInterID}','{oSub.HERPEntryID}','{oSub.HBackRelationQty}','{oSub.HNumerator}','{oSub.HDenominator}','{oSub.HBASEUNITID}','{oSub.HProcessID}','{oSub.HICMOENTRYSEQ}','{oSub.HPROJECTNO}','{oSub.HOPERID}','{oSub.HSEQ}','{oSub.HSTOCKSTATUSID}','{oSub.HLOT}','{oSub.HOPTQUEUE}','{oSub.HRESERVETYPE}','{oSub.HSelPickedQty}','{oSub.HSELPRCDRETURNQTY}','{oSub.HProcName}')");
+                ,'{oSub.HQtyMust}','{oSub.HWHID}','{oSub.HRemark}','{oSub.HSourceInterID}','{oSub.HSourceEntryID}','{oSub.HSourceBillNo}','{oSub.HSourceBillType}','{oSub.HICMOInterID}','{oSub.HICMOEntryID}','{oSub.HICMOBillNo}','{oSub.HCHILDSUPPLYORGID}','{oSub.HSUPPLYORGID}','{oSub.HENTRUSTPICKORGID}','{oSub.HSRCTRANSORGID}','{oSub.HGROUPBYOWNERID}','{oSub.HOWNERID}','{oSub.HOWNERTYPEID}','{oSub.HRelationQty}','{oSub.HMoveStockQty}','{oSub.HAuxPropID}','{oSub.HBatchNO}','{oSub.HMTONo}','{Convert.ToDecimal(oSub.HQtyScrap)}','{oSub.HERPInterID}','{oSub.HERPEntryID}','{oSub.HBackRelationQty}','{oSub.HNumerator}','{oSub.HDenominator}','{oSub.HBASEUNITID}','{oSub.HProcessID}','{oSub.HICMOENTRYSEQ}','{oSub.HPROJECTNO}','{oSub.HOPERID}','{oSub.HSEQ}','{oSub.HSTOCKSTATUSID}','{oSub.HLOT}','{oSub.HOPTQUEUE}','{oSub.HRESERVETYPE}','{oSub.HSelPickedQty}','{oSub.HSELPRCDRETURNQTY}','{oSub.HProcName}')");
                 }
                 oCN.Commit();
                 objJsonResult.code = "1";
@@ -330,6 +395,7 @@
             }
             catch (Exception e)
             {
+                LogService.Write(e.Message.ToString());
                 oCN.RollBack();
                 objJsonResult.code = "0";
                 objJsonResult.count = 0;
@@ -337,6 +403,7 @@
                 objJsonResult.data = null;
                 return objJsonResult;
             }
+          
         }
 
 
@@ -386,6 +453,8 @@
             string msg2 = sArray[0].ToString(); //涓昏〃鏁版嵁
             int OperationType = int.Parse(sArray[1].ToString()); // 鏁版嵁绫诲瀷 1娣诲姞 3淇敼
             string user = sArray[2].ToString();
+            int HEntryID = int.Parse(sArray[3].ToString());
+            string HComputerName = SystemInformation.ComputerName; //璁惧鍚嶇О
 
             try
             {
@@ -416,34 +485,95 @@
                 long HBomID = mainList[0].HBomID;//bom
                 //double? HPlanQty = mainList[0].HPlanQty == null ? 0 : mainList[0].HPlanQty;//璁″垝鏁伴噺
                 string HMaker = user;//鍒跺崟浜�
+                string HIsStockQty = mainList[0].HIsStockQty;
+                string HRemark3 = mainList[0].HRemark3;
+              
 
                 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)//鏂板
+                if ((OperationType == 1 || OperationType == 2 || OperationType == 4) && ds.Tables[0].Rows.Count == 0)//鏂板
                 {
+                    //淇濆瓨鍓嶆帶鍒�=========================================              
+                    ds = oCN.RunProcReturn("exec h_p_Sc_ICMOBill_BeforeSaveCtrl_New " + HInterID, "h_p_Sc_ICMOBill_BeforeSaveCtrl_New");
+
+                    if (ds == null || ds.Tables[0].Rows.Count == 0)
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = "淇濆瓨鍓嶅垽鏂け璐ワ紒";
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                    if (DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBack"]) != "0")
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = "淇濆瓨澶辫触锛�" + DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBackRemark"]);
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                    //=========================================================
                     //涓昏〃
                     oCN.RunProc(@"Insert Into Sc_ICMOBillMain   
-                        (HBillType,HInterID,HBillNo,HDate,HPRDORGID
+                        (HBillType,HBillStatus,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 +
+                        ,HCenterID,HPlanQty,HDeptID,HMaterID,HUnitID,HBomID,HPlanBeginDate,HPlanEndDate
+                        ,HIsStockQty,HRemark3)
+                        values('3710',1," + HInterID + ",'" + HBillNo + "','" + HDate + "'," + HPRDORGID +
                     "," + DateTime.Now.Year + "," + DateTime.Now.Month + ",'" + HRemark + "','" + HMaker + "',getdate()" +
                     ",'" + HSeOrderBillNo + "'," + HSeOrderInterID + "," + HSeOrderEntryID + "," + HEmpID + "," + HCusID +
-                    "," + HCenterID + ",0,0,0,0," + HBomID + ",'','') ");
+                    "," + HCenterID + ",0,0,0,0," + HBomID + ",'',''" +
+                    ",'"+ HIsStockQty + "','"+ HRemark3 + "') ");
+                    
+
+
+                    LogService.Write("鐢ㄦ埛:" + user + ",鏃ユ湡:" + DateTime.Now + ",鏂板鐢熶骇璁㈠崟鍗曟嵁:" + HBillNo);
+                    oCN.RunProc("Insert into System_log (GeginDate, userid, WorkstationName, WorkList, SystemName, NetuserName, State) select GETDATE(),'" + user + "','" + HComputerName + "','" + "鏂板鐢熶骇璁㈠崟鍗曟嵁锛�" + HBillNo + "','LMES-鐢熶骇璁㈠崟妯″潡','" + DBUtility.ClsPub.IPAddress + "','鏂板鍗曟嵁'", ref DBUtility.ClsPub.sExeReturnInfo);
+
                 }
                 else if (OperationType == 3 || ds.Tables[0].Rows.Count != 0)
-                { //淇敼
+                {
+                    if (ds.Tables[0].Rows[0]["瀹℃牳浜�"].ToString() != "")
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = "鍗曟嵁宸插鏍�,涓嶅厑璁镐慨鏀�!";
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+
+                    //淇敼
                     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);
+                                "HRemark='" + HRemark + "', HUpDater='" + HMaker + "', HUpDateDate=getdate()" +
+                                ", HSeOrderBillNo='" + HSeOrderBillNo + "', HSeOrderInterID=" + HSeOrderInterID + ", HSeOrderEntryID=" + HSeOrderEntryID + ", HEmpID=" + HEmpID + ", HCusID=" + HCusID +
+                                ", HCenterID=" + HCenterID + ",HBomID=" + HBomID + ",HIsStockQty='"+ HIsStockQty + "',HRemark3='" + HRemark3 + "' where HInterID=" + HInterID);
 
                     //鍒犻櫎瀛愯〃
-                    oCN.RunProc("delete from Sc_ICMOBillSub where HInterID='" + HInterID + "'");
+                    oCN.RunProc("delete from Sc_ICMOBillSub where HInterID='" + HInterID + "' and HEntryID='" + HEntryID + "'");
+
+                    LogService.Write("鐢ㄦ埛:" + user + ",鏃ユ湡:" + DateTime.Now + ",淇敼鐢熶骇璁㈠崟鍗曟嵁:" + HBillNo);
+                    oCN.RunProc("Insert into System_log (GeginDate, userid, WorkstationName, WorkList, SystemName, NetuserName, State) select GETDATE(),'" + user + "','" + HComputerName + "','" + "淇敼鐢熶骇璁㈠崟鍗曟嵁锛�" + HBillNo + "','LMES-鐢熶骇璁㈠崟妯″潡','" + DBUtility.ClsPub.IPAddress + "','淇敼鍗曟嵁'", ref DBUtility.ClsPub.sExeReturnInfo);
                 }
                 //淇濆瓨瀛愯〃
-                objJsonResult = AddBillSub_NoTable(msg3, HInterID, OperationType);
+                objJsonResult = AddBillSub_NoTable(msg3, HInterID, OperationType, HEntryID);
+
+
+                //鍙嶅啓婧愬崟-閿�鍞鍗曟暟鎹�
+                if ((OperationType == 1 || OperationType == 2 || OperationType == 4) && ds.Tables[0].Rows.Count == 0)
+                {
+                    //鐢熶骇璁㈠崟鏂板鍥炲~閿�鍞鍗曞叧鑱旀暟閲�
+                    oCN.RunProc("exec h_p_Xs_UpDateRelation_SeOrderToICMO_Add " + HInterID);
+                }
+                else if (OperationType == 3 || ds.Tables[0].Rows.Count != 0)
+                {
+                    //鐢熶骇璁㈠崟鍒犻櫎鍥炲~閿�鍞鍗曞叧鑱旀暟閲�
+                    oCN.RunProc("exec h_p_Xs_UpDateRelation_SeOrderToICMO_Delete " + HInterID);
+                    //鐢熶骇璁㈠崟鏂板鍥炲~閿�鍞鍗曞叧鑱旀暟閲�
+                    oCN.RunProc("exec h_p_Xs_UpDateRelation_SeOrderToICMO_Add " + HInterID);
+                }
+
+
 
                 if (objJsonResult.code == "0")
                 {
@@ -470,9 +600,11 @@
             }
         }
 
-        public json AddBillSub_NoTable(string msg3, long HInterID, int OperationType)
+        public json AddBillSub_NoTable(string msg3, long HInterID, int OperationType,int HEntryID)
         {
             ClsSc_ICMOBillSub oSub = Newtonsoft.Json.JsonConvert.DeserializeObject<ClsSc_ICMOBillSub>(msg3);
+
+
             if (oSub.HQty <= 0 || oSub.HQty == null)
             {
                 objJsonResult.code = "0";
@@ -491,14 +623,7 @@
                 return objJsonResult;
             }
 
-            if (oSub.HDeptID == 0)
-            {
-                objJsonResult.code = "0";
-                objJsonResult.count = 0;
-                objJsonResult.Message = "鐢熶骇杞﹂棿涓嶈兘涓虹┖";
-                objJsonResult.data = null;
-                return objJsonResult;
-            }
+          
 
             if (oSub.HUnitID == 0)
             {
@@ -509,29 +634,51 @@
                 return objJsonResult;
             }
 
-            if (oSub.HBomID == 0)
-            {
-                objJsonResult.code = "0";
-                objJsonResult.count = 0;
-                objJsonResult.Message = "BOM涓嶈兘涓虹┖";
-                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)}
+                ,HBomID,HEntryCusID,HSTOCKINORGID
+				,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney
+                ,HAuxQty,HAuxUnit,HWidth,HWeight,HColorRemark,HCusMaterName,HCusModel,HOrderPickRemark) 
+                 values({HInterID},{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.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)");
+                 ,{oSub.HBomID}  ,{oSub.HCusID} ,{oSub.HSTOCKINORGID}
+	                    ,{oSub.HSourceInterID},{oSub.HSourceEntryID},'{oSub.HSourceBillNo}','{oSub.HSourceBillType}',0,0
+                ,{oSub.HAuxQty},{oSub.HAuxUnit},{oSub.HWidth},{oSub.HWeight},'{oSub.HColorRemark}','{oSub.HCusMaterName}','{oSub.HCusModel}','{oSub.HOrderPickRemark}')");
 
+            //淇濆瓨鍚庢帶鍒�=========================================              
+            ds = oCN.RunProcReturn("exec h_p_Sc_ICMOBill_AfterSaveCtrl_New " + HInterID, "h_p_Sc_ICMOBill_AfterSaveCtrl_New");
+
+            if (ds == null || ds.Tables[0].Rows.Count == 0)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "淇濆瓨鍚庡垽鏂け璐ワ紒";
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+            if (DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBack"]) != "0")
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "淇濆瓨澶辫触锛�" + DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBackRemark"]);
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+            //=========================================================
 
             objJsonResult.code = "1";
             objJsonResult.count = 1;
@@ -541,6 +688,241 @@
         }
         #endregion
 
+        #region 鐢熶骇浠诲姟鍗曞鏍�/鍙嶅鏍稿姛鑳�
+        [Route("Sc_ICMOBill/CheckSc_ICMOReportBill")]
+        [HttpGet]
+        public object CheckSc_ICMOReportBill(string HInterID,int Type, string user)
+        {
+            try
+            {
+                //鍒ゆ柇鏄惁鏈夊垹闄ゆ潈闄�
+                if (!DBUtility.ClsPub.Security_Log("Sc_ICMOBill_Check", 1, false, user))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鏃犳潈闄愬鏍�!";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                if (string.IsNullOrWhiteSpace(HInterID))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "HInterID涓虹┖锛�";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                ClsPub.CurUserName = user;
+                oCN.BeginTran();//寮�濮嬩簨鍔�
+
+                //Type 1 瀹℃牳  2  鍙嶅鏍�
+                if (Type == 1)
+                {
+                    if (!BillOld.CheckBill(int.Parse(HInterID), ref ClsPub.sExeReturnInfo))
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 1;
+                        objJsonResult.Message = "瀹℃牳澶辫触!鍘熷洜:" + ClsPub.sExeReturnInfo;
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                }
+                else
+                {
+                    if (BillOld.AbandonCheck(int.Parse(HInterID), ref ClsPub.sExeReturnInfo))
+                    {
+                        SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
+                        DataSet DSet = oCn.RunProcReturn("exec h_p_Sc_ICMOBill_AbandonCheckCtrl " + int.Parse(HInterID), "h_p_Sc_ICMOBill_AbandonCheckCtrl");
+                        //if (DBUtility.ClsPub.isInt(DSet.Tables[0].Rows[0]["Hback"]) != 0)
+                        //{
+                        //    objJsonResult.code = "0";
+                        //    objJsonResult.count = 1;
+                        //    objJsonResult.Message = "璇ヤ换鍔″崟宸蹭笅鎺ㄦ祦杞崱锛屼笉鍏佽鍙嶅鏍�" + DBUtility.ClsPub.isStrNull(DSet.Tables[0].Rows[0]["HBackRemark"]);
+                        //    objJsonResult.data = null;
+                        //    return objJsonResult;
+                        //}
+                    }
+                    else
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 1;
+                        objJsonResult.Message = "瀹℃牳澶辫触!鍘熷洜:" + ClsPub.sExeReturnInfo;
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                }
+
+                oCN.Commit();//鎻愪氦浜嬪姟
+
+                objJsonResult.code = "0";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "鎵ц鎴愬姛锛�";
+                objJsonResult.data = null;
+                return objJsonResult; ;
+
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "鎵ц澶辫触锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
+        #region 鐢熶骇浠诲姟鍗曞叧闂�/鍙嶅叧闂姛鑳�
+        [Route("Sc_ICMOBill/CloseSc_ICMOReportBill")]
+        [HttpGet]
+        public object CloseSc_ICMOReportBill(string HInterID, int Type, string user)
+        {
+            try
+            {
+                //鍒ゆ柇鏄惁鏈夊垹闄ゆ潈闄�
+                if (!DBUtility.ClsPub.Security_Log("Sc_ICMOBill_Close", 1, false, user))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鏃犳潈闄愬叧闂�!";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                if (string.IsNullOrWhiteSpace(HInterID))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "HInterID涓虹┖锛�";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                ClsPub.CurUserName = user;
+
+                oCN.BeginTran();//寮�濮嬩簨鍔�
+
+                //Type 1 鍏抽棴  2  鍙嶅叧闂�
+                if (Type == 1)
+                {
+                    if (!BillOld.CloseBill(int.Parse(HInterID), ref ClsPub.sExeReturnInfo))
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 1;
+                        objJsonResult.Message = "鍏抽棴澶辫触!鍘熷洜:" + ClsPub.sExeReturnInfo;
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                }
+                else
+                {
+                    if (!BillOld.CancelClose(int.Parse(HInterID), ref ClsPub.sExeReturnInfo))
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 1;
+                        objJsonResult.Message = "鍙嶅叧闂け璐�!鍘熷洜:" + ClsPub.sExeReturnInfo;
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                }
+
+                oCN.Commit();//鎻愪氦浜嬪姟
+
+                objJsonResult.code = "0";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "鎵ц鎴愬姛锛�";
+                objJsonResult.data = null;
+                return objJsonResult; ;
+
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "鎵ц澶辫触锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
+        #region 鐢熶骇浠诲姟鍗曚綔搴�/鍙嶄綔搴熷姛鑳�
+        [Route("Sc_ICMOBill/CancellSc_ICMOReportBill")]
+        [HttpGet]
+        public object CancellSc_ICMOReportBill(string HInterID, int Type, string user)
+        {
+            try
+            {
+                //鍒ゆ柇鏄惁鏈夊垹闄ゆ潈闄�
+                if (!DBUtility.ClsPub.Security_Log("Sc_ICMOBill_Delete", 1, false, user))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鏃犳潈闄愪綔搴�!";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                if (string.IsNullOrWhiteSpace(HInterID))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "HInterID涓虹┖锛�";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                ClsPub.CurUserName = user;
+
+                oCN.BeginTran();//寮�濮嬩簨鍔�
+
+                //Type 1 浣滃簾  2  鍙嶄綔搴�
+                if (Type == 1)
+                {
+                    if (!BillOld.Cancelltion(int.Parse(HInterID), ref ClsPub.sExeReturnInfo))
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 1;
+                        objJsonResult.Message = "浣滃簾澶辫触!鍘熷洜:" + ClsPub.sExeReturnInfo;
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                }
+                else
+                {
+                    if (!BillOld.AbandonCancelltion(int.Parse(HInterID), ref ClsPub.sExeReturnInfo))
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 1;
+                        objJsonResult.Message = "鍙嶄綔搴熷け璐�!鍘熷洜:" + ClsPub.sExeReturnInfo;
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                }
+
+                oCN.Commit();//鎻愪氦浜嬪姟
+
+                objJsonResult.code = "0";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "鎵ц鎴愬姛锛�";
+                objJsonResult.data = null;
+                return objJsonResult; ;
+
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "鎵ц澶辫触锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
+
         #region 鐢熶骇浠诲姟鍗曞垹闄ゅ姛鑳�
         [Route("Sc_ICMOBill/DeltetSc_ICMOReportBill")]
         [HttpGet]
@@ -548,6 +930,8 @@
         {
             try
             {
+                string HComputerName = SystemInformation.ComputerName; //璁惧鍚嶇О    
+
                 //鍒ゆ柇鏄惁鏈夊垹闄ゆ潈闄�
                 if (!DBUtility.ClsPub.Security_Log("Sc_ICMOBill_Drop", 1, false, user))
                 {
@@ -576,8 +960,75 @@
                     objJsonResult.data = null;
                     return objJsonResult; ;
                 }
+
+                string sReturn = "";
+                if (oSystemParameter.ShowBill(ref sReturn))
+                {
+                    if (oSystemParameter.omodel.Sc_ICMOBill_DeleterAndMakerMustSame == "Y")
+                    {
+                        if (ds.Tables[0].Rows[0]["HMaker"].ToString() != user && (user != "admin" && user != "Admin"))
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "鍙兘鍒犻櫎鏈汉鐨勫崟鎹紒";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                    }
+                }
+
+                if (int.Parse(ds.Tables[0].Rows[0]["HBillStatus"].ToString()) > 1)
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鍗曟嵁涓嶆槸鏈鏍哥姸鎬�,涓嶅厑璁稿垹闄わ紒";
+                    objJsonResult.data = null;
+                    return objJsonResult; ;
+                }
+
+               var DataSet = oCN.RunProcReturn("select * from Sc_ProcessExchangeBillMain where HICMOBillNo='" + ds.Tables[0].Rows[0]["HBillNo"].ToString() +"'", "Sc_ProcessExchangeBillMain");
+
+                if (DataSet.Tables[0].Rows.Count > 0)
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鍗曟嵁宸蹭笅鎺ㄥ伐搴忔祦杞崱,涓嶅厑璁稿垹闄わ紒";
+                    objJsonResult.data = null;
+                    return objJsonResult; ;
+                }
+
+                 DataSet = oCN.RunProcReturn("select * from h_v_IF_ProductInBillList where 婧愬崟鍗曞彿='" + ds.Tables[0].Rows[0]["HBillNo"].ToString() + "'", "h_v_IF_ProductInBillList");
+
+                if (DataSet.Tables[0].Rows.Count > 0)
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鍗曟嵁宸蹭笅鎺ㄧ敓浜у叆搴撳崟,涓嶅厑璁稿垹闄わ紒";
+                    objJsonResult.data = null;
+                    return objJsonResult; ;
+                }
+
+                DataSet = oCN.RunProcReturn("select * from h_v_IF_MateOutBillList where 婧愬崟鍗曞彿='" + ds.Tables[0].Rows[0]["HBillNo"].ToString() + "'", "h_v_IF_MateOutBillList");
+
+                if (DataSet.Tables[0].Rows.Count > 0)
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鍗曟嵁宸蹭笅鎺ㄧ敓浜ч鏂欏崟,涓嶅厑璁稿垹闄わ紒";
+                    objJsonResult.data = null;
+                    return objJsonResult; ;
+                }
+
+                //鐢熶骇璁㈠崟鍒犻櫎鍥炲~閿�鍞鍗曞叧鑱旀暟閲�
+                oCN.RunProc("exec h_p_Xs_UpDateRelation_SeOrderToICMO_Delete " + HInterID);
+
+
                 oCN.RunProc("delete from Sc_ICMOBillMain  where HInterID=" + HInterID);
                 oCN.RunProc("delete from Sc_ICMOBillSub  where HInterID=" + HInterID);
+
+                LogService.Write("鐢ㄦ埛:" + user + ",鏃ユ湡:" + DateTime.Now + ",鍒犻櫎鐢熶骇璁㈠崟鍗曟嵁:" + ds.Tables[0].Rows[0]["HBillNo"].ToString());
+                oCN.RunProc("Insert into System_log (GeginDate, userid, WorkstationName, WorkList, SystemName, NetuserName, State) select GETDATE(),'" + user + "','" + HComputerName + "','" + "鍒犻櫎鐢熶骇璁㈠崟鍗曟嵁锛�" + ds.Tables[0].Rows[0]["HBillNo"].ToString() + "','LMES-鐢熶骇璁㈠崟妯″潡','" + DBUtility.ClsPub.IPAddress + "','鍒犻櫎鍗曟嵁'", ref DBUtility.ClsPub.sExeReturnInfo);
+
                 oCN.Commit();//鎻愪氦浜嬪姟
                 objJsonResult.code = "0";
                 objJsonResult.count = 1;
@@ -597,16 +1048,241 @@
         }
         #endregion
 
+        #region 鐢熶骇浠诲姟鍗� 澶氳鎵归噺涓嬫帹
+        [Route("Sc_ICMOBill/Sc_ICMOReportBill_dh")]
+        [HttpGet]
+        public object Sc_ICMOReportBill_dh(string HInterID, string user, int OrganizationID)
+        {
+            try
+            {
+                //鑾峰彇鍗曟嵁ID
+                string[] HBillNo = HInterID.Split(',');
+                string Error = "";
+                int i = 0;
+                foreach (var item in HBillNo)
+                {
+                    string err = "";
+                    DAL.ClsSc_ProcessExchangeBill oBill = new DAL.ClsSc_ProcessExchangeBill();
+                    Model.ClsSc_ProcessExchangeBillMain lsmain = new Model.ClsSc_ProcessExchangeBillMain();
+                    List<Model.ClsSc_ProcessExchangeBillSub> ls = new List<Model.ClsSc_ProcessExchangeBillSub>();
+                    string HBillNOs = "";
+                    string hmainid = item.Split('|')[0];
+                    string HEntryID = item.Split('|')[1];
+
+                    ds = oCN.RunProcReturn("select * from h_v_IF_ICMOBillList where 1 = 1  and hmainid=" + hmainid + " and  HEntryID=" + HEntryID + " order by 鍗曟嵁鍙� desc", "h_v_IF_ICMOBillList");
+                    if (ds.Tables[0].Rows.Count == 0)
+                    {
+                        err = "鏃犳暟鎹�! \n";
+                    }
+                    else
+                    {
+                        string HNumber = ds.Tables[0].Rows[0]["浜у搧浠g爜"].ToString();
+                        HBillNOs = ds.Tables[0].Rows[0]["鍗曟嵁鍙�"].ToString();
+
+                        if (ds.Tables[0].Rows[0]["瀹℃牳浜�"].ToString() == "")
+                        {
+                            err = "鎵�閫夌敓浜ц鍗曚负鏈鏍哥姸鎬侊紝涓嶅厑璁镐笅鎺ㄧ敓鎴愬伐搴忔祦杞崱锛乗n";
+                        }
+
+                        if (ds.Tables[0].Rows[0]["鍏抽棴浜�"].ToString() != "")
+                        {
+                            err = "鎵�閫夌敓浜ц鍗曚负宸插叧闂姸鎬侊紝涓嶅厑璁镐笅鎺ㄧ敓鎴愬伐搴忔祦杞崱锛乗n";
+                        }
+
+                        if (ds.Tables[0].Rows[0]["浣滃簾浜�"].ToString() != "")
+                        {
+                            err = "鎵�閫夌敓浜ц鍗曚负宸蹭綔搴熺姸鎬侊紝涓嶅厑璁镐笅鎺ㄧ敓鎴愬伐搴忔祦杞崱锛乗n";
+                        }
+
+                        ds = oCN.RunProcReturn("select * from h_v_S_Sc_ICMOBillList where hmainid=" + hmainid + " and HEntryID=" + HEntryID + " and HSTOCKINORGID='" + OrganizationID + "'", "h_v_S_Sc_ICMOBillList");
+
+                        if (double.Parse(ds.Tables[0].Rows[0]["娴佽浆鍗℃暟閲�"].ToString()) == 0)
+                        {
+                            err = "鎵�閫夌敓浜ц鍗曞凡鍏ㄩ儴涓嬫帹鐢熸垚宸ュ簭娴佽浆鍗★紝鍓╀綑鍙笅鎺ㄦ暟閲忎负0锛屼笉鍏佽涓嬫帹鐢熸垚宸ュ簭娴佽浆鍗★紒\n";
+                        }
+                        lsmain.HMaker = user;  //鍒跺崟浜�
+                        lsmain.HBillType = "3772";
+                        lsmain.HBillSubType = "3772";
+                        lsmain.HDate = DBUtility.ClsPub.isDate(DateTime.Now.ToString("yyyy-MM-dd"));
+                        lsmain.HYear = DBUtility.ClsPub.isLong(DateTime.Now.Year);
+                        lsmain.HPeriod = DBUtility.ClsPub.isLong(DateTime.Now.Month);
+                        lsmain.HICMOInterID = long.Parse(ds.Tables[0].Rows[0]["hmainid"].ToString());
+                        lsmain.HICMOBillNo = ds.Tables[0].Rows[0]["鐢熶骇璁㈠崟鍙�"].ToString();
+                        lsmain.HICMOEntryID = long.Parse(ds.Tables[0].Rows[0]["HEntryID"].ToString());
+                        lsmain.HOrderProcNO = ds.Tables[0].Rows[0]["璁㈠崟璺熻釜鍙�"].ToString();
+                        lsmain.HMaterID = long.Parse(ds.Tables[0].Rows[0]["hmaterid"].ToString());
+                        lsmain.HMaterID2 = long.Parse(ds.Tables[0].Rows[0]["hmaterid"].ToString());
+                        lsmain.HMaterNumber = ds.Tables[0].Rows[0]["鐗╂枡浠g爜"].ToString();
+                        lsmain.HMaterModel = ds.Tables[0].Rows[0]["瑙勬牸鍨嬪彿"].ToString();
+                        lsmain.HBatchNo = ds.Tables[0].Rows[0]["鎵瑰彿"].ToString();
+                        lsmain.HSplitNo =1;//閮芥槸1
+                        lsmain.HUnitID = long.Parse(ds.Tables[0].Rows[0]["hunitid"].ToString());
+                        lsmain.HUnitNumber = ds.Tables[0].Rows[0]["璁¢噺鍗曚綅浠g爜"].ToString();
+                        lsmain.HPlanQty = double.Parse(ds.Tables[0].Rows[0]["璁″垝鐢熶骇鏁伴噺"].ToString());
+                        lsmain.HQty = double.Parse(ds.Tables[0].Rows[0]["娴佽浆鍗℃暟閲�"].ToString());
+                        lsmain.HPlanBeginDate = DateTime.Parse(ds.Tables[0].Rows[0]["璁″垝寮�宸ユ棩鏈�"].ToString());
+                        lsmain.HPlanEndDate = DateTime.Parse(ds.Tables[0].Rows[0]["璁″垝瀹屽伐鏃ユ湡"].ToString());
+                        lsmain.HWorkShopID = long.Parse(ds.Tables[0].Rows[0]["hdeptid"].ToString());
+                        lsmain.HProdMaterCode = ds.Tables[0].Rows[0]["浜у搧CODE"].ToString();
+                        lsmain.HSeOrderBillNo = ds.Tables[0].Rows[0]["閿�鍞鍗曞彿"].ToString();
+                        lsmain.HCusShortName = ds.Tables[0].Rows[0]["瀹㈡埛绠�绉�"].ToString();
+                        lsmain.HCusNeedMaterial = ds.Tables[0].Rows[0]["瀹㈡埛瑕佹眰鏉愭枡鎴愬垎"].ToString();
+                        lsmain.HPlanSendGoodsDate = ds.Tables[0].Rows[0]["棰勮鍑鸿揣鏃ユ湡"].ToString()==""?DateTime.Now.ToString(): ds.Tables[0].Rows[0]["棰勮鍑鸿揣鏃ユ湡"].ToString();
+                        lsmain.HSellDate = DateTime.Now.ToString();
+                        lsmain.HPRDORGID = OrganizationID;
+                        lsmain.HProdMaterName = ds.Tables[0].Rows[0]["浜у搧鍚嶇О"].ToString();
+                        lsmain.HCusName = ds.Tables[0].Rows[0]["瀹㈡埛鍚嶇О"].ToString();
+                        lsmain.HWorkRemark = ds.Tables[0].Rows[0]["鐢熶骇澶囨敞"].ToString();
+                        lsmain.HImportNote = ds.Tables[0].Rows[0]["閲嶈鎻愮ず"].ToString();
+                        lsmain.HPicNumVer = ds.Tables[0].Rows[0]["鍥惧彿鐗堟湰"].ToString();
+                        lsmain.HPicNumAssemble = ds.Tables[0].Rows[0]["鎬昏鍥惧彿"].ToString();
+                        lsmain.HMaterTexture = ds.Tables[0].Rows[0]["鏉愯川"].ToString();
+                        lsmain.HProductNum = ds.Tables[0].Rows[0]["鎴愬搧缂栧彿"].ToString();
+                        lsmain.HVerNum = ds.Tables[0].Rows[0]["鐗堟湰"].ToString();
+                        //lsmain.HCusNumber = ds.Tables[0].Rows[0]["婧愬崟瀹㈡埛缂栫爜"].ToString();
+                        //lsmain.HPickLabel = ds.Tables[0].Rows[0]["鍖呰鏍囪瘑"].ToString();
+                        //lsmain.HPickLabelNumber = ds.Tables[0].Rows[0]["鍖呰鏍囪瘑缂栫爜"].ToString();
+                        //lsmain.HXTNumber = ds.Tables[0].Rows[0]["鑺綋鐗╂枡浠g爜"].ToString();
+                        //lsmain.HXTModel = ds.Tables[0].Rows[0]["鑺綋瑙勬牸鍨嬪彿"].ToString();
+                        lsmain.HWidth = double.Parse(ds.Tables[0].Rows[0]["HWidth"].ToString());
+                        lsmain.HWeight = double.Parse(ds.Tables[0].Rows[0]["HWeight"].ToString());
+                        lsmain.HAuxUnit = int.Parse(ds.Tables[0].Rows[0]["HAuxUnit"].ToString());
+                        lsmain.HRemark2 = ds.Tables[0].Rows[0]["澶囨敞"].ToString();
+                        lsmain.HEmpID = long.Parse(ds.Tables[0].Rows[0]["HEmpID"].ToString());
+                        lsmain.HCusID = long.Parse(ds.Tables[0].Rows[0]["HCusID"].ToString());
+                        lsmain.HColorRemark = ds.Tables[0].Rows[0]["鏌撹壊瑕佹眰"].ToString();
+                        lsmain.HBLFlag = ds.Tables[0].Rows[0]["HBLFlag"].ToString() == "0" ? false : true;
+                        lsmain.HAuxQty = 0;
+                        lsmain.HAuxUnit = 0;
+
+
+                        ds = oCN.RunProcReturn("select top 1000 * from h_v_Gy_RoutingBillList a left join Gy_Process p on a.hprocid = p.HItemID where 鐗╂枡浠g爜='" + HNumber + "' and 榛樿宸ヨ壓=1", "h_v_Gy_RoutingBillList");
+
+                        if (ds.Tables[0].Rows.Count == 0)
+                        {
+                            err = "鎵�閫夌敓浜ц鍗曞搴旂墿鏂欐湭璁剧疆瀵瑰簲鐨勫伐鑹鸿矾绾匡紝涓嶅厑璁镐笅鎺ㄧ敓鎴愬伐搴忔祦杞崱锛乗n";
+                        }
+                        else
+                        {
+                            lsmain.HRoutingBillID = ds.Tables[0].Rows[0]["hmainid"].ToString();
+                            oBill.omodel = lsmain;
+
+                            int j = 0;
+                            foreach (DataRow row in ds.Tables[0].Rows)
+                            {
+                                if (row["HTProcessFlag"].ToString() == "False")
+                                {
+                                    ClsSc_ProcessExchangeBillSub sub = new ClsSc_ProcessExchangeBillSub();
+                                    sub.HEntryID = j + 1;
+                                    sub.HEntryCloseDate = DBUtility.ClsPub.isDate(DateTime.Now);
+                                    sub.HProcNo = long.Parse(row["宸ュ簭鍙�"].ToString());
+                                    sub.HProcID = long.Parse(row["HProcID"].ToString());
+                                    sub.HProcNumber = row["宸ュ簭浠g爜"].ToString();
+                                    sub.HWorkRemark = row["琛ㄤ綋澶囨敞"].ToString();
+                                    sub.HCenterID = long.Parse(row["HCenterID"].ToString());
+                                    sub.HSupID = long.Parse(row["HSupID"].ToString());
+                                    sub.HSupFlag = row["濮斿鏍囪"].ToString() == "False" ? false : true;
+                                    sub.HQty = lsmain.HQty;
+                                    sub.HTechnologyParameter = row["宸ヨ壓鍙傛暟"].ToString();
+                                    sub.HPicNum = row["鍥剧焊缂栧彿"].ToString();
+                                    sub.HProcCheckNote = row["鏈伐搴忕‘璁よ褰�"].ToString();
+                                    sub.HDeptID = 0;
+                                    sub.HDeptNumber = "";
+                                    sub.HOutPrice = 0;
+                                    sub.HRemark = "";
+                                    sub.HRelationQty_In =0;
+                                    sub.HRelationQty_Out = 0;
+                                    sub.HRelationQty_WWOrder = 0;
+                                    sub.HRelationQty_Bad = 0;
+                                    sub.HOverRate = 0;
+                                    sub.HMaxQty = 0;
+                                    sub.HPassRate = 0;
+                                    sub.HSumPassRate = 0;
+                                    j++;
+                                    oBill.DetailColl.Add(sub);
+                                }
+                            }
+                           
+                        }
+                    }
+
+                    bool bResult = false;
+                    if (err != "")
+                    {
+                        Error += "鐢熶骇璁㈠崟鍗曟嵁鍙�:" + HBillNOs + "\n" + err;
+                    }
+                    else
+                    {
+                        oBill.omodel.HBillNo = DBUtility.ClsPub.CreateBillCode("3772", ref DBUtility.ClsPub.sExeReturnInfo,true);
+                        bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
+                        oBill.DetailColl.Clear();
+
+                        if (!bResult)
+                        {
+                            Error += "淇濆瓨澶辫触,鐢熶骇璁㈠崟鍗曟嵁鍙�:" + HBillNOs + "\n" + err;
+                        }
+                        else
+                        {
+                            i++;
+                        }
+                    }
+                }
+                Error = "鎴愬姛:" + i + "琛�  !!!    " + Error;
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = Error;
+                objJsonResult.data = null;
+                return objJsonResult; ;
+
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "涓嬫帹澶辫触锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
         #region 鐢熶骇浠诲姟鍗曡幏鍙栬溅闂�
         [Route("Sc_ICMOBill/GetHDeptList")]
         [HttpGet]
-        public object GetHDeptList()
+        public object GetHDeptList(string HOrgID)
         {
             try
             {
                 DataSet oDs = new DataSet();
                 //==========
-                oDs = oCN.RunProcReturn("select HItemID,HName from Gy_Department", "Gy_Department");
+                oDs = oCN.RunProcReturn("select HItemID,HName from Gy_Department where HUSEORGID="+ HOrgID, "Gy_Department");
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "鑾峰彇鎴愬姛锛�";
+                objJsonResult.data = oDs.Tables[0];
+                return objJsonResult; ;
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "鍒犻櫎澶辫触锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
+        #region 鐢熶骇浠诲姟鍗曡幏鍙栧伐浣滀腑蹇�
+        [Route("Sc_ICMOBill/GetHWorkCenterList")]
+        [HttpGet]
+        public object GetHWorkCenterList()
+        {
+            try
+            {
+                DataSet oDs = new DataSet();
+                //==========
+                oDs = oCN.RunProcReturn("select HItemID,HName from Gy_WorkCenter", "Gy_WorkCenter");
                 objJsonResult.code = "1";
                 objJsonResult.count = 1;
                 objJsonResult.Message = "鑾峰彇鎴愬姛锛�";
@@ -1080,5 +1756,418 @@
         #endregion
 
 
+        #region [鍚屾鍗曟嵁]
+        [Route("Sc_ICMOBill/Sc_ICMOBillViewApi")]
+        [HttpGet]
+        public json Sc_ICMOBillViewApi(string BillNo, string BillType)
+        {
+            string sql = string.Empty;
+            string sReturn = "";
+            if (oSystemParameter.ShowBill(ref sReturn) == true)
+            {
+                //绯荤粺鍙傛暟鏄惁涓虹鏈変簯妯″紡,N涓哄叕鏈変簯妯″紡锛孻涓虹鏈変簯妯″紡
+                if (oSystemParameter.omodel.WMS_CloudMode == "Y")
+                {
+                    #region [绉佹湁浜戞ā寮忥紝鐩存帴璋冪敤鏁版嵁搴撳瓨鍌ㄨ繃绋嬫洿鏂癩
+                    try
+                    {
+                        oCN.BeginTran();
+                        SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
+                        DataSet DS = oCn.RunProcReturn("exec h_p_WMS_ERPSourceBillToLocal '" + BillNo + "','" + BillType + "'", "h_p_WMS_ERPSourceBillToLocal");
+                        if (DS == null)
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "鍗曟嵁鍚屾澶辫触";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                        else
+                        {
+                            if (DBUtility.ClsPub.isStrNull(DS.Tables[0].Rows[0]["HBack"]) == "2")
+                            {
+                                objJsonResult.code = "0";
+                                objJsonResult.count = 0;
+                                objJsonResult.Message = "ERP涓笉瀛樺湪璇ュ崟鎹彿";
+                                objJsonResult.data = null;
+                                return objJsonResult;
+                            }
+                            else
+                            {
+                                objJsonResult.code = "1";
+                                objJsonResult.count = 1;
+                                objJsonResult.Message = "鍗曟嵁鍚屾鎴愬姛";
+                                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
+                }
+                else
+                {
+                    #region [鍏湁浜戞ā寮忥紝璋冪敤WEBAPI鐨勬柟寮忚繘琛屾洿鏂癩
+                    var json = new
+                    {
+                        CreateOrgId = 0,
+                        Number = BillNo,
+                        Id = ""
+                    };
+                    #region [閲戣澏閮ㄥ垎]
+                    //鐧诲綍閲戣澏
+                    var loginRet = InvokeHelper.Login();
+                    var isSuccess = JObject.Parse(loginRet)["LoginResultType"].Value<int>();
+                    //鍒ゆ柇鏄惁鐧诲綍鎴愬姛
+                    if (isSuccess < 0)
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = loginRet;
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                    //鏌ョ湅 鑾峰彇鏁版嵁                    
+                    var _result = InvokeHelper.View("PRD_MO", JsonConvert.SerializeObject(json));
+                    var _saveObj = JObject.Parse(_result);
+                    //鍒ゆ柇鏁版嵁鏄惁鑾峰彇鎴愬姛
+                    if (_saveObj["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper() != "TRUE")
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = "閲戣澏鐢熶骇浠诲姟鍗曞悓姝ュけ璐sonRoot锛�" + _result;
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+
+                    #endregion
+                    //鑾峰彇涓昏〃鏁版嵁
+                    DataSet Ds;
+                    Int64 InterID = 0;
+                    Ds = oCN.RunProcReturn("select * from Sc_ICMOBillMain where HBillNo = '" + BillNo + "'", "Sc_ICMOBillMain");
+                    if (Ds.Tables[0].Rows.Count != 0 && ClsPub.isLong(Ds.Tables[0].Rows[0]["HInterID"].ToString()) != 0)
+                    {
+                        InterID = ClsPub.isLong(Ds.Tables[0].Rows[0]["HInterID"].ToString());
+                    }
+
+                    #region [涓昏〃鏁版嵁璧嬪�糫
+                    var jsonData = new
+                    {
+                        HInterID = _saveObj["Result"]["Result"]["Id"],
+                        HYear = DateTime.Now.Year,
+                        HPeriod = DateTime.Now.Month,
+                        HBillType = 3710,
+                        HDate = _saveObj["Result"]["Result"]["Date"],
+                        HBillNo = _saveObj["Result"]["Result"]["BillNo"],
+                        HBillStatus = _saveObj["Result"]["Result"]["ApproverId_Id"].ToString() == Convert.ToString(0) ? 1 : 2,
+                        HEMPID = 0,
+                        HRoutingInterID = 0,
+                        HPlanQty = 1,
+                        HRelationQty = 0,
+                        HPlanBeginDate = _saveObj["Result"]["Result"]["Date"],
+                        HPlanEndDate = DateTime.Now.ToString(),
+                        HBeginDate = _saveObj["Result"]["Result"]["Date"],
+                        HEndDate = DateTime.Now.ToString(),
+                        HMaterID = 0,
+                        HUnitID = 0,
+                        HBomID = 0,
+                        HBatchNo = "",
+                        HSourceInterID = 0,
+                        HSourceEntryID = 0,
+                        HSourceBillNo = "",
+                        HSourceBillType = "",
+                        HSeOrderInterID = 0,
+                        HSeOrderEntryID = 0,
+                        HSeOrderBillNo = "",
+                        HPRDORGID = _saveObj["Result"]["Result"]["PrdOrgId_Id"],
+                        HENTRUSTORGID = _saveObj["Result"]["Result"]["ENTrustOrgId_Id"],
+                        HOWNERID = _saveObj["Result"]["Result"]["OwnerId_Id"],
+                        HOWNERTYPEID = _saveObj["Result"]["Result"]["OwnerTypeId"],
+                        HCusID = 0,
+                        HDeptID = _saveObj["Result"]["Result"]["WorkShopID_Id"].ToString() == null ? 0 : _saveObj["Result"]["Result"]["WorkShopID_Id"],
+                        HRemark = "CLOUD瀵煎叆",
+                        HMTONo = "",
+                        HERPInterID = _saveObj["Result"]["Result"]["Id"],
+                        HERPBillType = _saveObj["Result"]["Result"]["BillType_Id"],
+                        HMaker = _saveObj["Result"]["Result"]["CreatorId"]["Name"],
+                        HMakeDate = _saveObj["Result"]["Result"]["CreateDate"],
+                        HChecker = _saveObj["Result"]["Result"]["ApproverId"]["Name"],
+                        HCheckDate = _saveObj["Result"]["Result"]["ApproveDate"],
+                        HBillSubType = _saveObj["Result"]["Result"]["IsRework"] = true ? 1 : 0,
+                        HISENTRUST = _saveObj["Result"]["Result"]["IsEntrust"],
+                        HISREWORK = _saveObj["Result"]["Result"]["IsRework"]                       
+                    };
+                    #endregion
+                    // 鍒犻櫎涓昏〃瀵瑰簲鏁版嵁
+                    sql = $"delete from Sc_ICMOBillMain where HInterID = " + InterID;
+                    oCN.RunProc(sql);
+
+                    //鎻掑叆涓昏〃
+                    sql = $@"
+                insert into Sc_ICMOBillMain
+                (HInterID,HYear,HPeriod,HBillType,HDate
+	            ,HBillNo,HBillStatus,HEMPID,HRoutingInterID
+	            ,HPlanQty,HRelationQty,HPlanBeginDate,HPlanEndDate,HBeginDate,HEndDate
+	            ,HMaterID,HUnitID,HBomID,HBatchNo
+	            ,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HSeOrderInterID,HSeOrderEntryID,HSeOrderBillNo
+	            ,HPRDORGID,HENTRUSTORGID,HOWNERID,HOWNERTYPEID
+	            ,HCusID,HDeptID,HRemark,HMTONo,HERPInterID,HERPBillType
+	            ,HMaker,HMakeDate,HChecker,HCheckDate
+	            ,HBillSubType,HISENTRUST,HISREWORK
+                 )
+                values
+                ({jsonData.HInterID},{jsonData.HYear},{jsonData.HPeriod},{jsonData.HBillType},'{jsonData.HDate}','{jsonData.HBillNo}',
+                {jsonData.HBillStatus},{jsonData.HEMPID},{jsonData.HRoutingInterID},{jsonData.HPlanQty},{jsonData.HRelationQty},
+                '{jsonData.HPlanBeginDate}', '{jsonData.HPlanEndDate}','{jsonData.HBeginDate}','{jsonData.HEndDate}',{jsonData.HMaterID},
+                {jsonData.HUnitID},{jsonData.HBomID},'{jsonData.HBatchNo}',{jsonData.HSourceInterID},{jsonData.HSourceEntryID},
+                '{jsonData.HSourceBillNo}','{jsonData.HSourceBillType}',{jsonData.HSeOrderInterID}, {jsonData.HSeOrderEntryID},'{jsonData.HSeOrderBillNo}',
+                {jsonData.HPRDORGID},{jsonData.HENTRUSTORGID},{jsonData.HOWNERID},'{jsonData.HOWNERTYPEID}',{jsonData.HCusID},{jsonData.HDeptID},
+                '{jsonData.HRemark}','{jsonData.HMTONo}',{jsonData.HERPInterID},'{jsonData.HERPBillType}','{jsonData.HMaker}','{jsonData.HMakeDate}',
+                '{jsonData.HChecker}','{jsonData.HCheckDate}','{jsonData.HBillSubType}','{jsonData.HISENTRUST}','{jsonData.HISREWORK}')";
+
+                    oCN.RunProc(sql);
+
+                    #region [鐢宠瀛愯〃鍙橀噺]
+                    var dataArr = _saveObj["Result"]["Result"]["TreeEntity"];
+
+                    DataSet Cs;                   
+                    double RelationQty = 0;                  
+                    #endregion
+                    int i = 0;
+
+                    // 鑾峰彇瀛愯〃鏁版嵁
+                    Cs = oCN.RunProcReturn("select * from Sc_ICMOBillSub where HInterID = " + InterID, "Sc_ICMOBillSub");
+                    // 鍒犻櫎瀛愯〃瀵瑰簲鏁版嵁
+                    sql = $"delete from Sc_ICMOBillSub where HInterID = " + InterID;
+                    oCN.RunProc(sql);
+
+                    foreach (var oSub in dataArr)
+                    {
+                        #region [瀛愯〃鏁版嵁璧嬪�糫
+
+                        if (Cs.Tables[0].Rows.Count != 0 && ClsPub.isLong(Cs.Tables[0].Rows[0]["HInterID"].ToString()) != 0)
+                        {                           
+                            RelationQty = ClsPub.isDoule(Cs.Tables[0].Rows[i]["HRelationQty"].ToString());                          
+
+                            i++;
+                        }
+
+                        var subData = new
+                        {
+                            HInterID = _saveObj["Result"]["Result"]["Id"],
+                            HENTRYID = oSub["Id"],
+                            HSEQ = oSub["Seq"],
+                            HQty = oSub["Qty"],
+                            HQTYMUST = oSub["Qty"],
+                            HRelationQty = RelationQty,
+                            HRelationMoney = 0,
+                            HPlanBeginDate = oSub["IdPlanStartDate"],
+                            HPlanEndDate = oSub["PlanFinishDate"],
+                            HBeginDate = oSub["StartDate"],
+                            HEndDate = oSub["FinishDate"],
+                            HBomID = oSub["BomId_Id"],
+                            HRemark = "CLOUD瀵煎叆",
+                            HMaterID = oSub["MaterialId_Id"],
+                            HUnitID = oSub["UnitId_Id"],
+                            HWHID = oSub["StockId_Id"],
+                            HSPID = oSub["StockLocId_Id"],
+                            HPROCID = oSub["ProcessId_Id"],
+                            HDEPTID = oSub["WorkShopID_Id"],
+                            HBatchNo = oSub["Lot_Text"],
+                            HSourceInterID = oSub["SrcBillId"],
+                            HSourceEntryID = oSub["SrcBillEntryId"],
+                            HSourceBillNo = oSub["SrcBillNo"],
+                            HSourceBillType = oSub["SrcBillType"],
+                            HSeOrderInterID = oSub["SaleOrderId"],
+                            HSeOrderEntryID = oSub["SaleOrderEntryId"],
+                            HSeOrderBillNo = oSub["SaleOrderNo"],
+                            HSTOCKINORGID = oSub["StockInOrgId_Id"],
+                            HINSTOCKOWNERID = oSub["InStockOwnerId_Id"],
+                            HINSTOCKOWNERTYPEID = oSub["InStockOwnerTypeId"],
+                            HREQUESTORGID = oSub["RequestOrgId_Id"],
+                            HPlanMode = 0,
+                            HMTONo = oSub["MTONo"],
+                            HERPInterID = _saveObj["Result"]["Result"]["Id"],
+                            HERPEntryID = oSub["Id"],
+                            HSTATUS = oSub["Status"],
+                            HEntryCusID = 0,
+                            HICMOReportRelationQty = oSub["RepQuaSelAuxQty"],
+                            HAuxPropID = oSub["AuxPropId_Id"],
+                            HProdMaterCode = "",
+                            HCusShortName = "",
+                            HCusNeedMaterial = "",
+                            HPlanSendGoodsDate = "",
+                            HProdMaterName = "",
+                            HWorkRemark = "",
+                            HImportNote = "",
+                            HCusName = "",
+                            HInstockQty_Max = 0,
+                            HInstockQty_Min = 0,
+                            HPickLabel = "",
+                            HPickLabelNumber = oSub["StockInLimitH"],
+                            HCusNumber = oSub["StockInLimitL"],
+                            HINSTOCKTYPE = oSub["InStockType"],
+                            HCHECKPRODUCT = oSub["CheckProduct"],
+                            HQAIP = oSub["QAIP"],
+                            HISBACKFLUSH = oSub["ISBACKFLUSH"],
+                            HREQSRC = oSub["ReqSrc"],
+                            HSTOCKINQUASELAUXQTY = oSub["StockInQuaSelAuxQty"],
+                            HSeOrderEntrySEQ = oSub["SaleOrderEntrySeq"],
+                            HPROJECTNO = oSub["ProjectNo"],
+                            HPRODUCTTYPE = oSub["ProductType"],
+                            HCOSTRATE = oSub["CostRate"],
+                            HBASEUNITID = oSub["BaseUnitId_Id"],
+                        };
+                        #endregion                       
+
+                        //鎻掑叆瀛愯〃
+                        sql = $@"
+                 insert into Sc_ICMOBillSub
+                 (HInterID,HENTRYID,HSEQ,HQty,HQTYMUST,HRelationQty,HRelationMoney
+	            ,HPlanBeginDate,HPlanEndDate,HBeginDate,HEndDate,HBomID,HRemark
+	            ,HMaterID,HUnitID,HWHID,HSPID,HPROCID,HDEPTID,HBatchNo
+	            ,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType
+	            ,HSeOrderInterID,HSeOrderEntryID,HSeOrderBillNo
+	            ,HSTOCKINORGID,HINSTOCKOWNERID,HINSTOCKOWNERTYPEID,HREQUESTORGID
+	            ,HPlanMode,HMTONo,HERPInterID,HERPEntryID,HSTATUS
+	            ,HEntryCusID,HICMOReportRelationQty,HAuxPropID,HProdMaterCode,HCusShortName
+	            ,HCusNeedMaterial,HPlanSendGoodsDate,HProdMaterName,HWorkRemark,HImportNote,HCusName
+	            ,HInstockQty_Max,HInstockQty_Min,HPickLabel,HPickLabelNumber,HCusNumber
+	            ,HINSTOCKTYPE,HCHECKPRODUCT,HQAIP,HISBACKFLUSH,HREQSRC,HSTOCKINQUASELAUXQTY
+	            ,HSeOrderEntrySEQ,HPROJECTNO,HPRODUCTTYPE,HCOSTRATE,HBASEUNITID
+                 )
+                 values
+                 ({subData.HInterID},{subData.HENTRYID},{subData.HSEQ},{subData.HQty},{subData.HQTYMUST},{subData.HRelationQty},
+                  {subData.HRelationMoney},'{subData.HPlanBeginDate}','{subData.HPlanEndDate}','{subData.HBeginDate}','{subData.HEndDate}',{subData.HBomID},
+                  '{subData.HRemark}',{subData.HMaterID},{subData.HUnitID},{subData.HWHID},{subData.HSPID},{subData.HPROCID},{subData.HDEPTID},
+                  '{subData.HBatchNo}',{subData.HSourceInterID},{subData.HSourceEntryID},'{subData.HSourceBillNo}','{subData.HSourceBillType}',
+                  {subData.HSeOrderInterID},{subData.HSeOrderEntryID},'{subData.HSeOrderBillNo}',{subData.HSTOCKINORGID},{subData.HINSTOCKOWNERID},
+                  '{subData.HINSTOCKOWNERTYPEID}',{subData.HREQUESTORGID},'{subData.HPlanMode}','{subData.HMTONo}',{subData.HERPInterID},
+                  {subData.HERPEntryID},{subData.HSTATUS},{subData.HEntryCusID},{subData.HICMOReportRelationQty},{subData.HAuxPropID},                  
+                  '{subData.HProdMaterCode}','{subData.HCusShortName}','{subData.HCusNeedMaterial}','{subData.HPlanSendGoodsDate}',
+                  '{subData.HProdMaterName}','{subData.HWorkRemark}','{subData.HImportNote}','{subData.HCusName}',{subData.HInstockQty_Max},
+                  {subData.HInstockQty_Min},'{subData.HPickLabel}',{subData.HPickLabelNumber},{subData.HCusNumber},'{subData.HINSTOCKTYPE}',
+                  '{subData.HCHECKPRODUCT}','{subData.HQAIP}','{subData.HISBACKFLUSH}','{subData.HREQSRC}',{subData.HSTOCKINQUASELAUXQTY},
+                  {subData.HSeOrderEntrySEQ},'{subData.HPROJECTNO}','{subData.HPRODUCTTYPE}',{subData.HCOSTRATE},{subData.HBASEUNITID})";
+
+                        oCN.RunProc(sql);
+                    }
+
+
+                    objJsonResult.code = "1";
+                    objJsonResult.count = 1;
+                    objJsonResult.Message = "鍗曟嵁鍚屾鎴愬姛锛�";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+
+                    #endregion
+                }
+            }
+            else
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "鍗曟嵁璇诲彇澶辫触锛�";
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
+
+        #region 鐢熶骇浠诲姟鍗曡鍗曞寘瑁呭娉� 淇濆瓨鍔熻兘
+        [Route("Sc_ICMOBill/ICMOBillSaveRemark")]
+        [HttpGet]
+        public object ICMOBillSaveRemark(string HInterID,string HEntryID, string HOrderPickRemark)
+        {
+            try
+            {
+                if (string.IsNullOrEmpty(HInterID))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "Exception锛丠InterID涓嶈兘涓虹┖";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+                SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
+
+                oCN.BeginTran();
+                 oCN.RunProc("update Sc_ICMOBillSub set HOrderPickRemark = '" + HOrderPickRemark + "' where HInterID = " + HInterID + " and  HEntryID = " + HEntryID + "");
+                oCN.Commit();
+
+                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("Sc_ICMOBill/NotInDayPlan")]
+        [HttpGet]
+        public object Sc_ICMOBillList_NotInDayPlan(string sWhere, string user)
+        {
+            try
+            {
+                List<object> columnNameList = new List<object>();
+
+                ds = oCN.RunProcReturn("select * from  h_v_Sc_ICMOList_NotInDayPlan where 1 = 1" + sWhere , "h_v_Sc_ICMOList_NotInDayPlan");
+
+                if (ds == null && ds.Tables[0].Rows.Count == 0)
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "Sucess锛佹病鏈夋煡璇㈠埌鐩稿叧鏁版嵁";
+                    objJsonResult.data = ds.Tables[0];
+                    return objJsonResult;
+                }
+                else
+                {
+                    //娣诲姞鍒楀悕
+                    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鍒楀璞$殑鍒楀悕
+                    }
+
+                    objJsonResult.code = "1";
+                    objJsonResult.count = 1;
+                    objJsonResult.Message = "Sucess锛�";
+                    objJsonResult.data = ds.Tables[0];
+                    objJsonResult.list = columnNameList;
+                    return objJsonResult;
+                }               
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
     }
 }
\ No newline at end of file

--
Gitblit v1.9.1