Profile.xaml.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using PP_Ven_MosS.ModelBase;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  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 PP_Ven_MosS.Classes;
  17. using System.Data.Entity;
  18. namespace PP_Ven_MosS.Pages
  19. {
  20. /// <summary>
  21. /// Логика взаимодействия для Profile.xaml
  22. /// </summary>
  23. public partial class Profile : Page
  24. {
  25. public User buffer;
  26. public User changeuser;
  27. User user = new User();
  28. Users users = new Users();
  29. public Profile(User ID_User)
  30. {
  31. InitializeComponent();
  32. DataContext = ID_User;
  33. buffer = ID_User;
  34. changeuser = ID_User;
  35. User user = Classes.Database.entities.User.FirstOrDefault(x => x.Id_user == UserID.userid);
  36. txtSurn.Text = user.Surname;
  37. txtName.Text = user.Name;
  38. txtPatron.Text = user.Patronymic;
  39. txtPost.Text = user.Post;
  40. txtPhone.Text = user.Phone_number;
  41. txtLog.Text = user.Login;
  42. txtApp.Text = user.Count_complete_app.ToString();
  43. txtEvent.Text = user.Count_complete_event.ToString();
  44. if (UserRole.userrole == 2)
  45. {
  46. GBApp.Visibility = Visibility.Visible;
  47. GBEvent.Visibility = Visibility.Visible;
  48. }
  49. }
  50. // Кнопка сохранения изменений профиля
  51. private void Save_Click(object sender, RoutedEventArgs e)
  52. {
  53. PP_MininEntities2 DB = new PP_MininEntities2();
  54. User user = DB.User.FirstOrDefault(x => x.Id_user == UserID.userid);
  55. user.Surname = txtSurn.Text;
  56. user.Name = txtName.Text;
  57. user.Patronymic = txtPatron.Text;
  58. user.Post = txtPost.Text;
  59. user.Phone_number = txtPhone.Text;
  60. user.Login = txtLog.Text;
  61. if(txtPass.Text != null)
  62. {
  63. user.Password = txtPass.Text.GetHashCode().ToString();
  64. }
  65. DB.SaveChanges();
  66. MessageBox.Show("Изменения сохранены");
  67. }
  68. private void Exit_Click(object sender, RoutedEventArgs e)
  69. {
  70. if (UserRole.userrole == 1)
  71. {
  72. FrameClass.MainFrame.Navigate(new MenuAdmin());
  73. }
  74. else if (UserRole.userrole == 2)
  75. {
  76. FrameClass.MainFrame.Navigate(new ApplicationsListAdmin());
  77. }
  78. else
  79. {
  80. FrameClass.MainFrame.Navigate(new ApplicationsListUser());
  81. }
  82. }
  83. }
  84. }