Profile.xaml.cs 2.9 KB

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