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 { public class Sc_JIT_ComplementGoodBillController : ApiController { ClsXt_BaseBillMain omdelMian = new ClsXt_BaseBillMain(); List omodelsub = new List(); List omodelPODsub = new List(); List omodelNeedsub = new List(); private json objJsonResult = new json(); SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); DataSet ds; Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter(); #region 日计划平台基础资料 车间仓库对照 #region 车间仓库对照列表 [Route("Sc_JIT_ComplementGoodBill/ComplementGoodBillList")] [HttpGet] public object ComplementGoodBillList(string sWhere, string user) { try { List a = new List(); //查询权限 if (!DBUtility.ClsPub.Security_Log_second("JIT_ComplementGoodBill_Query", 1, false, user)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无权限查询!"; objJsonResult.data = null; return objJsonResult; } 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) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 车间仓库对照 添加/修改 [Route("Sc_JIT_ComplementGoodBill/AddComplementGoodBillList")] [HttpPost] public object AddComplementGoodBillList([FromBody] JObject sMainSub) { var _value = sMainSub["sMainSub"].ToString(); string msg1 = _value.ToString(); oCN.BeginTran(); //保存主表 objJsonResult = AddBillMain(msg1); if (objJsonResult.code == "0") { oCN.RollBack(); objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = objJsonResult.Message; objJsonResult.data = null; return objJsonResult; } oCN.Commit(); objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "新增单据成功!"; objJsonResult.data = null; return objJsonResult; } public json AddBillMain(string msg1) { string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); string msg2 = sArray[0].ToString(); string msg3 = sArray[1].ToString(); int OperationType = int.Parse(sArray[2].ToString());//数据类型 1添加 3修改 string user = sArray[3].ToString(); try { if (!DBUtility.ClsPub.Security_Log("JIT_ComplementGoodBill_Edit", 1, false, user)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无保存权限!"; objJsonResult.data = null; return objJsonResult; } omdelMian = Newtonsoft.Json.JsonConvert.DeserializeObject(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)//新增 { //主表 oCN.RunProc("insert into Gy_WorkWarehouseBillMain(HInterID,HBillNo,HYear,HPeriod,HBillType,HBillSubType,HDate,HBillStatus,HMaker,HMakeDate,HOrgId)" + $"values({omdelMian.HInterID}, '{omdelMian.HBillNo}',{DateTime.Now.Year}, {DateTime.Now.Month}, '{BillType}', '{BillType}', GETDATE(), 1, '{omdelMian.HMaker}', GETDATE(),{omdelMian.HPRDORGID})"); } else if (OperationType == 3) { //修改 oCN.RunProc("UpDate Gy_WorkWarehouseBillMain set " + " HOrgId='" + omdelMian.HPRDORGID + "'" + ",HUpDater='" + omdelMian.HMaker + "'" + ",HUpDateDate='" + DateTime.Now+ "'" + " where HInterID=" + omdelMian.HInterID.ToString()); } //保存子表 objJsonResult = AddBillSub(msg3); if (objJsonResult.code == "0") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = objJsonResult.Message; objJsonResult.data = null; return objJsonResult; } objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = null; objJsonResult.data = null; return objJsonResult; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "Exception!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } public json AddBillSub(string msg3) { omodelsub = Newtonsoft.Json.JsonConvert.DeserializeObject>(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) { oCN.RunProc("insert into Gy_WorkWarehouseBillMainSub(HInterID,HEntryID,HRemark,HWorkShopID," + "HWorkShopName,HWHID,HWHName) " + "values(" + omdelMian.HInterID.ToString() + "," + i + ",'" + oSub.HRemark + "'," + (oSub.HWorkShopID==null?0:oSub.HWorkShopID) + ",'" +oSub.HWorkShopName + "'," + (oSub.HWHID==null?0: oSub.HWHID) + ",'" + oSub.HWHName.ToString()+ "') "); i++; } objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = null; objJsonResult.data = null; return objJsonResult; } #endregion #region 车间仓库对照删除 [Route("Sc_JIT_ComplementGoodBill/DelComplementGoodBillList")] [HttpGet] public object DelComplementGoodBillList(string HInterID, string HEntryID, string User) { try { //删除权限 if (!DBUtility.ClsPub.Security_Log_second("JIT_ComplementGoodBill_Drop", 1, false, User)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无权限删除!"; objJsonResult.data = null; return objJsonResult; } ds = oCN.RunProcReturn("select * from h_v_JIT_Gy_WorkWarehouseBillList where 1=1 and hmainid=" + HInterID, "h_v_JIT_Gy_WorkWarehouseBillList"); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["单据状态"].ToString() != "1") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "当前单据不能删除!"; objJsonResult.data = null; return objJsonResult; } oCN.BeginTran();//开启事务 if (ds.Tables[0].Rows.Count == 1) { oCN.RunProc($"delete from Gy_WorkWarehouseBillMain where HInterID={HInterID}"); } oCN.RunProc($"delete from Gy_WorkWarehouseBillMainSub where HInterID={HInterID} and HEntryID={HEntryID}"); oCN.Commit();//结束事务 objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "删除成功!"; objJsonResult.data = null; return objJsonResult; } objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "当前单据不存在,无法删除!"; objJsonResult.data = null; return objJsonResult; } catch (Exception e) { oCN.RollBack();//回滚事务 objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #endregion #region 日计划平台基础资料 提料计划信息 #region 提料计划信息列表 [Route("Sc_JIT_ComplementGoodBill/PODemandPlanConfigBillList")] [HttpGet] public object PODemandPlanConfigBillList(string sWhere, string user) { try { List A = new List(); //查询权限 if (!DBUtility.ClsPub.Security_Log_second("Cg_PODemandPlanConfigBill_Query", 1, false, user)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无权限查询!"; objJsonResult.data = null; return objJsonResult; } 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) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 提料计划信息 添加/修改 [Route("Sc_JIT_ComplementGoodBill/AddPODemandPlanConfigBillList")] [HttpPost] public object AddPODemandPlanConfigBillList([FromBody] JObject sMainSub) { var _value = sMainSub["sMainSub"].ToString(); string msg1 = _value.ToString(); oCN.BeginTran(); //保存主表 objJsonResult = AddPODBillMain(msg1); if (objJsonResult.code == "0") { oCN.RollBack(); objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = objJsonResult.Message; objJsonResult.data = null; return objJsonResult; } oCN.Commit(); objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "新增单据成功!"; objJsonResult.data = null; return objJsonResult; } public json AddPODBillMain(string msg1) { string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); string msg2 = sArray[0].ToString();//主表数据 string msg3 = sArray[1].ToString();//子表数据 int OperationType = int.Parse(sArray[2].ToString());//数据类型 1添加 3修改 string user = sArray[3].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; } omdelMian = Newtonsoft.Json.JsonConvert.DeserializeObject(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)//新增 { //主表 oCN.RunProc("insert into Cg_PODemandPlanConfigBillMain(HInterID,HBillNo,HYear,HPeriod,HBillType,HBillSubType,HDate,HBillStatus,HMaker,HMakeDate,HOrgId)" + $"values({omdelMian.HInterID}, '{omdelMian.HBillNo}',{DateTime.Now.Year}, {DateTime.Now.Month}, '{BillType}', '{BillType}', GETDATE(), 1, '{omdelMian.HMaker}', GETDATE(), {omdelMian.HPRDORGID})"); } else if (OperationType == 3) { //修改 oCN.RunProc("UpDate Cg_PODemandPlanConfigBillMain set " + " HOrgId='" + omdelMian.HPRDORGID + "'" + ",HUpDater='" + omdelMian.HMaker + "'" + ",HUpDateDate='" + DateTime.Now + "'" + " where HInterID=" + omdelMian.HInterID.ToString()); } //保存子表 objJsonResult = AddPODBillSub(msg3); if (objJsonResult.code == "0") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = objJsonResult.Message; objJsonResult.data = null; return objJsonResult; } objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = null; objJsonResult.data = null; return objJsonResult; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "Exception!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } public json AddPODBillSub(string msg3) { string Ret = ""; oSystemParameter.ShowBill(ref Ret); omodelPODsub = Newtonsoft.Json.JsonConvert.DeserializeObject>(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) { 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}, {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++; } objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = null; objJsonResult.data = null; return objJsonResult; } #endregion #region 提料计划信息删除 [Route("Sc_JIT_ComplementGoodBill/DelPODemandPlanConfigBillList")] [HttpGet] public object DelPODemandPlanConfigBillList(string HInterID, string HEntryID, string User) { try { //删除权限 if (!DBUtility.ClsPub.Security_Log_second("Cg_PODemandPlanConfigBill_Drop", 1, false, User)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无权限删除!"; objJsonResult.data = null; return objJsonResult; } ds = oCN.RunProcReturn("select * from h_v_JIT_Cg_PODemandPlanConfigBillList where 1=1 and hmainid=" + HInterID, "h_v_JIT_Cg_PODemandPlanConfigBillList"); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["单据状态"].ToString() != "1") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "当前单据不能删除!"; objJsonResult.data = null; return objJsonResult; } oCN.BeginTran();//开启事务 if (ds.Tables[0].Rows.Count == 1) { oCN.RunProc($"delete from Cg_PODemandPlanConfigBillMain where HInterID={HInterID}"); } oCN.RunProc($"delete from Cg_PODemandPlanConfigBillSub where HInterID={HInterID} and HEntryID={HEntryID}"); oCN.Commit();//结束事务 objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "删除成功!"; objJsonResult.data = null; return objJsonResult; } objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "当前单据不存在,无法删除!"; objJsonResult.data = null; return objJsonResult; } catch (Exception e) { oCN.RollBack();//回滚事务 objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 提料计划信息 文件上传 [Route("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()).Replace("'", ""); HORGName = 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()).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()); 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(); } 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; } } 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("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 Excel = Newtonsoft.Json.JsonConvert.DeserializeObject>(msg2); List> list = new List>(); foreach (JObject item in Excel) { Dictionary dic = new Dictionary(); foreach (var itm in item.Properties()) { dic.Add(itm.Name, itm.Value.ToString()); } list.Add(dic); } oCN.BeginTran(); int i = 1; foreach (Dictionary 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==""?"0": 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 日计划平台基础资料 要料计划信息 #region 要料计划信息列表 [Route("Sc_JIT_ComplementGoodBill/NeedMaterPlanConfigBillList")] [HttpGet] public object NeedMaterPlanConfigBillList(string sWhere, string user) { try { //查询权限 if (!DBUtility.ClsPub.Security_Log_second("JIT_NeedMaterPlanConfigBill_Query", 1, false, user)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无权限查询!"; objJsonResult.data = null; return objJsonResult; } ds = oCN.RunProcReturn("select * from h_v_JIT_NeedMaterPlanConfigBillList where 1=1 " + sWhere + " order by hmainid desc ", "h_v_JIT_NeedMaterPlanConfigBillList"); objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "Sucess!"; objJsonResult.data = ds.Tables[0]; return objJsonResult; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 要料计划信息列表 添加/修改 [Route("Sc_JIT_ComplementGoodBill/AddNeedMaterPlanConfigBillList")] [HttpPost] public object AddNeedMaterPlanConfigBillList([FromBody] JObject sMainSub) { var _value = sMainSub["sMainSub"].ToString(); string msg1 = _value.ToString(); oCN.BeginTran(); //保存主表 objJsonResult = AddNeedBillMain(msg1); if (objJsonResult.code == "0") { oCN.RollBack(); objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = objJsonResult.Message; objJsonResult.data = null; return objJsonResult; } oCN.Commit(); objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "新增单据成功!"; objJsonResult.data = null; return objJsonResult; } public json AddNeedBillMain(string msg1) { string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); string msg2 = sArray[0].ToString();//主表数据 string msg3 = sArray[1].ToString();//子表数据 int OperationType = int.Parse(sArray[2].ToString());//数据类型 1添加 3修改 string user = sArray[3].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; } omdelMian = Newtonsoft.Json.JsonConvert.DeserializeObject(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)//新增 { //主表 oCN.RunProc("insert into JIT_NeedMaterPlanConfigBillMain(HInterID,HBillNo,HYear,HPeriod,HBillType,HBillSubType,HDate,HBillStatus,HMaker,HMakeDate,HOrgId)" + $"values({omdelMian.HInterID}, '{omdelMian.HBillNo}',{DateTime.Now.Year}, {DateTime.Now.Month}, '{BillType}', '{BillType}', GETDATE(), 1, '{omdelMian.HMaker}', GETDATE(), {omdelMian.HPRDORGID})"); } else if (OperationType == 3) { //修改 oCN.RunProc("UpDate JIT_NeedMaterPlanConfigBillMain set " + " HOrgId='" + omdelMian.HPRDORGID + "'" + ",HUpDater='" + omdelMian.HMaker + "'" + ",HUpDateDate='" + DateTime.Now + "'" + " where HInterID=" + omdelMian.HInterID.ToString()); } //保存子表 objJsonResult = AddNeedBillSub(msg3); if (objJsonResult.code == "0") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = objJsonResult.Message; objJsonResult.data = null; return objJsonResult; } objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = null; objJsonResult.data = null; return objJsonResult; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "Exception!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } public json AddNeedBillSub(string msg3) { string Ret = ""; omodelNeedsub = Newtonsoft.Json.JsonConvert.DeserializeObject>(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) { 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}, {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++; } objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = null; objJsonResult.data = null; return objJsonResult; } #endregion #region 要料计划信息删除 [Route("Sc_JIT_ComplementGoodBill/DelNeedMaterPlanConfigBillList")] [HttpGet] public object DelNeedMaterPlanConfigBillList(string HInterID, string HEntryID, string User) { try { //删除权限 if (!DBUtility.ClsPub.Security_Log_second("JIT_NeedMaterPlanConfigBill_Drop", 1, false, User)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无权限删除!"; objJsonResult.data = null; return objJsonResult; } ds = oCN.RunProcReturn("select * from h_v_JIT_NeedMaterPlanConfigBillList where 1=1 and hmainid=" + HInterID, "h_v_JIT_NeedMaterPlanConfigBillList"); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["单据状态"].ToString() != "1") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "当前单据不能删除!"; objJsonResult.data = null; return objJsonResult; } oCN.BeginTran();//开启事务 if (ds.Tables[0].Rows.Count == 1) { oCN.RunProc($"delete from JIT_NeedMaterPlanConfigBillMain where HInterID={HInterID}"); } oCN.RunProc($"delete from JIT_NeedMaterPlanConfigBillSub where HInterID={HInterID} and HEntryID={HEntryID}"); oCN.Commit();//结束事务 objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "删除成功!"; objJsonResult.data = null; return objJsonResult; } objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "当前单据不存在,无法删除!"; objJsonResult.data = null; return objJsonResult; } catch (Exception e) { oCN.RollBack();//回滚事务 objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 提料计划信息 文件上传 [Route("Sc_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 Excel = Newtonsoft.Json.JsonConvert.DeserializeObject>(msg2); List> list = new List>(); foreach (JObject item in Excel) { Dictionary dic = new Dictionary(); foreach (var itm in item.Properties()) { dic.Add(itm.Name, itm.Value.ToString()); } list.Add(dic); } oCN.BeginTran(); int i = 1; foreach (Dictionary 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 } }