MainFormBottomViewModel.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. using System;
  2. using Prism.Events;
  3. using Prism.Mvvm;
  4. using System.Windows.Media;
  5. using SHJX.Service.Common.Event;
  6. namespace SHJX.Service.Main.ViewModels
  7. {
  8. public class MainFormBottomViewModel : BindableBase
  9. {
  10. #region Peoperties
  11. private SolidColorBrush _lockDesktopDisplay;
  12. public SolidColorBrush LockDesktopDisplay
  13. {
  14. get => _lockDesktopDisplay;
  15. set => SetProperty(ref _lockDesktopDisplay, value);
  16. }
  17. private bool _lockDesktopState;
  18. public bool LockDesktopState
  19. {
  20. get => _lockDesktopState;
  21. set => SetProperty(ref _lockDesktopState, value);
  22. }
  23. private SolidColorBrush _heatingDisplay;
  24. public SolidColorBrush HeatingDisplay
  25. {
  26. get => _heatingDisplay;
  27. set => SetProperty(ref _heatingDisplay, value);
  28. }
  29. private bool _heatingState;
  30. public bool HeatingState
  31. {
  32. get => _heatingState;
  33. set => SetProperty(ref _heatingState, value);
  34. }
  35. private SolidColorBrush _portClientDisplay;
  36. public SolidColorBrush PortClientDisplay
  37. {
  38. get => _portClientDisplay;
  39. set => SetProperty(ref _portClientDisplay, value);
  40. }
  41. private bool _portClientState;
  42. public bool PortClientState
  43. {
  44. get => _portClientState;
  45. set => SetProperty(ref _portClientState, value);
  46. }
  47. private SolidColorBrush _cameraClientDisplay;
  48. public SolidColorBrush CameraClientDisplay
  49. {
  50. get => _cameraClientDisplay;
  51. set => SetProperty(ref _cameraClientDisplay, value);
  52. }
  53. private bool _cameraClientState;
  54. public bool CameraClientState
  55. {
  56. get => _cameraClientState;
  57. set => SetProperty(ref _cameraClientState, value);
  58. }
  59. private SolidColorBrush _cameraClientDisplay2;
  60. public SolidColorBrush CameraClientDisplay2
  61. {
  62. get => _cameraClientDisplay2;
  63. set => SetProperty(ref _cameraClientDisplay2, value);
  64. }
  65. private bool _cameraClientState2;
  66. public bool CameraClientState2
  67. {
  68. get => _cameraClientState2;
  69. set => SetProperty(ref _cameraClientState2, value);
  70. }
  71. private double _temperatureValue;
  72. public double TemperatureValue
  73. {
  74. get => _temperatureValue;
  75. set => SetProperty(ref _temperatureValue, value);
  76. }
  77. private double _kValue;
  78. public double KValue
  79. {
  80. get => _kValue;
  81. set => SetProperty(ref _kValue, value);
  82. }
  83. private double _tempeValue;
  84. public double TempValue
  85. {
  86. get => _tempeValue;
  87. set => SetProperty(ref _tempeValue, value);
  88. }
  89. private double _humidValue;
  90. public double HumidValue
  91. {
  92. get => _humidValue;
  93. set => SetProperty(ref _humidValue, value);
  94. }
  95. private double _taskNeedTime;
  96. public double TaskNeedTime
  97. {
  98. get => _taskNeedTime;
  99. set => SetProperty(ref _taskNeedTime, value);
  100. }
  101. #endregion
  102. public MainFormBottomViewModel(IEventAggregator ea)
  103. {
  104. TempValue = 18.3;
  105. HumidValue = 22.6;
  106. LockDesktopDisplay = Brushes.LightGreen;
  107. LockDesktopState = false;
  108. HeatingDisplay = Brushes.Red;
  109. HeatingState = true;
  110. PortClientDisplay = Brushes.Red;
  111. PortClientState = true;
  112. CameraClientDisplay = Brushes.Red;
  113. CameraClientState = true;
  114. CameraClientDisplay2 = Brushes.Red;
  115. CameraClientState2 = true;
  116. TaskNeedTime = 0;
  117. ea.GetEvent<LockDesktopEvent>().Subscribe((bl) =>
  118. {
  119. LockDesktopDisplay = bl ? Brushes.Red : Brushes.LightGreen;
  120. LockDesktopState = bl;
  121. });
  122. ea.GetEvent<HeatingStateEvent>().Subscribe((bl) =>
  123. {
  124. HeatingDisplay = bl ? Brushes.LightGreen : Brushes.Red;
  125. HeatingState = !bl;
  126. });
  127. ea.GetEvent<ClientCameraEvent>().Subscribe(SettingCameraState);
  128. ea.GetEvent<ClientCameraEvent2>().Subscribe(SettingCameraState2);
  129. ea.GetEvent<ClientResponseEvent>().Subscribe(SettingPortState);
  130. ea.GetEvent<DissolveCurrentHeatingValueEvent>().Subscribe(args =>
  131. {
  132. TemperatureValue = args.CurrentTemperature;
  133. });
  134. ea.GetEvent<NoticeKValueEvent>().Subscribe(value =>
  135. {
  136. KValue = Math.Round(value, 4);
  137. });
  138. ea.GetEvent<NoticeHumitureEvent>().Subscribe(args =>
  139. {
  140. TempValue = args.Temperature;
  141. HumidValue = args.Humidity;
  142. });
  143. ea.GetEvent<CalExecuteTaskNeedTimeEvent>().Subscribe(canExecuteTaskCount =>
  144. {
  145. if (canExecuteTaskCount == 0)
  146. {
  147. TaskNeedTime = 0;
  148. }
  149. if (canExecuteTaskCount > 0)
  150. {
  151. TaskNeedTime = (30 + 6 * canExecuteTaskCount) / 60.0;
  152. }
  153. });
  154. }
  155. private void SettingCameraState(bool state)
  156. {
  157. CameraClientDisplay = state ? Brushes.LightGreen : Brushes.Red;
  158. CameraClientState = !state;
  159. }
  160. private void SettingCameraState2(bool state)
  161. {
  162. CameraClientDisplay2 = state ? Brushes.LightGreen : Brushes.Red;
  163. CameraClientState2 = !state;
  164. }
  165. private void SettingPortState((string portName, bool clientState) obj)
  166. {
  167. PortClientState = !obj.clientState;
  168. PortClientDisplay = obj.clientState ? Brushes.LightGreen : Brushes.Red;
  169. }
  170. }
  171. }