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;
namespace GGwp
{
///
/// Логика взаимодействия для Zakaz.xaml
///
public partial class Zakaz : Page
{
TradePrytovEntities DB = new TradePrytovEntities();
int id;
public Zakaz(int id)
{
InitializeComponent();
OrderList.ItemsSource = DB.Order.ToList();
SortOrders.ItemsSource = new List() { "Без сортировки", "Сначала дешёвые", "Сначала дорогие" };
FilterOrders.ItemsSource = new List() { "Без фильтрации", "Скидка 0%-10%", "Скидка 10%-15%", "Скидка более 15%" };
SortOrders.SelectedIndex = 0;
FilterOrders.SelectedIndex = 0;
this.id = id;
}
private void WhatInOrder(object sender, RoutedEventArgs e)
{
TextBlock tb = (TextBlock)sender;
int id = Convert.ToInt32(tb.Uid);
string WhatIn = "";
foreach (OrderProduct op in DB.OrderProduct)
{
if (op.OrderID == id)
{
WhatIn += DB.Product.Where(x => x.ProductArticleNumber == op.ProductArticleNumber).Select(x => x.ProductName).FirstOrDefault() + " ";
WhatIn += op.ProductAmount + " " + DB.Product.Where(x => x.ProductArticleNumber == op.ProductArticleNumber).Select(x => x.UnitsOfMeasurement.UnitName).FirstOrDefault() + "\n";
}
}
tb.Text = WhatIn;
}
private void OrderCost(object sender, RoutedEventArgs e)
{
TextBlock tb = (TextBlock)sender;
int id = Convert.ToInt32(tb.Uid);
decimal? TotalCost = 0;
foreach (OrderProduct op in DB.OrderProduct)
{
if (op.OrderID == id)
{
TotalCost += DB.Product.Where(x => x.ProductArticleNumber == op.ProductArticleNumber).Select(x => x.ProductCost).FirstOrDefault() *
op.ProductAmount;
}
}
tb.Text = "Стоимость заказа: " + string.Format("{0:C2}", TotalCost);
}
private void TotalPromo(object sender, RoutedEventArgs e)
{
TextBlock tb = (TextBlock)sender;
int id = Convert.ToInt32(tb.Uid);
int? Promo = 0;
foreach (OrderProduct op in DB.OrderProduct)
{
if (op.OrderID == id)
{
Promo += DB.Product.Where(x => x.ProductArticleNumber == op.ProductArticleNumber).Select(x => x.ProductMaxDiscountAmount).FirstOrDefault();
}
}
tb.Text = "Общая скидка: " + Promo.ToString() + "%";
}
private void BgrLoad(object sender, RoutedEventArgs e)
{
Border br = (Border)sender;
int id = Convert.ToInt32(br.Uid);
Product pr = DB.OrderProduct.Where(x => x.OrderID == id).Select(x => x.Product).FirstOrDefault();
if (pr.ProductQuantityInStock > 3)
{
br.Background = (SolidColorBrush)new BrushConverter().ConvertFrom("#20b2aa");
}
if (pr.ProductQuantityInStock == 0)
{
br.Background = (SolidColorBrush)new BrushConverter().ConvertFrom("#ff8c00");
}
}
public void Filter()
{
List UpdateOrders = DB.Order.ToList();
if (SortOrders.SelectedIndex != 0)
{
decimal? TotalCost = 0;
foreach (Order or in UpdateOrders)
{
TotalCost = 0;
foreach (OrderProduct op in DB.OrderProduct)
{
if (op.OrderID == or.OrderID)
{
TotalCost += DB.Product.Where(x => x.ProductArticleNumber == op.ProductArticleNumber).Select(x => x.ProductCost).FirstOrDefault() *
op.ProductAmount;
}
}
or.OrderReceivingCode = Convert.ToInt32(TotalCost);
}
switch (SortOrders.SelectedIndex)
{
case 1:
UpdateOrders = UpdateOrders.OrderBy(x => x.OrderReceivingCode).ToList();
break;
case 2:
UpdateOrders = UpdateOrders.OrderByDescending(x => x.OrderReceivingCode).ToList();
break;
default:
break;
}
}
if (FilterOrders.SelectedIndex != 0)
{
int? TotalPromo = 0;
foreach (Order or in UpdateOrders)
{
TotalPromo = 0;
foreach (OrderProduct op in DB.OrderProduct)
{
if (op.OrderID == or.OrderID)
{
TotalPromo += DB.Product.Where(x => x.ProductArticleNumber == op.ProductArticleNumber).Select(x => x.ProductMaxDiscountAmount).FirstOrDefault();
}
}
or.OrderPickupPoint = Convert.ToInt32(TotalPromo);
}
switch (FilterOrders.SelectedIndex)
{
case 1:
UpdateOrders = UpdateOrders.Where(x => x.OrderPickupPoint >= 0 && x.OrderPickupPoint < 10).ToList();
break;
case 2:
UpdateOrders = UpdateOrders.Where(x => x.OrderPickupPoint >= 10 && x.OrderPickupPoint < 15).ToList();
break;
case 3:
UpdateOrders = UpdateOrders.Where(x => x.OrderPickupPoint >= 15).ToList();
break;
default:
break;
}
}
OrderList.ItemsSource = UpdateOrders;
}
private void SortOrFilter(object sender, SelectionChangedEventArgs e)
{
Filter();
}
private void BackToProduct(object sender, RoutedEventArgs e)
{
MainFRM.mFrame.Navigate(new Guest(id));
}
}
}