zrg
2025-04-08 d54613ce0b6960dafcbd28454172f21a2d0bb6d1
WebAPI/Controllers/SCGL/Èռƻ®¹ÜÀí/Sc_JIT_ComplementGoodBillController.cs
@@ -1,11 +1,14 @@
using DBUtility;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Http;
using WebAPI.Controllers.SCGL.日计划管理;
using WebAPI.Models;
namespace WebAPI.Controllers.SCGL
@@ -19,6 +22,7 @@
        private json objJsonResult = new json();
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
        DataSet ds;
        Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
        #region æ—¥è®¡åˆ’平台基础资料 è½¦é—´ä»“库对照
@@ -29,6 +33,7 @@
        {
            try
            {
                List<object> a = new List<object>();
                //查询权限
                if (!DBUtility.ClsPub.Security_Log_second("JIT_ComplementGoodBill_Query", 1, false, user))
                {
@@ -40,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)
@@ -91,9 +102,8 @@
            string msg2 = sArray[0].ToString();
            string msg3 = sArray[1].ToString();
            int hentryid = int.Parse(sArray[2].ToString());//子表的顺序id
            int OperationType = int.Parse(sArray[3].ToString());//数据类型 1添加 3修改
            string user = sArray[4].ToString();
            int OperationType = int.Parse(sArray[2].ToString());//数据类型 1添加 3修改
            string user = sArray[3].ToString();
            try
            {
                if (!DBUtility.ClsPub.Security_Log("JIT_ComplementGoodBill_Edit", 1, false, user))
@@ -106,8 +116,23 @@
                }
                omdelMian = Newtonsoft.Json.JsonConvert.DeserializeObject<ClsXt_BaseBillMain>(msg2);
                if (omdelMian.HPRDORGID.ToString() == "")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "组织不能为空";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                string BillType = "4612";
                ds = ds = oCN.RunProcReturn($"select * from  h_v_JIT_Gy_WorkWarehouseBillList where hmainid={omdelMian.HInterID} and  å•据号='{omdelMian.HBillNo}'", "h_v_JIT_Gy_WorkWarehouseBillList");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    OperationType = 3;
                }
                if (OperationType == 1)//新增
                {
@@ -123,12 +148,9 @@
                ",HUpDater='" + omdelMian.HMaker + "'" +
                ",HUpDateDate='" + DateTime.Now+ "'" +
                " where HInterID=" + omdelMian.HInterID.ToString());
                    //删除子表
                    oCN.RunProc("delete from Gy_WorkWarehouseBillMainSub where HInterID='" + omdelMian.HInterID.ToString() + "' and HEntryID='" + hentryid + "'");
                }
                //保存子表
                objJsonResult = AddBillSub(msg3, hentryid);
                objJsonResult = AddBillSub(msg3);
                if (objJsonResult.code == "0")
                {
                    objJsonResult.code = "0";
@@ -154,9 +176,33 @@
            }
        }
        public json AddBillSub(string msg3, int hentryid)
        public json AddBillSub(string msg3)
        {
            omodelsub = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Gy_WorkWarehouseBillMainSub>>(msg3);
            foreach (Models.Gy_WorkWarehouseBillMainSub oSub in omodelsub)
            {
                if (oSub.HWorkShopID == 0 || oSub.HWorkShopID ==null)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "生产车间不能为空";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (oSub.HWHID == 0|| oSub.HWHID == null)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "仓库不能为空";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
            }
            //删除子表
            oCN.RunProc("delete from Gy_WorkWarehouseBillMainSub where HInterID='" + omdelMian.HInterID.ToString() + "'");
            int i = 1;
            //插入子表
            foreach (Models.Gy_WorkWarehouseBillMainSub oSub in omodelsub)
@@ -164,7 +210,7 @@
                oCN.RunProc("insert into Gy_WorkWarehouseBillMainSub(HInterID,HEntryID,HRemark,HWorkShopID," +
                    "HWorkShopName,HWHID,HWHName) " +
                   "values("
                   + omdelMian.HInterID.ToString() + "," + (hentryid == -1 ? i : hentryid) + ",'" + oSub.HRemark + "'," + (oSub.HWorkShopID==null?0:oSub.HWorkShopID)
                   + omdelMian.HInterID.ToString() + "," + i + ",'" + oSub.HRemark + "'," + (oSub.HWorkShopID==null?0:oSub.HWorkShopID)
                   + ",'" +oSub.HWorkShopName + "'," + (oSub.HWHID==null?0: oSub.HWHID) + ",'" + oSub.HWHName.ToString()+ "') ");
                i++;
            }
