RegisterRegionViewModel.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. using PDF_Master.Helper;
  2. using PDF_Master.Model;
  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.Diagnostics;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Text.RegularExpressions;
  13. using System.Threading.Tasks;
  14. using System.Windows;
  15. using System.Windows.Controls;
  16. namespace PDF_Master.ViewModels.Dialog.ServiceDialog
  17. {
  18. public class RegisterRegionViewModel : BindableBase, INavigationAware
  19. {
  20. private RegisterDialogViewModel RegisterDialogViewModel;
  21. private ErrorCodeHelper ErrorCodeHelper = new ErrorCodeHelper();
  22. public IDialogService dialogs;
  23. public bool IsNavigationTarget(NavigationContext navigationContext)
  24. {
  25. return true;
  26. }
  27. public void OnNavigatedFrom(NavigationContext navigationContext)
  28. {
  29. }
  30. public void OnNavigatedTo(NavigationContext navigationContext)
  31. {
  32. navigationContext.Parameters.TryGetValue<RegisterDialogViewModel>("RegisterDialogViewModel", out RegisterDialogViewModel);
  33. }
  34. #region 文案
  35. private string _Text_Signup = "";
  36. public string Text_Signup
  37. {
  38. get { return _Text_Signup; }
  39. set { SetProperty(ref _Text_Signup, value); }
  40. }
  41. private string _registerText1 = "";
  42. public string Registertext1
  43. {
  44. get { return _registerText1; }
  45. set
  46. {
  47. SetProperty(ref _registerText1, value);
  48. }
  49. }
  50. private string _registerNextStep = "";
  51. public string RegisterNextStep
  52. {
  53. get { return _registerNextStep; }
  54. set
  55. {
  56. SetProperty(ref _registerNextStep, value);
  57. }
  58. }
  59. private string _registerEmailMsg = "";
  60. public string RegisterEmailMsg
  61. {
  62. get { return _registerEmailMsg; }
  63. set
  64. {
  65. SetProperty(ref _registerEmailMsg, value);
  66. }
  67. }
  68. private string _registerPasswordMsg = "";
  69. public string RegisterPasswordMsg
  70. {
  71. get { return _registerPasswordMsg; }
  72. set
  73. {
  74. SetProperty(ref _registerPasswordMsg, value);
  75. }
  76. }
  77. private string _Text_Login = "";
  78. public string Text_Login
  79. {
  80. get { return _Text_Login; }
  81. set { SetProperty(ref _Text_Login, value); }
  82. }
  83. private string _Text_remsg = "";
  84. public string Text_remsg
  85. {
  86. get { return _Text_remsg; }
  87. set
  88. {
  89. SetProperty(ref _Text_remsg, value);
  90. }
  91. }
  92. private string _Text_privary = "";
  93. public string Text_privary
  94. {
  95. get { return _Text_privary; }
  96. set
  97. {
  98. SetProperty(ref _Text_privary, value);
  99. }
  100. }
  101. private string _Text_and = "";
  102. public string Text_and
  103. {
  104. get { return _Text_and; }
  105. set
  106. {
  107. SetProperty(ref _Text_and, value);
  108. }
  109. }
  110. private string _Text_licens = "";
  111. public string Text_licens
  112. {
  113. get { return _Text_licens; }
  114. set
  115. {
  116. SetProperty(ref _Text_licens, value);
  117. }
  118. }
  119. private string _Containspaces = "";
  120. public string Containspaces
  121. {
  122. get { return _Containspaces; }
  123. set
  124. {
  125. SetProperty(ref _Containspaces, value);
  126. }
  127. }
  128. private string _Codemax = "";
  129. public string Codemax
  130. {
  131. get { return _Codemax; }
  132. set
  133. {
  134. SetProperty(ref _Codemax, value);
  135. }
  136. }
  137. private string _Codemin = "";
  138. public string Codemin
  139. {
  140. get { return _Codemin; }
  141. set
  142. {
  143. SetProperty(ref _Codemin, value);
  144. }
  145. }
  146. private string _Mailerr = "";
  147. public string Mailerr
  148. {
  149. get { return _Mailerr; }
  150. set
  151. {
  152. SetProperty(ref _Mailerr, value);
  153. }
  154. }
  155. private void InitString()
  156. {
  157. ErrorCodeHelper.InitString();
  158. Containspaces = App.ServiceLoader.GetString("code327");
  159. Text_Signup = App.ServiceLoader.GetString("Text_Signup");
  160. Registertext1 = App.ServiceLoader.GetString("Registertext1");
  161. RegisterEmailMsg = App.ServiceLoader.GetString("RegisterEmailMsg");
  162. RegisterPasswordMsg = App.ServiceLoader.GetString("RegisterPasswordMsg");
  163. RegisterNextStep = App.ServiceLoader.GetString("RegisterNextStep");
  164. Text_Login = App.ServiceLoader.GetString("Text_Login");
  165. Text_remsg = App.ServiceLoader.GetString("Text_remsg");
  166. Text_privary = App.ServiceLoader.GetString("Text_privary");
  167. Text_and = App.ServiceLoader.GetString("Text_and");
  168. Text_licens = App.ServiceLoader.GetString("Text_licens");
  169. Codemax = App.ServiceLoader.GetString("Codemax");
  170. Codemin = App.ServiceLoader.GetString("Codemin");
  171. Mailerr = App.ServiceLoader.GetString("Mailerr");
  172. }
  173. #endregion
  174. private bool enableNextStep = false;
  175. public bool EnableNextStep
  176. {
  177. get { return enableNextStep; }
  178. set { SetProperty(ref enableNextStep, value); }
  179. }
  180. private string _registerEmaillook;
  181. public string RegisterEmaillook
  182. {
  183. get { return _registerEmaillook; }
  184. set { SetProperty(ref _registerEmaillook, value); }
  185. }
  186. private string _registerePasswordlook;
  187. public string RegisterePasswordlook
  188. {
  189. get { return _registerePasswordlook; }
  190. set { SetProperty(ref _registerePasswordlook, value); }
  191. }
  192. private string _uriPolivy = "https://www.pdfreaderpro.com/privacy-policy";
  193. public string UriPolivy
  194. {
  195. get { return _uriPolivy; }
  196. set
  197. {
  198. SetProperty(ref _uriPolivy, value);
  199. }
  200. }
  201. private string _uriLicense = "https://www.pdfreaderpro.com/terms_of_service";
  202. public string UriLicense
  203. {
  204. get { return _uriLicense; }
  205. set
  206. {
  207. SetProperty(ref _uriLicense, value);
  208. }
  209. }
  210. private bool _isRegisterPasswordDisplayed = false;
  211. public bool IsRegisterPasswordDisplayed
  212. {
  213. get { return _isRegisterPasswordDisplayed; }
  214. set { SetProperty(ref _isRegisterPasswordDisplayed, value); }
  215. }
  216. private string _registerPassword = "";
  217. public string RegisterPassword
  218. {
  219. get { return _registerPassword; }
  220. set
  221. {
  222. SetProperty(ref _registerPassword, value);
  223. if (string.IsNullOrEmpty(RegisterPassword))
  224. {
  225. ChkVis = Visibility.Collapsed;
  226. }
  227. else
  228. {
  229. ChkVis = Visibility.Visible;
  230. }
  231. CheckEnableNextStepEncrypt();
  232. }
  233. }
  234. private string _registerEmail = "";
  235. public string RegisterEmail
  236. {
  237. get { return _registerEmail; }
  238. set
  239. {
  240. SetProperty(ref _registerEmail, value);
  241. RegisterEmaillook = "";
  242. //if (RegisterEmail=="")
  243. //{
  244. // RegisterEmaillook = "";
  245. //}
  246. //else
  247. //{
  248. // CheckMail(RegisterEmail);
  249. //}
  250. CheckEnableNextStepEncrypt();
  251. }
  252. }
  253. private Visibility _registerPasswordVisibility = Visibility.Visible;
  254. public Visibility RegisterPasswordVisibility
  255. {
  256. get { return _registerPasswordVisibility; }
  257. set
  258. {
  259. if (value == Visibility.Visible)
  260. {
  261. RegisterTextVisibility = Visibility.Collapsed;
  262. }
  263. else
  264. {
  265. RegisterTextVisibility = Visibility.Visible;
  266. }
  267. SetProperty(ref _registerPasswordVisibility, value);
  268. }
  269. }
  270. private Visibility _ChkVis = Visibility.Collapsed;
  271. public Visibility ChkVis
  272. {
  273. get { return _ChkVis; }
  274. set { SetProperty(ref _ChkVis, value); }
  275. }
  276. private Visibility _registerTextVisibility = Visibility.Collapsed;
  277. public Visibility RegisterTextVisibility
  278. {
  279. get { return _registerTextVisibility; }
  280. set { SetProperty(ref _registerTextVisibility, value); }
  281. }
  282. private bool _isPermissionsPasswordDisplayed = false;
  283. public bool IsPermissionsPasswordDisplayed
  284. {
  285. get { return _isPermissionsPasswordDisplayed; }
  286. set { SetProperty(ref _isPermissionsPasswordDisplayed, value); }
  287. }
  288. public DelegateCommand<object> DisplayPasswordCommand { get; set; }
  289. public DelegateCommand LinkPolicyCommand { get; set; }
  290. public DelegateCommand RegisterNextCommand { get; set; }
  291. public DelegateCommand GoLoginCommand { get; set; }
  292. public DelegateCommand RegisterPasswordChangedCommand { get; set; }
  293. public DelegateCommand LinkLicenseCommand { get; set; }
  294. RegisterRegionViewModel(IRegionManager regionManager, IDialogService dialogService)
  295. {
  296. dialogs = dialogService;
  297. DisplayPasswordCommand = new DelegateCommand<object>(DisplayPassword);
  298. LinkPolicyCommand = new DelegateCommand(LinkPolicy);
  299. LinkLicenseCommand = new DelegateCommand(LinkLicense);
  300. GoLoginCommand = new DelegateCommand(GoLogin);
  301. RegisterNextCommand = new DelegateCommand(RegisterNext);
  302. RegisterPasswordChangedCommand = new DelegateCommand(RegisterPasswordChanged);
  303. InitString();
  304. }
  305. private void RegisterPasswordChanged()
  306. {
  307. if(RegisterPassword.Length<6&& RegisterPassword.Length>0)
  308. {
  309. RegisterePasswordlook = Codemin;
  310. }
  311. else if(RegisterPassword.Length>24)
  312. {
  313. RegisterePasswordlook = Codemax;
  314. }
  315. else if (RegisterPassword.Contains(" ") == true)
  316. {
  317. RegisterePasswordlook = Containspaces;
  318. }
  319. else
  320. {
  321. RegisterePasswordlook = "";
  322. }
  323. }
  324. private void CheckMail(string mail)
  325. {
  326. string str = "^([a-z0-9_\\.-]+)@([\\da-z\\.-]+)\\.([a-z\\.]{2,6})$";
  327. Regex mReg = new Regex(str);
  328. if (mReg.IsMatch(mail))
  329. {
  330. RegisterEmaillook = "";
  331. }
  332. else
  333. {
  334. RegisterEmaillook =Mailerr;
  335. }
  336. }
  337. private void RegisterNext()
  338. {
  339. //去掉前后空格
  340. RegisterEmail = RegisterEmail.Trim();
  341. string code = ServiceHelper.Ok_email(RegisterEmail, "2");
  342. if (code == "200")
  343. {
  344. RegisterDialogViewModel.RegisterEmail = RegisterEmail;
  345. RegisterDialogViewModel.RegisterPassword = RegisterPassword;
  346. RegisterDialogViewModel.RegionMan("CodeRegion");
  347. }
  348. else
  349. {
  350. RegisterEmaillook = ErrorCodeHelper.Ercode(code);
  351. }
  352. }
  353. public void SetOpenPassword(object e)
  354. {
  355. var chk = e as CheckBox;
  356. if (chk != null)
  357. {
  358. IsRegisterPasswordDisplayed = false;
  359. RegisterPasswordVisibility = Visibility.Visible;
  360. }
  361. CheckEnableNextStepEncrypt();
  362. }
  363. private void GoLogin()
  364. {
  365. RegisterDialogViewModel.Close();
  366. App.mainWindowViewModel.OpenLogin();
  367. }
  368. private void LinkPolicy()
  369. {
  370. Process.Start(new ProcessStartInfo(UriPolivy));
  371. }
  372. private void LinkLicense()
  373. {
  374. Process.Start(new ProcessStartInfo(UriLicense));
  375. }
  376. private void CheckEnableNextStepEncrypt()
  377. {
  378. EnableNextStep = true;
  379. if (RegisterPassword.Length<6|| RegisterPassword.Length >24 || string.IsNullOrEmpty(RegisterEmail)|| RegisterEmaillook!= "" || RegisterPassword.Contains(" ") == true)
  380. {
  381. EnableNextStep = false;
  382. }
  383. }
  384. public void DisplayPassword(object e)
  385. {
  386. var chk = e as CheckBox;
  387. if (chk != null)
  388. {
  389. if (chk.IsChecked == true)
  390. {
  391. RegisterPasswordVisibility = Visibility.Collapsed;
  392. }
  393. else
  394. {
  395. RegisterPasswordVisibility = Visibility.Visible;
  396. }
  397. }
  398. }
  399. }
  400. }