Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

RootViewModel.cs 3.5 KiB

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