using System; using Microsoft.Toolkit.Mvvm.ComponentModel; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Collections.ObjectModel; using BPASmart.Model; using Microsoft.Toolkit.Mvvm.Input; using BPASmart.RecipeManagement.View; using System.Windows.Controls; using BPASmart.RecipeManagement.Globle; using BPASmartClient.Helper; namespace BPASmart.RecipeManagement.ViewModel { public class MaterialManagerViewModel : ObservableObject { /// /// 原料集合 /// public ObservableCollection MaterialList { get; set; } = Json.Data.locaMaterails; public RelayCommand CreateMaterailCommand { get; set; } public RelayCommand EditMaterailCommand { get; set; } public RelayCommand DeleteMaterailCommand { get; set; } private void EditMaterail(object o) { if (o == null) return; if (o is int item && item >= 0) { GlobleData.ChangeMaterail = new RecipeMaterials(); GlobleData.ChangeMaterail = MaterialList[item]; MaterialConfigure materialConfigure = new MaterialConfigure(); materialConfigure.ShowDialog(); } } private void DeleteMaterail(object o) { if (o == null) return; if (o is int item && item >= 0) { MaterialList.RemoveAt(item); Json.Save(); } } public MaterialManagerViewModel() { CreateMaterailCommand = new RelayCommand(() => { GlobleData.ChangeMaterail = null; MaterialConfigure materialConfigure = new MaterialConfigure(); materialConfigure.ShowDialog(); }); EditMaterailCommand = new RelayCommand(EditMaterail); DeleteMaterailCommand = new RelayCommand(DeleteMaterail); } } }