Orders.xaml.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.SqlClient;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16. using UP_Venediktov.ModelBase;
  17. using UP_Venediktov.Classes;
  18. namespace UP_Venediktov.Pages
  19. {
  20. /// <summary>
  21. /// Логика взаимодействия для Orders.xaml
  22. /// </summary>
  23. public partial class Orders : Page
  24. {
  25. Entities DB = new Entities();
  26. int id;
  27. public Orders(int id)
  28. {
  29. InitializeComponent();
  30. OrderList.ItemsSource = DB.Order.ToList();
  31. SortOrders.ItemsSource = new List<string>() { "Без сортировки", "Сначала дешёвые", "Сначала дорогие" };
  32. FilterOrders.ItemsSource = new List<string>() { "Без фильтрации", "Скидка 0%-10%", "Скидка 10%-15%", "Скидка более 15%" };
  33. SortOrders.SelectedIndex = 0;
  34. FilterOrders.SelectedIndex = 0;
  35. this.id = id;
  36. }
  37. private void WhatInOrder(object sender, RoutedEventArgs e)
  38. {
  39. TextBlock tb = (TextBlock)sender;
  40. int id = Convert.ToInt32(tb.Uid);
  41. string WhatIn = "";
  42. foreach (OrderProduct op in DB.OrderProduct)
  43. {
  44. if (op.OrderID == id)
  45. {
  46. WhatIn += DB.Product.Where(x => x.ProductArticleNumber == op.ProductArticleNumber).Select(x => x.ProductName).FirstOrDefault() + " ";
  47. WhatIn += op.ProductCont + " " + DB.Product.Where(x => x.ProductArticleNumber == op.ProductArticleNumber).Select(x => x.ProductMeasurement.NameMeasurement).FirstOrDefault() + "\n";
  48. }
  49. }
  50. tb.Text = WhatIn;
  51. }
  52. private void OrderCost(object sender, RoutedEventArgs e)
  53. {
  54. TextBlock tb = (TextBlock)sender;
  55. int id = Convert.ToInt32(tb.Uid);
  56. decimal? TotalCost = 0;
  57. foreach (OrderProduct op in DB.OrderProduct)
  58. {
  59. if (op.OrderID == id)
  60. {
  61. TotalCost += DB.Product.Where(x => x.ProductArticleNumber == op.ProductArticleNumber).Select(x => x.ProductCost).FirstOrDefault() *
  62. op.ProductCont;
  63. }
  64. }
  65. tb.Text = "Стоимость заказа: " + string.Format("{0:C2}", TotalCost);
  66. }
  67. private void TotalPromo(object sender, RoutedEventArgs e)
  68. {
  69. TextBlock tb = (TextBlock)sender;
  70. int id = Convert.ToInt32(tb.Uid);
  71. int? Promo = 0;
  72. foreach (OrderProduct op in DB.OrderProduct)
  73. {
  74. if (op.OrderID == id)
  75. {
  76. Promo += DB.Product.Where(x => x.ProductArticleNumber == op.ProductArticleNumber).Select(x => x.ProductDiscountAmount).FirstOrDefault();
  77. }
  78. }
  79. tb.Text = "Общая скидка: " + Promo.ToString() + "%";
  80. }
  81. private void BgrLoad(object sender, RoutedEventArgs e)
  82. {
  83. Border br = (Border)sender;
  84. int id = Convert.ToInt32(br.Uid);
  85. Product pr = DB.OrderProduct.Where(x => x.OrderID == id).Select(x => x.Product).FirstOrDefault();
  86. if (pr.ProductQuantityInStock > 3)
  87. {
  88. br.Background = (SolidColorBrush)new BrushConverter().ConvertFrom("#20b2aa");
  89. }
  90. if (pr.ProductQuantityInStock == 0)
  91. {
  92. br.Background = (SolidColorBrush)new BrushConverter().ConvertFrom("#ff8c00");
  93. }
  94. }
  95. public void Filter()
  96. {
  97. List<Order> UpdateOrders = DB.Order.ToList();
  98. if (SortOrders.SelectedIndex != 0)
  99. {
  100. decimal? TotalCost = 0;
  101. foreach (Order or in UpdateOrders)
  102. {
  103. TotalCost = 0;
  104. foreach (OrderProduct op in DB.OrderProduct)
  105. {
  106. if (op.OrderID == or.OrderID)
  107. {
  108. TotalCost += DB.Product.Where(x => x.ProductArticleNumber == op.ProductArticleNumber).Select(x => x.ProductCost).FirstOrDefault() *
  109. op.ProductCont;
  110. }
  111. }
  112. or.OrderCode = Convert.ToInt32(TotalCost);
  113. }
  114. switch (SortOrders.SelectedIndex)
  115. {
  116. case 1:
  117. UpdateOrders = UpdateOrders.OrderBy(x => x.OrderCode).ToList();
  118. break;
  119. case 2:
  120. UpdateOrders = UpdateOrders.OrderByDescending(x => x.OrderCode).ToList();
  121. break;
  122. default:
  123. break;
  124. }
  125. }
  126. if (FilterOrders.SelectedIndex != 0)
  127. {
  128. int? TotalPromo = 0;
  129. foreach (Order or in UpdateOrders)
  130. {
  131. TotalPromo = 0;
  132. foreach (OrderProduct op in DB.OrderProduct)
  133. {
  134. if (op.OrderID == or.OrderID)
  135. {
  136. TotalPromo += DB.Product.Where(x => x.ProductArticleNumber == op.ProductArticleNumber).Select(x => x.ProductDiscountAmount).FirstOrDefault();
  137. }
  138. }
  139. or.OrderPickupPoint = Convert.ToInt32(TotalPromo);
  140. }
  141. switch (FilterOrders.SelectedIndex)
  142. {
  143. case 1:
  144. UpdateOrders = UpdateOrders.Where(x => x.OrderPickupPoint >= 0 && x.OrderPickupPoint < 10).ToList();
  145. break;
  146. case 2:
  147. UpdateOrders = UpdateOrders.Where(x => x.OrderPickupPoint >= 10 && x.OrderPickupPoint < 15).ToList();
  148. break;
  149. case 3:
  150. UpdateOrders = UpdateOrders.Where(x => x.OrderPickupPoint >= 15).ToList();
  151. break;
  152. default:
  153. break;
  154. }
  155. }
  156. OrderList.ItemsSource = UpdateOrders;
  157. }
  158. private void SortOrFilter(object sender, SelectionChangedEventArgs e)
  159. {
  160. Filter();
  161. }
  162. private void BackToProduct(object sender, RoutedEventArgs e)
  163. {
  164. FrameClass.MainFrame.Navigate(new ProductListUser(id));
  165. }
  166. }
  167. }