// Подключаемые библиотеки
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
{
///
/// Логика взаимодействия для WindowShop.xaml
///
public partial class WindowShop : Window
{
Product prd = new Product();
List 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 = new List();
// Кнопка для перехода в корзину
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;
}
}
}
}