using Avalonia.Controls; using AuthAndCaptcha.Models; using Avalonia.Interactivity; using ReactiveUI; using System; using Avalonia.Media; using Avalonia.Controls.Shapes; using System.Runtime.Intrinsics.Arm; using Avalonia.Threading; namespace AuthAndCaptcha.ViewModels { public class MainWindowViewModel : ViewModelBase { UserControl uc = new Auth(); public UserControl Uc { get => uc; set => this.RaiseAndSetIfChanged(ref uc, value); } AuthViewModel authVM = new AuthViewModel(); public AuthViewModel AuthVM { get => authVM; set => authVM = value; } CalculatorViewModel calculatorVM = new CalculatorViewModel(); public CalculatorViewModel CalculatorVM { get => calculatorVM; set => calculatorVM = value; } DispatcherTimer timer = new DispatcherTimer(); private void TimerTick(object sender, EventArgs e) { AuthVM.CanTextTrue = ""; AuthVM.CreateCaptcha(); AuthVM.CanTextVisible = true; timer.Stop(); } public void toPageCalc() { Uc = new Calculator(); } public void Check() { if (AuthVM.UsersLogin == AuthClass.login && AuthVM.UsersPassword == AuthClass.password) { toPageCalc(); } else { AuthVM.UsersLogin = ""; AuthVM.UsersPassword = ""; AuthVM.AuthButtonVisible = false; AuthVM.CanTextVisible = true; AuthVM.CreateCaptcha(); } } public void CheckCaptcha() { if (AuthVM.UsersLogin == AuthClass.login && AuthVM.UsersPassword == AuthClass.password && AuthVM.CanText==AuthVM.CanTextTrue) { toPageCalc(); } else { AuthVM.UsersLogin = ""; AuthVM.UsersPassword = ""; AuthVM.CanText = ""; AuthVM.CanTextVisible = false; timer.Interval = new TimeSpan(0, 0, 10); timer.Tick += new EventHandler(TimerTick); timer.Start(); } } } }