终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

117 regels
3.3 KiB

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