| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- using Prism.Mvvm;
- using Prism.Events;
- using Prism.Commands;
- using System.Windows.Media;
- using SHJX.Service.Common.Event;
- using SHJX.Service.Control.Interface;
- namespace SHJX.Service.Main.ViewModels.Sidebar
- {
- public class OperateMedicineViewModel : BindableBase
- {
- #region Fields
- private readonly IEventAggregator _ea;
- private readonly IMainService _service;
- #endregion
- #region Properties
- public string _copyrightInformation;
- public string CopyrightInformation
- {
- get => _copyrightInformation;
- set => SetProperty(ref _copyrightInformation, value);
- }
- /// <summary>
- /// 连接名
- /// </summary>
- private string _clientName;
- public string ClientName
- {
- get => _clientName;
- set => SetProperty(ref _clientName, value);
- }
- /// <summary>
- /// 端口连接状态
- /// </summary>
- private SolidColorBrush _portClientFill;
- public SolidColorBrush PortClientFill
- {
- get => _portClientFill;
- set
- {
- SetProperty(ref _portClientFill, value);
- _portClientFill.Freeze();
- }
- }
- private bool _portClientState;
- public bool PortClientState
- {
- get => _portClientState;
- set => SetProperty(ref _portClientState, value);
- }
- /// <summary>
- /// 摄像头连接状态
- /// </summary>
- private SolidColorBrush _cameraClientFill;
- public SolidColorBrush CameraClientFill
- {
- get => _cameraClientFill;
- set
- {
- SetProperty(ref _cameraClientFill, value);
- _cameraClientFill.Freeze();
- }
- }
- private bool _cameraClientState;
- public bool CameraClientState
- {
- get => _cameraClientState;
- set => SetProperty(ref _cameraClientState, value);
- }
- /// <summary>
- /// 摄像头2连接状态
- /// </summary>
- private SolidColorBrush _cameraClientFill2;
- public SolidColorBrush CameraClientFill2
- {
- get => _cameraClientFill2;
- set
- {
- SetProperty(ref _cameraClientFill2, value);
- _cameraClientFill2.Freeze();
- }
- }
- private bool _cameraClientState2;
- public bool CameraClientState2
- {
- get => _cameraClientState2;
- set => SetProperty(ref _cameraClientState2, value);
- }
- private SolidColorBrush _temperatureSettingFill;
- public SolidColorBrush TemperatureSettingFill
- {
- get => _temperatureSettingFill;
- set
- {
- SetProperty(ref _temperatureSettingFill, value);
- _temperatureSettingFill.Freeze();
- }
- }
- private bool _temperatureSettingState;
- public bool TemperatureSettingState
- {
- get => _temperatureSettingState;
- set => SetProperty(ref _temperatureSettingState, value);
- }
- /// <summary>
- /// 是否锁定
- /// </summary>
- private bool? _mainLock;
- public bool? WhetherLockMain
- {
- get => _mainLock;
- set => SetProperty(ref _mainLock, value);
- }
- #endregion
- #region Commands
- private DelegateCommand _lockDestCommand;
- public DelegateCommand LockDestCommand => _lockDestCommand ??= new DelegateCommand(() =>
- {
- _ea.GetEvent<LockDesktopEvent>().Publish((bool)WhetherLockMain);
- });
- private DelegateCommand _freshClientCommand;
- public DelegateCommand FreshClientCommand => _freshClientCommand ?? new DelegateCommand(() =>
- {
- _service.FreshClient();
- });
- private DelegateCommand _freshCameraCommand;
- public DelegateCommand FreshCameraCommand => _freshCameraCommand ?? new DelegateCommand(() =>
- {
- _service.FreshCamera();
- });
- private DelegateCommand _resettingTemperatureCommand;
- public DelegateCommand ReSettingTemperatureCommand => _resettingTemperatureCommand ?? new DelegateCommand(() =>
- {
- _service.ResettingTemperature();
- });
- #endregion
- public OperateMedicineViewModel(IEventAggregator ea, IMainService service)
- {
- _ea = ea;
- _service = service;
- _ea.GetEvent<ClientCameraEvent>().Subscribe(ListenCameraState);
- _ea.GetEvent<ClientCameraEvent2>().Subscribe(ListenCameraState2);
- _ea.GetEvent<ClientResponseEvent>().Subscribe(ListenClientInfo);
- _ea.GetEvent<HeatingStateEvent>().Subscribe(ListenTemperatureSettingState);
- }
- #region Event Methods
- private void ListenTemperatureSettingState(bool state)
- {
- TemperatureSettingFill = state ? Brushes.LightGreen : Brushes.Red;
- TemperatureSettingState = !state;
- }
- private void ListenCameraState(bool state)
- {
- CameraClientFill = state ? Brushes.LightGreen : Brushes.Red;
- CameraClientState = !state;
- }
- private void ListenCameraState2(bool state)
- {
- CameraClientFill2 = state ? Brushes.LightGreen : Brushes.Red;
- CameraClientState2 = !state;
- }
- private void ListenClientInfo((string portName, bool clientState) obj)
- {
- ClientName = string.IsNullOrWhiteSpace(obj.portName) ? "NULL" : obj.portName;
- PortClientState = !obj.clientState;
- PortClientFill = obj.clientState ? Brushes.LightGreen : Brushes.Red;
- }
- #endregion
- }
- }
|