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.

176 lines
8.8 KiB

6 months ago
  1. using ICSSoft.ERPWMS.Entity;
  2. using Microsoft.Data.SqlClient;
  3. using Newtonsoft.Json;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace ICSSoft.ERPWMS.SQL
  11. {
  12. public class DeleteASNInfo
  13. {
  14. public static Result Create(List<DeleteASNInfoEntity> entityList)
  15. {
  16. Result res = new Result();
  17. try
  18. {
  19. string jsonstr = JsonConvert.SerializeObject(entityList);
  20. Log.WriteLogFile(jsonstr, "删除送货单日志");
  21. StringBuilder sb = new StringBuilder();//接口返回Message
  22. foreach (DeleteASNInfoEntity entity in entityList)
  23. {
  24. SqlConnection conn = new SqlConnection(ICSHelper.ReadConfig(ICSHelper.FileNameCompanyCon)["WMS"].ToString());
  25. conn.Open();
  26. SqlTransaction sqlTran = conn.BeginTransaction();
  27. SqlCommand cmd = new SqlCommand();
  28. cmd.Transaction = sqlTran;
  29. cmd.Connection = conn;
  30. try
  31. {
  32. if (string.IsNullOrWhiteSpace(entity.ASNCode))
  33. {
  34. throw new Exception("存在送货单号为空!!!");
  35. }
  36. if (string.IsNullOrWhiteSpace(entity.WorkPoint))
  37. {
  38. throw new Exception("表头站点参数为空!!!");
  39. }
  40. string WorkPoint = ICSHelper.GetConnectStringTest(entity.WorkPoint);
  41. if (WorkPoint == "NotExit")
  42. {
  43. throw new Exception("表头站点编码不存在!");
  44. }
  45. //查询送货单
  46. string sqlCheck = "Select ASNCode from ICSASN where workpoint='{0}' and ASNCode='{1}'";
  47. sqlCheck = string.Format(sqlCheck, WorkPoint, entity.ASNCode);
  48. DataTable dtCheck = ICSHelper.SQlReturnData(sqlCheck, cmd);
  49. if (dtCheck != null && dtCheck.Rows.Count > 0)
  50. {
  51. //检查送货单是否绑定到货单
  52. string sqlDN = "Select ASNCode from ICSDeliveryNotice Where workpoint='{0}' and ASNCode ='{1}'";
  53. sqlDN = string.Format(sqlDN, WorkPoint, entity.ASNCode);
  54. DataTable dtDN = ICSHelper.SQlReturnData(sqlDN, cmd);
  55. if (dtDN != null && dtDN.Rows.Count > 0)
  56. {
  57. throw new Exception("送货单已绑定到货单,不能删除!");
  58. }
  59. //删除送货单表头
  60. string DeleteSql = "Delete ICSASN Where workpoint='{0}' and ASNCode ='{1}';";
  61. DeleteSql = string.Format(DeleteSql, WorkPoint, entity.ASNCode);
  62. Log.WriteLogFile(DeleteSql, "删除送货单SQL日志");
  63. if (!ICSHelper.ExecuteNonQuery(DeleteSql, cmd))
  64. {
  65. throw new Exception("删除送货单表表头失败!");
  66. }
  67. //删除送货单表体
  68. string CheckDetailSql = "Select LotNO,workpoint from ICSASNDetail Where workpoint='{0}' and ASNCode ='{1}'";
  69. CheckDetailSql = string.Format(CheckDetailSql, WorkPoint, entity.ASNCode);
  70. DataTable dtCheckDetail = ICSHelper.SQlReturnData(CheckDetailSql, cmd);
  71. if (dtCheckDetail != null && dtCheckDetail.Rows.Count > 0)
  72. {
  73. DeleteSql = "Delete ICSASNDetail Where workpoint='{0}' and ASNCode ='{1}';";
  74. DeleteSql = string.Format(DeleteSql, WorkPoint, entity.ASNCode);
  75. Log.WriteLogFile(DeleteSql, "删除送货单SQL日志");
  76. if (!ICSHelper.ExecuteNonQuery(DeleteSql, cmd))
  77. {
  78. throw new Exception("删除送货单表表体失败!");
  79. }
  80. foreach (DataRow dr in dtCheckDetail.Rows)
  81. {
  82. ////删除自由项表
  83. //string sqlExten = "Select ExtensionID from ICSInventoryLot where workpoint='{0}' and LotNo = '{1}'";
  84. //sqlExten = string.Format(sqlExten, WorkPoint, dr["LotNO"].ToString());
  85. //DataTable dtExtension = ICSHelper.SQlReturnData(sqlExten, cmd);
  86. //if (dtExtension != null && dtExtension.Rows.Count > 0)
  87. //{
  88. // string Extensql = "Select ID From ICSExtension where workpoint='{0}' and ID = '{1}'";
  89. // Extensql = string.Format(Extensql, WorkPoint, dtExtension.Rows[0]["ExtensionID"].ToString());
  90. // DataTable dtNew = ICSHelper.SQlReturnData(Extensql, cmd);
  91. // if (dtNew != null && dtNew.Rows.Count > 0)
  92. // {
  93. // DeleteSql = "Delete ICSExtension where workpoint='{0}' and ID = '{1}'";
  94. // DeleteSql = string.Format(DeleteSql, WorkPoint, dtExtension.Rows[0]["ExtensionID"].ToString());
  95. // Log.WriteLogFile(DeleteSql, "删除送货单SQL日志");
  96. // if (!ICSHelper.ExecuteNonQuery(DeleteSql, cmd))
  97. // {
  98. // throw new Exception("删除自由项表失败!");
  99. // }
  100. // }
  101. //}
  102. //删除条码表表头
  103. DeleteSql = "Delete ICSInventoryLot where workpoint='{0}' and LotNo = '{1}'";
  104. DeleteSql = string.Format(DeleteSql, WorkPoint, dr["LotNO"].ToString());
  105. Log.WriteLogFile(DeleteSql, "删除送货单SQL日志");
  106. if (!ICSHelper.ExecuteNonQuery(DeleteSql, cmd))
  107. {
  108. throw new Exception("删除条码表表头失败!");
  109. }
  110. //删除条码表表体
  111. DeleteSql = "Delete ICSInventoryLotDetail where workpoint='{0}' and LotNo = '{1}'";
  112. DeleteSql = string.Format(DeleteSql, WorkPoint, dr["LotNO"].ToString());
  113. Log.WriteLogFile(DeleteSql, "删除送货单SQL日志");
  114. if (!ICSHelper.ExecuteNonQuery(DeleteSql, cmd))
  115. {
  116. throw new Exception("删除条码表表体失败!");
  117. }
  118. }
  119. }
  120. cmd.Transaction.Commit();
  121. }
  122. }
  123. catch (Exception ex)
  124. {
  125. cmd.Transaction.Rollback();
  126. sb.Append("执行报错,送货单号为:" + entity.ASNCode + ",报错信息:" + ex.Message + "!!!");
  127. continue;
  128. }
  129. finally
  130. {
  131. if (conn.State == ConnectionState.Open)
  132. {
  133. conn.Close();
  134. }
  135. conn.Dispose();
  136. }
  137. }
  138. if (sb.Length > 0)
  139. {
  140. res.IsSuccess = false;
  141. res.Message = sb.ToString();
  142. }
  143. else
  144. {
  145. res.IsSuccess = true;
  146. res.Message = "执行成功!";
  147. }
  148. return res;
  149. }
  150. catch (Exception ex)
  151. {
  152. res.IsSuccess = false;
  153. res.Message = ex.Message;
  154. return res;
  155. }
  156. }
  157. }
  158. }