LoginPasswordRegionViewModel.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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 _Codemax = "";
  87. public string Codemax
  88. {
  89. get { return _Codemax; }
  90. set
  91. {
  92. SetProperty(ref _Codemax, value);
  93. }
  94. }
  95. private string _Codemin = "";
  96. public string Codemin
  97. {
  98. get { return _Codemin; }
  99. set
  100. {
  101. SetProperty(ref _Codemin, value);
  102. }
  103. }
  104. private void InitString()
  105. {
  106. Codemax = App.ServiceLoader.GetString("Codemax");
  107. Codemin = App.ServiceLoader.GetString("Codemin");
  108. Text_Login = App.ServiceLoader.GetString("Text_Login");
  109. Text_chmail = App.ServiceLoader.GetString("Text_chmail");
  110. Text_enterpass = App.ServiceLoader.GetString("RegisterPasswordMsg");
  111. Text_forgetpass = App.ServiceLoader.GetString("Text_forgetpass");
  112. LoginPasswordMsg0 = App.ServiceLoader.GetString("LoginPasswordMsg0");
  113. }
  114. #endregion
  115. private bool enableNextStep = false;
  116. public bool EnableNextStep
  117. {
  118. get { return enableNextStep; }
  119. set { SetProperty(ref enableNextStep, value); }
  120. }
  121. private string _LoginEmail = "";
  122. public string LoginEmail
  123. {
  124. get { return _LoginEmail; }
  125. set
  126. {
  127. SetProperty(ref _LoginEmail, value);
  128. }
  129. }
  130. private string _LoginPasswordlook;
  131. public string LoginPasswordlook
  132. {
  133. get { return _LoginPasswordlook; }
  134. set { SetProperty(ref _LoginPasswordlook, value); }
  135. }
  136. private string _LoginPassword = "";
  137. public string LoginPassword
  138. {
  139. get { return _LoginPassword; }
  140. set
  141. {
  142. SetProperty(ref _LoginPassword, value);
  143. LoginPasswordmsglook = "";
  144. LoginPasswordlookVis = Visibility.Collapsed;
  145. if (string.IsNullOrEmpty(LoginPassword))
  146. {
  147. ChkVis = Visibility.Collapsed;
  148. }
  149. else
  150. {
  151. ChkVis = Visibility.Visible;
  152. }
  153. CheckEnableNextStepEncrypt();
  154. }
  155. }
  156. private string _LoginPasswordmsglook = "";
  157. public string LoginPasswordmsglook
  158. {
  159. get { return _LoginPasswordmsglook; }
  160. set
  161. {
  162. SetProperty(ref _LoginPasswordmsglook, value);
  163. }
  164. }
  165. private Visibility _LoginPasswordVisibility = Visibility.Visible;
  166. public Visibility LoginPasswordVisibility
  167. {
  168. get { return _LoginPasswordVisibility; }
  169. set
  170. {
  171. if (value == Visibility.Visible)
  172. {
  173. LoginTextVisibility = Visibility.Collapsed;
  174. }
  175. else
  176. {
  177. LoginTextVisibility = Visibility.Visible;
  178. }
  179. SetProperty(ref _LoginPasswordVisibility, value);
  180. }
  181. }
  182. private Visibility _ChkVis = Visibility.Collapsed;
  183. public Visibility ChkVis
  184. {
  185. get { return _ChkVis; }
  186. set { SetProperty(ref _ChkVis, value); }
  187. }
  188. private Visibility _LoginTextVisibility = Visibility.Collapsed;
  189. public Visibility LoginTextVisibility
  190. {
  191. get { return _LoginTextVisibility; }
  192. set { SetProperty(ref _LoginTextVisibility, value); }
  193. }
  194. private Visibility _LoginPasswordlookVis = Visibility.Collapsed;
  195. public Visibility LoginPasswordlookVis
  196. {
  197. get { return _LoginPasswordlookVis; }
  198. set { SetProperty(ref _LoginPasswordlookVis, value); }
  199. }
  200. public DelegateCommand<object> DisplayPasswordCommand { get; set; }
  201. public DelegateCommand ChangeEmailCommand { get; set; }
  202. public DelegateCommand GoCodeUpdataCommand { get; set; }
  203. public DelegateCommand LoginCommand { get; set; }
  204. public DelegateCommand LinkLicenseCommand { get; set; }
  205. public DelegateCommand LoginPasswordChangedCommand { get; set; }
  206. LoginPasswordRegionViewModel(IRegionManager regionManager, IDialogService dialogService)
  207. {
  208. dialogs = dialogService;
  209. InitString();
  210. DisplayPasswordCommand = new DelegateCommand<object>(DisplayPassword);
  211. LoginCommand = new DelegateCommand(Login);
  212. ChangeEmailCommand = new DelegateCommand(ChangeEmail);
  213. GoCodeUpdataCommand = new DelegateCommand(GoCodeUpdata);
  214. LoginPasswordChangedCommand = new DelegateCommand(LoginPasswordChanged);
  215. }
  216. //密码改变
  217. private void LoginPasswordChanged()
  218. {
  219. if (LoginPassword.Length < 6 && LoginPassword.Length > 0)
  220. {
  221. LoginPasswordlook = Codemin;
  222. }
  223. else if (LoginPassword.Length > 24)
  224. {
  225. LoginPasswordlook = Codemax;
  226. }
  227. else
  228. {
  229. LoginPasswordlook = "";
  230. }
  231. }
  232. //获取忘记密码验证码
  233. private void GoCodeUpdata()
  234. {
  235. LoginPassword = "";
  236. LoginDialogViewModel.IsReset = true;
  237. LoginDialogViewModel.RegionMan("CodeRegion");
  238. }
  239. //登录
  240. private void Login()
  241. {
  242. string code = ServiceHelper.Login(LoginEmail, LoginPassword, uuid);
  243. if (code == "200")
  244. {
  245. LoginDialogViewModel.Close();
  246. App.mainWindowViewModel.UserVis = Visibility.Visible;
  247. App.mainWindowViewModel.RegisterVis = Visibility.Collapsed;
  248. App.mainWindowViewModel.LoginVis = Visibility.Collapsed;
  249. App.mainWindowViewModel.OphVis = Visibility.Collapsed;
  250. Settings.Default.UserDate.Email = LoginEmail;
  251. }
  252. else
  253. {
  254. LoginPasswordmsglook = ErrorCodeHelper.Ercode(code);
  255. LoginPasswordlookVis = Visibility.Visible;
  256. }
  257. }
  258. private void ChangeEmail()
  259. {
  260. LoginDialogViewModel.RegionMan("LoginRegion");
  261. }
  262. private void CheckEnableNextStepEncrypt()
  263. {
  264. EnableNextStep = true;
  265. if (LoginPassword.Length < 6 || LoginPassword.Length > 24 )
  266. {
  267. EnableNextStep = false;
  268. }
  269. }
  270. public void DisplayPassword(object e)
  271. {
  272. var chk = e as CheckBox;
  273. if (chk != null)
  274. {
  275. if (chk.IsChecked == true)
  276. {
  277. LoginPasswordVisibility = Visibility.Collapsed;
  278. }
  279. else
  280. {
  281. LoginPasswordVisibility = Visibility.Visible;
  282. }
  283. }
  284. }
  285. }
  286. }