using BPASmart.Model; using BPASmartClient.Helper; 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 PowerManagerViewModel : ObservableObject { public ObservableCollection UserName { get; set; } = new ObservableCollection(); /// /// 全部物料 /// public ObservableCollection AllMaterials { get; set; } = Json.Data.locaMaterails; /// /// 用户权限物料 /// public ObservableCollection UserMaterials { get; set; } = new ObservableCollection(); /// /// 全部配方 /// public ObservableCollection AllRecipes { get; set; } = Json.Data.locaRecipes; /// /// 用户权限配方 /// public ObservableCollection UserRecipes { get; set; } = new ObservableCollection(); public RelayCommand DeleteAllCommand { get; set; } public RelayCommand AddAllCommand { get; set; } public RelayCommand AddMaterialCommand { get; set; } public RelayCommand DeleteMaterialCommand { get; set; } public RelayCommand AddRecipeCommand { get; set; } public RelayCommand DeleteRecipeCommand { get; set; } private void DeleteAll(object o) { if (o == null) return; if (o.ToString() == "Materials") { UserMaterials.Clear(); } else if (o.ToString() == "Recipes") { UserRecipes.Clear(); } } private void AddAll(object o) { if (o == null) return; if (o.ToString() == "Materials") { UserMaterials.Clear(); foreach (RecipeMaterials item in AllMaterials) { UserMaterials.Add(item); } } else if (o.ToString() == "Recipes") { UserRecipes.Clear(); foreach (Recipes item in AllRecipes) { UserRecipes.Add(item); } } } private void AddMaterial(object o) { if (o == null) return; if (o is string materail) { var res = AllMaterials.FirstOrDefault(p => p.Name == materail); if (UserMaterials.FirstOrDefault(p => p.Name == res.Name) == null) { UserMaterials.Add(res); } } } private void DeleteMaterial(object o) { if (o == null) return; if (o is string materail) { var res = UserMaterials.FirstOrDefault(p => p.Name == materail); UserMaterials.Remove(res); } } private void AddRecipe(object o) { if (o == null) return; if (o is string materail) { var res = AllRecipes.FirstOrDefault(p => p.Name == materail); if (UserRecipes.FirstOrDefault(p => p.Name == res.Name) == null) { UserRecipes.Add(res); } } } private void DeleteRecipe(object o) { if (o == null) return; if (o is string materail) { var res = UserRecipes.FirstOrDefault(p => p.Name == materail); UserRecipes.Remove(res); } } public PowerManagerViewModel() { DeleteAllCommand = new RelayCommand(DeleteAll); AddAllCommand = new RelayCommand(AddAll); AddMaterialCommand = new RelayCommand(AddMaterial); DeleteMaterialCommand = new RelayCommand(DeleteMaterial); AddRecipeCommand = new RelayCommand(AddRecipe); DeleteRecipeCommand = new RelayCommand(DeleteRecipe); UserName.Add("admin"); UserName.Add("员工1号"); UserName.Add("员工2号"); UserName.Add("员工3号"); UserName.Add("员工4号"); UserName.Add("员工5号"); UserName.Add("员工6号"); } } }