ListPage.xaml.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 WpfApp2.Pages
  16. {
  17. /// <summary>
  18. /// Логика взаимодействия для ListPage.xaml
  19. /// </summary>
  20. public partial class ListPage : Page
  21. {
  22. public List<Book> cart = new List<Book>();
  23. public float sum = 0;
  24. public int count = 0;
  25. public ListPage()
  26. {
  27. InitializeComponent();
  28. list.ItemsSource = DB.data.Books.ToList();
  29. buySum.Text = sum.ToString();
  30. selectedCount.Text = count.ToString();
  31. }
  32. private void Button_Click(object sender, RoutedEventArgs e)
  33. {
  34. var book = (Book)((Button)sender).DataContext;
  35. if (book.countStock == 0 && book.countStrore == 0)
  36. {
  37. MessageBox.Show("Кнмиги нет в наличии!");
  38. return;
  39. }
  40. book.Count++;
  41. if (!cart.Any(a=>a.title == book.title))
  42. {
  43. cart.Add(book);
  44. }
  45. selectedCount.Text = cart.Sum(a=>a.Count).ToString();
  46. sum = (float)cart.Sum(a => a.price * a.Count);
  47. buySum.Text = sum.ToString();
  48. }
  49. private void Button_Click_1(object sender, RoutedEventArgs e)
  50. {
  51. FrameClass.frame.Navigate(new CartPage(cart));
  52. }
  53. }
  54. }