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.

174 lines
9.4 KiB

6 months ago
  1. using ICSSoft.ERPWMS.Entity;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace ICSSoft.ERPWMS.SQL
  9. {
  10. public class GetDNInfo
  11. {
  12. public static Result Get(GetDNCondition condition)
  13. {
  14. Result res = new Result();
  15. try
  16. {
  17. if (condition.PageIndex == null)
  18. {
  19. throw new Exception("页码未传!");
  20. }
  21. if (condition.PageSize == null)
  22. {
  23. throw new Exception("每页数量未传!");
  24. }
  25. if (string.IsNullOrWhiteSpace(condition.WorkPoint))
  26. {
  27. res.IsSuccess = false;
  28. res.Message = "站点参数为空!";
  29. return res;
  30. }
  31. string WorkPoint = ICSHelper.GetConnectStringTest(condition.WorkPoint);
  32. if (WorkPoint == "NotExit")
  33. {
  34. throw new Exception("站点编码不存在!");
  35. }
  36. string sql1 = @"Select distinct a.ID,a.DNCode as '到货单号',a.Sequence as '到货单行号',a.VenCode as '供应商代码',a.InvCode as '物料代码',a.Quantity as '数量',
  37. a.Amount as '',a.Status as '',a.CreatePerson as '',a.CreateDateTime as '',n.POCode as '',n.Sequence as '',
  38. a.ASNCode as '',a.WorkPoint as '',a.Mtime as '',d.cFree1 as '1',d.cFree2 as '2',
  39. d.cFree3 as '3',d.cFree4 as '4',d.cFree2 as '5',a.dntype as ''
  40. from ICSDeliveryNotice a
  41. inner JOIN ICSASNDETAIL C ON A.ASNCode = C.ASNCode and a.WorkPoint = c.WorkPoint
  42. INNER JOIN ICSInventoryLot e ON c.LotNo=e.LotNo AND a.InvCode=e.InvCode AND c.WorkPoint=e.WorkPoint and a.ExtensionID = e.ExtensionID
  43. INNER JOIN ICSInventoryLotDetail m on e.LotNo=m.LotNo and e.WorkPoint=m.WorkPoint
  44. INNER JOIN ICSPurchaseOrder n ON m.TransCode =n.POCode AND m.TransSequence=n.Sequence AND a.PODetailID=n.PODetailID AND m.WorkPoint=n.WorkPoint
  45. inner JOIN ICSExtension D ON e.ExtensionID = D.ID and e.WorkPoint = d.WorkPoint
  46. where a.WorkPoint ='{0}' and a.dntype='1'";
  47. string sql2 = @"Select distinct a.ID,a.ODNCode as '到货单号',a.Sequence as '到货单行号',a.VenCode as '供应商代码',a.InvCode as '物料代码',a.Quantity as '数量',
  48. a.Amount as '',a.Status as '',a.CreatePerson as '',a.CreateDateTime as '',n.OOCode as '',n.Sequence as '',
  49. a.OASNCode as '',a.WorkPoint as '',a.Mtime as '',d.cFree1 as '1',d.cFree2 as '2',
  50. d.cFree3 as '3',d.cFree4 as '4',d.cFree2 as '5',a.ODNType as ''
  51. from ICSODeliveryNotice a
  52. inner JOIN ICSASNDETAIL C ON A.OASNCode = C.ASNCode and a.WorkPoint = c.WorkPoint
  53. INNER JOIN ICSInventoryLot e ON c.LotNo=e.LotNo AND a.InvCode=e.InvCode AND c.WorkPoint=e.WorkPoint and a.ExtensionID = e.ExtensionID
  54. INNER JOIN ICSInventoryLotDetail m on e.LotNo=m.LotNo and e.WorkPoint=m.WorkPoint
  55. INNER JOIN ICSOutsourcingOrder n ON m.TransCode =n.OOCode AND m.TransSequence=n.Sequence AND a.OODetailID=n.OODetailID AND m.WorkPoint=n.WorkPoint
  56. inner JOIN ICSExtension D ON e.ExtensionID = D.ID and e.WorkPoint = d.WorkPoint
  57. where a.WorkPoint ='{0}' and a.ODNType='1'";
  58. sql1 = string.Format(sql1, WorkPoint);
  59. sql2 = string.Format(sql2, WorkPoint);
  60. if (condition.dModifyDateFrom != null)
  61. {
  62. sql1 += " and a.Mtime >= '{0}'";
  63. sql1 = string.Format(sql1, condition.dModifyDateFrom);
  64. sql2 += " and a.Mtime >= '{0}'";
  65. sql2 = string.Format(sql2, condition.dModifyDateFrom);
  66. }
  67. if (condition.dModifyDateTo != null)
  68. {
  69. sql1 += " and a.Mtime <= '{0}'";
  70. sql1 = string.Format(sql1, condition.dModifyDateTo);
  71. sql2 += " and a.Mtime <= '{0}'";
  72. sql2 = string.Format(sql2, condition.dModifyDateTo);
  73. }
  74. if (condition.ASNCode != null)
  75. {
  76. sql1 += " and a.ASNCode like '%{0}%'";
  77. sql1 = string.Format(sql1, condition.ASNCode);
  78. sql2 += " and a.OASNCode like '%{0}%'";
  79. sql2 = string.Format(sql2, condition.ASNCode);
  80. }
  81. if (condition.PO != null)
  82. {
  83. sql1 += " and n.POCode like '%{0}%'";
  84. sql1 = string.Format(sql1, condition.PO);
  85. sql2 += " and n.OOCode like '%{0}%'";
  86. sql2 = string.Format(sql2, condition.PO);
  87. }
  88. string sql = sql1 + " Union All " + sql2;
  89. string sqlNew = @" select * from (select aa.*,rn=ROW_NUMBER() over(order by ID) from( ";
  90. sqlNew += sql;
  91. sqlNew += ") aa)bb where bb.rn between {0} and {1} ";
  92. sqlNew = string.Format(sqlNew, (condition.PageIndex - 1) * condition.PageSize + 1, condition.PageIndex * condition.PageSize);
  93. DataTable dt = ICSHelper.GetDataTable(sqlNew);
  94. List<GetDNEntity> entityList = new List<GetDNEntity>();
  95. if (dt != null && dt.Rows.Count > 0)
  96. {
  97. foreach (DataRow dr in dt.Rows)
  98. {
  99. GetDNEntity entity = new GetDNEntity();
  100. entity.ID = dr["ID"].ToString();
  101. entity.DNCode = dr["到货单号"].ToString();
  102. entity.DNLine = string.IsNullOrWhiteSpace(dr["到货单行号"].ToString()) ? 1 : Convert.ToInt32(dr["到货单行号"].ToString());
  103. entity.VenCode = dr["供应商代码"].ToString();
  104. entity.DNType = string.IsNullOrWhiteSpace(dr["类型"].ToString()) ? 1 : Convert.ToInt32(dr["类型"].ToString());
  105. entity.InvCode = dr["物料代码"].ToString();
  106. entity.Quantity = string.IsNullOrWhiteSpace(dr["数量"].ToString()) ? 0.00m : Convert.ToDecimal(dr["数量"].ToString());
  107. entity.Amount = string.IsNullOrWhiteSpace(dr["辅计量数量"].ToString()) ? 0.00m : Convert.ToDecimal(dr["辅计量数量"].ToString());
  108. entity.Status = dr["状态"].ToString();
  109. entity.CreatePerson = dr["创建人"].ToString();
  110. if (string.IsNullOrWhiteSpace(dr["创建时间"].ToString()))
  111. {
  112. entity.CreateDate = null;
  113. }
  114. else
  115. {
  116. entity.CreateDate = Convert.ToDateTime(dr["创建时间"].ToString());
  117. }
  118. entity.PO = dr["采购订单"].ToString();
  119. entity.POLine = string.IsNullOrWhiteSpace(dr["采购订单行号"].ToString()) ? 1 : Convert.ToInt32(dr["采购订单行号"].ToString());
  120. entity.ASNCode = dr["送货单号"].ToString();
  121. entity.ASNLine = 1;
  122. entity.Extension1 = dr["自由项1"].ToString();
  123. entity.Extension2 = dr["自由项2"].ToString();
  124. entity.Extension3 = dr["自由项3"].ToString();
  125. entity.Extension4 = dr["自由项4"].ToString();
  126. entity.Extension5 = dr["自由项5"].ToString();
  127. if (string.IsNullOrWhiteSpace(dr["操作时间"].ToString()))
  128. {
  129. entity.dModifyDate = null;
  130. }
  131. else
  132. {
  133. entity.dModifyDate = Convert.ToDateTime(dr["操作时间"].ToString());
  134. }
  135. entity.WorkPoint = dr["站点"].ToString();
  136. entityList.Add(entity);
  137. }
  138. res.IsSuccess = true;
  139. res.Message = "执行成功!";
  140. res.data = entityList;
  141. return res;
  142. }
  143. else
  144. {
  145. res.IsSuccess = true;
  146. res.Message = "查询无数据!";
  147. res.data = entityList;
  148. return res;
  149. }
  150. }
  151. catch (Exception ex)
  152. {
  153. res.IsSuccess = false;
  154. res.Message = ex.Message;
  155. return res;
  156. }
  157. }
  158. }
  159. }