OperateMedicineViewModel.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. using Prism.Mvvm;
  2. using Prism.Events;
  3. using Prism.Commands;
  4. using System.Windows.Media;
  5. using SHJX.Service.Common.Event;
  6. using SHJX.Service.Control.Interface;
  7. namespace SHJX.Service.Main.ViewModels.Sidebar
  8. {
  9. public class OperateMedicineViewModel : BindableBase
  10. {
  11. #region Fields
  12. private readonly IEventAggregator _ea;
  13. private readonly IMainService _service;
  14. #endregion
  15. #region Properties
  16. public string _copyrightInformation;
  17. public string CopyrightInformation
  18. {
  19. get => _copyrightInformation;
  20. set => SetProperty(ref _copyrightInformation, value);
  21. }
  22. /// <summary>
  23. /// 连接名
  24. /// </summary>
  25. private string _clientName;
  26. public string ClientName
  27. {
  28. get => _clientName;
  29. set => SetProperty(ref _clientName, value);
  30. }
  31. /// <summary>
  32. /// 端口连接状态
  33. /// </summary>
  34. private SolidColorBrush _portClientFill;
  35. public SolidColorBrush PortClientFill
  36. {
  37. get => _portClientFill;
  38. set
  39. {
  40. SetProperty(ref _portClientFill, value);
  41. _portClientFill.Freeze();
  42. }
  43. }
  44. private bool _portClientState;
  45. public bool PortClientState
  46. {
  47. get => _portClientState;
  48. set => SetProperty(ref _portClientState, value);
  49. }
  50. /// <summary>
  51. /// 摄像头连接状态
  52. /// </summary>
  53. private SolidColorBrush _cameraClientFill;
  54. public SolidColorBrush CameraClientFill
  55. {
  56. get => _cameraClientFill;
  57. set
  58. {
  59. SetProperty(ref _cameraClientFill, value);
  60. _cameraClientFill.Freeze();
  61. }
  62. }
  63. private bool _cameraClientState;
  64. public bool CameraClientState
  65. {
  66. get => _cameraClientState;
  67. set => SetProperty(ref _cameraClientState, value);
  68. }
  69. /// <summary>
  70. /// 摄像头2连接状态
  71. /// </summary>
  72. private SolidColorBrush _cameraClientFill2;
  73. public SolidColorBrush CameraClientFill2
  74. {
  75. get => _cameraClientFill2;
  76. set
  77. {
  78. SetProperty(ref _cameraClientFill2, value);
  79. _cameraClientFill2.Freeze();
  80. }
  81. }
  82. private bool _cameraClientState2;
  83. public bool CameraClientState2
  84. {
  85. get => _cameraClientState2;
  86. set => SetProperty(ref _cameraClientState2, value);
  87. }
  88. private SolidColorBrush _temperatureSettingFill;
  89. public SolidColorBrush TemperatureSettingFill
  90. {
  91. get => _temperatureSettingFill;
  92. set
  93. {
  94. SetProperty(ref _temperatureSettingFill, value);
  95. _temperatureSettingFill.Freeze();
  96. }
  97. }
  98. private bool _temperatureSettingState;
  99. public bool TemperatureSettingState
  100. {
  101. get => _temperatureSettingState;
  102. set => SetProperty(ref _temperatureSettingState, value);
  103. }
  104. /// <summary>
  105. /// 是否锁定
  106. /// </summary>
  107. private bool? _mainLock;
  108. public bool? WhetherLockMain
  109. {
  110. get => _mainLock;
  111. set => SetProperty(ref _mainLock, value);
  112. }
  113. #endregion
  114. #region Commands
  115. private DelegateCommand _lockDestCommand;
  116. public DelegateCommand LockDestCommand => _lockDestCommand ??= new DelegateCommand(() =>
  117. {
  118. _ea.GetEvent<LockDesktopEvent>().Publish((bool)WhetherLockMain);
  119. });
  120. private DelegateCommand _freshClientCommand;
  121. public DelegateCommand FreshClientCommand => _freshClientCommand ?? new DelegateCommand(() =>
  122. {
  123. _service.FreshClient();
  124. });
  125. private DelegateCommand _freshCameraCommand;
  126. public DelegateCommand FreshCameraCommand => _freshCameraCommand ?? new DelegateCommand(() =>
  127. {
  128. _service.FreshCamera();
  129. });
  130. private DelegateCommand _resettingTemperatureCommand;
  131. public DelegateCommand ReSettingTemperatureCommand => _resettingTemperatureCommand ?? new DelegateCommand(() =>
  132. {
  133. _service.ResettingTemperature();
  134. });
  135. #endregion
  136. public OperateMedicineViewModel(IEventAggregator ea, IMainService service)
  137. {
  138. _ea = ea;
  139. _service = service;
  140. _ea.GetEvent<ClientCameraEvent>().Subscribe(ListenCameraState);
  141. _ea.GetEvent<ClientCameraEvent2>().Subscribe(ListenCameraState2);
  142. _ea.GetEvent<ClientResponseEvent>().Subscribe(ListenClientInfo);
  143. _ea.GetEvent<HeatingStateEvent>().Subscribe(ListenTemperatureSettingState);
  144. }
  145. #region Event Methods
  146. private void ListenTemperatureSettingState(bool state)
  147. {
  148. TemperatureSettingFill = state ? Brushes.LightGreen : Brushes.Red;
  149. TemperatureSettingState = !state;
  150. }
  151. private void ListenCameraState(bool state)
  152. {
  153. CameraClientFill = state ? Brushes.LightGreen : Brushes.Red;
  154. CameraClientState = !state;
  155. }
  156. private void ListenCameraState2(bool state)
  157. {
  158. CameraClientFill2 = state ? Brushes.LightGreen : Brushes.Red;
  159. CameraClientState2 = !state;
  160. }
  161. private void ListenClientInfo((string portName, bool clientState) obj)
  162. {
  163. ClientName = string.IsNullOrWhiteSpace(obj.portName) ? "NULL" : obj.portName;
  164. PortClientState = !obj.clientState;
  165. PortClientFill = obj.clientState ? Brushes.LightGreen : Brushes.Red;
  166. }
  167. #endregion
  168. }
  169. }