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