123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- 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
- {
- /// <summary>
- /// Логика взаимодействия для ShowProductPage.xaml
- /// </summary>
- public partial class ShowProductPage : Page
- {
- List<Product> products = DataBaseClass.entity.Product.ToList();
- public ShowProductPage(int id)
- {
- InitializeComponent();
- List<User> 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();
- }
- }
- }
|