MainWindowViewModel.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. using Avalonia.Controls;
  2. using Avalonia.Threading;
  3. using AvaloniaApplication4.Models;
  4. using ReactiveUI;
  5. using System;
  6. namespace AvaloniaApplication4.ViewModels
  7. {
  8. public class MainWindowViewModel : ViewModelBase
  9. {
  10. UserControl _us = new Page1();
  11. public UserControl Us
  12. {
  13. get => _us;
  14. set => this.RaiseAndSetIfChanged(ref _us, value);
  15. }
  16. Page1ViewModel _page1VM = new Page1ViewModel();
  17. public Page1ViewModel Page1VM
  18. {
  19. get => _page1VM;
  20. set => _page1VM = value;
  21. }
  22. Page2ViewModel page2VM = new Page2ViewModel();
  23. public Page2ViewModel Page2VM
  24. {
  25. get => page2VM;
  26. set => page2VM = value;
  27. }
  28. public void ToPage2()
  29. {
  30. Us = new Page2();
  31. }
  32. public void ToPage1()
  33. {
  34. Us = new Page1();
  35. }
  36. public void proverka()
  37. {
  38. if (Page1VM.loginn == Model.login && Page1VM.pass == Model.parol)
  39. {
  40. Page1VM.Res = "Верный логин и пароль";
  41. Us = new Page2();
  42. }
  43. else if (Page1VM.loginn != Model.login || Page1VM.pass != Model.parol)
  44. {
  45. Page1VM.Res = "Неверный логин или пароль";
  46. Page1VM.IsButtonVisible = false;
  47. Page1VM.IsButtonVisible1 = true;
  48. Page1VM.IsButtonVisible2 = true;
  49. Page1VM.IsTBvis = true;
  50. Page1VM.CreateCaptha();
  51. Page1VM.count++;
  52. }
  53. }
  54. public void CheckCaptcha()
  55. {
  56. if (Page1VM.count != 2)
  57. {
  58. if (Page1VM.loginn == Model.login && Page1VM.pass == Model.parol)
  59. {
  60. string captchaText = new string(Page1VM.stringChars);
  61. if (Page1VM.enteredtext.ToLower() == captchaText.ToLower())
  62. {
  63. Page1VM.Res = "Верный логин и пароль";
  64. Page1VM.Res1 = "Верный код капчи";
  65. Us = new Page2();
  66. }
  67. else
  68. {
  69. Page1VM.Res1 = "Неверный код капчи";
  70. Page1VM.count++;
  71. Page1VM.CreateCaptha();
  72. }
  73. }
  74. else
  75. {
  76. Page1VM.Res = "Неверный логин или пароль";
  77. Page1VM.CreateCaptha();
  78. Page1VM.count++;
  79. }
  80. }
  81. else
  82. {
  83. Page1VM.Enabled = false;
  84. Page1VM.IsButtonVisible1 = false;
  85. Page1VM.IsButtonVisible2 = false;
  86. Page1VM.IsTBvis = false;
  87. DispatcherTimer timer = new DispatcherTimer();
  88. timer.Interval = new TimeSpan(0, 0, 10);
  89. timer.Tick += (sender, e) =>
  90. {
  91. Page1VM.IsButtonVisible1 = true;
  92. Page1VM.IsButtonVisible2 = true;
  93. Page1VM.IsTBvis = true;
  94. Page1VM.Enabled = true;
  95. Page1VM.Login = "";
  96. Page1VM.Password = 0;
  97. Page1VM.Enteredt = "";
  98. Page1VM.count = 0;
  99. Page1VM.CreateCaptha();
  100. timer.Stop();
  101. };
  102. timer.Start();
  103. }
  104. }
  105. }
  106. }