books.xaml.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.Specialized;
  4. using System.ComponentModel;
  5. using System.Data.Entity;
  6. using System.Diagnostics;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Controls;
  12. using System.Windows.Data;
  13. using System.Windows.Documents;
  14. using System.Windows.Input;
  15. using System.Windows.Media;
  16. using System.Windows.Media.Imaging;
  17. using System.Windows.Navigation;
  18. using System.Windows.Shapes;
  19. using ClassLibrary1;
  20. namespace test
  21. {
  22. /// <summary>
  23. /// Логика взаимодействия для books.xaml
  24. /// </summary>
  25. public partial class books : Page
  26. {
  27. public int CountTakedBooks { get; set; }
  28. List<int> korz = new List<int>();
  29. ViewModel viewModel = new ViewModel();
  30. int totalcost = 0;
  31. int TotalSale = 0;
  32. public string op { get; set; }
  33. public books()
  34. {
  35. InitializeComponent();
  36. lb.ItemsSource = viewModel.books.ToList();
  37. lb.Items.Refresh();
  38. op = "None";
  39. }
  40. private void add_Click(object sender, RoutedEventArgs e)
  41. {
  42. try
  43. {
  44. CountTakedBooks = 0;
  45. Button button = (Button)sender;
  46. int id = Convert.ToInt32(button.Uid);
  47. Books books = Base.Entities.Books.FirstOrDefault(x => x.IdBook == id);
  48. int ss = books.CountInStock + books.CountInStore;
  49. if (books.CountInStock == 0 && books.CountInStore == 0)
  50. {
  51. throw new Exception("Данной книги нет в наличии.");
  52. }
  53. books.CountInCart++;
  54. if (books.CountInCart > ss)
  55. {
  56. throw new Exception("Превышен лимит товара");
  57. }
  58. korz.Add(id);
  59. CountTakedBooks = korz.Count;
  60. totalcost += Convert.ToInt32(books.Cost);
  61. Class1 class1 = new Class1();
  62. TotalSale = class1.sale(korz.Count, totalcost);
  63. kolbook.Text = korz.Count.ToString();
  64. price.Text = totalcost.ToString();
  65. sale.Text = TotalSale.ToString();
  66. if (TotalSale > 0)
  67. {
  68. //op = "Strikethrough";
  69. //PropertyChanged(this, new PropertyChangedEventArgs("op"));
  70. newprice.Visibility = Visibility.Visible;
  71. price.TextDecorations = TextDecorations.Strikethrough;
  72. }
  73. double ab = totalcost - (totalcost * TotalSale / 100);
  74. newprice.Text = Math.Floor(ab).ToString();
  75. }
  76. catch (Exception ex)
  77. {
  78. MessageBox.Show(ex.Message);
  79. }
  80. }
  81. public List<Books> buf3 = new List<Books>();
  82. public Books buf4;
  83. private void korz_Click(object sender, RoutedEventArgs e)
  84. {
  85. try
  86. {
  87. foreach (int y in korz.Distinct().ToList())
  88. {
  89. buf4 = Base.Entities.Books.FirstOrDefault(x => x.IdBook == y);
  90. buf3.Add(buf4);
  91. }
  92. ChangePage.Frame.Navigate(new korzinka(buf3, TotalSale));
  93. }
  94. catch
  95. {
  96. MessageBox.Show("Ошибка");
  97. }
  98. }
  99. }
  100. }