BasketPage.xaml.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 Tren.Pages
  16. {
  17. /// <summary>
  18. /// Логика взаимодействия для BasketPage.xaml
  19. /// </summary>
  20. public partial class BasketPage : Page
  21. {
  22. decimal? help;
  23. public BasketPage()
  24. {
  25. InitializeComponent();
  26. BasketList.ItemsSource = CurrentList.basketProducts;
  27. CountOfSelected.Text = (CurrentList.basketProducts.Count).ToString();
  28. CurrentList.priceTotal = 0;
  29. CurrentList.discountTotal = 0;
  30. foreach (Products item in CurrentList.basketProducts)
  31. {
  32. CurrentList.priceTotal += item.Price;
  33. }
  34. help = CurrentList.priceTotal;
  35. while (help > 0)
  36. {
  37. help -= 500;
  38. CurrentList.discountTotal += 1;
  39. }
  40. CurrentList.discountTotal -= 1;
  41. if (CurrentList.basketProducts.Count >= 3 && CurrentList.basketProducts.Count < 5)
  42. {
  43. CurrentList.discountTotal += 5;
  44. }
  45. Price.Text = CurrentList.priceTotal.ToString();
  46. Discount.Text = CurrentList.discountTotal.ToString();
  47. }
  48. private void ClearButton_Click(object sender, RoutedEventArgs e)
  49. {
  50. BasketList.ItemsSource = null;
  51. CurrentList.basketProducts.Clear();
  52. CountOfSelected.Text = (CurrentList.basketProducts.Count).ToString();
  53. CurrentList.priceTotal = 0;
  54. CurrentList.discountTotal = 0;
  55. foreach (Products item in CurrentList.basketProducts)
  56. {
  57. CurrentList.priceTotal += item.Price;
  58. }
  59. help = CurrentList.priceTotal;
  60. while (help > 0)
  61. {
  62. help -= 500;
  63. CurrentList.discountTotal += 1;
  64. }
  65. CurrentList.discountTotal -= 1;
  66. if (CurrentList.basketProducts.Count >= 3 && CurrentList.basketProducts.Count < 5)
  67. {
  68. CurrentList.discountTotal += 5;
  69. }
  70. Price.Text = CurrentList.priceTotal.ToString();
  71. Discount.Text = CurrentList.discountTotal.ToString();
  72. }
  73. private void OrderButton_Click(object sender, RoutedEventArgs e)
  74. {
  75. }
  76. private void BackButton_Click(object sender, RoutedEventArgs e)
  77. {
  78. Manager.frame.Navigate(new MainPage());
  79. }
  80. private void DeleteButton_Click(object sender, RoutedEventArgs e)
  81. {
  82. Products result = (sender as Button)?.DataContext as Products; // получение объекта, который нужно добавить
  83. CurrentList.basketProducts.Remove(result); // добавляем элемент в лист корзины
  84. BasketList.ItemsSource = null;
  85. BasketList.ItemsSource = CurrentList.basketProducts;
  86. CountOfSelected.Text = (CurrentList.basketProducts.Count).ToString();
  87. CurrentList.priceTotal = 0;
  88. CurrentList.discountTotal = 0;
  89. foreach (Products item in CurrentList.basketProducts)
  90. {
  91. CurrentList.priceTotal += item.Price;
  92. }
  93. help = CurrentList.priceTotal;
  94. while (help > 0)
  95. {
  96. help -= 500;
  97. CurrentList.discountTotal += 1;
  98. }
  99. CurrentList.discountTotal -= 1;
  100. if (CurrentList.basketProducts.Count >= 3 && CurrentList.basketProducts.Count < 5)
  101. {
  102. CurrentList.discountTotal += 5;
  103. }
  104. Price.Text = CurrentList.priceTotal.ToString();
  105. Discount.Text = CurrentList.discountTotal.ToString();
  106. }
  107. }
  108. }