yangle
2024-06-29 1445994a1b07f15b7c412c0659dba66e9a145b81
WebAPI/Controllers/Éú²ú¹ÜÀí/Éú²úÈÎÎñµ¥/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
@@ -72,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
@@ -110,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 + "" +
@@ -175,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;
@@ -233,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;
@@ -255,7 +308,7 @@
        {
            try
            {
                //LogService.Write(sMainSub.ToString());
                LogService.Write("生产订单"+sMainSub.ToString());
                var model = sMainSub["model"].ToString();
                var entry = sMainSub["model"]["HENTRY"].ToString();
                var _model = sMainSub["model"]["HPPBOMMAINENTRY"].ToString();
@@ -271,16 +324,30 @@
                oCN.RunProc(sql);
                sql = $"delete Sc_ICMOBillSub where HinterID = {mainList[0].HInterID}";
                oCN.RunProc(sql);
                LogService.Write("生产订单" + @"Insert Into Sc_ICMOBillMain
                        (HBillType,HInterID,HBillNo,HDate,HPRDORGID
                        ,HYear,HPeriod,HRemark,HMaker,HMakeDate,HChecker,HCheckDate
                        ,HSeOrderBillNo,HSeOrderInterID,HSeOrderEntryID,HEmpID,HCusID
                        ,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].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].HOWNERID + ",'" + mainList[0].HOWNERTYPEID + "') ");
                //主表
                oCN.RunProc(@"Insert Into Sc_ICMOBillMain   
                        (HBillType,HInterID,HBillNo,HDate,HPRDORGID
                        ,HYear,HPeriod,HRemark,HMaker,HMakeDate
                        ,HYear,HPeriod,HRemark,HMaker,HMakeDate,HChecker,HCheckDate
                        ,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()" +
                "," + DateTime.Now.Year + "," + DateTime.Now.Month + ",'" + mainList[0].HRemark + "','" + mainList[0].HMaker + "',getdate(),'" + 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)
                {
@@ -289,12 +356,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)
@@ -397,6 +466,7 @@
            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
            {
@@ -415,6 +485,7 @@
                long HInterID = mainList[0].HInterID;//递入type得到的单据ID
                string HBillNo = mainList[0].HBillNo;//递入type得到的单据号
                string HMainSourceBillSubType = mainList[0].HMainSourceBillSubType;
                long HPRDORGID = mainList[0].HPRDORGID;//组织
                DateTime HDate = mainList[0].HDate;//日期
                string HRemark = mainList[0].HRemark;//备注
@@ -427,34 +498,117 @@
                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 HIsStockQty_SeOrderBill = mainList[0].HIsStockQty_SeOrderBill;
                string HRemark3 = mainList[0].HRemark3;
                //保存前控制=========================================
                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;
                }
                //=========================================================
                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)//新增
                {
                    //主表
                    oCN.RunProc(@"Insert Into Sc_ICMOBillMain   
                        (HBillType,HInterID,HBillNo,HDate,HPRDORGID
                        (HBillType,HMainSourceBillSubType,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,HIsStockQty_SeOrderBill,HRemark3)
                        values('3710','" + (HMainSourceBillSubType==null?"":HMainSourceBillSubType) + "',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 + "','" + HIsStockQty_SeOrderBill + "','"+ 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 " +
                                "HMainSourceBillSubType='" + (HMainSourceBillSubType == null ? "" : HMainSourceBillSubType) + "'," +
                                "HRemark='" + HRemark + "', HUpDater='" + HMaker + "', HUpDateDate=getdate()" +
                                ", HSeOrderBillNo='" + HSeOrderBillNo + "', HSeOrderInterID=" + HSeOrderInterID + ", HSeOrderEntryID=" + HSeOrderEntryID + ", HEmpID=" + HEmpID + ", HCusID=" + HCusID + "" +
                                ", HCenterID=" + HCenterID + ",HBomID=" + HBomID + " where HInterID=" + HInterID);
                                ", HSeOrderBillNo='" + HSeOrderBillNo + "', HSeOrderInterID=" + HSeOrderInterID + ", HSeOrderEntryID=" + HSeOrderEntryID + ", HEmpID=" + HEmpID + ", HCusID=" + HCusID +
                                ", HCenterID=" + HCenterID + ",HBomID=" + HBomID + ",HIsStockQty='"+ HIsStockQty + "',HIsStockQty_SeOrderBill='" + HIsStockQty_SeOrderBill + "',HRemark3='" + HRemark3 + "' where HInterID=" + HInterID);
                    //生产订单删除回填销售订单关联数量
                    oCN.RunProc("exec h_p_Xs_UpDateRelation_SeOrderToICMO_Delete " + 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, HEntryID);
                //反写源单-销售订单数据
                if ((OperationType == 1 || OperationType == 2 || OperationType == 4))
                {
                    //生产订单新增回填销售订单关联数量
                    oCN.RunProc("exec h_p_Xs_UpDateRelation_SeOrderToICMO_Add " + HInterID);
                }
                else if (OperationType == 3)
                {
                    //生产订单新增回填销售订单关联数量
                    oCN.RunProc("exec h_p_Xs_UpDateRelation_SeOrderToICMO_Add " + HInterID);
                }
                //保存后控制=========================================
                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;
                }
                //=========================================================
                if (objJsonResult.code == "0")
                {
@@ -484,6 +638,8 @@
        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";
@@ -502,14 +658,7 @@
                return objJsonResult;
            }
            if (oSub.HDeptID == 0)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "生产车间不能为空";
                objJsonResult.data = null;
                return objJsonResult;
            }
            if (oSub.HUnitID == 0)
            {
@@ -534,14 +683,16 @@
                ,HPlanBeginDate,HPlanEndDate
               ,HBeginDate,HEndDate
                ,HMaterID,HUnitID,HRemark,HSourceID,HDeptID,HSTATUS
                ,HBomID,HEntryCusID
            ,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney)
                ,HBomID,HEntryCusID,HSTOCKINORGID
            ,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney
                ,HAuxQty,HAuxUnit,HAuxQty2,HAuxUnit2,HWidth,HWeight,HColorRemark,HCusMaterName,HCusModel,HOrderPickRemark,HCusMaterNumber,HWidth_New,HWeight_New,HMaterModel,HRemark_New,HPlanOrderProcNo)
                 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.HAuxQty2},{oSub.HAuxUnit2},{oSub.HWidth},{oSub.HWeight},'{oSub.HColorRemark}','{oSub.HCusMaterName}','{oSub.HCusModel}','{oSub.HOrderPickRemark}','{oSub.HCusMaterNumber}',{oSub.HWidth_New},{oSub.HWeight_New},'{oSub.HModel}','{oSub.HRemark_New}','{oSub.HPlanOrderProcNo}')");
            objJsonResult.code = "1";
