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.Shapes;
using static System.Net.Mime.MediaTypeNames;
namespace UP43P_Krupina.Windows
{
///
/// Логика взаимодействия для OrdersWindow.xaml
///
public partial class OrdersWindow : Window
{
User current_user;
List orders = new List();
List discount_d = new List() { "Все диапозоны (не робит)", "0-9,99%", "10-14,99%", "15% и более" };
public OrdersWindow(User user)
{
InitializeComponent();
current_user = user;
if (current_user.UserRole == 1)
{
orders = Base.MyBase.Order.Where(x => x.UserID == current_user.UserID).ToList();
TBNameUser.Text = "Заказы пользователя: " + user.UserName + " " + user.UserSurname;
SPForAdminOrManager.Visibility = Visibility.Collapsed;
}
else
{
orders = Base.MyBase.Order.ToList();
CBDiscount.ItemsSource = discount_d;
CBDiscount.SelectedIndex = 0;
RBUsial.IsChecked = true;
}
LVOrders.ItemsSource = orders;
}
private void Sort()
{
orders = Base.MyBase.Order.ToList();
if (RBNew.IsChecked == true)
{
orders = orders.Where(x=>x.OrderStatus == 2).ToList();
}
if (RBFinished.IsChecked == true)
{
orders = orders.Where(x => x.OrderStatus == 1).ToList();
}
if (RBDrop.IsChecked == true)
{
RBDrop.IsChecked = false;
RBFinished.IsChecked = false;
RBFinished.IsChecked = false;
RBUsial.IsChecked= true;
CBDiscount.SelectedIndex=0;
}
LVOrders.ItemsSource= orders;
}
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Sort();
}
private void RadioButton_Checked(object sender, RoutedEventArgs e)
{
Sort();
}
private void Back_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void Products_Loaded(object sender, RoutedEventArgs e)
{
TextBlock textBlock = (TextBlock)sender;
List op = Base.MyBase.OrderProduct.Where(x=>x.OrderID.ToString() == textBlock.Uid).ToList();
List products = new List();
string text = "Товары: ";
foreach (OrderProduct a in op)
{
Product b = Base.MyBase.Product.FirstOrDefault(x=>x.ProductArticleNumber == a.ProductArticleNumber);
text += b.ProductName + " (" + b.ProductArticleNumber + ") " + op.Count + " шт., ";
}
text = text.Substring(0, text.Length - 2);
textBlock.TextWrapping = TextWrapping.Wrap;
textBlock.Text = text;
}
private void Summ_Loaded(object sender, RoutedEventArgs e)
{
TextBlock textBlock = (TextBlock)sender;
List op = Base.MyBase.OrderProduct.Where(x => x.OrderID.ToString() == textBlock.Uid).ToList();
string text = "";
double all_cost = 0;
double cost = 0;
double discount = 0;
foreach (OrderProduct a in op)
{
Product b = Base.MyBase.Product.FirstOrDefault(x => x.ProductArticleNumber == a.ProductArticleNumber);
all_cost += Convert.ToDouble(b.ProductCost * a.ProductCount);
discount += Convert.ToDouble(b.ProductCost * b.ProductDiscountAmount / 100);
cost += Convert.ToDouble((b.ProductCost - b.ProductCost * b.ProductDiscountAmount / 100) * a.ProductCount);
}
if (discount == 0)
{
text = "Итого: " + all_cost.ToString() + " рублей";
}
else
{
text = "Общая сумма: " + all_cost.ToString() + " рублей\n" + "Скидка: " + discount.ToString() + " рублей\n" + "Итого: " + cost.ToString() + " рублей";
}
textBlock.Text = text;
}
private void UserName_Loaded(object sender, RoutedEventArgs e)
{
TextBlock textBlock = (TextBlock)sender;
User user = Base.MyBase.User.FirstOrDefault(x => x.UserID.ToString() == textBlock.Uid);
if (user != null)
{
textBlock.Text = "Заказчик: " + user.UserSurname + user.UserName + " " + user.UserPatronymic;
}
else
{
textBlock.Text = "Заказчик: не найдено";
}
if (current_user.UserRole == 1) textBlock.Text = "";
}
}
}