Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

RootViewModel.cs 5.6 KiB

il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. using HandyControl.Data;
  2. using HKCardIN.Helper;
  3. using HKCardIN.Logic;
  4. using HKCardIN.Logic.Model;
  5. using HKCardIN.Views;
  6. using HKLog;
  7. using Stylet;
  8. using System;
  9. using System.Text.RegularExpressions;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. using UHFHelper;
  14. namespace HKCardIN.ViewModels
  15. {
  16. public class RootViewModel : Conductor<IScreen>
  17. {
  18. bool IsLocker = false;
  19. public RootViewModel()
  20. {
  21. CodeVisible = Visibility.Collapsed;
  22. ContentVisible = Visibility.Visible;
  23. }
  24. #region 属性
  25. decimal _ShowMoney;
  26. public decimal ShowMoney
  27. {
  28. get => _ShowMoney;
  29. set => SetAndNotify(ref _ShowMoney, value);
  30. }
  31. Visibility _ContentVisible;
  32. public Visibility ContentVisible
  33. {
  34. get => _ContentVisible;
  35. set => SetAndNotify(ref _ContentVisible, value);
  36. }
  37. Visibility _CodeVisible;
  38. public Visibility CodeVisible
  39. {
  40. get => _CodeVisible;
  41. set => SetAndNotify(ref _CodeVisible, value);
  42. }
  43. string _InputMoney;
  44. public string InputMoney
  45. {
  46. get => _InputMoney;
  47. set
  48. {
  49. SetAndNotify(ref _InputMoney, value);
  50. decimal.TryParse(value, out decimal data);
  51. ShowMoney = data;
  52. }
  53. }
  54. string _CardNo;
  55. public string CardNo
  56. {
  57. get => _CardNo;
  58. set => SetAndNotify(ref _CardNo, value);
  59. }
  60. UserAndCardInfo _Info;
  61. public UserAndCardInfo Info
  62. {
  63. get => _Info;
  64. set => SetAndNotify(ref _Info, value);
  65. }
  66. #endregion
  67. #region 命令
  68. public void ReadAction()
  69. {
  70. if (!UHFCardHelper.GetInstance().ComOpen)
  71. {
  72. var res = UHFCardHelper.GetInstance().OpenPort();
  73. HKLogImport.WriteInfo(res.ResMes);
  74. }
  75. var RCardNo = UHFCardHelper.GetInstance().ReadCard();
  76. if (!Regex.IsMatch(RCardNo, "\\d{19}"))
  77. {
  78. var res = HandyControl.Controls.MessageBox.Show(new MessageBoxInfo
  79. {
  80. Button = MessageBoxButton.YesNo,
  81. IconKey = "InfoGeometry",
  82. IconBrushKey = "InfoBrush",
  83. YesContent = "是",
  84. NoContent = "否",
  85. Message = "此卡是新卡,前往制卡",
  86. Caption = "提示!"
  87. });
  88. if (res == MessageBoxResult.Yes)
  89. {
  90. CardView view = new CardView();
  91. if (view.ShowDialog().Value) HandyControl.Controls.Growl.InfoGlobal("制卡成功");
  92. else HandyControl.Controls.Growl.InfoGlobal("制卡失败");
  93. }
  94. Info = BaseLogic.GetInstance().PullUserAndCardInfo(CardNo);
  95. UHFCardHelper.GetInstance().ClosePort();
  96. }
  97. else
  98. {
  99. CardNo = RCardNo;
  100. Info = BaseLogic.GetInstance().PullUserAndCardInfo(CardNo);
  101. UHFCardHelper.GetInstance().ClosePort();
  102. }
  103. }
  104. public void InputAction(string input)
  105. {
  106. if (IsLocker) return;
  107. ShowMoney = decimal.Parse(input);
  108. }
  109. public void LockSreenAction()
  110. {
  111. IsLocker = true;
  112. ContentVisible = Visibility.Collapsed;
  113. CodeVisible = Visibility.Visible;
  114. }
  115. public void UnLockAction(HandyControl.Controls.PasswordBox input)
  116. {
  117. if (input.Password.Equals(DataBus.LockCode))
  118. {
  119. IsLocker = false;
  120. CodeVisible = Visibility.Collapsed;
  121. ContentVisible = Visibility.Visible;
  122. }
  123. }
  124. public void SaveAction()
  125. {
  126. if (!DataBus.NetWordState)
  127. {
  128. HandyControl.Controls.Growl.InfoGlobal("系统已离线,请连接网络!!!");
  129. return;
  130. }
  131. if (BaseLogic.GetInstance().PushMoneyToServer(CardNo, ShowMoney))
  132. {
  133. HandyControl.Controls.Growl.SuccessGlobal($"【{CardNo}】充值成功,充值金额【{ShowMoney}】");
  134. Task.Run(() =>
  135. {
  136. Thread.Sleep(5 * 1000);
  137. Info = null;
  138. });
  139. }
  140. else
  141. HandyControl.Controls.Growl.InfoGlobal($"【{CardNo}】充值失败");
  142. }
  143. #endregion
  144. #region 方法
  145. protected override void OnViewLoaded()
  146. {
  147. MainThread();
  148. }
  149. private void MainThread()
  150. {
  151. ThreadManage.GetInstance().StartLong(new Action(() =>
  152. {
  153. try
  154. {
  155. //1.检测网络上下线
  156. bool network = HKHelper.GetInstance().GetNetworkState();
  157. if (network != DataBus.NetWordState)
  158. {
  159. if (network) HandyControl.Controls.Growl.InfoGlobal("网络连接成功");
  160. else HandyControl.Controls.Growl.InfoGlobal("系统已离线,请连接网络!!!");
  161. DataBus.NetWordState = network;
  162. }
  163. Thread.Sleep(3000);
  164. }
  165. catch (Exception ex)
  166. {
  167. HandyControl.Controls.Growl.InfoGlobal(ex.Message);
  168. }
  169. }), "循环状态监测线程", false);
  170. }
  171. #endregion
  172. }
  173. }