123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- 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 DemoExam
- {
- /// <summary>
- /// Логика взаимодействия для pgAgentsOutput.xaml
- /// </summary>
- public partial class pgAgentsOutput : Page
- {
- DBConnect dbConnect = new DBConnect();
- List<Agent> agents = new List<Agent>();
- List<AgentType> agentTypes = new List<AgentType>();
- public pgAgentsOutput()
- {
- InitializeComponent();
- agents = dbConnect.agentEntities.Agent.ToList();
- lbAgents.ItemsSource = agents;
- agentTypes = dbConnect.agentEntities.AgentType.ToList();
- cbFilter.Items.Add("Все типы");
- cbFilter.SelectedIndex = 0;
- cbSort.Items.Add("Без сортировки");
- cbSort.Items.Add("Наименование (по возрастанию)");
- cbSort.Items.Add("Наименование (по убыванию)");
- cbSort.Items.Add("Размер скидки (по возрастанию)");
- cbSort.Items.Add("Размер скидки (по убыванию)");
- cbSort.Items.Add("Приоритет (по возрастанию)");
- cbSort.Items.Add("Приоритет (по убыванию)");
- cbSort.SelectedIndex = 0;
-
- foreach (var type in agentTypes)
- {
- cbFilter.Items.Add(type.Title);
- }
-
- }
- private void Filters()
- {
-
- if (cbFilter.SelectedIndex != 0)
- {
- agents = dbConnect.agentEntities.Agent.Where(x => x.AgentType.Title == cbFilter.SelectedItem.ToString()).ToList();
- }
- else
- {
- agents = dbConnect.agentEntities.Agent.ToList();
- }
- if (tbSearch.Text.Length > 0)
- {
- agents = agents.Where(x => x.Title.Contains(tbSearch.Text) || x.Email.Contains(tbSearch.Text) || x.Phone.Contains(tbSearch.Text)).ToList();
- }
- switch (cbSort.SelectedIndex)
- {
- case 0:
- {
- if (cbFilter.SelectedIndex != 0)
- {
- agents = dbConnect.agentEntities.Agent.Where(x => x.AgentType.Title == cbFilter.SelectedItem.ToString()).ToList();
- }
- break;
- }
- case 1:
- {
- agents = agents.OrderBy(x => x.Title).ToList();
- break;
- }
- case 2:
- {
- agents = agents.OrderByDescending(x => x.Title).ToList();
- break;
- }
- case 3:
- {
- agents = agents.OrderBy(x => x.Discount).ToList();
- break;
- }
- case 4:
- {
- agents = agents.OrderByDescending(x => x.Discount).ToList();
- break;
- }
- case 5:
- {
- agents = agents.OrderBy(x => x.Priority).ToList();
- break;
- }
- case 6:
- {
- agents = agents.OrderByDescending(x => x.Priority).ToList();
- break;
- }
- }
- lbAgents.ItemsSource = agents;
- }
- private void cbChanged(object sender, SelectionChangedEventArgs e)
- {
- Filters();
- }
- private void tbSearch_TextChanged(object sender, TextChangedEventArgs e)
- {
- Filters();
- }
- private void lbAgents_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if(lbAgents.SelectedItems.Count >= 2)
- {
- btnChangePriority.Visibility = Visibility.Visible;
- }
- }
- private void btnChangePriority_Click(object sender, RoutedEventArgs e)
- {
- List<Agent> selectedAgents = new List<Agent>();
- List<int> ids = new List<int>();
- foreach(var item in lbAgents.SelectedItems)
- {
- selectedAgents.Add(item as Agent);
- }
- windChangePriority windChangePriority = new windChangePriority(selectedAgents);
- windChangePriority.ShowDialog();
- lbAgents.Items.Refresh();
- }
- }
- }
|