王 垚
2022-12-07 ee9f4215d0750a15031bfb89f0f347dadc8c1b70
WebAPI/Controllers/POStockInBillController.cs
@@ -51,6 +51,7 @@
        public ClsGy_BarCodeBill_WMS_Model_View oView = new ClsGy_BarCodeBill_WMS_Model_View();
        public ClsKF_PonderationBillMain_Temp model = new ClsKF_PonderationBillMain_Temp();
        public ClsKf_ICStockBill_WMS oBar = new Model.ClsKf_ICStockBill_WMS();
        Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
        public double sRelQty = 0;
        SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
        // private DataBaseServices objDataBaseServices = new DataBaseServices();
@@ -81,6 +82,7 @@
        {
            try
            {
                var sJXCode = POStockInBillController.JX_Json(sCode, sInterID, HBillType, HOWNERID, HBillNo, sMaker);
                //if (sRedBlue == true)
                //{
                //    HBillType = "1239";
@@ -89,7 +91,8 @@
                WebS.WebService1 oWebs = new WebS.WebService1();
                WebS.ClsKf_ICStockBill_WMS WebSoBar = new WebS.ClsKf_ICStockBill_WMS();
                string sExpressNumber = "";
                WebSoBar = oWebs.get_CheckTypeByBarCode_All(sCode, sInterID, HBillType, sBillNo, sMaker, WhID, SPID, sQty, sRedBlue, SourceFlag, sSourceBillNo, sSourceType, HOWNERID, sExpressNumber, ref DBUtility.ClsPub.sErrInfo);
                WebSoBar = oWebs.get_CheckTypeByBarCode_All(sJXCode, sInterID, HBillType, sBillNo, sMaker, WhID, SPID, sQty, sRedBlue, SourceFlag, sSourceBillNo, sSourceType, HOWNERID, sExpressNumber, ref DBUtility.ClsPub.sErrInfo);
                //WebSoBar = oWebs.get_ba(sCode, sInterID, HBillType, sBillNo, sMaker, WhID, SPID, sQty, sRedBlue, SourceFlag, sSourceBillNo, sSourceType, HOWNERID, sExpressNumber, ref DBUtility.ClsPub.sErrInfo);
                if (WebSoBar == null)
                {
                    objJsonResult.code = "0";
@@ -167,6 +170,700 @@
            }
        }
        [Route("kf_PoStockInBill/JX_Json")]
        [HttpGet]
        public static string JX_Json(string sBarCodeNew, Int64 hinterid, string HBillType,Int64 HOrgID,string HBillNo,string HMaker)
        {
            try
            {
                //1.判断系统参数是否安瑞  不是安瑞 直接跳掉
                //如果是安瑞  走下面
                //解析条码
                //如果在条码档案里面   不处理  没有的话 存入条码档案
                //根据解析的物料 +  批次  判断 条码临时表  记录是否存在  没有的话  进行扫源单的动作
                //加了  生产日期  有效期至   保质期标志
                Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
                //if (oSystemParameter.omodel.WMS_CampanyName == "安瑞")
                //{
                string HTM = "";
                //采购入库
                if (HBillType == "1201")
                {
                    string[] sArray = sBarCodeNew.Split('@');
                    string HMaterNumber = "";
                    HMaterNumber = sArray[0];
                    Int64 HQty = 0;
                    HQty = ClsPub.isInt(sArray[4]);
                    string HBarchNo = "";
                    HBarchNo = sArray[6];
                    DateTime HSCRQ = ClsPub.isDate(sArray[3]);
                    DateTime HYXQZ = ClsPub.isDate(sArray[5]);
                    //采购订单号
                    string HPOOrderBillNo = "";
                    HPOOrderBillNo = ClsPub.isStrNull(sArray[8]);
                    Int64 HMaterID = 0;
                    SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
                    DataSet Dss;
                    Dss = oCn.RunProcReturn(" select HNumber from h_v_CLD_ORGANIZATIONSList where HItemID= " + HOrgID, "h_v_CLD_ORGANIZATIONSList");
                    string HOrgNumber = Pub_Class.ClsPub.isStrNull(Dss.Tables[0].Rows[0]["HNumber"]);
                    DataSet Dss1;
                    Dss1 = oCn.RunProcReturn(" select HItemID,HName,HModel,HUnitID from Gy_Material where HNumber= '" + HMaterNumber + "' and  huseorgid = " + HOrgID, "Gy_Material");
                    HMaterID = Pub_Class.ClsPub.isLong(Dss1.Tables[0].Rows[0]["HItemID"]);
                    string HMaterName = Pub_Class.ClsPub.isStrNull(Dss1.Tables[0].Rows[0]["HName"]);
                    string HMaterModel = Pub_Class.ClsPub.isStrNull(Dss1.Tables[0].Rows[0]["HModel"]);
                    Int64 HUnitID = Pub_Class.ClsPub.isInt(Dss1.Tables[0].Rows[0]["HUnitID"]);
                    HTM = HOrgNumber + HMaterID + HBarchNo;
                    //如果条码档案不存在  进行存入条码档案的动作
                    //根据物料 + 批次  +   采购订单号 找到对应的收料通知单号
                    DataSet Dss2;
                    Dss2 = oCn.RunProcReturn(" select fid,FMATERIALID,FENTRYID,FBILLNO from h_v_RECEIVEQuery where FSRCBILLNO= '" + HPOOrderBillNo + "' and  FMATERIALID = " + HMaterID, "h_v_RECEIVEQuery");
                    HMaterID = Pub_Class.ClsPub.isLong(Dss2.Tables[0].Rows[0]["FMATERIALID"]);
                    Int64 HSourceInterID = Pub_Class.ClsPub.isLong(Dss2.Tables[0].Rows[0]["fid"]);
                    Int64 HSourceEntryID = Pub_Class.ClsPub.isLong(Dss2.Tables[0].Rows[0]["FENTRYID"]);
                    string HSourceBillNo = Pub_Class.ClsPub.isStrNull(Dss2.Tables[0].Rows[0]["FBILLNO"]);
                    //判断条码档案是否存在该条码
                    //如果存在 再判断扫码临时表是否存在该条码
                    //如果不存在  进行扫源单的方法
                    DataSet Dss5;
                    Dss5 = oCn.RunProcReturn(" select * from Gy_BarCodeBill where HBarCode= '" + HTM + "'", "Gy_BarCodeBill");
                    if (Dss5.Tables[0].Rows.Count > 0)
                    {
                        DataSet Dss6;
                        Dss6 = oCn.RunProcReturn(" select * from KF_PonderationBillMain_Temp where HBarCode= '" + HTM + "' and HInterID = " + hinterid.ToString() + " and HBillType = '" + HBillType + "' and hsourcebillno = '" + HSourceBillNo + "' ", "KF_PonderationBillMain_Temp");
                        if (Dss6.Tables[0].Rows.Count > 0)
                        {
                        }
                        else
                        {
                            POStockInBillController POStockInBill = new POStockInBillController();
                            POStockInBill.set_SavePonderationBillMain_Temp_Source_Fast_Json("1103", HSourceBillNo, hinterid, HBillNo);
                        }
                    }
                    else
                    {
                        string ModName = "85";
                        var HInterID = DBUtility.ClsPub.CreateBillID_Prod(ModName, ref DBUtility.ClsPub.sExeReturnInfo);
                        Int64 HSupID = 0;
                        oCn.RunProc("insert into Gy_BarCodeBill (HBarCode,HBarCodeType,HMaterID,HUnitID,HQty" +
                                           ",HBatchNo,HSupID,HGroupID,HMaker,HMakeDate,HPrintQty,HinitQty" +
                                           ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HEndQty " +
                                           ",HBarcodeQtys,HBarcodeNo,HDeptID,HWhID,HSPID,HRemark " +
                                           ",HCusID,HCusType,HEndDate,HProduceDate,HExpiryDate,HWorkLineName,HBarCodeDate " +
                                           ",HSTOCKORGID,HOWNERID,HSeOrderBillNo,HInterID,HEntryID " +
                                           ",HGiveAwayFlag,HSeOrderSEQ,HInitSourceEntryID " +
                                           ",HMaterName,HMaterModel,HPinfan,HAuxPropID,HMTONo,HInnerBillNo,HExpirationDateFlag " +
                                           ") values ("
                                           + "'" + HTM + "','批次条码'," + HMaterID.ToString() + "," + HUnitID.ToString() + "," + HQty.ToString()
                                           + ",'" + HBarchNo + "'," + HSupID.ToString() + ",0,'" + ClsPub.CurUserName + "',getdate(),0," + HQty.ToString()
                                           + ", " + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + ",'" + HSourceBillNo.ToString() + "','1103',0"
                                           + ", 0,'',0,0,0,''"
                                           + ",0,'','','" + HSCRQ.ToShortDateString() + "','" + HYXQZ.ToShortDateString() + "','',getdate()"
                                           + ", " + HOrgID.ToString() + "," + HOrgID.ToString() + ",''," + HInterID.ToString() + ",1"
                                           + ",0,0,0"
                                           + ",'" + HMaterName + "','" + HMaterModel + "','',0,'','',1)");
                        DataSet Dss7;
                        Dss7 = oCn.RunProcReturn(" select * from KF_PonderationBillMain_Temp where HBarCode= '" + HTM + "' and HInterID = " + hinterid.ToString() + " and HBillType = '" + HBillType + "' and hsourcebillno = '" + HSourceBillNo + "' ", "KF_PonderationBillMain_Temp");
                        if (Dss7.Tables[0].Rows.Count > 0)
                        {
                        }
                        else
                        {
                            POStockInBillController POStockInBill = new POStockInBillController();
                            POStockInBill.set_SavePonderationBillMain_Temp_Source_Fast_Json("1103", HSourceBillNo, hinterid, HBillNo);
                        }
                    }
                }
                //产品入库
                if(HBillType == "1202")
                {
                    string HMaterNumber = "";
                    HMaterNumber = sBarCodeNew.Substring(0, 10);
                    string HSCRQ = "";
                    HSCRQ = "20" + sBarCodeNew.Substring(10, 6);
                    Int64 Year =  ClsPub.isInt(HSCRQ.Substring(0, 4));
                    Int64 Month = ClsPub.isInt(HSCRQ.Substring(4, 2));
                    Int64 Day = ClsPub.isInt(HSCRQ.Substring(6, 2));
                    string HBatchNo = "";
                    HBatchNo = sBarCodeNew.Substring(16, 11);
                    SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                    DataSet ds;
                    Int64 HMaterID = 0;
                    DataSet Dss1;
                    Dss1 = oCN.RunProcReturn(" select HItemID,HName,HModel,HUnitID from Gy_Material where HNumber= '" + HMaterNumber + "' and  huseorgid = " + HOrgID, "Gy_Material");
                    HMaterID = Pub_Class.ClsPub.isLong(Dss1.Tables[0].Rows[0]["HItemID"]);
                    string HMaterName = Pub_Class.ClsPub.isStrNull(Dss1.Tables[0].Rows[0]["HName"]);
                    string HMaterModel = Pub_Class.ClsPub.isStrNull(Dss1.Tables[0].Rows[0]["HModel"]);
                    Int64 HUnitID = Pub_Class.ClsPub.isInt(Dss1.Tables[0].Rows[0]["HUnitID"]);
                    ds = oCN.RunProcReturn("select * from h_v_SCStockInCheckBill_Json where  HYear =" + Year + " and HMonth = " + Month + " and HDay = " + Day + " and HMaterID = " + HMaterID.ToString() + "and 批次 = '" + HBatchNo.ToString() + "'", "h_v_SCStockInCheckBill_Json");
                    Int64 HSourceInterID = Pub_Class.ClsPub.isLong(ds.Tables[0].Rows[0]["HSourceInterID"]);
                    Int64 HSourceEntryID = Pub_Class.ClsPub.isLong(ds.Tables[0].Rows[0]["HSourceEntryID"]);
                    string HSourceBillNo = Pub_Class.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBillNo"]);
                    DataSet Dss;
                    Dss = oCN.RunProcReturn(" select HNumber from h_v_CLD_ORGANIZATIONSList where HItemID= " + HOrgID, "h_v_CLD_ORGANIZATIONSList");
                    string HOrgNumber = Pub_Class.ClsPub.isStrNull(Dss.Tables[0].Rows[0]["HNumber"]);
                    HTM = HOrgNumber + HMaterID + HBatchNo;
                    DateTime HSCRQ1 = ClsPub.isDate(Year + "-" + Month + "-" + Day);
                    string  HYXQZ = "20" + sBarCodeNew.Substring(27, 6);
                    Int64 Year1 = ClsPub.isInt(HYXQZ.Substring(0, 4));
                    Int64 Month1 = ClsPub.isInt(HYXQZ.Substring(4, 2));
                    Int64 Day1 = ClsPub.isInt(HYXQZ.Substring(6, 2));
                    DateTime HYXQZ1 = ClsPub.isDate(Year1 + "-" + Month1 + "-" + Day1);
                    Int64 HQty = 0;
                    HQty = ClsPub.isInt(sBarCodeNew.Substring(33,3));
                    DataSet Dss5;
                    Dss5 = oCN.RunProcReturn(" select * from Gy_BarCodeBill where HBarCode= '" + HTM + "'", "Gy_BarCodeBill");
                    if (Dss5.Tables[0].Rows.Count > 0)
                    {
                        DataSet Dss6;
                        Dss6 = oCN.RunProcReturn(" select * from KF_PonderationBillMain_Temp where HBarCode= '" + HTM + "' and HInterID = " + hinterid.ToString() + " and HBillType = '" + HBillType + "' and hsourcebillno = '" + HSourceBillNo + "' ", "KF_PonderationBillMain_Temp");
                        if (Dss6.Tables[0].Rows.Count > 0)
                        {
                        }
                        else
                        {
                            WEBSController WEBS = new WEBSController();
                            WEBS.get_SourceBarCode_ProductIn_Json(hinterid, HBillNo, HBillType, HSourceBillNo, "3714", HMaker,HOrgID);
                        }
                    }
                    else
                    {
                        string ModName = "85";
                        var HInterID = DBUtility.ClsPub.CreateBillID_Prod(ModName, ref DBUtility.ClsPub.sExeReturnInfo);
                        Int64 HSupID = 0;
                        oCN.RunProc("insert into Gy_BarCodeBill (HBarCode,HBarCodeType,HMaterID,HUnitID,HQty" +
                                           ",HBatchNo,HSupID,HGroupID,HMaker,HMakeDate,HPrintQty,HinitQty" +
                                           ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HEndQty " +
                                           ",HBarcodeQtys,HBarcodeNo,HDeptID,HWhID,HSPID,HRemark " +
                                           ",HCusID,HCusType,HEndDate,HProduceDate,HExpiryDate,HWorkLineName,HBarCodeDate " +
                                           ",HSTOCKORGID,HOWNERID,HSeOrderBillNo,HInterID,HEntryID " +
                                           ",HGiveAwayFlag,HSeOrderSEQ,HInitSourceEntryID " +
                                           ",HMaterName,HMaterModel,HPinfan,HAuxPropID,HMTONo,HInnerBillNo,HExpirationDateFlag " +
                                           ") values ("
                                           + "'" + HTM + "','批次条码'," + HMaterID.ToString() + "," + HUnitID.ToString() + "," + HQty.ToString()
                                           + ",'" + HBatchNo + "'," + HSupID.ToString() + ",0,'" + ClsPub.CurUserName + "',getdate(),0," + HQty.ToString()
                                           + ", " + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + ",'" + HSourceBillNo.ToString() + "','3714',0"
                                           + ", 0,'',0,0,0,''"
                                           + ",0,'','','" + HSCRQ1.ToShortDateString() + "','" + HYXQZ1.ToShortDateString() + "','',getdate()"
                                           + ", " + HOrgID.ToString() + "," + HOrgID.ToString() + ",''," + HInterID.ToString() + ",1"
                                           + ",0,0,0"
                                           + ",'" + HMaterName + "','" + HMaterModel + "','',0,'','',1)");
                        DataSet Dss7;
                        Dss7 = oCN.RunProcReturn(" select * from KF_PonderationBillMain_Temp where HBarCode= '" + HTM + "' and HInterID = " + hinterid.ToString() + " and HBillType = '" + HBillType + "' and hsourcebillno = '" + HSourceBillNo + "' ", "KF_PonderationBillMain_Temp");
                        if (Dss7.Tables[0].Rows.Count > 0)
                        {
                        }
                        else
                        {
                            WEBSController WEBS = new WEBSController();
                            WEBS.get_SourceBarCode_ProductIn_Json(hinterid, HBillNo, HBillType, HSourceBillNo, "3714", HMaker, HOrgID);
                        }
                    }
                }
                //生产退料
                if (HBillType == "1244")
                {
                    string HMaterNumber = "";
                    HMaterNumber = sBarCodeNew.Substring(0, 10);
                    string HSCRQ = "";
                    HSCRQ = "20" + sBarCodeNew.Substring(10, 6);
                    Int64 Year = ClsPub.isInt(HSCRQ.Substring(0, 4));
                    Int64 Month = ClsPub.isInt(HSCRQ.Substring(4, 2));
                    Int64 Day = ClsPub.isInt(HSCRQ.Substring(6, 2));
                    string HBatchNo = "";
                    HBatchNo = sBarCodeNew.Substring(16, 11);
                    SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                    Int64 HMaterID = 0;
                    DataSet Dss1;
                    Dss1 = oCN.RunProcReturn(" select HItemID,HName,HModel,HUnitID from Gy_Material where HNumber= '" + HMaterNumber + "' and  huseorgid = " + HOrgID, "Gy_Material");
                    HMaterID = Pub_Class.ClsPub.isLong(Dss1.Tables[0].Rows[0]["HItemID"]);
                    string HMaterName = Pub_Class.ClsPub.isStrNull(Dss1.Tables[0].Rows[0]["HName"]);
                    string HMaterModel = Pub_Class.ClsPub.isStrNull(Dss1.Tables[0].Rows[0]["HModel"]);
                    Int64 HUnitID = Pub_Class.ClsPub.isInt(Dss1.Tables[0].Rows[0]["HUnitID"]);
                    DataSet Dss;
                    Dss = oCN.RunProcReturn(" select HNumber from h_v_CLD_ORGANIZATIONSList where HItemID= " + HOrgID, "h_v_CLD_ORGANIZATIONSList");
                    string HOrgNumber = Pub_Class.ClsPub.isStrNull(Dss.Tables[0].Rows[0]["HNumber"]);
                    HTM = HOrgNumber + HMaterID + HBatchNo;
                    DateTime HSCRQ1 = ClsPub.isDate(Year + "-" + Month + "-" + Day);
                    string HYXQZ = "20" + sBarCodeNew.Substring(27, 6);
                    Int64 Year1 = ClsPub.isInt(HYXQZ.Substring(0, 4));
                    Int64 Month1 = ClsPub.isInt(HYXQZ.Substring(4, 2));
                    Int64 Day1 = ClsPub.isInt(HYXQZ.Substring(6, 2));
                    DateTime HYXQZ1 = ClsPub.isDate(Year1 + "-" + Month1 + "-" + Day1);
                    Int64 HQty = 0;
                    HQty = ClsPub.isInt(sBarCodeNew.Substring(33, 3));
                    DataSet Dss5;
                    Dss5 = oCN.RunProcReturn(" select * from Gy_BarCodeBill where HBarCode= '" + HTM + "'", "Gy_BarCodeBill");
                    if (Dss5.Tables[0].Rows.Count > 0)
                    {
                    }
                    else
                    {
                        string ModName = "85";
                        var HInterID = DBUtility.ClsPub.CreateBillID_Prod(ModName, ref DBUtility.ClsPub.sExeReturnInfo);
                        Int64 HSupID = 0;
                        oCN.RunProc("insert into Gy_BarCodeBill (HBarCode,HBarCodeType,HMaterID,HUnitID,HQty" +
                                           ",HBatchNo,HSupID,HGroupID,HMaker,HMakeDate,HPrintQty,HinitQty" +
                                           ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HEndQty " +
                                           ",HBarcodeQtys,HBarcodeNo,HDeptID,HWhID,HSPID,HRemark " +
                                           ",HCusID,HCusType,HEndDate,HProduceDate,HExpiryDate,HWorkLineName,HBarCodeDate " +
                                           ",HSTOCKORGID,HOWNERID,HSeOrderBillNo,HInterID,HEntryID " +
                                           ",HGiveAwayFlag,HSeOrderSEQ,HInitSourceEntryID " +
                                           ",HMaterName,HMaterModel,HPinfan,HAuxPropID,HMTONo,HInnerBillNo,HExpirationDateFlag " +
                                           ") values ("
                                           + "'" + HTM + "','批次条码'," + HMaterID.ToString() + "," + HUnitID.ToString() + "," + HQty.ToString()
                                           + ",'" + HBatchNo + "'," + HSupID.ToString() + ",0,'" + ClsPub.CurUserName + "',getdate(),0," + HQty.ToString()
                                           + ", 0,0,'','',0"
                                           + ", 0,'',0,0,0,''"
                                           + ",0,'','','" + HSCRQ1.ToShortDateString() + "','" + HYXQZ1.ToShortDateString() + "','',getdate()"
                                           + ", " + HOrgID.ToString() + "," + HOrgID.ToString() + ",''," + HInterID.ToString() + ",1"
                                           + ",0,0,0"
                                           + ",'" + HMaterName + "','" + HMaterModel + "','',0,'','',1)");
                    }
                }
                //调拨单
                if (HBillType == "1207")
                {
                    string HMaterNumber = "";
                    HMaterNumber = sBarCodeNew.Substring(0, 10);
                    string HSCRQ = "";
                    HSCRQ = "20" + sBarCodeNew.Substring(10, 6);
                    Int64 Year = ClsPub.isInt(HSCRQ.Substring(0, 4));
                    Int64 Month = ClsPub.isInt(HSCRQ.Substring(4, 2));
                    Int64 Day = ClsPub.isInt(HSCRQ.Substring(6, 2));
                    string HBatchNo = "";
                    HBatchNo = sBarCodeNew.Substring(16, 11);
                    SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                    Int64 HMaterID = 0;
                    DataSet Dss1;
                    Dss1 = oCN.RunProcReturn(" select HItemID,HName,HModel,HUnitID from Gy_Material where HNumber= '" + HMaterNumber + "' and  huseorgid = " + HOrgID, "Gy_Material");
                    HMaterID = Pub_Class.ClsPub.isLong(Dss1.Tables[0].Rows[0]["HItemID"]);
                    string HMaterName = Pub_Class.ClsPub.isStrNull(Dss1.Tables[0].Rows[0]["HName"]);
                    string HMaterModel = Pub_Class.ClsPub.isStrNull(Dss1.Tables[0].Rows[0]["HModel"]);
                    Int64 HUnitID = Pub_Class.ClsPub.isInt(Dss1.Tables[0].Rows[0]["HUnitID"]);
                    DataSet Dss;
                    Dss = oCN.RunProcReturn(" select HNumber from h_v_CLD_ORGANIZATIONSList where HItemID= " + HOrgID, "h_v_CLD_ORGANIZATIONSList");
                    string HOrgNumber = Pub_Class.ClsPub.isStrNull(Dss.Tables[0].Rows[0]["HNumber"]);
                    HTM = HOrgNumber + HMaterID + HBatchNo;
                    DateTime HSCRQ1 = ClsPub.isDate(Year + "-" + Month + "-" + Day);
                    string HYXQZ = "20" + sBarCodeNew.Substring(27, 6);
                    Int64 Year1 = ClsPub.isInt(HYXQZ.Substring(0, 4));
                    Int64 Month1 = ClsPub.isInt(HYXQZ.Substring(4, 2));
                    Int64 Day1 = ClsPub.isInt(HYXQZ.Substring(6, 2));
                    DateTime HYXQZ1 = ClsPub.isDate(Year1 + "-" + Month1 + "-" + Day1);
                    Int64 HQty = 0;
                    HQty = ClsPub.isInt(sBarCodeNew.Substring(33, 3));
                    DataSet Dss5;
                    Dss5 = oCN.RunProcReturn(" select * from Gy_BarCodeBill where HBarCode= '" + HTM + "'", "Gy_BarCodeBill");
                    if (Dss5.Tables[0].Rows.Count > 0)
                    {
                    }
                    else
                    {
                        string ModName = "85";
                        var HInterID = DBUtility.ClsPub.CreateBillID_Prod(ModName, ref DBUtility.ClsPub.sExeReturnInfo);
                        Int64 HSupID = 0;
                        oCN.RunProc("insert into Gy_BarCodeBill (HBarCode,HBarCodeType,HMaterID,HUnitID,HQty" +
                                           ",HBatchNo,HSupID,HGroupID,HMaker,HMakeDate,HPrintQty,HinitQty" +
                                           ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HEndQty " +
                                           ",HBarcodeQtys,HBarcodeNo,HDeptID,HWhID,HSPID,HRemark " +
                                           ",HCusID,HCusType,HEndDate,HProduceDate,HExpiryDate,HWorkLineName,HBarCodeDate " +
                                           ",HSTOCKORGID,HOWNERID,HSeOrderBillNo,HInterID,HEntryID " +
                                           ",HGiveAwayFlag,HSeOrderSEQ,HInitSourceEntryID " +
                                           ",HMaterName,HMaterModel,HPinfan,HAuxPropID,HMTONo,HInnerBillNo,HExpirationDateFlag " +
                                           ") values ("
                                           + "'" + HTM + "','批次条码'," + HMaterID.ToString() + "," + HUnitID.ToString() + "," + HQty.ToString()
                                           + ",'" + HBatchNo + "'," + HSupID.ToString() + ",0,'" + ClsPub.CurUserName + "',getdate(),0," + HQty.ToString()
                                           + ", 0,0,'','',0"
                                           + ", 0,'',0,0,0,''"
                                           + ",0,'','','" + HSCRQ1.ToShortDateString() + "','" + HYXQZ1.ToShortDateString() + "','',getdate()"
                                           + ", " + HOrgID.ToString() + "," + HOrgID.ToString() + ",''," + HInterID.ToString() + ",1"
                                           + ",0,0,0"
                                           + ",'" + HMaterName + "','" + HMaterModel + "','',0,'','',1)");
                    }
                }
                //其他出库单
                if (HBillType == "1206")
                {
                    string HMaterNumber = "";
                    HMaterNumber = sBarCodeNew.Substring(0, 10);
                    string HSCRQ = "";
                    HSCRQ = "20" + sBarCodeNew.Substring(10, 6);
                    Int64 Year = ClsPub.isInt(HSCRQ.Substring(0, 4));
                    Int64 Month = ClsPub.isInt(HSCRQ.Substring(4, 2));
                    Int64 Day = ClsPub.isInt(HSCRQ.Substring(6, 2));
                    string HBatchNo = "";
                    HBatchNo = sBarCodeNew.Substring(16, 11);
                    SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                    Int64 HMaterID = 0;
                    DataSet Dss1;
                    Dss1 = oCN.RunProcReturn(" select HItemID,HName,HModel,HUnitID from Gy_Material where HNumber= '" + HMaterNumber + "' and  huseorgid = " + HOrgID, "Gy_Material");
                    HMaterID = Pub_Class.ClsPub.isLong(Dss1.Tables[0].Rows[0]["HItemID"]);
                    string HMaterName = Pub_Class.ClsPub.isStrNull(Dss1.Tables[0].Rows[0]["HName"]);
                    string HMaterModel = Pub_Class.ClsPub.isStrNull(Dss1.Tables[0].Rows[0]["HModel"]);
                    Int64 HUnitID = Pub_Class.ClsPub.isInt(Dss1.Tables[0].Rows[0]["HUnitID"]);
                    DataSet Dss;
                    Dss = oCN.RunProcReturn(" select HNumber from h_v_CLD_ORGANIZATIONSList where HItemID= " + HOrgID, "h_v_CLD_ORGANIZATIONSList");
                    string HOrgNumber = Pub_Class.ClsPub.isStrNull(Dss.Tables[0].Rows[0]["HNumber"]);
                    HTM = HOrgNumber + HMaterID + HBatchNo;
                    DateTime HSCRQ1 = ClsPub.isDate(Year + "-" + Month + "-" + Day);
                    string HYXQZ = "20" + sBarCodeNew.Substring(27, 6);
                    Int64 Year1 = ClsPub.isInt(HYXQZ.Substring(0, 4));
                    Int64 Month1 = ClsPub.isInt(HYXQZ.Substring(4, 2));
                    Int64 Day1 = ClsPub.isInt(HYXQZ.Substring(6, 2));
                    DateTime HYXQZ1 = ClsPub.isDate(Year1 + "-" + Month1 + "-" + Day1);
                    Int64 HQty = 0;
                    HQty = ClsPub.isInt(sBarCodeNew.Substring(33, 3));
                    DataSet Dss5;
                    Dss5 = oCN.RunProcReturn(" select * from Gy_BarCodeBill where HBarCode= '" + HTM + "'", "Gy_BarCodeBill");
                    if (Dss5.Tables[0].Rows.Count > 0)
                    {
                    }
                    else
                    {
                        string ModName = "85";
                        var HInterID = DBUtility.ClsPub.CreateBillID_Prod(ModName, ref DBUtility.ClsPub.sExeReturnInfo);
                        Int64 HSupID = 0;
                        oCN.RunProc("insert into Gy_BarCodeBill (HBarCode,HBarCodeType,HMaterID,HUnitID,HQty" +
                                           ",HBatchNo,HSupID,HGroupID,HMaker,HMakeDate,HPrintQty,HinitQty" +
                                           ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HEndQty " +
                                           ",HBarcodeQtys,HBarcodeNo,HDeptID,HWhID,HSPID,HRemark " +
                                           ",HCusID,HCusType,HEndDate,HProduceDate,HExpiryDate,HWorkLineName,HBarCodeDate " +
                                           ",HSTOCKORGID,HOWNERID,HSeOrderBillNo,HInterID,HEntryID " +
                                           ",HGiveAwayFlag,HSeOrderSEQ,HInitSourceEntryID " +
                                           ",HMaterName,HMaterModel,HPinfan,HAuxPropID,HMTONo,HInnerBillNo,HExpirationDateFlag " +
                                           ") values ("
                                           + "'" + HTM + "','批次条码'," + HMaterID.ToString() + "," + HUnitID.ToString() + "," + HQty.ToString()
                                           + ",'" + HBatchNo + "'," + HSupID.ToString() + ",0,'" + ClsPub.CurUserName + "',getdate(),0," + HQty.ToString()
                                           + ", 0,0,'','',0"
                                           + ", 0,'',0,0,0,''"
                                           + ",0,'','','" + HSCRQ1.ToShortDateString() + "','" + HYXQZ1.ToShortDateString() + "','',getdate()"
                                           + ", " + HOrgID.ToString() + "," + HOrgID.ToString() + ",''," + HInterID.ToString() + ",1"
                                           + ",0,0,0"
                                           + ",'" + HMaterName + "','" + HMaterModel + "','',0,'','',1)");
                    }
                }
                //领料出库校验
                if (HBillType == "1204")
                {
                    string[] sArray = sBarCodeNew.Split('@');
                    string HMaterNumber = "";
                    HMaterNumber = sArray[0];
                    Int64 HQty = 0;
                    HQty = ClsPub.isInt(sArray[4]);
                    string HBarchNo = "";
                    HBarchNo = sArray[6];
                    DateTime HSCRQ = ClsPub.isDate(sArray[3]);
                    DateTime HYXQZ = ClsPub.isDate(sArray[5]);
                    //采购订单号
                    string HPOOrderBillNo = "";
                    HPOOrderBillNo = ClsPub.isStrNull(sArray[8]);
                    Int64 HMaterID = 0;
                    SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
                    DataSet Dss;
                    Dss = oCn.RunProcReturn(" select HNumber from h_v_CLD_ORGANIZATIONSList where HItemID= " + HOrgID, "h_v_CLD_ORGANIZATIONSList");
                    string HOrgNumber = Pub_Class.ClsPub.isStrNull(Dss.Tables[0].Rows[0]["HNumber"]);
                    DataSet Dss1;
                    Dss1 = oCn.RunProcReturn(" select HItemID,HName,HModel,HUnitID from Gy_Material where HNumber= '" + HMaterNumber + "' and  huseorgid = " + HOrgID, "Gy_Material");
                    HMaterID = Pub_Class.ClsPub.isLong(Dss1.Tables[0].Rows[0]["HItemID"]);
                    string HMaterName = Pub_Class.ClsPub.isStrNull(Dss1.Tables[0].Rows[0]["HName"]);
                    string HMaterModel = Pub_Class.ClsPub.isStrNull(Dss1.Tables[0].Rows[0]["HModel"]);
                    Int64 HUnitID = Pub_Class.ClsPub.isInt(Dss1.Tables[0].Rows[0]["HUnitID"]);
                    HTM = HOrgNumber + HMaterID + HBarchNo;
                    DataSet Dss5;
                    Dss5 = oCn.RunProcReturn(" select * from Gy_BarCodeBill where HBarCode= '" + HTM + "'", "Gy_BarCodeBill");
                    if (Dss5.Tables[0].Rows.Count > 0)
                    {
                    }
                    else
                    {
                        string ModName = "85";
                        var HInterID = DBUtility.ClsPub.CreateBillID_Prod(ModName, ref DBUtility.ClsPub.sExeReturnInfo);
                        Int64 HSupID = 0;
                        oCn.RunProc("insert into Gy_BarCodeBill (HBarCode,HBarCodeType,HMaterID,HUnitID,HQty" +
                                           ",HBatchNo,HSupID,HGroupID,HMaker,HMakeDate,HPrintQty,HinitQty" +
                                           ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HEndQty " +
                                           ",HBarcodeQtys,HBarcodeNo,HDeptID,HWhID,HSPID,HRemark " +
                                           ",HCusID,HCusType,HEndDate,HProduceDate,HExpiryDate,HWorkLineName,HBarCodeDate " +
                                           ",HSTOCKORGID,HOWNERID,HSeOrderBillNo,HInterID,HEntryID " +
                                           ",HGiveAwayFlag,HSeOrderSEQ,HInitSourceEntryID " +
                                           ",HMaterName,HMaterModel,HPinfan,HAuxPropID,HMTONo,HInnerBillNo,HExpirationDateFlag " +
                                           ") values ("
                                           + "'" + HTM + "','批次条码'," + HMaterID.ToString() + "," + HUnitID.ToString() + "," + HQty.ToString()
                                           + ",'" + HBarchNo + "'," + HSupID.ToString() + ",0,'" + ClsPub.CurUserName + "',getdate(),0," + HQty.ToString()
                                           + ", " + 0 + "," + 0 + ",'','',0"
                                           + ", 0,'',0,0,0,''"
                                           + ",0,'','','" + HSCRQ.ToShortDateString() + "','" + HYXQZ.ToShortDateString() + "','',getdate()"
                                           + ", " + HOrgID.ToString() + "," + HOrgID.ToString() + ",''," + HInterID.ToString() + ",1"
                                           + ",0,0,0"
                                           + ",'" + HMaterName + "','" + HMaterModel + "','',0,'','',1)");
                    }
                }
                //生产补料校验
                if (HBillType == "1254")
                {
                    string[] sArray = sBarCodeNew.Split('@');
                    string HMaterNumber = "";
                    HMaterNumber = sArray[0];
                    Int64 HQty = 0;
                    HQty = ClsPub.isInt(sArray[4]);
                    string HBarchNo = "";
                    HBarchNo = sArray[6];
                    DateTime HSCRQ = ClsPub.isDate(sArray[3]);
                    DateTime HYXQZ = ClsPub.isDate(sArray[5]);
                    //采购订单号
                    string HPOOrderBillNo = "";
                    HPOOrderBillNo = ClsPub.isStrNull(sArray[8]);
                    Int64 HMaterID = 0;
                    SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
                    DataSet Dss;
                    Dss = oCn.RunProcReturn(" select HNumber from h_v_CLD_ORGANIZATIONSList where HItemID= " + HOrgID, "h_v_CLD_ORGANIZATIONSList");
                    string HOrgNumber = Pub_Class.ClsPub.isStrNull(Dss.Tables[0].Rows[0]["HNumber"]);
                    DataSet Dss1;
                    Dss1 = oCn.RunProcReturn(" select HItemID,HName,HModel,HUnitID from Gy_Material where HNumber= '" + HMaterNumber + "' and  huseorgid = " + HOrgID, "Gy_Material");
                    HMaterID = Pub_Class.ClsPub.isLong(Dss1.Tables[0].Rows[0]["HItemID"]);
                    string HMaterName = Pub_Class.ClsPub.isStrNull(Dss1.Tables[0].Rows[0]["HName"]);
                    string HMaterModel = Pub_Class.ClsPub.isStrNull(Dss1.Tables[0].Rows[0]["HModel"]);
                    Int64 HUnitID = Pub_Class.ClsPub.isInt(Dss1.Tables[0].Rows[0]["HUnitID"]);
                    HTM = HOrgNumber + HMaterID + HBarchNo;
                    DataSet Dss5;
                    Dss5 = oCn.RunProcReturn(" select * from Gy_BarCodeBill where HBarCode= '" + HTM + "'", "Gy_BarCodeBill");
                    if (Dss5.Tables[0].Rows.Count > 0)
                    {
                    }
                    else
                    {
                        string ModName = "85";
                        var HInterID = DBUtility.ClsPub.CreateBillID_Prod(ModName, ref DBUtility.ClsPub.sExeReturnInfo);
                        Int64 HSupID = 0;
                        oCn.RunProc("insert into Gy_BarCodeBill (HBarCode,HBarCodeType,HMaterID,HUnitID,HQty" +
                                           ",HBatchNo,HSupID,HGroupID,HMaker,HMakeDate,HPrintQty,HinitQty" +
                                           ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HEndQty " +
                                           ",HBarcodeQtys,HBarcodeNo,HDeptID,HWhID,HSPID,HRemark " +
                                           ",HCusID,HCusType,HEndDate,HProduceDate,HExpiryDate,HWorkLineName,HBarCodeDate " +
                                           ",HSTOCKORGID,HOWNERID,HSeOrderBillNo,HInterID,HEntryID " +
                                           ",HGiveAwayFlag,HSeOrderSEQ,HInitSourceEntryID " +
                                           ",HMaterName,HMaterModel,HPinfan,HAuxPropID,HMTONo,HInnerBillNo,HExpirationDateFlag " +
                                           ") values ("
                                           + "'" + HTM + "','批次条码'," + HMaterID.ToString() + "," + HUnitID.ToString() + "," + HQty.ToString()
                                           + ",'" + HBarchNo + "'," + HSupID.ToString() + ",0,'" + ClsPub.CurUserName + "',getdate(),0," + HQty.ToString()
                                           + ", " + 0 + "," + 0 + ",'','',0"
                                           + ", 0,'',0,0,0,''"
                                           + ",0,'','','" + HSCRQ.ToShortDateString() + "','" + HYXQZ.ToShortDateString() + "','',getdate()"
                                           + ", " + HOrgID.ToString() + "," + HOrgID.ToString() + ",''," + HInterID.ToString() + ",1"
                                           + ",0,0,0"
                                           + ",'" + HMaterName + "','" + HMaterModel + "','',0,'','',1)");
                    }
                }
                //销售出库校验
                if (HBillType == "1205")
                {
                    string HMaterNumber = "";
                    HMaterNumber = sBarCodeNew.Substring(0, 10);
                    string HSCRQ = "";
                    HSCRQ = "20" + sBarCodeNew.Substring(10, 6);
                    Int64 Year = ClsPub.isInt(HSCRQ.Substring(0, 4));
                    Int64 Month = ClsPub.isInt(HSCRQ.Substring(4, 2));
                    Int64 Day = ClsPub.isInt(HSCRQ.Substring(6, 2));
                    string HBatchNo = "";
                    HBatchNo = sBarCodeNew.Substring(16, 11);
                    SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                    Int64 HMaterID = 0;
                    DataSet Dss1;
                    Dss1 = oCN.RunProcReturn(" select HItemID,HName,HModel,HUnitID from Gy_Material where HNumber= '" + HMaterNumber + "' and  huseorgid = " + HOrgID, "Gy_Material");
                    HMaterID = Pub_Class.ClsPub.isLong(Dss1.Tables[0].Rows[0]["HItemID"]);
                    string HMaterName = Pub_Class.ClsPub.isStrNull(Dss1.Tables[0].Rows[0]["HName"]);
                    string HMaterModel = Pub_Class.ClsPub.isStrNull(Dss1.Tables[0].Rows[0]["HModel"]);
                    Int64 HUnitID = Pub_Class.ClsPub.isInt(Dss1.Tables[0].Rows[0]["HUnitID"]);
                    DataSet Dss;
                    Dss = oCN.RunProcReturn(" select HNumber from h_v_CLD_ORGANIZATIONSList where HItemID= " + HOrgID, "h_v_CLD_ORGANIZATIONSList");
                    string HOrgNumber = Pub_Class.ClsPub.isStrNull(Dss.Tables[0].Rows[0]["HNumber"]);
                    HTM = HOrgNumber + HMaterID + HBatchNo;
                    DateTime HSCRQ1 = ClsPub.isDate(Year + "-" + Month + "-" + Day);
                    string HYXQZ = "20" + sBarCodeNew.Substring(27, 6);
                    Int64 Year1 = ClsPub.isInt(HYXQZ.Substring(0, 4));
                    Int64 Month1 = ClsPub.isInt(HYXQZ.Substring(4, 2));
                    Int64 Day1 = ClsPub.isInt(HYXQZ.Substring(6, 2));
                    DateTime HYXQZ1 = ClsPub.isDate(Year1 + "-" + Month1 + "-" + Day1);
                    Int64 HQty = 0;
                    HQty = ClsPub.isInt(sBarCodeNew.Substring(33, 3));
                    DataSet Dss5;
                    Dss5 = oCN.RunProcReturn(" select * from Gy_BarCodeBill where HBarCode= '" + HTM + "'", "Gy_BarCodeBill");
                    if (Dss5.Tables[0].Rows.Count > 0)
                    {
                    }
                    else
                    {
                        string ModName = "85";
                        var HInterID = DBUtility.ClsPub.CreateBillID_Prod(ModName, ref DBUtility.ClsPub.sExeReturnInfo);
                        Int64 HSupID = 0;
                        oCN.RunProc("insert into Gy_BarCodeBill (HBarCode,HBarCodeType,HMaterID,HUnitID,HQty" +
                                           ",HBatchNo,HSupID,HGroupID,HMaker,HMakeDate,HPrintQty,HinitQty" +
                                           ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HEndQty " +
                                           ",HBarcodeQtys,HBarcodeNo,HDeptID,HWhID,HSPID,HRemark " +
                                           ",HCusID,HCusType,HEndDate,HProduceDate,HExpiryDate,HWorkLineName,HBarCodeDate " +
                                           ",HSTOCKORGID,HOWNERID,HSeOrderBillNo,HInterID,HEntryID " +
                                           ",HGiveAwayFlag,HSeOrderSEQ,HInitSourceEntryID " +
                                           ",HMaterName,HMaterModel,HPinfan,HAuxPropID,HMTONo,HInnerBillNo,HExpirationDateFlag " +
                                           ") values ("
                                           + "'" + HTM + "','批次条码'," + HMaterID.ToString() + "," + HUnitID.ToString() + "," + HQty.ToString()
                                           + ",'" + HBatchNo + "'," + HSupID.ToString() + ",0,'" + ClsPub.CurUserName + "',getdate(),0," + HQty.ToString()
                                           + ", 0,0,'','',0"
                                           + ", 0,'',0,0,0,''"
                                           + ",0,'','','" + HSCRQ1.ToShortDateString() + "','" + HYXQZ1.ToShortDateString() + "','',getdate()"
                                           + ", " + HOrgID.ToString() + "," + HOrgID.ToString() + ",''," + HInterID.ToString() + ",1"
                                           + ",0,0,0"
                                           + ",'" + HMaterName + "','" + HMaterModel + "','',0,'','',1)");
                    }
                }
                //objJsonResult.code = "0";
                //objJsonResult.count = 1;
                //objJsonResult.Message = DBUtility.ClsPub.sErrInfo;
                //objJsonResult.data = ;
                return HTM;
            }
            catch (Exception e)
            {
                //objJsonResult.code = "0";
                //objJsonResult.count = 1;
                //objJsonResult.Message = e.Message + ";" + e.StackTrace;
                //objJsonResult.data = null;
                return e.Message + ";" + e.StackTrace;
            }
        }
@@ -409,6 +1106,249 @@
                return objJsonResult;
            }
        }
        [Route("Kf_QCStockInCheckBill_Fast/BarCode_Json")]
        [HttpGet]
        public object BarCode_Json(string HBarCode,Int64 HOrgID)
        {
            try
            {
                SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                //string[] sArray = HBarCode.Split('@');
                //string HMaterNumber = "";
                //HMaterNumber = sArray[0];
                ////采购订单号
                //string HPOOrderBillNo = "";
                //HPOOrderBillNo = ClsPub.isStrNull(sArray[8]);
                //Int64 HMaterID = 0;
                //DataSet Dss1;
                //Dss1 = oCn.RunProcReturn(" select HItemID,HName,HModel,HUnitID from Gy_Material where HNumber= '" + HMaterNumber + "' and  huseorgid = " + HOrgID, "Gy_Material");
                //HMaterID = Pub_Class.ClsPub.isLong(Dss1.Tables[0].Rows[0]["HItemID"]);
                ////根据物料 + 批次  +   采购订单号 找到对应的收料通知单号
                //DataSet Dss2;
                //Dss2 = oCn.RunProcReturn(" select fid,FMATERIALID,FENTRYID,FBILLNO from h_v_RECEIVEQuery where FSRCBILLNO= '" + HPOOrderBillNo + "' and  FMATERIALID = " + HMaterID, "h_v_RECEIVEQuery");
                //HMaterID = Pub_Class.ClsPub.isLong(Dss2.Tables[0].Rows[0]["FMATERIALID"]);
                //string HSourceBillNo = Pub_Class.ClsPub.isStrNull(Dss2.Tables[0].Rows[0]["FBILLNO"]);
                string HTM = "";
                string[] sArray = HBarCode.Split('@');
                string HMaterNumber = "";
                HMaterNumber = sArray[0];
                Int64 HQty = 0;
                HQty = ClsPub.isInt(sArray[4]);
                string HBarchNo = "";
                HBarchNo = sArray[6];
                DateTime HSCRQ = ClsPub.isDate(sArray[3]);
                DateTime HYXQZ = ClsPub.isDate(sArray[5]);
                //采购订单号
                string HPOOrderBillNo = "";
                HPOOrderBillNo = ClsPub.isStrNull(sArray[8]);
                Int64 HMaterID = 0;
                SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
                DataSet Dss;
                Dss = oCn.RunProcReturn(" select HNumber from h_v_CLD_ORGANIZATIONSList where HItemID= " + HOrgID, "h_v_CLD_ORGANIZATIONSList");
                string HOrgNumber = Pub_Class.ClsPub.isStrNull(Dss.Tables[0].Rows[0]["HNumber"]);
                DataSet Dss1;
                Dss1 = oCn.RunProcReturn(" select HItemID,HName,HModel,HUnitID from Gy_Material where HNumber= '" + HMaterNumber + "' and  huseorgid = " + HOrgID, "Gy_Material");
                HMaterID = Pub_Class.ClsPub.isLong(Dss1.Tables[0].Rows[0]["HItemID"]);
                string HMaterName = Pub_Class.ClsPub.isStrNull(Dss1.Tables[0].Rows[0]["HName"]);
                string HMaterModel = Pub_Class.ClsPub.isStrNull(Dss1.Tables[0].Rows[0]["HModel"]);
                Int64 HUnitID = Pub_Class.ClsPub.isInt(Dss1.Tables[0].Rows[0]["HUnitID"]);
                HTM = HOrgNumber + HMaterID + HBarchNo;
                //如果条码档案不存在  进行存入条码档案的动作
                //根据物料 + 批次  +   采购订单号 找到对应的收料通知单号
                DataSet Dss2;
                Dss2 = oCn.RunProcReturn(" select fid,FMATERIALID,FENTRYID,FBILLNO from h_v_RECEIVEQuery where FSRCBILLNO= '" + HPOOrderBillNo + "' and  FMATERIALID = " + HMaterID, "h_v_RECEIVEQuery");
                HMaterID = Pub_Class.ClsPub.isLong(Dss2.Tables[0].Rows[0]["FMATERIALID"]);
                Int64 HSourceInterID = Pub_Class.ClsPub.isLong(Dss2.Tables[0].Rows[0]["fid"]);
                Int64 HSourceEntryID = Pub_Class.ClsPub.isLong(Dss2.Tables[0].Rows[0]["FENTRYID"]);
                string HSourceBillNo = Pub_Class.ClsPub.isStrNull(Dss2.Tables[0].Rows[0]["FBILLNO"]);
                //判断条码档案是否存在该条码
                //如果存在 再判断扫码临时表是否存在该条码
                //如果不存在  进行扫源单的方法
                DataSet Dss5;
                Dss5 = oCn.RunProcReturn(" select * from Gy_BarCodeBill where HBarCode= '" + HTM + "'", "Gy_BarCodeBill");
                if (Dss5.Tables[0].Rows.Count > 0)
                {
                    DataSet ds;
                    ds = oCN.RunProcReturn("select * from h_v_QCStockInCheckBill_Json where  HSourceBillNo ='" + HSourceBillNo.ToString() + "'", "h_v_QCStockInCheckBill_Json");
                    if (ds == null || ds.Tables[0].Rows.Count <= 0)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "没有返回任何记录!";
                        objJsonResult.data = null;
                        return objJsonResult;
                        //DBUtility.ClsPub.MessageBeep((int)DBUtility.ClsPub.BeepType.Warning);
                    }
                    else
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "获取信息成功!";
                        objJsonResult.data = ds.Tables[0];
                        return objJsonResult;
                    }
                }
                else
                {
                    string ModName = "85";
                    var HInterID = DBUtility.ClsPub.CreateBillID_Prod(ModName, ref DBUtility.ClsPub.sExeReturnInfo);
                    Int64 HSupID = 0;
                    oCn.RunProc("insert into Gy_BarCodeBill (HBarCode,HBarCodeType,HMaterID,HUnitID,HQty" +
                                       ",HBatchNo,HSupID,HGroupID,HMaker,HMakeDate,HPrintQty,HinitQty" +
                                       ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HEndQty " +
                                       ",HBarcodeQtys,HBarcodeNo,HDeptID,HWhID,HSPID,HRemark " +
                                       ",HCusID,HCusType,HEndDate,HProduceDate,HExpiryDate,HWorkLineName,HBarCodeDate " +
                                       ",HSTOCKORGID,HOWNERID,HSeOrderBillNo,HInterID,HEntryID " +
                                       ",HGiveAwayFlag,HSeOrderSEQ,HInitSourceEntryID " +
                                       ",HMaterName,HMaterModel,HPinfan,HAuxPropID,HMTONo,HInnerBillNo,HExpirationDateFlag " +
                                       ") values ("
                                       + "'" + HTM + "','批次条码'," + HMaterID.ToString() + "," + HUnitID.ToString() + "," + HQty.ToString()
                                       + ",'" + HBarchNo + "'," + HSupID.ToString() + ",0,'" + ClsPub.CurUserName + "',getdate(),0," + HQty.ToString()
                                       + ", " + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + ",'" + HSourceBillNo.ToString() + "','1103',0"
                                       + ", 0,'',0,0,0,''"
                                       + ",0,'','','" + HSCRQ.ToShortDateString() + "','" + HYXQZ.ToShortDateString() + "','',getdate()"
                                       + ", " + HOrgID.ToString() + "," + HOrgID.ToString() + ",''," + HInterID.ToString() + ",1"
                                       + ",0,0,0"
                                       + ",'" + HMaterName + "','" + HMaterModel + "','',0,'','',1)");
                    DataSet ds;
                    ds = oCN.RunProcReturn("select * from h_v_QCStockInCheckBill_Json where  HSourceBillNo ='" + HSourceBillNo.ToString() + "'", "h_v_QCStockInCheckBill_Json");
                    if (ds == null || ds.Tables[0].Rows.Count <= 0)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "没有返回任何记录!";
                        objJsonResult.data = null;
                        return objJsonResult;
                        //DBUtility.ClsPub.MessageBeep((int)DBUtility.ClsPub.BeepType.Warning);
                    }
                    else
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "获取信息成功!";
                        objJsonResult.data = ds.Tables[0];
                        return objJsonResult;
                    }
                }
                //ds = oCN.RunProcReturn("select * from h_v_QCStockInCheckBill_Json where  条码编号 ='" + HBarCode.ToString() + "'", "h_v_QCStockInCheckBill_Json");
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "没有返回任何记录!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        [Route("Kf_SCStockInCheckBill_Fast/BarCode_Json1")]
        [HttpGet]
        public object BarCode_Json1(string HBarCode,Int64 HOrgID)
        {
            try
            {
                //根据拆分的物料ID +  批次 +  生产日期 能找到唯一的工序汇报单
                string HMaterNumber = "";
                HMaterNumber = HBarCode.Substring(0, 10);
                string HSCRQ = "";
                HSCRQ = "20" + HBarCode.Substring(10, 6);
                Int64 Year = ClsPub.isInt(HSCRQ.Substring(0, 4));
                Int64 Month = ClsPub.isInt(HSCRQ.Substring(4, 2));
                Int64 Day = ClsPub.isInt(HSCRQ.Substring(6, 2));
                string HBatchNo = "";
                HBatchNo = HBarCode.Substring(16, 11);
                SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                DataSet ds;
                Int64 HMaterID = 0;
                DataSet Dss1;
                Dss1 = oCN.RunProcReturn(" select HItemID,HName,HModel,HUnitID from Gy_Material where HNumber= '" + HMaterNumber + "' and  huseorgid = " + HOrgID, "Gy_Material");
                HMaterID = Pub_Class.ClsPub.isLong(Dss1.Tables[0].Rows[0]["HItemID"]);
                string HMaterName = Pub_Class.ClsPub.isStrNull(Dss1.Tables[0].Rows[0]["HName"]);
                string HMaterModel = Pub_Class.ClsPub.isStrNull(Dss1.Tables[0].Rows[0]["HModel"]);
                Int64 HUnitID = Pub_Class.ClsPub.isInt(Dss1.Tables[0].Rows[0]["HUnitID"]);
                DateTime HSCRQ1 = ClsPub.isDate(Year + "-" + Month + "-" + Day);
                Int64 HQty = 0;
                HQty = ClsPub.isInt(HBarCode.Substring(33, 3));
                ds = oCN.RunProcReturn("select * from h_v_SCStockInCheckBill_Json where  HYear =" + Year.ToString() + "and HMonth = " + Month.ToString() + "and HDay = " + Day.ToString() + " and HMaterID = " + HMaterID.ToString() + "and 批次 = '" + HBatchNo.ToString() + "'", "h_v_SCStockInCheckBill_Json");
                if (ds == null || ds.Tables[0].Rows.Count <= 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "没有返回任何记录!";
                    objJsonResult.data = null;
                    return objJsonResult;
                    //DBUtility.ClsPub.MessageBeep((int)DBUtility.ClsPub.BeepType.Warning);
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "获取信息成功!";
                    objJsonResult.data = ds.Tables[0];
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "没有返回任何记录!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        /// <summary>
@@ -992,7 +1932,6 @@
        }
        #region 到货确认
        [Route("POStockInBillList/Get_ReciveBill")]
        [HttpGet]
@@ -1002,25 +1941,6 @@
            {
                json result = Get_ReciveBillCheckDate(HBillno);
                return result;
                //SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
                //string sql = $"select * from H_v_SRM_POInStockBillList where 单据号 ='{HBillno}'";
                //ds = oCn.RunProcReturn(sql, "H_v_SRM_POInStockBillList");
                //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)
            {
@@ -1029,372 +1949,6 @@
                objJsonResult.Message = "没有返回任何记录!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        [Route("POStockInBillList/AuditPOInStockBill")]
        [HttpGet]
        public object AuditPOInStockBill(string HInterID, string CurUserName, string HBillNo)
        {
            Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
            json objjson = new json();
            try
            {
                SQLHelper.ClsCNSRM oCn = new SQLHelper.ClsCNSRM();
                //采购订单 生成送货单列表
                if (!String.IsNullOrEmpty(HBillNo))
                    HInterID = GetHinterIDByBillNo(HBillNo, "Aduit").ToString();
                if (HInterID == "0")
                {
                    objjson.code = "0";
                    objjson.count = 0;
                    objjson.Message = "操作失败,请先保存订单";
                    objjson.data = null;
                    return objjson;
                }
                string parameterSql = $"select HValue from Xt_SystemParameter where HKey ='Cg_POInStockBill_ErpAduit'";
                var HValue = oCn.RunProcReturn(parameterSql, "dt").Tables[0].Rows[0][0].ToString();
                string sql = string.Empty;
                if (HValue == "Y")
                {
                    var kdTbaleName = Util.GetConfigKey(AppDomain.CurrentDomain.BaseDirectory + "/Config/kdapi.config", "DataBaseName");
                    string FCusName = oSystemParameter.GetSingleSystemParameter("WMS_CampanyName", ref DBUtility.ClsPub.sExeReturnInfo);
                    DataTable dt = new DataTable();
                    List<string> fidList = new List<string>();
                    if (FCusName == "瑞与祺" || FCusName == "")
                    {
                        sql = string.Format(@"
SELECT T3.FNAME AS FTYPENAME,M.HBILLNO,B.HINTERID,B.HENTRYID,C.FID,C.FENTRYID, D.FBILLNO,B.HQTY,CD.FRECEIVEORGID,CDOO.FNUMBER AS FRECEIVENUMBER
,D.FSUPPLIERID,DS.FNUMBER AS FSUPPLIERNUMBER,D.FPURCHASEORGID,DOO.FNUMBER AS FPURCHASEORGNUMBER,CROO.FNUMBER  AS FSETTLEORGNUMBER,
E.FPRICETIMEPOINT,E.FSETTLECURRID,EC.FNUMBER AS FSETTLECURRNUMBER,C.FMATERIALID,CM.FNUMBER AS FMATERIALNUMBER ,C.FUNITID
,CU.FNUMBER AS FUNITNUMBER,CR.FPRICE,CR.FTAXPRICE,CR.FTAXRATE,D.FPURCHASERID,isnull(T4.FNUMBER,'') AS FPURCHASERNUMBER
FROM CG_POINSTOCKBILLSUB B
JOIN CG_POINSTOCKBILLMAIN M ON B.HINTERID = M.HINTERID
JOIN {0}..T_PUR_POORDERENTRY C ON B.HSOURCEINTERID = C.FID AND B.HSOURCEENTRYID = C.FENTRYID
LEFT JOIN {0}..T_BD_MATERIAL CM ON C.FMATERIALID =CM.FMATERIALID
LEFT JOIN {0}..T_BD_UNIT CU ON C.FUNITID =CU.FUNITID
JOIN {0}..T_PUR_POORDERENTRY_D CD ON    C.FENTRYID = CD.FENTRYID
LEFT JOIN {0}..T_ORG_ORGANIZATIONS CDOO ON CD.FRECEIVEORGID = CDOO.FORGID
JOIN {0}..T_PUR_POORDERENTRY_F CR ON    C.FENTRYID = CR.FENTRYID
LEFT JOIN {0}..T_ORG_ORGANIZATIONS CROO ON CR.FSETTLEORGID = CROO.FORGID
LEFT JOIN {0}..T_PUR_POORDER D ON C.FID =D.FID
LEFT JOIN {0}..T_BAS_BILLTYPE T2 ON D.FBILLTYPEID = T2.FBILLTYPEID
LEFT JOIN {0}..T_BAS_BILLTYPE_L T3 ON T2.FBILLTYPEID = T3.FBILLTYPEID and FLOCALEID=2052
LEFT JOIN  {0}..V_BD_BUYER T4 ON D.FPURCHASERID =T4.FID
LEFT JOIN {0}..T_BD_SUPPLIER DS ON D.FSUPPLIERID = DS.FSUPPLIERID
LEFT JOIN {0}..T_ORG_ORGANIZATIONS DOO ON D.FPURCHASEORGID = DOO.FORGID
JOIN {0}..T_PUR_POORDERFIN E ON C.FID =E.FID
LEFT JOIN {0}..T_BD_CURRENCY EC ON E. FSETTLECURRID =EC.FCURRENCYID
 WHERE b.hinterid in ({1}) and M.HERPInterID = 0
", kdTbaleName, HInterID);
                        //LEFT JOIN  {0}..T_HR_EMPINFO T5 ON D.F_XBKF_BASE1 = T5.FID
                        dt = oCn.RunProcReturn(sql, "sltz").Tables[0];
                        if (dt.Rows.Count > 0)
                        {
                            foreach (DataRow dr in dt.Rows)
                            {
                                if (fidList.Contains(dr["FID"].ToString() + dr["HINTERID"].ToString()))
                                    continue;
                                else
                                    fidList.Add(dr["FID"].ToString() + dr["HINTERID"].ToString());
                                DataRow[] drs = dt.Select("FID = " + dr["FID"].ToString() + " and HINTERID = " + dr["HINTERID"].ToString());
                                JObject model = new JObject();
                                string fTypeName = "SLD01_SYS";//标准采购订单类型
                                string ywTypeName = "CG";//标准业务类型
                                if (dr["FTYPENAME"].ToString().Contains("委外"))
                                {
                                    fTypeName = "SLD03_SYS";
                                    ywTypeName = "WW";
                                }
                                if (dr["FTYPENAME"].ToString().Contains("资产"))
                                {
                                    fTypeName = "SLD04_SYS";
                                    ywTypeName = "ZCCG";
                                }
                                model.Add("FBILLTYPEID", new JObject() { ["Fnumber"] = fTypeName }); //单据类型
                                model.Add("FBusinessType", ywTypeName); //业务类型
                                model.Add("FBILLNO", dr["HBillNo"].ToString()); //单据编号
                                model.Add("FDate", DateTime.Now.ToString("yyyy-MM-dd")); //通知日期
                                model.Add("FStockOrgId", new JObject() { ["Fnumber"] = dr["FRECEIVENUMBER"].ToString() }); // 收料组织
                                model.Add("FPurOrgId", new JObject() { ["Fnumber"] = dr["FPURCHASEORGNUMBER"].ToString() }); //采购组织
                                model.Add("FSupplierId", new JObject() { ["Fnumber"] = dr["FSUPPLIERNUMBER"].ToString() }); //供应商
                                model.Add("FPURCHASERID", new JObject() { ["Fnumber"] = dr["FPURCHASERNUMBER"].ToString() }); //采购员
                                model.Add("FOwnerTypeIdHead", "BD_Supplier");//  货主类型
                                model.Add("FOwnerIdHead", new JObject() { ["Fnumber"] = dr["FSUPPLIERNUMBER"].ToString() });//货主 供应商
                                JArray Fentity = new JArray();
                                foreach (var item in drs)
                                {
                                    JObject FentityModel = new JObject();
                                    FentityModel.Add("FMaterialId", new JObject() { ["Fnumber"] = item["FMATERIALNUMBER"].ToString() }); // 物料编码
                                    FentityModel.Add("FUnitID", new JObject() { ["Fnumber"] = item["FUNITNUMBER"].ToString() }); // 单位
                                    FentityModel.Add("FPreDeliveryDate", DateTime.Now.ToString("yyyy-MM-dd")); //预计到货日期
                                    FentityModel.Add("FPriceUnitId", new JObject() { ["Fnumber"] = item["FUNITNUMBER"].ToString() }); // 计价单位
                                    FentityModel.Add("FStockUnitID", new JObject() { ["Fnumber"] = item["FUNITNUMBER"].ToString() }); //  库存单位
                                    FentityModel.Add("FActReceiveQty", Convert.ToDecimal(item["HQTY"])); // 供应商送货数量(提料计划数量 - 已生成送货单数量)
                                    FentityModel.Add("FOwnerTypeId", "BD_OwnerOrg");//货主类型
                                    FentityModel.Add("FOwnerID", new JObject() { ["Fnumber"] = dr["FPURCHASEORGNUMBER"].ToString() });//货主
                                    FentityModel.Add("FSrcId", item["FID"].ToString());//源单内码
                                    FentityModel.Add("FSRCFORMID", "PUR_PurchaseOrder");//源单类型
                                    FentityModel.Add("FSrcBillNo", item["FBILLNO"].ToString());//源单单号
                                    FentityModel.Add("FSRCENTRYID", item["FENTRYID"].ToString());//源单分录内码
                                    FentityModel.Add("FORDERBILLNO", item["FBILLNO"].ToString());//源单单号
                                    FentityModel.Add("FPOORDERENTRYID", item["FENTRYID"].ToString());//源单分录内码
                                    FentityModel.Add("FSRMENTRYID", item["HENTRYID"].ToString());//SRM hentryid
                                    FentityModel.Add("FPrice", item["FPRICE"].ToString());//单价
                                    FentityModel.Add("FTaxPrice", item["FTAXPRICE"].ToString());//含税单价
                                    FentityModel.Add("FEntryTaxRate", item["FTAXRATE"].ToString());//税率
                                    JArray Fentity2 = new JArray();
                                    JObject FentityModel2 = new JObject();
                                    FentityModel2.Add("FDetailEntity_Link_FRULEID", "PUR_PurchaseOrder-PUR_ReceiveBill");
                                    FentityModel2.Add("FDetailEntity_Link_FSTableName", "t_PUR_POOrderEntry");
                                    FentityModel2.Add("FDetailEntity_Link_FSBillId", item["FID"].ToString());
                                    FentityModel2.Add("FDetailEntity_Link_FSId", item["FEntryID"].ToString());
                                    Fentity2.Add(FentityModel2);
                                    FentityModel.Add("FDetailEntity_Link", Fentity2);
                                    Fentity.Add(FentityModel);
                                }
                                model.Add("FDetailEntity", Fentity); //明细信息
                                JObject _FentityModel = new JObject();
                                _FentityModel.Add("FSettleOrgId", new JObject() { ["Fnumber"] = dr["FSETTLEORGNUMBER"].ToString() }); //  结算组织
                                _FentityModel.Add("FSettleCurrId", new JObject() { ["Fnumber"] = dr["FSETTLECURRNUMBER"].ToString() }); //  结算币别
                                _FentityModel.Add("FPricePoint", 0); //  定价时点
                                model.Add("FinanceEntity ", _FentityModel);//财务信息
                                JObject jsonRoot = new JObject()
                                {
                                    ["Creator"] = "",
                                    ["NeedUpDateFields"] = new JArray(),
                                    ["NeedReturnFields"] = new JArray(),
                                    ["IsDeleteEntry"] = "false",
                                    ["SubSystemId"] = "",
                                    ["IsVerifyBaseDataField"] = "false",
                                    ["Model"] = model
                                };
                                var loginRet = InvokeHelper.Login();
                                var isSuccess = JObject.Parse(loginRet)["LoginResultType"].Value<int>();
                                if (isSuccess <= 0)
                                {
                                    objjson.code = "0";
                                    objjson.count = 0;
                                    objjson.Message = loginRet;
                                    objjson.data = null;
                                    return objjson;
                                }
                                //LogService.Write("jsonRoot:" + jsonRoot.ToString());
                                var result = InvokeHelper.Save("PUR_ReceiveBill", jsonRoot.ToString());
                                //LogService.Write(result);
                                if (JObject.Parse(result)["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper() == "TRUE")
                                {
                                    //更新送货单 主表 ERP单据号 以及 ERP主内玛
                                    string FBillNo = JObject.Parse(result)["Result"]["Number"].ToString();
                                    string FID = JObject.Parse(result)["Result"]["Id"].ToString();
                                    string updateSql = string.Format(@"
                                                      update a set
                                                      a.HERPInterID = {0} ,
                                                      a.HERPBillNO   ='{1}'
                                                      from Cg_POInStockBillMain a
                                                      join Cg_POInStockBillSub b on a.hinterid = b.hinterid
                                                      where b.HInterID = ({2})
                                                      and b. HSOURCEINTERID = {3}
                                                      and a.HERPInterID = 0
                                                     ", FID, FBillNo, dr["HINTERID"].ToString(), dr["FID"].ToString());
                                    oCn.RunProc(updateSql);
                                }
                                else
                                {
                                    objjson.code = "0";
                                    objjson.count = 0;
                                    objjson.Message = result;
                                    objjson.data = null;
                                    return objjson;
                                }
                            }
                        }
                    }
                    else if (FCusName == "夏宝电器")
                    {
                        sql = string.Format(@"
SELECT T3.FNAME AS FTYPENAME,M.HBILLNO,B.HINTERID,B.HENTRYID,C.FID,C.FENTRYID, D.FBILLNO,B.HQTY,CD.FRECEIVEORGID,CDOO.FNUMBER AS FRECEIVENUMBER
,D.FSUPPLIERID,DS.FNUMBER AS FSUPPLIERNUMBER,D.FPURCHASEORGID,DOO.FNUMBER AS FPURCHASEORGNUMBER,CROO.FNUMBER  AS FSETTLEORGNUMBER,
E.FPRICETIMEPOINT,E.FSETTLECURRID,EC.FNUMBER AS FSETTLECURRNUMBER,C.FMATERIALID,CM.FNUMBER AS FMATERIALNUMBER ,C.FUNITID
,CU.FNUMBER AS FUNITNUMBER,D.F_XBKF_COMBO1,CR.FPRICE,CR.FTAXPRICE,CR.FTAXRATE,D.FPURCHASERID,isnull(T4.FNUMBER,'') AS FPURCHASERNUMBER,D.F_XBKF_BASE1,isnull(T5.FNUMBER,'') AS FRECEIVEMENNUMBER
FROM CG_POINSTOCKBILLSUB B
JOIN CG_POINSTOCKBILLMAIN M ON B.HINTERID = M.HINTERID
JOIN {0}..T_PUR_POORDERENTRY C ON B.HSOURCEINTERID = C.FID AND B.HSOURCEENTRYID = C.FENTRYID
LEFT JOIN {0}..T_BD_MATERIAL CM ON C.FMATERIALID =CM.FMATERIALID
LEFT JOIN {0}..T_BD_UNIT CU ON C.FUNITID =CU.FUNITID
JOIN {0}..T_PUR_POORDERENTRY_D CD ON    C.FENTRYID = CD.FENTRYID
LEFT JOIN {0}..T_ORG_ORGANIZATIONS CDOO ON CD.FRECEIVEORGID = CDOO.FORGID
JOIN {0}..T_PUR_POORDERENTRY_F CR ON    C.FENTRYID = CR.FENTRYID
LEFT JOIN {0}..T_ORG_ORGANIZATIONS CROO ON CR.FSETTLEORGID = CROO.FORGID
LEFT JOIN {0}..T_PUR_POORDER D ON C.FID =D.FID
LEFT JOIN {0}..T_BAS_BILLTYPE T2 ON D.FBILLTYPEID = T2.FBILLTYPEID
LEFT JOIN {0}..T_BAS_BILLTYPE_L T3 ON T2.FBILLTYPEID = T3.FBILLTYPEID  and FLOCALEID=2052
LEFT JOIN  {0}..V_BD_BUYER T4 ON D.FPURCHASERID =T4.FID
LEFT JOIN  {0}..T_HR_EMPINFO T5 ON D.F_XBKF_BASE1 = T5.FID
LEFT JOIN {0}..T_BD_SUPPLIER DS ON D.FSUPPLIERID = DS.FSUPPLIERID
LEFT JOIN {0}..T_ORG_ORGANIZATIONS DOO ON D.FPURCHASEORGID = DOO.FORGID
JOIN {0}..T_PUR_POORDERFIN E ON C.FID =E.FID
LEFT JOIN {0}..T_BD_CURRENCY EC ON E. FSETTLECURRID =EC.FCURRENCYID
 WHERE b.hinterid in ({1}) and M.HERPInterID = 0
", kdTbaleName, HInterID);
                        dt = oCn.RunProcReturn(sql, "sltz").Tables[0];
                        if (dt.Rows.Count > 0)
                        {
                            foreach (DataRow dr in dt.Rows)
                            {
                                if (fidList.Contains(dr["FID"].ToString() + dr["HINTERID"].ToString()))
                                    continue;
                                else
                                    fidList.Add(dr["FID"].ToString() + dr["HINTERID"].ToString());
                                DataRow[] drs = dt.Select("FID = " + dr["FID"].ToString() + " and HINTERID = " + dr["HINTERID"].ToString());
                                JObject model = new JObject();
                                string fTypeName = "SLD01_SYS";//标准采购订单类型
                                string ywTypeName = "CG";//标准业务类型
                                if (dr["FTYPENAME"].ToString().Contains("委外"))
                                {
                                    fTypeName = "SLD03_SYS";
                                    ywTypeName = "WW";
                                }
                                if (dr["FTYPENAME"].ToString().Contains("资产"))
                                {
                                    fTypeName = "SLD04_SYS";
                                    ywTypeName = "ZCCG";
                                }
                                model.Add("FBILLTYPEID", new JObject() { ["Fnumber"] = fTypeName }); //单据类型
                                model.Add("FBusinessType", ywTypeName); //业务类型
                                model.Add("FBILLNO", dr["HBillNo"].ToString()); //单据编号
                                model.Add("FDate", DateTime.Now.ToString("yyyy-MM-dd")); //通知日期
                                model.Add("FStockOrgId", new JObject() { ["Fnumber"] = dr["FRECEIVENUMBER"].ToString() }); // 收料组织
                                model.Add("FPurOrgId", new JObject() { ["Fnumber"] = dr["FPURCHASEORGNUMBER"].ToString() }); //采购组织
                                model.Add("FSupplierId", new JObject() { ["Fnumber"] = dr["FSUPPLIERNUMBER"].ToString() }); //供应商
                                model.Add("FPURCHASERID", new JObject() { ["Fnumber"] = dr["FPURCHASERNUMBER"].ToString() }); //采购员
                                model.Add("F_xbkf_Base", new JObject() { ["Fnumber"] = dr["FRECEIVEMENNUMBER"].ToString() }); //收料员
                                model.Add("FOwnerTypeIdHead", "BD_Supplier");//  货主类型
                                model.Add("FOwnerIdHead", new JObject() { ["Fnumber"] = dr["FSUPPLIERNUMBER"].ToString() });//货主 供应商
                                model.Add("F_XBKF_COMBO", dr["F_xbkf_Combo1"].ToString());//是否有票
                                JArray Fentity = new JArray();
                                foreach (var item in drs)
                                {
                                    JObject FentityModel = new JObject();
                                    FentityModel.Add("FMaterialId", new JObject() { ["Fnumber"] = item["FMATERIALNUMBER"].ToString() }); // 物料编码
                                    FentityModel.Add("FUnitID", new JObject() { ["Fnumber"] = item["FUNITNUMBER"].ToString() }); // 单位
                                    FentityModel.Add("FPreDeliveryDate", DateTime.Now.ToString("yyyy-MM-dd")); //预计到货日期
                                    FentityModel.Add("FPriceUnitId", new JObject() { ["Fnumber"] = item["FUNITNUMBER"].ToString() }); // 计价单位
                                    FentityModel.Add("FStockUnitID", new JObject() { ["Fnumber"] = item["FUNITNUMBER"].ToString() }); //  库存单位
                                    FentityModel.Add("FActReceiveQty", Convert.ToDecimal(item["HQTY"])); // 供应商送货数量(提料计划数量 - 已生成送货单数量)
                                    FentityModel.Add("FOwnerTypeId", "BD_OwnerOrg");//货主类型
                                    FentityModel.Add("FOwnerID", new JObject() { ["Fnumber"] = dr["FPURCHASEORGNUMBER"].ToString() });//货主
                                    FentityModel.Add("FSrcId", item["FID"].ToString());//源单内码
                                    FentityModel.Add("FSRCFORMID", "PUR_PurchaseOrder");//源单类型
                                    FentityModel.Add("FSrcBillNo", item["FBILLNO"].ToString());//源单单号
                                    FentityModel.Add("FSRCENTRYID", item["FENTRYID"].ToString());//源单分录内码
                                    FentityModel.Add("FORDERBILLNO", item["FBILLNO"].ToString());//源单单号
                                    FentityModel.Add("FPOORDERENTRYID", item["FENTRYID"].ToString());//源单分录内码
                                    FentityModel.Add("FSRMENTRYID", item["HENTRYID"].ToString());//SRM hentryid
                                    FentityModel.Add("FPrice", item["FPRICE"].ToString());//单价
                                    FentityModel.Add("FTaxPrice", item["FTAXPRICE"].ToString());//含税单价
                                    FentityModel.Add("FEntryTaxRate", item["FTAXRATE"].ToString());//税率
                                    JArray Fentity2 = new JArray();
                                    JObject FentityModel2 = new JObject();
                                    FentityModel2.Add("FDetailEntity_Link_FRULEID", "PUR_PurchaseOrder-PUR_ReceiveBill");
                                    FentityModel2.Add("FDetailEntity_Link_FSTableName", "t_PUR_POOrderEntry");
                                    FentityModel2.Add("FDetailEntity_Link_FSBillId", item["FID"].ToString());
                                    FentityModel2.Add("FDetailEntity_Link_FSId", item["FEntryID"].ToString());
                                    Fentity2.Add(FentityModel2);
                                    FentityModel.Add("FDetailEntity_Link", Fentity2);
                                    Fentity.Add(FentityModel);
                                }
                                model.Add("FDetailEntity", Fentity); //明细信息
                                JObject _FentityModel = new JObject();
                                _FentityModel.Add("FSettleOrgId", new JObject() { ["Fnumber"] = dr["FSETTLEORGNUMBER"].ToString() }); //  结算组织
                                _FentityModel.Add("FSettleCurrId", new JObject() { ["Fnumber"] = dr["FSETTLECURRNUMBER"].ToString() }); //  结算币别
                                _FentityModel.Add("FPricePoint", 0); //  定价时点
                                model.Add("FinanceEntity ", _FentityModel);//财务信息
                                JObject jsonRoot = new JObject()
                                {
                                    ["Creator"] = "",
                                    ["NeedUpDateFields"] = new JArray(),
                                    ["NeedReturnFields"] = new JArray(),
                                    ["IsDeleteEntry"] = "false",
                                    ["SubSystemId"] = "",
                                    ["IsVerifyBaseDataField"] = "false",
                                    ["Model"] = model
                                };
                                var loginRet = InvokeHelper.Login();
                                var isSuccess = JObject.Parse(loginRet)["LoginResultType"].Value<int>();
                                if (isSuccess < 0)
                                {
                                    objjson.code = "0";
                                    objjson.count = 0;
                                    objjson.Message = loginRet;
                                    objjson.data = null;
                                    return objjson;
                                }
                                //LogService.Write("jsonRoot:" + jsonRoot.ToString());
                                var result = InvokeHelper.Save("PUR_ReceiveBill", jsonRoot.ToString());
                                //LogService.Write(result);
                                if (JObject.Parse(result)["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper() == "TRUE")
                                {
                                    //更新送货单 主表 ERP单据号 以及 ERP主内玛
                                    string FBillNo = JObject.Parse(result)["Result"]["Number"].ToString();
                                    string FID = JObject.Parse(result)["Result"]["Id"].ToString();
                                    string updateSql = string.Format(@"
                                                      update a set
                                                      a.HERPInterID = {0} ,
                                                      a.HERPBillNO   ='{1}'
                                                      from Cg_POInStockBillMain a
                                                      join Cg_POInStockBillSub b on a.hinterid = b.hinterid
                                                      where b.HInterID = ({2})
                                                      and b. HSOURCEINTERID = {3}
                                                      and a.HERPInterID = 0
                                                     ", FID, FBillNo, dr["HINTERID"].ToString(), dr["FID"].ToString());
                                    oCn.RunProc(updateSql);
                                }
                                else
                                {
                                    objjson.code = "0";
                                    objjson.count = 0;
                                    objjson.Message = result;
                                    objjson.data = null;
                                    return objjson;
                                }
                            }
                        }
                    }
                }
                var check = Exec_ReciveBillCheck(HBillNo);
                if (check.code == "0")
                    return check;
                //if(check)
                //更新主表状态 审核
                sql = string.Format(@"update Cg_POInStockBillMain set
HBillStatus = 2 ,
HChecker   ='{0}',
HCheckDate   = getdate()
where HInterID in ({1})", CurUserName, HInterID);
                oCn.RunProc(sql);
                objjson.code = "1";
                objjson.count = 1;
                objjson.Message = "操作成功";
                objjson.data = null;
                return objjson;
            }
            catch (Exception ex)
            {
                objjson.code = "0";
                objjson.count = 0;
                objjson.Message = "操作失败" + ex.Message.ToString();
                objjson.data = null;
                return objjson;
            }
        }
        public int GetHinterIDByBillNo(string HBillNo, string type)
@@ -1421,7 +1975,12 @@
            try
            {
                SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
                DataSet Ds = oCn.RunProcReturn("exec h_p_KF_PonderationBillMain_Temp_Add_POInStockCheck2 '" + HBarCode + "'", "h_p_KF_PonderationBillMain_Temp_Add_POInStockCheck2");
                DataSet Ds;
                string FCusName = oSystemParameter.GetSingleSystemParameter("WMS_CampanyName", ref DBUtility.ClsPub.sExeReturnInfo);//客户名称
                if (FCusName.Contains("安瑞"))
                    Ds = oCn.RunProcReturn("exec h_p_GetPOInStockByBarCode'" + HBarCode + "'", "h_p_GetPOInStockByBarCode");
                else
                    Ds = oCn.RunProcReturn("exec h_p_KF_PonderationBillMain_Temp_Add_POInStockCheck2 '" + HBarCode + "'", "h_p_KF_PonderationBillMain_Temp_Add_POInStockCheck2");
                if (Ds == null || Ds.Tables[0].Rows.Count == 0)
                {
                    objjson.code = "0";
@@ -1474,8 +2033,29 @@
                DAL.ClsCg_POInStockBill oBill = new DAL.ClsCg_POInStockBill();
                var hinterID = list[0].HInterID;
                var FID = list[0].FID;
                oCn.BeginTran();
                string FCusName = oSystemParameter.GetSingleSystemParameter("WMS_CampanyName", ref DBUtility.ClsPub.sExeReturnInfo);//客户名称
                string FisRealess = oSystemParameter.GetSingleSystemParameter("Cg_POInStockBill_ErpAduit", ref DBUtility.ClsPub.sExeReturnInfo);//送货单到货确认后同步金蝶云收料通知单
                string FishaveBarcode = oSystemParameter.GetSingleSystemParameter("Cg_POInStockBill_BarCodeCtl", ref DBUtility.ClsPub.sExeReturnInfo);//到货确认必须扫码箱条码
                var kdTbaleName = Util.GetConfigKey(AppDomain.CurrentDomain.BaseDirectory + "/Config/kdapi.config", "DataBaseName");
                string sql = string.Empty;
                #region 校验是否扫描条码
                if (FishaveBarcode == "Y")
                {
                    var HInterID = list[0].HInterID;
                    string jysql = string.Format(@"select * from KF_PonderationBillMain_Temp where HSourceInterID = {0}", HInterID);
                    DataTable jyDt = oCn.RunProcReturn(jysql, "jysql").Tables[0];
                    if (jyDt.Rows.Count == 0 || jyDt == null)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "请扫描条码";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                #endregion
                #region 金蝶审核后会重新同步单据到mes 故不需要更新mes的收料通知单
                oCn.BeginTran();
                foreach (var item in list)
                {
                    if (item.HSQty == 0)
@@ -1483,61 +2063,231 @@
                    sql = $"update Cg_POInStockBillSub set Hqty = {item.HSQty} where HInterID ={item.HInterID} and HEntryID = {item.HEntryID}";
                    oCn.RunProc(sql);
                }
                oCn.RunProc("exec h_p_Cg_UpDatePOOrderRelation_Del " + hinterID);//删除关联关系
                //更新成功后 同步更新金蝶
                oCn.Commit();
                #endregion
                JObject jsonRoot = new JObject();
                jsonRoot.Add("Creator", "");
                jsonRoot.Add("NeedUpDateFields", new JArray());
                jsonRoot.Add("NeedReturnFields", new JArray());
                jsonRoot.Add("IsDeleteEntry", "false");
                jsonRoot.Add("SubSystemId", "");
                jsonRoot.Add("IsVerifyBaseDataField", "");
                if (FCusName.Contains("安瑞"))
                {
                    sql = string.Format(@"
SELECT T3.FNAME AS FTYPENAME,M.HBILLNO,B.HINTERID,B.HENTRYID,C.FID,C.FENTRYID, D.FBILLNO,B.HQTY,CD.FRECEIVEORGID,CDOO.FNUMBER AS FRECEIVENUMBER
,D.FSUPPLIERID,DS.FNUMBER AS FSUPPLIERNUMBER,D.FPURCHASEORGID,DOO.FNUMBER AS FPURCHASEORGNUMBER,CROO.FNUMBER  AS FSETTLEORGNUMBER,
E.FPRICETIMEPOINT,E.FSETTLECURRID,EC.FNUMBER AS FSETTLECURRNUMBER,C.FMATERIALID,CM.FNUMBER AS FMATERIALNUMBER ,C.FUNITID
,CU.FNUMBER AS FUNITNUMBER,CR.FPRICE,CR.FTAXPRICE,CR.FTAXRATE,D.FPURCHASERID,isnull(T4.FNUMBER,'') AS FPURCHASERNUMBER
FROM CG_POINSTOCKBILLSUB B
JOIN CG_POINSTOCKBILLMAIN M ON B.HINTERID = M.HINTERID
JOIN {0}..T_PUR_POORDERENTRY C ON B.HSOURCEINTERID = C.FID AND B.HSOURCEENTRYID = C.FENTRYID
LEFT JOIN {0}..T_BD_MATERIAL CM ON C.FMATERIALID =CM.FMATERIALID
LEFT JOIN {0}..T_BD_UNIT CU ON C.FUNITID =CU.FUNITID
JOIN {0}..T_PUR_POORDERENTRY_D CD ON    C.FENTRYID = CD.FENTRYID
LEFT JOIN {0}..T_ORG_ORGANIZATIONS CDOO ON CD.FRECEIVEORGID = CDOO.FORGID
JOIN {0}..T_PUR_POORDERENTRY_F CR ON    C.FENTRYID = CR.FENTRYID
LEFT JOIN {0}..T_ORG_ORGANIZATIONS CROO ON CR.FSETTLEORGID = CROO.FORGID
LEFT JOIN {0}..T_PUR_POORDER D ON C.FID =D.FID
LEFT JOIN {0}..T_BAS_BILLTYPE T2 ON D.FBILLTYPEID = T2.FBILLTYPEID
LEFT JOIN {0}..T_BAS_BILLTYPE_L T3 ON T2.FBILLTYPEID = T3.FBILLTYPEID and FLOCALEID = 2052
LEFT JOIN  {0}..V_BD_BUYER T4 ON D.FPURCHASERID =T4.FID
LEFT JOIN {0}..T_BD_SUPPLIER DS ON D.FSUPPLIERID = DS.FSUPPLIERID
LEFT JOIN {0}..T_ORG_ORGANIZATIONS DOO ON D.FPURCHASEORGID = DOO.FORGID
JOIN {0}..T_PUR_POORDERFIN E ON C.FID =E.FID
LEFT JOIN {0}..T_BD_CURRENCY EC ON E. FSETTLECURRID =EC.FCURRENCYID
 WHERE b.hinterid in ({1}) and M.HERPInterID = 0
", kdTbaleName, hinterID);
                    DataTable dt = oCn.RunProcReturn(sql, "sltz").Tables[0];
                    List<string> fidList = new List<string>();
                    if (dt.Rows.Count > 0)
                    {
                        //foreach (DataRow dr in dt.Rows)
                        //{
                        //    //采购订单下推生成送货单 时候 判断是否有生成采购订单变更单 如果有且变更单状态不为已审核 限制下推
                        //    objJsonResult = TestPOOrder(dr["FEntryID"].ToString());
                        //    if (objJsonResult.code == "0")
                        //        return objJsonResult;
                        //}
                        foreach (DataRow dr in dt.Rows)
                        {
                            if (fidList.Contains(dr["HINTERID"].ToString()))
                                continue;
                            else
                                fidList.Add(dr["HINTERID"].ToString());
                            DataRow[] drs = dt.Select("HINTERID = " + dr["HINTERID"].ToString());
                            JObject model = new JObject();
                            string fTypeName = "SLD01_SYS";//标准采购订单类型
                            string ywTypeName = "CG";//标准业务类型
                            if (dr["FTYPENAME"].ToString().Contains("委外"))
                            {
                                fTypeName = "SLD03_SYS";
                                ywTypeName = "WW";
                            }
                            if (dr["FTYPENAME"].ToString().Contains("资产"))
                            {
                                fTypeName = "SLD04_SYS";
                                ywTypeName = "ZCCG";
                            }
                            model.Add("FBILLTYPEID", new JObject() { ["Fnumber"] = fTypeName }); //单据类型
                            model.Add("FBusinessType", ywTypeName); //业务类型
                            model.Add("FBILLNO", dr["HBillNo"].ToString()); //单据编号
                            model.Add("FDate", DateTime.Now.ToString("yyyy-MM-dd")); //通知日期
                            model.Add("FStockOrgId", new JObject() { ["Fnumber"] = dr["FRECEIVENUMBER"].ToString() }); // 收料组织
                            model.Add("FPurOrgId", new JObject() { ["Fnumber"] = dr["FPURCHASEORGNUMBER"].ToString() }); //采购组织
                            model.Add("FSupplierId", new JObject() { ["Fnumber"] = dr["FSUPPLIERNUMBER"].ToString() }); //供应商
                            model.Add("FPURCHASERID", new JObject() { ["Fnumber"] = dr["FPURCHASERNUMBER"].ToString() }); //采购员
                            model.Add("FOwnerTypeIdHead", "BD_Supplier");//  货主类型
                            model.Add("FOwnerIdHead", new JObject() { ["Fnumber"] = dr["FSUPPLIERNUMBER"].ToString() });//货主 供应商
                            JArray Fentity = new JArray();
                            foreach (var item in drs)
                            {
                                JObject FentityModel = new JObject();
                                FentityModel.Add("FMaterialId", new JObject() { ["Fnumber"] = item["FMATERIALNUMBER"].ToString() }); // 物料编码
                                FentityModel.Add("FUnitID", new JObject() { ["Fnumber"] = item["FUNITNUMBER"].ToString() }); // 单位
                                FentityModel.Add("FPreDeliveryDate", DateTime.Now.ToString("yyyy-MM-dd")); //预计到货日期
                                FentityModel.Add("FPriceUnitId", new JObject() { ["Fnumber"] = item["FUNITNUMBER"].ToString() }); // 计价单位
                                FentityModel.Add("FStockUnitID", new JObject() { ["Fnumber"] = item["FUNITNUMBER"].ToString() }); //  库存单位
                                FentityModel.Add("FStockID", new JObject() { ["Fnumber"] = "BJCK-SH.01.005" }); //  库存单位
                                FentityModel.Add("FActReceiveQty", Convert.ToDecimal(item["HQTY"])); // 供应商送货数量(提料计划数量 - 已生成送货单数量)
                                FentityModel.Add("FOwnerTypeId", "BD_OwnerOrg");//货主类型
                                FentityModel.Add("FOwnerID", new JObject() { ["Fnumber"] = dr["FPURCHASEORGNUMBER"].ToString() });//货主
                                FentityModel.Add("FSrcId", item["FID"].ToString());//源单内码
                                FentityModel.Add("FSRCFORMID", "PUR_PurchaseOrder");//源单类型
                                FentityModel.Add("FSrcBillNo", item["FBILLNO"].ToString());//源单单号
                                FentityModel.Add("FSRCENTRYID", item["FENTRYID"].ToString());//源单分录内码
                                FentityModel.Add("FORDERBILLNO", item["FBILLNO"].ToString());//源单单号
                                FentityModel.Add("FPOORDERENTRYID", item["FENTRYID"].ToString());//源单分录内码
                                FentityModel.Add("FSRMENTRYID", item["HENTRYID"].ToString());//SRM hentryid
                                FentityModel.Add("FPrice", item["FPRICE"].ToString());//单价
                                FentityModel.Add("FTaxPrice", item["FTAXPRICE"].ToString());//含税单价
                                FentityModel.Add("FEntryTaxRate", item["FTAXRATE"].ToString());//税率
                JObject jsonModel = new JObject();
                jsonModel.Add("FID", FID);
                JArray Entry = new JArray();
                foreach (var item in list)
                {
                    if (item.HSQty == 0)
                        continue;
                    JObject jsonFPOOrderEntry = new JObject();
                    jsonFPOOrderEntry.Add("FEntryID", item.FEntryID);
                    jsonFPOOrderEntry.Add("FHQty ", item.HSQty); ;
                    Entry.Add(jsonFPOOrderEntry);
                                JArray Fentity2 = new JArray();
                                JObject FentityModel2 = new JObject();
                                FentityModel2.Add("FDetailEntity_Link_FRULEID", "PUR_PurchaseOrder-PUR_ReceiveBill");
                                FentityModel2.Add("FDetailEntity_Link_FSTableName", "t_PUR_POOrderEntry");
                                FentityModel2.Add("FDetailEntity_Link_FSBillId", item["FID"].ToString());
                                FentityModel2.Add("FDetailEntity_Link_FSId", item["FEntryID"].ToString());
                                Fentity2.Add(FentityModel2);
                                FentityModel.Add("FDetailEntity_Link", Fentity2);
                                Fentity.Add(FentityModel);
                            }
                            model.Add("FDetailEntity", Fentity); //明细信息
                            JObject _FentityModel = new JObject();
                            _FentityModel.Add("FSettleOrgId", new JObject() { ["Fnumber"] = dr["FSETTLEORGNUMBER"].ToString() }); //  结算组织
                            _FentityModel.Add("FSettleCurrId", new JObject() { ["Fnumber"] = dr["FSETTLECURRNUMBER"].ToString() }); //  结算币别
                            _FentityModel.Add("FPricePoint", 0); //  定价时点
                            model.Add("FinanceEntity ", _FentityModel);//财务信息
                            JObject jsonRoot = new JObject()
                            {
                                ["Creator"] = "",
                                ["NeedUpDateFields"] = new JArray(),
                                ["NeedReturnFields"] = new JArray(),
                                ["IsDeleteEntry"] = "false",
                                ["SubSystemId"] = "",
                                ["IsVerifyBaseDataField"] = "false",
                                ["Model"] = model
                            };
                            var loginRet = InvokeHelper.Login();
                            var isSuccess = JObject.Parse(loginRet)["LoginResultType"].Value<int>();
                            if (isSuccess == 0)
                            {
                                objJsonResult.code = "0";
                                objJsonResult.count = 0;
                                objJsonResult.Message = loginRet;
                                objJsonResult.data = null;
                                return objJsonResult;
                            }
                            //LogService.Write("jsonRoot:" + jsonRoot.ToString());
                            var result = InvokeHelper.Save("PUR_ReceiveBill", jsonRoot.ToString());
                            //LogService.Write(result);
                            if (JObject.Parse(result)["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper() == "TRUE")
                            {
                                //更新送货单 主表 ERP单据号 以及 ERP主内玛
                                string FBillNo = JObject.Parse(result)["Result"]["Number"].ToString();
                                FID = JObject.Parse(result)["Result"]["Id"].ToString();
                                string updateSql = string.Format(@"
                                                      update a set
                                                      a.HERPInterID = {0} ,
                                                      a.HERPBillNO   ='{1}'
                                                      from Cg_POInStockBillMain a
                                                      join Cg_POInStockBillSub b on a.hinterid = b.hinterid
                                                      where b.HInterID = ({2})
                                                      and b. HSOURCEINTERID = {3}
                                                      and a.HERPInterID = 0
                                                     ", FID, FBillNo, dr["HINTERID"].ToString(), dr["FID"].ToString());
                                oCn.RunProc(updateSql);
                            }
                            else
                            {
                                objJsonResult.code = "0";
                                objJsonResult.count = 0;
                                objJsonResult.Message = result;
                                objJsonResult.data = null;
                                return objJsonResult;
                            }
                        }
                    }
                    else
                    {
                        LogService.Write("收料通知单审核无数据:" + sql);
                    }
                }
                jsonModel.Add("FEntity", Entry);
                jsonRoot.Add("Model", jsonModel);
                var loginRet = InvokeHelper.Login();
                var isSuccess = JObject.Parse(loginRet)["LoginResultType"].Value<int>();
                if (isSuccess <= 0)
                else //夏宝 ,更新erp信息
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = loginRet;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                var result = InvokeHelper.Save("PUR_ReceiveBill", jsonRoot.ToString());
                //LogService.Write(result);
                if (JObject.Parse(result)["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper() == "TRUE")
                {
                    LogService.Write("收料通知单修改失败jsonRoot:" + jsonRoot.ToString());
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "金蝶收料通知单更新失败" + result;
                    objJsonResult.data = null;
                    return objJsonResult;
                    JObject jsonRoot = new JObject();
                    jsonRoot.Add("Creator", "");
                    jsonRoot.Add("NeedUpDateFields", new JArray());
                    jsonRoot.Add("NeedReturnFields", new JArray());
                    jsonRoot.Add("IsDeleteEntry", "false");
                    jsonRoot.Add("SubSystemId", "");
                    jsonRoot.Add("IsVerifyBaseDataField", "");
                    JObject jsonModel = new JObject();
                    jsonModel.Add("FID", FID);
                    JArray Entry = new JArray();
                    foreach (var item in list)
                    {
                        if (item.HSQty == 0)
                            continue;
                        JObject jsonFPOOrderEntry = new JObject();
                        jsonFPOOrderEntry.Add("FEntryID", item.FEntryID);
                        jsonFPOOrderEntry.Add("FActReceiveQty ", item.HSQty); ;
                        Entry.Add(jsonFPOOrderEntry);
                    }
                    jsonModel.Add("FDetailEntity", Entry);
                    jsonRoot.Add("Model", jsonModel);
                    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.Save("PUR_ReceiveBill", jsonRoot.ToString());
                    //LogService.Write(result);
                    if (JObject.Parse(result)["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper() != "TRUE")
                    {
                        LogService.Write("收料通知单修改失败jsonRoot:" + jsonRoot.ToString());
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "金蝶收料通知单更新失败" + result;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                var json = new
                {
                    Ids = FID,
                };
                //LogService.Write(json);
                //提交
                var _result = InvokeHelper.Submit("PUR_ReceiveBill", JsonConvert.SerializeObject(json));
                var _saveObj = JObject.Parse(_result);
                if (_saveObj["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper() != "TRUE")
                {
                    LogService.Write("收料通知单提交失败jsonRoot:" + jsonRoot.ToString());
                    LogService.Write("收料通知单提交失败jsonRoot:" + json.ToString());
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "金蝶收料通知单提交失败" + _result;
@@ -1550,7 +2300,7 @@
                _saveObj = JObject.Parse(_result);
                if (_saveObj["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper() != "TRUE")
                {
                    LogService.Write("收料通知单审核失败jsonRoot:" + jsonRoot.ToString());
                    LogService.Write("收料通知单审核失败jsonRoot:" + json.ToString());
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "金蝶收料通知单审核失败jsonRoot" + _result;
@@ -1559,13 +2309,7 @@
                }
                sql = string.Format(@"update Cg_POInStockBillMain set
HBillStatus = 2 ,
HCheckDate   = getdate()
where HInterID in ({0})",  HInterID);
                oCn.RunProc(sql);//更新mes状态
                //更新成功后 同步更新金蝶
                oCn.Commit();
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "操作成功!";
@@ -1574,7 +2318,7 @@
            }
            catch (Exception e)
            {
                oCn.RollBack();
                //oCn.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "异常!" + e.ToString();
@@ -1596,8 +2340,14 @@
        {
            try
            {
                //var code = HBarcode.Split('#')[0];
                //校验条码是否存在
                string sql = $"select* from  Gy_BarCodeBill where HSourceInterID ={HInterID} and HBarCode = '{HBarcode}'";
                string FCusName = oSystemParameter.GetSingleSystemParameter("WMS_CampanyName", ref DBUtility.ClsPub.sExeReturnInfo);//客户名称
                string sql = string.Empty;
                if (FCusName.Contains("安瑞"))
                    sql = $"select top 1 HItemID,HSourceBillNo,HQty,HSourceInterID,HSourceEntryID from  Gy_BarCodeBill where HSourceInterID =(select distinct HSourceInterID from Cg_POInStockBillSub where HInterID ={HInterID}) and HBarCode = '{HBarcode}' and HBarCodeType ='箱号内条码'";
                else
                    sql = $"select HItemID,HSourceBillNo,HQty,HSourceInterID,HSourceEntryID from  Gy_BarCodeBill where HSourceInterID ={HInterID} and HBarCode = '{HBarcode.Split('#')[0]}' and HQty = {HBarcode.Split('#')[1]}";
                DataSet ds = oCn.RunProcReturn(sql, "H_v_SRM_POOrderBillList");
                if (ds.Tables[0].Rows.Count == 0)
                {
@@ -1607,6 +2357,29 @@
                    objJsonResult.data = ds.Tables[0];
                    return objJsonResult;
                }
                else
                {
                    //存入条码临时表
                    sql = $"delete from KF_PonderationBillMain_Temp Where HBillNo='{ds.Tables[0].Rows[0]["HSourceBillNo"]}' ";
                    oCn.RunProc(sql);
                    sql = string.Format(@"Insert into KF_PonderationBillMain_Temp
   (HInterID,HBillNo,HBillType,HMaterID,HProcID,HWhID,HSCWHID
   ,HStockPlaceID,HOutStockPlaceID,HGroupID,HQty,HQtyMust,HPieceQty
   ,HAuxPropID,HBatchNo,HBarCode,HAddr,HMaker,HMakeDate
   ,HSourceInterID,HSourceEntryID,HSourceBillType,HSourceBillNo,HMTONo
   ,HSTOCKORGID,HOWNERID,HExpressNumber,HSubBillType
   ,HRelationInterID,HRelationEntryID,HRelationBillNo,HRedBlueFlag
   ,HCusID)
   select HInterID,HSourceBillNo,HBillType,HMaterID,0,0,0
   ,0,0,0,HQty,HQty,0
   ,HAuxPropID,HBatchNo,'','','System',getdate()
   ,HSourceInterID,HSourceEntryID,HSourceBillType,HSourceBillNo,HMTONo
   ,HSTOCKORGID,HOWNERID,'',HBillType
   ,0,0,'',0
   ,0 from Gy_BarCodeBill
   where HItemID = {0}", ds.Tables[0].Rows[0]["HItemID"]);
                    oCn.RunProc(sql);
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;