MainWindowViewModel.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using Avalonia.Controls;
  2. using AuthAndCaptcha.Models;
  3. using Avalonia.Interactivity;
  4. using ReactiveUI;
  5. using System;
  6. using Avalonia.Media;
  7. using Avalonia.Controls.Shapes;
  8. using System.Runtime.Intrinsics.Arm;
  9. using Avalonia.Threading;
  10. namespace AuthAndCaptcha.ViewModels
  11. {
  12. public class MainWindowViewModel : ViewModelBase
  13. {
  14. UserControl uc = new Auth();
  15. public UserControl Uc { get => uc; set => this.RaiseAndSetIfChanged(ref uc, value); }
  16. AuthViewModel authVM = new AuthViewModel();
  17. public AuthViewModel AuthVM { get => authVM; set => authVM = value; }
  18. CalculatorViewModel calculatorVM = new CalculatorViewModel();
  19. public CalculatorViewModel CalculatorVM { get => calculatorVM; set => calculatorVM = value; }
  20. DispatcherTimer timer = new DispatcherTimer();
  21. private void TimerTick(object sender, EventArgs e)
  22. {
  23. AuthVM.CanTextTrue = "";
  24. AuthVM.CreateCaptcha();
  25. AuthVM.CanTextVisible = true;
  26. timer.Stop();
  27. }
  28. public void toPageCalc()
  29. {
  30. Uc = new Calculator();
  31. }
  32. public void Check()
  33. {
  34. if (AuthVM.UsersLogin == AuthClass.login && AuthVM.UsersPassword == AuthClass.password)
  35. {
  36. toPageCalc();
  37. }
  38. else
  39. {
  40. AuthVM.UsersLogin = "";
  41. AuthVM.UsersPassword = "";
  42. AuthVM.AuthButtonVisible = false;
  43. AuthVM.CanTextVisible = true;
  44. AuthVM.CreateCaptcha();
  45. }
  46. }
  47. public void CheckCaptcha()
  48. {
  49. if (AuthVM.UsersLogin == AuthClass.login && AuthVM.UsersPassword == AuthClass.password && AuthVM.CanText==AuthVM.CanTextTrue)
  50. {
  51. toPageCalc();
  52. }
  53. else
  54. {
  55. AuthVM.UsersLogin = "";
  56. AuthVM.UsersPassword = "";
  57. AuthVM.CanText = "";
  58. AuthVM.CanTextVisible = false;
  59. timer.Interval = new TimeSpan(0, 0, 10);
  60. timer.Tick += new EventHandler(TimerTick);
  61. timer.Start();
  62. }
  63. }
  64. }
  65. }