using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace SneakersSkakunov
{
///
/// Логика взаимодействия для RedactPhotoUser.xaml
///
public partial class RedactPhotoUser : Window
{
public RedactPhotoUser()
{
InitializeComponent();
}
Sniker snk = new Sniker();
Users user = new Users();
List Phs = new List();
int n = 0;
int id;
public RedactPhotoUser(int UsId)
{
InitializeComponent();
user = snk.Users.Where(x => x.id_Users == UsId).FirstOrDefault();
Phs = snk.PhotoUsers.Where(x => x.id_Users == UsId).ToList();
byte[] bt = Phs[n].PhotoUser;
ShowImage(bt, foto);
id = user.id_Users;
}
private void BackPhoto(object sender, RoutedEventArgs e)
{
try
{
n--;
byte[] bt = Phs[n].PhotoUser;
ShowImage(bt, foto);
}
catch (ArgumentOutOfRangeException)
{
n = Phs.Count - 1;
byte[] bt = Phs[n].PhotoUser;
ShowImage(bt, foto);
}
}
private void NextPhoto(object sender, RoutedEventArgs e)
{
try
{
n++;
byte[] bt = Phs[n].PhotoUser;
ShowImage(bt, foto);
}
catch (ArgumentOutOfRangeException)
{
n = 0;
byte[] bt = Phs[n].PhotoUser;
ShowImage(bt, foto);
}
}
private void SelectThis(object sender, RoutedEventArgs e)
{
user.id_photouser = Phs[n].id_photouser;
snk.SaveChanges();
MessageBox.Show("Фото обновлено");
MainFrame.mframe.Navigate(new UserPage(user.id_Users));
}
private void Back(object sender, RoutedEventArgs e)
{
this.Close();
}
void ShowImage(byte[] arr, System.Windows.Controls.Image img)
{
BitmapImage BI = new BitmapImage();
BI.BeginInit();
BI.StreamSource = new MemoryStream(arr);
BI.EndInit();
img.Source = BI;
}
}
}