@@ -254,6 +300,7 @@
        {
            try
            {
                List<object> A = new List<object>();
                //查询权限
                if (!DBUtility.ClsPub.Security_Log_second("Cg_PODemandPlanConfigBill_Query", 1, false, user))
                {
@@ -265,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)
@@ -316,9 +370,8 @@
            string msg2 = sArray[0].ToString();//主表数据
            string msg3 = sArray[1].ToString();//子表数据
            int hentryid = int.Parse(sArray[2].ToString());//子表的顺序id
            int OperationType = int.Parse(sArray[3].ToString());//数据类型 1添加 3修改
            string user = sArray[4].ToString();
            int OperationType = int.Parse(sArray[2].ToString());//数据类型 1添加 3修改
            string user = sArray[3].ToString();
            try
            {
                if (!DBUtility.ClsPub.Security_Log("Cg_PODemandPlanConfigBill_Edit", 1, false, user))
@@ -333,6 +386,11 @@
                omdelMian = Newtonsoft.Json.JsonConvert.DeserializeObject<ClsXt_BaseBillMain>(msg2);
                string BillType = "4611";
                ds = ds = oCN.RunProcReturn($"select * from  h_v_JIT_Cg_PODemandPlanConfigBillList where hmainid={omdelMian.HInterID} and  å•据号='{omdelMian.HBillNo}'", "h_v_JIT_Cg_PODemandPlanConfigBillList");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    OperationType = 3;
                }
                if (OperationType == 1)//新增
                {
@@ -348,12 +406,9 @@
                ",HUpDater='" + omdelMian.HMaker + "'" +
                ",HUpDateDate='" + DateTime.Now + "'" +
                " where HInterID=" + omdelMian.HInterID.ToString());
                    //删除子表
                    oCN.RunProc("delete from Cg_PODemandPlanConfigBillSub where HInterID='" + omdelMian.HInterID.ToString() + "' and HEntryID='" + hentryid + "'");
                }
                //保存子表
                objJsonResult = AddPODBillSub(msg3, hentryid);
                objJsonResult = AddPODBillSub(msg3);
                if (objJsonResult.code == "0")
                {
                    objJsonResult.code = "0";
@@ -379,9 +434,64 @@
            }
        }
        public json AddPODBillSub(string msg3, int hentryid)
        public json AddPODBillSub(string msg3)
        {
            string Ret = "";
            oSystemParameter.ShowBill(ref Ret);
            omodelPODsub = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Cg_PODemandPlanConfigBillSub>>(msg3);
            foreach (Models.Cg_PODemandPlanConfigBillSub oSub in omodelPODsub)
            {
                if (oSub.HSupplierID == 0 || oSub.HSupplierID == null)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "供应商不能为空";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (oSub.HMaterID == 0 || oSub.HMaterID == null)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "物料不能为空";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (oSub.HLeadTime == 0 || oSub.HLeadTime == null)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = " JIT供货提前期不能为空";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (oSystemParameter.omodel.WMS_CampanyName != "帅威"&& oSystemParameter.omodel.WMS_CampanyName != "宝工" && oSystemParameter.omodel.WMS_CampanyName != "三升")
                {
                    if (oSub.HLeadTime_Sec == 0 || oSub.HLeadTime_Sec == null)
                    {
                        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;
                    }
                }
            }
            //删除子表
            oCN.RunProc("delete from Cg_PODemandPlanConfigBillSub where HInterID='" + omdelMian.HInterID.ToString() + "'");
            int i = 1;
            //插入子表
            foreach (Models.Cg_PODemandPlanConfigBillSub oSub in omodelPODsub)
@@ -389,7 +499,7 @@
                oCN.RunProc("insert into Cg_PODemandPlanConfigBillSub(HInterID,HEntryID,HRemark,HSupplierID,HSupplierName,HMaterID," +
                    "HMaterName, HMaterModel, HJITMaterGroup, HJITSafeStock, HJITMaterDemand, HJITBatchQty, HDeliveryPeriod, " +
                    "HLeadTime, HLeadTime_Sec, HDeliveryMode, HDeliveryDaysCtrl)values" +
                    $"({omdelMian.HInterID}, {(hentryid == -1 ? i : hentryid) }, '{oSub.HRemark}', {(oSub.HSupplierID==null?0: oSub.HSupplierID)}, '{oSub.HSupplierName}', {(oSub.HMaterID == null ? 0 : oSub.HMaterID)}," +
                    $"({omdelMian.HInterID}, {i}, '{oSub.HRemark}', {(oSub.HSupplierID==null?0: oSub.HSupplierID)}, '{oSub.HSupplierName}', {(oSub.HMaterID == null ? 0 : oSub.HMaterID)}," +
                    $" '{oSub.HMaterName}', '{oSub.HMaterModel}', '{oSub.HJITMaterGroup}', {(oSub.HJITSafeStock == null ? 0 : oSub.HJITSafeStock)}, {(oSub.HJITMaterDemand == null ? 0 : oSub.HJITMaterDemand)},{(oSub.HJITBatchQty == null ? 0 : oSub.HJITBatchQty)},{(oSub.HDeliveryPeriod == null ? 0 : oSub.HDeliveryPeriod)}," +
                    $" {(oSub.HLeadTime == null ? 0 : oSub.HLeadTime)}, {(oSub.HLeadTime_Sec == null ? 0 : oSub.HLeadTime_Sec)}, '{oSub.HDeliveryMode}', {(oSub.HDeliveryDaysCtrl == null ? 0 : oSub.HDeliveryDaysCtrl)}) ");
                i++;
@@ -469,6 +579,428 @@
        }
        #endregion
        #region ææ–™è®¡åˆ’信息 æ–‡ä»¶ä¸Šä¼ 
        [Route("Cg_PODemandPlanConfigBill/Cg_PODemandPlanConfigBill_Excel")]
        [HttpPost]
        public object Cg_PODemandPlanConfigBill_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("HSupID", typeof(Int32));//供应商
                tb2.Columns.Add("HMaterID", typeof(Int32));//物料ID
                tb2.Columns.Add("HUnitID", typeof(Int32));//计量单位
                //添加数据
                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("计量单位"))
                    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 HSupNumer = "";
                    string HSupName = "";
                    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());
                    HORGName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["组织"].ToString());
                    HSupNumer = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["供应商代码"].ToString());
                    HSupName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["供应商"].ToString());
                    HMaterNumer = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["物料代码"].ToString());
                    HMaterName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["物料名称"].ToString());
                    HMaterModel = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["规格型号"].ToString());
                    HUntilName = 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_Supplier where  HNumber='" + HSupNumer + "'  and HUSEORGID=" + HORGid + "", "Gy_Supplier");
                        if (ds.Tables[0].Rows.Count == 0)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "第" + index + "行,该" + HORGName + "组织,供应商:"+ HSupName + ",不存在!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        else
                        {
                            tb2.Rows[i]["HSupID"] = 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();
                        }
                        //查询计量单位
                        ds = oCN.RunProcReturn("select * from Gy_Unit where  HName='" + HUntilName + "' ", "Gy_Unit"); //and HUSEORGID=" + HORGid + "
                        if (ds.Tables[0].Rows.Count == 0)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "第" + index + "行,该" + HORGName + "组织,计量单位:"+ HUntilName + ",不存在!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        else
                        {
                            tb2.Rows[i]["HUnitID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
                        }
                        //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("Cg_PODemandPlanConfigBill/Cg_PODemandPlanConfigBill_btnSave")]
        [HttpPost]
        public object Cg_PODemandPlanConfigBill_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("Cg_PODemandPlanConfigBill_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 HSupID = item["HSupID"].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();//计量单位
                    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 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})";
                        //主表
                        oCN.RunProc(sql);
                        //子表
                        oCN.RunProc(sql1);
                    }
                    else
                    {
                        oCN.RunProc("   update  Cg_PODemandPlanConfigBillSub set HLeadTime=" + JISLT + "  where HMaterID=" + HMaterID + " and HSupplierID=" + HSupID);
                    }
                    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
        #region æ—¥è®¡åˆ’平台基础资料 è¦æ–™è®¡åˆ’信息
