UserOutCodeRegionViewModel.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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 UserOutCodeRegionViewModel : BindableBase, INavigationAware
  17. {
  18. private string uuid = ServiceHelper.GetDeviceSerialNumber();
  19. private ErrorCodeHelper ErrorCodeHelper = new ErrorCodeHelper();
  20. public IDialogService dialogs;
  21. private UserDialogViewModel UserDialogViewModel;
  22. private int time = 60;
  23. #region 文案
  24. private string _Text_userout = "";
  25. public string Text_userout
  26. {
  27. get { return _Text_userout; }
  28. set { SetProperty(ref _Text_userout, value); }
  29. }
  30. private string _Text_Cancellatio = "";
  31. public string Text_Cancellatio
  32. {
  33. get { return _Text_Cancellatio; }
  34. set { SetProperty(ref _Text_Cancellatio, value); }
  35. }
  36. private string _Text_vcode = "";
  37. public string Text_vcode
  38. {
  39. get { return _Text_vcode; }
  40. set { SetProperty(ref _Text_vcode, value); }
  41. }
  42. private string _Text_novcode = "";
  43. public string Text_novcode
  44. {
  45. get { return _Text_novcode; }
  46. set { SetProperty(ref _Text_novcode, value); }
  47. }
  48. private string _Text_recode = "";
  49. public string Text_recode
  50. {
  51. get { return _Text_recode; }
  52. set { SetProperty(ref _Text_recode, value); }
  53. }
  54. private string _BtText_cancel = "";
  55. public string BtText_cancel
  56. {
  57. get { return _BtText_cancel; }
  58. set { SetProperty(ref _BtText_cancel, value); }
  59. }
  60. private void InitString()
  61. {
  62. Text_userout = App.ServiceLoader.GetString("Text_userout");
  63. Text_Cancellatio = App.ServiceLoader.GetString("Text_Cancellatio");
  64. Text_vcode = App.ServiceLoader.GetString("Text_vcode");
  65. Text_novcode = App.ServiceLoader.GetString("Text_novcode");
  66. Text_recode = App.ServiceLoader.GetString("Text_recode");
  67. BtText_cancel = App.ServiceLoader.GetString("Text_cancel");
  68. }
  69. #endregion
  70. private bool _EnableNextStep =false;
  71. public bool EnableNextStep
  72. {
  73. get { return _EnableNextStep; }
  74. set { SetProperty(ref _EnableNextStep, value);
  75. }
  76. }
  77. private string _codetime = " (60)";
  78. public string Codetime
  79. {
  80. get { return _codetime; }
  81. set { SetProperty(ref _codetime, value); }
  82. }
  83. private string _Codesum = "";
  84. public string Codesum
  85. {
  86. get { return _Codesum; }
  87. set { SetProperty(ref _Codesum, value); }
  88. }
  89. private string _Code1 = "";
  90. public string Code1
  91. {
  92. get { return _Code1; }
  93. set { SetProperty(ref _Code1, value);
  94. if (CodeSum())
  95. {
  96. Code6Changed();
  97. }
  98. }
  99. }
  100. private string _Code2 = "";
  101. public string Code2
  102. {
  103. get { return _Code2; }
  104. set { SetProperty(ref _Code2, value);
  105. if (CodeSum())
  106. {
  107. Code6Changed();
  108. }
  109. }
  110. }
  111. private string _Code3 = "";
  112. public string Code3
  113. {
  114. get { return _Code3; }
  115. set { SetProperty(ref _Code3, value);
  116. if (CodeSum())
  117. {
  118. Code6Changed();
  119. }
  120. }
  121. }
  122. private string _Code4 = "";
  123. public string Code4
  124. {
  125. get { return _Code4; }
  126. set { SetProperty(ref _Code4, value);
  127. if (CodeSum())
  128. {
  129. Code6Changed();
  130. }
  131. }
  132. }
  133. private string _Code5 = "";
  134. public string Code5
  135. {
  136. get { return _Code5; }
  137. set { SetProperty(ref _Code5, value);
  138. if (CodeSum())
  139. {
  140. Code6Changed();
  141. }
  142. }
  143. }
  144. private string _Code6 = "";
  145. public string Code6
  146. {
  147. get { return _Code6; }
  148. set { SetProperty(ref _Code6, value);}
  149. }
  150. private string _UserCodemsg = "";
  151. public string UserCodemsg
  152. {
  153. get { return _UserCodemsg; }
  154. set { SetProperty(ref _UserCodemsg, value); }
  155. }
  156. private Visibility _codeagin = Visibility.Collapsed;
  157. public Visibility Codeagin
  158. {
  159. get { return _codeagin; }
  160. set { SetProperty(ref _codeagin, value); }
  161. }
  162. private Visibility _UserCodemsgVis = Visibility.Collapsed;
  163. public Visibility UserCodemsgVis
  164. {
  165. get { return _UserCodemsgVis; }
  166. set { SetProperty(ref _UserCodemsgVis, value); }
  167. }
  168. public bool IsNavigationTarget(NavigationContext navigationContext)
  169. {
  170. return true;
  171. }
  172. public void OnNavigatedFrom(NavigationContext navigationContext)
  173. {
  174. }
  175. public void OnNavigatedTo(NavigationContext navigationContext)
  176. {
  177. navigationContext.Parameters.TryGetValue<UserDialogViewModel>("UserDialogViewModel", out UserDialogViewModel);
  178. }
  179. public DelegateCommand UserOutCancelCommand { get; set; }
  180. public DelegateCommand CodetooCommand { get; set; }
  181. public DelegateCommand Code6ChangedCommand { get; set; }
  182. public DelegateCommand UserOutCommand { get; set; }
  183. public UserOutCodeRegionViewModel(IRegionManager regionManager, IDialogService dialogService)
  184. {
  185. dialogs = dialogService;
  186. UserOutCancelCommand = new DelegateCommand(UserOutCancel);
  187. CodetooCommand = new DelegateCommand(Codetoo);
  188. Code6ChangedCommand = new DelegateCommand(Code6Changed);
  189. UserOutCommand = new DelegateCommand(UserOut);
  190. InitString();
  191. string code = ServiceHelper.Get_code("user_log_off", Settings.Default.UserDate.Email);
  192. if (code=="315")
  193. {
  194. Codeagin = Visibility.Visible;
  195. Codetime = " ";
  196. disTimer.Stop();
  197. UserCodemsg = ErrorCodeHelper.Ercode("codehad");
  198. UserCodemsgVis = Visibility.Visible;
  199. }
  200. else if (code == "200")
  201. {
  202. Codeagin = Visibility.Collapsed;
  203. Timebegin();
  204. }
  205. }
  206. private void UserOutCancel()
  207. {
  208. UserDialogViewModel.Close();
  209. }
  210. //注销
  211. private void UserOut()
  212. {
  213. Codesum = Code1 + Code2 + Code3 + Code4 + Code5 + Code6;
  214. if (CodeSum()==true)
  215. {
  216. string code = ServiceHelper.Usergout(Codesum);
  217. if (code == "200")
  218. {
  219. Settings.Default.AppProperties.LoginToken = "";
  220. App.IsLogin = false;
  221. Settings.Default.Save();
  222. App.mainWindowViewModel.UserVis = Visibility.Collapsed;
  223. App.mainWindowViewModel.RegisterVis = Visibility.Collapsed;
  224. App.mainWindowViewModel.LoginVis = Visibility.Visible;
  225. UserDialogViewModel.RegionMan("UserOutOKRegion");
  226. }
  227. else
  228. {
  229. EnableNextStep = false;
  230. UserCodemsg = ErrorCodeHelper.Ercode(code);
  231. UserCodemsgVis = Visibility.Visible;
  232. }
  233. }
  234. }
  235. //第六个密码框改变
  236. private void Code6Changed()
  237. {
  238. Codesum = Code1 + Code2 + Code3 + Code4 + Code5 + Code6;
  239. if (CodeSum() == true)
  240. {
  241. string code = ServiceHelper.Ok_code(UserDialogViewModel.UserEmail, Codesum, "user_log_off");
  242. if ( code== "200")
  243. {
  244. EnableNextStep = true;
  245. UserCodemsgVis = Visibility.Collapsed;
  246. }
  247. else
  248. {
  249. EnableNextStep = false;
  250. UserCodemsg = ErrorCodeHelper.Ercode(code);
  251. UserCodemsgVis = Visibility.Visible;
  252. }
  253. }
  254. else
  255. {
  256. EnableNextStep = false;
  257. }
  258. }
  259. private bool CodeSum()
  260. {
  261. Codesum = Code1 + Code2 + Code3 + Code4 + Code5 + Code6;
  262. if (Codesum.Length == 6)
  263. {
  264. return true;
  265. }
  266. else
  267. {
  268. return false;
  269. }
  270. }
  271. private void Codetoo()
  272. {
  273. string code = ServiceHelper.Get_code("user_log_off", Settings.Default.UserDate.Email);
  274. if (code == "315")
  275. {
  276. Codeagin = Visibility.Visible;
  277. Codetime = " ";
  278. disTimer.Stop();
  279. UserCodemsg = ErrorCodeHelper.Ercode("codehad");
  280. UserCodemsgVis = Visibility.Visible;
  281. }
  282. else if (code == "200")
  283. {
  284. Codeagin = Visibility.Collapsed;
  285. Timebegin();
  286. }
  287. }
  288. private DispatcherTimer disTimer = new DispatcherTimer();
  289. public void disTimer_Tick(object sender, EventArgs e)
  290. {
  291. if (time == 0)
  292. {
  293. Codeagin = Visibility.Visible;
  294. Codetime = " ";
  295. disTimer.Stop();
  296. }
  297. else
  298. {
  299. time--;
  300. Codetime = " (" + time.ToString() + ")";
  301. }
  302. }
  303. public void Timebegin()
  304. {
  305. time = 60;
  306. //设置定时器
  307. disTimer.Tick += new EventHandler(disTimer_Tick);//每一秒执行的方法
  308. disTimer.Interval = new TimeSpan(10000000); //时间间隔为一秒。
  309. disTimer.Start();//计时开始
  310. }
  311. }
  312. }