123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows;
- using System.Windows.Controls;
- namespace SergechevExam
- {
- /// <summary>
- /// Логика взаимодействия для ProductList.xaml
- /// </summary>
- public partial class ProductList : Page
- {
- public ProductList()
- {
- InitializeComponent();
- productList.ItemsSource = DataBaseConnection.dataBaseEntities.Products.ToList();
- }
- private void oldPrice_Loaded(object sender, RoutedEventArgs e) // Проверка на наличие скидки у товара. Если она есть, то отрисовывается перечеркнутый TB, в котором старая цена
- {
- TextBlock oldPrice = (TextBlock)sender;
- int indexProduct = Convert.ToInt32(oldPrice.Uid);
- Products currentProduct = DataBaseConnection.dataBaseEntities.Products.FirstOrDefault(x => x.Code_Product == indexProduct);
- if (currentProduct.Discount_Product != 0)
- {
- oldPrice.Visibility = Visibility.Visible;
- }
- }
- private void mainPrice_Loaded(object sender, RoutedEventArgs e) // Проверка на наличие скидки у товара. Если она есть, то рядом с перечеркнутым TB отрисовывается новая цена
- {
- TextBlock mainPrice = (TextBlock)sender;
- int indexProduct = Convert.ToInt32(mainPrice.Uid);
- Products currentProduct = DataBaseConnection.dataBaseEntities.Products.FirstOrDefault(x => x.Code_Product == indexProduct);
- if (currentProduct.Discount_Product > 0)
- {
- mainPrice.Text = $"{currentProduct.Price_Product - (currentProduct.Price_Product * currentProduct.Discount_Product)}";
- }
- }
- private void discount_Loaded(object sender, RoutedEventArgs e)
- {
- TextBlock discount = (TextBlock)sender;
- int indexProduct = Convert.ToInt32(discount.Uid);
- Products currentProduct = DataBaseConnection.dataBaseEntities.Products.FirstOrDefault(x => x.Code_Product == indexProduct);
- if (currentProduct.Discount_Product != 0)
- {
- discount.Visibility = Visibility.Visible;
- discount.Text = $"Скидка: {Convert.ToInt32(currentProduct.Discount_Product*100)}%";
- }
- }
- private List<Products> _shoppingCartProduct = new List<Products>();
- private void addToCart_Click(object sender, RoutedEventArgs e)
- {
- Products selectedProduct = productList.SelectedItem as Products;
- bool checkSameProduct = false;
- foreach (Products product in _shoppingCartProduct)
- {
- if (selectedProduct == product)
- {
- checkSameProduct = true;
- product.Count += 1;
- break;
- }
- }
- if (checkSameProduct == false)
- {
- selectedProduct.Count = 1;
- _shoppingCartProduct.Add(selectedProduct);
- }
- else
- {
- checkSameProduct = false;
- }
- if (_shoppingCartProduct.Count > 0)
- {
- openShoppingCart.Visibility = Visibility.Visible;
- }
- else
- {
- openShoppingCart.Visibility = Visibility.Collapsed;
- }
- }
- private void openShoppingCart_Click(object sender, RoutedEventArgs e)
- {
- ShoppingCart shoppingCart = new ShoppingCart(_shoppingCartProduct);
- shoppingCart.ShowDialog();
- }
- }
- }
|