OrdersWindow.xaml.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Shapes;
  14. using static System.Net.Mime.MediaTypeNames;
  15. namespace UP43P_Krupina.Windows
  16. {
  17. /// <summary>
  18. /// Логика взаимодействия для OrdersWindow.xaml
  19. /// </summary>
  20. public partial class OrdersWindow : Window
  21. {
  22. User current_user;
  23. List<Order> orders = new List<Order>();
  24. List<string> discount_d = new List<string>() { "Все диапозоны (не робит)", "0-9,99%", "10-14,99%", "15% и более" };
  25. public OrdersWindow(User user)
  26. {
  27. InitializeComponent();
  28. current_user = user;
  29. if (current_user.UserRole == 1)
  30. {
  31. orders = Base.MyBase.Order.Where(x => x.UserID == current_user.UserID).ToList();
  32. TBNameUser.Text = "Заказы пользователя: " + user.UserName + " " + user.UserSurname;
  33. SPForAdminOrManager.Visibility = Visibility.Collapsed;
  34. }
  35. else
  36. {
  37. orders = Base.MyBase.Order.ToList();
  38. CBDiscount.ItemsSource = discount_d;
  39. CBDiscount.SelectedIndex = 0;
  40. RBUsial.IsChecked = true;
  41. }
  42. LVOrders.ItemsSource = orders;
  43. }
  44. private void Sort()
  45. {
  46. orders = Base.MyBase.Order.ToList();
  47. if (RBNew.IsChecked == true)
  48. {
  49. orders = orders.Where(x=>x.OrderStatus == 2).ToList();
  50. }
  51. if (RBFinished.IsChecked == true)
  52. {
  53. orders = orders.Where(x => x.OrderStatus == 1).ToList();
  54. }
  55. if (RBDrop.IsChecked == true)
  56. {
  57. RBDrop.IsChecked = false;
  58. RBFinished.IsChecked = false;
  59. RBFinished.IsChecked = false;
  60. RBUsial.IsChecked= true;
  61. CBDiscount.SelectedIndex=0;
  62. }
  63. LVOrders.ItemsSource= orders;
  64. }
  65. private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  66. {
  67. Sort();
  68. }
  69. private void RadioButton_Checked(object sender, RoutedEventArgs e)
  70. {
  71. Sort();
  72. }
  73. private void Back_Click(object sender, RoutedEventArgs e)
  74. {
  75. this.Close();
  76. }
  77. private void Products_Loaded(object sender, RoutedEventArgs e)
  78. {
  79. TextBlock textBlock = (TextBlock)sender;
  80. List<OrderProduct> op = Base.MyBase.OrderProduct.Where(x=>x.OrderID.ToString() == textBlock.Uid).ToList();
  81. List<Product> products = new List<Product>();
  82. string text = "Товары: ";
  83. foreach (OrderProduct a in op)
  84. {
  85. Product b = Base.MyBase.Product.FirstOrDefault(x=>x.ProductArticleNumber == a.ProductArticleNumber);
  86. text += b.ProductName + " (" + b.ProductArticleNumber + ") " + op.Count + " шт., ";
  87. }
  88. text = text.Substring(0, text.Length - 2);
  89. textBlock.TextWrapping = TextWrapping.Wrap;
  90. textBlock.Text = text;
  91. }
  92. private void Summ_Loaded(object sender, RoutedEventArgs e)
  93. {
  94. TextBlock textBlock = (TextBlock)sender;
  95. List<OrderProduct> op = Base.MyBase.OrderProduct.Where(x => x.OrderID.ToString() == textBlock.Uid).ToList();
  96. string text = "";
  97. double all_cost = 0;
  98. double cost = 0;
  99. double discount = 0;
  100. foreach (OrderProduct a in op)
  101. {
  102. Product b = Base.MyBase.Product.FirstOrDefault(x => x.ProductArticleNumber == a.ProductArticleNumber);
  103. all_cost += Convert.ToDouble(b.ProductCost * a.ProductCount);
  104. discount += Convert.ToDouble(b.ProductCost * b.ProductDiscountAmount / 100);
  105. cost += Convert.ToDouble((b.ProductCost - b.ProductCost * b.ProductDiscountAmount / 100) * a.ProductCount);
  106. }
  107. if (discount == 0)
  108. {
  109. text = "Итого: " + all_cost.ToString() + " рублей";
  110. }
  111. else
  112. {
  113. text = "Общая сумма: " + all_cost.ToString() + " рублей\n" + "Скидка: " + discount.ToString() + " рублей\n" + "Итого: " + cost.ToString() + " рублей";
  114. }
  115. textBlock.Text = text;
  116. }
  117. private void UserName_Loaded(object sender, RoutedEventArgs e)
  118. {
  119. TextBlock textBlock = (TextBlock)sender;
  120. User user = Base.MyBase.User.FirstOrDefault(x => x.UserID.ToString() == textBlock.Uid);
  121. if (user != null)
  122. {
  123. textBlock.Text = "Заказчик: " + user.UserSurname + user.UserName + " " + user.UserPatronymic;
  124. }
  125. else
  126. {
  127. textBlock.Text = "Заказчик: не найдено";
  128. }
  129. if (current_user.UserRole == 1) textBlock.Text = "";
  130. }
  131. }
  132. }