using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Toolkit.Mvvm.ComponentModel; using System.Collections.Concurrent; using System.Collections.ObjectModel; using System.Windows; using BPASmartClient.Helper; using Microsoft.Toolkit.Mvvm.Input; using BPASmartClient.DosingSystem.View; using BPASmartClient.CustomResource.UserControls; using BPASmartClient.CustomResource.UserControls.Model; using BPASmartClient.CustomResource.UserControls.Enum; using System.Windows.Media; using BPASmartClient.CustomResource.UserControls.MessageShow; using BPASmartClient.CustomResource.Pages.Model; using BPASmartClient.Model; namespace BPASmartClient.DosingSystem.ViewModel { public class RecipeSettingsViewModel : ObservableObject { public RecipeSettingsViewModel() { Recipes = Json.Data.Recipes; NewMaterital = new RelayCommand(() => { NewMaterialView newMateritalView = new NewMaterialView(); newMateritalView.ShowDialog(); }); NewRecipe = new RelayCommand(() => { NewRecipeView nrv = new NewRecipeView(); nrv.ShowDialog(); MessageLog.GetInstance.ShowUserLog("新建配方"); }); SaveRecipe = new RelayCommand(() => { Json.Save(); MessageLog.GetInstance.ShowUserLog("保存配方"); NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方保存成功!"); }); RemoveCommand = new RelayCommand((o) => { if (!string.IsNullOrEmpty(o?.ToString())) { if (MessageLog.GetInstance.ShowDialog($"是否删除【{o.ToString()}】配方,删除后数据将永久丢失!无法找回", DialogType.Warning)) { var res = Json.Data.Recipes.FirstOrDefault(p => p.RecipeName == o.ToString()); if (res != null) Json.Data.Recipes.Remove(res); Json.Save(); NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方删除成功!"); MessageLog.GetInstance.ShowUserLog($"删除配方 {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 nrv = new NewRecipeView(); ActionManage.GetInstance.Send("Details", res); nrv.ShowDialog(); } //MessageLog.GetInstance.ShowUserLog($"编辑配方名称——{res.RecipeName}"); } }); } public RelayCommand NewMaterital { get; set; } public RelayCommand NewRecipe { get; set; } public RelayCommand SaveRecipe { get; set; } public RelayCommand EditCommand { get; set; } public RelayCommand DetailsCommand { get; set; } public RelayCommand RemoveCommand { get; set; } public ObservableCollection Recipes { get; set; } } }