LocationPropertyManager.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. using DbCommon.BusinessCore.DbCore;
  2. using DbCommon.Enties.DbModels;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace DbCommon.BusinessCore.BaseCore
  10. {
  11. public class LocationPropertyManager : DbContext<LocationProperty>
  12. {
  13. public DataTable QueryLocation(string wHouse)
  14. {
  15. return Db.Queryable<LocationProperty>()
  16. .Where(d => d.WareHouseCode == wHouse)
  17. .ToDataTable();
  18. }
  19. public LocationProperty QueryData(string locationCode)
  20. {
  21. return Db.Queryable<LocationProperty>()
  22. .Where(d => d.LocationCode == locationCode)
  23. .First();
  24. }
  25. public List<LocationProperty> QueryDataList(string wHouse)
  26. {
  27. return Db.Queryable<LocationProperty>()
  28. .Where(d => d.WareHouseCode == wHouse)
  29. .ToList();
  30. }
  31. public string QueryWareHouse(string locationCode)
  32. {
  33. return Db.Queryable<LocationProperty>()
  34. .Where(d => d.LocationCode == locationCode)
  35. .Select(f => f.WareHouseCode)
  36. .First();
  37. }
  38. public bool CheckLocation(LocationProperty data)
  39. {
  40. if (data == null) return false;
  41. //检查出库的线路上是否都是空状态(障碍检测)
  42. var location = Db.Queryable<LocationProperty>()
  43. .Where(d => d.WareHouseCode == data.WareHouseCode
  44. && d.Status != LocationStatus.Empty
  45. && d.ColumnIndex == data.ColumnIndex
  46. && d.RowIndex < data.RowIndex)
  47. .Select(f => f.LocationCode)
  48. .First();
  49. return string.IsNullOrEmpty(location);
  50. }
  51. public bool CheckLocation(string locationCode)
  52. {
  53. var data = Db.Queryable<LocationProperty>()
  54. .Where(d => d.LocationCode == locationCode)
  55. .First();
  56. if (data == null)
  57. {
  58. return false;
  59. }
  60. return CheckLocation(data);
  61. }
  62. public string QueryLocation_Out(string wHouse, LocationStatus status)
  63. {
  64. var locationList = Db.Queryable<LocationProperty>()
  65. .Where(d => d.WareHouseCode == wHouse && d.Status == status)
  66. .OrderBy(d => d.ColumnIndex, SqlSugar.OrderByType.Asc)
  67. .OrderBy(d => d.RowIndex, SqlSugar.OrderByType.Asc)
  68. .ToList();
  69. return locationList.FirstOrDefault(d => CheckLocation(d))?.LocationCode;
  70. }
  71. public string QueryLocation_Out(string wHouse, LocationStatus status, string material)
  72. {
  73. var locationList = Db.Queryable<LocationProperty>()
  74. .Where(d => d.WareHouseCode == wHouse && d.Status == status && d.MaterialId == material)
  75. .OrderBy(d => d.ColumnIndex, SqlSugar.OrderByType.Asc)
  76. .OrderBy(d => d.RowIndex, SqlSugar.OrderByType.Asc)
  77. .ToList();
  78. return locationList.FirstOrDefault(d => CheckLocation(d))?.LocationCode;
  79. }
  80. public List<LocationProperty> QueryLocation_Out_DataList(string wHouse, LocationStatus status)
  81. {
  82. var locationList = Db.Queryable<LocationProperty>()
  83. .Where(d => d.WareHouseCode == wHouse && d.Status == status)
  84. .OrderBy(d => d.ColumnIndex, SqlSugar.OrderByType.Asc)
  85. .OrderBy(d => d.RowIndex, SqlSugar.OrderByType.Asc)
  86. .ToList();
  87. return locationList.Where(d => CheckLocation(d)).ToList();
  88. }
  89. public List<LocationProperty> QueryLocation_In_DataList(string wHouse, LocationStatus status)
  90. {
  91. var locationList = Db.Queryable<LocationProperty>()
  92. .Where(d => d.WareHouseCode == wHouse && d.Status == status)
  93. .OrderBy(d => d.ColumnIndex, SqlSugar.OrderByType.Asc)
  94. .OrderBy(d => d.RowIndex, SqlSugar.OrderByType.Desc)
  95. .ToList();
  96. return locationList.Where(d => CheckLocation(d)).ToList();
  97. }
  98. public string QueryLocation_In(string wHouse, LocationStatus status)
  99. {
  100. var locationList = Db.Queryable<LocationProperty>()
  101. .Where(d => d.WareHouseCode == wHouse && d.Status == status)
  102. .OrderBy(d => d.ColumnIndex, SqlSugar.OrderByType.Asc)
  103. .OrderBy(d => d.RowIndex, SqlSugar.OrderByType.Desc)
  104. .ToList();
  105. return locationList.FirstOrDefault(d => CheckLocation(d))?.LocationCode;
  106. }
  107. public bool UpdateStatus(string locationCode, LocationStatus status)
  108. {
  109. string nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  110. return CurrentDb.Update(
  111. d => new LocationProperty()
  112. {
  113. Status = status,
  114. ModifyTime = nowTime
  115. },
  116. d => d.LocationCode == locationCode);
  117. }
  118. public bool UpdateStatusAndMaterial(string locationCode, LocationStatus status, string material)
  119. {
  120. string nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  121. return CurrentDb.Update(
  122. d => new LocationProperty()
  123. {
  124. Status = status,
  125. MaterialId = material,
  126. ModifyTime = nowTime
  127. },
  128. d => d.LocationCode == locationCode);
  129. }
  130. public bool UpdateStatusAndStatusBackup(string locationCode, LocationStatus status, LocationStatus statusBackup)
  131. {
  132. string nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  133. return CurrentDb.Update(
  134. d => new LocationProperty()
  135. {
  136. Status = status,
  137. StatusBackup = ((int)statusBackup).ToString(),
  138. ModifyTime = nowTime
  139. },
  140. d => d.LocationCode == locationCode);
  141. }
  142. public bool UpdateStatusNotLocked(string locationCode, LocationStatus status)
  143. {
  144. string nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  145. return CurrentDb.Update(
  146. d => new LocationProperty()
  147. {
  148. Status = status,
  149. ModifyTime = nowTime
  150. },
  151. d => d.LocationCode == locationCode
  152. && d.Status != LocationStatus.Locked);
  153. }
  154. public bool UpdateStatusMaterialNotLocked(string locationCode, LocationStatus status, string material)
  155. {
  156. string nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  157. return CurrentDb.Update(
  158. d => new LocationProperty()
  159. {
  160. Status = status,
  161. MaterialId = material,
  162. ModifyTime = nowTime
  163. },
  164. d => d.LocationCode == locationCode
  165. && d.Status != LocationStatus.Locked);
  166. }
  167. }
  168. }