终端一体化运控平台
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 

228 řádky
7.1 KiB

  1. using BPA.Helper;
  2. using BPA.Models;
  3. using BPASmartClient.MorkF.Model;
  4. using System;
  5. using System.Collections.Concurrent;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace BPASmartClient.MorkF
  11. {
  12. internal class MaterialSurplusOperation : Singleton<MaterialSurplusOperation>
  13. {
  14. public MaterialSurplus materialSurplus { get; set; } = new MaterialSurplus();
  15. /// <summary>
  16. /// 更新余量
  17. /// </summary>
  18. /// <param name="number">编号</param>
  19. /// <param name="surplus">余量</param>
  20. public bool UpdateSurplus(string loc, int surplus)
  21. {
  22. //找到所有id对应的
  23. MaterialInfo material = materialSurplus.dicSurplus.Find(t => t.Loc == loc);
  24. if(material == null)
  25. {
  26. return false;
  27. }
  28. else
  29. {
  30. material.Qty = decimal.Parse(surplus.ToString());
  31. return true;
  32. }
  33. }
  34. /// <summary>
  35. /// 返回有效的菜品库对象
  36. /// </summary>
  37. /// <param name="id"></param>
  38. /// <returns></returns>
  39. public MaterialInfo GetVailedMaterial(string id)
  40. {
  41. int surplus = 0;
  42. //获取该菜品所有的余量
  43. if(!GetAllSurplus(id,out surplus))
  44. {
  45. return null;
  46. }
  47. //判断库存数量是否有效
  48. if(surplus <= 0)
  49. {
  50. return null;
  51. }
  52. return GetMaterial(id);
  53. }
  54. /// <summary>
  55. /// 根据编号返回余量
  56. /// </summary>
  57. /// <param name="number">编号</param>
  58. /// <param name="surplus">余量</param>
  59. /// <returns></returns>
  60. private MaterialInfo GetMaterial(string id)
  61. {
  62. //找到所有id对应的
  63. MaterialInfo material = materialSurplus.dicSurplus.Find(t => t.Id == id && t.Qty != 0);
  64. return material;
  65. }
  66. /// <summary>
  67. /// 根据编号返回余量
  68. /// </summary>
  69. /// <param name="number">编号</param>
  70. /// <param name="surplus">余量</param>
  71. /// <returns></returns>
  72. private bool GetAllSurplus(string id, out int surplus)
  73. {
  74. surplus = 0;
  75. //找到所有id对应的
  76. List<MaterialInfo> materials = materialSurplus.dicSurplus.FindAll(t=>t.Id == id);
  77. if (materials != null)
  78. {
  79. foreach(MaterialInfo material in materials)
  80. {
  81. //surplus += int.Parse(material.Qty.ToString());
  82. surplus += Convert.ToInt32(material.Qty);
  83. }
  84. return true;
  85. }
  86. else
  87. {
  88. return false;
  89. }
  90. }
  91. /// <summary>
  92. /// 余量减少
  93. /// </summary>
  94. /// <param name="number"></param>
  95. /// <returns></returns>
  96. public bool ReduceSurplus(string loc)
  97. {
  98. MaterialInfo materialInfo = materialSurplus.dicSurplus.Find(t => t.Loc == loc);
  99. if (materialInfo != null)
  100. {
  101. materialInfo.Qty--;
  102. return true;
  103. }
  104. else
  105. {
  106. return false;
  107. }
  108. }
  109. /// <summary>
  110. /// 余量减少
  111. /// </summary>
  112. /// <param name="loc">菜品位置</param>
  113. /// <param name="count">菜品减少数量</param>
  114. /// <returns></returns>
  115. public bool ReduceSurplus(string loc,int count)
  116. {
  117. MaterialInfo materialInfo = materialSurplus.dicSurplus.Find(t => t.Loc == loc);
  118. if (materialInfo != null)
  119. {
  120. materialInfo.Qty -= count;
  121. return true;
  122. }
  123. else
  124. {
  125. return false;
  126. }
  127. }
  128. /// <summary>
  129. /// 余量增加
  130. /// </summary>
  131. /// <param name="number"></param>
  132. /// <returns></returns>
  133. public bool AddSurplus(string loc)
  134. {
  135. MaterialInfo materialInfo = materialSurplus.dicSurplus.Find(t => t.Loc == loc);
  136. if (materialInfo != null)
  137. {
  138. materialInfo.Qty++;
  139. return true;
  140. }
  141. else
  142. {
  143. return false;
  144. }
  145. }
  146. /// <summary>
  147. ///
  148. /// </summary>
  149. /// <param name="newMaterialSurplus"></param>
  150. public void UpdateSurplusAll(List<MaterialInfo> newMaterialSurplus)
  151. {
  152. if (newMaterialSurplus != null)
  153. {
  154. List<MaterialInfo> materialInfos = materialSurplus.dicSurplus;
  155. if(materialInfos.Count != newMaterialSurplus.Count)
  156. {
  157. materialInfos.Clear();
  158. materialSurplus.dicSurplus = newMaterialSurplus;
  159. }
  160. else
  161. {
  162. MaterialInfo findMaterial = null;
  163. //遍历旧菜品库,是否与服务器的新菜品库一致
  164. foreach (MaterialInfo materialInfo in materialSurplus.dicSurplus)
  165. {
  166. //查找该菜品是否还在
  167. findMaterial = newMaterialSurplus.Find(t => (t.Id == materialInfo.Id && t.Loc == materialInfo.Loc));
  168. //不存在则准备移除
  169. if (findMaterial == null)
  170. {
  171. //查找该菜品是否还在
  172. //位置上的菜品可能会更变
  173. findMaterial = newMaterialSurplus.Find(t => (t.Loc == materialInfo.Loc));
  174. if (findMaterial != null)
  175. {
  176. materialInfo.Qty = findMaterial.Qty;
  177. materialInfo.Key = findMaterial.Key;
  178. materialInfo.Id = findMaterial.Id;
  179. materialInfo.Name = findMaterial.Name;
  180. }
  181. }
  182. //存在则更新菜品库数据
  183. else
  184. {
  185. materialInfo.Qty = findMaterial.Qty;
  186. materialInfo.Key = findMaterial.Key;
  187. materialInfo.Name = findMaterial.Name;
  188. }
  189. }
  190. }
  191. }
  192. else
  193. {
  194. //materialSurplus.dicSurplus.Clear();
  195. }
  196. }
  197. }
  198. internal class MaterialSurplus
  199. {
  200. /// <summary>
  201. /// 余量字典,key:菜品库编号,value:余量
  202. /// </summary>
  203. public List<MaterialInfo> dicSurplus { get; set; } = new List<MaterialInfo>();
  204. //public MaterialSurplus()
  205. //{
  206. // //增加新的
  207. // foreach (var item in MaterialCoordinate.MLNumberList)
  208. // {
  209. // dicSurplus.Add(item, 0);
  210. // }
  211. //}
  212. }
  213. }