|
- using HKCardIN.Helper;
- using HKCardIN.Logic;
- using HKCardIN.Logic.Model;
- using Stylet;
- using System;
- using System.Threading;
- using System.Windows;
-
- namespace HKCardIN.ViewModels
- {
- public class RootViewModel : Conductor<IScreen>
- {
- 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 _InputMoney;
- public string InputMoney
- {
- get => _InputMoney;
- set
- {
- SetAndNotify(ref _InputMoney, value);
- decimal.TryParse(value, out decimal data);
- ShowMoney = data;
- }
- }
- string _CardNo;
- public string CardNo
- {
- get => _CardNo;
- set => SetAndNotify(ref _CardNo, value);
- }
- UserAndCardInfo _Info;
- public UserAndCardInfo Info
- {
- get => _Info;
- set => SetAndNotify(ref _Info, value);
- }
- #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(HandyControl.Controls.PasswordBox input)
- {
- if (input.Password.Equals(DataBus.LockCode))
- {
- IsLocker = false;
- CodeVisible = Visibility.Collapsed;
- ContentVisible = Visibility.Visible;
- }
- }
- public void SaveAction()
- {
- if (!DataBus.NetWordState)
- {
- HandyControl.Controls.Growl.InfoGlobal("系统已离线,请连接网络!!!");
- return;
- }
-
- if (BaseLogic.GetInstance().PushMoneyToServer(CardNo, ShowMoney))
- HandyControl.Controls.Growl.SuccessGlobal($"【{CardNo}】充值成功");
- else
- HandyControl.Controls.Growl.InfoGlobal($"【{CardNo}】充值失败");
- }
- #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
- }
- }
|