123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- 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
- {
- /// <summary>
- /// Логика взаимодействия для Sneaker.xaml
- /// </summary>
- 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<string> s = new List<string>() { "Без фильтров", "По цене" };
- List<Brand> 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<Sneakers> snkFilter = new List<Sneakers>();
- if (brnds.SelectedIndex != 0)
- {
- List<Brand> 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();
- }
- }
- }
|