123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- using System;
- using System.Collections.Generic;
- using System.Data.SqlClient;
- 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;
- using UP_Venediktov.ModelBase;
- using UP_Venediktov.Classes;
- namespace UP_Venediktov.Pages
- {
- /// <summary>
- /// Логика взаимодействия для Orders.xaml
- /// </summary>
- public partial class Orders : Page
- {
- Entities DB = new Entities();
- int id;
- public Orders(int id)
- {
- InitializeComponent();
- OrderList.ItemsSource = DB.Order.ToList();
- SortOrders.ItemsSource = new List<string>() { "Без сортировки", "Сначала дешёвые", "Сначала дорогие" };
- FilterOrders.ItemsSource = new List<string>() { "Без фильтрации", "Скидка 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.ProductCont + " " + DB.Product.Where(x => x.ProductArticleNumber == op.ProductArticleNumber).Select(x => x.ProductMeasurement.NameMeasurement).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.ProductCont;
- }
- }
- 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.ProductDiscountAmount).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<Order> 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.ProductCont;
- }
- }
- or.OrderCode = Convert.ToInt32(TotalCost);
- }
- switch (SortOrders.SelectedIndex)
- {
- case 1:
- UpdateOrders = UpdateOrders.OrderBy(x => x.OrderCode).ToList();
- break;
- case 2:
- UpdateOrders = UpdateOrders.OrderByDescending(x => x.OrderCode).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.ProductDiscountAmount).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)
- {
- FrameClass.MainFrame.Navigate(new ProductListUser(id));
- }
- }
- }
|