1
yangle
17 小时以前 6d0bfe2160e06a4502dc3052c43fab9813341db3
WebAPI/Controllers/SCGL/Èռƻ®¹ÜÀí/Sc_JIT_ComplementGoodBillController.cs
@@ -1,4 +1,5 @@
using DBUtility;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
@@ -32,6 +33,7 @@
        {
            try
            {
                List<object> a = new List<object>();
                //查询权限
                if (!DBUtility.ClsPub.Security_Log_second("JIT_ComplementGoodBill_Query", 1, false, user))
                {
@@ -43,11 +45,17 @@
                }
                ds = oCN.RunProcReturn("select * from h_v_JIT_Gy_WorkWarehouseBillList where 1=1 " + sWhere + " order by hmainid desc ", "h_v_JIT_Gy_WorkWarehouseBillList");
                foreach (DataColumn col in ds.Tables[0].Columns)//遍历ds中第一个表(Tables[0])的所有列(Columns)每次循环中,col变量会持有当前列的引用
                {
                    Type dataType = col.DataType; //获取当前数据类型传入 è‡ªå®šä¹‰å˜é‡datadataType
                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}"; //字符串拼接         // å°†åˆ—名和数据类型信息拼接成一个JSON格式的字符串
                    a.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                objJsonResult.list = a;
                return objJsonResult;
            }
            catch (Exception e)
@@ -292,6 +300,7 @@
        {
            try
            {
                List<object> A = new List<object>();
                //查询权限
                if (!DBUtility.ClsPub.Security_Log_second("Cg_PODemandPlanConfigBill_Query", 1, false, user))
                {
@@ -303,11 +312,18 @@
                }
                ds = oCN.RunProcReturn("select * from h_v_JIT_Cg_PODemandPlanConfigBillList where 1=1 " + sWhere + " order by hmainid desc ", "h_v_JIT_Cg_PODemandPlanConfigBillList");
                foreach (DataColumn col in ds.Tables[0].Columns)//遍历ds中第一个表(Tables[0])的所有列(Columns)每次循环中,col变量会持有当前列的引用
                {
                    Type dataType = col.DataType; //获取当前数据类型传入 è‡ªå®šä¹‰å˜é‡datadataType
                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}"; //字符串拼接         // å°†åˆ—名和数据类型信息拼接成一个JSON格式的字符串
                    A.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                objJsonResult.list = A;
                return objJsonResult;
            }
            catch (Exception e)
@@ -451,7 +467,7 @@
                    return objJsonResult;
                }
                if (oSystemParameter.omodel.WMS_CampanyName != "帅威")
                if (oSystemParameter.omodel.WMS_CampanyName != "帅威"&& oSystemParameter.omodel.WMS_CampanyName != "宝工" && oSystemParameter.omodel.WMS_CampanyName != "三升")
                {
                    if (oSub.HLeadTime_Sec == 0 || oSub.HLeadTime_Sec == null)
                    {
@@ -608,7 +624,15 @@
                    {
                        row[j] = ExcelDs.Tables[0].Rows[i][j].ToString();
                    }
                    tb2.Rows.Add(row);
                    //如果表格第i行的第一列为空,则判断为这一行的数据为空,跳出循环并且不把数据写入 tb2
                    if (ExcelDs.Tables[0].Rows[i][0].ToString() == "")
                    {
                        continue;
                    }
                    else
                    {
                        tb2.Rows.Add(row);
                    }
                }
@@ -695,11 +719,11 @@
                    string JIDLT = ""; //JIT到货前置期(天)
                    string JIMLC = ""; //JIT最小起送量
                    HORGNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["组织编码"].ToString());
                    HORGNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["组织编码"].ToString()).Replace("'", "");
                    HORGName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["组织"].ToString());
                    HSupNumer = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["供应商代码"].ToString());
                    HSupNumer = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["供应商代码"].ToString()).Replace("'", "");
                    HSupName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["供应商"].ToString());
                    HMaterNumer = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["物料代码"].ToString());
                    HMaterNumer = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["物料代码"].ToString()).Replace("'", "");
                    HMaterName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["物料名称"].ToString());
                    HMaterModel = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["规格型号"].ToString());
                    HUntilName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["计量单位"].ToString());
