123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- using System.Windows;
- using System.ComponentModel;
- using System.Collections.Generic;
- using WpfApp1.SQL;
- using System;
- using System.Linq;
- using System.Windows.Input;
- using System.Windows.Controls;
- using WpfApp1.AddEdit;
- namespace WpfApp1
- {
- /// <summary>
- /// Логика взаимодействия для MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window, INotifyPropertyChanged
- {
- public event PropertyChangedEventHandler PropertyChanged;
- public List<string> sortList
- {
- get => Items.sortList.ToList();
- }
- private List<Agent> _AgentList;
- public List<Agent> AgentList
- {
- get
- {
- List<Agent> agentList = _AgentList;
- if (SearchText != null)
- agentList = agentList.Where(item => item.Title.IndexOf(SearchText, StringComparison.OrdinalIgnoreCase) != -1).ToList();
- if (SortList && ChooseSortItem == 0)
- return agentList.OrderBy(items => items.Title).ToList();
- else if (SortList && ChooseSortItem == 1)
- return agentList.OrderBy(items => items.Title).ToList();
- else if (SortList && ChooseSortItem == 2)
- return agentList.OrderBy(items => items.Priority).ToList();
- else if (!SortList && ChooseSortItem == 0)
- return agentList.OrderBy(items => items.Title).ToList();
- else if (!SortList && ChooseSortItem == 1)
- return agentList.OrderBy(items => items.Title).ToList();
- else
- return agentList.OrderByDescending(items => items.Priority).ToList();
- }
- set
- {
- _AgentList = value;
- if (PropertyChanged != null)
- {
- PropertyChanged(this, new PropertyChangedEventArgs("AgentList"));
- PropertyChanged(this, new PropertyChangedEventArgs("SortList"));
- }
- }
- }
- private string _SearchText;
- public string SearchText
- {
- get => _SearchText;
- set
- {
- _SearchText = value;
- if (PropertyChanged != null)
- {
- PropertyChanged(this, new PropertyChangedEventArgs("AgentList"));
- PropertyChanged(this, new PropertyChangedEventArgs("SearchText"));
- }
- }
- }
- private byte _ChooseSortItem;
- public byte ChooseSortItem
- {
- get => _ChooseSortItem;
- set
- {
- _ChooseSortItem = value;
- if (PropertyChanged != null)
- {
- PropertyChanged(this, new PropertyChangedEventArgs("ChooseSortItem"));
- PropertyChanged(this, new PropertyChangedEventArgs("AgentList"));
- }
- }
- }
- private bool _SortList = false;
- public bool SortList
- {
- get => _SortList;
- set
- {
- _SortList = value;
- if (PropertyChanged != null)
- {
- PropertyChanged(this, new PropertyChangedEventArgs("SortList"));
- PropertyChanged(this, new PropertyChangedEventArgs("AgentList"));
- PropertyChanged(this, new PropertyChangedEventArgs("GetContentButtonSort"));
- }
- }
- }
- public string GetContentButtonSort
- {
- get => SortList ? "По возрастанию" : "По убыванию";
- }
- public MainWindow()
- {
- InitializeComponent();
- AgentList = Base.EM.Agent.ToList();
- DataContext = this;
- }
- private void TextBox_Name_KeyUp(object sender, KeyEventArgs e)
- {
- SearchText = TextBox_Name.Text;
- }
- private void Button_Sort_Click(object sender, RoutedEventArgs e)
- {
- if (SortList)
- SortList = false;
- else SortList = true;
- }
- private void ComboBox_Sort_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- ChooseSortItem = (byte)ComboBox_Sort.SelectedIndex;
- }
- private void DataView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
- {
- Agent item = ListView_Agent.SelectedItem as Agent;
- AddEditItems aei = new AddEditItems(item);
- if (aei.ShowDialog() == true)
- {
- AgentList = Base.EM.Agent.ToList();
- PropertyChanged(this, new PropertyChangedEventArgs("AgentList"));
- }
- }
- private void Button_Add_Click(object sender, RoutedEventArgs e)
- {
- Agent item = new Agent();
- AddEditItems aei = new AddEditItems(item);
- if (aei.ShowDialog() == true)
- {
- AgentList = Base.EM.Agent.ToList();
- PropertyChanged(this, new PropertyChangedEventArgs("AgentList"));
- }
- }
- private void Button_Exit_Click(object sender, RoutedEventArgs e) => Application.Current.Shutdown();
- }
- }
|