ListProduct.ItemsSource = ClassDBase.DB.Product.ToList()
//Работа с заглушкой картинки:
//Поиск, фильтрация, сортировка:
void Filter()
{
List product = new List();
product = ClassDBase.DB.Product.ToList();
//Поиск по названию
if (!string.IsNullOrWhiteSpace(SearchName.Text)) // Проверка пустую запись и запись состоящую из пробелов
{
product = product.Where(x => x.ProductName.ToLower().Contains(SearchName.Text.ToLower())).ToList();
if (product.Count == 0)
{
MessageBox.Show("Записей с таким названием нет");
SearchName.Text = "";
}
}
//Фильтрация по размеру скидки
switch (Filtering.SelectedIndex)
{
case 0:
{
product = product.ToList();
}
break;
case 1:
{
product = product.Where(x => ((x.ProductDiscountAmount >= 0) && (x.ProductDiscountAmount < 10))).ToList();
}
break;
case 2:
{
product = product.Where(x => ((x.ProductDiscountAmount >= 10) && (x.ProductDiscountAmount < 15))).ToList();
}
break;
case 3:
{
product = product.Where(x => (x.ProductDiscountAmount>= 15)).ToList();
}
break;
}
//сортировка
switch (Sorting.SelectedIndex)
{
case 0:
{
product.Sort((x, y) => x.ProductCost.CompareTo(y.ProductCost));
}
break;
case 1:
{
product.Sort((x, y) => x.ProductCost.CompareTo(y.ProductCost));
product.Reverse();
}
break;
}
ListProduct.ItemsSource = product;
//количество записей на странице
if (product.Count == 0)
{
MessageBox.Show("нет записей");
CountProduct.Text = ClassDBase.DB.Product.ToList().Count + "/" + ClassDBase.DB.Product.ToList().Count;
SearchName.Text = "";
Sorting.SelectedIndex = 0;
Filtering.SelectedIndex = 0;
}
CountProduct.Text = product.Count + "/" + ClassDBase.DB.Product.ToList().Count;
}
// добавление в корзину
// в классе с создание объекта бд
public static List products = new List();
// событие на правую кнопку мыши
private void MenuItem_Click(object sender, RoutedEventArgs e)
{
MenuItem mi = (MenuItem)sender;
string index = mi.Uid;
Product product = ClassDBase.DB.Product.FirstOrDefault(x => x.ProductArticleNumber == index);
ClassDBase.products.Add(product);
ShowOrders.Visibility = Visibility.Visible;
}
// обновление суммы товаров корзины
private void ButonDelete_Click(object sender, RoutedEventArgs e)
{
Button Buton = (Button)sender;
int index = Convert.ToInt32(Buton.Uid);
ProductBasket productBasket = bascet.FirstOrDefault(x => x.product.ID == index);
_ = bascet.Remove(productBasket);
if (bascet.Count == 0)
{
Close();
}
lvProduct.Items.Refresh();
calculateSummaAndDiscount();
}
///
/// Подсчёт суммы заказа и скидок
///
private void calculateSummaAndDiscount()
{
summa = 0;
summaDiscount = 0;
foreach (ProductBasket productBasket in bascet)
{
summa += productBasket.count * productBasket.product.costWithDiscount;
summaDiscount += productBasket.count * ((double)productBasket.product.ProductCost - productBasket.product.costWithDiscount);
}
TBSumma.Text = "Сумма заказа: " + summa.ToString("0.00") + " руб.";
TBSummaDiscount.Text = "Сумма скидки: " + summaDiscount.ToString("0.00") + " руб.";
}
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
TextBox TB = (TextBox)sender;
int index = Convert.ToInt32(TB.Uid);
ProductBasket productBasket = bascet.FirstOrDefault(x => x.product.ID == index);
productBasket.count = TB.Text.Replace(" ", "") == "" ? 0 : Convert.ToInt32(TB.Text);
if (productBasket.count == 0) // Если колличество 0, то продукт из корзины удаляется
{
_ = bascet.Remove(productBasket);
}
if (bascet.Count == 0) // Если в корзине нет товаров, то окно закрывается
{
Close();
}
lvProduct.Items.Refresh();
calculateSummaAndDiscount();
}
// вывод на всякий
// частичный класс
public partial class Order
{
public string FullName
{
get
{
return User.UserSurname + " " + User.UserName + " " + User.UserPatronymic;
}
}
public string OrderComposition
{
get
{
string str = "Состав заказа: ";
List orderProducts = ClassDBase.DB.OrderProduct.Where(x => x.OrderID == OrderID).ToList();
foreach (OrderProduct prod in orderProducts)
{
Product product = ClassDBase.DB.Product.FirstOrDefault(z => z.ProductArticleNumber == prod.ProductArticleNumber);
str += product.ProductName + " (" + product.ProductArticleNumber + "), ";
}
str = str.Substring(0, str.Length - 2);
return str;
}
}
public string OrderAmountPrint
{
get
{
double resultCost = 0;
List orderProducts = ClassDBase.DB.OrderProduct.Where(x => x.OrderID == OrderID).ToList();
foreach (OrderProduct prod in orderProducts)
{
Product product = ClassDBase.DB.Product.FirstOrDefault(z => z.ProductArticleNumber == prod.ProductArticleNumber);
resultCost += product.CostOrder;
}
return "Стоимость заказа: " + resultCost;
}
}
public double OrderAmount
{
get
{
double resultCost = 0;
List orderProducts = ClassDBase.DB.OrderProduct.Where(x => x.OrderID == OrderID).ToList();
foreach (OrderProduct orderProduct in orderProducts)
{
Product product = ClassDBase.DB.Product.FirstOrDefault(z => z.ProductArticleNumber == orderProduct.ProductArticleNumber);
resultCost += product.CostOrder;
}
return resultCost;
}
}
public string DiscountOrderPrint
{
get
{
double discount = 0;
double withoutDiscount = 0;
double newAmount = 0;
List orderProducts = ClassDBase.DB.OrderProduct.Where(x => x.OrderID == OrderID).ToList();
foreach (OrderProduct prod in orderProducts)
{
Product product = ClassDBase.DB.Product.FirstOrDefault(z => z.ProductArticleNumber == prod.ProductArticleNumber);
withoutDiscount += (double)product.ProductCost;
newAmount += product.CostOrder;
}
discount = 100 - 100 * newAmount / withoutDiscount;
return "Общая скидка: " + discount + "%";
}
}
public double DiscountOrder
{
get
{
double discount = 0;
double withoutDiscount = 0;
double newAmount = 0;
List orderProducts = ClassDBase.DB.OrderProduct.Where(x => x.OrderID == OrderID).ToList();
foreach (OrderProduct prod in orderProducts)
{
Product product = ClassDBase.DB.Product.FirstOrDefault(z => z.ProductArticleNumber == prod.ProductArticleNumber);
withoutDiscount += (double)product.ProductCost;
newAmount += product.CostOrder;
}
discount = 100 - 100 * newAmount / withoutDiscount;
return discount;
}
}
public SolidColorBrush ColorOrder
{
get
{
bool moreThree = false;
bool zero = false;
List orderProducts = ClassDBase.DB.OrderProduct.Where(x => x.OrderID == OrderID).ToList();
foreach (OrderProduct prod in orderProducts)
{
Product product = ClassDBase.DB.Product.FirstOrDefault(z => z.ProductArticleNumber == prod.ProductArticleNumber);
if (product.ProductQuantityInStock > 3)
{
moreThree = true;
}
else
{
moreThree = false;
if (product.ProductQuantityInStock == 0)
{
moreThree = false;
zero = true;
goto met;
}
}
}
met: if (moreThree == true)
{
return (SolidColorBrush)new BrushConverter().ConvertFrom("#20b2aa");
}
else if (zero == true)
{
return (SolidColorBrush)new BrushConverter().ConvertFrom("#ff8c00");
}
else
{
return Brushes.White;
}
}
}
}
// и еще один
public partial class Product
{
public SolidColorBrush Brush
{
get
{
var brushConverter = new BrushConverter();
if (ProductDiscountAmount < 15 || ProductDiscountAmount == null)
{
return Brushes.White;
}
else
{
return (SolidColorBrush)(Brush)brushConverter.ConvertFrom("#7fff00");
}
}
}
public string Price
{
get
{
if (ProductDiscountAmount != null)
{
double b = (Convert.ToDouble(ProductCost) / 100) * (100 - ProductDiscountAmount.Value);
return b + "";
}
else
{
double a = Convert.ToDouble(ProductCost);
return a + "";
}
}
}
public string Cost
{
get
{
if (ProductDiscountAmount != null)
{
return Math.Round(Convert.ToDouble(ProductCost)) + " ";
}
return "";
}
}
public double PriceOrder
{
get
{
if (ProductDiscountAmount != null)
{
double b = (Convert.ToDouble(ProductCost) / 100) * (100 - ProductDiscountAmount.Value);
return b;
}
else
{
double a = Convert.ToDouble(ProductCost);
return a;
}
}
}
public double CostOrder
{
get
{
if (ProductDiscountAmount != null)
{
return Math.Round(Convert.ToDouble(ProductCost));
}
return 0;
}
}
public string Discount
{
get
{
return ProductDiscountAmount + "%";
}
}
}