123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- using System;
- using System.Collections.Generic;
- using System.Data.Entity;
- using System.Diagnostics;
- using System.Linq;
- using System.Security.Cryptography.Xml;
- 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;
- using static Write_erase.Classes.RoleClass;
- namespace Write_erase.UserPages
- {
- /// <summary>
- /// Логика взаимодействия для ShowProductPage.xaml
- /// </summary>
- public partial class ShowProductPage : Page
- {
- RoleUser nowRole;
- User nowUser;
- List<Product> products = DataBaseClass.entity.Product.ToList();
- string Click = "";
- int id;
- public ShowProductPage()
- {
- 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;
- nowRole = RoleUser.Noname;
- }
- public ShowProductPage(int id)
- {
- id = 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;
- nowRole = RoleUser.User;
- nowUser = DataBaseClass.entity.User.FirstOrDefault(x => x.UserID == id);
- }
- 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();
- }
- private void Delete_Click(object sender, RoutedEventArgs e)
- {
- }
- private void Add_Click(object sender, RoutedEventArgs e)
- {
- Product p = DataBaseClass.entity.Product.FirstOrDefault(x => x.ProductArticleNumber == ((Product)ProductPanelUser.SelectedItem).ProductArticleNumber);
- if (p != null)
- {
- switch (((MenuItem)sender).Header)
- {
- case "Добавить к заказу":
- if (BascketClass.bascket.Contains(p))
- {
- p.CountProduct++;
- }
- else
- {
- p.CountProduct++;
- BascketClass.bascket.Add(p);
- }
- Basket.Visibility = Visibility.Visible;
- break;
- case "Удалить из заказа":
- if (BascketClass.bascket.Contains(p) && p.CountProduct > 1)
- {
- p.CountProduct--;
- }
- else if (BascketClass.bascket.Contains(p) && p.CountProduct == 1)
- {
- p.CountProduct--;
- BascketClass.bascket.Remove(p);
- Basket.Visibility = Visibility.Hidden;
- }
- break;
- }
- }
- }
- private void Back_Click(object sender, RoutedEventArgs e)
- {
- FrameClass.MFrame.Navigate(new MainPages.AutorizePage());
- }
- private void Basket_Click(object sender, RoutedEventArgs e)
- {
- BasketWindow bw;
- if (nowRole == RoleUser.Noname)
- bw = new BasketWindow(BascketClass.bascket);
- else
- bw = new BasketWindow(BascketClass.bascket, nowUser);
- bw.ShowDialog();
- if (BascketClass.bascket.Count > 0)
- Basket.Visibility = Visibility.Visible;
- else
- Basket.Visibility = Visibility.Collapsed;
- }
- }
- }
|