CodeRegionViewModel.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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 CodeRegionViewModel : BindableBase, INavigationAware
  17. {
  18. private string uuid = ServiceHelper.GetDeviceSerialNumber();
  19. private RegisterDialogViewModel RegisterDialogViewModel;
  20. private LoginDialogViewModel LoginDialogViewModel;
  21. public IDialogService dialogs;
  22. //60秒倒计时
  23. private int time = 60;
  24. private bool _EnableNextStep = true;
  25. public bool EnableNextStep
  26. {
  27. get { return _EnableNextStep; }
  28. set { SetProperty(ref _EnableNextStep, value); }
  29. }
  30. private string _CodeTypeName = "注册账号";
  31. public string CodeTypeName
  32. {
  33. get { return _CodeTypeName; }
  34. set { SetProperty(ref _CodeTypeName, value); }
  35. }
  36. private string _CodeType = "user_register";
  37. public string CodeType
  38. {
  39. get { return _CodeType; }
  40. set { SetProperty(ref _CodeType, value); }
  41. }
  42. private string _codetime = "60";
  43. public string Codetime
  44. {
  45. get { return _codetime; }
  46. set { SetProperty(ref _codetime, value); }
  47. }
  48. private string _Codesum = "";
  49. public string Codesum
  50. {
  51. get { return _Codesum; }
  52. set { SetProperty(ref _Codesum, value); }
  53. }
  54. private string _Code1 = "";
  55. public string Code1
  56. {
  57. get { return _Code1; }
  58. set { SetProperty(ref _Code1, value);
  59. if( CodeSum())
  60. {
  61. Code6Changed();
  62. }
  63. }
  64. }
  65. private string _Code2 = "";
  66. public string Code2
  67. {
  68. get { return _Code2; }
  69. set { SetProperty(ref _Code2, value);
  70. if (CodeSum())
  71. {
  72. Code6Changed();
  73. }
  74. }
  75. }
  76. private string _Code3 = "";
  77. public string Code3
  78. {
  79. get { return _Code3; }
  80. set { SetProperty(ref _Code3, value);
  81. if (CodeSum())
  82. {
  83. Code6Changed();
  84. }
  85. }
  86. }
  87. private string _Code4 = "";
  88. public string Code4
  89. {
  90. get { return _Code4; }
  91. set { SetProperty(ref _Code4, value);
  92. if (CodeSum())
  93. {
  94. Code6Changed();
  95. }
  96. }
  97. }
  98. private string _Code5 = "";
  99. public string Code5
  100. {
  101. get { return _Code5; }
  102. set { SetProperty(ref _Code5, value);
  103. if (CodeSum())
  104. {
  105. Code6Changed();
  106. }
  107. }
  108. }
  109. private string _Code6 = "";
  110. public string Code6
  111. {
  112. get { return _Code6; }
  113. set { SetProperty(ref _Code6, value); }
  114. }
  115. private string _RegisterCodemsg = "";
  116. public string RegisterCodemsg
  117. {
  118. get { return _RegisterCodemsg; }
  119. set { SetProperty(ref _RegisterCodemsg, value); }
  120. }
  121. private Visibility _codeagin = Visibility.Collapsed;
  122. public Visibility Codeagin
  123. {
  124. get { return _codeagin; }
  125. set { SetProperty(ref _codeagin, value); }
  126. }
  127. private Visibility _RegisterCodemsgVis = Visibility.Collapsed;
  128. public Visibility RegisterCodemsgVis
  129. {
  130. get { return _RegisterCodemsgVis; }
  131. set { SetProperty(ref _RegisterCodemsgVis, value); }
  132. }
  133. public bool IsNavigationTarget(NavigationContext navigationContext)
  134. {
  135. return true;
  136. }
  137. public void OnNavigatedFrom(NavigationContext navigationContext)
  138. {
  139. }
  140. public void OnNavigatedTo(NavigationContext navigationContext)
  141. {
  142. navigationContext.Parameters.TryGetValue<RegisterDialogViewModel>("RegisterDialogViewModel", out RegisterDialogViewModel);
  143. navigationContext.Parameters.TryGetValue<LoginDialogViewModel>("LoginDialogViewModel", out LoginDialogViewModel);
  144. if (LoginDialogViewModel!=null&&LoginDialogViewModel.IsReset == true)
  145. {
  146. CodeType = "user_reset_password";
  147. LoginDialogViewModel.IsReset = false;
  148. }
  149. else
  150. {
  151. CodeType = "user_register";
  152. }
  153. if (CodeType == "user_reset_password")
  154. {
  155. CodeTypeName = "重置密码";
  156. }
  157. else
  158. {
  159. CodeTypeName = "注册账号";
  160. }
  161. }
  162. public DelegateCommand BackRegisterLastCommand { get; set; }
  163. public DelegateCommand CodetooCommand { get; set; }
  164. public DelegateCommand Code6ChangedCommand { get; set; }
  165. public DelegateCommand RegisterNextCommand { get; set; }
  166. public CodeRegionViewModel(IRegionManager regionManager, IDialogService dialogService)
  167. {
  168. Timebegin();
  169. dialogs = dialogService;
  170. BackRegisterLastCommand = new DelegateCommand(BackRegisterLast);
  171. CodetooCommand = new DelegateCommand(Codetoo);
  172. Code6ChangedCommand = new DelegateCommand(Code6Changed);
  173. RegisterNextCommand = new DelegateCommand(RegisterNext);
  174. if (LoginDialogViewModel != null && LoginDialogViewModel.IsReset == true)
  175. {
  176. CodeType = "user_reset_password";
  177. LoginDialogViewModel.IsReset = false;
  178. }
  179. else
  180. {
  181. CodeType = "user_register";
  182. }
  183. if (CodeType == "user_reset_password")
  184. {
  185. CodeTypeName = "重置密码";
  186. }
  187. else
  188. {
  189. CodeTypeName = "注册账号";
  190. }
  191. }
  192. private bool CodeSum()
  193. {
  194. Codesum = Code1 + Code2 + Code3 + Code4 + Code5 + Code6;
  195. if(Codesum.Length==6)
  196. {
  197. return true;
  198. }
  199. else
  200. {
  201. return false;
  202. }
  203. }
  204. //下一步按钮
  205. private void RegisterNext()
  206. {
  207. Codesum = Code1 + Code2 + Code3 + Code4 + Code5 + Code6;
  208. if (Codesum.Length == 6)
  209. {
  210. if (CodeType == "user_register")
  211. {
  212. if (ServiceHelper.Ok_code(RegisterDialogViewModel.RegisterEmail, Codesum, CodeType) == "success")
  213. {
  214. if (ServiceHelper.Register_email(RegisterDialogViewModel.RegisterEmail, RegisterDialogViewModel.RegisterPassword, Codesum, uuid) == "success")
  215. {
  216. App.mainWindowViewModel.UserVis = Visibility.Visible;
  217. App.mainWindowViewModel.RegisterVis = Visibility.Collapsed;
  218. App.mainWindowViewModel.LoginVis = Visibility.Collapsed;
  219. App.mainWindowViewModel.OphVis = Visibility.Collapsed;
  220. Settings.Default.UserDate.Email = RegisterDialogViewModel.RegisterEmail;
  221. RegisterDialogViewModel.RegionMan("RegisterOKRegion");
  222. }
  223. else
  224. {
  225. RegisterCodemsg = ServiceHelper.Register_email(RegisterDialogViewModel.RegisterEmail, RegisterDialogViewModel.RegisterPassword, Codesum, uuid);
  226. RegisterCodemsgVis = Visibility.Visible;
  227. }
  228. }
  229. else
  230. {
  231. RegisterCodemsg = ServiceHelper.Ok_code(RegisterDialogViewModel.RegisterEmail, Codesum, CodeType);
  232. RegisterCodemsgVis = Visibility.Visible;
  233. }
  234. }
  235. else
  236. {
  237. if (ServiceHelper.Ok_code(LoginDialogViewModel.LoginEmail, Codesum, CodeType) == "success")
  238. {
  239. LoginDialogViewModel.PasswordCode = Codesum;
  240. LoginDialogViewModel.RegionMan("PasswordUpdataRegion");
  241. }
  242. else
  243. {
  244. RegisterCodemsg = ServiceHelper.Ok_code(LoginDialogViewModel.LoginEmail, Codesum, CodeType);
  245. RegisterCodemsgVis = Visibility.Visible;
  246. }
  247. }
  248. }
  249. else
  250. {
  251. RegisterCodemsg = "请输入六位数验证码";
  252. }
  253. }
  254. //第六个密码框改变
  255. private void Code6Changed()
  256. {
  257. if(Code6.Length==1)
  258. {
  259. ;
  260. if (CodeSum() ==true)
  261. {
  262. if (CodeType == "user_register")
  263. {
  264. if (ServiceHelper.Ok_code(RegisterDialogViewModel.RegisterEmail, Codesum, CodeType) == "success")
  265. {
  266. if (ServiceHelper.Register_email(RegisterDialogViewModel.RegisterEmail, RegisterDialogViewModel.RegisterPassword, Codesum, uuid) == "success")
  267. {
  268. App.mainWindowViewModel.UserVis = Visibility.Visible;
  269. App.mainWindowViewModel.RegisterVis = Visibility.Collapsed;
  270. App.mainWindowViewModel.LoginVis = Visibility.Collapsed;
  271. App.mainWindowViewModel.OphVis = Visibility.Collapsed;
  272. Settings.Default.UserDate.Email = RegisterDialogViewModel.RegisterEmail;
  273. RegisterDialogViewModel.RegionMan("RegisterOKRegion");
  274. }
  275. else
  276. {
  277. RegisterCodemsg = ServiceHelper.Register_email(RegisterDialogViewModel.RegisterEmail, RegisterDialogViewModel.RegisterPassword, Codesum, uuid);
  278. RegisterCodemsgVis = Visibility.Visible;
  279. }
  280. }
  281. else
  282. {
  283. RegisterCodemsg = ServiceHelper.Ok_code(RegisterDialogViewModel.RegisterEmail, Codesum, CodeType);
  284. RegisterCodemsgVis = Visibility.Visible;
  285. }
  286. }
  287. else
  288. {
  289. if (ServiceHelper.Ok_code(LoginDialogViewModel.LoginEmail, Codesum, CodeType) == "success")
  290. {
  291. LoginDialogViewModel.PasswordCode = Codesum;
  292. LoginDialogViewModel.RegionMan("PasswordUpdataRegion");
  293. }
  294. else
  295. {
  296. RegisterCodemsg = ServiceHelper.Ok_code(LoginDialogViewModel.LoginEmail, Codesum, CodeType);
  297. RegisterCodemsgVis = Visibility.Visible;
  298. }
  299. }
  300. }
  301. else
  302. {
  303. RegisterCodemsg = "请输入六位数验证码";
  304. RegisterCodemsgVis = Visibility.Visible;
  305. }
  306. }
  307. }
  308. //重发密码
  309. private void Codetoo()
  310. {
  311. time = 60;
  312. Codeagin = Visibility.Collapsed;
  313. if (CodeType == "user_register")
  314. {
  315. ServiceHelper.Get_code(CodeType, RegisterDialogViewModel.RegisterEmail);
  316. }
  317. else if (CodeType == "user_reset_password")
  318. {
  319. ServiceHelper.Get_code(CodeType, LoginDialogViewModel.LoginEmail);
  320. }
  321. }
  322. //计数
  323. public void disTimer_Tick(object sender, EventArgs e)
  324. {
  325. if (time == 0)
  326. {
  327. Codeagin = Visibility.Visible;
  328. Codetime = "";
  329. }
  330. else
  331. {
  332. time--;
  333. Codetime = "("+time.ToString()+")";
  334. }
  335. }
  336. //计时器
  337. private DispatcherTimer disTimer = new DispatcherTimer();
  338. public void Timebegin()
  339. {
  340. time = 60;
  341. //设置定时器
  342. disTimer.Tick += new EventHandler(disTimer_Tick);//每一秒执行的方法
  343. disTimer.Interval = new TimeSpan(10000000); //时间间隔为一秒。
  344. disTimer.Start();//计时开始
  345. }
  346. //判断验证类型
  347. private void BackRegisterLast()
  348. {
  349. if(CodeType== "user_register")
  350. {
  351. RegisterDialogViewModel.RegionMan("RegisterRegion");
  352. }
  353. else if(CodeType == "user_reset_password")
  354. {
  355. LoginDialogViewModel.RegionMan("LoginPasswordRegion");
  356. }
  357. }
  358. }
  359. }