RecipeStepNameViewModel.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using Caliburn.Micro.Core;
  2. using DocumentFormat.OpenXml.Office2010.Excel;
  3. using FurnaceUI.Models;
  4. using MECF.Framework.UI.Client.CenterViews.Configs.SystemConfig;
  5. using System;
  6. using System.Collections.ObjectModel;
  7. using System.Linq;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. namespace FurnaceUI.Views.Editors
  11. {
  12. public class RecipeStepNameViewModel : FurnaceUIViewModelBase
  13. {
  14. public class StepInfo : PropertyChangedBase
  15. {
  16. private string _Name;
  17. public string Name
  18. {
  19. get { return _Name; }
  20. set { _Name = value; this.NotifyOfPropertyChange(nameof(Name)); }
  21. }
  22. private bool _IsChecked;
  23. public bool IsChecked
  24. {
  25. get { return _IsChecked; }
  26. set { _IsChecked = value; this.NotifyOfPropertyChange(nameof(IsChecked)); }
  27. }
  28. }
  29. public ObservableCollection<StepInfo> Steps { get; set; }=new ObservableCollection<StepInfo>();
  30. public bool IsEnable => CGlobal.RecipeProcessEditViewEnable;//是否是View模式
  31. public string SelectedStepName { get; set; }
  32. private ConfigNode _configNode;
  33. public ConfigNode ConfigNode
  34. {
  35. get { return _configNode; }
  36. set { _configNode = value; this.NotifyOfPropertyChange(nameof(ConfigNode)); }
  37. }
  38. protected override void OnInitialize()
  39. {
  40. base.OnInitialize();
  41. ConfigNode _rootNode = SystemConfigProvider.Instance.GetConfig(true);
  42. string strHeader = "PM1.RecipeEditParameter.StepName";
  43. ConfigNode = FindNodeByName(_rootNode, strHeader);
  44. for (int i = 0; i < ConfigNode.Items.Count; i++)
  45. {
  46. string key = String.Format("{0}.{1}", strHeader, ConfigNode.Items[i].Name);
  47. ConfigNode.Items[i].CurrentValue = SystemConfigProvider.Instance.GetValueByName(key);
  48. }
  49. for (int i = 0; i < ConfigNode.Items.Count; i++)
  50. {
  51. Steps.Add(new StepInfo() { Name = $"{i + 1}:{ConfigNode.Items[i].CurrentValue}" });
  52. }
  53. var step = Steps.FirstOrDefault(x => x.Name == SelectedStepName);
  54. if (step != null)
  55. {
  56. step.IsChecked = true;
  57. }
  58. }
  59. private ConfigNode FindNodeByName(ConfigNode parentNode, string strName)
  60. {
  61. string strCates = strName.Split('.')[0];
  62. ConfigNode node = parentNode.SubNodes.Find((x) => x.Name == strCates);
  63. if (node == null)
  64. return parentNode;
  65. else
  66. return FindNodeByName(node, strName.Replace(strCates + ".", ""));
  67. }
  68. public void Select(object para)
  69. {
  70. SelectedStepName = (para as RadioButton).Content.ToString();
  71. ((Window)GetView()).DialogResult = true;
  72. }
  73. public void StepNameEdit(string cmdName)
  74. {
  75. switch (cmdName)
  76. {
  77. case "Close":
  78. ((Window)GetView()).DialogResult = false;
  79. break;
  80. case "Save":
  81. ((Window)GetView()).DialogResult = true;
  82. break;
  83. }
  84. }
  85. }
  86. }