CodeRegionViewModel.cs 15 KB

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