RedactPhotoUser.xaml.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  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.Shapes;
  15. namespace SneakersSkakunov
  16. {
  17. /// <summary>
  18. /// Логика взаимодействия для RedactPhotoUser.xaml
  19. /// </summary>
  20. public partial class RedactPhotoUser : Window
  21. {
  22. public RedactPhotoUser()
  23. {
  24. InitializeComponent();
  25. }
  26. Sniker snk = new Sniker();
  27. Users user = new Users();
  28. List<PhotoUsers> Phs = new List<PhotoUsers>();
  29. int n = 0;
  30. int id;
  31. public RedactPhotoUser(int UsId)
  32. {
  33. InitializeComponent();
  34. user = snk.Users.Where(x => x.id_Users == UsId).FirstOrDefault();
  35. Phs = snk.PhotoUsers.Where(x => x.id_Users == UsId).ToList();
  36. byte[] bt = Phs[n].PhotoUser;
  37. ShowImage(bt, foto);
  38. id = user.id_Users;
  39. }
  40. private void BackPhoto(object sender, RoutedEventArgs e)
  41. {
  42. try
  43. {
  44. n--;
  45. byte[] bt = Phs[n].PhotoUser;
  46. ShowImage(bt, foto);
  47. }
  48. catch (ArgumentOutOfRangeException)
  49. {
  50. n = Phs.Count - 1;
  51. byte[] bt = Phs[n].PhotoUser;
  52. ShowImage(bt, foto);
  53. }
  54. }
  55. private void NextPhoto(object sender, RoutedEventArgs e)
  56. {
  57. try
  58. {
  59. n++;
  60. byte[] bt = Phs[n].PhotoUser;
  61. ShowImage(bt, foto);
  62. }
  63. catch (ArgumentOutOfRangeException)
  64. {
  65. n = 0;
  66. byte[] bt = Phs[n].PhotoUser;
  67. ShowImage(bt, foto);
  68. }
  69. }
  70. private void SelectThis(object sender, RoutedEventArgs e)
  71. {
  72. user.id_photouser = Phs[n].id_photouser;
  73. snk.SaveChanges();
  74. MessageBox.Show("Фото обновлено");
  75. MainFrame.mframe.Navigate(new UserPage(user.id_Users));
  76. }
  77. private void Back(object sender, RoutedEventArgs e)
  78. {
  79. this.Close();
  80. }
  81. void ShowImage(byte[] arr, System.Windows.Controls.Image img)
  82. {
  83. BitmapImage BI = new BitmapImage();
  84. BI.BeginInit();
  85. BI.StreamSource = new MemoryStream(arr);
  86. BI.EndInit();
  87. img.Source = BI;
  88. }
  89. }
  90. }