123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- 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
- {
- /// <summary>
- /// Логика взаимодействия для MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- List<Agent> _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<Agent> newList = new List<Agent>();
- 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<Agent> selected = new List<Agent>();
- 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();
- }
- }
- }
|