UserOutCodeRegionViewModel.cs 8.7 KB

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