Zakaz.xaml.cs 6.6 KB

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