终端一体化运控平台
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

181 行
8.7 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. RemoveCommand = new((id) =>
  29. {
  30. if (MessageNotify.GetInstance.ShowDialog("是否删除该配方?", DialogType.Warning))
  31. {
  32. var deleteRecipe = Json<RecipesInfo>.Data.LocalRecipes.FirstOrDefault(recipe => recipe.Id == id.ToString());
  33. if (deleteRecipe != null)
  34. {
  35. Json<RecipesInfo>.Data.LocalRecipes.Remove(deleteRecipe);
  36. Json<RecipesInfo>.Save();
  37. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "提示", $"删除配方:{deleteRecipe.Id} 并保存成功!");
  38. }
  39. }
  40. });
  41. ClearAllRecipeCommand = new(() =>
  42. {
  43. if (MessageNotify.GetInstance.ShowDialog("是否清除所有配方?", DialogType.Warning))
  44. {
  45. Json<RecipesInfo>.Data.LocalRecipes.Clear();
  46. Json<RecipesInfo>.Save();
  47. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "提示", $"清除所有配方信息成功!");
  48. }
  49. });
  50. IssueCommand = new((o) =>
  51. {
  52. //参数为ControlData,可能需要转换。
  53. if (MessageNotify.GetInstance.ShowDialog("请确认,是否下发订单?"))
  54. {
  55. if (o != null && o is ControlData)
  56. {
  57. var jsonString = o.ToJSON();
  58. var data = JsonConvert.DeserializeObject<ControlData>(jsonString);
  59. #region 查询主料,调料,辅料是否在信息中。
  60. foreach (var item in data.ControlFuncs)
  61. {
  62. switch (item.eFunc)
  63. {
  64. case EFunc.搅拌启动:
  65. case EFunc.搅拌停止:
  66. case EFunc.加热启动:
  67. case EFunc.加热停止:
  68. case EFunc.炒锅回原点位:
  69. case EFunc.出餐启动:
  70. case EFunc.炒锅清洗:
  71. case EFunc.炒锅回调料投料位置:
  72. case EFunc.去指定炒制位:
  73. case EFunc.炒制:
  74. break;
  75. case EFunc.添加主料:
  76. var Id = item.funcPars[0].Id;
  77. var weight = Convert.ToSingle(item.funcPars[1].ParValue);
  78. if (!Json<ItemStorageInfo>.Data.IngredientsStorage.Any(i => i.MaterialID == Id/* && i.Weight ==weight*/))
  79. {
  80. MessageNotify.GetInstance.ShowDialog($"未在主料库查找到配方所需的主料【{Id}】,下发失败。", DialogType.Error);
  81. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "提示", $"下发订单{data.Name}失败!");
  82. return;
  83. }
  84. break;
  85. case EFunc.添加辅料:
  86. if (SqliteHelper.GetInstance.GetAccessoriesInfo(item.funcPars[0].Id) == null)
  87. {
  88. MessageNotify.GetInstance.ShowDialog($"未在辅料信息查找到配方所需的辅料【{item.funcPars[0].Id}】,下发失败。", DialogType.Error);
  89. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "提示", $"下发订单{data.Name}失败!");
  90. return;
  91. }
  92. break;
  93. case EFunc.添加调料:
  94. if (SqliteHelper.GetInstance.GetSeasoningInfo(item.funcPars[0].Id) == null)
  95. {
  96. MessageNotify.GetInstance.ShowDialog($"未在调料信息查找到配方所需的调料【{item.funcPars[0].Id}】,下发失败。", DialogType.Error);
  97. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "提示", $"下发订单{data.Name}失败!");
  98. return;
  99. }
  100. break;
  101. }
  102. }
  103. #endregion 查询主料,调料,辅料是否在信息中。
  104. var tempDeviceType = EDeviceType.无;
  105. if (data.DishType == Model.Recipe.EDishType.炒菜)
  106. {
  107. FryPanSelectView selectView = new();
  108. if (selectView.ShowDialog() == true)
  109. {
  110. switch (FryPanSelectViewModel.DeviceType)
  111. {
  112. case EDeviceType.炒锅1:
  113. case EDeviceType.炒锅2:
  114. tempDeviceType = FryPanSelectViewModel.DeviceType;
  115. break;
  116. default:
  117. return;
  118. }
  119. }
  120. else
  121. return;
  122. }
  123. else
  124. {
  125. tempDeviceType = EDeviceType.压力锅;
  126. }
  127. data.DeviceType = tempDeviceType;
  128. ActionManage.GetInstance.Send(NotifyTopic.FormulaDistribution, data);
  129. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "提示", $"下发订单{data.Name}成功!");
  130. }
  131. }
  132. });
  133. EditCommand = new((o) =>
  134. {
  135. EditRecipeView editRecipeView = new EditRecipeView();
  136. ActionManage.GetInstance.Send("OpenRecipeEditView", o);
  137. editRecipeView.ShowDialog();
  138. });
  139. }
  140. /// <summary>配方类,里面应该包含配方数据。</summary>
  141. public ObservableCollection<ControlData> Recipes { get; set; }
  142. /// <summary>保存参数。</summary>
  143. //public BPARelayCommand SaveParamCommand { get; set; }
  144. /// <summary>添加配方。</summary>
  145. public BPARelayCommand AddRecipeCommand { get; set; }
  146. /// <summary>移除配方。</summary>
  147. public BPARelayCommand<object> RemoveCommand { get; set; }
  148. /// <summary>下发配方。</summary>
  149. public BPARelayCommand<object> IssueCommand { get; set; }
  150. /// <summary>编辑配方。</summary>
  151. public BPARelayCommand<object> EditCommand { get; set; }
  152. public BPARelayCommand ClearAllRecipeCommand { get; set; }
  153. private void AddTestData()
  154. {
  155. Recipes.Clear();
  156. for (int i = 1; i < 10; i++)
  157. {
  158. //Recipes.Add(new LocalRecipeData() { ID = i.ToString(), Name = $"{i}道菜", Remark = $"这是第{i}道菜。" });
  159. }
  160. }
  161. }
  162. }