HelpQustionWindow.xaml.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 Hotel_Course_Project
  15. {
  16. /// <summary>
  17. /// Логика взаимодействия для HelpQustionWindow.xaml
  18. /// </summary>
  19. public partial class HelpQustionWindow : Window
  20. {
  21. public Staff _user;
  22. public HelpQustionWindow(Staff user)
  23. {
  24. InitializeComponent();
  25. _user = user;
  26. TypeQuestionCB.ItemsSource = DataBase.db.HelpQuestion.ToList();
  27. if (user.Id_HelpQuestion != null)
  28. {
  29. TypeQuestionCB.Text = user.ToString();
  30. TypeQuestionCB.IsEditable = false;
  31. }
  32. else
  33. {
  34. TypeQuestionCB.IsEditable = true;
  35. }
  36. }
  37. private void CancelBtn_Click(object sender, RoutedEventArgs e)
  38. {
  39. DialogResult = false;
  40. }
  41. private void AcceptBtn_Click(object sender, RoutedEventArgs e)
  42. {
  43. if(TypeQuestionCB.SelectedItem == null)
  44. {
  45. MessageBox.Show("Выберите вопрос");
  46. }
  47. else if(AnswerTB.Text == "" || AnswerTB.Text == string.Empty)
  48. {
  49. MessageBox.Show("Поле с ответом -- пустое");
  50. }
  51. else
  52. {
  53. int numQuestion = DataBase.db.HelpQuestion.SingleOrDefault(x => x.Name == TypeQuestionCB.Text).id;
  54. if (_user.Id_HelpQuestion == null)
  55. {
  56. _user.Id_HelpQuestion = numQuestion;
  57. _user.AnswerOnHelpQuestion = AnswerTB.Text;
  58. MessageBox.Show("Способ восстановления пароля добавлен");
  59. DialogResult = true;
  60. }
  61. else
  62. {
  63. if (_user.Id_HelpQuestion != numQuestion || (_user.Id_HelpQuestion == numQuestion && _user.AnswerOnHelpQuestion != AnswerTB.Text))
  64. {
  65. MessageBox.Show("Ошибка при восстановлении пароля");
  66. AnswerTB.Text = "";
  67. }
  68. else
  69. {
  70. MessageBox.Show("Пароль сброшен!\nНовый пароль: 123");
  71. _user.Password = SomeMethods.Hash("123");
  72. DataBase.db.SaveChanges();
  73. DialogResult = true;
  74. }
  75. }
  76. }
  77. }
  78. }
  79. }