using Aurora; using Aurora.Api; using Aurora.View; using System; using System.ComponentModel; using System.Windows; using System.Windows.Input; using System.Windows.Threading; namespace WeldingCommon.Views.DoorInterlock { public class WinDoorInterlockViewModel : NotifyPropertyChangedBase { public ICommand CMD_VisibleChanged { get; } public ICommand CMD_UserEdit { get; } public ICommand CMD_CheckPassword { get; } public ICommand CMD_Exit { get; } private string _strPhoneNumber = "000-0000-0000"; private string _strPassword = "****"; private bool _bEdit = true; private string _CurrentTime; private string _IdCurrentTime; private bool _IsPasswordBtnEnabled = true; public string PhoneNumber { get => _strPhoneNumber; set => SetProperty(ref _strPhoneNumber, value); } public string Password { get => _strPassword; set => SetProperty(ref _strPassword, value); } public bool IsEdit { get => _bEdit; set => SetProperty(ref _bEdit, value); } public bool IsPasswordBtnEnabled { get => _IsPasswordBtnEnabled; set => SetProperty(ref _IsPasswordBtnEnabled, value); } public string CurrentTime { get { return _CurrentTime; } set { _CurrentTime = value; SetProperty(ref _CurrentTime, value); } } public string IdCurrentTime { get { return _IdCurrentTime; } set { _IdCurrentTime = value; SetProperty(ref _IdCurrentTime, value); } } private readonly string _settingId; private readonly IAuroraEnvironment _aurora; private readonly ISettingEntry _settingManager; private readonly DispatcherTimer _monitorTimer; private bool _isViewActive; private KeyboardHook keyboardHook; public bool IsViewActive { get { return _isViewActive; } set { if (_isViewActive != value) { _isViewActive = value; RaisePropertyChanged(nameof(IsViewActive)); if (_isViewActive) { keyboardHook.HookKeyboard(); } else { keyboardHook.UnhookKeyboard(); } } } } public event PropertyChangedEventHandler PropertyChanged; protected virtual void RaisePropertyChanged(string propertyName) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } public WinDoorInterlockViewModel(ISettingEntry settingMngr, string settingId) { _settingId = settingId; _settingManager = settingMngr; var setting = _settingManager[_settingId] as DoorInterlockSetting; CMD_VisibleChanged = new DelegateCommand(VisibleChanged); CMD_UserEdit = new Aurora.View.DelegateCommand(BtnUserEdit); CMD_CheckPassword = new Aurora.View.DelegateCommand(BtnCheckPassword); //btnCheckPassword CMD_Exit = new DelegateCommand(BtnExit); _monitorTimer = new DispatcherTimer(); _monitorTimer.Tick += OnMonitoring; _monitorTimer.Interval = TimeSpan.FromMilliseconds(300); IsEdit = true; _IsPasswordBtnEnabled = setting.PasswordButtonEnabled; keyboardHook = new KeyboardHook(); } private void OnMonitoring(object sender, EventArgs e) { try { CurrentTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); } catch (Exception) { //_Log.Error(ex); } } private void VisibleChanged(object obj) { //현재 VisibleChanged가 Window 발생 시 브레이킹포인트에 들어오는지 확인이 안됨.. 타이머 스타트가 안되는듯함 bool visible = (bool)obj; if (visible) { _monitorTimer.Start(); } else { _monitorTimer.Stop(); } } private void BtnUserEdit(object obj) { WinDoorInterlockEditViewModel viewModel = new WinDoorInterlockEditViewModel(_settingManager, _settingId); WinDoorInterlockEdit window = new WinDoorInterlockEdit(viewModel); window.WindowStartupLocation = WindowStartupLocation.CenterOwner; window.ShowDialog(); if (window.DialogResult.HasValue && window.DialogResult.Value) { var setting = _settingManager[_settingId] as DoorInterlockSetting; PhoneNumber = setting.PhoneNumber; IsEdit = false; } } private void BtnCheckPassword(object obj) { WinDoorInterlockPasswordViewModel viewModel = new WinDoorInterlockPasswordViewModel(_settingManager, _settingId); WinDoorInterlockPassword window = new WinDoorInterlockPassword(viewModel); window.WindowStartupLocation = WindowStartupLocation.CenterOwner; window.ShowDialog(); if (window.DialogResult.HasValue && window.DialogResult.Value) { IsEdit = true; DoorInterlockPopup.GetInstance().PopupMaintClose(); // 인터락 임의해제면 도어오픈이라도 다시 띄우지 않음 if (!(_settingManager[_settingId] as DoorInterlockSetting).UseManualUnlock) { DoorInterlockSetting SettingItem = _settingManager[_settingId] as DoorInterlockSetting; SettingItem.DoorInterlockPopUpOff = false; _settingManager.Save(_settingId, SettingItem, string.Empty); } } } private void BtnExit(object obj) { DoorInterlockPopup.GetInstance().PopupMaintClose(); } } }