123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- // Подключаемые библиотеки
- 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.Shapes;
- namespace Met_Fam
- {
- /// <summary>
- /// Логика взаимодействия для WindowShop.xaml
- /// </summary>
- public partial class WindowShop : Window
- {
- Product prd = new Product();
- List<Goods> change;
- User user = new User();
- // Вывод товаров в окно магазина
- public WindowShop(User user)
- {
- this.user = user;
- InitializeComponent();
- InitializeComponent();
- LBAllGoods.ItemsSource = prd.gds.ToList();
- LBAllGoods.Items.Refresh();
- change = prd.gds;
- Filter.ItemsSource = DataBase.BaseModel.Type_Goods.ToList();
- Filter.SelectedValuePath = "ID_Type_Goods";
- Filter.DisplayMemberPath = "Title_Type_Goods";
- Filter.SelectedIndex = -1;
- }
- // Метод с поисковой строкой, фильтрами и сортировкой
- public void Filter_SelectionChanged(object sender, RoutedEventArgs e)
- {
- change = prd.gds;
- if (Filter.SelectedIndex == -1)
- {
- change = prd.gds;
- }
- else
- {
- change = change.Where(x => x.ID_Type_Goods - 1 == Filter.SelectedIndex).ToList();
- }
- LBAllGoods.ItemsSource = change;
- switch (Sort.SelectedIndex)
- {
- case 0:
- change = change.OrderBy(x => x.Title_Goods).ToList();
- break;
- case 1:
- change = change.OrderBy(x => x.Title_Goods).ToList();
- change.Reverse();
- break;
- case 2:
- change = change.OrderBy(x => x.Price_Goods).ToList();
- break;
- case 3:
- change = change.OrderBy(x => x.Price_Goods).ToList();
- change.Reverse();
- break;
- }
- LBAllGoods.ItemsSource = change;
- if (Scan.Text != "")
- {
- change = change.Where(x => x.Title_Goods.Contains(Scan.Text)).ToList();
- }
- LBAllGoods.ItemsSource = change;
- }
- // Кнопка для перехода в Профиль
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- new WindowProf(user).Show();
- this.Close();
- }
- List<Goods> goods = new List<Goods>();
- // Кнопка для перехода в корзину
- private void Button_Click_1(object sender, RoutedEventArgs e)
- {
- Window window = new WindowBasket(goods);
- window.Show();
- this.Close();
- }
- // Кнопка для добавления товара в корзину
- private void Button_Click_2(object sender, RoutedEventArgs e)
- {
- Button button = (Button)sender;
- int id = Convert.ToInt32(button.Uid);
- if (goods.FirstOrDefault(x => x.ID_Goods == id) == null)
- {
- Goods gds = DataBase.BaseModel.Goods.FirstOrDefault(x => x.ID_Goods == id);
- goods.Add(gds);
- }
- else
- {
- Goods gds = DataBase.BaseModel.Goods.FirstOrDefault(x => x.ID_Goods == id);
- goods.Remove(gds);
- Goods gds1 = DataBase.BaseModel.Goods.FirstOrDefault(x => x.ID_Goods == id);
- goods.Add(gds1);
- gds1.CountfForBuing += 1;
- }
- }
- }
- }
|