AlarmErrorCallRecipeViewModel.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. private RecipeTable _SelectedTable = new RecipeTable();
  50. public RecipeTable SelectedTable
  51. {
  52. get { return _SelectedTable; }
  53. set { _SelectedTable = value; this.NotifyOfPropertyChange(nameof(SelectedTable)); }
  54. }
  55. public string ResultParameterStr { get; set; }
  56. private RecipeDataBase _CurrentRecipe = new RecipeDataBase();
  57. public RecipeDataBase CurrentRecipe
  58. {
  59. get { return _CurrentRecipe; }
  60. set { _CurrentRecipe = value; this.NotifyOfPropertyChange(nameof(CurrentRecipe)); }
  61. }
  62. protected override void OnInitialize()
  63. {
  64. base.OnInitialize();
  65. LoadData();
  66. }
  67. private void LoadData()
  68. {
  69. CurrentRecipe.Clear();
  70. var prefixPath = $"Furnace\\{CallReciepType}";
  71. var recipes = _recipeProvider.GetXmlRecipeList(prefixPath);
  72. var firstFile = RecipeSequenceTreeBuilder.GetFileNodeParameterList(prefixPath)[0].Files.FirstOrDefault(); ;
  73. if (firstFile != null)
  74. {
  75. var recipeContent = _recipeProvider.LoadRecipe(prefixPath, firstFile.FullPath);
  76. CurrentRecipe.InitData(prefixPath, firstFile.Name, recipeContent, "PM1");
  77. foreach (var item in CurrentRecipe.Tables)
  78. {
  79. var stepItem = new ParameterTable()
  80. {
  81. StepNo = item.Index,
  82. Name = item.Name,
  83. IsChecked = false,
  84. };
  85. Steps.Add(stepItem);
  86. }
  87. if (ResultParameterStr != null)
  88. {
  89. var stepNo = ResultParameterStr.Split(':')[0];
  90. var one = Steps.Where(a => a.StepNo.Equals(int.Parse(stepNo))).FirstOrDefault();
  91. one.IsChecked = true;
  92. SelectItemName = one.Name;
  93. SelectedTable = CurrentRecipe.Tables[one.StepNo - 1];
  94. }
  95. else
  96. {
  97. var first = Steps.FirstOrDefault();
  98. if (first != null)
  99. {
  100. first.IsChecked = true;
  101. SelectItemName = first.Name;
  102. ResultParameterStr = $"{first.StepNo}:{first.Name}";
  103. SelectedTable = CurrentRecipe.Tables[first.StepNo-1];
  104. }
  105. }
  106. }
  107. }
  108. public void SelectTable(object step)
  109. {
  110. if (step != null)
  111. {
  112. var step1 = step as ParameterTable;
  113. var SelectedStep = this.Steps.Where(x => x.StepNo == step1.StepNo).FirstOrDefault();
  114. SelectedStep.IsChecked = true;
  115. SelectItemName = step1.Name;
  116. SelectItemTable = new ObservableCollection<ParameterTable>();
  117. ResultParameterStr = $"{step1.StepNo}:{step1.Name}";
  118. SelectedTable = CurrentRecipe.Tables[SelectedStep.StepNo-1];
  119. }
  120. }
  121. public void AlarmTableSelected(object step)
  122. {
  123. if (step != null)
  124. {
  125. var step1 = step as ParameterTable;
  126. var SelectedStep = this.Steps.Where(x => x.StepNo == step1.StepNo).FirstOrDefault();
  127. SelectedStep.IsChecked = true;
  128. SelectItemName = step1.Name;
  129. SelectItemTable = new ObservableCollection<ParameterTable>();
  130. ResultParameterStr = $"{step1.StepNo}:{step1.Name}";
  131. SelectedTable = CurrentRecipe.Tables[SelectedStep.StepNo-1];
  132. }
  133. }
  134. public void CloseCommand()
  135. {
  136. ((Window)GetView()).DialogResult = false;
  137. }
  138. public void OKCommand()
  139. {
  140. ((Window)GetView()).DialogResult = true;
  141. }
  142. }
  143. }