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

351 lines
16 KiB

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