using ICSSoft.ERPWMS.Entity; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ICSSoft.ERPWMS.SQL { public class UpdatePurchasePlanParameter { public static Result Update(List list) { Result res = new Result(); try { string jsonstr = JsonConvert.SerializeObject(list); Log.WriteLogFile(jsonstr, "更新料品采购参数日志"); StringBuilder sb = new StringBuilder();//接口返回Message foreach (PurchasePlanParameterEntity entity in list) { try { if (string.IsNullOrWhiteSpace(entity.cInvCode)) { throw new Exception("存在物料编码为空!"); } if (entity.fSupplyMulti == null) { throw new Exception("供应倍数为空!"); } if (entity.iInvAdvance == null) { throw new Exception("固定提前期为空!"); } if (string.IsNullOrWhiteSpace(entity.WorkPoint)) { throw new Exception("站点为空!"); } string WorkPoint = ICSHelper.GetConnectStringTest(entity.WorkPoint); if (WorkPoint == "NotExit") { throw new Exception("站点编码不存在!"); } //检查物料代码是否存在 string sqlCheck = "Select * from {0}.dbo.Inventory Where cInvCode ='{1}'"; sqlCheck = string.Format(sqlCheck, WorkPoint, entity.cInvCode); DataTable dtCheck = ICSHelper.GetDataTableERP(sqlCheck); if (dtCheck.Rows.Count < 1) { throw new Exception("物料代码不存在!"); } string sql = @"Update {0}.dbo.Inventory set fSupplyMulti ='{1}',iInvAdvance='{2}'"; sql = string.Format(sql, WorkPoint, entity.fSupplyMulti, entity.iInvAdvance); if (entity.fMinSupply != null) { sql += ",fMinSupply='{0}'"; sql = string.Format(sql, entity.fMinSupply); } sql += " Where cInvCode ='{0}';"; sql = string.Format(sql, entity.cInvCode); if (entity.fMinSupply != null) { sql += " Update {0}.dbo.bas_part set MinQty ='{1}',MulQty ='{3}' where InvCode ='{2}';"; sql = string.Format(sql, WorkPoint, entity.fMinSupply, entity.cInvCode,entity.fSupplyMulti); //sql += " update {0}.dbo.mps_currentstockfty set MinQty='{1}', MulQty ='{3}' where InvCode ='{2}';"; //sql = string.Format(sql, WorkPoint, entity.fMinSupply, entity.cInvCode, entity.fSupplyMulti); } Log.WriteLogFile(sql, "更新料品采购参数SQL日志"); if (ICSHelper.ExecuteSqlERP(sql) < 1) { throw new Exception("更新料品采购计划失败!"); } } catch (Exception ex) { sb.Append("执行报错,物料编码为:" + entity.cInvCode + ",报错信息:" + ex.Message + "!!!"); continue; } } if (sb.Length > 0) { res.IsSuccess = false; res.Message = sb.ToString(); } else { res.IsSuccess = true; res.Message = "执行成功!"; } return res; } catch (Exception ex) { res.IsSuccess = false; res.Message = ex.Message; return res; } } } }