StandbyFactorViewModel.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using Caliburn.Micro;
  2. using Caliburn.Micro.Core;
  3. using Aitex.Core.Common.DeviceData;
  4. using Aitex.Core.UI.ControlDataContext;
  5. using Aitex.Core.Util;
  6. using MECF.Framework.Common.DataCenter;
  7. using MECF.Framework.Common.OperationCenter;
  8. using MECF.Framework.Common.CommonData;
  9. using FurnaceUI.Models;
  10. using FurnaceUI.Views.Editors;
  11. using System.Collections.ObjectModel;
  12. using System.Collections.Generic;
  13. using System.Threading.Tasks;
  14. using System.Reflection;
  15. using System;
  16. using Aitex.Core.RT.Log;
  17. using System.Linq;
  18. using System.Windows;
  19. namespace FurnaceUI.Views.Operations
  20. {
  21. public class StandbyFactorViewModel : FurnaceUIViewModelBase
  22. {
  23. public string MainRecipeName { get; set; }
  24. public ObservableCollection<StandbyFactorViewItem> StandbyFactorViewItems { get; set; } = new ObservableCollection<StandbyFactorViewItem>();
  25. private SerializableDictionary<string, bool> _conditionCheck;
  26. [Subscription("PM1.ConditionCheck")]
  27. public SerializableDictionary<string, bool> ConditionCheck
  28. {
  29. get
  30. {
  31. return _conditionCheck;
  32. }
  33. set
  34. {
  35. _conditionCheck = value;
  36. if (_conditionCheck != null && _conditionCheck.Count > 0)
  37. {
  38. bool needClear = false;
  39. foreach(var item in StandbyFactorViewItems)
  40. {
  41. if(!_conditionCheck.ContainsKey(item.Factor))
  42. {
  43. needClear = true;
  44. break;
  45. }
  46. }
  47. if(needClear)
  48. StandbyFactorViewItems.Clear();
  49. foreach (var key in _conditionCheck.Keys)
  50. {
  51. if(StandbyFactorViewItems.Any(x => x.Factor == key))
  52. {
  53. var item = StandbyFactorViewItems.SingleOrDefault(x => x.Factor == key);
  54. item.Result = _conditionCheck[key] ? "Success" : "Wait";
  55. item.IsBypassEnabled = !_conditionCheck[key];
  56. }
  57. else
  58. {
  59. StandbyFactorViewItems.Add(new StandbyFactorViewItem
  60. {
  61. Factor = key,
  62. Result = _conditionCheck[key] ? "Success" : "Wait",
  63. IsBypassEnabled = !_conditionCheck[key]
  64. });
  65. }
  66. }
  67. }
  68. }
  69. }
  70. public StandbyFactorViewModel()
  71. {
  72. }
  73. protected override void OnInitialize()
  74. {
  75. base.OnInitialize();
  76. }
  77. public void FactorAction(object target)
  78. {
  79. InvokeClient.Instance.Service.DoOperation($"PM1.BypassStandbyFactor", target.ToString());
  80. }
  81. public void ClosedCmd()
  82. {
  83. (GetView() as Window).Close();
  84. }
  85. }
  86. public class StandbyFactorViewItem : NotifiableItem
  87. {
  88. private string _factor;
  89. public string Factor
  90. {
  91. get => _factor;
  92. set
  93. {
  94. _factor = value;
  95. InvokePropertyChanged(nameof(Factor));
  96. }
  97. }
  98. private string _result;
  99. public string Result
  100. {
  101. get => _result;
  102. set
  103. {
  104. _result = value;
  105. InvokePropertyChanged(nameof(Result));
  106. }
  107. }
  108. private bool _isBypassEnabled;
  109. public bool IsBypassEnabled
  110. {
  111. get => _isBypassEnabled;
  112. set
  113. {
  114. _isBypassEnabled = value;
  115. InvokePropertyChanged(nameof(IsBypassEnabled));
  116. }
  117. }
  118. }
  119. }