MainPage.xaml.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. /// Логика взаимодействия для MainPage.xaml
  19. /// </summary>
  20. public partial class MainPage : Page
  21. {
  22. public MainPage()
  23. {
  24. InitializeComponent();
  25. CurrentList.products = CurrentList.db.Products
  26. .ToList();
  27. MainList.ItemsSource = CurrentList.products;
  28. if (CurrentList.basketProducts.Count != 0)
  29. {
  30. BasketButton.Visibility = Visibility.Visible;
  31. CurrentList.priceTotal = 0;
  32. CurrentList.discountTotal = 0;
  33. CountOfSelected.Text = (CurrentList.basketProducts.Count).ToString();
  34. foreach (Products item in CurrentList.basketProducts)
  35. {
  36. CurrentList.priceTotal += item.Price;
  37. }
  38. help = CurrentList.priceTotal;
  39. while (help > 0)
  40. {
  41. help -= 500;
  42. CurrentList.discountTotal += 1;
  43. }
  44. CurrentList.discountTotal -= 1;
  45. if (CurrentList.basketProducts.Count >= 3 && CurrentList.basketProducts.Count < 5)
  46. {
  47. CurrentList.discountTotal += 5;
  48. }
  49. Price.Text = CurrentList.priceTotal.ToString();
  50. Discount.Text = CurrentList.discountTotal.ToString();
  51. }
  52. }
  53. private void Button_Click(object sender, RoutedEventArgs e)
  54. {
  55. Manager.frame.Navigate(new BasketPage());
  56. }
  57. decimal? help;
  58. private void MenuItem_Click(object sender, RoutedEventArgs e)
  59. {
  60. BasketButton.Visibility = Visibility.Visible;
  61. CurrentList.basketProducts.Add(MainList.SelectedValue as Products);
  62. Products product = MainList.SelectedValue as Products;
  63. CountOfSelected.Text = (CurrentList.basketProducts.Count).ToString();
  64. CurrentList.priceTotal += product.Price;
  65. help = CurrentList.priceTotal;
  66. while (help > 0)
  67. {
  68. help -= 500;
  69. CurrentList.discountTotal += 1;
  70. }
  71. CurrentList.discountTotal -= 1;
  72. if (CurrentList.basketProducts.Count >= 3 && CurrentList.basketProducts.Count < 5)
  73. {
  74. CurrentList.discountTotal += 5;
  75. }
  76. Price.Text = CurrentList.priceTotal.ToString();
  77. Discount.Text = CurrentList.discountTotal.ToString();
  78. }
  79. }
  80. }