|
- 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<RecipesInfo>.Data.LocalRecipes;
- //AddTestData();
-
- //SaveParamCommand = new(() =>
- //{
- // if (MessageNotify.GetInstance.ShowDialog("是否保存所有配方信息?", DialogType.Warning))
- // {
- // Json<RecipesInfo>.Save();
- // NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "提示", $"保存配方信息成功!");
- // }
- //});
- AddRecipeCommand = new(() =>
- {
- EditRecipeView editRecipeView = new EditRecipeView();
- editRecipeView.ShowDialog();
- });
- RemoveCommand = new((id) =>
- {
- if (MessageNotify.GetInstance.ShowDialog("是否删除该配方?", DialogType.Warning))
- {
- var deleteRecipe = Json<RecipesInfo>.Data.LocalRecipes.FirstOrDefault(recipe => recipe.Id == id.ToString());
- if (deleteRecipe != null)
- {
- Json<RecipesInfo>.Data.LocalRecipes.Remove(deleteRecipe);
- Json<RecipesInfo>.Save();
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "提示", $"删除配方:{deleteRecipe.Id} 并保存成功!");
- }
- }
- });
- ClearAllRecipeCommand = new(() =>
- {
- if (MessageNotify.GetInstance.ShowDialog("是否清除所有配方?", DialogType.Warning))
- {
- Json<RecipesInfo>.Data.LocalRecipes.Clear();
- Json<RecipesInfo>.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<ControlData>(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<ItemStorageInfo>.Data.IngredientsStorage.Any(i => i.MaterialID == Id/* && i.Weight ==weight*/))
- {
- MessageNotify.GetInstance.ShowDialog($"未在主料库查找到配方所需的主料【{Id}】,下发失败。", DialogType.Error);
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "提示", $"下发订单{data.Name}失败!");
- return;
- }
- break;
-
- case EFunc.添加辅料:
- if (SqliteHelper.GetInstance.GetAccessoriesInfo(item.funcPars[0].Id) == null)
- {
- MessageNotify.GetInstance.ShowDialog($"未在辅料信息查找到配方所需的辅料【{item.funcPars[0].Id}】,下发失败。", DialogType.Error);
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "提示", $"下发订单{data.Name}失败!");
- return;
- }
- break;
-
- case EFunc.添加调料:
- if (SqliteHelper.GetInstance.GetSeasoningInfo(item.funcPars[0].Id) == null)
- {
- MessageNotify.GetInstance.ShowDialog($"未在调料信息查找到配方所需的调料【{item.funcPars[0].Id}】,下发失败。", DialogType.Error);
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "提示", $"下发订单{data.Name}失败!");
- return;
- }
- 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(NotifyTopic.FormulaDistribution, data);
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "提示", $"下发订单{data.Name}成功!");
- }
- }
- });
- EditCommand = new((o) =>
- {
- EditRecipeView editRecipeView = new EditRecipeView();
- ActionManage.GetInstance.Send("OpenRecipeEditView", o);
- editRecipeView.ShowDialog();
- });
- }
-
- /// <summary>配方类,里面应该包含配方数据。</summary>
- public ObservableCollection<ControlData> Recipes { get; set; }
-
- /// <summary>保存参数。</summary>
- //public BPARelayCommand SaveParamCommand { get; set; }
-
- /// <summary>添加配方。</summary>
- public BPARelayCommand AddRecipeCommand { get; set; }
-
- /// <summary>移除配方。</summary>
- public BPARelayCommand<object> RemoveCommand { get; set; }
-
- /// <summary>下发配方。</summary>
- public BPARelayCommand<object> IssueCommand { get; set; }
-
- /// <summary>编辑配方。</summary>
- public BPARelayCommand<object> 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}道菜。" });
- }
- }
- }
- }
|