RegWind.xaml.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Shapes;
  14. namespace WindowedMyApp
  15. {
  16. /// <summary>
  17. /// Логика взаимодействия для RegWind.xaml
  18. /// </summary>
  19. public partial class RegWind : Window
  20. {
  21. public RegWind()
  22. {
  23. InitializeComponent();
  24. }
  25. private void Button_Click(object sender, RoutedEventArgs e)
  26. {
  27. using (ModelClass db = new ModelClass())
  28. {
  29. int HashPasswrd = surnameText.Password.GetHashCode();
  30. Klients klient = db.Klients
  31. .FirstOrDefault(x => x.Login == nameText.Text && x.Patronymic == PatronymText.Text && x.Password == HashPasswrd);
  32. if (klient == null)
  33. {
  34. Klients Newklient = new Klients() { Login = nameText.Text, Patronymic = PatronymText.Text, Password = HashPasswrd, ID_Group = 1};
  35. db.Klients.Add(Newklient);
  36. db.SaveChanges();
  37. MessageBox.Show("Вы успешно зарегестрировались");
  38. MainWindow wind = new MainWindow();
  39. wind.Show();
  40. Close();
  41. }
  42. else
  43. {
  44. MessageBox.Show("Такой пользователь уже существует");
  45. }
  46. }
  47. }
  48. private void toLoginButton_Click(object sender, RoutedEventArgs e)
  49. {
  50. MainWindow wind = new MainWindow();
  51. wind.Show();
  52. Close();
  53. }
  54. }
  55. }