@@ -542,9 +1074,8 @@
            string msg2 = sArray[0].ToString();//主表数据
            string msg3 = sArray[1].ToString();//子表数据
            int hentryid = int.Parse(sArray[2].ToString());//子表的顺序id
            int OperationType = int.Parse(sArray[3].ToString());//数据类型 1添加 3修改
            string user = sArray[4].ToString();
            int OperationType = int.Parse(sArray[2].ToString());//数据类型 1添加 3修改
            string user = sArray[3].ToString();
            try
            {
                if (!DBUtility.ClsPub.Security_Log("JIT_NeedMaterPlanConfigBill_Edit", 1, false, user))
@@ -558,6 +1089,12 @@
                omdelMian = Newtonsoft.Json.JsonConvert.DeserializeObject<ClsXt_BaseBillMain>(msg2);
                string BillType = "4615";
                ds = ds = oCN.RunProcReturn($"select * from  h_v_JIT_NeedMaterPlanConfigBillList where hmainid={omdelMian.HInterID} and  å•据号='{omdelMian.HBillNo}'", "h_v_JIT_NeedMaterPlanConfigBillList");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    OperationType = 3;
                }
                if (OperationType == 1)//新增
@@ -575,12 +1112,9 @@
                ",HUpDater='" + omdelMian.HMaker + "'" +
                ",HUpDateDate='" + DateTime.Now + "'" +
                " where HInterID=" + omdelMian.HInterID.ToString());
                    //删除子表
                    oCN.RunProc("delete from JIT_NeedMaterPlanConfigBillSub where HInterID='" + omdelMian.HInterID.ToString() + "' and HEntryID='" + hentryid + "'");
                }
                //保存子表
                objJsonResult = AddNeedBillSub(msg3, hentryid);
                objJsonResult = AddNeedBillSub(msg3);
                if (objJsonResult.code == "0")
                {
                    objJsonResult.code = "0";
@@ -606,9 +1140,62 @@
            }
        }
        public json AddNeedBillSub(string msg3, int hentryid)
        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)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "生产车间不能为空";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (oSub.HMaterID == 0 || oSub.HMaterID == null)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "物料不能为空";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (oSub.HLeadTime == 0 || oSub.HLeadTime == null)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = " JIT供货提前期不能为空";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (oSub.HLeadTime_Sec == 0 || oSub.HLeadTime_Sec == null)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = " JIT到货前置期不能为空";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (oSystemParameter.omodel.WMS_CampanyName != "宝工"&& oSystemParameter.omodel.WMS_CampanyName != "三升")
                {
                    if (oSub.HDeliveryDaysCtrl == 0 || oSub.HDeliveryDaysCtrl == null)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = " JIT送货控制天数不能为空";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
            }
            //删除子表
            oCN.RunProc("delete from JIT_NeedMaterPlanConfigBillSub where HInterID='" + omdelMian.HInterID.ToString() + "'");
            int i = 1;
            //插入子表
            foreach (Models.JIT_NeedMaterPlanConfigBillSub oSub in omodelNeedsub)
