终端一体化运控平台
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

230 líneas
8.9 KiB

  1. using BPA.Models;
  2. using BPA.Helper;
  3. using BPASmartClient.Model;
  4. using BPASmartClient.Model.小炒机;
  5. using BPASmartClient.MorkF.Model;
  6. using BPASmartClient.ViewModel;
  7. using BPA.Helper;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Collections.ObjectModel;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows;
  15. using System.Windows.Threading;
  16. namespace BPASmartClient.MorkF.ViewModel
  17. {
  18. partial class LocalMenuViewModel:NotifyBase
  19. {
  20. /// <summary>
  21. /// 单个菜品流程
  22. /// </summary>
  23. public ObservableCollection<PotActions> PotActionStep { get { return _PotActionStep; }
  24. set { _PotActionStep = value; OnPropertyChanged(); } }
  25. private ObservableCollection<PotActions> _PotActionStep = new ObservableCollection<PotActions>();
  26. public string MaterialName { get; set; }
  27. /// <summary>
  28. /// 选中的菜品
  29. /// </summary>
  30. public string SelectMaterialName { get { return _selectMaterialName; } set { _selectMaterialName = value; OnPropertyChanged(); } }
  31. private string _selectMaterialName;
  32. /// <summary>
  33. /// 菜品combox集合
  34. /// </summary>
  35. public ObservableCollection<string> MaterialNames { get; set; } = new ObservableCollection<string>();
  36. /// <summary>
  37. /// 动作名称combox集合
  38. /// </summary>
  39. public ObservableCollection<string> strPotActions { get; set; } = new ObservableCollection<string>();
  40. /// <summary>
  41. /// 全部菜品流程集合
  42. /// </summary>
  43. public MaterialAndFryingTime materialAndFryingTime { get; set; } = Json<MaterialAndFryingTime>.Data;
  44. public BPARelayCommand<object> Delete { get; set; }
  45. public BPARelayCommand AddFryTime { get; set; }
  46. public BPARelayCommand NewStartLocalMaterial { get; set; }
  47. public BPARelayCommand AddMaterial { get; set; }
  48. public BPARelayCommand DeleteMaterial { get; set; }
  49. public BPARelayCommand RenameMaterial { get; set; }
  50. public BPARelayCommand Save { get; set; }
  51. private void Deleted(object o)
  52. {
  53. if (o == null) return;
  54. if(o is PotActions p)
  55. {
  56. PotActionStep.Remove(p);
  57. }
  58. for (int i = 0; i < PotActionStep.Count; i++)
  59. {
  60. PotActionStep[i].FryTime = i + 1;
  61. }
  62. }
  63. public LocalMenuViewModel()
  64. {
  65. //if (Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions.Count > 0)
  66. //{
  67. // PotActionStep.Clear();
  68. // PotActionStep = new ObservableCollection<PotActions>(Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions);
  69. //}
  70. Json<MaterialAndFryingTime>.Read();
  71. if (Json<MaterialAndFryingTime>.Data.materials.Count > 0)
  72. {
  73. MaterialNames.Clear();
  74. materialAndFryingTime.materials = Json<MaterialAndFryingTime>.Data.materials;
  75. foreach (var item in materialAndFryingTime.materials)
  76. {
  77. MaterialNames.Add(item.Key);
  78. //if (MaterialNames.Count == 1)
  79. //{
  80. // MaterialName = item.Key;
  81. // PotActionStep.Clear();
  82. // foreach (var item2 in item.Value)
  83. // {
  84. // PotActionStep.Add(item2);
  85. // }
  86. //}
  87. }
  88. }
  89. Delete = new BPARelayCommand<object>(Deleted);
  90. AddFryTime = new BPARelayCommand(() =>
  91. {
  92. List<SeasoningList> seasoningLists = new List<SeasoningList>();
  93. seasoningLists.Add(new SeasoningList { Loc = 0, Qty = 0 });
  94. PotActionStep.Add(new BPA.Models.PotActions
  95. {
  96. FryTime = PotActionStep.Count + 1,
  97. During = 0,
  98. SeasoningLists = seasoningLists,
  99. });
  100. });
  101. NewStartLocalMaterial = new BPARelayCommand(() =>
  102. {
  103. ActionManage.GetInstance.Send("NewStartLocalOrder", SelectMaterialName);
  104. });
  105. AddMaterial = new BPARelayCommand(() =>
  106. {
  107. //尝试是否能找到
  108. if(MaterialNames.FirstOrDefault(o=>o == MaterialName) == MaterialName)
  109. {
  110. MessageBox.Show("该菜品已经添加");
  111. }
  112. else
  113. {
  114. MaterialNames.Add(MaterialName);
  115. SelectMaterialName = MaterialName;
  116. }
  117. });
  118. DeleteMaterial = new BPARelayCommand(() =>
  119. {
  120. if (materialAndFryingTime.materials.ContainsKey(SelectMaterialName))
  121. {
  122. materialAndFryingTime.materials.Remove(SelectMaterialName);
  123. }
  124. MaterialNames.Remove(SelectMaterialName);
  125. PotActionStep.Clear();
  126. });
  127. //RenameMaterial = new BPARelayCommand(() =>
  128. //{
  129. // //尝试是否能找到
  130. // if (MaterialNames.FirstOrDefault(o => o == SelectMaterialName) == SelectMaterialName)
  131. // {
  132. // MaterialNames.Remove(SelectMaterialName);
  133. // MaterialNames.Add(MaterialName);
  134. // if (materialAndFryingTime.materials.ContainsKey(SelectMaterialName))
  135. // {
  136. // materialAndFryingTime.materials.Add(MaterialName, materialAndFryingTime.materials[SelectMaterialName]);
  137. // materialAndFryingTime.materials.Remove(SelectMaterialName);
  138. // }
  139. // }
  140. //});
  141. Save = new BPARelayCommand(new Action(() =>
  142. {
  143. if(PotActionStep.Count > 0)
  144. {
  145. ObservableCollection<PotActions> newPotActionSteps = new ObservableCollection<PotActions>();
  146. foreach (var step in PotActionStep)
  147. {
  148. newPotActionSteps.Add(step);
  149. }
  150. if (materialAndFryingTime.materials.ContainsKey(SelectMaterialName))
  151. {
  152. materialAndFryingTime.materials[SelectMaterialName] = newPotActionSteps;
  153. }
  154. else
  155. {
  156. materialAndFryingTime.materials.Add(SelectMaterialName, newPotActionSteps);
  157. }
  158. }
  159. //Json<LocalPotStep>.Data.LocalstirFryGoods.GoodsKey = 11;
  160. //Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions = new List<PotActions>(PotActionStep);
  161. //Json<LocalPotStep>.Save();
  162. //Json<MaterialAndFryingTime>.Data.materials = materialAndFryingTime.materials;
  163. Json<MaterialAndFryingTime>.Save();
  164. //ActionManage.GetInstance.Send("LocalMenuClose");
  165. }));
  166. foreach(var pot in Enum.GetNames(typeof(StirFryPotActionEnum)))
  167. {
  168. strPotActions.Add(pot);
  169. }
  170. ActionManage.GetInstance.Register(new Action(()=>
  171. {
  172. for (int i = 0; i < Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions.Count; i++)
  173. {
  174. Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions[i].FryTime = i + 1;
  175. }
  176. }), "SortFryTime");
  177. ActionManage.GetInstance.Register(new Action<object>((o) =>
  178. {
  179. if (o == null) return ;
  180. if(o is int[] ints)
  181. {
  182. Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions[ints[0]].FryTime = ints[1]+1;
  183. Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions[ints[1]].FryTime = ints[0]+1;
  184. var res = Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions[ints[0]];
  185. Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions.Remove(res);
  186. Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions.Insert(ints[1],res);
  187. }
  188. }), "PotActionStep");
  189. ActionManage.GetInstance.Register(new Action<object>(o =>
  190. {
  191. if (o is string str)
  192. {
  193. SelectMaterialName = str;
  194. PotActionStep.Clear();
  195. if (materialAndFryingTime.materials.ContainsKey(str))
  196. {
  197. foreach (var item2 in materialAndFryingTime.materials[str])
  198. {
  199. PotActionStep.Add(item2);
  200. }
  201. }
  202. }
  203. }), "LoacMenuSelectMaterial",true);
  204. }
  205. }
  206. }