CodeRegionViewModel.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  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. else
  227. {
  228. RegisterCodemsg = ErrorCodeHelper.Ercode("codehad");
  229. Bordcolor = "#F3465B";
  230. BottomBackgroubd = "#FFF1C1";
  231. RegisterCodemsgVis = Visibility.Visible;
  232. }
  233. }
  234. else
  235. {
  236. CodeType = "user_register";
  237. string code = ServiceHelper.Get_code("user_register", RegisterDialogViewModel.RegisterEmail);
  238. if (code == "315")
  239. {
  240. Codeagin = Visibility.Visible;
  241. Codetime = " ";
  242. disTimer.Stop();
  243. RegisterCodemsg = ErrorCodeHelper.Ercode("codehad");
  244. RegisterCodemsgVis = Visibility.Visible;
  245. Bordcolor = "#FFAF25";
  246. BottomBackgroubd = "#FFF1C1";
  247. }
  248. else if (code == "200")
  249. {
  250. Codeagin = Visibility.Collapsed;
  251. Timebegin();
  252. }
  253. else
  254. {
  255. RegisterCodemsg = ErrorCodeHelper.Ercode("codehad");
  256. Bordcolor = "#F3465B";
  257. BottomBackgroubd = "#FFF1C1";
  258. RegisterCodemsgVis = Visibility.Visible;
  259. }
  260. }
  261. if (CodeType == "user_reset_password")
  262. {
  263. CodeTypeName = Text_toocode;
  264. }
  265. else
  266. {
  267. CodeTypeName = Text_Signup;
  268. }
  269. }
  270. public DelegateCommand BackRegisterLastCommand { get; set; }
  271. public DelegateCommand CodetooCommand { get; set; }
  272. public DelegateCommand Code6ChangedCommand { get; set; }
  273. public DelegateCommand RegisterNextCommand { get; set; }
  274. public CodeRegionViewModel(IRegionManager regionManager, IDialogService dialogService)
  275. {
  276. dialogs = dialogService;
  277. BackRegisterLastCommand = new DelegateCommand(BackRegisterLast);
  278. CodetooCommand = new DelegateCommand(Codetoo);
  279. Code6ChangedCommand = new DelegateCommand(Code6Changed);
  280. RegisterNextCommand = new DelegateCommand(RegisterNext);
  281. if (CodeType == "user_reset_password")
  282. {
  283. CodeTypeName = Text_toocode;
  284. }
  285. else
  286. {
  287. CodeTypeName = Text_Signup;
  288. }
  289. }
  290. private void Codeclear()
  291. {
  292. Code1 = "";
  293. Code2 = "";
  294. Code3 = "";
  295. Code4 = "";
  296. Code5 = "";
  297. Code6= "";
  298. }
  299. private bool CodeSum()
  300. {
  301. Codesum = Code1 + Code2 + Code3 + Code4 + Code5 + Code6;
  302. if(Codesum.Length==6)
  303. {
  304. return true;
  305. }
  306. else
  307. {
  308. return false;
  309. }
  310. }
  311. //下一步按钮
  312. private void RegisterNext()
  313. {
  314. if (CodeType == "user_register")
  315. {
  316. string code = ServiceHelper.Register_email(RegisterDialogViewModel.RegisterEmail, RegisterDialogViewModel.RegisterPassword, Codesum, uuid);
  317. if (code == "200")
  318. {
  319. App.mainWindowViewModel.UserVis = Visibility.Visible;
  320. App.mainWindowViewModel.RegisterVis = Visibility.Collapsed;
  321. App.mainWindowViewModel.LoginVis = Visibility.Collapsed;
  322. App.mainWindowViewModel.OphVis = Visibility.Collapsed;
  323. Settings.Default.UserDate.Email = RegisterDialogViewModel.RegisterEmail;
  324. //RegisterDialogViewModel.RegionMan("RegisterOKRegion");
  325. Codeclear();
  326. RegisterDialogViewModel.Close();
  327. App.mainWindowViewModel.OpenRegisterOK();
  328. }
  329. else
  330. {
  331. EnableNextStep = false;
  332. RegisterCodemsg = ErrorCodeHelper.Ercode(code);
  333. Bordcolor = "#F3465B";
  334. BottomBackgroubd = "#FDC7C6";
  335. RegisterCodemsgVis = Visibility.Visible;
  336. }
  337. }
  338. else
  339. {
  340. LoginDialogViewModel.PasswordCode = Codesum;
  341. LoginDialogViewModel.RegionMan("PasswordUpdataRegion");
  342. Codeclear();
  343. }
  344. }
  345. //第六个密码框改变
  346. private void Code6Changed()
  347. {
  348. Codesum = Code1 + Code2 + Code3 + Code4 + Code5 + Code6;
  349. if (CodeSum() ==true)
  350. {
  351. if (CodeType == "user_register")
  352. {
  353. string code = ServiceHelper.Ok_code(RegisterDialogViewModel.RegisterEmail, Codesum, CodeType);
  354. if (code == "200")
  355. {
  356. EnableNextStep = true;
  357. RegisterCodemsgVis = Visibility.Collapsed;
  358. }
  359. else
  360. {
  361. EnableNextStep = false;
  362. RegisterCodemsg = ErrorCodeHelper.Ercode(code);
  363. Bordcolor = "#F3465B";
  364. BottomBackgroubd = "#FDC7C6";
  365. RegisterCodemsgVis = Visibility.Visible;
  366. }
  367. }
  368. else
  369. {
  370. string code = ServiceHelper.Ok_code(LoginDialogViewModel.LoginEmail, Codesum, CodeType);
  371. if (code == "200")
  372. {
  373. EnableNextStep = true;
  374. }
  375. else
  376. {
  377. EnableNextStep = false;
  378. RegisterCodemsg = ErrorCodeHelper.Ercode(code);
  379. Bordcolor = "#F3465B";
  380. BottomBackgroubd = "#FDC7C6";
  381. RegisterCodemsgVis = Visibility.Visible;
  382. }
  383. }
  384. }
  385. else
  386. {
  387. EnableNextStep = false;
  388. }
  389. }
  390. //重发密码
  391. private void Codetoo()
  392. {
  393. time = 60;
  394. Codeagin = Visibility.Collapsed;
  395. if (CodeType == "user_register")
  396. {
  397. ServiceHelper.Get_code(CodeType, RegisterDialogViewModel.RegisterEmail);
  398. }
  399. else if (CodeType == "user_reset_password")
  400. {
  401. ServiceHelper.Get_code(CodeType, LoginDialogViewModel.LoginEmail);
  402. }
  403. }
  404. //计数
  405. public void disTimer_Tick(object sender, EventArgs e)
  406. {
  407. if (time == 0)
  408. {
  409. Codeagin = Visibility.Visible;
  410. Codetime = " ";
  411. }
  412. else
  413. {
  414. time--;
  415. Codetime = " ("+time.ToString()+")";
  416. }
  417. }
  418. //计时器
  419. private DispatcherTimer disTimer = new DispatcherTimer();
  420. public void Timebegin()
  421. {
  422. time = 60;
  423. //设置定时器
  424. disTimer.Tick += new EventHandler(disTimer_Tick);//每一秒执行的方法
  425. disTimer.Interval = new TimeSpan(10000000); //时间间隔为一秒。
  426. disTimer.Start();//计时开始
  427. }
  428. //判断验证类型
  429. private void BackRegisterLast()
  430. {
  431. if(CodeType== "user_register")
  432. {
  433. RegisterDialogViewModel.RegionMan("RegisterRegion");
  434. }
  435. else if(CodeType == "user_reset_password")
  436. {
  437. LoginDialogViewModel.RegionMan("LoginPasswordRegion");
  438. }
  439. Codeclear();
  440. }
  441. }
  442. }