using System;
using System.Collections.Generic;
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.Navigation;
using System.Windows.Shapes;
namespace SneakersSkakunov
{
///
/// Логика взаимодействия для Sneaker.xaml
///
public partial class Sneaker : Page
{
int id;
private void Revert(object sender, RoutedEventArgs e)
{
MainFrame.mframe.Navigate(new AdminPage(id));
}
private void Addendum(object sender, RoutedEventArgs e)
{
MainFrame.mframe.Navigate(new Add());
}
public Sneaker()
{
InitializeComponent();
Sniker DB = new Sniker();
SneakerList.ItemsSource = DB.Sneakers.ToList();
List s = new List() { "Без фильтров", "По цене" };
List brd = DB.Brand.ToList();
brnds.Items.Add("Все бренды");
foreach (Brand i in brd)
{
brnds.Items.Add(i.Label);
}
RBNow.ItemsSource = s;
RBNow.SelectedItem = "Без фильтров";
brnds.SelectedIndex = 0;
}
public void brands(object sender, RoutedEventArgs e)
{
TextBlock brand = (TextBlock)sender;
int index = Convert.ToInt32(brand.Uid);
Sniker DB = new Sniker();
string a = DB.Brand.Where(x => x.id_Brand == index).Select(x => x.Label).First();
brand.Text = "Брэнд: " + a;
}
//public void models(object sender, RoutedEventArgs e)
//{
// TextBlock model = (TextBlock)sender;
// int index = Convert.ToInt32(model.Uid);
// Sniker DB = new Sniker();
// string b = DB.Model.Where(x => x.id_model == index).Select(x => x.Model1 + " ").First();
// model.Text = "Модель: " + b;
//}
public void Colors(object sender, RoutedEventArgs e)
{
TextBlock color = (TextBlock)sender;
int index = Convert.ToInt32(color.Uid);
Sniker DB = new Sniker();
string c = DB.Sneakers.Where(x => x.id_Sneakers == index).Select(x => x.Colors + " ").First();
color.Text = "Цвет: " + c;
}
public void prices(object sender, RoutedEventArgs e)
{
TextBlock price = (TextBlock)sender;
int index = Convert.ToInt32(price.Uid);
Sniker DB = new Sniker();
string d = DB.Sneakers.Where(x => x.id_Sneakers == index).Select(x => x.Price + " ").First().ToString();
price.Text = "Цена: " + d + "р.";
}
//public void Date(object sender, RoutedEventArgs e)
//{
// TextBlock data = (TextBlock)sender;
// int index = Convert.ToInt32(data.Uid);
// Sniker DB = new Sniker();
// string d = DB.Cheque.Where(x => x.id_Cheque == index).Select(x => x.Date_of_formation + " ").First().ToString();
// data.Text = "Дата: " + d;
//}
public void Sizes(object sender, RoutedEventArgs e)
{
TextBlock size = (TextBlock)sender;
int index = Convert.ToInt32(size.Uid);
Sniker DB = new Sniker();
string c = DB.Sneakers.Where(x => x.id_Sneakers == index).Select(x => x.Size + " ").First();
size.Text = "Размер: " + c;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Button tb = (Button)sender;
int index = Convert.ToInt32(tb.Uid);
Sniker DB = new Sniker();
MainFrame.mframe.Navigate(new Add());
}
private void Delete(object sender, RoutedEventArgs e)
{
Button tb = (Button)sender;
int index = Convert.ToInt32(tb.Uid);
Sniker DB = new Sniker();
Sneakers SneakerRemove = DB.Sneakers.FirstOrDefault(x => x.id_Sneakers == index);
switch (MessageBox.Show("Удалить Кроссовки?", "SneakerInsurance", MessageBoxButton.YesNo, MessageBoxImage.Question))
{
case MessageBoxResult.Yes:
DB.Sneakers.Remove(SneakerRemove);
MessageBox.Show("Кроссовки были удалены");
DB.SaveChanges();
MainFrame.mframe.Navigate(new Sneaker());
break;
case MessageBoxResult.No:
MessageBox.Show("Кроссовки не были удалены");
break;
}
}
public void Filter()
{
Sniker DB = new Sniker();
List snkFilter = new List();
if (brnds.SelectedIndex != 0)
{
List br = DB.Brand.ToList();
int index = Convert.ToInt32(br.Where(x => x.id_Brand == brnds.SelectedIndex).Select(x => x.id_Brand).FirstOrDefault());
snkFilter = DB.Sneakers.Where(x => x.id_Brand == index).ToList();
}
else
{
snkFilter = DB.Sneakers.ToList();
}
if (!string.IsNullOrWhiteSpace(Clr.Text))
{
snkFilter = snkFilter.Where(x => x.Colors.ToString().Contains(Clr.Text.ToString())).ToList();
}
if (RBNow.SelectedItem.ToString() == "По цене" && RBUp.IsChecked == true)
{
snkFilter = snkFilter.OrderBy(x => x.Price).ToList();
}
if (RBNow.SelectedItem.ToString() == "По цене" && RBDown.IsChecked == true)
{
snkFilter = snkFilter.OrderByDescending(x => x.Price).ToList();
}
SneakerList.ItemsSource = snkFilter;
}
private void TBSearch_TextChanged(object sender, TextChangedEventArgs e)
{
Filter();
}
private void CBFilterBreed_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Filter();
}
private void CBOnly_Checked(object sender, RoutedEventArgs e)
{
Filter();
}
private void CBOnly_Unchecked(object sender, RoutedEventArgs e)
{
Filter();
}
private void RBUp_Checked(object sender, RoutedEventArgs e)
{
Filter();
}
private void SortChanged(object sender, SelectionChangedEventArgs e)
{
Filter();
}
}
}