WindowShop.xaml.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // Подключаемые библиотеки
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Shapes;
  15. namespace Met_Fam
  16. {
  17. /// <summary>
  18. /// Логика взаимодействия для WindowShop.xaml
  19. /// </summary>
  20. public partial class WindowShop : Window
  21. {
  22. Product prd = new Product();
  23. List<Goods> change;
  24. User user = new User();
  25. // Вывод товаров в окно магазина
  26. public WindowShop(User user)
  27. {
  28. this.user = user;
  29. InitializeComponent();
  30. InitializeComponent();
  31. LBAllGoods.ItemsSource = prd.gds.ToList();
  32. LBAllGoods.Items.Refresh();
  33. change = prd.gds;
  34. Filter.ItemsSource = DataBase.BaseModel.Type_Goods.ToList();
  35. Filter.SelectedValuePath = "ID_Type_Goods";
  36. Filter.DisplayMemberPath = "Title_Type_Goods";
  37. Filter.SelectedIndex = -1;
  38. }
  39. // Метод с поисковой строкой, фильтрами и сортировкой
  40. public void Filter_SelectionChanged(object sender, RoutedEventArgs e)
  41. {
  42. change = prd.gds;
  43. if (Filter.SelectedIndex == -1)
  44. {
  45. change = prd.gds;
  46. }
  47. else
  48. {
  49. change = change.Where(x => x.ID_Type_Goods - 1 == Filter.SelectedIndex).ToList();
  50. }
  51. LBAllGoods.ItemsSource = change;
  52. switch (Sort.SelectedIndex)
  53. {
  54. case 0:
  55. change = change.OrderBy(x => x.Title_Goods).ToList();
  56. break;
  57. case 1:
  58. change = change.OrderBy(x => x.Title_Goods).ToList();
  59. change.Reverse();
  60. break;
  61. case 2:
  62. change = change.OrderBy(x => x.Price_Goods).ToList();
  63. break;
  64. case 3:
  65. change = change.OrderBy(x => x.Price_Goods).ToList();
  66. change.Reverse();
  67. break;
  68. }
  69. LBAllGoods.ItemsSource = change;
  70. if (Scan.Text != "")
  71. {
  72. change = change.Where(x => x.Title_Goods.Contains(Scan.Text)).ToList();
  73. }
  74. LBAllGoods.ItemsSource = change;
  75. }
  76. // Кнопка для перехода в Профиль
  77. private void Button_Click(object sender, RoutedEventArgs e)
  78. {
  79. new WindowProf(user).Show();
  80. this.Close();
  81. }
  82. List<Goods> goods = new List<Goods>();
  83. // Кнопка для перехода в корзину
  84. private void Button_Click_1(object sender, RoutedEventArgs e)
  85. {
  86. Window window = new WindowBasket(goods);
  87. window.Show();
  88. this.Close();
  89. }
  90. // Кнопка для добавления товара в корзину
  91. private void Button_Click_2(object sender, RoutedEventArgs e)
  92. {
  93. Button button = (Button)sender;
  94. int id = Convert.ToInt32(button.Uid);
  95. if (goods.FirstOrDefault(x => x.ID_Goods == id) == null)
  96. {
  97. Goods gds = DataBase.BaseModel.Goods.FirstOrDefault(x => x.ID_Goods == id);
  98. goods.Add(gds);
  99. }
  100. else
  101. {
  102. Goods gds = DataBase.BaseModel.Goods.FirstOrDefault(x => x.ID_Goods == id);
  103. goods.Remove(gds);
  104. Goods gds1 = DataBase.BaseModel.Goods.FirstOrDefault(x => x.ID_Goods == id);
  105. goods.Add(gds1);
  106. gds1.CountfForBuing += 1;
  107. }
  108. }
  109. }
  110. }