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.

163 lines
8.9 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 GetPurchaseStockInInfo
  11. {
  12. public static Result Get(GetPurchaseStockInCondition 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 sql = @"Select a.ID,a.LotNo as '条码',b.ASNCode as '送货单号',b.Sequence as '送货单行号',c.DNCode as '到货单号',c.Sequence as '到货单行号',
  37. n.POCode as '',n.Sequence as '',a.InvCode as '',a.Quantity as '',a.ToWarehouseCode as '',
  38. a.ToLocationCode as '',a.ERPCode as '',a.ERPSequence as '',a.MUSER as '',a.MUSERName as '',
  39. a.MTIME as '',a.WorkPoint as ''
  40. from ICSWareHouseLotInfoLog a
  41. inner join ICSASNDETAIL b on a.LotNo = b.LotNo and a.WorkPoint = b.WorkPoint
  42. inner join ICSDeliveryNotice c on b.ASNCode = c.ASNCode and b.WorkPoint = c.WorkPoint
  43. INNER JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint
  44. INNER JOIN ICSInventoryLotDetail m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  45. INNER JOIN ICSPurchaseOrder n ON m.TransCode =n.POCode AND m.TransSequence=n.Sequence AND c.PODetailID=n.PODetailID AND m.WorkPoint=n.WorkPoint
  46. where a.WorkPoint ='{0}' and a.TransType ='2' and a.BusinessCode ='1'";
  47. string sql2 = @"Select a.ID,a.LotNo as '条码',b.ASNCode as '送货单号',b.Sequence as '送货单行号',c.ODNCode as '到货单号',c.Sequence as '到货单行号',
  48. n.OOCode as '',n.Sequence as '',a.InvCode as '',a.Quantity as '',a.ToWarehouseCode as '',
  49. a.ToLocationCode as '',a.ERPCode as '',a.ERPSequence as '',a.MUSER as '',a.MUSERName as '',
  50. a.MTIME as '',a.WorkPoint as ''
  51. from ICSWareHouseLotInfoLog a
  52. inner join ICSASNDETAIL b on a.LotNo = b.LotNo and a.WorkPoint = b.WorkPoint
  53. inner join ICSODeliveryNotice c on b.ASNCode = c.OASNCode and b.WorkPoint = c.WorkPoint
  54. INNER JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint
  55. INNER JOIN ICSInventoryLotDetail m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  56. INNER JOIN ICSOutsourcingOrder n ON m.TransCode =n.OOCode AND m.TransSequence=n.Sequence AND c.OODetailID=n.OODetailID AND m.WorkPoint=n.WorkPoint
  57. where a.WorkPoint ='{0}' and a.TransType ='2' and a.BusinessCode ='9'";
  58. sql = string.Format(sql, WorkPoint);
  59. sql2 = string.Format(sql2, WorkPoint);
  60. if (condition.dModifyDateFrom != null)
  61. {
  62. sql += " and a.Mtime >= '{0}'";
  63. sql = string.Format(sql, condition.dModifyDateFrom);
  64. sql2 += " and a.Mtime >= '{0}'";
  65. sql2 = string.Format(sql2, condition.dModifyDateFrom);
  66. }
  67. if (condition.dModifyDateTo != null)
  68. {
  69. sql += " and a.Mtime <= '{0}'";
  70. sql = string.Format(sql, condition.dModifyDateTo);
  71. sql2 += " and a.Mtime <= '{0}'";
  72. sql2 = string.Format(sql2, condition.dModifyDateTo);
  73. }
  74. if (condition.ASNCode != null)
  75. {
  76. sql += " and b.ASNCode like '%{0}%'";
  77. sql = string.Format(sql, condition.ASNCode);
  78. sql2 += " and b.ASNCode like '%{0}%'";
  79. sql2 = string.Format(sql2, condition.ASNCode);
  80. }
  81. if (condition.PO != null)
  82. {
  83. sql += " and n.POCode like '%{0}%'";
  84. sql = string.Format(sql, condition.PO);
  85. sql2 += " and n.OOCode like '%{0}%'";
  86. sql2 = string.Format(sql2, condition.PO);
  87. }
  88. sql = sql + " 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<GetPurchaseStockInEntity> entityList = new List<GetPurchaseStockInEntity>();
  95. if (dt != null && dt.Rows.Count > 0)
  96. {
  97. foreach (DataRow dr in dt.Rows)
  98. {
  99. GetPurchaseStockInEntity entity = new GetPurchaseStockInEntity();
  100. entity.ID = dr["ID"].ToString();
  101. entity.LotNo = dr["条码"].ToString();
  102. entity.ASNCode = dr["送货单号"].ToString();
  103. entity.ASNLine = string.IsNullOrWhiteSpace(dr["送货单行号"].ToString()) ? 1 : Convert.ToInt32(dr["送货单行号"].ToString());
  104. entity.DNCode = dr["到货单号"].ToString();
  105. entity.DNLine = string.IsNullOrWhiteSpace(dr["到货单行号"].ToString()) ? 1 : Convert.ToInt32(dr["到货单行号"].ToString());
  106. entity.PO = dr["采购订单"].ToString();
  107. entity.POLine = string.IsNullOrWhiteSpace(dr["采购订单行号"].ToString()) ? 1 : Convert.ToInt32(dr["采购订单行号"].ToString());
  108. entity.InvCode = dr["物料代码"].ToString();
  109. entity.Quantity = string.IsNullOrWhiteSpace(dr["入库数量"].ToString()) ? 0.00m : Convert.ToDecimal(dr["入库数量"].ToString());
  110. entity.ToWarehouseCode = dr["入库仓库"].ToString();
  111. entity.ToLocationCode = dr["入库库位"].ToString();
  112. entity.RcvDoc = dr["采购入库单号"].ToString();
  113. entity.RcvDocLine = string.IsNullOrWhiteSpace(dr["采购入库单行号"].ToString()) ? 1 : Convert.ToInt32(dr["采购入库单行号"].ToString());
  114. entity.TransType = "2";
  115. entity.BusinessCode = "1";
  116. entity.MUSER = dr["操作人"].ToString();
  117. entity.MUSERName = dr["操作人名称"].ToString();
  118. if (string.IsNullOrWhiteSpace(dr["操作时间"].ToString()))
  119. {
  120. entity.dModifyDate = null;
  121. }
  122. else
  123. {
  124. entity.dModifyDate = Convert.ToDateTime(dr["操作时间"].ToString());
  125. }
  126. entity.WorkPoint = dr["站点"].ToString();
  127. entityList.Add(entity);
  128. }
  129. res.IsSuccess = true;
  130. res.Message = "执行成功!";
  131. res.data = entityList;
  132. return res;
  133. }
  134. else
  135. {
  136. res.IsSuccess = true;
  137. res.Message = "查询无数据!";
  138. res.data = entityList;
  139. return res;
  140. }
  141. }
  142. catch (Exception ex)
  143. {
  144. res.IsSuccess = false;
  145. res.Message = ex.Message;
  146. return res;
  147. }
  148. }
  149. }
  150. }