using HKCardIN.Helper; using Stylet; using System; using System.Threading; using System.Windows; namespace HKCardIN.ViewModels { public class RootViewModel : Conductor { bool IsLocker = false; public RootViewModel() { CodeVisible = Visibility.Collapsed; ContentVisible = Visibility.Visible; MainThread(); } #region 属性 decimal _ShowMoney; public decimal ShowMoney { get => _ShowMoney; set => SetAndNotify(ref _ShowMoney, value); } Visibility _ContentVisible; public Visibility ContentVisible { get => _ContentVisible; set => SetAndNotify(ref _ContentVisible, value); } Visibility _CodeVisible; public Visibility CodeVisible { get => _CodeVisible; set => SetAndNotify(ref _CodeVisible, value); } string _LockCode; public string LockCode { get => _LockCode; set => SetAndNotify(ref _LockCode, value); } string _InputMoney; public string InputMoney { get => _InputMoney; set { SetAndNotify(ref _InputMoney, value); decimal.TryParse(value, out decimal data); ShowMoney = data; } } #endregion #region 命令 public void InputAction(string input) { if (IsLocker) return; ShowMoney = decimal.Parse(input); } public void LockSreenAction() { IsLocker = true; ContentVisible = Visibility.Collapsed; CodeVisible = Visibility.Visible; } public void UnLockAction() { if (LockCode.Equals(DataBus.LockCode)) { IsLocker = false; CodeVisible = Visibility.Collapsed; ContentVisible = Visibility.Visible; LockCode = string.Empty; } } public void ResetAction() { LockCode = string.Empty; } public void SaveAction() { if (!DataBus.NetWordState) { HandyControl.Controls.Growl.InfoGlobal("系统已离线,请连接网络!!!"); return; } } #endregion #region 方法 private void MainThread() { ThreadManage.GetInstance().StartLong(new Action(() => { try { //1.检测网络上下线 bool network = HKHelper.GetInstance().GetNetworkState(); if (network != DataBus.NetWordState) { if (network) HandyControl.Controls.Growl.InfoGlobal("网络连接成功"); else HandyControl.Controls.Growl.InfoGlobal("系统已离线,请连接网络!!!"); DataBus.NetWordState = network; } Thread.Sleep(3000); } catch (Exception ex) { HandyControl.Controls.Growl.InfoGlobal(ex.Message); } }), "循环状态监测线程", false); } #endregion } }