LoginPasswordRegionViewModel.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. using PDF_Master.CustomControl;
  2. using PDF_Master.Helper;
  3. using PDF_Master.Model;
  4. using PDF_Master.Properties;
  5. using PDF_Master.Views.Dialog.ServiceDialog;
  6. using Prism.Commands;
  7. using Prism.Mvvm;
  8. using Prism.Regions;
  9. using Prism.Services.Dialogs;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Diagnostics;
  13. using System.Linq;
  14. using System.Text;
  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 LoginPasswordRegionViewModel : BindableBase, INavigationAware
  23. {
  24. private string uuid = ServiceHelper.GetDeviceSerialNumber();
  25. private LoginDialogViewModel LoginDialogViewModel;
  26. private ErrorCodeHelper ErrorCodeHelper = new ErrorCodeHelper();
  27. public IDialogService dialogs;
  28. public bool IsNavigationTarget(NavigationContext navigationContext)
  29. {
  30. return true;
  31. }
  32. public void OnNavigatedFrom(NavigationContext navigationContext)
  33. {
  34. }
  35. public void OnNavigatedTo(NavigationContext navigationContext)
  36. {
  37. navigationContext.Parameters.TryGetValue<LoginDialogViewModel>("LoginDialogViewModel", out LoginDialogViewModel);
  38. LoginEmail = LoginDialogViewModel.LoginEmail;
  39. }
  40. #region 文案
  41. private string _Text_Login = "";
  42. public string Text_Login
  43. {
  44. get { return _Text_Login; }
  45. set
  46. {
  47. SetProperty(ref _Text_Login, value);
  48. }
  49. }
  50. private string _Text_chmail = "";
  51. public string Text_chmail
  52. {
  53. get { return _Text_chmail; }
  54. set
  55. {
  56. SetProperty(ref _Text_chmail, value);
  57. }
  58. }
  59. private string _Text_enterpass = "";
  60. public string Text_enterpass
  61. {
  62. get { return _Text_enterpass; }
  63. set
  64. {
  65. SetProperty(ref _Text_enterpass, value);
  66. }
  67. }
  68. private string _LoginPasswordMsg0 = "";
  69. public string LoginPasswordMsg0
  70. {
  71. get { return _LoginPasswordMsg0; }
  72. set
  73. {
  74. SetProperty(ref _LoginPasswordMsg0, value);
  75. }
  76. }
  77. private string _Text_forgetpass = "";
  78. public string Text_forgetpass
  79. {
  80. get { return _Text_forgetpass; }
  81. set
  82. {
  83. SetProperty(ref _Text_forgetpass, value);
  84. }
  85. }
  86. private string _Containspaces = "";
  87. public string Containspaces
  88. {
  89. get { return _Containspaces; }
  90. set
  91. {
  92. SetProperty(ref _Containspaces, value);
  93. }
  94. }
  95. private string _Codemax = "";
  96. public string Codemax
  97. {
  98. get { return _Codemax; }
  99. set
  100. {
  101. SetProperty(ref _Codemax, value);
  102. }
  103. }
  104. private string _Codemin = "";
  105. public string Codemin
  106. {
  107. get { return _Codemin; }
  108. set
  109. {
  110. SetProperty(ref _Codemin, value);
  111. }
  112. }
  113. private void InitString()
  114. {
  115. Codemax = App.ServiceLoader.GetString("Codemax");
  116. Codemin = App.ServiceLoader.GetString("Codemin");
  117. Containspaces = App.ServiceLoader.GetString("code327");
  118. Text_Login = App.ServiceLoader.GetString("Text_Login");
  119. Text_chmail = App.ServiceLoader.GetString("Text_chmail");
  120. Text_enterpass = App.ServiceLoader.GetString("RegisterPasswordMsg");
  121. Text_forgetpass = App.ServiceLoader.GetString("Text_forgetpass");
  122. LoginPasswordMsg0 = App.ServiceLoader.GetString("LoginPasswordMsg0");
  123. }
  124. #endregion
  125. private bool enableNextStep = false;
  126. public bool EnableNextStep
  127. {
  128. get { return enableNextStep; }
  129. set { SetProperty(ref enableNextStep, value); }
  130. }
  131. private string _LoginEmail = "";
  132. public string LoginEmail
  133. {
  134. get { return _LoginEmail; }
  135. set
  136. {
  137. SetProperty(ref _LoginEmail, value);
  138. }
  139. }
  140. private string _LoginPasswordlook;
  141. public string LoginPasswordlook
  142. {
  143. get { return _LoginPasswordlook; }
  144. set { SetProperty(ref _LoginPasswordlook, value); }
  145. }
  146. private string _LoginPassword = "";
  147. public string LoginPassword
  148. {
  149. get { return _LoginPassword; }
  150. set
  151. {
  152. SetProperty(ref _LoginPassword, value);
  153. LoginPasswordmsglook = "";
  154. LoginPasswordlookVis = Visibility.Collapsed;
  155. if (string.IsNullOrEmpty(LoginPassword))
  156. {
  157. ChkVis = Visibility.Collapsed;
  158. }
  159. else
  160. {
  161. ChkVis = Visibility.Visible;
  162. }
  163. CheckEnableNextStepEncrypt();
  164. }
  165. }
  166. private string _LoginPasswordmsglook = "";
  167. public string LoginPasswordmsglook
  168. {
  169. get { return _LoginPasswordmsglook; }
  170. set
  171. {
  172. SetProperty(ref _LoginPasswordmsglook, value);
  173. }
  174. }
  175. private Visibility _LoginPasswordVisibility = Visibility.Visible;
  176. public Visibility LoginPasswordVisibility
  177. {
  178. get { return _LoginPasswordVisibility; }
  179. set
  180. {
  181. if (value == Visibility.Visible)
  182. {
  183. LoginTextVisibility = Visibility.Collapsed;
  184. }
  185. else
  186. {
  187. LoginTextVisibility = Visibility.Visible;
  188. }
  189. SetProperty(ref _LoginPasswordVisibility, value);
  190. }
  191. }
  192. private Visibility _ChkVis = Visibility.Collapsed;
  193. public Visibility ChkVis
  194. {
  195. get { return _ChkVis; }
  196. set { SetProperty(ref _ChkVis, value); }
  197. }
  198. private Visibility _LoginTextVisibility = Visibility.Collapsed;
  199. public Visibility LoginTextVisibility
  200. {
  201. get { return _LoginTextVisibility; }
  202. set { SetProperty(ref _LoginTextVisibility, value); }
  203. }
  204. private Visibility _LoginPasswordlookVis = Visibility.Collapsed;
  205. public Visibility LoginPasswordlookVis
  206. {
  207. get { return _LoginPasswordlookVis; }
  208. set { SetProperty(ref _LoginPasswordlookVis, value); }
  209. }
  210. public DelegateCommand<object> DisplayPasswordCommand { get; set; }
  211. public DelegateCommand ChangeEmailCommand { get; set; }
  212. public DelegateCommand GoCodeUpdataCommand { get; set; }
  213. public DelegateCommand LoginCommand { get; set; }
  214. public DelegateCommand LinkLicenseCommand { get; set; }
  215. public DelegateCommand LoginPasswordChangedCommand { get; set; }
  216. LoginPasswordRegionViewModel(IRegionManager regionManager, IDialogService dialogService)
  217. {
  218. dialogs = dialogService;
  219. InitString();
  220. DisplayPasswordCommand = new DelegateCommand<object>(DisplayPassword);
  221. LoginCommand = new DelegateCommand(Login);
  222. ChangeEmailCommand = new DelegateCommand(ChangeEmail);
  223. GoCodeUpdataCommand = new DelegateCommand(GoCodeUpdata);
  224. LoginPasswordChangedCommand = new DelegateCommand(LoginPasswordChanged);
  225. }
  226. //密码改变
  227. private void LoginPasswordChanged()
  228. {
  229. if (LoginPassword.Length < 6 && LoginPassword.Length > 0)
  230. {
  231. LoginPasswordlook = Codemin;
  232. }
  233. else if (LoginPassword.Length > 24)
  234. {
  235. LoginPasswordlook = Codemax;
  236. }
  237. else if(LoginPassword.Contains(" ")==true)
  238. {
  239. LoginPasswordlook = Containspaces;
  240. }
  241. else
  242. {
  243. LoginPasswordlook = "";
  244. }
  245. }
  246. //获取忘记密码验证码
  247. private void GoCodeUpdata()
  248. {
  249. LoginPassword = "";
  250. LoginDialogViewModel.IsReset = true;
  251. LoginDialogViewModel.RegionMan("CodeRegion");
  252. }
  253. //登录
  254. private void Login()
  255. {
  256. string code = ServiceHelper.Login(LoginEmail, LoginPassword, uuid);
  257. if (code == "200")
  258. {
  259. LoginDialogViewModel.Close();
  260. App.mainWindowViewModel.UserVis = Visibility.Visible;
  261. App.mainWindowViewModel.RegisterVis = Visibility.Collapsed;
  262. App.mainWindowViewModel.LoginVis = Visibility.Collapsed;
  263. App.mainWindowViewModel.OphVis = Visibility.Collapsed;
  264. Settings.Default.UserDate.Email = LoginEmail;
  265. }
  266. else
  267. {
  268. LoginPasswordmsglook = ErrorCodeHelper.Ercode(code);
  269. LoginPasswordlookVis = Visibility.Visible;
  270. }
  271. }
  272. private void ChangeEmail()
  273. {
  274. LoginDialogViewModel.RegionMan("LoginRegion");
  275. }
  276. private void CheckEnableNextStepEncrypt()
  277. {
  278. EnableNextStep = true;
  279. if (LoginPassword.Length < 6 || LoginPassword.Length > 24 || LoginPassword.Contains(" ") == true)
  280. {
  281. EnableNextStep = false;
  282. }
  283. }
  284. public void DisplayPassword(object e)
  285. {
  286. var chk = e as CheckBox;
  287. if (chk != null)
  288. {
  289. if (chk.IsChecked == true)
  290. {
  291. LoginPasswordVisibility = Visibility.Collapsed;
  292. }
  293. else
  294. {
  295. LoginPasswordVisibility = Visibility.Visible;
  296. }
  297. }
  298. }
  299. }
  300. }