@@ -557,6 +708,7 @@
        [HttpGet]
        public object CheckSc_ICMOReportBill(string HInterID,int Type, string user)
        {
            string sql = "";
            try
            {
                //判断是否有删除权限
@@ -579,12 +731,47 @@
                }
                ClsPub.CurUserName = user;
                oCN.BeginTran();//开始事务
                ds = oCN.RunProcReturn("select * from Sc_ICMOBillMain where HInterID = " + int.Parse(HInterID), "Sc_ICMOBillMain");
                string HBillNo = "";
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "单据不存在!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    HBillNo = ds.Tables[0].Rows[0]["HBillNo"].ToString();
                }
                //Type 1 å®¡æ ¸  2  åå®¡æ ¸
                if (Type == 1)
                {
                    if (!BillOld.CheckBill(int.Parse(HInterID), ref ClsPub.sExeReturnInfo))
                    //审核前控制
                    sql = "exec h_p_Sc_ICMOBill_BeforeCheckCtrl " + int.Parse(HInterID) + ",'" + HBillNo + "','" + user + "'";
                    ds = oCN.RunProcReturn(sql, "h_p_Sc_ICMOBill_BeforeCheckCtrl");
                    if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "审核失败!原因:审核前判断失败,请与网络管理人员联系";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "审核失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    if (!BillOld.CheckBill(int.Parse(HInterID),HBillNo, "h_p_Sc_ICMOBill_AfterCheckCtrl", user, ref ClsPub.sExeReturnInfo))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
@@ -595,7 +782,28 @@
                }
                else
                {
                    if (BillOld.AbandonCheck(int.Parse(HInterID), ref ClsPub.sExeReturnInfo))
                    //反审核前控制
                    sql = "exec h_p_Sc_ICMOBill_BeforeUnCheckCtrl " + int.Parse(HInterID) + ",'" + HBillNo + "','" + user + "'";
                    ds = oCN.RunProcReturn(sql, "h_p_Sc_ICMOBill_BeforeUnCheckCtrl");
                    if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "反审核失败!原因:反审核前判断失败,请与网络管理人员联系";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "反审核失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    if (BillOld.AbandonCheck(int.Parse(HInterID), HBillNo, "h_p_Sc_ICMOBill_AfterUnCheckCtrl", user, 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");
