StepGroupEditViewModel.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using MECF.Framework.Common.DataCenter;
  2. using MECF.Framework.UI.Client.CenterViews.Configs.SystemConfig;
  3. using MECF.Framework.UI.Client.ClientBase;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. namespace MECF.Framework.UI.Client.CenterViews.Parameter
  11. {
  12. public class StepGroupEditViewModel : ModuleUiViewModelBase
  13. {
  14. private List<ConfigItem> _stepIdList = new List<ConfigItem>();
  15. public List<ConfigItem> StepIdList
  16. {
  17. get => _stepIdList;
  18. set
  19. {
  20. _stepIdList = value;
  21. NotifyOfPropertyChange(nameof(StepIdList));
  22. }
  23. }
  24. public string StepGroupName = "Group1";
  25. public List<string> HasSelectStepIds = new List<string>();
  26. public string SelectStepIDStr = "";
  27. private ConfigNode _rootNode;
  28. public void Save()
  29. {
  30. ((Window)GetView()).DialogResult = true;
  31. }
  32. public void Cancle()
  33. {
  34. (GetView() as Window).Close();
  35. }
  36. protected override void OnInitialize()
  37. {
  38. base.OnInitialize();
  39. this.SystemName = "System";
  40. _rootNode = SystemConfigProvider.Instance.GetConfig(true);
  41. var stepNameNode = FindNodeByName(_rootNode, $"PM1.RecipeEditParameter.StepName");
  42. if (stepNameNode != null && stepNameNode.Items.Count > 0)
  43. {
  44. var datas = QueryDataClient.Instance.Service.PollConfig(stepNameNode.Items.Select(a => $"{a.Path}.{a.Name}").ToList());
  45. foreach (var item in stepNameNode.Items)
  46. {
  47. if (HasSelectStepIds != null && HasSelectStepIds.Count > 0)
  48. {
  49. if (HasSelectStepIds.Contains(item.Name))
  50. {
  51. continue;
  52. }
  53. }
  54. var key = $"{item.Path}.{item.Name}";
  55. datas.TryGetValue(key, out var value);
  56. item.CurrentValue = (string)value;
  57. item.Display = $"{item.Name}:{item.CurrentValue}";
  58. StepIdList.Add(item);
  59. }
  60. }
  61. }
  62. protected override void OnActivate()
  63. {
  64. base.OnActivate();
  65. var gropuDataStr = (string)QueryDataClient.Instance.Service.GetConfig($"PM1.RecipeEditParameter.StepGroup.{StepGroupName}");
  66. if (!string.IsNullOrEmpty(gropuDataStr))
  67. {
  68. foreach (var item in gropuDataStr.Split(',').ToList())
  69. {
  70. StepIdList.Where(a => a.Name == item).FirstOrDefault().IsExpanded = true;
  71. }
  72. }
  73. }
  74. private ConfigNode FindNodeByName(ConfigNode parentNode, string strName)
  75. {
  76. string strCates = strName.Split('.')[0];
  77. ConfigNode node = parentNode.SubNodes.Find((x) => x.Name == strCates);
  78. if (node == null)
  79. return parentNode;
  80. else
  81. return FindNodeByName(node, strName.Replace(strCates + ".", ""));
  82. }
  83. }
  84. }