|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- using BPA.Helper;
- using HandyControl.Data;
- using HKCardIN.Helper;
- using HKCardIN.Logic;
- using HKCardIN.Logic.Model;
- using HKCardIN.Views;
- using HKLog;
- using Stylet;
- using System;
- using System.Text.RegularExpressions;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows;
- using UHFHelper;
-
- namespace HKCardIN.ViewModels
- {
- public class RootViewModel : Conductor<IScreen>
- {
- bool IsLocker = false;
-
- public RootViewModel()
- {
- CodeVisible = Visibility.Collapsed;
- ContentVisible = Visibility.Visible;
- }
-
- #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 ReadAction()
- {
- if (!UHFCardHelper.GetInstance().ComOpen)
- {
- var res = UHFCardHelper.GetInstance().OpenPort();
- HKLogImport.WriteInfo(res.ResMes);
- }
- var RCardNo = UHFCardHelper.GetInstance().ReadCard();
- if (!Regex.IsMatch(RCardNo, "\\d{19}"))
- {
- var res = HandyControl.Controls.MessageBox.Show(new MessageBoxInfo
- {
- Button = MessageBoxButton.YesNo,
- IconKey = "InfoGeometry",
- IconBrushKey = "InfoBrush",
- YesContent = "是",
- NoContent = "否",
- Message = "此卡是新卡,前往制卡",
- Caption = "提示!"
- });
- if (res == MessageBoxResult.Yes)
- {
- CardView view = new CardView();
- if (view.ShowDialog().Value) HandyControl.Controls.Growl.InfoGlobal("制卡成功");
- else HandyControl.Controls.Growl.InfoGlobal("制卡失败");
- }
- Info = BaseLogic.GetInstance().PullUserAndCardInfo(CardNo);
- UHFCardHelper.GetInstance().ClosePort();
- }
- else
- {
- CardNo = RCardNo;
- Info = BaseLogic.GetInstance().PullUserAndCardInfo(CardNo);
- UHFCardHelper.GetInstance().ClosePort();
- }
-
- }
- 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}】充值成功,充值金额【{ShowMoney}】");
- Task.Run(() =>
- {
- Thread.Sleep(5 * 1000);
- Info = null;
- });
- }
- else
- HandyControl.Controls.Growl.InfoGlobal($"【{CardNo}】充值失败");
- }
- #endregion
-
- #region 方法
- protected override void OnViewLoaded()
- {
- MainThread();
- }
- 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
- }
- }
|