|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410 |
- using BPASmartClient.CustomResource.Pages.Model;
- using BPASmartClient.CustomResource.UserControls.MessageShow;
- using BPASmartClient.MorkCL.Model.Json;
- using BPASmartClient.MorkCL.Model.Recipe;
-
- namespace BPASmartClient.MorkCL.ViewModel
- {
- public class EditRecipeViewModel : NotifyBase
- {
- public EditRecipeViewModel()
- {
- //AddTestData();
-
- Functions = new();
-
- ActionManage.GetInstance.Register((object o) =>
- {
- if (o != null && o is ControlData recipe)
- {
- this.Name = recipe.Name;
- this.ID = recipe.Id;
- this.DishType = recipe.DishType;
- int step = 0;
- Functions.Clear();
- foreach (var func in recipe.ControlFuncs)
- {
- step++;
- Functions.Add(new FuncModel() { eFunc = func.eFunc, funcPars = func.funcPars });
- }
- }
- }, "OpenRecipeEditView", true);
-
- AllFunc = new ObservableCollection<string>();
- foreach (var item in Enum.GetNames(typeof(EFunc)))
- {
- AllFunc.Add(item);
- }
-
- AllDishType = new ObservableCollection<string>();
- foreach (var item in Enum.GetNames(typeof(EDishType)))
- {
- AllDishType.Add(item);
- }
-
- SaveParamCommand = new BPARelayCommand(() =>
- {
- if (!MessageNotify.GetInstance.ShowDialog("请确认是否保存该配方?"))
- {
- return;
- }
-
- #region 数据验证
-
- if (String.IsNullOrEmpty(Name) || Name.Length <= 0)
- {
- MessageNotify.GetInstance.ShowDialog("配方名称不可为空,请重新输入后重试!", DialogType.Error);
- return;
- }
- //if (!int.TryParse(ID,out int Id))
- //{
- // MessageNotify.GetInstance.ShowDialog("配方ID不是数字,请重新输入后重试!");
- // return;
- //}
- if (Functions == null || Functions.Count <= 0)
- {
- MessageNotify.GetInstance.ShowDialog("没有可保存的配方功能配置,请验证后重试!", DialogType.Error);
- return;
- }
- foreach (FuncModel item in Functions)
- {
- for (int i = 0; i < item.funcPars.Count; i++)
- {
- var argument = item.funcPars[i].ParValue;
- if (argument == null || String.IsNullOrEmpty(argument.ToString()) || argument.ToString().Length <= 0)
- {
- MessageNotify.GetInstance.ShowDialog($"{item.eFunc}功能的参数项未设置,请修改验证后重试!", DialogType.Error);
- return;
- }
- }
- switch (item.eFunc)
- {
- case EFunc.搅拌启动:
- if (int.TryParse(item.funcPars[0].ParValue?.ToString(), out int agitateSpeed))
- {
- if (agitateSpeed > 60 || agitateSpeed <= 0)
- {
- MessageNotify.GetInstance.ShowDialog($"{item.eFunc}功能的搅拌速度限值0--60HZ,请修改验证后重试!", DialogType.Error);
- return;
- }
- }
- else
- {
- MessageNotify.GetInstance.ShowDialog($"{item.eFunc}功能的搅拌速度不是整数,请修改验证后重试!", DialogType.Error);
- return;
- }
- break;
-
- case EFunc.搅拌停止:
- break;
-
- case EFunc.加热启动:
- if (int.TryParse(item.funcPars[0].ParValue?.ToString(), out int heatGear))
- {
- if (heatGear > 8 || heatGear <= 0)
- {
- MessageNotify.GetInstance.ShowDialog($"{item.eFunc}功能的加热档位限值1--8,请修改验证后重试!", DialogType.Error);
- return;
- }
- }
- else
- {
- MessageNotify.GetInstance.ShowDialog($"{item.eFunc}功能的加热档位不是整数,请修改验证后重试!", DialogType.Error);
- return;
- }
- break;
-
- case EFunc.加热停止:
- break;
-
- case EFunc.添加调料:
- if (double.TryParse(item.funcPars[1].ParValue?.ToString(), out double seasoningWeight))
- {
- if (seasoningWeight <= 0)
- {
- MessageNotify.GetInstance.ShowDialog($"{item.eFunc}功能的调料需求值小于0,请修改验证后重试!", DialogType.Error);
- return;
- }
- }
- else
- {
- MessageNotify.GetInstance.ShowDialog($"{item.eFunc}功能的调料需求值不是纯数字,请修改验证后重试!", DialogType.Error);
- return;
- }
- break;
-
- case EFunc.添加主料:
- if (double.TryParse(item.funcPars[1].ParValue?.ToString(), out double ingredientsWeight))
- {
- if (ingredientsWeight <= 0)
- {
- MessageNotify.GetInstance.ShowDialog($"{item.eFunc}功能的主料份量小于0,请修改验证后重试!", DialogType.Error);
- return;
- }
- }
- else
- {
- MessageNotify.GetInstance.ShowDialog($"{item.eFunc}功能的主料份量不是纯数字,请修改验证后重试!", DialogType.Error);
- return;
- }
- break;
-
- case EFunc.添加辅料:
- break;
-
- case EFunc.炒锅回原点位:
- break;
-
- case EFunc.出餐启动:
- break;
-
- case EFunc.炒锅清洗:
- break;
-
- case EFunc.炒锅回调料投料位置:
- break;
-
- case EFunc.去指定炒制位:
- if (int.TryParse(item.funcPars[0].ParValue?.ToString(), out int fryingPanLoc))
- {
- if (fryingPanLoc > 4 || fryingPanLoc <= 0)
- {
- MessageNotify.GetInstance.ShowDialog($"{item.eFunc}功能的设定炒制位限值1--4,请修改验证后重试!", DialogType.Error);
- return;
- }
- }
- else
- {
- MessageNotify.GetInstance.ShowDialog($"{item.eFunc}功能的设定炒制不是整数,请修改验证后重试!", DialogType.Error);
- return;
- }
- break;
-
- case EFunc.炒制:
- if (int.TryParse(item.funcPars[0].ParValue.ToString(), out int stirFryTime))
- {
- if (stirFryTime <= 0)
- {
- MessageNotify.GetInstance.ShowDialog($"{item.eFunc}功能的炒制时间设置小于0,请修改验证后重试!", DialogType.Error);
- return;
- }
- }
- else
- {
- MessageNotify.GetInstance.ShowDialog($"{item.eFunc}功能的炒制时间不是纯数字,请修改验证后重试!", DialogType.Error);
- return;
- }
- break;
-
- default:
- break;
- }
- }
-
- #endregion 数据验证
-
- List<FuncModel> TempFunces = new List<FuncModel>();
- //查询是否是编辑现有配方。
- int index = Array.FindIndex(Json<RecipesInfo>.Data.LocalRecipes.ToArray(), p => p.Id == ID);
- //修改配方
- if (index >= 0)
- {
- foreach (var item in Functions)
- {
- //TempFunces.Add((EFunc)Enum.Parse(typeof(EFunc), item.FuncName), item.FuncPars?.ToArray());
- TempFunces.Add(new FuncModel()
- {
- eFunc = item.eFunc,
- funcPars = new List<FuncPar>(item.funcPars)
- });
- }
- Json<RecipesInfo>.Data.LocalRecipes.ElementAt(index).Id = ID;
- Json<RecipesInfo>.Data.LocalRecipes.ElementAt(index).Name = Name;
- Json<RecipesInfo>.Data.LocalRecipes.ElementAt(index).DishType = DishType;
- Json<RecipesInfo>.Data.LocalRecipes.ElementAt(index).ControlFuncs = new ConcurrentQueue<FuncModel>(TempFunces);
- Json<RecipesInfo>.Save();
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "提示", $"修改配方:{Name} 并保存成功!");
- }
- //没找到则为新增配方
- else
- {
- foreach (var item in Functions)
- {
- //TempFunces.Add((EFunc)Enum.Parse(typeof(EFunc), item.FuncName), item.FuncPars?.ToArray());
- TempFunces.Add(new FuncModel()
- {
- eFunc = item.eFunc,
- funcPars = new List<FuncPar>(item.funcPars)
- });
- }
- Json<RecipesInfo>.Data.LocalRecipes.Add(new ControlData()
- {
- Id = Guid.NewGuid().ToString(),
- Name = Name,
- Remark = " ",
- DishType = DishType,
- ControlFuncs = new ConcurrentQueue<FuncModel>(TempFunces)
- });
- Json<RecipesInfo>.Save();
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "提示", $"新增配方:{Name} 并保存成功!");
- }
- //关闭窗体。
- ActionManage.GetInstance.Send("CloseEditRecipeView");
- });
- AddFuncCommand = new BPARelayCommand(() =>
- {
- Functions.Add(new FuncModel()
- {
- eFunc = EFunc.搅拌启动,
- funcPars = InitData.FunParInit[EFunc.搅拌启动]?.ToList()
- });
- });
- FuncChangeCommand = new BPARelayCommand<object>((o) =>
- {
- if (o != null && o is FuncModel model)
- {
- model.funcPars = InitData.FunParInit[model.eFunc].ToList();
- }
- });
- RemoveCommand = new BPARelayCommand<object>((o) =>
- {
- if (o != null && o is FuncModel func)
- {
- Functions.Remove(func);
- }
- });
-
- EditCommand = new BPARelayCommand<object>((o) =>
- {
- if (o is FuncModel funcSet)
- {
- EditFunctionParamView editFunction = new EditFunctionParamView();
- ActionManage.GetInstance.Send("OpenFuncEditView", o);
- if (editFunction.ShowDialog() == true)
- {
- funcSet.funcPars.Clear();
- //funcSet.funcPars = EditFunctionParamViewModel.FuncPars?.ToList();
- foreach (var item in EditFunctionParamViewModel.FuncPars)
- {
- funcSet.funcPars.Add(new FuncPar() { Id = item.Id, ParName = item.ParName, ParValue = item.ParValue, ParUnit = item.ParUnit, ParDescribe = item.ParDescribe });
- //funcSet.funcPars.Add((FuncPar)item);
- }
- }
- }
- });
- MoveUpCommand = new((o) =>
- {
- if (o != null && o is FuncModel funcmodel)
- {
- var index = Functions.IndexOf(funcmodel);
- if (index > 0)
- {
- int newIndex = index - 1;
- Functions.RemoveAt(index);
- Functions.Insert(newIndex, funcmodel);
- }
- }
- });
-
- MoveDownCommand = new((o) =>
- {
- if (o != null && o is FuncModel funcmodel)
- {
- var index = Functions.IndexOf(funcmodel);
- if (index < Functions.Count - 1)
- {
- int newIndex = index + 1;
- Functions.RemoveAt(index);
- Functions.Insert(newIndex, funcmodel);
- }
- }
- });
- }
-
- private void AddTestData()
- {
- ID = "32587";
- Name = "红烧肉";
-
- //Functions = InitData.FunParInit;
- //Functions = new ObservableCollection<EFunc>();
- //foreach (var item in InitData.FunParInit.Keys)
- //{
- // Functions.Add(item);
- //}
- }
-
- /// <summary>保存参数。</summary>
- public BPARelayCommand SaveParamCommand { get; set; }
-
- /// <summary>添加功能</summary>
- public BPARelayCommand AddFuncCommand { get; set; }
-
- /// <summary>删除功能。</summary>
- public BPARelayCommand<object> RemoveCommand { get; set; }
-
- /// <summary>功能选择改变。</summary>
- public BPARelayCommand<object> FuncChangeCommand { get; set; }
-
- /// <summary>编辑功能。</summary>
- public BPARelayCommand<object> EditCommand { get; set; }
-
- /// <summary>功能上移。</summary>
- public BPARelayCommand<object> MoveUpCommand { get; set; }
-
- /// <summary>功能下移。</summary>
- public BPARelayCommand<object> MoveDownCommand { get; set; }
-
- private ObservableCollection<FuncModel> _Functions;
-
- public ObservableCollection<FuncModel> Functions
- {
- get { return _Functions; }
- set { _Functions = value; OnPropertyChanged(); }
- }
-
- private string _Name;
-
- /// <summary>配方名称</summary>
- public string Name
- {
- get { return _Name; }
- set { _Name = value; OnPropertyChanged(); }
- }
-
- private string _ID;
-
- /// <summary>配方ID。</summary>
- public string ID
- {
- get { return _ID; }
- set { _ID = value; OnPropertyChanged(); }
- }
-
- private ObservableCollection<string> _AllFunc;
-
- /// <summary>所有功能集合。</summary>
- public ObservableCollection<string> AllFunc
- {
- get { return _AllFunc; }
- set { _AllFunc = value; OnPropertyChanged(); }
- }
-
- private ObservableCollection<string> _AllDishType;
-
- /// <summary>所有菜品集合。</summary>
- public ObservableCollection<string> AllDishType
- {
- get { return _AllDishType; }
- set { _AllDishType = value; OnPropertyChanged(); }
- }
-
- private EDishType _DishType;
-
- public EDishType DishType
- {
- get { return _DishType; }
- set { _DishType = value; OnPropertyChanged(); }
- }
- }
- }
|