@@ -617,8 +825,6 @@
                        return objJsonResult;
                    }
                }
                oCN.Commit();//提交事务
                objJsonResult.code = "0";
                objJsonResult.count = 1;
@@ -794,6 +1000,8 @@
        {
            try
            {
                string HComputerName = SystemInformation.ComputerName; //设备名称
                //判断是否有删除权限
                if (!DBUtility.ClsPub.Security_Log("Sc_ICMOBill_Drop", 1, false, user))
                {
@@ -812,7 +1020,8 @@
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                oCN.BeginTran();//开始事务
                string HBillNo = "";
                ds = oCN.RunProcReturn("select * from Sc_ICMOBillMain where HInterID=" + HInterID, "Sc_ICMOBillMain");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
@@ -822,8 +1031,139 @@
                    objJsonResult.data = null;
                    return objJsonResult; ;
                }
                else
                {
                    HBillNo = ds.Tables[0].Rows[0]["HBillNo"].ToString();
                }
                //删除前控制=========================================
                string sql1 = "exec h_p_Sc_ICMOBill_BeforeDelCtrl " + HInterID + ",'" + HBillNo + "','" + user + "'";
                ds = oCN.RunProcReturn(sql1, "h_p_Sc_ICMOBill_BeforeDelCtrl");
                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:删除前判断失败,请与网络管理人员联系";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                //==================================================================================
                ds = oCN.RunProcReturn("select * from Sc_ICMOBillMain where HInterID=" + HInterID, "Sc_ICMOBillMain");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "没有数据,无法删除!";
                    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.BeginTran();//开始事务
                //生产订单删除回填销售订单关联数量
                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);
                //删除后控制==================================================================================
                string sql2 = "exec h_p_Sc_ICMOBill_AfterDelCtrl " + HInterID + ",'" + HBillNo + "','" + user + "'";
                ds = oCN.RunProcReturn(sql2, "h_p_Sc_ICMOBill_AfterDelCtrl");
                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                {
                    sReturn = "删除后判断失败,请与网络管理人员联系";
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:" + sReturn ;
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
                {
                    sReturn = ds.Tables[0].Rows[0]["HRemark"].ToString();
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除失败!原因:" + sReturn;
                    objJsonResult.data = null;
                    oCN.RollBack();
                    return objJsonResult;
                }
                //==============================================================================================
                oCN.Commit();//提交事务
                objJsonResult.code = "0";
                objJsonResult.count = 1;
@@ -831,6 +1171,232 @@
                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;
            }
        }
        #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]["产品代码"].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]["物料代码"].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]["计量单位代码"].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]["芯体物料代码"].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 ç‰©æ–™ä»£ç ='" + 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["工序代码"].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(string HOrgID)
        {
            try
            {
                DataSet oDs = new DataSet();
                //==========
                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)
            {
@@ -843,16 +1409,16 @@
        }
        #endregion
        #region ç”Ÿäº§ä»»åŠ¡å•èŽ·å–è½¦é—´
        [Route("Sc_ICMOBill/GetHDeptList")]
        #region ç”Ÿäº§ä»»åŠ¡å•èŽ·å–å·¥ä½œä¸­å¿ƒ
        [Route("Sc_ICMOBill/GetHWorkCenterList")]
        [HttpGet]
        public object GetHDeptList()
        public object GetHWorkCenterList()
        {
            try
            {
                DataSet oDs = new DataSet();
                //==========
                oDs = oCN.RunProcReturn("select HItemID,HName from Gy_Department", "Gy_Department");
                oDs = oCN.RunProcReturn("select HItemID,HName from Gy_WorkCenter", "Gy_WorkCenter");
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "获取成功!";
@@ -1652,5 +2218,129 @@
        }
        #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!HInterID不能为空";
                    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));//获取到DataColumn列对象的列名
                    }
                    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
        #region ç”Ÿäº§è®¢å• æ ¹æ®ä¸»å†…码与子内码获取生产订单数据
        [Route("Sc_ICMOBill/loadSc_ICMOBill_Push")]
        [HttpGet]
        public object loadSc_ICMOBill_Push(long HInterID, long HSubID)
        {
            try
            {
                ds = oCN.RunProcReturn("select * from h_v_IF_ICMOBillList where hmainid =" + HInterID + " and hsubid = " + HSubID, "h_v_IF_ICMOBillList");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "未查询到源单信息!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "Sucess!";
                    objJsonResult.data = ds.Tables[0];
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
    }
}