using BPASmartClient.Helper; using BPASmartClient.Message; using FryPot_DosingSystem.Model; using FryPot_DosingSystem.View; using Microsoft.Toolkit.Mvvm.ComponentModel; using Microsoft.Toolkit.Mvvm.Input; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace FryPot_DosingSystem.ViewModel { internal class RecipeSetViewModel : ObservableObject { ///// ///// 配方编号 ///// //private int _serialNumber; //public int SerialNumber { get { return _serialNumber; } set { _serialNumber = value;OnPropertyChanged(); } } ///// ///// 配方名称 ///// //private string _recipeName; //public string RecipeName { get { return _recipeName; } set { _recipeName = value; OnPropertyChanged(); } } public ObservableCollection recipeModels { get; set; } = new ObservableCollection(); public Action NewRecipe { get; set; } public Action SaveRecipe { get; set; } /// /// 编辑配方 /// public RelayCommand EditRecipeCommand { get; set; } /// /// 删除配方 /// public RelayCommand DeleteRecipeCommand { get; set; } public RecipeSetViewModel() { Json.Read(); recipeModels = Json.Data.Recipes; NewRecipe = new Action(() => { NewRecipeView nrv = new NewRecipeView(); nrv.ShowDialog(); MessageLog.GetInstance.Show("新建配方"); }); SaveRecipe = new Action(() => { Json.Save(); }); EditRecipeCommand = new RelayCommand((Id) => { if (Id != null) { ActionManage.GetInstance.CancelRegister("EditRecipe"); NewRecipeView nrv = new NewRecipeView(); ActionManage.GetInstance.Send("EditRecipe", Id); nrv.ShowDialog(); } }); DeleteRecipeCommand = new RelayCommand((Id) => { if (Id != null && Id is String strId) { var res= recipeModels.FirstOrDefault(p => p.RecipeId == strId); if (res != null && res is NewRecipeModel nes) { recipeModels.Remove(res);//删除配方 Json.Save();//保存配方 } } }); } } }