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.

152 lines
7.1 KiB

5 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 ReplyPOArrivalDate
  12. {
  13. public static Result Update(List<ReplyPOArrivalDateEntity> entityList)
  14. {
  15. Result res = new Result();
  16. try
  17. {
  18. string jsonstr = JsonConvert.SerializeObject(entityList);
  19. Log.WriteLogFile(jsonstr, "回复预计到货日期日志");
  20. StringBuilder sb = new StringBuilder();//接口返回Message
  21. foreach (ReplyPOArrivalDateEntity entity in entityList)
  22. {
  23. try
  24. {
  25. if (string.IsNullOrWhiteSpace(entity.POCode))
  26. {
  27. throw new Exception("存在订单号为空!");
  28. }
  29. if (entity.Sequence == null)
  30. {
  31. throw new Exception("订单行号为空!");
  32. }
  33. if (entity.SubSequence == null)
  34. {
  35. throw new Exception("SRM拆行为空!");
  36. }
  37. if (entity.Quantity == null)
  38. {
  39. throw new Exception("预计到货数量为空!");
  40. }
  41. if (string.IsNullOrWhiteSpace(entity.dReplyArriveDate))
  42. {
  43. throw new Exception("预计到货日期为空!");
  44. }
  45. if (string.IsNullOrWhiteSpace(entity.WorkPoint))
  46. {
  47. throw new Exception("站点参数为空!");
  48. }
  49. string WorkPoint = ICSHelper.GetConnectStringTest(entity.WorkPoint);
  50. if (WorkPoint == "NotExit")
  51. {
  52. throw new Exception("站点编码不存在!");
  53. }
  54. //验证采购订单是否存在
  55. string sqlCheck = "Select cPOID from {0}.dbo.PO_Pomain where cPOID ='{1}'";
  56. sqlCheck = string.Format(sqlCheck, WorkPoint, entity.POCode);
  57. DataTable dtCheck = ICSHelper.GetDataTableERP(sqlCheck);
  58. if (dtCheck.Rows.Count<1)
  59. {
  60. //验证委外订单是否存在
  61. sqlCheck = "Select cCode From {0}.dbo.OM_MOMain Where cCode='{1}'";
  62. sqlCheck = String.Format(sqlCheck,WorkPoint, entity.POCode);
  63. dtCheck = ICSHelper.GetDataTableERP(sqlCheck);
  64. if (dtCheck!=null&&dtCheck.Rows.Count>0)
  65. {
  66. //验证委外订单明细是否存在
  67. string sqldetail = "Select MODetailsID from {0}.dbo.OM_MODetails where MOID =(Select MOID from {0}.dbo.OM_MOMain where cCode ='{1}') and ivouchrowno ='{2}'";
  68. sqldetail = string.Format(sqldetail, WorkPoint, entity.POCode, entity.Sequence);
  69. DataTable dtDetail = ICSHelper.GetDataTableERP(sqldetail);
  70. if (dtDetail != null && dtDetail.Rows.Count > 0)
  71. {
  72. string Total = entity.SubSequence.ToString() + ":" + entity.Quantity.ToString() + "-[" + entity.dReplyArriveDate + "]";
  73. string sql = @"Update {0}.dbo.OM_MODetails Set cdefine28 ='{1}' Where MODetailsID='{2}'";
  74. sql = string.Format(sql, WorkPoint, Total, dtDetail.Rows[0]["MODetailsID"].ToString());
  75. Log.WriteLogFile(sql, "回复预计到货日期SQL日志");
  76. if (ICSHelper.ExecuteSqlERP(sql) < 1)
  77. {
  78. throw new Exception("更新委外订单预计到货日期失败!");
  79. }
  80. }
  81. else
  82. {
  83. throw new Exception("委外订单明细不存在!");
  84. }
  85. }
  86. else
  87. {
  88. throw new Exception("订单号不存在!");
  89. }
  90. }
  91. else
  92. {
  93. //验证采购订单明细是否存在
  94. string sqldetail = "Select ID from {0}.dbo.PO_Podetails where POID =(Select poid from {0}.dbo.PO_Pomain where cpoid ='{1}') and ivouchrowno ='{2}'";
  95. sqldetail = string.Format(sqldetail, WorkPoint, entity.POCode, entity.Sequence);
  96. DataTable dtDetail = ICSHelper.GetDataTableERP(sqldetail);
  97. if (dtDetail != null && dtDetail.Rows.Count > 0)
  98. {
  99. string Total = entity.SubSequence.ToString() + ":" + entity.Quantity.ToString() + "-[" + entity.dReplyArriveDate + "]";
  100. string sql = @"Update {0}.dbo.PO_Podetails Set cdefine28 ='{1}' Where ID='{2}'";
  101. sql = string.Format(sql, WorkPoint, Total, dtDetail.Rows[0]["ID"].ToString());
  102. Log.WriteLogFile(sql, "回复预计到货日期SQL日志");
  103. if (ICSHelper.ExecuteSqlERP(sql) < 1)
  104. {
  105. throw new Exception("更新采购订单预计到货日期失败!");
  106. }
  107. }
  108. else
  109. {
  110. throw new Exception("采购订单明细不存在!");
  111. }
  112. }
  113. }
  114. catch (Exception ex)
  115. {
  116. sb.Append("执行报错,订单号为:" + entity.POCode + ",报错信息:" + ex.Message + "!!!");
  117. continue;
  118. }
  119. }
  120. if (sb.Length > 0)
  121. {
  122. res.IsSuccess = false;
  123. res.Message = sb.ToString();
  124. }
  125. else
  126. {
  127. res.IsSuccess = true;
  128. res.Message = "执行成功!";
  129. }
  130. return res;
  131. }
  132. catch (Exception ex)
  133. {
  134. res.IsSuccess = false;
  135. res.Message = ex.Message;
  136. return res;
  137. }
  138. }
  139. }
  140. }