123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- 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 UP_Venediktov.Classes;
- using UP_Venediktov.ModelBase;
- namespace UP_Venediktov.Pages
- {
- /// <summary>
- /// Логика взаимодействия для ProductListUser.xaml
- /// </summary>
- public partial class ProductListUser : Page
- {
- Entities DB = new Entities();
- int AllData;
- int id;
- public ProductListUser()
- {
- InitializeComponent();
- ProductList.ItemsSource = DB.Product.ToList();
- CB_Filter.ItemsSource = new List<string>() { "Все", "Скидка 0-9,99%", "Скидка 10-14,99%", "Скидка 15% и более" };
- CB_Sort.ItemsSource = new List<string>() { "Без сортировки", "По имени А-Я", "По имени Я-А" };
- CB_Sort.SelectedIndex = 0;
- CB_Filter.SelectedIndex = 0;
- AllData = ProductList.Items.Count;
- //AmountOfData.Text = AllData + " из " + AllData + " товаров";
- }
- public ProductListUser(int id)
- {
- InitializeComponent();
- ProductList.ItemsSource = DB.Product.ToList();
- User user = DB.User.Where(x => x.UserID == id).FirstOrDefault();
- if (user.UserRole == 1)
- {
- ButtonsForAdmin.Visibility = Visibility.Visible;
- ViewOrder.Visibility = Visibility.Visible;
- }
- if (user.UserRole == 3)
- {
- ViewOrder.Visibility = Visibility.Visible;
- }
- CB_Filter.ItemsSource = new List<string>() { "Все", "Скидка 0-9,99%", "Скидка 10-14,99%", "Скидка 15% и более" };
- CB_Sort.ItemsSource = new List<string>() { "Без сортировки", "По имени А-Я", "По имени Я-А" };
- CB_Sort.SelectedIndex = 0;
- CB_Filter.SelectedIndex = 0;
- this.id = id;
- }
- public void BackgroundLoad(object sender, RoutedEventArgs e)
- {
- Grid bgr = (Grid)sender;
- string Article = bgr.Uid.ToString();
- Product pr = DB.Product.Where(x => x.ProductArticleNumber == Article).FirstOrDefault();
- if (pr.ProductDiscountAmount > 15)
- {
- bgr.Background = (SolidColorBrush)new BrushConverter().ConvertFrom("#7fff00");
- }
- }
- public void StrikePrice(object sender, RoutedEventArgs e)
- {
- TextBlock tb = (TextBlock)sender;
- string Article = tb.Uid.ToString();
- Product pr = DB.Product.Where(x => x.ProductArticleNumber == Article).FirstOrDefault();
- tb.Text = "Цена: " + string.Format("{0:C2}", pr.ProductCost);
- if (pr.ProductDiscountAmount > 0)
- {
- tb.TextDecorations = TextDecorations.Strikethrough;
- }
- }
- public void PromoPrice(object sender, RoutedEventArgs e)
- {
- TextBlock tb = (TextBlock)sender;
- string Article = tb.Uid.ToString();
- Product pr = DB.Product.Where(x => x.ProductArticleNumber == Article).FirstOrDefault();
- if (pr.ProductDiscountAmount > 0)
- {
- tb.Text = "Цена: " + string.Format("{0:C2}", (pr.ProductCost - (pr.ProductCost / 100 * pr.ProductDiscountAmount)));
- tb.FontWeight = FontWeights.Bold;
- }
- }
- private void Photo(object sender, RoutedEventArgs e)
- {
- Image pic = (Image)sender;
- string Article = pic.Uid.ToString();
- string photoPath = DB.Product.Where(x => x.ProductArticleNumber == Article).Select(x => x.ProductPhoto).FirstOrDefault();
- if (photoPath != null && photoPath != "")
- {
- pic.Source = new BitmapImage(new Uri(Environment.CurrentDirectory + "\\Pictures\\" + photoPath, UriKind.RelativeOrAbsolute));
- }
- else
- {
- pic.Source = new BitmapImage(new Uri(Environment.CurrentDirectory + "\\Pictures\\picture.png", UriKind.RelativeOrAbsolute));
- }
- }
- private void Filter()
- {
- List<Product> products = DB.Product.ToList();
- if (CB_Sort.SelectedIndex != 0)
- {
- switch (CB_Sort.SelectedIndex)
- {
- case 1:
- products = products.OrderBy(x => x.ProductName).ToList();
- break;
- case 2:
- products = products.OrderByDescending(x => x.ProductName).ToList();
- break;
- }
- }
- if (CB_Filter.SelectedIndex != 0)
- {
- switch (CB_Filter.SelectedIndex)
- {
- case 1:
- products = products.Where(x => x.ProductDiscountAmount >= 0 && x.ProductDiscountAmount < 10).ToList();
- break;
- case 2:
- products = products.Where(x => x.ProductDiscountAmount >= 10 && x.ProductDiscountAmount < 15).ToList();
- break;
- case 3:
- products = products.Where(x => x.ProductDiscountAmount >= 15).ToList();
- break;
- }
- }
- if (!string.IsNullOrEmpty(TB_Search.Text))
- {
- products = products.Where(x => x.ProductName.ToUpper().Contains(TB_Search.Text.ToUpper())).ToList();
- }
- ProductList.ItemsSource = products;
- //AmountOfData.Text = products.Count() + " из " + AllData + " товаров";
- }
- private void SortFilterChanged(object sender, SelectionChangedEventArgs e)
- {
- Filter();
- }
- private void SearchChanged(object sender, TextChangedEventArgs e)
- {
- Filter();
- }
- private void CartAdd(object sender, RoutedEventArgs e)
- {
- MenuItem bt = (MenuItem)sender;
- string article = bt.Uid.ToString();
- Product pr = DB.Product.Where(x => x.ProductArticleNumber == article).First();
- AmountofProduct pa = new AmountofProduct();
- if (CardOrder.Products.Count != 0 && CardOrder.Products.Contains(pr))
- {
- pa = CardOrder.AmountofProducts.Where(x => x.Article == article).First();
- }
- if (pa.Article != null)
- {
- int index = CardOrder.AmountofProducts.IndexOf(pa);
- CardOrder.AmountofProducts[index].Amount++;
- }
- else
- {
- pa.Amount = 1;
- pa.Article = article;
- CardOrder.Products.Add(pr);
- CardOrder.AmountofProducts.Add(pa);
- }
- GoToCard.Visibility = Visibility.Visible;
- }
- private void CartGo(object sender, RoutedEventArgs e)
- {
- CardOrder ct = new CardOrder();
- if (CardOrder.Products.Count > 0)
- {
- FrameClass.MainFrame.Navigate(new CardOrder());
- }
- else
- {
- MessageBox.Show("Чтобы перейти в корзину добавьте в неё товар");
- }
- }
- private void ViewOrders(object sender, RoutedEventArgs e)
- {
- FrameClass.MainFrame.Navigate(new Orders(id));
- }
- private void BackToAvt(object sender, RoutedEventArgs e)
- {
- FrameClass.MainFrame.Navigate(new Avtorization());
- }
- }
- }
|