UserOutCodeRegionViewModel.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. using PDF_Office.Helper;
  2. using PDF_Office.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_Office.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 = true;
  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())
  46. {
  47. Code6Changed();
  48. }
  49. }
  50. }
  51. private string _Code2 = "";
  52. public string Code2
  53. {
  54. get { return _Code2; }
  55. set { SetProperty(ref _Code2, value);
  56. if (CodeSum())
  57. {
  58. Code6Changed();
  59. }
  60. }
  61. }
  62. private string _Code3 = "";
  63. public string Code3
  64. {
  65. get { return _Code3; }
  66. set { SetProperty(ref _Code3, value);
  67. if (CodeSum())
  68. {
  69. Code6Changed();
  70. }
  71. }
  72. }
  73. private string _Code4 = "";
  74. public string Code4
  75. {
  76. get { return _Code4; }
  77. set { SetProperty(ref _Code4, value);
  78. if (CodeSum())
  79. {
  80. Code6Changed();
  81. }
  82. }
  83. }
  84. private string _Code5 = "";
  85. public string Code5
  86. {
  87. get { return _Code5; }
  88. set { SetProperty(ref _Code5, value);
  89. if (CodeSum())
  90. {
  91. Code6Changed();
  92. }
  93. }
  94. }
  95. private string _Code6 = "";
  96. public string Code6
  97. {
  98. get { return _Code6; }
  99. set { SetProperty(ref _Code6, value);
  100. }
  101. }
  102. private string _UserCodemsg = "";
  103. public string UserCodemsg
  104. {
  105. get { return _UserCodemsg; }
  106. set { SetProperty(ref _UserCodemsg, value); }
  107. }
  108. private Visibility _codeagin = Visibility.Collapsed;
  109. public Visibility Codeagin
  110. {
  111. get { return _codeagin; }
  112. set { SetProperty(ref _codeagin, value); }
  113. }
  114. private Visibility _UserCodemsgVis = Visibility.Collapsed;
  115. public Visibility UserCodemsgVis
  116. {
  117. get { return _UserCodemsgVis; }
  118. set { SetProperty(ref _UserCodemsgVis, value); }
  119. }
  120. public bool IsNavigationTarget(NavigationContext navigationContext)
  121. {
  122. return true;
  123. }
  124. public void OnNavigatedFrom(NavigationContext navigationContext)
  125. {
  126. }
  127. public void OnNavigatedTo(NavigationContext navigationContext)
  128. {
  129. navigationContext.Parameters.TryGetValue<UserDialogViewModel>("UserDialogViewModel", out UserDialogViewModel);
  130. }
  131. public DelegateCommand UserOutCancelCommand { get; set; }
  132. public DelegateCommand CodetooCommand { get; set; }
  133. public DelegateCommand Code6ChangedCommand { get; set; }
  134. public DelegateCommand UserOutCommand { get; set; }
  135. public UserOutCodeRegionViewModel(IRegionManager regionManager, IDialogService dialogService)
  136. {
  137. Timebegin();
  138. dialogs = dialogService;
  139. UserOutCancelCommand = new DelegateCommand(UserOutCancel);
  140. CodetooCommand = new DelegateCommand(Codetoo);
  141. Code6ChangedCommand = new DelegateCommand(Code6Changed);
  142. UserOutCommand = new DelegateCommand(UserOut);
  143. }
  144. private void UserOutCancel()
  145. {
  146. UserDialogViewModel.Close();
  147. }
  148. //注销
  149. private void UserOut()
  150. {
  151. Codesum = Code1 + Code2 + Code3 + Code4 + Code5 + Code6;
  152. if (Codesum.Length == 6)
  153. {
  154. if (ServiceHelper.Ok_code(UserDialogViewModel.UserEmail, Codesum, "user_log_off") == "success")
  155. {
  156. if (ServiceHelper.Usergout(Codesum) == "success")
  157. {
  158. Settings.Default.AppProperties.LoginToken = "";
  159. App.IsLogin =false;
  160. Settings.Default.Save();
  161. App.mainWindowViewModel.UserVis = Visibility.Collapsed;
  162. App.mainWindowViewModel.RegisterVis = Visibility.Collapsed;
  163. App.mainWindowViewModel.LoginVis = Visibility.Visible;
  164. UserDialogViewModel.Close();
  165. }
  166. else
  167. {
  168. UserCodemsg = ServiceHelper.Usergout(Codesum);
  169. UserCodemsgVis = Visibility.Visible;
  170. }
  171. }
  172. else
  173. {
  174. UserCodemsg = ServiceHelper.Ok_code(UserDialogViewModel.UserEmail, Codesum, "user_log_off");
  175. UserCodemsgVis = Visibility.Visible;
  176. }
  177. }
  178. else
  179. {
  180. UserCodemsg = "请输入六位数验证码";
  181. }
  182. }
  183. private bool CodeSum()
  184. {
  185. Codesum = Code1 + Code2 + Code3 + Code4 + Code5 + Code6;
  186. if (Codesum.Length == 6)
  187. {
  188. return true;
  189. }
  190. else
  191. {
  192. return false;
  193. }
  194. }
  195. private void Code6Changed()
  196. {
  197. if (Code6.Length == 1)
  198. {
  199. if (CodeSum() == true)
  200. {
  201. if (ServiceHelper.Ok_code(UserDialogViewModel.UserEmail, Codesum, "user_log_off") == "success")
  202. {
  203. if (ServiceHelper.Usergout(Codesum) == "success")
  204. {
  205. Settings.Default.AppProperties.LoginToken = "";
  206. App.IsLogin = false;
  207. Settings.Default.Save();
  208. App.mainWindowViewModel.UserVis = Visibility.Collapsed;
  209. App.mainWindowViewModel.RegisterVis = Visibility.Collapsed;
  210. App.mainWindowViewModel.LoginVis = Visibility.Visible;
  211. UserDialogViewModel.Close();
  212. }
  213. else
  214. {
  215. UserCodemsg = ServiceHelper.Usergout(Codesum);
  216. UserCodemsgVis = Visibility.Visible;
  217. }
  218. }
  219. else
  220. {
  221. UserCodemsg = ServiceHelper.Ok_code(UserDialogViewModel.UserEmail, Codesum, "user_log_off");
  222. UserCodemsgVis = Visibility.Visible;
  223. }
  224. }
  225. else
  226. {
  227. UserCodemsg = "请输入六位数验证码";
  228. UserCodemsgVis = Visibility.Visible;
  229. }
  230. }
  231. }
  232. private void Codetoo()
  233. {
  234. Codeagin = Visibility.Collapsed;
  235. time = 60;
  236. ServiceHelper.Get_code("user_log_off", UserDialogViewModel.UserEmail);
  237. }
  238. public void disTimer_Tick(object sender, EventArgs e)
  239. {
  240. if (time == 0)
  241. {
  242. Codeagin = Visibility.Visible;
  243. Codetime = "";
  244. }
  245. else
  246. {
  247. time--;
  248. Codetime = "(" + time.ToString() + ")";
  249. }
  250. }
  251. private DispatcherTimer disTimer = new DispatcherTimer();
  252. public void Timebegin()
  253. {
  254. time = 60;
  255. //设置定时器
  256. disTimer.Tick += new EventHandler(disTimer_Tick);//每一秒执行的方法
  257. disTimer.Interval = new TimeSpan(10000000); //时间间隔为一秒。
  258. disTimer.Start();//计时开始
  259. }
  260. }
  261. }