using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Toolkit.Mvvm.ComponentModel; using System.Collections.Concurrent; using System.Collections.ObjectModel; using System.Windows; using BPASmartClient.Helper; using Microsoft.Toolkit.Mvvm.Input; using BPASmartClient.DosingSystem.Model; using BPASmartClient.DosingSystem.View; namespace BPASmartClient.DosingSystem.ViewModel { public class RecipeSettingsViewModel : ObservableObject { public RecipeSettingsViewModel() { //Json.Read(); Recipes = Json.Data.Recipes; NewRecipe = new Action(() => { NewRecipeView nrv = new NewRecipeView(); nrv.ShowDialog(); }); SaveRecipe = new Action(() => { Json.Save(); }); RemoveCommand = new RelayCommand((o) => { if (o is string str) { var res = Json.Data.Recipes.FirstOrDefault(p => p.RecipCode == str); if (res != null) Json.Data.Recipes.Remove(res); } }); DetailsCommand = new RelayCommand((o) => { if (o != null && o is string str) { ActionManage.GetInstance.CancelRegister("Details"); NewRecipeView nrv = new NewRecipeView(); ActionManage.GetInstance.Send("Details", Json.Data.Recipes.FirstOrDefault(p => p.RecipCode == str)); nrv.ShowDialog(); } }); } public Action NewRecipe { get; set; } public Action SaveRecipe { get; set; } public RelayCommand EditCommand { get; set; } public RelayCommand DetailsCommand { get; set; } public RelayCommand RemoveCommand { get; set; } public ObservableCollection Recipes { get; set; } } }