UserPage.xaml.cs 4.0 KB

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