123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- using System;
- using System.Collections.Generic;
- using System.Collections.Specialized;
- using System.ComponentModel;
- using System.Data.Entity;
- using System.Diagnostics;
- 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 ClassLibrary1;
- namespace test
- {
- /// <summary>
- /// Логика взаимодействия для books.xaml
- /// </summary>
- public partial class books : Page
- {
- public int CountTakedBooks { get; set; }
- List<int> korz = new List<int>();
- ViewModel viewModel = new ViewModel();
- int totalcost = 0;
- int TotalSale = 0;
- public string op { get; set; }
- public books()
- {
- InitializeComponent();
- lb.ItemsSource = viewModel.books.ToList();
- lb.Items.Refresh();
- op = "None";
- }
- private void add_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- CountTakedBooks = 0;
- Button button = (Button)sender;
- int id = Convert.ToInt32(button.Uid);
- Books books = Base.Entities.Books.FirstOrDefault(x => x.IdBook == id);
- int ss = books.CountInStock + books.CountInStore;
- if (books.CountInStock == 0 && books.CountInStore == 0)
- {
- throw new Exception("Данной книги нет в наличии.");
- }
- books.CountInCart++;
- if (books.CountInCart > ss)
- {
- throw new Exception("Превышен лимит товара");
- }
- korz.Add(id);
- CountTakedBooks = korz.Count;
- totalcost += Convert.ToInt32(books.Cost);
- Class1 class1 = new Class1();
- TotalSale = class1.sale(korz.Count, totalcost);
- kolbook.Text = korz.Count.ToString();
- price.Text = totalcost.ToString();
- sale.Text = TotalSale.ToString();
- if (TotalSale > 0)
- {
- //op = "Strikethrough";
- //PropertyChanged(this, new PropertyChangedEventArgs("op"));
- newprice.Visibility = Visibility.Visible;
- price.TextDecorations = TextDecorations.Strikethrough;
- }
- double ab = totalcost - (totalcost * TotalSale / 100);
- newprice.Text = Math.Floor(ab).ToString();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- public List<Books> buf3 = new List<Books>();
- public Books buf4;
- private void korz_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- foreach (int y in korz.Distinct().ToList())
- {
- buf4 = Base.Entities.Books.FirstOrDefault(x => x.IdBook == y);
- buf3.Add(buf4);
- }
- ChangePage.Frame.Navigate(new korzinka(buf3, TotalSale));
- }
- catch
- {
- MessageBox.Show("Ошибка");
- }
- }
- }
- }
|