终端一体化运控平台
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

100 lines
3.9 KiB

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