|
- using BPA.Models;
- using BPA.Helper;
- using BPASmartClient.Model;
- using BPASmartClient.Model.小炒机;
- using BPASmartClient.MorkF.Model;
- using BPASmartClient.ViewModel;
- using BPA.Helper;
-
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Threading;
-
- namespace BPASmartClient.MorkF.ViewModel
- {
-
- partial class LocalMenuViewModel:NotifyBase
- {
- /// <summary>
- /// 单个菜品流程
- /// </summary>
- public ObservableCollection<PotActions> PotActionStep { get { return _PotActionStep; }
- set { _PotActionStep = value; OnPropertyChanged(); } }
- private ObservableCollection<PotActions> _PotActionStep = new ObservableCollection<PotActions>();
-
-
- public string MaterialName { get; set; }
- /// <summary>
- /// 选中的菜品
- /// </summary>
- public string SelectMaterialName { get { return _selectMaterialName; } set { _selectMaterialName = value; OnPropertyChanged(); } }
- private string _selectMaterialName;
- /// <summary>
- /// 菜品combox集合
- /// </summary>
- public ObservableCollection<string> MaterialNames { get; set; } = new ObservableCollection<string>();
-
- /// <summary>
- /// 动作名称combox集合
- /// </summary>
- public ObservableCollection<string> strPotActions { get; set; } = new ObservableCollection<string>();
- /// <summary>
- /// 全部菜品流程集合
- /// </summary>
- public MaterialAndFryingTime materialAndFryingTime { get; set; } = Json<MaterialAndFryingTime>.Data;
-
- public BPARelayCommand<object> Delete { get; set; }
- public BPARelayCommand AddFryTime { get; set; }
- public BPARelayCommand NewStartLocalMaterial { get; set; }
- public BPARelayCommand AddMaterial { get; set; }
- public BPARelayCommand DeleteMaterial { get; set; }
- public BPARelayCommand RenameMaterial { get; set; }
- public BPARelayCommand Save { get; set; }
-
- private void Deleted(object o)
- {
- if (o == null) return;
- if(o is PotActions p)
- {
- PotActionStep.Remove(p);
- }
- for (int i = 0; i < PotActionStep.Count; i++)
- {
- PotActionStep[i].FryTime = i + 1;
- }
- }
-
-
- public LocalMenuViewModel()
- {
- //if (Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions.Count > 0)
- //{
- // PotActionStep.Clear();
- // PotActionStep = new ObservableCollection<PotActions>(Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions);
- //}
- Json<MaterialAndFryingTime>.Read();
- if (Json<MaterialAndFryingTime>.Data.materials.Count > 0)
- {
- MaterialNames.Clear();
- materialAndFryingTime.materials = Json<MaterialAndFryingTime>.Data.materials;
- foreach (var item in materialAndFryingTime.materials)
- {
- MaterialNames.Add(item.Key);
- //if (MaterialNames.Count == 1)
- //{
- // MaterialName = item.Key;
- // PotActionStep.Clear();
- // foreach (var item2 in item.Value)
- // {
- // PotActionStep.Add(item2);
- // }
- //}
- }
- }
- Delete = new BPARelayCommand<object>(Deleted);
- AddFryTime = new BPARelayCommand(() =>
- {
- List<SeasoningList> seasoningLists = new List<SeasoningList>();
- seasoningLists.Add(new SeasoningList { Loc = 0, Qty = 0 });
- PotActionStep.Add(new BPA.Models.PotActions
- {
- FryTime = PotActionStep.Count + 1,
- During = 0,
- SeasoningLists = seasoningLists,
- });
- });
- NewStartLocalMaterial = new BPARelayCommand(() =>
- {
- ActionManage.GetInstance.Send("NewStartLocalOrder", SelectMaterialName);
- });
- AddMaterial = new BPARelayCommand(() =>
- {
- //尝试是否能找到
- if(MaterialNames.FirstOrDefault(o=>o == MaterialName) == MaterialName)
- {
- MessageBox.Show("该菜品已经添加");
- }
- else
- {
- MaterialNames.Add(MaterialName);
- SelectMaterialName = MaterialName;
- }
- });
- DeleteMaterial = new BPARelayCommand(() =>
- {
- if (materialAndFryingTime.materials.ContainsKey(SelectMaterialName))
- {
- materialAndFryingTime.materials.Remove(SelectMaterialName);
- }
- MaterialNames.Remove(SelectMaterialName);
- PotActionStep.Clear();
- });
- //RenameMaterial = new BPARelayCommand(() =>
- //{
- // //尝试是否能找到
- // if (MaterialNames.FirstOrDefault(o => o == SelectMaterialName) == SelectMaterialName)
- // {
- // MaterialNames.Remove(SelectMaterialName);
- // MaterialNames.Add(MaterialName);
- // if (materialAndFryingTime.materials.ContainsKey(SelectMaterialName))
- // {
- // materialAndFryingTime.materials.Add(MaterialName, materialAndFryingTime.materials[SelectMaterialName]);
- // materialAndFryingTime.materials.Remove(SelectMaterialName);
-
- // }
- // }
- //});
- Save = new BPARelayCommand(new Action(() =>
- {
- if(PotActionStep.Count > 0)
- {
- ObservableCollection<PotActions> newPotActionSteps = new ObservableCollection<PotActions>();
- foreach (var step in PotActionStep)
- {
- newPotActionSteps.Add(step);
- }
- if (materialAndFryingTime.materials.ContainsKey(SelectMaterialName))
- {
- materialAndFryingTime.materials[SelectMaterialName] = newPotActionSteps;
- }
- else
- {
- materialAndFryingTime.materials.Add(SelectMaterialName, newPotActionSteps);
- }
- }
- //Json<LocalPotStep>.Data.LocalstirFryGoods.GoodsKey = 11;
- //Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions = new List<PotActions>(PotActionStep);
- //Json<LocalPotStep>.Save();
- //Json<MaterialAndFryingTime>.Data.materials = materialAndFryingTime.materials;
- Json<MaterialAndFryingTime>.Save();
-
- //ActionManage.GetInstance.Send("LocalMenuClose");
- }));
-
- foreach(var pot in Enum.GetNames(typeof(StirFryPotActionEnum)))
- {
- strPotActions.Add(pot);
- }
-
- ActionManage.GetInstance.Register(new Action(()=>
- {
-
- for (int i = 0; i < Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions.Count; i++)
- {
- Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions[i].FryTime = i + 1;
- }
- }), "SortFryTime");
- ActionManage.GetInstance.Register(new Action<object>((o) =>
- {
- if (o == null) return ;
- if(o is int[] ints)
- {
- Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions[ints[0]].FryTime = ints[1]+1;
- Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions[ints[1]].FryTime = ints[0]+1;
- var res = Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions[ints[0]];
-
- Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions.Remove(res);
- Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions.Insert(ints[1],res);
-
- }
-
-
- }), "PotActionStep");
-
- ActionManage.GetInstance.Register(new Action<object>(o =>
- {
- if (o is string str)
- {
- SelectMaterialName = str;
- PotActionStep.Clear();
- if (materialAndFryingTime.materials.ContainsKey(str))
- {
- foreach (var item2 in materialAndFryingTime.materials[str])
- {
- PotActionStep.Add(item2);
- }
- }
- }
- }), "LoacMenuSelectMaterial",true);
-
- }
- }
-
-
- }
|