Regestration.xaml.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16. using TeaTime;
  17. namespace teaTime
  18. {
  19. /// <summary>
  20. /// Логика взаимодействия для Regestration.xaml
  21. /// </summary>
  22. public partial class Regestration : Page
  23. {
  24. public Regestration()
  25. {
  26. InitializeComponent();
  27. }
  28. public bool check()
  29. {
  30. try
  31. {
  32. Regex checkName = new Regex(@"^[А-я ,.'-]+$");
  33. Regex checkEmail = new Regex(@"^\S+@\S+\.\S+$");
  34. Regex checkNumberPhone = new Regex("^((\\+?7|8))\\d{10}$");
  35. bool flag = true;
  36. if (checkName.IsMatch(aSurname.Text))
  37. {
  38. eSurname.Visibility = Visibility.Hidden;
  39. }
  40. else
  41. {
  42. eSurname.Visibility = Visibility.Visible;
  43. flag = false;
  44. }
  45. if (checkName.IsMatch(aName.Text))
  46. {
  47. eName.Visibility = Visibility.Hidden;
  48. }
  49. else
  50. {
  51. eName.Visibility = Visibility.Visible;
  52. flag = false;
  53. }
  54. if (checkName.IsMatch(aMiddleName.Text))
  55. {
  56. eMiddleName.Visibility = Visibility.Hidden;
  57. }
  58. else
  59. {
  60. eMiddleName.Visibility = Visibility.Visible;
  61. flag = false;
  62. }
  63. if (checkEmail.IsMatch(aEmail.Text))
  64. {
  65. eEmail.Visibility = Visibility.Hidden;
  66. }
  67. else
  68. {
  69. eEmail.Visibility = Visibility.Visible;
  70. flag = false;
  71. }
  72. if (checkNumberPhone.IsMatch(aPhoneNum.Text))
  73. {
  74. ePhoneNumber.Visibility = Visibility.Hidden;
  75. }
  76. else
  77. {
  78. ePhoneNumber.Visibility = Visibility.Visible;
  79. flag = false;
  80. }
  81. if (aPass.Password == arePass.Password && aPass.Password != "")
  82. {
  83. ePass.Visibility = Visibility.Hidden;
  84. }
  85. else
  86. {
  87. ePass.Visibility = Visibility.Visible;
  88. flag = false;
  89. }
  90. return flag;
  91. }
  92. catch (Exception ex)
  93. {
  94. MessageBox.Show(ex.Message);
  95. return false;
  96. }
  97. }
  98. private void bReg_Click(object sender, RoutedEventArgs e)
  99. {
  100. //код
  101. if (check())
  102. {
  103. try
  104. {
  105. List<Member> List = DataBaseConnect.DataBase.Member.ToList();
  106. var lastItem = List.Last();
  107. Member newUser = new Member()
  108. {
  109. surname = aSurname.Text,
  110. name = aName.Text,
  111. middleName = aMiddleName.Text,
  112. phone = aPhoneNum.Text,
  113. email = aEmail.Text,
  114. login = aLogin.Text,
  115. password = aPass.Password
  116. };
  117. DataBaseConnect.DataBase.Member.Add(newUser);
  118. DataBaseConnect.DataBase.SaveChanges();
  119. DataBaseConnect.DataBase = new KotkovaISazonovaEntities_();
  120. NavigationService.Navigate(new Authorization());
  121. }
  122. catch
  123. {
  124. MessageBox.Show("При регистрации возникли технические неполадки попробуйте еще раз");
  125. }
  126. }
  127. else
  128. {
  129. MessageBox.Show("При регистрации возникли ошибки!\nПожалуйста перепроверьте введенные Вами данные или обратитесь к подсказкам справа.");
  130. }
  131. }
  132. private void bClose_Click(object sender, RoutedEventArgs e)
  133. {
  134. NavigationService.Navigate(new Authorization());
  135. }
  136. }
  137. }