UserOutCodeRegionViewModel.cs 8.2 KB

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