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

224 rivejä
12 KiB

  1. using BPA.Message;
  2. using BPASmartClient.CustomResource.Pages.Model;
  3. using BPASmartClient.CustomResource.UserControls.MessageShow;
  4. using BPASmartClient.MorkCL.Model.Json;
  5. using BPASmartClient.MorkCL.Server;
  6. using Newtonsoft.Json;
  7. namespace BPASmartClient.MorkCL.ViewModel
  8. {
  9. public class RecipeManageViewModel : NotifyBase
  10. {
  11. public RecipeManageViewModel()
  12. {
  13. Recipes = Json<RecipesInfo>.Data.LocalRecipes;
  14. //AddTestData();
  15. //SaveParamCommand = new(() =>
  16. //{
  17. // if (MessageNotify.GetInstance.ShowDialog("是否保存所有配方信息?", DialogType.Warning))
  18. // {
  19. // Json<RecipesInfo>.Save();
  20. // NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "提示", $"保存配方信息成功!");
  21. // }
  22. //});
  23. AddRecipeCommand = new(() =>
  24. {
  25. EditRecipeView editRecipeView = new EditRecipeView();
  26. editRecipeView.ShowDialog();
  27. });
  28. AddTemplateRecipeCommand = new BPARelayCommand(() =>
  29. {
  30. ControlData template = new ControlData();
  31. #region 给模板配方生成数据。
  32. template.Name = "模板配方";
  33. template.Id = Guid.NewGuid().ToString();
  34. template.Remark = "";
  35. template.DishType = Model.Recipe.EDishType.炒菜;
  36. //1. 开机 热锅
  37. template.ControlFuncs.Enqueue(new FuncModel() { eFunc = EFunc.搅拌启动, funcPars = InitData.FunParInit[EFunc.搅拌启动]?.ToList() });
  38. template.ControlFuncs.Enqueue(new FuncModel() { eFunc = EFunc.加热启动, funcPars = InitData.FunParInit[EFunc.加热启动]?.ToList() });
  39. template.ControlFuncs.Enqueue(new FuncModel() { eFunc = EFunc.炒制, funcPars = InitData.FunParInit[EFunc.炒制]?.ToList() });
  40. template.ControlFuncs.Enqueue(new FuncModel() { eFunc = EFunc.添加调料, funcPars = InitData.FunParInit[EFunc.添加调料]?.ToList() });
  41. template.ControlFuncs.Enqueue(new FuncModel() { eFunc = EFunc.添加主料, funcPars = InitData.FunParInit[EFunc.添加主料]?.ToList() });
  42. template.ControlFuncs.Enqueue(new FuncModel() { eFunc = EFunc.添加辅料, funcPars = InitData.FunParInit[EFunc.添加辅料]?.ToList() });
  43. template.ControlFuncs.Enqueue(new FuncModel() { eFunc = EFunc.添加主料, funcPars = InitData.FunParInit[EFunc.添加主料]?.ToList() });
  44. template.ControlFuncs.Enqueue(new FuncModel() { eFunc = EFunc.添加辅料, funcPars = InitData.FunParInit[EFunc.添加辅料]?.ToList() });
  45. template.ControlFuncs.Enqueue(new FuncModel() { eFunc = EFunc.加热停止, funcPars = InitData.FunParInit[EFunc.加热停止]?.ToList() });
  46. template.ControlFuncs.Enqueue(new FuncModel() { eFunc = EFunc.出餐启动, funcPars = InitData.FunParInit[EFunc.搅拌停止]?.ToList() });
  47. template.ControlFuncs.Enqueue(new FuncModel() { eFunc = EFunc.搅拌停止, funcPars = InitData.FunParInit[EFunc.搅拌停止]?.ToList() });
  48. #endregion
  49. EditRecipeView editRecipeView = new EditRecipeView();
  50. ActionManage.GetInstance.Send(template, "OpenRecipeEditView");
  51. editRecipeView.ShowDialog();
  52. });
  53. RemoveCommand = new((id) =>
  54. {
  55. if (MessageNotify.GetInstance.ShowDialog("是否删除该配方?", DialogType.Warning))
  56. {
  57. var deleteRecipe = Json<RecipesInfo>.Data.LocalRecipes.FirstOrDefault(recipe => recipe.Id == id.ToString());
  58. if (deleteRecipe != null)
  59. {
  60. Json<RecipesInfo>.Data.LocalRecipes.Remove(deleteRecipe);
  61. Json<RecipesInfo>.Save();
  62. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "提示", $"删除配方:{deleteRecipe.Id} 并保存成功!");
  63. }
  64. }
  65. });
  66. ClearAllRecipeCommand = new(() =>
  67. {
  68. if (MessageNotify.GetInstance.ShowDialog("是否清除所有配方?", DialogType.Warning))
  69. {
  70. Json<RecipesInfo>.Data.LocalRecipes.Clear();
  71. Json<RecipesInfo>.Save();
  72. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "提示", $"清除所有配方信息成功!");
  73. }
  74. });
  75. IssueCommand = new((o) =>
  76. {
  77. //参数为ControlData,可能需要转换。
  78. if (MessageNotify.GetInstance.ShowDialog("请确认,是否下发订单?"))
  79. {
  80. if (o != null && o is ControlData)
  81. {
  82. var jsonString = o.ToJSON();
  83. var data = JsonConvert.DeserializeObject<ControlData>(jsonString);
  84. #region 查询主料,调料,辅料是否在信息中。
  85. foreach (var item in data.ControlFuncs)
  86. {
  87. switch (item.eFunc)
  88. {
  89. case EFunc.搅拌启动:
  90. case EFunc.搅拌停止:
  91. case EFunc.加热启动:
  92. case EFunc.加热停止:
  93. case EFunc.炒锅回原点位:
  94. case EFunc.出餐启动:
  95. case EFunc.炒锅清洗:
  96. //case EFunc.炒锅回调料投料位置:
  97. case EFunc.去指定炒制位:
  98. case EFunc.炒制:
  99. break;
  100. case EFunc.添加主料:
  101. var Id = item.funcPars[0].Id;
  102. var weight = Convert.ToSingle(item.funcPars[1].ParValue);
  103. if (!Json<ItemStorageInfo>.Data.IngredientsStorage.Any(i => i.MaterialID == Id/* && i.Weight ==weight*/))
  104. {
  105. string name = item.funcPars[0].ParValue.ToString();
  106. MessageNotify.GetInstance.ShowDialog($"未在主料库查找到配方所需的主料【{name}】,下发失败。", DialogType.Error);
  107. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "提示", $"下发订单{data.Name}失败!");
  108. return;
  109. }
  110. break;
  111. case EFunc.添加辅料:
  112. if (SqliteHelper.GetInstance.GetAccessoriesInfo(item.funcPars[0].Id) == null)
  113. {
  114. string name = item.funcPars[0].ParValue.ToString();
  115. MessageNotify.GetInstance.ShowDialog($"未在辅料信息查找到配方所需的辅料【{name}】,下发失败。", DialogType.Error);
  116. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "提示", $"下发订单{data.Name}失败!");
  117. return;
  118. }
  119. break;
  120. case EFunc.添加调料:
  121. if (SqliteHelper.GetInstance.GetSeasoningInfo(item.funcPars[0].Id) == null)
  122. {
  123. string name = item.funcPars[0].ParValue.ToString();
  124. MessageNotify.GetInstance.ShowDialog($"未在调料信息查找到配方所需的调料【{name}】,下发失败。", DialogType.Error);
  125. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "提示", $"下发订单{data.Name}失败!");
  126. return;
  127. }
  128. break;
  129. default:
  130. break;
  131. }
  132. }
  133. #endregion 查询主料,调料,辅料是否在信息中。
  134. var tempDeviceType = EDeviceType.无;
  135. if (data.DishType == Model.Recipe.EDishType.炒菜)
  136. {
  137. FryPanSelectView selectView = new();
  138. if (selectView.ShowDialog() == true)
  139. {
  140. switch (FryPanSelectViewModel.DeviceType)
  141. {
  142. case EDeviceType.炒锅1:
  143. case EDeviceType.炒锅2:
  144. tempDeviceType = FryPanSelectViewModel.DeviceType;
  145. break;
  146. default:
  147. return;
  148. }
  149. }
  150. else
  151. return;
  152. }
  153. else
  154. {
  155. tempDeviceType = EDeviceType.压力锅;
  156. }
  157. data.DeviceType = tempDeviceType;
  158. ActionManage.GetInstance.Send(data, NotifyTopic.FormulaDistribution);
  159. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "提示", $"下发订单{data.Name}成功!");
  160. }
  161. }
  162. });
  163. EditCommand = new((o) =>
  164. {
  165. EditRecipeView editRecipeView = new EditRecipeView();
  166. ActionManage.GetInstance.Send(o, "OpenRecipeEditView");
  167. editRecipeView.ShowDialog();
  168. });
  169. }
  170. /// <summary>配方类,里面应该包含配方数据。</summary>
  171. public ObservableCollection<ControlData> Recipes { get; set; }
  172. /// <summary>保存参数。</summary>
  173. //public BPARelayCommand SaveParamCommand { get; set; }
  174. /// <summary>添加配方。</summary>
  175. public BPARelayCommand AddRecipeCommand { get; set; }
  176. /// <summary>
  177. /// 添加一个模板配方。
  178. /// </summary>
  179. public BPARelayCommand AddTemplateRecipeCommand { get; set; }
  180. /// <summary>移除配方。</summary>
  181. public BPARelayCommand<object> RemoveCommand { get; set; }
  182. /// <summary>下发配方。</summary>
  183. public BPARelayCommand<object> IssueCommand { get; set; }
  184. /// <summary>编辑配方。</summary>
  185. public BPARelayCommand<object> EditCommand { get; set; }
  186. public BPARelayCommand ClearAllRecipeCommand { get; set; }
  187. private void AddTestData()
  188. {
  189. Recipes.Clear();
  190. for (int i = 1; i < 10; i++)
  191. {
  192. //Recipes.Add(new LocalRecipeData() { ID = i.ToString(), Name = $"{i}道菜", Remark = $"这是第{i}道菜。" });
  193. }
  194. }
  195. }
  196. }