using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using BPA.Helper; using BPASmartClient.CustomResource.Pages.Model; using BPASmartClient.CustomResource.UserControls; using BPASmartClient.CustomResource.UserControls.MessageShow; using BPASmartClient.SmallBatchingSystem.Views; using Microsoft.Toolkit.Mvvm.ComponentModel; using Microsoft.Toolkit.Mvvm.Input; namespace BPASmartClient.SmallBatchingSystem.ViewModels { public class RecipeViewModel : BaseModel { public RecipeViewModel() { AddCommand = new RelayCommand(() => { NewRecipeView newOutletView = new NewRecipeView(); newOutletView.ShowDialog(); }); SaveCommand = new RelayCommand(() => { Json.Save(); Control.GetInstance.NotifyPrompt("配方保存成功"); }); RecipeInfoModels = Json.Data.Recipes; RemoveCommand = new RelayCommand((o) => { if (!string.IsNullOrEmpty(o?.ToString())) { var res = Json.Data.Recipes.FirstOrDefault(p => p.RecipeName == o.ToString()); if (res != null) { if (MessageNotify.GetInstance.ShowDialog($"是否删除【{res.RecipeName}】配方,删除后数据将永久丢失!无法找回", DialogType.Warning)) { Json.Data.Recipes.Remove(res); Control.GetInstance.NotifyPrompt($"{res.RecipeName} 删除成功"); Control.GetInstance.OperationLog($"{res.RecipeName} 删除成功"); } } } }); DetailsCommand = new RelayCommand((o) => { if (!string.IsNullOrEmpty(o?.ToString())) { var res = Json.Data.Recipes.FirstOrDefault(p => p.RecipeName == o.ToString()); if (res != null) { NewRecipeView newOutletView = new NewRecipeView(); ActionManage.GetInstance.Send("OpenNewRecipe", res); newOutletView.ShowDialog(); Control.GetInstance.OperationLog($"{res.RecipeName} 编辑完成"); } } }); } public ObservableCollection RecipeInfoModels { get; set; } } }