123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- using System.Collections.Generic;
- 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 WpfApp1.model;
- namespace WpfApp1
- {
- public partial class MainWindow : Window, INotifyPropertyChanged
- {
- public event PropertyChangedEventHandler PropertyChanged;
- private void Invalidate()
- {
- if (PropertyChanged != null)
- PropertyChanged(this, new PropertyChangedEventArgs("ClientList"));
- }
- public string selectedCategory = "Все категории";
- public ClientPrice? selectedPrice = null;
- private IEnumerable<Client> _ClientList;
- public IEnumerable<Client> ClientList
- {
- get
- {
- var res = _ClientList;
- res = res
- .Where(c => (selectedPrice == null || (c.Price >= selectedPrice.PriceFrom && c.Price < selectedPrice.PriceTo)))
- .Where(c => (c.Category == selectedCategory || selectedCategory == "Все категории"));
- if (searchFilter != "")
- res = res.Where(c => c.Name.IndexOf(
- searchFilter,
- StringComparison.OrdinalIgnoreCase) >= 0 || c.Category.IndexOf(
- searchFilter,
- StringComparison.OrdinalIgnoreCase) >= 0 || c.Place.IndexOf(
- searchFilter,
- StringComparison.OrdinalIgnoreCase) >= 0);
- if (sortAsc) res = res.OrderBy(c => c.Price);
- else res = res.OrderByDescending(c => c.Price);
- if (sortAsc) res = res.OrderBy(c => c.Price);
- else res = res.OrderByDescending(c => c.Price);
- return res;
- }
- set
- {
- _ClientList = value;
- }
- }
- public List<Client> Client { get; set; }
- public List<ClientCategory> ClientCategoryList { get; set; }
- public List<ClientPrice> ClientPriceList { get; set; }
- public MainWindow()
- {
- {
- InitializeComponent();
- DataContext = this;
- Globals.dataProvider = new LocalDataProvider();
- ClientList = Globals.dataProvider.getClient();
- ClientPriceList = Globals.dataProvider.getPrice().ToList();
- ClientCategoryList = Globals.dataProvider.getCategory().ToList();
- ClientCategoryList.Insert(0, new ClientCategory() { title = "Все категории" });
- }
- }
- private void ExitButton_Click(object sender, RoutedEventArgs e)
- {
- Application.Current.Shutdown();
- }
- private string searchFilter = "";
- private void SearchFilter_KeyUp(object sender, KeyEventArgs e)
- {
- searchFilter = SearchFilterTextBox.Text;
- Invalidate();
- }
- private void ClientCategoryFilterComboBox_selectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
- {
- selectedCategory = (CategoryFilterComboBox.SelectedItem as ClientCategory).title;
- Invalidate();
- }
- private void ClientPriceFilterComboBox_selectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
- {
- selectedPrice = PriceFilterComboBox.SelectedItem as ClientPrice;
- Invalidate();
- }
- private bool sortAsc = true;
- private void RadioButton_Checked(object sender, RoutedEventArgs e)
- {
- sortAsc = (sender as RadioButton).Tag.ToString() == "1";
- Invalidate();
- }
- private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- }
- }
- interface IDataProvider
- {
- IEnumerable<Client> getClient();
- IEnumerable<ClientPrice> getPrice();
- IEnumerable<ClientCategory> getCategory();
- }
- public class LocalDataProvider : IDataProvider
- {
-
- public IEnumerable<ClientCategory> getCategory()
- {
- return new ClientCategory[]
- {
- new ClientCategory()
- {
- title="По России"
- },
- new ClientCategory()
- {
- title="За границей"
- },
- };
- }
- public IEnumerable<ClientPrice> getPrice()
- {
- return new ClientPrice[]
- {
- new ClientPrice()
- {
- title = "Все цены",
- PriceFrom = 500,
- PriceTo = 30000
- },
- new ClientPrice()
- {
- title = "Низкая цена",
- PriceFrom = 500,
- PriceTo = 3000
- },
- new ClientPrice()
- {
- title = "Средняя цена",
- PriceFrom = 3000,
- PriceTo = 15000
- },
- new ClientPrice()
- {
- title = "Высокая цена",
- PriceFrom = 15000,
- PriceTo = 30000
- }
- };
- }
- public IEnumerable<Client> getClient()
- {
- return new Client[]{
- new Client{
- Name = "Никита",
- Age = 20,
- Price=2300,
- Category="По России",
- Place="Москва"},
- new Client{
- Name = "Маша",
- Age = 15,
- Price=5000,
- Category="По России",
- Place="Сочи"},
- new Client{
- Name = "Алиса",
- Age = 35,
- Price=15000,
- Category="За границей",
- Place="Токио"},
- new Client{
- Name = "Леша",
- Age = 19,
- Price=20000,
- Category="За границей",
- Place="Южная Корея"},
- new Client{
- Name = "Андрей",
- Age = 28,
- Price=3000,
- Category="По России",
- Place="Крым"},
- new Client{
- Name = "Костя",
- Age = 14,
- Price=18000,
- Category="За границей",
- Place="Токио"},
- new Client{
- Name = "Даша",
- Age = 12,
- Price=25000,
- Category="За границей",
- Place="Лондон"},
- new Client{
- Name = "Ольга",
- Age = 55,
- Price=22000,
- Category="За границей",
- Place="Люксембург"},
- new Client{
- Name = "Катя",
- Age = 30,
- Price=1500,
- Category="По России",
- Place="Адлер"},
- new Client{
- Name = "Анжела",
- Age = 61,
- Price=25000,
- Category="За границей",
- Place="Мальдивы"},
- new Client{
- Name = "Миша",
- Age = 17,
- Price=30000,
- Category="За границей",
- Place="Дубаи"},
-
- };
- }
- }
- }
|