|
@@ -0,0 +1,173 @@
|
|
|
+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;
|
|
|
+
|
|
|
+namespace AppSkakunov.PagesApp
|
|
|
+{
|
|
|
+ /// <summary>
|
|
|
+ /// Логика взаимодействия для OrdersApp.xaml
|
|
|
+ /// </summary>
|
|
|
+ public partial class OrdersApp : Page
|
|
|
+ {
|
|
|
+ TradeSKakunovEntities DB = new TradeSKakunovEntities();
|
|
|
+ int id;
|
|
|
+ public OrdersApp(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.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("#bbbbbb");
|
|
|
+ }
|
|
|
+ if (pr.ProductQuantityInStock == 0)
|
|
|
+ {
|
|
|
+ br.Background = (SolidColorBrush)new BrushConverter().ConvertFrom("#140f0b");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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.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)
|
|
|
+ {
|
|
|
+ MainFrame.mFrame.Navigate(new PageUserGuestApp(id));
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|