@@ -783,71 +807,87 @@
                            tb2.Rows[i]["HUnitID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
                        }
                        //JIT物料分类
                        if (JITType == "")
                        string msg = "";
                        oSystemParameter.ShowBill(ref msg);
                        if (oSystemParameter.omodel.WMS_CampanyName == "宝工"|| oSystemParameter.omodel.WMS_CampanyName == "三升")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "第" + index + "行,JIT物料分类为空!";
                            objJsonResult.data = null;
                            return objJsonResult;
                            //JIT供货提前期(天)
                            if (JISLT == "")
                            {
                                objJsonResult.code = "0";
                                objJsonResult.count = 0;
                                objJsonResult.Message = "第" + index + "行,JIT供货提前期(天)为空!";
                                objJsonResult.data = null;
                                return objJsonResult;
                            }
                        }
                        //JIT提货经济批量
                        if (JIPEB == "")
                        else
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "第" + index + "行,JIT提货经济批量为空!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                            //JIT物料分类
                            if (JITType == "")
                            {
                                objJsonResult.code = "0";
                                objJsonResult.count = 0;
                                objJsonResult.Message = "第" + index + "行,JIT物料分类为空!";
                                objJsonResult.data = null;
                                return objJsonResult;
                            }
                        //JIT供货提前期(天)
                        if (JISLT == "")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "第" + index + "行,JIT供货提前期(天)为空!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                            //JIT提货经济批量
                            if (JIPEB == "")
                            {
                                objJsonResult.code = "0";
                                objJsonResult.count = 0;
                                objJsonResult.Message = "第" + index + "行,JIT提货经济批量为空!";
                                objJsonResult.data = null;
                                return objJsonResult;
                            }
                        //JIT到货前置期(天)
                        if (JIDLT == "")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "第" + index + "行,JIT到货前置期(天)为空!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                            //JIT供货提前期(天)
                            if (JISLT == "")
                            {
                                objJsonResult.code = "0";
                                objJsonResult.count = 0;
                                objJsonResult.Message = "第" + index + "行,JIT供货提前期(天)为空!";
                                objJsonResult.data = null;
                                return objJsonResult;
                            }
                        //JIT最小起送量
                        if (JIMLC == "")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "第" + index + "行,JIT最小起送量为空!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                            //JIT到货前置期(天)
                            if (JIDLT == "")
                            {
                                objJsonResult.code = "0";
                                objJsonResult.count = 0;
                                objJsonResult.Message = "第" + index + "行,JIT到货前置期(天)为空!";
                                objJsonResult.data = null;
                                return objJsonResult;
                            }
                        //审核代码是否合理
                        if (!DBUtility.ClsPub.AllowNumber(HMaterNumer))
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "第" + index + "行,物料代码中不能出现连续‘.’并且首位末位不能为‘.’!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                            //JIT最小起送量
                            if (JIMLC == "")
                            {
                                objJsonResult.code = "0";
                                objJsonResult.count = 0;
                                objJsonResult.Message = "第" + index + "行,JIT最小起送量为空!";
                                objJsonResult.data = null;
                                return objJsonResult;
                            }
                            //审核代码是否合理
                            if (!DBUtility.ClsPub.AllowNumber(HMaterNumer))
                            {
                                objJsonResult.code = "0";
                                objJsonResult.count = 0;
                                objJsonResult.Message = "第" + index + "行,物料代码中不能出现连续‘.’并且首位末位不能为‘.’!";
                                objJsonResult.data = null;
                                return objJsonResult;
                            }
                        }
                    }
                    else
                    {
                        objJsonResult.code = "1";
                        objJsonResult.count = 1;
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "第" + index + "行,组织代码为空";
                        objJsonResult.data = null;
                        return objJsonResult;
@@ -909,12 +949,10 @@
                int i = 1;
                foreach (Dictionary<string, string> item in list)
                {
                    long HInterID = DBUtility.ClsPub.CreateBillID_Prod("4611", ref DBUtility.ClsPub.sExeReturnInfo);//获得一个新的id
                    string HBillNo = DBUtility.ClsPub.CreateBillCode_Prod("4611", ref DBUtility.ClsPub.sExeReturnInfo, true);//获得一个新的单据号
                    string HOrgID = item["HOrgID"].ToString();//组织ID
                    string HSupID = item["HSupID"].ToString();//供应商
                    string HSupplierName = item["供应商"].ToString();
                    string HMaterID = item["HMaterID"].ToString();//物料ID
                    string HOrgID = item["HOrgID"].ToString();//组织ID
                    string HSupplierName = item["供应商"].ToString();
                    string HMaterName = item["物料名称"].ToString();
                    string HMaterModel = item["规格型号"].ToString();
                    string HUnitID = item["HUnitID"].ToString();//计量单位
@@ -929,21 +967,33 @@
                    string JIMLC = item["JIT最小起送量"].ToString();
                    string HRemark = item["备注"].ToString();
                    string sql = "insert into Cg_PODemandPlanConfigBillMain(HInterID,HBillNo,HYear,HPeriod,HBillType,HBillSubType,HDate,HBillStatus,HMaker,HMakeDate,HOrgId)" +
                        $"values({HInterID}, '{HBillNo}',{DateTime.Now.Year}, {DateTime.Now.Month}, '4611', '4611', GETDATE(), 1, '{user}', GETDATE(), {HOrgID})";
                    string sql1 = "insert into Cg_PODemandPlanConfigBillSub(HInterID,HEntryID,HRemark,HSupplierID,HSupplierName,HMaterID," +
                   "HMaterName, HMaterModel, HJITMaterGroup, HJITSafeStock, HJITMaterDemand, HJITBatchQty, HDeliveryPeriod, " +
                   "HLeadTime, HLeadTime_Sec, HDeliveryMode, HDeliveryDaysCtrl,HUnitID,HJITMinDeliveryQty)values" +
                   $"({HInterID}, 1, '{HRemark}', {(HSupID == "" ? "0" : HSupID)}, '{HSupplierName}', {(HMaterID == "" ? "0" : HMaterID)}," +
                   $" '{HMaterName}', '{HMaterModel}', '{JITType}', {(JITPSL == "" ? "0" : JITPSL)}, {(JITMDSC == "" ? "0" : JITMDSC)},{(JIPEB == "" ? "0" : JIPEB)},{(JITPBCC == "" ? "0" : JITPBCC)}," +
                   $" {(JISLT == "" ? "0" : JISLT)}, {(JIDLT == "" ? "0" : JIDLT)}, '', {(JITDCD == "" ? "0" : JITDCD)} ,{HUnitID},{JIMLC})";
                    LogService.Write("sql" + i + ":" + sql);
                    LogService.Write("sql1" + i + ":" + sql1);
                   //主表
                   oCN.RunProc(sql);
                    //子表
                    oCN.RunProc(sql1);
                    ds = oCN.RunProcReturn("select * from Cg_PODemandPlanConfigBillSub where HMaterID=" + HMaterID + " and HSupplierID=" + HSupID, "Cg_PODemandPlanConfigBillSub");
                    if (ds.Tables[0].Rows.Count == 0)
                    {
                        long HInterID = DBUtility.ClsPub.CreateBillID_Prod("4611", ref DBUtility.ClsPub.sExeReturnInfo);//获得一个新的id
                        string HBillNo = DBUtility.ClsPub.CreateBillCode_Prod("4611", ref DBUtility.ClsPub.sExeReturnInfo, true);//获得一个新的单据号
                        string sql = "insert into Cg_PODemandPlanConfigBillMain(HInterID,HBillNo,HYear,HPeriod,HBillType,HBillSubType,HDate,HBillStatus,HMaker,HMakeDate,HOrgId)" +
                            $"values({HInterID}, '{HBillNo}',{DateTime.Now.Year}, {DateTime.Now.Month}, '4611', '4611', GETDATE(), 1, '{user}', GETDATE(), {HOrgID})";
                        string sql1 = "insert into Cg_PODemandPlanConfigBillSub(HInterID,HEntryID,HRemark,HSupplierID,HSupplierName,HMaterID," +
                       "HMaterName, HMaterModel, HJITMaterGroup, HJITSafeStock, HJITMaterDemand, HJITBatchQty, HDeliveryPeriod, " +
                       "HLeadTime, HLeadTime_Sec, HDeliveryMode, HDeliveryDaysCtrl,HUnitID,HJITMinDeliveryQty)values" +
                       $"({HInterID}, 1, '{HRemark}', {(HSupID == "" ? "0" : HSupID)}, '{HSupplierName}', {(HMaterID == "" ? "0" : HMaterID)}," +
                       $" '{HMaterName}', '{HMaterModel}', '{JITType}', {(JITPSL == "" ? "0" : JITPSL)}, {(JITMDSC == "" ? "0" : JITMDSC)},{(JIPEB == "" ? "0" : JIPEB)},{(JITPBCC == "" ? "0" : JITPBCC)}," +
                       $" {(JISLT == "" ? "0" : JISLT)}, {(JIDLT == "" ? "0" : JIDLT)}, '', {(JITDCD == "" ? "0" : JITDCD)} ,{HUnitID},{(JIMLC==""?"0": JIMLC)})";
                        //主表
                        oCN.RunProc(sql);
                        //子表
                        oCN.RunProc(sql1);
                    }
                    else
                    {
                        oCN.RunProc("   update  Cg_PODemandPlanConfigBillSub set HLeadTime=" + JISLT + "  where HMaterID=" + HMaterID + " and HSupplierID=" + HSupID);
                    }
                    i++;
                }
              
@@ -1108,8 +1158,9 @@
        public json AddNeedBillSub(string msg3)
        {
            string Ret = "";
            omodelNeedsub = Newtonsoft.Json.JsonConvert.DeserializeObject<List<JIT_NeedMaterPlanConfigBillSub>>(msg3);
            oSystemParameter.ShowBill(ref Ret);
            foreach (Models.JIT_NeedMaterPlanConfigBillSub oSub in omodelNeedsub)
            {
                if (oSub.HWorkShopID == 0 || oSub.HWorkShopID == null)
@@ -1144,14 +1195,18 @@
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (oSub.HDeliveryDaysCtrl == 0 || oSub.HDeliveryDaysCtrl == null)
                if (oSystemParameter.omodel.WMS_CampanyName != "宝工"&& oSystemParameter.omodel.WMS_CampanyName != "三升")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = " JIT送货控制天数不能为空";
                    objJsonResult.data = null;
                    return objJsonResult;
                    if (oSub.HDeliveryDaysCtrl == 0 || oSub.HDeliveryDaysCtrl == null)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = " JIT送货控制天数不能为空";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
            }
            //删除子表
@@ -1244,6 +1299,433 @@
        }
        #endregion
        #region ææ–™è®¡åˆ’信息 æ–‡ä»¶ä¸Šä¼ 
        [Route("Sc_JIT_ComplementGoodBill/Sc_JIT_ComplementGoodBill_Excel")]
        [HttpPost]
        public object Sc_JIT_ComplementGoodBill_Excel()
        {
            try
            {
                //var WorkBookName = HttpContext.Current.Request["WorkBookName"];
                //DBUtility.ClsPub.HOrgID = long.Parse(HttpContext.Current.Request["HOrgID"]);
                //获取文件名称
                var file = HttpContext.Current.Request.Files[0];
                //获取文件物理路径
                string ExcelPath = HttpContext.Current.Server.MapPath("~/" + file.FileName);
                //保存文件
                file.SaveAs(ExcelPath);
                NpoiHelper np = new NpoiHelper();
                DataSet ExcelDs = np.ReadExcel(ExcelPath, 1, 1, "0");
                //删除文件
                File.Delete(ExcelPath);
                //创建临时表
                DataTable tb2 = new DataTable("dt2");
                //添加列名
                for (int i = 0; i < ExcelDs.Tables[0].Columns.Count; i++)
                {
                    tb2.Columns.Add(ExcelDs.Tables[0].Rows[0][i].ToString());
                }
                //模板缺少列 ä½†éœ€è¦ä»Žæ•°æ®åº“中查询出来显示在页面的字段
                tb2.Columns.Add("HOrgID", typeof(Int32));//组织ID
                tb2.Columns.Add("HWorkShopID", typeof(Int32));//供应商
                tb2.Columns.Add("HMaterID", typeof(Int32));//物料ID
                //添加数据
                for (int i = 1; i < ExcelDs.Tables[0].Rows.Count; i++)
                {
                    DataRow row = tb2.NewRow();
                    for (int j = 0; j < ExcelDs.Tables[0].Columns.Count; j++)
                    {
                        row[j] = ExcelDs.Tables[0].Rows[i][j].ToString();
                    }
                    //如果表格第i行的第一列为空,则判断为这一行的数据为空,跳出循环并且不把数据写入 tb2
                    if (ExcelDs.Tables[0].Rows[i][0].ToString() == "")
                    {
                        continue;
                    }
                    else
                    {
                        tb2.Rows.Add(row);
                    }
                }
                var error = "";
                //查询工艺路线没有的列
                if (!tb2.Columns.Contains("组织编码"))
                    error += "没有找到【组织编码】的标题,";
                if (!tb2.Columns.Contains("组织"))
                    error += "没有找到【组织】的标题,";
                if (!tb2.Columns.Contains("车间代码"))
                    error += "没有找到【车间代码】的标题,";
                if (!tb2.Columns.Contains("车间"))
                    error += "没有找到【车间】的标题,";
                if (!tb2.Columns.Contains("物料代码"))
                    error += "没有找到【物料代码】的标题,";
                if (!tb2.Columns.Contains("物料名称"))
                    error += "没有找到【物料名称】的标题,";
                if (!tb2.Columns.Contains("规格型号"))
                    error += "没有找到【规格型号】的标题,";
                if (!tb2.Columns.Contains("JIT物料分类"))
                    error += "没有找到【JIT物料分类】的标题,";
                if (!tb2.Columns.Contains("JIT拉动安全库存量"))
                    error += "没有找到【JIT拉动安全库存量】的标题,";
                if (!tb2.Columns.Contains("JIT物料需求供货周期"))
                    error += "没有找到【JIT物料需求供货周期】的标题,";
                if (!tb2.Columns.Contains("JIT提货批量"))
                    error += "没有找到【JIT提货批量】的标题,";
                if (!tb2.Columns.Contains("JIT提货批量对应周期(天)"))
                    error += "没有找到【JIT提货批量对应周期(天)】的标题,";
                if (!tb2.Columns.Contains("JIT供货提前期(天)"))
                    error += "没有找到【JIT供货提前期(天)】的标题,";
                if (!tb2.Columns.Contains("JIT到货前置期(天)"))
                    error += "没有找到【JIT到货前置期(天)】的标题,";
                if (!tb2.Columns.Contains("JIT送货控制天数"))
                    error += "没有找到【JIT送货控制天数】的标题,";
                if (!tb2.Columns.Contains("JIT送货方式"))
                    error += "没有找到【JIT送货方式】的标题,";
                if (!tb2.Columns.Contains("备注"))
                    error += "没有找到【备注】的标题,";
                if (error.Length > 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = $"Excel模板存在错误,{error}\r\n";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                for (int i = 0; i <= tb2.Rows.Count - 1; i++)
                {
                    string HORGNumber = "";
                    string HORGName = "";
                    string HWorkShopNumer = "";
                    string HWorkShopName = "";
                    string HMaterNumer = "";
                    string HMaterName = "";
                    string HMaterModel = "";
                    string HUntilName = "";
                    string JITType = "";//JIT物料分类
                    string JIPEB = ""; //JIT提货经济批量
                    string JISLT = ""; //JIT供货提前期(天)
                    string JIDLT = ""; //JIT到货前置期(天)
                    string JIMLC = ""; //JIT最小起送量
                    HORGNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["组织编码"].ToString()).Replace("'","");
                    HORGName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["组织"].ToString());
                    HWorkShopNumer = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["车间代码"].ToString()).Replace("'", "");
                    HWorkShopName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["车间"].ToString());
                    HMaterNumer = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["物料代码"].ToString()).Replace("'", "");
                    HMaterName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["物料名称"].ToString());
                    HMaterModel = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["规格型号"].ToString());
                    JITType = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["JIT物料分类"].ToString());
                    JIPEB = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["JIT提货批量"].ToString());
                    JISLT = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["JIT供货提前期(天)"].ToString());
                    JIDLT = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["JIT到货前置期(天)"].ToString());
                    JIMLC = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["JIT送货方式"].ToString());
                    //检查物料
                    int index = i + 1;
                    if (HORGNumber != "")
                    {
                        //查询组织
                        ds = oCN.RunProcReturn("select * from Xt_ORGANIZATIONS where  HNumber='" + HORGNumber + "' and Hname='" + HORGName + "'", "Xt_ORGANIZATIONS");
                        if (ds.Tables[0].Rows.Count == 0)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "第" + index + "行,组织不存在!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        else
                        {
                            tb2.Rows[i]["HOrgID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
                        }
                        string HORGid = ds.Tables[0].Rows[0]["HItemID"].ToString();
                        //查询供应商
                        ds = oCN.RunProcReturn("select * from Gy_Department where  HNumber='" + HWorkShopNumer + "'  and HUSEORGID=" + HORGid + "", "Gy_Department");
                        if (ds.Tables[0].Rows.Count == 0)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "第" + index + "行,该" + HORGName + "组织,车间:" + HWorkShopName + ",不存在!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        else
                        {
                            tb2.Rows[i]["HWorkShopID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
                        }
                        //查询物料
                        ds = oCN.RunProcReturn("select * from Gy_Material where  HNumber='" + HMaterNumer + "' and HUSEORGID=" + HORGid + "", "Gy_Material");
                        if (ds.Tables[0].Rows.Count == 0)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "第" + index + "行,该" + HORGName + "组织,物料:" + HMaterName + ",物料代码:" + HMaterNumer + ",不存在!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        else
                        {
                            tb2.Rows[i]["HMaterID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
                        }
                        string msg = "";
                        oSystemParameter.ShowBill(ref msg);
                        if (oSystemParameter.omodel.WMS_CampanyName == "宝工")
                        {
                            //JIT供货提前期(天)
                            if (JISLT == "")
                            {
                                objJsonResult.code = "0";
                                objJsonResult.count = 0;
                                objJsonResult.Message = "第" + index + "行,JIT供货提前期(天)为空!";
                                objJsonResult.data = null;
                                return objJsonResult;
                            }
                            //JIT到货前置期(天)
                            if (JIDLT == "")
                            {
                                objJsonResult.code = "0";
                                objJsonResult.count = 0;
                                objJsonResult.Message = "第" + index + "行,JIT到货前置期(天)为空!";
                                objJsonResult.data = null;
                                return objJsonResult;
                            }
                        }
                        else
                        {
                            //JIT物料分类
                            if (JITType == "")
                            {
                                objJsonResult.code = "0";
                                objJsonResult.count = 0;
                                objJsonResult.Message = "第" + index + "行,JIT物料分类为空!";
                                objJsonResult.data = null;
                                return objJsonResult;
                            }
                            //JIT提货批量
                            if (JIPEB == "")
                            {
                                objJsonResult.code = "0";
                                objJsonResult.count = 0;
                                objJsonResult.Message = "第" + index + "行,JIT提货批量为空!";
                                objJsonResult.data = null;
                                return objJsonResult;
                            }
                            //JIT供货提前期(天)
                            if (JISLT == "")
                            {
                                objJsonResult.code = "0";
                                objJsonResult.count = 0;
                                objJsonResult.Message = "第" + index + "行,JIT供货提前期(天)为空!";
                                objJsonResult.data = null;
                                return objJsonResult;
                            }
                            //JIT到货前置期(天)
                            if (JIDLT == "")
                            {
                                objJsonResult.code = "0";
                                objJsonResult.count = 0;
                                objJsonResult.Message = "第" + index + "行,JIT到货前置期(天)为空!";
                                objJsonResult.data = null;
                                return objJsonResult;
                            }
                            //JIT最小起送量
                            if (JIMLC == "")
                            {
                                objJsonResult.code = "0";
                                objJsonResult.count = 0;
                                objJsonResult.Message = "第" + index + "行,JIT送货方式为空!";
                                objJsonResult.data = null;
                                return objJsonResult;
                            }
                            //审核代码是否合理
                            if (!DBUtility.ClsPub.AllowNumber(HMaterNumer))
                            {
                                objJsonResult.code = "0";
                                objJsonResult.count = 0;
                                objJsonResult.Message = "第" + index + "行,物料代码中不能出现连续‘.’并且首位末位不能为‘.’!";
                                objJsonResult.data = null;
                                return objJsonResult;
                            }
                        }
                    }
                    else
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "第" + index + "行,组织代码为空";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = error;
                objJsonResult.data = tb2;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region è¦æ–™è®¡åˆ’信息 å¯¼å…¥(保存)
        [Route("Sc_JIT_ComplementGoodBill/Sc_JIT_ComplementGoodBill_btnSave")]
        [HttpPost]
        public object Sc_JIT_ComplementGoodBill_btnSave([FromBody] JObject sMainSub)
        {
            var _value = sMainSub["sMainSub"].ToString();
            string msg1 = _value.ToString();
            string[] sArray = msg1.Split(new string[] { "&和" }, StringSplitOptions.RemoveEmptyEntries);
            string msg2 = sArray[0].ToString();
            string user = sArray[1].ToString();
            try
            {
                if (!DBUtility.ClsPub.Security_Log("JIT_NeedMaterPlanConfigBill_Edit", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无保存权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                List<object> Excel = Newtonsoft.Json.JsonConvert.DeserializeObject<List<object>>(msg2);
                List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
                foreach (JObject item in Excel)
                {
                    Dictionary<string, string> dic = new Dictionary<string, string>();
                    foreach (var itm in item.Properties())
                    {
                        dic.Add(itm.Name, itm.Value.ToString());
                    }
                    list.Add(dic);
                }
                oCN.BeginTran();
                int i = 1;
                foreach (Dictionary<string, string> item in list)
                {
                    string HWorkShopID = item["HWorkShopID"].ToString();//车间
                    string HMaterID = item["HMaterID"].ToString();//物料ID
                    string HOrgID = item["HOrgID"].ToString();//组织ID
                    string HWorkShopName = item["车间"].ToString();
                    string HMaterName = item["物料名称"].ToString();
                    string HMaterModel = item["规格型号"].ToString();
                    string JITType = item["JIT物料分类"].ToString();
                    string JITPSL = item["JIT拉动安全库存量"].ToString();
                    string JITMDSC = item["JIT物料需求供货周期"].ToString();
                    string JIPEB = item["JIT提货批量"].ToString();
                    string JITPBCC = item["JIT提货批量对应周期(天)"].ToString();
                    string JISLT = item["JIT供货提前期(天)"].ToString();
                    string JIDLT = item["JIT到货前置期(天)"].ToString();
                    string JITDCD = item["JIT送货控制天数"].ToString();
                    string JIMLC = item["JIT送货方式"].ToString();
                    string HRemark = item["备注"].ToString();
                    ds = oCN.RunProcReturn("select * from JIT_NeedMaterPlanConfigBillSub where HMaterID=" + HMaterID + " and HWorkShopID=" + HWorkShopID, "JIT_NeedMaterPlanConfigBillSub");
                    if (ds.Tables[0].Rows.Count == 0)
                    {
                        long HInterID = DBUtility.ClsPub.CreateBillID_Prod("4615", ref DBUtility.ClsPub.sExeReturnInfo);//获得一个新的id
                        string HBillNo = DBUtility.ClsPub.CreateBillCode_Prod("4615", ref DBUtility.ClsPub.sExeReturnInfo, true);//获得一个新的单据号
                        string sql = "insert into JIT_NeedMaterPlanConfigBillMain" +
                            "(HInterID,HBillNo,HYear,HPeriod,HBillType,HBillSubType,HDate,HBillStatus,HMaker,HMakeDate,HOrgId)" +
                            $"values({HInterID}, '{HBillNo}',{DateTime.Now.Year}, {DateTime.Now.Month}, '4615', '4615', GETDATE(), 1, '{user}', GETDATE(), {HOrgID})";
                        string sql1 = "insert into JIT_NeedMaterPlanConfigBillSub(HInterID,HEntryID,HRemark,HWorkShopID,HWorkShopName,HMaterID," +
                       "HMaterName, HMaterModel, HJITMaterGroup, HJITSafeStock, HJITMaterDemand, HJITBatchQty, HDeliveryPeriod, " +
                       "HLeadTime, HLeadTime_Sec, HDeliveryDaysCtrl, HDeliveryMode) values" +
                       $"({HInterID}, 1, '{HRemark}', {(HWorkShopID == "" ? "0" : HWorkShopID)}, '{HWorkShopName}', {(HMaterID == "" ? "0" : HMaterID)}," +
                       $" '{HMaterName}', '{HMaterModel}', '{JITType}', {(JITPSL == "" ? "0" : JITPSL)}, {(JITMDSC == "" ? "0" : JITMDSC)},{(JIPEB == "" ? "0" : JIPEB)},{(JITPBCC == "" ? "0" : JITPBCC)}," +
                       $" {(JISLT == "" ? "0" : JISLT)}, {(JIDLT == "" ? "0" : JIDLT)}, {(JITDCD == "" ? "0" : JITDCD)}, '{(JIMLC == "" ? "" : JIMLC)}')";
                        //主表
                        oCN.RunProc(sql);
                        //子表
                        oCN.RunProc(sql1);
                    }
                    else
                    {
                        oCN.RunProc("   update  JIT_NeedMaterPlanConfigBillMain set HLeadTime=" + JISLT + ",HLeadTime_Sec=" + JIDLT + "  where HMaterID=" + HMaterID + " and HWorkShopID = " + HWorkShopID);
                    }
                    i++;
                }
                oCN.Commit();
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "导入成功!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                LogService.Write(e);
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #endregion