using BPASmart.Model; using BPASmart.RecipeManagement.View; 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<Recipes> RecipeList { get; set; } = Json<LocalRecipes>.Data.locaRecipes; /// <summary> /// 创建配方 /// </summary> public RelayCommand CreateRecipeCommand { get; set; } public RelayCommand<object> EditRecipeCommand { get; set; } public RelayCommand<object> DeleteRecipeCommand { get; set; } /// <summary> /// 配方工艺 /// </summary> public RelayCommand<object> PecipeSettingCommand { get; set; } /// <summary> /// 配方下发 /// </summary> public RelayCommand<object> PecipeStartCommand { 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<LocalRecipes>.Save(); } } private void PecipeSetting(object o) { if (o == null) return; if (o is string id) { var res = Json<LocalRecipes>.Data.locaRecipes.FirstOrDefault(p => p.ID == id); if (res != null) { Globle.GlobleData.recipeTechnologyProcess = null; Globle.GlobleData.recipeTechnologyProcess = res; TechnologyProcess technologyProcess = new TechnologyProcess(); technologyProcess.ShowDialog(); } } } private void PecipeStart(object o) { if (o == null) return; if (o is string id) { var res = Json<LocalRecipes>.Data.locaRecipes.FirstOrDefault(p => p.ID == id); if (res != null) { //下发配方 } } } public RecipeManagerViewModel() { CreateRecipeCommand = new RelayCommand(() => { Globle.GlobleData.ChangeRecipes = null; RecipesConfigure recipesConfigure = new RecipesConfigure(); recipesConfigure.ShowDialog(); }); EditRecipeCommand = new RelayCommand<object>(EditRecipe); DeleteRecipeCommand = new RelayCommand<object>(DeleteRecipe); PecipeSettingCommand = new RelayCommand<object>(PecipeSetting); PecipeStartCommand = new RelayCommand<object>(PecipeStart); } } }