LoginPage.xaml.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.Linq;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. using System.Windows.Navigation;
  6. namespace MyTests.Pages
  7. {
  8. public partial class LoginPage : Page
  9. {
  10. bool Test = true;
  11. public LoginPage()
  12. {
  13. InitializeComponent();
  14. }
  15. private void RegButton_Click(object sender, RoutedEventArgs e)
  16. {
  17. NavigationService.Navigate(new Pages.RegistrationPage());
  18. }
  19. private void LogButton_Click(object sender, RoutedEventArgs e)
  20. {
  21. if (Test)
  22. {
  23. Session.User = cnt.db.Users.Where(item => item.IdUser == 1).FirstOrDefault();
  24. NavigationService.Navigate(new Pages.MainPage());
  25. }
  26. else
  27. {
  28. try
  29. {
  30. if (!Functions.IsValidLogAndPass(LogBox.Text, PassBox.Password))
  31. new ErrorWindow("Поля не могут быть пустыми").Show();
  32. else if (!Functions.LoginCheck(LogBox.Text, PassBox.Password))
  33. new ErrorWindow("Неверный логин или пароль").Show();
  34. else
  35. {
  36. //Profile.userId = cnt.db.User.Where(item => item.NickName == LogBox.Text).Select(item => item.Id).FirstOrDefault();
  37. NavigationService.Navigate(new Pages.MainPage());
  38. }
  39. }
  40. catch
  41. {
  42. new ErrorWindow("Ошибка входа").ShowDialog();
  43. }
  44. }
  45. }
  46. }
  47. }