123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- 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;
- using System.Threading.Tasks;
- using System;
- using WpfApp1.model;
- using WpfApp1.model;
- using WpfApp1.model;
- namespace WpfApp1
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window, INotifyPropertyChanged
- {
- public event PropertyChangedEventHandler PropertyChanged;
- private void Invalidate()
- {
- if (PropertyChanged != null)
- PropertyChanged(this, new PropertyChangedEventArgs("WorkerList"));
- }
- public string selectedPos = "Должность";
- public WorkerAge? selectedAge = null;
- public string selectedSex = "Пол";
-
- private IEnumerable<Worker> _WorkerList;
- public IEnumerable<Worker> WorkerList
- {
- get
- {
- var res = _WorkerList;
- res = res
- .Where(c => (c.Pos == selectedPos || selectedPos == "Должность"))
- .Where(c => (selectedAge == null || (c.Age >= selectedAge.AgeFrom && c.Age < selectedAge.AgeTo)))
- .Where(c => (c.Sex == selectedSex || selectedSex == "Пол"));
- if (searchFilter != "")
- res = res.Where(c => c.name.IndexOf(
- searchFilter,
- StringComparison.OrdinalIgnoreCase) >= 0);
- if (sortAsc) res = res.OrderBy(c => c.Age);
- else res = res.OrderByDescending(c => c.Age);
- return res;
- }
- set
- {
- _WorkerList = value;
- }
- }
-
- public List<WorkerPos> WorkerPosList { get; set; }
- public List<WorkerAge> WorkerAgeList { get; set; }
- public List<WorkerSex> WorkerSexList { get; set; }
- public MainWindow()
- {
- InitializeComponent();
- DataContext = this;
- Globals.dataProvider = new LocalDataProvider();
- WorkerList = Globals.dataProvider.getWorker();
- WorkerPosList = Globals.dataProvider.getPos().ToList();
- WorkerPosList.Insert(0, new WorkerPos { title = "Должность" });
- WorkerAgeList = Globals.dataProvider.getAge().ToList();
- WorkerSexList = Globals.dataProvider.getSex().ToList();
- WorkerSexList.Insert(0, new WorkerSex { title = "Пол" });
- Globals.dataProvider = new CSVDataProvider();
- WorkerList = Globals.dataProvider.getWorker();
- }
-
- private void ExitButton_Click(object sender, RoutedEventArgs e)
- {
- Application.Current.Shutdown();
- }
- private void PosFilterComboBox_SelectionChanged_1(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
- {
- selectedPos = (PosFilterComboBox.SelectedItem as WorkerPos).title;
- Invalidate();
- }
- private void AgeFilterComboBox_SelectionChanged_2(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
- {
- selectedAge = (AgeFilterComboBox.SelectedItem as WorkerAge);
- Invalidate();
- }
- private void SexFilterComboBox_SelectionChanged_3(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
- {
- selectedSex = (SexFilterComboBox.SelectedItem as WorkerSex).title;
- Invalidate();
- }
- private string searchFilter = "";
- private void SearchFilter_KeyUp(object sender, KeyEventArgs e)
- {
- searchFilter = SearchFilterTextBox.Text;
- Invalidate();
- }
- private bool sortAsc = true;
- private void RadioButton_Checked(object sender, RoutedEventArgs e)
- {
- sortAsc = (sender as RadioButton).Tag.ToString() == "1";
- Invalidate();
- }
- }
- interface IDataProvider
- {
- IEnumerable<Worker> getWorker();
- IEnumerable<WorkerPos> getPos();
- IEnumerable<WorkerAge> getAge();
- IEnumerable<WorkerSex> getSex();
- }
- public class LocalDataProvider : IDataProvider
- {
- public IEnumerable<WorkerPos> getPos()
- {
- return new WorkerPos[]
- {
- new WorkerPos()
- {
- title="Директор"
- },
- new WorkerPos()
- {
- title="Продавец"
- },
- new WorkerPos()
- {
- title="Механик"
- },
- new WorkerPos()
- {
- title="Уборщик"
- },
- new WorkerPos()
- {
- title="Стажер"
- },
- new WorkerPos()
- {
- title="Оператор"
- },
- };
- }
- public IEnumerable<WorkerAge> getAge()
- {
- return new WorkerAge[]
- {
- new WorkerAge()
- {
- title="Все возраста",
- AgeFrom=0,
- AgeTo=110
- },
- new WorkerAge()
- {
- title="Дети",
- AgeFrom=1,
- AgeTo=6
- },
- new WorkerAge()
- {
- title="Подростки",
- AgeFrom=7,
- AgeTo=21
- },
- new WorkerAge()
- {
- title="Молодые",
- AgeFrom=22,
- AgeTo=50
- },
- new WorkerAge()
- {
- title="Старики",
- AgeFrom=51,
- AgeTo=110
- }
- };
- }
- public IEnumerable<WorkerSex> getSex()
- {
- return new WorkerSex[]
- {
- new WorkerSex()
- {
- title="Человек"
- },
- new WorkerSex()
- {
- title="Женщина"
- }
- };
- }
- public IEnumerable<Worker> getWorker()
- {
- return new Worker[]{
- new Worker{
- Sex="Человек",
- name="Вася",
- Age=25,
- Pos="Директор"},
- new Worker{
- Sex="Человек",
- name="Петя",
- Age=45,
- Pos="Продавец"},
- new Worker{
- Sex="Человек",
- name="Степа",
- Age = 30,
- Pos="Механик"},
- new Worker{
- Sex="Человек",
- name="Миша",
- Age = 100,
- Pos="Стажер"},
- new Worker{
- Sex="Женщина",
- name="Лена",
- Age = 12,
- Pos="Оператор"}
- };
- }
- }
- }
|