UserPage.xaml.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using Microsoft.Win32;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Navigation;
  16. using System.Windows.Shapes;
  17. namespace SneakersSkakunov
  18. {
  19. /// <summary>
  20. /// Логика взаимодействия для UserPage.xaml
  21. /// </summary>
  22. public partial class UserPage : Page
  23. {
  24. Users user = new Users();
  25. Sniker snk = new Sniker();
  26. public UserPage(int UsId)
  27. {
  28. InitializeComponent();
  29. user = snk.Users.Where(x => x.id_Users == UsId).FirstOrDefault();
  30. imya.Text = user.Name;
  31. fam.Text = user.Surname;
  32. otch.Text = user.Patronymic;
  33. if (user.id_Gender == 1)
  34. {
  35. pol.Text = "Мужской";
  36. }
  37. else
  38. {
  39. pol.Text = "Женский";
  40. }
  41. string bd = user.DateBirth.ToString();
  42. BirthDate.Text = DateTime.Parse(bd).ToShortDateString();
  43. lg.Text = user.Login;
  44. pss.Text = "Надежный";
  45. PhotoUsers ph = snk.PhotoUsers.Where(x => x.id_photouser == user.id_photouser).FirstOrDefault();
  46. if (ph != null)
  47. {
  48. byte[] bt = ph.PhotoUser;
  49. ShowImage(bt, foto);
  50. }
  51. }
  52. void ShowImage(byte[] arr, System.Windows.Controls.Image img)
  53. {
  54. BitmapImage BI = new BitmapImage();
  55. BI.BeginInit();
  56. BI.StreamSource = new MemoryStream(arr);
  57. BI.EndInit();
  58. img.Source = BI;
  59. }
  60. private void RedUserInfo(object sender, RoutedEventArgs e)
  61. {
  62. Redact wns = new Redact(user.id_Users);
  63. wns.ShowDialog();
  64. MainFrame.mframe.Navigate(new UserPage(user.id_Users));
  65. }
  66. private void RedAuthInfo(object sender, RoutedEventArgs e)
  67. {
  68. RedactAuth wns = new RedactAuth(user.id_Users);
  69. wns.ShowDialog();
  70. MainFrame.mframe.Navigate(new UserPage(user.id_Users));
  71. }
  72. private void SelectPh(object sender, RoutedEventArgs e)
  73. {
  74. RedactPhotoUser wns = new RedactPhotoUser(user.id_Users);
  75. wns.ShowDialog();
  76. MainFrame.mframe.Navigate(new UserPage(user.id_Users));
  77. }
  78. private void UploadPhoto(object sender, RoutedEventArgs e)
  79. {
  80. try
  81. {
  82. OpenFileDialog FileDialog = new OpenFileDialog();
  83. FileDialog.ShowDialog();
  84. PhotoUsers UpPh = new PhotoUsers();
  85. UpPh.id_Users = user.id_Users;
  86. UpPh.PhotoUser = File.ReadAllBytes(FileDialog.FileName);
  87. snk.PhotoUsers.Add(UpPh);
  88. snk.SaveChanges();
  89. user.id_photouser = UpPh.id_photouser;
  90. snk.SaveChanges();
  91. MessageBox.Show("Ваше фото добавлено");
  92. MainFrame.mframe.Navigate(new UserPage(user.id_Users));
  93. }
  94. catch
  95. {
  96. MessageBox.Show("К сожалению ваше фото не добавлено, попробуйте снова!");
  97. }
  98. }
  99. private void UploadPhotos(object sender, RoutedEventArgs e)
  100. {
  101. OpenFileDialog FileDialog = new OpenFileDialog();
  102. FileDialog.Multiselect = true;
  103. if (FileDialog.ShowDialog() == true)
  104. {
  105. foreach (string file in FileDialog.FileNames)
  106. {
  107. PhotoUsers UsPh = new PhotoUsers();
  108. UsPh.id_Users = user.id_Users;
  109. UsPh.PhotoUser = File.ReadAllBytes(file);
  110. snk.PhotoUsers.Add(UsPh);
  111. }
  112. }
  113. snk.SaveChanges();
  114. MessageBox.Show("Ваши фото добавлены");
  115. }
  116. }
  117. }