pgBooksCatalog.xaml.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using Calculation;
  2. using System;
  3. using System.Collections.Generic;
  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. namespace Exam19Apr
  17. {
  18. /// <summary>
  19. /// Логика взаимодействия для pgBooksCatalog.xaml
  20. /// </summary>
  21. public partial class pgBooksCatalog : Page
  22. {
  23. int count = 0;
  24. decimal price = 0;
  25. List<Books> books;
  26. int Sale = 0;
  27. public pgBooksCatalog()
  28. {
  29. InitializeComponent();
  30. BaseConnect.BaseModel = new Entities();
  31. lbBooks.ItemsSource = BaseConnect.BaseModel.Books.ToList();
  32. books = new List<Books>();
  33. tbPer.Visibility = Visibility.Collapsed;
  34. tbRub.Visibility = Visibility.Collapsed;
  35. tbSalePrice.Visibility = Visibility.Collapsed;
  36. }
  37. private void btnAddBok_Click(object sender, RoutedEventArgs e)
  38. {
  39. Button btn = (Button)sender;
  40. int id = Convert.ToInt32(btn.Uid);
  41. Books book = BaseConnect.BaseModel.Books.FirstOrDefault(x => x.id == id);
  42. Books checkBook = books.FirstOrDefault(x => x.id == id);
  43. int summ = BaseConnect.BaseModel.Books.Where(x => x.id == id).Sum(x => x.StockCount) + BaseConnect.BaseModel.Books.Where(x => x.id == id).Sum(x => x.StoreCount);
  44. int summList = 0;
  45. if (book.StockCount > 0 || book.StoreCount > 0)
  46. {
  47. if (checkBook == null)
  48. {
  49. checkBook = book;
  50. checkBook.FullCount = 0;
  51. books.Add(checkBook);
  52. }
  53. if (book.StockCount + book.StoreCount > checkBook.FullCount)
  54. {
  55. summList = books.Where(x => x.id == id).Sum(x => x.StockCount) + books.Where(x => x.id == id).Sum(x => x.StoreCount);
  56. checkBook.FullCount++;
  57. count++;
  58. tbCount.Text = count.ToString();
  59. price += book.Price;
  60. tbPrice.Text = price.ToString();
  61. if (tbPrice.Text != "" || tbSalePrice.Text != "")
  62. {
  63. tbRub.Visibility = Visibility.Visible;
  64. }
  65. lbBooks.Items.Refresh();
  66. tbPrice.Text = tbPrice.Text.Replace(".", ",");
  67. Calculator calc = new Calculator();
  68. int countTb = Convert.ToInt32(tbCount.Text);
  69. decimal priceTb = Convert.ToDecimal(tbPrice.Text);
  70. Sale = calc.Calc(priceTb, countTb);
  71. foreach (Books booke in books)
  72. {
  73. booke.Sale = Sale;
  74. }
  75. }
  76. else
  77. MessageBox.Show("Товар нельзя купить!");
  78. }
  79. else
  80. MessageBox.Show("Товар нельзя купить!");
  81. if (Sale > 0 && Sale <= 100)
  82. {
  83. tbPrice.TextDecorations = TextDecorations.Strikethrough;
  84. tbPer.Visibility = Visibility.Visible;
  85. tbSale.Visibility = Visibility.Visible;
  86. tbSalePrice.Visibility = Visibility.Visible;
  87. tbPer.Visibility = Visibility.Visible;
  88. decimal salePrice;
  89. salePrice = Convert.ToDecimal(tbPrice.Text) - Convert.ToDecimal(tbPrice.Text) * (Convert.ToDecimal(Sale) / 100);
  90. tbSalePrice.Text = salePrice.ToString();
  91. tbSale.Text = Sale.ToString();
  92. }
  93. }
  94. private void btnGoCart_Click(object sender, RoutedEventArgs e)
  95. {
  96. LoadPages.goPage.Navigate(new pgTrash(books));
  97. }
  98. }
  99. }