using BPASmart.Model; using BPASmart.RecipeManagement.View; using BPASmartClient.CustomResource.UserControls; using BPASmartClient.CustomResource.UserControls.MessageShow; 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; using System.Windows; 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; } /// /// 配方工艺 /// public RelayCommand PecipeSettingCommand { get; set; } /// /// 配方下发 /// public RelayCommand 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.Save(); } } private void PecipeSetting(object o) { if (o == null) return; if (o is string id) { var res = Json.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.Data.locaRecipes.FirstOrDefault(p => p.ID == id); if (res != null) { //下发配方 NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "提示", $"配方下发成功!"); } } } public RecipeManagerViewModel() { CreateRecipeCommand = new RelayCommand(() => { Globle.GlobleData.ChangeRecipes = null; RecipesConfigure recipesConfigure = new RecipesConfigure(); recipesConfigure.ShowDialog(); }); EditRecipeCommand = new RelayCommand(EditRecipe); DeleteRecipeCommand = new RelayCommand(DeleteRecipe); PecipeSettingCommand = new RelayCommand(PecipeSetting); PecipeStartCommand = new RelayCommand(PecipeStart); } } }