using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using ClassLibrary_CountingSale; namespace modulekz { /// /// Логика взаимодействия для ListBook.xaml /// public partial class ListBook : Page { VModel VM = new VModel(); double sale = 0; int kol_vo = 0; List tableBooks = new List(); public ListBook(List books) { InitializeComponent(); sale = 0; tableBooks = books; ListBooks.ItemsSource = VM.books; int ii = 0; double c = 0; foreach (Book b in books) { ii += b.inc; sale = b.sale; c += Math.Floor(Convert.ToDouble(b.Cost) * b.inc); } kol_vo = ii; RKol_v.Text = kol_vo.ToString(); Rsale.Text = sale.ToString(); FirstCost.Text = c.ToString(); if (sale > 0) { FirstCost.TextDecorations = TextDecorations.Strikethrough; SecCost.Text = Math.Floor(c - c * (sale / 100)).ToString(); } } /// /// Переход в корзину /// /// /// private void Gocart_Click(object sender, RoutedEventArgs e) { LoadPage.MainFrame.Navigate(new Cart(tableBooks, sale)); } /// /// Добавление позиции в корзину /// /// /// private void AddCart_Click(object sender, RoutedEventArgs e) { System.Windows.Controls.Button btn = sender as System.Windows.Controls.Button; int uid = Convert.ToInt32(btn.Uid); AddCart(uid); } /// /// Модуль пересчета стоимости, скидки, количества позиции /// /// public void AddCart(int i) { List bl; try { bl = BaseConnect.BaseModel.Book.ToList(); Book book = BaseConnect.BaseModel.Book.FirstOrDefault(x => x.Id == i); if ((book.Stock < 0) && (book.Store < 0)) { MessageBox.Show("Данного товара на данный момент нет!"); throw new Exception(); } else if (book.inc == (book.Stock + book.Store)) { MessageBox.Show("Превышен лимит"); throw new Exception(); } book.inc += 1; kol_vo += 1; RKol_v.Text = kol_vo.ToString(); double c = 0; foreach (Book b in bl) { c += Math.Floor(Convert.ToDouble(b.Cost) * b.inc); } FirstCost.Text = c.ToString(); sale = SaleCount.saleCount(kol_vo, c); Rsale.Text = sale.ToString(); if (sale > 0) { FirstCost.TextDecorations = TextDecorations.Strikethrough; SecCost.Text = Math.Floor((c - c * (sale / 100))).ToString(); } book.sale = sale; tableBooks.Remove(book); tableBooks.Add(book); } catch { } bl = BaseConnect.BaseModel.Book.ToList(); } } }