using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; 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; namespace WhiteList { /// /// Логика взаимодействия для MainWindow.xaml /// public partial class MainWindow : Window { List _listAgents; public MainWindow() { InitializeComponent(); ComboBoxFilter.Items.Add("Все"); foreach (AgentType at in DB.dbCon.AgentType.ToList()) { ComboBoxFilter.Items.Add(at.Title); } ComboBoxFilter.SelectedIndex = 0; } public void Filt() //фильтрация данных { _listAgents = DB.dbCon.Agent.ToList(); if(TextBoxSearch.Text.Length>0) //по поисковику { string searchStroke = TextBoxSearch.Text.ToLower(); List newList = new List(); foreach(Agent a in _listAgents) { if(a.Title.ToLower().Contains(searchStroke)||a.Email.ToLower().Contains(searchStroke)||a.Phone.ToLower().Contains(searchStroke)) //содержится в почте, названии или номере телефона { newList.Add(a); } } _listAgents = newList; } if(ComboBoxFilter.SelectedIndex>0) { _listAgents = _listAgents.Where(x => x.AgentType.Title == ComboBoxFilter.SelectedValue.ToString()).ToList(); } ListViewDataBase.Items.Clear(); foreach (Agent a in _listAgents) { ListViewDataBase.Items.Add(a); } } private void TextBoxSearch_TextChanged(object sender, TextChangedEventArgs e) { Filt(); } private void ComboBoxFilter_SelectionChanged(object sender, SelectionChangedEventArgs e) { Filt(); } private void ChangePriority_Click(object sender, RoutedEventArgs e) { List selected = new List(); foreach(Agent a in ListViewDataBase.SelectedItems) //получаем из выделенных итемов обьекты таблицы { selected.Add(a); } ChangePriority w = new ChangePriority(selected); w.Owner = this; w.Visibility = Visibility.Visible; w.WindowStartupLocation = WindowStartupLocation.CenterOwner; w.ShowDialog(); ListViewDataBase.Items.Refresh(); //перезагрузка } private void ListViewDataBase_SelectionChanged(object sender, SelectionChangedEventArgs e) //для видимости кнопки { if(ListViewDataBase.SelectedItems.Count>0) { BtnChangePriority.Visibility = Visibility.Visible; } else { BtnChangePriority.Visibility = Visibility.Collapsed; } } private void Add_Click(object sender, RoutedEventArgs e) { AddAndRedactAgent w = new AddAndRedactAgent(); w.Owner = this; w.Visibility = Visibility.Visible; w.WindowStartupLocation = WindowStartupLocation.CenterOwner; w.ShowDialog(); Filt(); } } }