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; using Write_erase.Classes; namespace Write_erase.ManagerPages { /// /// Логика взаимодействия для ShowProductPage.xaml /// public partial class ShowProductPage : Page { List products = DataBaseClass.entity.Product.ToList(); public ShowProductPage(int id) { InitializeComponent(); List users = DataBaseClass.entity.User.Where(x => x.UserID == id).ToList(); foreach (User user in users) { FIO.Text = user.UserPatronymic + " " + user.UserName + " " + user.UserSurname; } ProductPanelUser.ItemsSource = DataBaseClass.entity.Product.ToList(); CBDiscount.Items.Add("Все диапазоны"); CBDiscount.Items.Add("0-9,99%"); CBDiscount.Items.Add("10-14,99%"); CBDiscount.Items.Add("15% и более"); CBDiscount.SelectedIndex = 0; TBShowAll.Text = "Всего товаров: " + DataBaseClass.entity.Product.ToList().Count; } private void Filter() { switch (CBDiscount.SelectedIndex) { case 0: products = DataBaseClass.entity.Product.ToList(); break; case 1: products = DataBaseClass.entity.Product.Where(x => x.ProductDiscountAmount / 100 < 0.0999).ToList(); break; case 2: products = DataBaseClass.entity.Product.Where(x => x.ProductDiscountAmount / 100 >= 10 && x.ProductDiscountAmount / 100 < 0.1499).ToList(); break; case 3: products = DataBaseClass.entity.Product.Where(x => x.ProductDiscountAmount / 100 >= 0.15).ToList(); break; } ProductPanelUser.ItemsSource = products; TBShowPart.Text = "Показано предложений: " + products.Count; } private void Sorter() { if (!string.IsNullOrWhiteSpace(TBXSearch.Text)) { products = DataBaseClass.entity.Product.Where(x => x.ProductName.ToLower().Contains(TBXSearch.Text.ToLower())).ToList(); } if (RBUp.IsChecked == true) { products.Sort((x, y) => x.ProductCost.CompareTo(y.ProductCost)); } else if (RBDown.IsChecked == true) { products.Sort((x, y) => x.ProductCost.CompareTo(y.ProductCost)); products.Reverse(); } else if (RBDefault.IsChecked == true) { products.Sort((x, y) => x.ProductArticleNumber.CompareTo(y.ProductArticleNumber)); } if (products.Count == 0) { MessageBox.Show("Товаров с таким диапазоном скидок нет"); } ProductPanelUser.ItemsSource = products; TBShowPart.Text = "Показано предложений: " + products.Count; } private void RBUp_Click(object sender, RoutedEventArgs e) { Sorter(); } private void RBDown_Click(object sender, RoutedEventArgs e) { Sorter(); } private void RBDefault_Click(object sender, RoutedEventArgs e) { Sorter(); } private void CBDiscount_SelectionChanged(object sender, SelectionChangedEventArgs e) { Filter(); } private void TBXSearch_TextChanged(object sender, TextChangedEventArgs e) { Sorter(); } } }