AlarmErrorCallRecipeViewModel.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. using DocumentFormat.OpenXml.Bibliography;
  2. using FurnaceUI.Models;
  3. using MECF.Framework.UI.Client.CenterViews.Editors.Recipe;
  4. using MECF.Framework.UI.Client.CenterViews.Editors.Sequence;
  5. using MECF.Framework.UI.Client.CenterViews.Parameter;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Collections.ObjectModel;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. namespace FurnaceUI.Views.Editors
  14. {
  15. public class AlarmErrorCallRecipeViewModel : FurnaceUIViewModelBase
  16. {
  17. private ObservableCollection<ParameterTable> _steps = new ObservableCollection<ParameterTable>();
  18. public ObservableCollection<ParameterTable> Steps
  19. {
  20. get { return _steps; }
  21. set { _steps = value; this.NotifyOfPropertyChange(nameof(Steps)); }
  22. }
  23. private ObservableCollection<ParameterTable> _selectItemTable = new ObservableCollection<ParameterTable>();
  24. public ObservableCollection<ParameterTable> SelectItemTable
  25. {
  26. get { return _selectItemTable; }
  27. set { _selectItemTable = value; this.NotifyOfPropertyChange(nameof(SelectItemTable)); }
  28. }
  29. private string _selectItemName;
  30. public string SelectItemName
  31. {
  32. get { return _selectItemName; }
  33. set { _selectItemName = value; this.NotifyOfPropertyChange(nameof(SelectItemName)); }
  34. }
  35. private string _selectItemEndStatus;
  36. public string SelectItemEndStatus
  37. {
  38. get { return _selectItemEndStatus; }
  39. set { _selectItemEndStatus = value; this.NotifyOfPropertyChange(nameof(SelectItemEndStatus)); }
  40. }
  41. private Visibility _isAlarmVisibility;
  42. public Visibility IsAlarmVisibility
  43. {
  44. get { return _isAlarmVisibility; }
  45. set { _isAlarmVisibility = value; this.NotifyOfPropertyChange(nameof(IsAlarmVisibility)); }
  46. }
  47. private RecipeProvider _recipeProvider = new RecipeProvider();
  48. public string ResultParameterStr { get; set; }
  49. private RecipeDataBase _CurrentRecipe = new RecipeDataBase();
  50. public RecipeDataBase CurrentRecipe
  51. {
  52. get { return _CurrentRecipe; }
  53. set { _CurrentRecipe = value; this.NotifyOfPropertyChange(nameof(CurrentRecipe)); }
  54. }
  55. protected override void OnInitialize()
  56. {
  57. base.OnInitialize();
  58. LoadData();
  59. }
  60. private void LoadData()
  61. {
  62. CurrentRecipe.Clear();
  63. var prefixPath = "Furnace\\alarm";
  64. var recipes = _recipeProvider.GetXmlRecipeList(prefixPath);
  65. var firstFile = RecipeSequenceTreeBuilder.BuildFileNode(prefixPath, "", false, recipes)[0].Files.FirstOrDefault();
  66. if (firstFile != null)
  67. {
  68. var recipeContent = _recipeProvider.LoadRecipe(prefixPath, firstFile.Name);
  69. CurrentRecipe.InitData(prefixPath, firstFile.Name, recipeContent, "PM1");
  70. foreach (var item in CurrentRecipe.Tables)
  71. {
  72. var stepItem = new ParameterTable()
  73. {
  74. StepNo = item.Index,
  75. Name = item.Name,
  76. IsChecked = false,
  77. };
  78. Steps.Add(stepItem);
  79. }
  80. if (ResultParameterStr != null)
  81. {
  82. var stepNo = ResultParameterStr.Split(':')[0];
  83. var one = Steps.Where(a => a.StepNo.Equals(int.Parse(stepNo))).FirstOrDefault();
  84. one.IsChecked = true;
  85. SelectItemName = one.Name;
  86. }
  87. else
  88. {
  89. var first = Steps.FirstOrDefault();
  90. if (first != null)
  91. {
  92. first.IsChecked = true;
  93. SelectItemName = first.Name;
  94. ResultParameterStr = $"{first.StepNo}:{first.Name}";
  95. }
  96. }
  97. }
  98. }
  99. public void SelectTable(object step)
  100. {
  101. if (step != null)
  102. {
  103. var step1 = step as ParameterTable;
  104. var SelectedStep = this.Steps.Where(x => x.StepNo == step1.StepNo).FirstOrDefault();
  105. SelectedStep.IsChecked = true;
  106. SelectItemName = step1.Name;
  107. SelectItemTable = new ObservableCollection<ParameterTable>();
  108. ResultParameterStr = $"{step1.StepNo}:{step1.Name}";
  109. }
  110. }
  111. public void AlarmTableSelected(object step)
  112. {
  113. if (step != null)
  114. {
  115. var step1 = step as ParameterTable;
  116. var SelectedStep = this.Steps.Where(x => x.StepNo == step1.StepNo).FirstOrDefault();
  117. SelectedStep.IsChecked = true;
  118. SelectItemName = step1.Name;
  119. SelectItemTable = new ObservableCollection<ParameterTable>();
  120. ResultParameterStr = $"{step1.StepNo}:{step1.Name}";
  121. }
  122. }
  123. public void CloseCommand()
  124. {
  125. ((Window)GetView()).DialogResult = false;
  126. }
  127. public void OKCommand()
  128. {
  129. ((Window)GetView()).DialogResult = true;
  130. }
  131. }
  132. }