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.

116 regels
3.3 KiB

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