ShowProductPage.xaml.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 Write_erase.Classes;
  16. namespace Write_erase.ManagerPages
  17. {
  18. /// <summary>
  19. /// Логика взаимодействия для ShowProductPage.xaml
  20. /// </summary>
  21. public partial class ShowProductPage : Page
  22. {
  23. List<Product> products = DataBaseClass.entity.Product.ToList();
  24. public ShowProductPage(int id)
  25. {
  26. InitializeComponent();
  27. List<User> users = DataBaseClass.entity.User.Where(x => x.UserID == id).ToList();
  28. foreach (User user in users)
  29. {
  30. FIO.Text = user.UserPatronymic + " " + user.UserName + " " + user.UserSurname;
  31. }
  32. ProductPanelUser.ItemsSource = DataBaseClass.entity.Product.ToList();
  33. CBDiscount.Items.Add("Все диапазоны");
  34. CBDiscount.Items.Add("0-9,99%");
  35. CBDiscount.Items.Add("10-14,99%");
  36. CBDiscount.Items.Add("15% и более");
  37. CBDiscount.SelectedIndex = 0;
  38. TBShowAll.Text = "Всего товаров: " + DataBaseClass.entity.Product.ToList().Count;
  39. }
  40. private void Filter()
  41. {
  42. switch (CBDiscount.SelectedIndex)
  43. {
  44. case 0: products = DataBaseClass.entity.Product.ToList(); break;
  45. case 1: products = DataBaseClass.entity.Product.Where(x => x.ProductDiscountAmount / 100 < 0.0999).ToList(); break;
  46. case 2: products = DataBaseClass.entity.Product.Where(x => x.ProductDiscountAmount / 100 >= 10 && x.ProductDiscountAmount / 100 < 0.1499).ToList(); break;
  47. case 3: products = DataBaseClass.entity.Product.Where(x => x.ProductDiscountAmount / 100 >= 0.15).ToList(); break;
  48. }
  49. ProductPanelUser.ItemsSource = products;
  50. TBShowPart.Text = "Показано предложений: " + products.Count;
  51. }
  52. private void Sorter()
  53. {
  54. if (!string.IsNullOrWhiteSpace(TBXSearch.Text))
  55. {
  56. products = DataBaseClass.entity.Product.Where(x => x.ProductName.ToLower().Contains(TBXSearch.Text.ToLower())).ToList();
  57. }
  58. if (RBUp.IsChecked == true)
  59. {
  60. products.Sort((x, y) => x.ProductCost.CompareTo(y.ProductCost));
  61. }
  62. else if (RBDown.IsChecked == true)
  63. {
  64. products.Sort((x, y) => x.ProductCost.CompareTo(y.ProductCost));
  65. products.Reverse();
  66. }
  67. else if (RBDefault.IsChecked == true)
  68. {
  69. products.Sort((x, y) => x.ProductArticleNumber.CompareTo(y.ProductArticleNumber));
  70. }
  71. if (products.Count == 0)
  72. {
  73. MessageBox.Show("Товаров с таким диапазоном скидок нет");
  74. }
  75. ProductPanelUser.ItemsSource = products;
  76. TBShowPart.Text = "Показано предложений: " + products.Count;
  77. }
  78. private void RBUp_Click(object sender, RoutedEventArgs e)
  79. {
  80. Sorter();
  81. }
  82. private void RBDown_Click(object sender, RoutedEventArgs e)
  83. {
  84. Sorter();
  85. }
  86. private void RBDefault_Click(object sender, RoutedEventArgs e)
  87. {
  88. Sorter();
  89. }
  90. private void CBDiscount_SelectionChanged(object sender, SelectionChangedEventArgs e)
  91. {
  92. Filter();
  93. }
  94. private void TBXSearch_TextChanged(object sender, TextChangedEventArgs e)
  95. {
  96. Sorter();
  97. }
  98. }
  99. }