using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using BPA.Helper; using System.Collections.Concurrent; using System.Collections.ObjectModel; using System.Windows; using BPA.Helper; using BPASmartClient.DosingSystemSingle.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.DosingSystemSingle.ViewModel { public class RecipeSettingsViewModel : NotifyBase { public RecipeSettingsViewModel() { Recipes = Json.Data.Recipes; NewMaterital = new BPARelayCommand(() => { NewMaterialView newMateritalView = new NewMaterialView(); newMateritalView.ShowDialog(); }); NewRecipe = new BPARelayCommand(() => { NewRecipeView nrv = new NewRecipeView(); nrv.ShowDialog(); MessageNotify.GetInstance.ShowUserLog("新建配方"); }); SaveRecipe = new BPARelayCommand(() => { Json.Save(); MessageNotify.GetInstance.ShowUserLog("保存配方"); NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方保存成功!"); }); RemoveCommand = new BPARelayCommand((o) => { if (!string.IsNullOrEmpty(o?.ToString())) { if (MessageNotify.GetInstance.ShowDialog($"是否删除【{o.ToString()}】配方,删除后数据将永久丢失!无法找回", DialogType.Warning)) { var res = Json.Data.Recipes.FirstOrDefault(p => p.RecipeName == o.ToString()); if (res.IsEnable) { if (res != null) Json.Data.Recipes.Remove(res); Json.Save(); NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方删除成功!"); MessageNotify.GetInstance.ShowUserLog($"删除配方 {res.RecipeName}"); } else { NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "提示", $"删除【{o.ToString()}】配方失败,配方正在使用!"); } } } }); DetailsCommand = new BPARelayCommand((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 BPARelayCommand NewMaterital { get; set; } public BPARelayCommand NewRecipe { get; set; } public BPARelayCommand SaveRecipe { get; set; } public BPARelayCommand EditCommand { get; set; } public BPARelayCommand DetailsCommand { get; set; } public BPARelayCommand RemoveCommand { get; set; } public ObservableCollection Recipes { get; set; } } }