LoginRegionViewModel.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. using PDF_Master.CustomControl;
  2. using PDF_Master.Helper;
  3. using PDF_Master.Model;
  4. using PDF_Master.Views.Dialog.ServiceDialog;
  5. using Prism.Commands;
  6. using Prism.Mvvm;
  7. using Prism.Regions;
  8. using Prism.Services.Dialogs;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Diagnostics;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Text.RegularExpressions;
  15. using System.Threading.Tasks;
  16. using System.Windows;
  17. using System.Windows.Controls;
  18. using System.Windows.Documents;
  19. using System.Windows.Navigation;
  20. namespace PDF_Master.ViewModels.Dialog.ServiceDialog
  21. {
  22. public class LoginRegionViewModel : BindableBase, INavigationAware
  23. {
  24. private LoginDialogViewModel LoginDialogViewModel;
  25. private ErrorCodeHelper ErrorCodeHelper = new ErrorCodeHelper();
  26. public IDialogService dialogs;
  27. public bool IsNavigationTarget(NavigationContext navigationContext)
  28. {
  29. return true;
  30. }
  31. public void OnNavigatedFrom(NavigationContext navigationContext)
  32. {
  33. }
  34. public void OnNavigatedTo(NavigationContext navigationContext)
  35. {
  36. navigationContext.Parameters.TryGetValue<LoginDialogViewModel>("LoginDialogViewModel", out LoginDialogViewModel);
  37. }
  38. #region 文案
  39. private string _Text_Login = "";
  40. public string Text_Login
  41. {
  42. get { return _Text_Login; }
  43. set
  44. {
  45. SetProperty(ref _Text_Login, value);
  46. }
  47. }
  48. private string _Text_emailac = "";
  49. public string Text_emailac
  50. {
  51. get { return _Text_emailac; }
  52. set
  53. {
  54. SetProperty(ref _Text_emailac, value);
  55. }
  56. }
  57. private string _Text_next = "";
  58. public string Text_next
  59. {
  60. get { return _Text_next; }
  61. set
  62. {
  63. SetProperty(ref _Text_next, value);
  64. }
  65. }
  66. private string _Text_noacc = "";
  67. public string Text_noacc
  68. {
  69. get { return _Text_noacc; }
  70. set
  71. {
  72. SetProperty(ref _Text_noacc, value);
  73. }
  74. }
  75. private string _Text_toregister = "";
  76. public string Text_toregister
  77. {
  78. get { return _Text_toregister; }
  79. set
  80. {
  81. SetProperty(ref _Text_toregister, value);
  82. }
  83. }
  84. private string _LoginEmailMsg = "";
  85. public string LoginEmailMsg
  86. {
  87. get { return _LoginEmailMsg; }
  88. set
  89. {
  90. SetProperty(ref _LoginEmailMsg, value);
  91. }
  92. }
  93. private string _Mailerr = "";
  94. public string Mailerr
  95. {
  96. get { return _Mailerr; }
  97. set
  98. {
  99. SetProperty(ref _Mailerr, value);
  100. }
  101. }
  102. private void InitString()
  103. {
  104. Text_Login = App.ServiceLoader.GetString("Text_Login");
  105. Text_emailac = App.ServiceLoader.GetString("Text_emailac");
  106. Text_next = App.ServiceLoader.GetString("RegisterNextStep");
  107. Text_noacc = App.ServiceLoader.GetString("Text_noacc");
  108. Text_toregister = App.ServiceLoader.GetString("Text_Signup");
  109. Mailerr = App.ServiceLoader.GetString("Mailerr");
  110. LoginEmailMsg = App.ServiceLoader.GetString("RegisterEmailMsg");
  111. }
  112. #endregion
  113. private bool enableNextStep = false;
  114. public bool EnableNextStep
  115. {
  116. get { return enableNextStep; }
  117. set { SetProperty(ref enableNextStep, value); }
  118. }
  119. private string _LoginEmaillook;
  120. public string LoginEmaillook
  121. {
  122. get { return _LoginEmaillook; }
  123. set { SetProperty(ref _LoginEmaillook, value);}
  124. }
  125. private string _LoginEmail = "";
  126. public string LoginEmail
  127. {
  128. get { return _LoginEmail; }
  129. set
  130. {
  131. SetProperty(ref _LoginEmail, value);
  132. if (LoginEmail == "")
  133. {
  134. LoginEmaillook = "";
  135. }
  136. else
  137. {
  138. CheckMail(LoginEmail);
  139. }
  140. CheckEnableNextStepEncrypt();
  141. }
  142. }
  143. public DelegateCommand LoginNextCommand { get; set; }
  144. public DelegateCommand GoLoginCommand { get; set; }
  145. LoginRegionViewModel(IRegionManager regionManager, IDialogService dialogService)
  146. {
  147. dialogs = dialogService;
  148. LoginNextCommand = new DelegateCommand(LoginNext);
  149. GoLoginCommand = new DelegateCommand(GoLogin);
  150. InitString();
  151. }
  152. private void LoginNext()
  153. {
  154. if (ServiceHelper.Ok_email(LoginEmail, "1") == "200")
  155. {
  156. LoginDialogViewModel.LoginEmail = LoginEmail;
  157. LoginDialogViewModel.RegionMan("LoginPasswordRegion");
  158. }
  159. else if (ServiceHelper.Ok_email(LoginEmail, "1") == "300")
  160. {
  161. LoginDialogViewModel.RegionMan("NOInternetRegion");
  162. }
  163. else if (ServiceHelper.Ok_email(LoginEmail, "1") == "318")
  164. {
  165. dialogs.ShowDialog(DialogNames.UserOutingLogin, new DialogParameters(""), r =>
  166. {
  167. });
  168. }
  169. else
  170. {
  171. LoginEmaillook = ErrorCodeHelper.Ercode(ServiceHelper.Ok_email(LoginEmail, "1"));
  172. }
  173. }
  174. private void CheckMail(string mail)
  175. {
  176. string str = "^([a-z0-9_\\.-]+)@([\\da-z\\.-]+)\\.([a-z\\.]{2,6})$";
  177. Regex mReg = new Regex(str);
  178. if (mReg.IsMatch(mail))
  179. {
  180. LoginEmaillook = "";
  181. }
  182. else
  183. {
  184. LoginEmaillook = Mailerr;
  185. }
  186. }
  187. private void GoLogin()
  188. {
  189. LoginDialogViewModel.Close();
  190. App.mainWindowViewModel.OpenRegister();
  191. }
  192. private void CheckEnableNextStepEncrypt()
  193. {
  194. EnableNextStep = true;
  195. if (string.IsNullOrEmpty(LoginEmail)||LoginEmaillook!="")
  196. {
  197. EnableNextStep = false;
  198. }
  199. }
  200. }
  201. }