UserOutCodeRegionViewModel.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. using PDF_Master.Helper;
  2. using PDF_Master.Properties;
  3. using Prism.Commands;
  4. using Prism.Mvvm;
  5. using Prism.Regions;
  6. using Prism.Services.Dialogs;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. using System.Windows.Threading;
  14. namespace PDF_Master.ViewModels.Dialog.ServiceDialog
  15. {
  16. public class UserOutCodeRegionViewModel : BindableBase, INavigationAware
  17. {
  18. private string uuid = ServiceHelper.GetDeviceSerialNumber();
  19. public IDialogService dialogs;
  20. private UserDialogViewModel UserDialogViewModel;
  21. private int time = 60;
  22. private bool _EnableNextStep =false;
  23. public bool EnableNextStep
  24. {
  25. get { return _EnableNextStep; }
  26. set { SetProperty(ref _EnableNextStep, value); }
  27. }
  28. private string _codetime = "60";
  29. public string Codetime
  30. {
  31. get { return _codetime; }
  32. set { SetProperty(ref _codetime, value); }
  33. }
  34. private string _Codesum = "";
  35. public string Codesum
  36. {
  37. get { return _Codesum; }
  38. set { SetProperty(ref _Codesum, value); }
  39. }
  40. private string _Code1 = "";
  41. public string Code1
  42. {
  43. get { return _Code1; }
  44. set { SetProperty(ref _Code1, value);
  45. if(CodeSum()==true)
  46. {
  47. EnableNextStep = true;
  48. }
  49. else
  50. {
  51. EnableNextStep = false;
  52. }
  53. }
  54. }
  55. private string _Code2 = "";
  56. public string Code2
  57. {
  58. get { return _Code2; }
  59. set { SetProperty(ref _Code2, value);
  60. if (CodeSum() == true)
  61. {
  62. EnableNextStep = true;
  63. }
  64. else
  65. {
  66. EnableNextStep = false;
  67. }
  68. }
  69. }
  70. private string _Code3 = "";
  71. public string Code3
  72. {
  73. get { return _Code3; }
  74. set { SetProperty(ref _Code3, value);
  75. if (CodeSum() == true)
  76. {
  77. EnableNextStep = true;
  78. }
  79. else
  80. {
  81. EnableNextStep = false;
  82. }
  83. }
  84. }
  85. private string _Code4 = "";
  86. public string Code4
  87. {
  88. get { return _Code4; }
  89. set { SetProperty(ref _Code4, value);
  90. if (CodeSum() == true)
  91. {
  92. EnableNextStep = true;
  93. }
  94. else
  95. {
  96. EnableNextStep = false;
  97. }
  98. }
  99. }
  100. private string _Code5 = "";
  101. public string Code5
  102. {
  103. get { return _Code5; }
  104. set { SetProperty(ref _Code5, value);
  105. if (CodeSum() == true)
  106. {
  107. EnableNextStep = true;
  108. }
  109. else
  110. {
  111. EnableNextStep = false;
  112. }
  113. }
  114. }
  115. private string _Code6 = "";
  116. public string Code6
  117. {
  118. get { return _Code6; }
  119. set { SetProperty(ref _Code6, value);
  120. if (CodeSum() == true)
  121. {
  122. EnableNextStep = true;
  123. }
  124. else
  125. {
  126. EnableNextStep = false;
  127. }
  128. }
  129. }
  130. private string _UserCodemsg = "";
  131. public string UserCodemsg
  132. {
  133. get { return _UserCodemsg; }
  134. set { SetProperty(ref _UserCodemsg, value); }
  135. }
  136. private Visibility _codeagin = Visibility.Collapsed;
  137. public Visibility Codeagin
  138. {
  139. get { return _codeagin; }
  140. set { SetProperty(ref _codeagin, value); }
  141. }
  142. private Visibility _UserCodemsgVis = Visibility.Collapsed;
  143. public Visibility UserCodemsgVis
  144. {
  145. get { return _UserCodemsgVis; }
  146. set { SetProperty(ref _UserCodemsgVis, value); }
  147. }
  148. public bool IsNavigationTarget(NavigationContext navigationContext)
  149. {
  150. return true;
  151. }
  152. public void OnNavigatedFrom(NavigationContext navigationContext)
  153. {
  154. }
  155. public void OnNavigatedTo(NavigationContext navigationContext)
  156. {
  157. navigationContext.Parameters.TryGetValue<UserDialogViewModel>("UserDialogViewModel", out UserDialogViewModel);
  158. }
  159. public DelegateCommand UserOutCancelCommand { get; set; }
  160. public DelegateCommand CodetooCommand { get; set; }
  161. public DelegateCommand UserOutCommand { get; set; }
  162. public UserOutCodeRegionViewModel(IRegionManager regionManager, IDialogService dialogService)
  163. {
  164. Timebegin();
  165. dialogs = dialogService;
  166. UserOutCancelCommand = new DelegateCommand(UserOutCancel);
  167. CodetooCommand = new DelegateCommand(Codetoo);
  168. UserOutCommand = new DelegateCommand(UserOut);
  169. }
  170. private void UserOutCancel()
  171. {
  172. UserDialogViewModel.Close();
  173. }
  174. //注销
  175. private void UserOut()
  176. {
  177. Codesum = Code1 + Code2 + Code3 + Code4 + Code5 + Code6;
  178. if (Codesum.Length == 6)
  179. {
  180. if (ServiceHelper.Ok_code(UserDialogViewModel.UserEmail, Codesum, "user_log_off") == "success")
  181. {
  182. if (ServiceHelper.Usergout(Codesum) == "success")
  183. {
  184. Settings.Default.AppProperties.LoginToken = "";
  185. App.IsLogin =false;
  186. Settings.Default.Save();
  187. App.mainWindowViewModel.UserVis = Visibility.Collapsed;
  188. App.mainWindowViewModel.RegisterVis = Visibility.Collapsed;
  189. App.mainWindowViewModel.LoginVis = Visibility.Visible;
  190. UserDialogViewModel.Close();
  191. }
  192. else
  193. {
  194. UserCodemsg = ServiceHelper.Usergout(Codesum);
  195. UserCodemsgVis = Visibility.Visible;
  196. }
  197. }
  198. else
  199. {
  200. UserCodemsg = ServiceHelper.Ok_code(UserDialogViewModel.UserEmail, Codesum, "user_log_off");
  201. UserCodemsgVis = Visibility.Visible;
  202. }
  203. }
  204. else
  205. {
  206. UserCodemsg = "请输入六位数验证码";
  207. }
  208. }
  209. private bool CodeSum()
  210. {
  211. Codesum = Code1 + Code2 + Code3 + Code4 + Code5 + Code6;
  212. if (Codesum.Length == 6)
  213. {
  214. return true;
  215. }
  216. else
  217. {
  218. return false;
  219. }
  220. }
  221. private void Codetoo()
  222. {
  223. Codeagin = Visibility.Collapsed;
  224. time = 60;
  225. ServiceHelper.Get_code("user_log_off", UserDialogViewModel.UserEmail);
  226. }
  227. public void disTimer_Tick(object sender, EventArgs e)
  228. {
  229. if (time == 0)
  230. {
  231. Codeagin = Visibility.Visible;
  232. Codetime = "";
  233. }
  234. else
  235. {
  236. time--;
  237. Codetime = "(" + time.ToString() + ")";
  238. }
  239. }
  240. private DispatcherTimer disTimer = new DispatcherTimer();
  241. public void Timebegin()
  242. {
  243. time = 60;
  244. //设置定时器
  245. disTimer.Tick += new EventHandler(disTimer_Tick);//每一秒执行的方法
  246. disTimer.Interval = new TimeSpan(10000000); //时间间隔为一秒。
  247. disTimer.Start();//计时开始
  248. }
  249. }
  250. }