@@ -616,7 +1203,7 @@
                oCN.RunProc("insert into JIT_NeedMaterPlanConfigBillSub(HInterID,HEntryID,HRemark,HWorkShopID,HWorkShopName,HMaterID," +
                    "HMaterName, HMaterModel, HJITMaterGroup, HJITSafeStock, HJITMaterDemand, HJITBatchQty, HDeliveryPeriod, " +
                    "HLeadTime, HLeadTime_Sec, HDeliveryMode, HDeliveryDaysCtrl)values" +
                    $"({omdelMian.HInterID}, {(hentryid == -1 ? i : hentryid) }, '{oSub.HRemark}', {(oSub.HWorkShopID == null ? 0 : oSub.HWorkShopID)}, '{oSub.HWorkShopName}', {(oSub.HMaterID == null ? 0 : oSub.HMaterID)}," +
                    $"({omdelMian.HInterID}, {i}, '{oSub.HRemark}', {(oSub.HWorkShopID == null ? 0 : oSub.HWorkShopID)}, '{oSub.HWorkShopName}', {(oSub.HMaterID == null ? 0 : oSub.HMaterID)}," +
                    $" '{oSub.HMaterName}', '{oSub.HMaterModel}', '{oSub.HJITMaterGroup}', {(oSub.HJITSafeStock == null ? 0 : oSub.HJITSafeStock)}, {(oSub.HJITMaterDemand == null ? 0 : oSub.HJITMaterDemand)},{(oSub.HJITBatchQty == null ? 0 : oSub.HJITBatchQty)},{(oSub.HDeliveryPeriod == null ? 0 : oSub.HDeliveryPeriod)}," +
                    $" {(oSub.HLeadTime == null ? 0 : oSub.HLeadTime)}, {(oSub.HLeadTime_Sec == null ? 0 : oSub.HLeadTime_Sec)}, '{oSub.HDeliveryMode}', {(oSub.HDeliveryDaysCtrl == null ? 0 : oSub.HDeliveryDaysCtrl)}) ");
                i++;