StepGroupEditViewModel.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 string SelectStepIDStr = "";
  26. private ConfigNode _rootNode;
  27. public void Save()
  28. {
  29. ((Window)GetView()).DialogResult = true;
  30. }
  31. public void Cancle()
  32. {
  33. (GetView() as Window).Close();
  34. }
  35. protected override void OnInitialize()
  36. {
  37. base.OnInitialize();
  38. this.SystemName = "System";
  39. _rootNode = SystemConfigProvider.Instance.GetConfig(true);
  40. var stepNameNode = FindNodeByName(_rootNode, $"PM1.RecipeEditParameter.StepName");
  41. if (stepNameNode != null && stepNameNode.Items.Count > 0)
  42. {
  43. var datas = QueryDataClient.Instance.Service.PollConfig(stepNameNode.Items.Select(a => $"{a.Path}.{a.Name}").ToList());
  44. foreach (var item in stepNameNode.Items)
  45. {
  46. var key = $"{item.Path}.{item.Name}";
  47. datas.TryGetValue(key,out var value);
  48. item.CurrentValue = (string)value;
  49. item.Display = $"{item.Name}:{item.CurrentValue}";
  50. StepIdList.Add(item);
  51. }
  52. }
  53. }
  54. protected override void OnActivate()
  55. {
  56. base.OnActivate();
  57. var gropuDataStr = (string)QueryDataClient.Instance.Service.GetConfig($"PM1.RecipeEditParameter.StepGroup.{StepGroupName}");
  58. if (!string.IsNullOrEmpty(gropuDataStr))
  59. {
  60. foreach (var item in gropuDataStr.Split(',').ToList())
  61. {
  62. StepIdList.Where(a => a.Name == item).FirstOrDefault().IsExpanded = true;
  63. }
  64. }
  65. }
  66. private ConfigNode FindNodeByName(ConfigNode parentNode, string strName)
  67. {
  68. string strCates = strName.Split('.')[0];
  69. ConfigNode node = parentNode.SubNodes.Find((x) => x.Name == strCates);
  70. if (node == null)
  71. return parentNode;
  72. else
  73. return FindNodeByName(node, strName.Replace(strCates + ".", ""));
  74. }
  75. }
  76. }