You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 line
3.7 KiB

  1. using HKCardIN.Helper;
  2. using HKCardIN.Logic;
  3. using HKCardIN.Logic.Model;
  4. using Stylet;
  5. using System;
  6. using System.Threading;
  7. using System.Windows;
  8. namespace HKCardIN.ViewModels
  9. {
  10. public class RootViewModel : Conductor<IScreen>
  11. {
  12. bool IsLocker = false;
  13. public RootViewModel()
  14. {
  15. CodeVisible = Visibility.Collapsed;
  16. ContentVisible = Visibility.Visible;
  17. MainThread();
  18. }
  19. #region 属性
  20. decimal _ShowMoney;
  21. public decimal ShowMoney
  22. {
  23. get => _ShowMoney;
  24. set => SetAndNotify(ref _ShowMoney, value);
  25. }
  26. Visibility _ContentVisible;
  27. public Visibility ContentVisible
  28. {
  29. get => _ContentVisible;
  30. set => SetAndNotify(ref _ContentVisible, value);
  31. }
  32. Visibility _CodeVisible;
  33. public Visibility CodeVisible
  34. {
  35. get => _CodeVisible;
  36. set => SetAndNotify(ref _CodeVisible, value);
  37. }
  38. string _InputMoney;
  39. public string InputMoney
  40. {
  41. get => _InputMoney;
  42. set
  43. {
  44. SetAndNotify(ref _InputMoney, value);
  45. decimal.TryParse(value, out decimal data);
  46. ShowMoney = data;
  47. }
  48. }
  49. string _CardNo;
  50. public string CardNo
  51. {
  52. get => _CardNo;
  53. set => SetAndNotify(ref _CardNo, value);
  54. }
  55. UserAndCardInfo _Info;
  56. public UserAndCardInfo Info
  57. {
  58. get => _Info;
  59. set => SetAndNotify(ref _Info, value);
  60. }
  61. #endregion
  62. #region 命令
  63. public void InputAction(string input)
  64. {
  65. if (IsLocker) return;
  66. ShowMoney = decimal.Parse(input);
  67. }
  68. public void LockSreenAction()
  69. {
  70. IsLocker = true;
  71. ContentVisible = Visibility.Collapsed;
  72. CodeVisible = Visibility.Visible;
  73. }
  74. public void UnLockAction(HandyControl.Controls.PasswordBox input)
  75. {
  76. if (input.Password.Equals(DataBus.LockCode))
  77. {
  78. IsLocker = false;
  79. CodeVisible = Visibility.Collapsed;
  80. ContentVisible = Visibility.Visible;
  81. }
  82. }
  83. public void SaveAction()
  84. {
  85. if (!DataBus.NetWordState)
  86. {
  87. HandyControl.Controls.Growl.InfoGlobal("系统已离线,请连接网络!!!");
  88. return;
  89. }
  90. if (BaseLogic.GetInstance().PushMoneyToServer(CardNo, ShowMoney))
  91. HandyControl.Controls.Growl.SuccessGlobal($"【{CardNo}】充值成功");
  92. else
  93. HandyControl.Controls.Growl.InfoGlobal($"【{CardNo}】充值失败");
  94. }
  95. #endregion
  96. #region 方法
  97. private void MainThread()
  98. {
  99. ThreadManage.GetInstance().StartLong(new Action(() =>
  100. {
  101. try
  102. {
  103. //1.检测网络上下线
  104. bool network = HKHelper.GetInstance().GetNetworkState();
  105. if (network != DataBus.NetWordState)
  106. {
  107. if (network) HandyControl.Controls.Growl.InfoGlobal("网络连接成功");
  108. else HandyControl.Controls.Growl.InfoGlobal("系统已离线,请连接网络!!!");
  109. DataBus.NetWordState = network;
  110. }
  111. Thread.Sleep(3000);
  112. }
  113. catch (Exception ex)
  114. {
  115. HandyControl.Controls.Growl.InfoGlobal(ex.Message);
  116. }
  117. }), "循环状态监测线程", false);
  118. }
  119. #endregion
  120. }
  121. }