using System.ComponentModel;
using System.Text;
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.Navigation;
using System.Windows.Shapes;
using wpf_template.Model;
namespace wpf_template
{
///
/// Interaction logic for MainWindow.xaml
///
///
public partial class MainWindow : Window, INotifyPropertyChanged
{
private IEnumerable _productList;
public IEnumerable ProductList
{
get
{
var res = _productList;
res = _productList
.Where(p =>(selectedCategory == "Все категории" || p.Category == selectedCategory))
.Where(p =>(selectedPrice == null || (p.Price>=selectedPrice.priceFrom && p.Price(selectedCompany == "Все компании" || p.Company == selectedCompany));
if (searchFilter != "")
res = res.Where(c => c.Title.IndexOf(searchFilter, StringComparison.OrdinalIgnoreCase) >= 0);
if (sortAsc) res = res.OrderBy(p => p.Price);
else res = res.OrderByDescending(p => p.Price);
return res;
}
set
{
_productList = value;
}
}
public List CategoryList { get; set; }
public List ProductPrices { get; set; }
public List ProductCompanies { get; set; }
string selectedCategory = "";
string selectedCompany = "";
private ProductPrice? selectedPrice = null;
private string searchFilter = "";
private bool sortAsc = true;
public MainWindow()
{
InitializeComponent();
DataContext = this;
Globals.dataProvider = new CSVDataProvider();
ProductList = Globals.dataProvider.GetProducts();
ProductPrices = Globals.dataProvider.GetPrices().ToList();
CategoryList = Globals.dataProvider.GetCategories().ToList();
CategoryList.Insert(0, new ProductCategory { title = "Все категории" });
ProductCompanies = Globals.dataProvider.GetCompanies().ToList();
ProductCompanies.Insert(0, new ProductCompany { title = "Все компании" });
}
private void ExitButton_Click(object sender, RoutedEventArgs e)
{
Application.Current.Shutdown();
}
private void CategoryFilterComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
selectedCategory = (CategoryFilterComboBox.SelectedItem as ProductCategory).title;
Invalidate();
}
private void PriceFilterComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
selectedPrice = PriceFilterComboBox.SelectedItem as ProductPrice;
Invalidate();
}
private void CompanyFilterComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
selectedCompany = (CompanyFilterComboBox.SelectedItem as ProductCompany).title;
Invalidate();
}
private void SearchFilterTextBox_KeyUp(object sender, KeyEventArgs e)
{
searchFilter = SearchFilterTextBox.Text;
Invalidate();
}
private void RadioButton_Checked(object sender, RoutedEventArgs e)
{
sortAsc = (sender as RadioButton).Tag.ToString() == "1";
Invalidate();
}
public event PropertyChangedEventHandler PropertyChanged;
private void Invalidate()
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("ProductList"));
}
}
class Globals
{
public static IDataProvider dataProvider;
}
}