OrderNew.xaml.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. using Sessioa.BaseModel;
  2. using Sessioa.Classes;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data.Entity;
  6. using System.Linq;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. namespace Sessioa.Pages
  12. {
  13. /// <summary>
  14. /// Логика взаимодействия для OrderNew.xaml
  15. /// </summary>
  16. public partial class OrderNew : Page
  17. {
  18. User user = null;
  19. List<string> sortList = new List<string>() { "Без сортировки", "По убыванию стоимости", "По возрастанию стоимости" };
  20. List<string> filtList = new List<string>() { "Без фильтрации", "0-10%", "11-14%", "15% >" };
  21. List<Order> orders = new List<Order>();
  22. public OrderNew(User userSign)
  23. {
  24. InitializeComponent();
  25. user = userSign;
  26. if (userSign.UserRole == 2 || userSign.UserRole == 3)
  27. {
  28. orders = BaseClass.C_Base.Order.Include(x => x.PointsOfIssue).Include(x => x.User).Include(x => x.OrderProduct).ToList();
  29. LB_OrderProduct.ItemsSource = orders;
  30. }
  31. else if (userSign.UserRole == 1)
  32. {
  33. orders = BaseClass.C_Base.Order.Include(x => x.PointsOfIssue).Where(x => x.UserID == userSign.UserID).Include(x => x.OrderProduct).ToList();
  34. LB_OrderProduct.ItemsSource = orders;
  35. }
  36. Sort.ItemsSource = sortList;
  37. Sort.SelectedItem = sortList[0];
  38. Filt.ItemsSource = filtList;
  39. Filt.SelectedItem = filtList[0];
  40. }
  41. private void UserOrder_Loaded(object sender, RoutedEventArgs e)
  42. {
  43. TextBlock tb = (TextBlock)sender;
  44. if (tb.Uid != null && (user.UserRole == 2 || user.UserRole == 3))
  45. {
  46. User us = BaseClass.C_Base.User.FirstOrDefault(x => x.UserID.ToString() == tb.Uid);
  47. tb.Text = $"Заказчик: {us.UserSurname} {us.UserName[0]}.{(us.UserPatronymic != null && us.UserPatronymic != string.Empty ? $"{us.UserPatronymic[0]}." : "")}";
  48. }
  49. }
  50. private void B_Back_Click(object sender, RoutedEventArgs e)
  51. {
  52. Application.Current.Properties["ListOrderUser"] = new List<Product>();
  53. Application.Current.Properties["ListOrderCountUser"] = new Dictionary<string, int>();
  54. FrameClass.C_Frame.Navigate(new ProductsPage(user));
  55. }
  56. private void TextBlock_Loaded(object sender, RoutedEventArgs e)
  57. {
  58. TextBlock tb = (TextBlock)sender;
  59. Order tmp = BaseClass.C_Base.Order.FirstOrDefault(x => x.OrderID.ToString() == tb.Uid);
  60. if (tmp.OrderDeliveryDate == null)
  61. {
  62. tb.Text = "Дата выдачи не указана";
  63. tb.Foreground = new SolidColorBrush(Color.FromRgb(235, 156, 0));
  64. }
  65. }
  66. private void Border_MouseDown(object sender, MouseButtonEventArgs e)
  67. {
  68. if (e.ClickCount > 1)
  69. {
  70. FrameClass.C_Frame.Navigate(new OrderCard(user, ((Order)LB_OrderProduct.SelectedItem).OrderID));
  71. }
  72. }
  73. private void TB_StatusOrder_Loaded(object sender, RoutedEventArgs e)
  74. {
  75. TextBlock tb = (TextBlock)sender;
  76. Order tmp = BaseClass.C_Base.Order.FirstOrDefault(x => x.OrderID.ToString() == tb.Uid);
  77. if (tmp.OrderStatus == 2)
  78. {
  79. tb.Text = "Статус: Новый";
  80. tb.Foreground = new SolidColorBrush(Color.FromRgb(73, 140, 81));
  81. }
  82. else
  83. {
  84. tb.Text = "Статус: Завершен";
  85. tb.Foreground = new SolidColorBrush(Color.FromRgb(255, 0, 0));
  86. }
  87. }
  88. private void Border_Loaded(object sender, RoutedEventArgs e)
  89. {
  90. Border brd = (Border)sender;
  91. List<OrderProduct> op = BaseClass.C_Base.OrderProduct.Where(x => x.OrderID.ToString() == brd.Uid).ToList();
  92. foreach (OrderProduct opItem in op)
  93. {
  94. Product prd = BaseClass.C_Base.Product.FirstOrDefault(x => x.ProductArticleNumber == opItem.ProductArticleNumber);
  95. if (prd.ProductQuantityInStock < 3)
  96. brd.BorderBrush = new SolidColorBrush(Color.FromRgb(255, 140, 0));
  97. }
  98. }
  99. private void Sort_SelectionChanged(object sender, SelectionChangedEventArgs e)
  100. {
  101. Sett();
  102. }
  103. private void Filt_SelectionChanged(object sender, SelectionChangedEventArgs e)
  104. {
  105. Sett();
  106. }
  107. private void Sett()
  108. {
  109. foreach (Order od in orders)
  110. {
  111. decimal itogoBezSkidki = 0;
  112. decimal itogoSoSkidkoy = 0;
  113. List<OrderProduct> tmpOP = BaseClass.C_Base.OrderProduct.Where(x => x.OrderID == od.OrderID).ToList();
  114. foreach (OrderProduct opItem in tmpOP)
  115. {
  116. Product prAdd = BaseClass.C_Base.Product.FirstOrDefault(x => x.ProductArticleNumber == opItem.ProductArticleNumber);
  117. itogoBezSkidki += prAdd.ProductCost * opItem.ProductCount;
  118. if (prAdd.ProductDiscountAmount != null && prAdd.ProductDiscountAmount != 0)
  119. {
  120. itogoSoSkidkoy += (prAdd.ProductCost - (prAdd.ProductCost * ((decimal)prAdd.ProductDiscountAmount / 100))) * opItem.ProductCount;
  121. }
  122. else
  123. itogoSoSkidkoy += prAdd.ProductCost * opItem.ProductCount;
  124. }
  125. od.Cost = itogoSoSkidkoy;
  126. od.Discount = Math.Round((1 - (itogoSoSkidkoy / itogoBezSkidki)) * 100, 2);
  127. }
  128. if (user.UserRole == 2 || user.UserRole == 3)
  129. orders = BaseClass.C_Base.Order.Include(x => x.PointsOfIssue).Include(x => x.User).Include(x => x.OrderProduct).ToList();
  130. else if (user.UserRole == 1)
  131. orders = BaseClass.C_Base.Order.Include(x => x.PointsOfIssue).Where(x => x.UserID == user.UserID).Include(x => x.OrderProduct).ToList();
  132. switch (Filt.SelectedIndex)
  133. {
  134. case 1:
  135. {
  136. orders = orders.Where(x => x.Discount <= 10).ToList();
  137. break;
  138. }
  139. case 2:
  140. {
  141. orders = orders.Where(x => x.Discount > 10 && x.Discount <= 14).ToList();
  142. break;
  143. }
  144. case 3:
  145. {
  146. orders = orders.Where(x => x.Discount >= 15).ToList();
  147. break;
  148. }
  149. }
  150. switch (Sort.SelectedIndex)
  151. {
  152. case 1:
  153. {
  154. orders = orders.OrderByDescending(x => x.Cost).ToList();
  155. LB_OrderProduct.ItemsSource = orders;
  156. break;
  157. }
  158. case 2:
  159. {
  160. orders = orders.OrderBy(x => x.Cost).ToList();
  161. LB_OrderProduct.ItemsSource = orders;
  162. break;
  163. }
  164. default:
  165. {
  166. break;
  167. }
  168. }
  169. LB_OrderProduct.ItemsSource = orders;
  170. }
  171. }
  172. }