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.

138 lines
6.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 GetInventoryInfo
  11. {
  12. public static Result Get(InventoryCondition 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. throw new Exception("站点未传!");
  28. }
  29. string WorkPoint = ICSHelper.GetConnectStringTest(condition.WorkPoint);
  30. if (WorkPoint== "NotExit")
  31. {
  32. throw new Exception("站点编码不存在!");
  33. }
  34. string sql = @"select a.cInvCode as '物料编码',a.cInvAddCode as '物料代码',a.cInvName as '物料名称',a.cInvStd as '规格型号',
  35. a.cComUnitCode as '',a.cAssComUnitCode as '',a.cInvMnemCode as '',a.iTaxRate as '',
  36. a.dSDate as '',a.dEDate as '',a.cCurrencyName as '',a.cInvCCode as '',
  37. b.cInvCName as '',a.cEnglishName as '',a.cPurPersonCode as '',a.bSale as '',
  38. a.bPurchase as '',a.bSelf as '',a.dModifyDate as '',a.cInvPersonCode as ''
  39. from {0}.dbo.Inventory a
  40. left join {0}.dbo.InventoryClass b on a.cInvCCode = b.cInvCCode
  41. where 1=1";
  42. sql = string.Format(sql, WorkPoint);
  43. if (condition.dModifyDateFrom != null)
  44. {
  45. sql += " and a.dModifyDate >= '{0}'";
  46. sql = string.Format(sql, condition.dModifyDateFrom);
  47. }
  48. if (condition.dModifyDateTo != null)
  49. {
  50. sql += " and a.dModifyDate <= '{0}'";
  51. sql = string.Format(sql, condition.dModifyDateTo);
  52. }
  53. if (condition.cInvCode != null)
  54. {
  55. sql += " and a.cInvCode like '%{0}%'";
  56. sql = string.Format(sql, condition.cInvCode);
  57. }
  58. string sqlNew = @" select * from (select aa.*,rn=ROW_NUMBER() over(order by 物料编码) from( ";
  59. sqlNew += sql;
  60. sqlNew += ") aa)bb where bb.rn between {0} and {1} ";
  61. sqlNew = string.Format(sqlNew, (condition.PageIndex - 1) * condition.PageSize + 1, condition.PageIndex * condition.PageSize);
  62. DataTable dt = ICSHelper.GetDataTableERP(sqlNew);
  63. List<InventoryEntity> entityList = new List<InventoryEntity>();
  64. if (dt != null && dt.Rows.Count > 0)
  65. {
  66. foreach (DataRow dr in dt.Rows)
  67. {
  68. InventoryEntity entity = new InventoryEntity();
  69. entity.cInvCode = dr["物料编码"].ToString();
  70. entity.cInvAddCode = dr["物料代码"].ToString();
  71. entity.cInvName = dr["物料名称"].ToString();
  72. entity.cInvStd = dr["规格型号"].ToString();
  73. entity.cComUnitCode = dr["主计量单位"].ToString();
  74. entity.cAssComUnitCode = dr["辅计量单位"].ToString();
  75. entity.cInvMnemCode = dr["助记码"].ToString();
  76. if (string.IsNullOrWhiteSpace(dr["税率"].ToString()))
  77. {
  78. entity.iTaxRate = 0.00f;
  79. }
  80. else
  81. {
  82. entity.iTaxRate = float.Parse(dr["税率"].ToString());
  83. }
  84. if (string.IsNullOrWhiteSpace(dr["启用日期"].ToString()))
  85. {
  86. entity.dSDate = null;
  87. }
  88. else
  89. {
  90. entity.dSDate = Convert.ToDateTime(dr["启用日期"].ToString());
  91. }
  92. if (string.IsNullOrWhiteSpace(dr["停用日期"].ToString()))
  93. {
  94. entity.dEDate = null;
  95. }
  96. else
  97. {
  98. entity.dEDate = Convert.ToDateTime(dr["停用日期"].ToString());
  99. }
  100. entity.cCurrencyName = dr["通用名称"].ToString();
  101. entity.cInvCName = dr["存货大类名称"].ToString();
  102. entity.cEnglishName = dr["物料英文名称"].ToString();
  103. entity.cPurPersonCode = dr["采购员"].ToString();
  104. entity.bSale = Convert.ToBoolean(dr["是否销售"].ToString());
  105. entity.bPurchase = Convert.ToBoolean(dr["是否采购"].ToString());
  106. entity.bSelf = Convert.ToBoolean(dr["是否自制"].ToString());
  107. entity.dModifyDate = dr["修改日期"].ToString();
  108. entity.cInvPersonCode = dr["计划员"].ToString();
  109. entityList.Add(entity);
  110. }
  111. res.IsSuccess = true;
  112. res.Message = "执行成功!";
  113. res.data = entityList;
  114. return res;
  115. }
  116. else
  117. {
  118. res.IsSuccess = true;
  119. res.Message = "查询无数据!";
  120. res.data = entityList;
  121. return res;
  122. }
  123. }
  124. catch (Exception ex)
  125. {
  126. res.IsSuccess = false;
  127. res.Message = ex.Message;
  128. return res;
  129. }
  130. }
  131. }
  132. }