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);
}
///
/// 连接名
///
private string _clientName;
public string ClientName
{
get => _clientName;
set => SetProperty(ref _clientName, value);
}
///
/// 端口连接状态
///
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);
}
///
/// 摄像头连接状态
///
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);
}
///
/// 摄像头2连接状态
///
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);
}
///
/// 是否锁定
///
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().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().Subscribe(ListenCameraState);
_ea.GetEvent().Subscribe(ListenCameraState2);
_ea.GetEvent().Subscribe(ListenClientInfo);
_ea.GetEvent().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
}
}