UserInfo.xaml.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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.Navigation;
  14. using System.Windows.Shapes;
  15. namespace WPF01.pages
  16. {
  17. using db;
  18. /// <summary>
  19. /// Логика взаимодействия для UserInfo.xaml
  20. /// </summary>
  21. public partial class UserInfo : Page
  22. {
  23. public UserInfo()
  24. {
  25. InitializeComponent();
  26. }
  27. private void Button_Click(object sender, RoutedEventArgs e)
  28. {
  29. Database.User.Phone = phoneTextBox.Text;
  30. Database.User.FirstName = fistnameTextBox.Text;
  31. Database.User.SecondName = lastnameTextBox.Text;
  32. Database.User.Patronymic = patronymicTextBox.Text;
  33. if (
  34. passwordBox.Password.Length != 0 &&
  35. passwordBox.Password.Length > 3 &&
  36. passwordBox.Password.Length < 11
  37. )
  38. {
  39. Database.User.Password = passwordBox.Password;
  40. }
  41. int result = Database.Context.SaveChanges();
  42. if (result > 0)
  43. {
  44. MessageBox.Show("Данные успешно изменены", "Информация", MessageBoxButton.OK, MessageBoxImage.Information);
  45. }
  46. }
  47. private void Page_Loaded(object sender, RoutedEventArgs e)
  48. {
  49. if (Database.User != null)
  50. {
  51. loginLabel.Content = Database.User.Login;
  52. phoneTextBox.Text = Database.User.Phone;
  53. fistnameTextBox.Text = Database.User.FirstName;
  54. lastnameTextBox.Text = Database.User.SecondName;
  55. patronymicTextBox.Text = Database.User.Patronymic;
  56. }
  57. }
  58. }
  59. }