终端一体化运控平台
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 

88 rader
3.5 KiB

  1. using BPA.Helper;
  2. using BPASmartClient.CustomResource.Pages.Model;
  3. using BPASmartClient.CustomResource.UserControls;
  4. using BPASmartClient.CustomResource.UserControls.MessageShow;
  5. using BPASmartClient.Academy.Model;
  6. using BPASmartClient.Academy.View;
  7. using System.Collections.ObjectModel;
  8. using System.Linq;
  9. namespace BPASmartClient.Academy.ViewModel
  10. {
  11. public class RecipeSettingsViewModel : NotifyBase
  12. {
  13. public RecipeSettingsViewModel()
  14. {
  15. Recipes = Json<LocalRecipe>.Data.Recipes;
  16. NewMaterital = new BPARelayCommand(() =>
  17. {
  18. NewMaterialView newMateritalView = new NewMaterialView();
  19. newMateritalView.ShowDialog();
  20. });
  21. NewRecipe = new BPARelayCommand(() =>
  22. {
  23. NewRecipeView nrv = new NewRecipeView();
  24. nrv.ShowDialog();
  25. MessageNotify.GetInstance.ShowUserLog("新建配方");
  26. });
  27. SaveRecipe = new BPARelayCommand(() =>
  28. {
  29. Json<LocalRecipe>.Save();
  30. MessageNotify.GetInstance.ShowUserLog("保存配方");
  31. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方保存成功!");
  32. });
  33. RemoveCommand = new BPARelayCommand<object>((o) =>
  34. {
  35. if (!string.IsNullOrEmpty(o?.ToString()))
  36. {
  37. if (MessageNotify.GetInstance.ShowDialog($"是否删除【{o.ToString()}】配方,删除后数据将永久丢失!无法找回", DialogType.Warning))
  38. {
  39. var res = Json<LocalRecipe>.Data.Recipes.FirstOrDefault(p => p.RecipeName == o.ToString());
  40. if (res.IsEnable)
  41. {
  42. if (res != null) Json<LocalRecipe>.Data.Recipes.Remove(res);
  43. Json<LocalRecipe>.Save();
  44. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方删除成功!");
  45. MessageNotify.GetInstance.ShowUserLog($"删除配方 {res.RecipeName}");
  46. }
  47. else
  48. {
  49. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "提示", $"删除【{o.ToString()}】配方失败,配方正在使用!");
  50. }
  51. }
  52. }
  53. });
  54. DetailsCommand = new BPARelayCommand<object>((o) =>
  55. {
  56. if (!string.IsNullOrEmpty(o?.ToString()))
  57. {
  58. var res = Json<LocalRecipe>.Data.Recipes.FirstOrDefault(p => p.RecipeName == o.ToString());
  59. if (res != null)
  60. {
  61. NewRecipeView nrv = new NewRecipeView();
  62. //ActionManage.GetInstance.Send("Details", res);
  63. nrv.ShowDialog();
  64. }
  65. }
  66. });
  67. }
  68. public BPARelayCommand NewMaterital { get; set; }
  69. public BPARelayCommand NewRecipe { get; set; }
  70. public BPARelayCommand SaveRecipe { get; set; }
  71. public BPARelayCommand<object> EditCommand { get; set; }
  72. public BPARelayCommand<object> DetailsCommand { get; set; }
  73. public BPARelayCommand<object> RemoveCommand { get; set; }
  74. public ObservableCollection<RecipeModel> Recipes { get; set; }
  75. }
  76. }