using BPASmart.Model.配方; using BPASmartClient.Helper; using BPASmartClient.RecipeManagement.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 BPASmart.RecipeManagement.ViewModel { public class RecipeManagerViewModel:ObservableObject { public ObservableCollection RecipeList { get; set; } = Json.Data.locaRecipes; public RelayCommand CreateRecipeCommand { get; set; } public RelayCommand EditRecipeCommand { get; set; } public RelayCommand DeleteRecipeCommand { get; set; } private void EditRecipe(object o) { if (o == null) return; if (o is int item && item >= 0) { Globle.GlobleData.ChangeRecipes = new Recipes(); Globle.GlobleData.ChangeRecipes = RecipeList[item]; RecipesConfigure recipesConfigure = new RecipesConfigure(); recipesConfigure.ShowDialog(); } } private void DeleteRecipe(object o) { if (o == null) return; if (o is int i && i >= 0) { RecipeList.RemoveAt(i); Json.Save(); } } public RecipeManagerViewModel() { CreateRecipeCommand = new RelayCommand(() => { Globle.GlobleData.ChangeRecipes = null; RecipesConfigure recipesConfigure = new RecipesConfigure(); recipesConfigure.ShowDialog(); }); EditRecipeCommand = new RelayCommand(EditRecipe); DeleteRecipeCommand = new RelayCommand(DeleteRecipe); } } }