ListBook.xaml.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. using ClassLibrary_CountingSale;
  16. namespace modulekz
  17. {
  18. /// <summary>
  19. /// Логика взаимодействия для ListBook.xaml
  20. /// </summary>
  21. public partial class ListBook : Page
  22. {
  23. VModel VM = new VModel();
  24. double sale = 0;
  25. int kol_vo = 0;
  26. List<Book> tableBooks = new List<Book>();
  27. public ListBook(List<Book> books)
  28. {
  29. InitializeComponent();
  30. sale = 0;
  31. tableBooks = books;
  32. ListBooks.ItemsSource = VM.books;
  33. int ii = 0;
  34. double c = 0;
  35. foreach (Book b in books)
  36. {
  37. ii += b.inc;
  38. sale = b.sale;
  39. c += Math.Floor(Convert.ToDouble(b.Cost) * b.inc);
  40. }
  41. kol_vo = ii;
  42. RKol_v.Text = kol_vo.ToString();
  43. Rsale.Text = sale.ToString();
  44. FirstCost.Text = c.ToString();
  45. if (sale > 0)
  46. {
  47. FirstCost.TextDecorations = TextDecorations.Strikethrough;
  48. SecCost.Text = Math.Floor(c - c * (sale / 100)).ToString();
  49. }
  50. }
  51. /// <summary>
  52. /// Переход в корзину
  53. /// </summary>
  54. /// <param name="sender"></param>
  55. /// <param name="e"></param>
  56. private void Gocart_Click(object sender, RoutedEventArgs e)
  57. {
  58. LoadPage.MainFrame.Navigate(new Cart(tableBooks, sale));
  59. }
  60. /// <summary>
  61. /// Добавление позиции в корзину
  62. /// </summary>
  63. /// <param name="sender"></param>
  64. /// <param name="e"></param>
  65. private void AddCart_Click(object sender, RoutedEventArgs e)
  66. {
  67. System.Windows.Controls.Button btn = sender as System.Windows.Controls.Button;
  68. int uid = Convert.ToInt32(btn.Uid);
  69. AddCart(uid);
  70. }
  71. /// <summary>
  72. /// Модуль пересчета стоимости, скидки, количества позиции
  73. /// </summary>
  74. /// <param name="i"></param>
  75. public void AddCart(int i)
  76. {
  77. List<Book> bl;
  78. try
  79. {
  80. bl = BaseConnect.BaseModel.Book.ToList();
  81. Book book = BaseConnect.BaseModel.Book.FirstOrDefault(x => x.Id == i);
  82. if ((book.Stock < 0) && (book.Store < 0))
  83. {
  84. MessageBox.Show("Данного товара на данный момент нет!");
  85. throw new Exception();
  86. }
  87. else if (book.inc == (book.Stock + book.Store))
  88. {
  89. MessageBox.Show("Превышен лимит");
  90. throw new Exception();
  91. }
  92. book.inc += 1;
  93. kol_vo += 1;
  94. RKol_v.Text = kol_vo.ToString();
  95. double c = 0;
  96. foreach (Book b in bl)
  97. {
  98. c += Math.Floor(Convert.ToDouble(b.Cost) * b.inc);
  99. }
  100. FirstCost.Text = c.ToString();
  101. sale = SaleCount.saleCount(kol_vo, c);
  102. Rsale.Text = sale.ToString();
  103. if (sale > 0)
  104. {
  105. FirstCost.TextDecorations = TextDecorations.Strikethrough;
  106. SecCost.Text = Math.Floor((c - c * (sale / 100))).ToString();
  107. }
  108. book.sale = sale;
  109. tableBooks.Remove(book);
  110. tableBooks.Add(book);
  111. }
  112. catch { }
  113. bl = BaseConnect.BaseModel.Book.ToList();
  114. }
  115. }
  116. }