Page3.xaml.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 SSS
  18. {
  19. /// <summary>
  20. /// Логика взаимодействия для Page3.xaml
  21. /// </summary>
  22. public partial class Page3 : Page
  23. {
  24. Client user = new Client();
  25. Entities ent = new Entities();
  26. public Page3(int UsId)
  27. {
  28. InitializeComponent();
  29. user = ent.Client.Where(x => x.id_Client == UsId).FirstOrDefault();
  30. Nam.Text = user.Name;
  31. Fam.Text = user.Surname;
  32. Patr.Text = user.Patronymic;
  33. if (user.id_Gender == 1)
  34. {
  35. Gen.Text = "Мужской";
  36. }
  37. else
  38. {
  39. Gen.Text = "Женский";
  40. }
  41. string bd = user.BirthDate.ToString();
  42. DateBirth.Text = DateTime.Parse(bd).ToShortDateString();
  43. Log.Text = user.Login;
  44. Pass.Text = "сложный";
  45. Photos ph = ent.Photos.Where(x => x.id_photo == user.id_photo).FirstOrDefault();
  46. if (ph != null)
  47. {
  48. byte[] bt = ph.Photo;
  49. ShowImage(bt, imUser);
  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. Izmen wns = new Izmen(user.id_Client);
  63. wns.ShowDialog();
  64. ClassF.Mfrm.Navigate(new Page3(user.id_Client));
  65. }
  66. private void RedAuthInfo(object sender, RoutedEventArgs e)
  67. {
  68. IzmenPar wns = new IzmenPar(user.id_Client);
  69. wns.ShowDialog();
  70. ClassF.Mfrm.Navigate(new Page3(user.id_Client));
  71. }
  72. private void SelectPh(object sender, RoutedEventArgs e)
  73. {
  74. redphoto wns = new redphoto(user.id_Client);
  75. wns.ShowDialog();
  76. ClassF.Mfrm.Navigate(new Page3(user.id_Client));
  77. }
  78. private void UploadPhoto(object sender, RoutedEventArgs e)
  79. {
  80. try
  81. {
  82. OpenFileDialog FileDialog = new OpenFileDialog();
  83. FileDialog.ShowDialog();
  84. Photos UpPh = new Photos();
  85. UpPh.id_Client = user.id_Client;
  86. UpPh.Photo = File.ReadAllBytes(FileDialog.FileName);
  87. ent.Photos.Add(UpPh);
  88. ent.SaveChanges();
  89. user.id_photo = UpPh.id_photo;
  90. ent.SaveChanges();
  91. MessageBox.Show("Изображение загружено");
  92. ClassF.Mfrm.Navigate(new Page3(user.id_Client));
  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. Photos UsPh = new Photos();
  108. UsPh.id_Client = user.id_Client;
  109. UsPh.Photo = File.ReadAllBytes(file);
  110. ent.Photos.Add(UsPh);
  111. }
  112. }
  113. ent.SaveChanges();
  114. MessageBox.Show("Фотографии загружены");
  115. }
  116. }
  117. }