终端一体化运控平台
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ů.
 
 
 

296 řádky
12 KiB

  1. using BPASmartClient.CustomResource.Pages.Model;
  2. using BPASmartClient.CustomResource.UserControls.MessageShow;
  3. using BPASmartClient.MorkCL.Model.DB;
  4. using BPASmartClient.MorkCL.Model.Json;
  5. using BPASmartClient.MorkCL.Server;
  6. namespace BPASmartClient.MorkCL.ViewModel
  7. {
  8. public class ItemStorageViewModel : NotifyBase
  9. {
  10. public ItemStorageViewModel()
  11. {
  12. //加载读取数据。
  13. //AddTestData();
  14. ActionManage.GetInstance.Register(() =>
  15. {
  16. IngredientsItorage = new ObservableCollection<ItemStorage>(Json<ItemStorageInfo>.Data.IngredientsStorage);
  17. AccessoriesItorage = new ObservableCollection<ItemStorage>(Json<ItemStorageInfo>.Data.AccessoriesStorage);
  18. }, "RefreshItemStorage", true);
  19. ActionManage.GetInstance.Register((() =>
  20. {
  21. Ingredients = new ObservableCollection<IngredientsTB>(SqliteHelper.GetInstance.GetIngredients());
  22. }), "RefreshIngredients", true);
  23. ActionManage.GetInstance.Register((object o) =>
  24. {
  25. if (o != null && o is float f)
  26. {
  27. #if !FORMAL
  28. ScaleCurrentWeight = f;
  29. #else
  30. ScaleCurrentWeight = 1.23f;
  31. #endif
  32. }
  33. }, "SendCurrentWeight",true);
  34. //ActionManage.GetInstance.Register((object o) =>
  35. //{
  36. // CanItemStorage = (bool)o;
  37. //}, "RefreshCanItemStorage", true);
  38. //实例化时调用一次,更新数据。
  39. ActionManage.GetInstance.Send("RefreshItemStorage");
  40. ActionManage.GetInstance.Send("RefreshIngredients");
  41. InStorageCommand = new BPARelayCommand<object>((o) =>
  42. {
  43. ActionManage.GetInstance.Send(NotifyTopic.ItemStorage, o);
  44. #region 暂时弃用
  45. //if (!CanItemStorage)
  46. //{
  47. // MessageNotify.GetInstance.ShowDialog("当前有炒菜任务正在排队,为避免影响菜品口味,不可入库,请稍后再试。", DialogType.Warning);
  48. // NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "入库失败", $"物料入库失败,当前正在制作菜品。");
  49. // return;
  50. //}
  51. //TaskManage.GetInstance.Start(() =>
  52. //{
  53. // if (o != null && o is IngredientsTB ingredients)
  54. // {
  55. // foreach (ItemStorage item in Json<ItemStorageInfo>.Data.IngredientsStorage)
  56. // {
  57. // if (item.IsEmploy == false)
  58. // {
  59. // item.MaterialID = ingredients.Id;
  60. // item.Name = ingredients.Name;
  61. // item.IsEmploy = true;
  62. // item.Weight = ScaleCurrentWeight;
  63. // ActionManage.GetInstance.Send("ItemStorage", IngredientsItorage.IndexOf(item) +
  64. // 1); Json<ItemStorageInfo>.Save();
  65. // IngredientsItorage = new ObservableCollection<ItemStorage>(Json<ItemStorageInfo>.Data.IngredientsStorage);
  66. // Application.Current.Dispatcher.Invoke(() => {
  67. // NoticeDemoViewModel.OpenMsg(EnumPromptType.Success,
  68. // Application.Current.MainWindow, "入库成功", $"物料{ingredients.Name}入库成功。");
  69. // });
  70. // return;
  71. // }
  72. // }
  73. // Application.Current.Dispatcher.Invoke(() =>
  74. // {
  75. // NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "入库失败", $"物料库已满。");
  76. // });
  77. // }
  78. // else
  79. // {
  80. // Application.Current.Dispatcher.Invoke(() =>
  81. // {
  82. // NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "入库失败", $"物料入库失败。");
  83. // });
  84. // }
  85. //}, "ItemStorageTask");
  86. #endregion 暂时弃用
  87. });
  88. InitialStorageCommand = new(() =>
  89. {
  90. if (MessageNotify.GetInstance.ShowDialog($"确定清空所有仓位吗?"))
  91. {
  92. for (int i = 0; i < Json<ItemStorageInfo>.Data.IngredientsStorage.Length; i++)
  93. {
  94. Json<ItemStorageInfo>.Data.IngredientsStorage[i] = new();
  95. }
  96. Json<ItemStorageInfo>.Save();
  97. ActionManage.GetInstance.Send("RefreshItemStorage");
  98. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "成功", "清空仓位信息成功。");
  99. }
  100. });
  101. WeigherTareCommand = new(() =>
  102. {
  103. if (MessageNotify.GetInstance.ShowDialog("请确认是否执行电子秤【除皮】操作?"))
  104. {
  105. Task.Run(() =>
  106. {
  107. ActionManage.GetInstance.Send("WeighrTare");
  108. });
  109. }
  110. });
  111. WeigherZeroCommand = new(() =>
  112. {
  113. if (MessageNotify.GetInstance.ShowDialog("请确认是否执行电子秤【置零】操作?"))
  114. {
  115. Task.Run(() =>
  116. {
  117. ActionManage.GetInstance.Send("WeighrZero");
  118. });
  119. }
  120. });
  121. ModifySelectStorageCommand = new((o) =>
  122. {
  123. if (o is not null && o is int index)
  124. {
  125. if (ActionManage.GetInstance.SendResult("SystemIsBusy") is bool isBusy)
  126. {
  127. if (isBusy == true)
  128. {
  129. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "失败", $"当前还有配方任务在排队制作,请稍后后再试。");
  130. return;
  131. }
  132. if (MessageNotify.GetInstance.ShowDialog($"确认修改库位【{index + 1}】的库位信息吗?"))
  133. {
  134. if (index >= 0 && index < Json<ItemStorageInfo>.Data.IngredientsStorage.Length)
  135. {
  136. ManualSetItemStorageView view = new();
  137. ActionManage.GetInstance.Send("SendItemStorageInfo", index);
  138. var result= view.ShowDialog();
  139. ActionManage.GetInstance.Send("RefreshItemStorage");
  140. if (result==true)
  141. {
  142. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "成功", $"修改库位【{index + 1}】信息成功。");
  143. }
  144. }
  145. else
  146. {
  147. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "失败", $"未找到库位【{index + 1}】,请确认后重试。");
  148. }
  149. }
  150. }
  151. }
  152. });
  153. ClearSelectStorageCommand = new((o) =>
  154. {
  155. if (o is not null && o is int index)
  156. {
  157. if (ActionManage.GetInstance.SendResult("SystemIsBusy") is bool isBusy)
  158. {
  159. if (isBusy == true)
  160. {
  161. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "失败", $"当前还有配方任务在排队制作,请稍后后再试。");
  162. return;
  163. }
  164. if (MessageNotify.GetInstance.ShowDialog($"确认清除库位【{index + 1}】的库位信息吗?"))
  165. {
  166. if (index >= 0 && index < Json<ItemStorageInfo>.Data.IngredientsStorage.Length)
  167. {
  168. Json<ItemStorageInfo>.Data.IngredientsStorage[index] = new ItemStorage();
  169. Json<ItemStorageInfo>.Save();
  170. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "成功", $"清除库位【{index+1}】信息成功。");
  171. ActionManage.GetInstance.Send("RefreshItemStorage");
  172. }
  173. else
  174. {
  175. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "失败", $"未找到库位【{index + 1}】,请确认后重试。");
  176. }
  177. }
  178. }
  179. }
  180. });
  181. }
  182. private void AddTestData()
  183. {
  184. ScaleCurrentWeight = 1.23f;
  185. //Materials.Clear();
  186. //for (int i = 1; i < 13; i++)
  187. //{
  188. // Materials.Add(new TempMaterial() { ID = 10000 + i, Loc = i.ToString(), Name = $"第{i}库位", Weight = new Random().NextSingle()*10000 });
  189. //}
  190. //Seasonings.Clear();
  191. //for (int i = 1; i < 9; i++)
  192. //{
  193. // Seasonings.Add(new TempMaterial() { ID = 10000 + i, Loc = i.ToString(), Name = $"第{i}库位", Weight = new Random().NextSingle()*10000 });
  194. //}
  195. }
  196. public BPARelayCommand<object> InStorageCommand { get; set; }
  197. /// <summary>
  198. /// 初始化库位。
  199. /// </summary>
  200. public BPARelayCommand InitialStorageCommand { get; set; }
  201. /// <summary>
  202. /// 电子秤除皮。
  203. /// </summary>
  204. [Obsolete("除皮功能弃用,不会用这个功能。")]
  205. public BPARelayCommand WeigherTareCommand { get; set; }
  206. /// <summary>
  207. /// 电子秤置零。
  208. /// </summary>
  209. public BPARelayCommand WeigherZeroCommand { get; set; }
  210. /// <summary>
  211. /// 修改指定库位信息。
  212. /// </summary>
  213. public BPARelayCommand<object> ModifySelectStorageCommand { get; set; }
  214. /// <summary>
  215. /// 清空指定库位信息。
  216. /// </summary>
  217. public BPARelayCommand<object> ClearSelectStorageCommand { get; set; }
  218. private float _ScaleCurrentWeight;
  219. public float ScaleCurrentWeight
  220. { get { return _ScaleCurrentWeight; } set { _ScaleCurrentWeight = value; OnPropertyChanged(); } }
  221. private IngredientsTB _SelectIngreditent;
  222. public IngredientsTB SelectIngreditent
  223. {
  224. get { return _SelectIngreditent; }
  225. set { _SelectIngreditent = value; OnPropertyChanged(); }
  226. }
  227. private ObservableCollection<ItemStorage> _IngredientsItorage;
  228. /// <summary>主料库位。</summary>
  229. public ObservableCollection<ItemStorage> IngredientsItorage
  230. {
  231. get { return _IngredientsItorage; }
  232. set { _IngredientsItorage = value; OnPropertyChanged(); }
  233. }
  234. private ObservableCollection<ItemStorage> _AccessoriesItorage;
  235. /// <summary>辅料库位</summary>
  236. public ObservableCollection<ItemStorage> AccessoriesItorage
  237. {
  238. get { return _AccessoriesItorage; }
  239. set { _AccessoriesItorage = value; OnPropertyChanged(); }
  240. }
  241. private ObservableCollection<IngredientsTB> _Ingredients;
  242. /// <summary>所有的主料数据。作为ComboBox的数据源。</summary>
  243. public ObservableCollection<IngredientsTB> Ingredients
  244. {
  245. get { return _Ingredients; }
  246. set { _Ingredients = value; OnPropertyChanged(); }
  247. }
  248. //private int _storageIndex;
  249. ///// <summary>
  250. ///// 库位选择的Index。
  251. ///// </summary>
  252. //public int StorageIndex
  253. //{
  254. // get { return _storageIndex; }
  255. // set { _storageIndex = value;OnPropertyChanged(); }
  256. //}
  257. }
  258. }