12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- 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
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- ///
- public partial class MainWindow : Window, INotifyPropertyChanged
- {
- private IEnumerable<Product> _productList;
- public IEnumerable<Product> ProductList
- {
- get
- {
- return _productList
- .Where(p =>(selectedCategory == "Все категории" || p.Category == selectedCategory))
- .Where(p =>(selectedPrice == null || (p.Price>=selectedPrice.priceFrom && p.Price<selectedPrice.priceTo)))
- .Where(p =>(selectedCompany == "Все компании" || p.Company == selectedCompany));
- }
- set
- {
- _productList = value;
- }
- }
- public List <ProductCategory> CategoryList { get; set; }
- public List <ProductPrice> ProductPrices { get; set; }
- public List <ProductCompany> ProductCompanies { get; set; }
- string selectedCategory = "";
- string selectedCompany = "";
- private ProductPrice? selectedPrice = null;
- public MainWindow()
- {
- InitializeComponent();
- DataContext = this;
- Globals.dataProvider = new LocalDataProvider();
- 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();
- }
- public event PropertyChangedEventHandler PropertyChanged;
- private void Invalidate()
- {
- if (PropertyChanged != null)
- PropertyChanged(this, new PropertyChangedEventArgs("ProductList"));
- }
- }
- class Globals
- {
- public static IDataProvider dataProvider;
- }
- }
|