终端一体化运控平台
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

154 satır
4.7 KiB

  1. using BPASmart.Model;
  2. using BPASmartClient.Helper;
  3. using Microsoft.Toolkit.Mvvm.ComponentModel;
  4. using Microsoft.Toolkit.Mvvm.Input;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Collections.ObjectModel;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace BPASmart.RecipeManagement.ViewModel
  12. {
  13. public class PowerManagerViewModel : ObservableObject
  14. {
  15. public ObservableCollection<string> UserName { get; set; } = new ObservableCollection<string>();
  16. /// <summary>
  17. /// 全部物料
  18. /// </summary>
  19. public ObservableCollection<RecipeMaterials> AllMaterials { get; set; } = Json<LocalMaterails>.Data.locaMaterails;
  20. /// <summary>
  21. /// 用户权限物料
  22. /// </summary>
  23. public ObservableCollection<RecipeMaterials> UserMaterials { get; set; } = new ObservableCollection<RecipeMaterials>();
  24. /// <summary>
  25. /// 全部配方
  26. /// </summary>
  27. public ObservableCollection<Recipes> AllRecipes { get; set; } = Json<LocalRecipes>.Data.locaRecipes;
  28. /// <summary>
  29. /// 用户权限配方
  30. /// </summary>
  31. public ObservableCollection<Recipes> UserRecipes { get; set; } = new ObservableCollection<Recipes>();
  32. public RelayCommand<object> DeleteAllCommand { get; set; }
  33. public RelayCommand<object> AddAllCommand { get; set; }
  34. public RelayCommand<object> AddMaterialCommand { get; set; }
  35. public RelayCommand<object> DeleteMaterialCommand { get; set; }
  36. public RelayCommand<object> AddRecipeCommand { get; set; }
  37. public RelayCommand<object> DeleteRecipeCommand { get; set; }
  38. private void DeleteAll(object o)
  39. {
  40. if (o == null) return;
  41. if (o.ToString() == "Materials")
  42. {
  43. UserMaterials.Clear();
  44. }
  45. else if (o.ToString() == "Recipes")
  46. {
  47. UserRecipes.Clear();
  48. }
  49. }
  50. private void AddAll(object o)
  51. {
  52. if (o == null) return;
  53. if (o.ToString() == "Materials")
  54. {
  55. UserMaterials.Clear();
  56. foreach (RecipeMaterials item in AllMaterials)
  57. {
  58. UserMaterials.Add(item);
  59. }
  60. }
  61. else if (o.ToString() == "Recipes")
  62. {
  63. UserRecipes.Clear();
  64. foreach (Recipes item in AllRecipes)
  65. {
  66. UserRecipes.Add(item);
  67. }
  68. }
  69. }
  70. private void AddMaterial(object o)
  71. {
  72. if (o == null) return;
  73. if (o is string materail)
  74. {
  75. var res = AllMaterials.FirstOrDefault(p => p.Name == materail);
  76. if (UserMaterials.FirstOrDefault(p => p.Name == res.Name) == null)
  77. {
  78. UserMaterials.Add(res);
  79. }
  80. }
  81. }
  82. private void DeleteMaterial(object o)
  83. {
  84. if (o == null) return;
  85. if (o is string materail)
  86. {
  87. var res = UserMaterials.FirstOrDefault(p => p.Name == materail);
  88. UserMaterials.Remove(res);
  89. }
  90. }
  91. private void AddRecipe(object o)
  92. {
  93. if (o == null) return;
  94. if (o is string materail)
  95. {
  96. var res = AllRecipes.FirstOrDefault(p => p.Name == materail);
  97. if (UserRecipes.FirstOrDefault(p => p.Name == res.Name) == null)
  98. {
  99. UserRecipes.Add(res);
  100. }
  101. }
  102. }
  103. private void DeleteRecipe(object o)
  104. {
  105. if (o == null) return;
  106. if (o is string materail)
  107. {
  108. var res = UserRecipes.FirstOrDefault(p => p.Name == materail);
  109. UserRecipes.Remove(res);
  110. }
  111. }
  112. public PowerManagerViewModel()
  113. {
  114. DeleteAllCommand = new RelayCommand<object>(DeleteAll);
  115. AddAllCommand = new RelayCommand<object>(AddAll);
  116. AddMaterialCommand = new RelayCommand<object>(AddMaterial);
  117. DeleteMaterialCommand = new RelayCommand<object>(DeleteMaterial);
  118. AddRecipeCommand = new RelayCommand<object>(AddRecipe);
  119. DeleteRecipeCommand = new RelayCommand<object>(DeleteRecipe);
  120. UserName.Add("admin");
  121. UserName.Add("员工1号");
  122. UserName.Add("员工2号");
  123. UserName.Add("员工3号");
  124. UserName.Add("员工4号");
  125. UserName.Add("员工5号");
  126. UserName.Add("员工6号");
  127. }
  128. }
  129. }