终端一体化运控平台
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

110 wiersze
3.1 KiB

  1. using BPASmartClient.FoodStationTest.Model;
  2. using BPASmartClient.Helper;
  3. using Microsoft.Toolkit.Mvvm.ComponentModel;
  4. using Microsoft.Toolkit.Mvvm.Input;
  5. using System.Collections.ObjectModel;
  6. using System.Linq;
  7. namespace BPASmartClient.FoodStationTest.ViewModel
  8. {
  9. internal class SelectRecipesViewModel : ObservableObject
  10. {
  11. public SelectRecipesViewModel()
  12. {
  13. AllRecipes = new();
  14. foreach (var item in Json<LocalRecipeDataColl>.Data.SelectedRecipes)
  15. {
  16. SelectRecipes.Add(item);
  17. }
  18. if (Json<LocalRecipeDataColl>.Data.Recipes != null)
  19. {
  20. foreach (var item in Json<LocalRecipeDataColl>.Data.Recipes)
  21. {
  22. AllRecipes.Add(new RecipeDataWithCheck()
  23. {
  24. Recipe = item,
  25. IsSelected = SelectRecipes.Any(p => p.RecipeCode == item.RecipeCode)
  26. });
  27. }
  28. }
  29. ConfirmCommand = new(() =>
  30. {
  31. RefreshSelected();
  32. ActionManage.GetInstance.Send("CloseSelectRecipesView");
  33. });
  34. CancelCommand = new(() =>
  35. {
  36. ActionManage.GetInstance.Send("CloseSelectRecipesView");
  37. });
  38. AllSelectCommand = new(() =>
  39. {
  40. foreach (var item in AllRecipes)
  41. {
  42. item.IsSelected = true;
  43. }
  44. });
  45. AllCancelCommand = new(() =>
  46. {
  47. foreach (var item in AllRecipes)
  48. {
  49. item.IsSelected = false;
  50. }
  51. });
  52. }
  53. private void RefreshSelected()
  54. {
  55. SelectRecipes.Clear();
  56. foreach (var item in AllRecipes)
  57. {
  58. if (item.IsSelected == true)
  59. {
  60. SelectRecipes.Add(item.Recipe);
  61. }
  62. }
  63. }
  64. public ObservableCollection<RecipeDataWithCheck> AllRecipes { get; set; }
  65. public static ObservableCollection<RemoteRecipeData> SelectRecipes { get; set; } = new ObservableCollection<RemoteRecipeData>();
  66. /// <summary>
  67. /// 取消筛选,即关闭本窗口。
  68. /// </summary>
  69. public RelayCommand CancelCommand { get; set; }
  70. /// <summary>
  71. /// 全选。
  72. /// </summary>
  73. public RelayCommand AllSelectCommand { get; set; }
  74. /// <summary>
  75. /// 全部取消选择。
  76. /// </summary>
  77. public RelayCommand AllCancelCommand { get; set; }
  78. /// <summary>
  79. /// 确认选择。
  80. /// </summary>
  81. public RelayCommand ConfirmCommand { get; set; }
  82. internal class RecipeDataWithCheck : ObservableObject
  83. {
  84. public RemoteRecipeData Recipe { get; set; }
  85. private bool _IsSelected;
  86. public bool IsSelected
  87. {
  88. get { return _IsSelected; }
  89. set { _IsSelected = value; OnPropertyChanged(); }
  90. }
  91. }
  92. }
  93. }