飞依诺接口
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.

104 lines
4.0 KiB

2 years 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. Log.WriteLogFile(sql, "更新料品采购参数SQL日志");
  64. if (ICSHelper.ExecuteSqlERP(sql) < 1)
  65. {
  66. throw new Exception("更新料品采购计划失败!");
  67. }
  68. }
  69. catch (Exception ex)
  70. {
  71. sb.Append("执行报错,物料编码为:" + entity.cInvCode + ",报错信息:" + ex.Message + "!!!");
  72. continue;
  73. }
  74. }
  75. if (sb.Length > 0)
  76. {
  77. res.IsSuccess = false;
  78. res.Message = sb.ToString();
  79. }
  80. else
  81. {
  82. res.IsSuccess = true;
  83. res.Message = "执行成功!";
  84. }
  85. return res;
  86. }
  87. catch (Exception ex)
  88. {
  89. res.IsSuccess = false;
  90. res.Message = ex.Message;
  91. return res;
  92. }
  93. }
  94. }
  95. }