You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
4.6 KiB

11 months ago
  1. using ICSSoft.ERPWMS.Entity;
  2. using Newtonsoft.Json;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace ICSSoft.ERPWMS.SQL
  10. {
  11. public class UpdatePurchasePlanParameter
  12. {
  13. public static Result Update(List<PurchasePlanParameterEntity> list)
  14. {
  15. Result res = new Result();
  16. try
  17. {
  18. string jsonstr = JsonConvert.SerializeObject(list);
  19. Log.WriteLogFile(jsonstr, "更新料品采购参数日志");
  20. StringBuilder sb = new StringBuilder();//接口返回Message
  21. foreach (PurchasePlanParameterEntity entity in list)
  22. {
  23. try
  24. {
  25. if (string.IsNullOrWhiteSpace(entity.cInvCode))
  26. {
  27. throw new Exception("存在物料编码为空!");
  28. }
  29. if (entity.fSupplyMulti == null)
  30. {
  31. throw new Exception("供应倍数为空!");
  32. }
  33. if (entity.iInvAdvance == null)
  34. {
  35. throw new Exception("固定提前期为空!");
  36. }
  37. if (string.IsNullOrWhiteSpace(entity.WorkPoint))
  38. {
  39. throw new Exception("站点为空!");
  40. }
  41. string WorkPoint = ICSHelper.GetConnectStringTest(entity.WorkPoint);
  42. if (WorkPoint == "NotExit")
  43. {
  44. throw new Exception("站点编码不存在!");
  45. }
  46. //检查物料代码是否存在
  47. string sqlCheck = "Select * from {0}.dbo.Inventory Where cInvCode ='{1}'";
  48. sqlCheck = string.Format(sqlCheck, WorkPoint, entity.cInvCode);
  49. DataTable dtCheck = ICSHelper.GetDataTableERP(sqlCheck);
  50. if (dtCheck.Rows.Count < 1)
  51. {
  52. throw new Exception("物料代码不存在!");
  53. }
  54. string sql = @"Update {0}.dbo.Inventory set fSupplyMulti ='{1}',iInvAdvance='{2}'";
  55. sql = string.Format(sql, WorkPoint, entity.fSupplyMulti, entity.iInvAdvance);
  56. if (entity.fMinSupply != null)
  57. {
  58. sql += ",fMinSupply='{0}'";
  59. sql = string.Format(sql, entity.fMinSupply);
  60. }
  61. sql += " Where cInvCode ='{0}';";
  62. sql = string.Format(sql, entity.cInvCode);
  63. if (entity.fMinSupply != null)
  64. {
  65. sql += " Update {0}.dbo.bas_part set MinQty ='{1}',MulQty ='{3}' where InvCode ='{2}';";
  66. sql = string.Format(sql, WorkPoint, entity.fMinSupply, entity.cInvCode,entity.fSupplyMulti);
  67. //sql += " update {0}.dbo.mps_currentstockfty set MinQty='{1}', MulQty ='{3}' where InvCode ='{2}';";
  68. //sql = string.Format(sql, WorkPoint, entity.fMinSupply, entity.cInvCode, entity.fSupplyMulti);
  69. }
  70. Log.WriteLogFile(sql, "更新料品采购参数SQL日志");
  71. if (ICSHelper.ExecuteSqlERP(sql) < 1)
  72. {
  73. throw new Exception("更新料品采购计划失败!");
  74. }
  75. }
  76. catch (Exception ex)
  77. {
  78. sb.Append("执行报错,物料编码为:" + entity.cInvCode + ",报错信息:" + ex.Message + "!!!");
  79. continue;
  80. }
  81. }
  82. if (sb.Length > 0)
  83. {
  84. res.IsSuccess = false;
  85. res.Message = sb.ToString();
  86. }
  87. else
  88. {
  89. res.IsSuccess = true;
  90. res.Message = "执行成功!";
  91. }
  92. return res;
  93. }
  94. catch (Exception ex)
  95. {
  96. res.IsSuccess = false;
  97. res.Message = ex.Message;
  98. return res;
  99. }
  100. }
  101. }
  102. }