终端一体化运控平台
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

110 строки
3.0 KiB

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