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.

155 lines
8.5 KiB

3 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 GetInspectionInfo
  11. {
  12. public static Result Get(GetInspectionCondition 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 distinct d.ID,a.AsnCode as '送货单号',a.Sequence as '送货单行号',b.DNCode as '到货单号',
  37. n.POCode as '',n.Sequence as '',a.Lotno as '',d.InvCode as '',d.Quantity as '',
  38. d.QualifiedQuantity as '',d.UnqualifiedQuantity as '',d.WaiveQuantity as '',d.BRCODE AS '',
  39. d.MUSER as '',d.MUSERName as '',d.MTime as '',d.WorkPoint as '',d.type as ''
  40. from ICSASNDETAIL a
  41. inner join ICSDeliveryNotice b on a.AsnCode = b.AsnCode and a.WorkPoint = b.WorkPoint
  42. INNER JOIN ICSInventoryLot e ON a.LotNo=e.LotNo AND b.InvCode=e.InvCode AND a.WorkPoint=e.WorkPoint
  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 b.PODetailID=n.PODetailID AND m.WorkPoint=n.WorkPoint
  45. inner join ICSInspection d on a.Lotno = d.Lotno and a.WorkPoint = d.WorkPoint
  46. where a.WorkPoint ='{0}' and d.type='1' and d.Enable ='1'";
  47. string sql2 = @"Select distinct d.ID,a.AsnCode as '送货单号',a.Sequence as '送货单行号',b.ODNCode as '到货单号',
  48. n.OOCode as '',n.Sequence as '',a.Lotno as '',d.InvCode as '',d.Quantity as '',
  49. d.QualifiedQuantity as '',d.UnqualifiedQuantity as '',d.WaiveQuantity as '',d.BRCODE AS '',
  50. d.MUSER as '',d.MUSERName as '',d.MTime as '',d.WorkPoint as '',d.type as ''
  51. from ICSASNDETAIL a
  52. inner join ICSODeliveryNotice b on a.AsnCode = b.OASNCode and a.WorkPoint = b.WorkPoint
  53. INNER JOIN ICSInventoryLot e ON a.LotNo=e.LotNo AND b.InvCode=e.InvCode AND a.WorkPoint=e.WorkPoint
  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 b.OODetailID=n.OODetailID AND m.WorkPoint=n.WorkPoint
  56. inner join ICSInspection d on a.Lotno = d.Lotno and a.WorkPoint = d.WorkPoint
  57. where a.WorkPoint ='{0}' and d.type='3' and d.Enable ='1'";
  58. sql = string.Format(sql, WorkPoint);
  59. sql2 = string.Format(sql2, WorkPoint);
  60. if (condition.dModifyDateFrom != null)
  61. {
  62. sql += " and d.Mtime >= '{0}'";
  63. sql = string.Format(sql, condition.dModifyDateFrom);
  64. sql2 += " and d.Mtime >= '{0}'";
  65. sql2 = string.Format(sql2, condition.dModifyDateFrom);
  66. }
  67. if (condition.dModifyDateTo != null)
  68. {
  69. sql += " and d.Mtime <= '{0}'";
  70. sql = string.Format(sql, condition.dModifyDateTo);
  71. sql2 += " and d.Mtime <= '{0}'";
  72. sql2 = string.Format(sql2, condition.dModifyDateTo);
  73. }
  74. if (condition.ASNCode != null)
  75. {
  76. sql += " and a.ASNCode like '%{0}%'";
  77. sql = string.Format(sql, condition.ASNCode);
  78. sql2 += " and a.ASNCode like '%{0}%'";
  79. sql2 = string.Format(sql2, condition.ASNCode);
  80. }
  81. sql = sql + " Union All " + sql2;
  82. string sqlNew = @" select * from (select aa.*,rn=ROW_NUMBER() over(order by ID) from( ";
  83. sqlNew += sql;
  84. sqlNew += ") aa)bb where bb.rn between {0} and {1} ";
  85. sqlNew = string.Format(sqlNew, (condition.PageIndex - 1) * condition.PageSize + 1, condition.PageIndex * condition.PageSize);
  86. DataTable dt = ICSHelper.GetDataTable(sqlNew);
  87. List<GetInspectionEntity> entityList = new List<GetInspectionEntity>();
  88. if (dt != null && dt.Rows.Count > 0)
  89. {
  90. foreach (DataRow dr in dt.Rows)
  91. {
  92. GetInspectionEntity entity = new GetInspectionEntity();
  93. entity.ID = dr["ID"].ToString();
  94. entity.ASNCode = dr["送货单号"].ToString();
  95. entity.ASNLine = string.IsNullOrWhiteSpace(dr["送货单行号"].ToString()) ? 1 : Convert.ToInt32(dr["送货单行号"].ToString());
  96. entity.DNCode = dr["到货单号"].ToString();
  97. entity.DNLine = 1;
  98. entity.PO = dr["采购订单"].ToString();
  99. entity.POLine = string.IsNullOrWhiteSpace(dr["采购订单行号"].ToString()) ? 1 : Convert.ToInt32(dr["采购订单行号"].ToString());
  100. entity.LotNo = dr["条码"].ToString();
  101. entity.InvCode = dr["物料编码"].ToString();
  102. entity.Quantity = string.IsNullOrWhiteSpace(dr["数量"].ToString()) ? 0.00m : Convert.ToDecimal(dr["数量"].ToString());
  103. entity.QualifiedQuantity = string.IsNullOrWhiteSpace(dr["合格数量"].ToString()) ? 0.00m : Convert.ToDecimal(dr["合格数量"].ToString());
  104. entity.UnqualifiedQuantity = string.IsNullOrWhiteSpace(dr["不合格数量"].ToString()) ? 0.00m : Convert.ToDecimal(dr["不合格数量"].ToString());
  105. entity.WaiveQuantity = string.IsNullOrWhiteSpace(dr["特采数量"].ToString()) ? 0.00m : Convert.ToDecimal(dr["特采数量"].ToString());
  106. entity.ECSCode = dr["不良原因代码"].ToString();
  107. entity.Type = dr["类型"].ToString();
  108. entity.MUSER = dr["操作人"].ToString();
  109. entity.MUSERName = dr["操作人名称"].ToString();
  110. if (string.IsNullOrWhiteSpace(dr["操作时间"].ToString()))
  111. {
  112. entity.dModifyDate = null;
  113. }
  114. else
  115. {
  116. entity.dModifyDate = Convert.ToDateTime(dr["操作时间"].ToString());
  117. }
  118. entity.WorkPoint = dr["站点"].ToString();
  119. entityList.Add(entity);
  120. }
  121. res.IsSuccess = true;
  122. res.Message = "执行成功!";
  123. res.data = entityList;
  124. return res;
  125. }
  126. else
  127. {
  128. res.IsSuccess = true;
  129. res.Message = "查询无数据!";
  130. res.data = entityList;
  131. return res;
  132. }
  133. }
  134. catch (Exception ex)
  135. {
  136. res.IsSuccess = false;
  137. res.Message = ex.Message;
  138. return res;
  139. }
  140. }
  141. }
  142. }