AlarmErrorCallRecipeViewModel.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. public string CallReciepType { get; set; }
  24. private ObservableCollection<ParameterTable> _selectItemTable = new ObservableCollection<ParameterTable>();
  25. public ObservableCollection<ParameterTable> SelectItemTable
  26. {
  27. get { return _selectItemTable; }
  28. set { _selectItemTable = value; this.NotifyOfPropertyChange(nameof(SelectItemTable)); }
  29. }
  30. private string _selectItemName;
  31. public string SelectItemName
  32. {
  33. get { return _selectItemName; }
  34. set { _selectItemName = value; this.NotifyOfPropertyChange(nameof(SelectItemName)); }
  35. }
  36. private string _selectItemEndStatus;
  37. public string SelectItemEndStatus
  38. {
  39. get { return _selectItemEndStatus; }
  40. set { _selectItemEndStatus = value; this.NotifyOfPropertyChange(nameof(SelectItemEndStatus)); }
  41. }
  42. private Visibility _isAlarmVisibility;
  43. public Visibility IsAlarmVisibility
  44. {
  45. get { return _isAlarmVisibility; }
  46. set { _isAlarmVisibility = value; this.NotifyOfPropertyChange(nameof(IsAlarmVisibility)); }
  47. }
  48. private RecipeProvider _recipeProvider = new RecipeProvider();
  49. public string ResultParameterStr { get; set; }
  50. private RecipeDataBase _CurrentRecipe = new RecipeDataBase();
  51. public RecipeDataBase CurrentRecipe
  52. {
  53. get { return _CurrentRecipe; }
  54. set { _CurrentRecipe = value; this.NotifyOfPropertyChange(nameof(CurrentRecipe)); }
  55. }
  56. protected override void OnInitialize()
  57. {
  58. base.OnInitialize();
  59. LoadData();
  60. }
  61. private void LoadData()
  62. {
  63. CurrentRecipe.Clear();
  64. var prefixPath = $"Furnace\\{CallReciepType}";
  65. var recipes = _recipeProvider.GetXmlRecipeList(prefixPath);
  66. var firstFile = RecipeSequenceTreeBuilder.GetFileNodeParameterList(prefixPath)[0].Files.FirstOrDefault(); ;
  67. if (firstFile != null)
  68. {
  69. var recipeContent = _recipeProvider.LoadRecipe(prefixPath, firstFile.FullPath);
  70. CurrentRecipe.InitData(prefixPath, firstFile.Name, recipeContent, "PM1");
  71. foreach (var item in CurrentRecipe.Tables)
  72. {
  73. var stepItem = new ParameterTable()
  74. {
  75. StepNo = item.Index,
  76. Name = item.Name,
  77. IsChecked = false,
  78. };
  79. Steps.Add(stepItem);
  80. }
  81. if (ResultParameterStr != null)
  82. {
  83. var stepNo = ResultParameterStr.Split(':')[0];
  84. var one = Steps.Where(a => a.StepNo.Equals(int.Parse(stepNo))).FirstOrDefault();
  85. one.IsChecked = true;
  86. SelectItemName = one.Name;
  87. }
  88. else
  89. {
  90. var first = Steps.FirstOrDefault();
  91. if (first != null)
  92. {
  93. first.IsChecked = true;
  94. SelectItemName = first.Name;
  95. ResultParameterStr = $"{first.StepNo}:{first.Name}";
  96. }
  97. }
  98. }
  99. }
  100. public void SelectTable(object step)
  101. {
  102. if (step != null)
  103. {
  104. var step1 = step as ParameterTable;
  105. var SelectedStep = this.Steps.Where(x => x.StepNo == step1.StepNo).FirstOrDefault();
  106. SelectedStep.IsChecked = true;
  107. SelectItemName = step1.Name;
  108. SelectItemTable = new ObservableCollection<ParameterTable>();
  109. ResultParameterStr = $"{step1.StepNo}:{step1.Name}";
  110. }
  111. }
  112. public void AlarmTableSelected(object step)
  113. {
  114. if (step != null)
  115. {
  116. var step1 = step as ParameterTable;
  117. var SelectedStep = this.Steps.Where(x => x.StepNo == step1.StepNo).FirstOrDefault();
  118. SelectedStep.IsChecked = true;
  119. SelectItemName = step1.Name;
  120. SelectItemTable = new ObservableCollection<ParameterTable>();
  121. ResultParameterStr = $"{step1.StepNo}:{step1.Name}";
  122. }
  123. }
  124. public void CloseCommand()
  125. {
  126. ((Window)GetView()).DialogResult = false;
  127. }
  128. public void OKCommand()
  129. {
  130. ((Window)GetView()).DialogResult = true;
  131. }
  132. }
  133. }