using BPA.Message; using BPASmartClient.CustomResource.Pages.Model; using BPASmartClient.CustomResource.UserControls.MessageShow; using BPASmartClient.MorkCL.Model.Json; using BPASmartClient.MorkCL.Server; using Newtonsoft.Json; namespace BPASmartClient.MorkCL.ViewModel { public class RecipeManageViewModel : NotifyBase { public RecipeManageViewModel() { Recipes = Json.Data.LocalRecipes; //AddTestData(); //SaveParamCommand = new(() => //{ // if (MessageNotify.GetInstance.ShowDialog("是否保存所有配方信息?", DialogType.Warning)) // { // Json.Save(); // NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "提示", $"保存配方信息成功!"); // } //}); AddRecipeCommand = new(() => { EditRecipeView editRecipeView = new EditRecipeView(); editRecipeView.ShowDialog(); }); AddTemplateRecipeCommand = new BPARelayCommand(() => { ControlData template = new ControlData(); #region 给模板配方生成数据。 template.Name = "模板配方"; template.Id = Guid.NewGuid().ToString(); template.Remark = ""; template.DishType = Model.Recipe.EDishType.炒菜; //1. 开机 热锅 template.ControlFuncs.Enqueue(new FuncModel() { eFunc = EFunc.搅拌启动, funcPars = InitData.FunParInit[EFunc.搅拌启动]?.ToList() }); template.ControlFuncs.Enqueue(new FuncModel() { eFunc = EFunc.加热启动, funcPars = InitData.FunParInit[EFunc.加热启动]?.ToList() }); template.ControlFuncs.Enqueue(new FuncModel() { eFunc = EFunc.炒制, funcPars = InitData.FunParInit[EFunc.炒制]?.ToList() }); template.ControlFuncs.Enqueue(new FuncModel() { eFunc = EFunc.添加调料, funcPars = InitData.FunParInit[EFunc.添加调料]?.ToList() }); template.ControlFuncs.Enqueue(new FuncModel() { eFunc = EFunc.添加主料, funcPars = InitData.FunParInit[EFunc.添加主料]?.ToList() }); template.ControlFuncs.Enqueue(new FuncModel() { eFunc = EFunc.添加辅料, funcPars = InitData.FunParInit[EFunc.添加辅料]?.ToList() }); template.ControlFuncs.Enqueue(new FuncModel() { eFunc = EFunc.添加主料, funcPars = InitData.FunParInit[EFunc.添加主料]?.ToList() }); template.ControlFuncs.Enqueue(new FuncModel() { eFunc = EFunc.添加辅料, funcPars = InitData.FunParInit[EFunc.添加辅料]?.ToList() }); template.ControlFuncs.Enqueue(new FuncModel() { eFunc = EFunc.加热停止, funcPars = InitData.FunParInit[EFunc.加热停止]?.ToList() }); template.ControlFuncs.Enqueue(new FuncModel() { eFunc = EFunc.出餐启动, funcPars = InitData.FunParInit[EFunc.搅拌停止]?.ToList() }); template.ControlFuncs.Enqueue(new FuncModel() { eFunc = EFunc.搅拌停止, funcPars = InitData.FunParInit[EFunc.搅拌停止]?.ToList() }); #endregion EditRecipeView editRecipeView = new EditRecipeView(); ActionManage.GetInstance.Send(template, "OpenRecipeEditView"); editRecipeView.ShowDialog(); }); RemoveCommand = new((id) => { if (MessageNotify.GetInstance.ShowDialog("是否删除该配方?", DialogType.Warning)) { var deleteRecipe = Json.Data.LocalRecipes.FirstOrDefault(recipe => recipe.Id == id.ToString()); if (deleteRecipe != null) { Json.Data.LocalRecipes.Remove(deleteRecipe); Json.Save(); NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "提示", $"删除配方:{deleteRecipe.Id} 并保存成功!"); } } }); ClearAllRecipeCommand = new(() => { if (MessageNotify.GetInstance.ShowDialog("是否清除所有配方?", DialogType.Warning)) { Json.Data.LocalRecipes.Clear(); Json.Save(); NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "提示", $"清除所有配方信息成功!"); } }); IssueCommand = new((o) => { //参数为ControlData,可能需要转换。 if (MessageNotify.GetInstance.ShowDialog("请确认,是否下发订单?")) { if (o != null && o is ControlData) { var jsonString = o.ToJSON(); var data = JsonConvert.DeserializeObject(jsonString); #region 查询主料,调料,辅料是否在信息中。 foreach (var item in data.ControlFuncs) { switch (item.eFunc) { case EFunc.搅拌启动: case EFunc.搅拌停止: case EFunc.加热启动: case EFunc.加热停止: case EFunc.炒锅回原点位: case EFunc.出餐启动: case EFunc.炒锅清洗: //case EFunc.炒锅回调料投料位置: case EFunc.去指定炒制位: case EFunc.炒制: break; case EFunc.添加主料: var Id = item.funcPars[0].Id; var weight = Convert.ToSingle(item.funcPars[1].ParValue); if (!Json.Data.IngredientsStorage.Any(i => i.MaterialID == Id/* && i.Weight ==weight*/)) { string name = item.funcPars[0].ParValue.ToString(); MessageNotify.GetInstance.ShowDialog($"未在主料库查找到配方所需的主料【{name}】,下发失败。", DialogType.Error); NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "提示", $"下发订单{data.Name}失败!"); return; } break; case EFunc.添加辅料: if (SqliteHelper.GetInstance.GetAccessoriesInfo(item.funcPars[0].Id) == null) { string name = item.funcPars[0].ParValue.ToString(); MessageNotify.GetInstance.ShowDialog($"未在辅料信息查找到配方所需的辅料【{name}】,下发失败。", DialogType.Error); NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "提示", $"下发订单{data.Name}失败!"); return; } break; case EFunc.添加调料: if (SqliteHelper.GetInstance.GetSeasoningInfo(item.funcPars[0].Id) == null) { string name = item.funcPars[0].ParValue.ToString(); MessageNotify.GetInstance.ShowDialog($"未在调料信息查找到配方所需的调料【{name}】,下发失败。", DialogType.Error); NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "提示", $"下发订单{data.Name}失败!"); return; } break; default: break; } } #endregion 查询主料,调料,辅料是否在信息中。 var tempDeviceType = EDeviceType.无; if (data.DishType == Model.Recipe.EDishType.炒菜) { FryPanSelectView selectView = new(); if (selectView.ShowDialog() == true) { switch (FryPanSelectViewModel.DeviceType) { case EDeviceType.炒锅1: case EDeviceType.炒锅2: tempDeviceType = FryPanSelectViewModel.DeviceType; break; default: return; } } else return; } else { tempDeviceType = EDeviceType.压力锅; } data.DeviceType = tempDeviceType; ActionManage.GetInstance.Send(data, NotifyTopic.FormulaDistribution); NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "提示", $"下发订单{data.Name}成功!"); } } }); EditCommand = new((o) => { EditRecipeView editRecipeView = new EditRecipeView(); ActionManage.GetInstance.Send(o, "OpenRecipeEditView"); editRecipeView.ShowDialog(); }); } /// 配方类,里面应该包含配方数据。 public ObservableCollection Recipes { get; set; } /// 保存参数。 //public BPARelayCommand SaveParamCommand { get; set; } /// 添加配方。 public BPARelayCommand AddRecipeCommand { get; set; } /// /// 添加一个模板配方。 /// public BPARelayCommand AddTemplateRecipeCommand { get; set; } /// 移除配方。 public BPARelayCommand RemoveCommand { get; set; } /// 下发配方。 public BPARelayCommand IssueCommand { get; set; } /// 编辑配方。 public BPARelayCommand EditCommand { get; set; } public BPARelayCommand ClearAllRecipeCommand { get; set; } private void AddTestData() { Recipes.Clear(); for (int i = 1; i < 10; i++) { //Recipes.Add(new LocalRecipeData() { ID = i.ToString(), Name = $"{i}道菜", Remark = $"这是第{i}道菜。" }); } } } }