123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- 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;
- using DemoexamUser11.classes;
- using DemoexamUser11.windows;
- namespace DemoexamUser11.pages
- {
- /// <summary>
- /// Логика взаимодействия для AgentsList.xaml
- /// </summary>
- public partial class AgentsList : Page
- {
- List<string> sortList = new List<string>() { "Наименование", "Размер скидки", "Приоритет" };
- List<Agent> agents = BaseConnector.BaseConnect.Agent.ToList();
- List<Agent> agentsForFilters = BaseConnector.BaseConnect.Agent.ToList();
- List<AgentType> agentTypes = BaseConnector.BaseConnect.AgentType.ToList();
- public AgentsList()
- {
- InitializeComponent();
- listBoxAgents.ItemsSource = agents;
- agentTypes.Add(new AgentType { ID = 9999, Title = "Все типы" });
- comboBoxFilter.ItemsSource = agentTypes;
- comboBoxFilter.DisplayMemberPath = "Title";
- comboBoxFilter.SelectedValuePath = "ID";
- comboBoxFilter.SelectedIndex = comboBoxFilter.Items.Count - 1;
- comboBoxSort.ItemsSource = sortList;
- }
- private void Search(object sender, TextChangedEventArgs e)
- {
- if (textBoxSearch.Text.Replace(" ", "") != "")
- {
- try
- {
- agentsForFilters = agentsForFilters.Where(x => x.Title.Contains(textBoxSearch.Text) || x.Phone.Contains(textBoxSearch.Text) || x.Email.Contains(textBoxSearch.Text)).ToList();
- listBoxAgents.ItemsSource = agentsForFilters;
- }
- catch
- {
- MessageBox.Show("Не удалось выполнить поиск!");
- }
- }
- if (textBoxSearch.Text.Replace(" ", "") == "" && (int)comboBoxFilter.SelectedValue == 9999)
- {
- listBoxAgents.ItemsSource = agents;
- agentsForFilters = BaseConnector.BaseConnect.Agent.ToList();
- }
- else if (textBoxSearch.Text.Replace(" ", "") == "" && (int)comboBoxFilter.SelectedValue != 9999)
- {
- listBoxAgents.ItemsSource = agents.Where(x => x.AgentTypeID == (int)comboBoxFilter.SelectedValue).ToList();
- agentsForFilters = BaseConnector.BaseConnect.Agent.ToList();
- }
- }
- private void Filter(object sender, SelectionChangedEventArgs e)
- {
- if (comboBoxFilter.SelectedItem != null && (int)comboBoxFilter.SelectedValue != 9999)
- {
- agentsForFilters = agentsForFilters.Where(x => x.AgentTypeID == (int)comboBoxFilter.SelectedValue).ToList();
- }
- if ((int)comboBoxFilter.SelectedValue == 9999)
- agentsForFilters = BaseConnector.BaseConnect.Agent.ToList();
- if (comboBoxSort.SelectedItem != null)
- {
- switch (comboBoxSort.SelectedValue)
- {
- case "Наименование":
- agentsForFilters.Sort(delegate(Agent a1, Agent a2)
- {
- return a1.Title.CompareTo(a2.Title);
- });
- break;
- case "Размер скидки":
- break;
- case "Приоритет":
- agentsForFilters.Sort(delegate (Agent a1, Agent a2)
- {
- return a1.Priority.CompareTo(a2.Priority);
- });
- break;
- }
- }
-
- listBoxAgents.ItemsSource = agentsForFilters;
- }
- private void buttomBigger_Click(object sender, RoutedEventArgs e)
- {
- agentsForFilters.Reverse();
- listBoxAgents.ItemsSource = agentsForFilters;
- listBoxAgents.Items.Refresh();
- }
- private void buttomChangePriority_Click(object sender, RoutedEventArgs e)
- {
- if (listBoxAgents.SelectedItems.Count != 0)
- {
- List<Agent> agentsListNew = new List<Agent>();
- foreach (var item in listBoxAgents.SelectedItems)
- {
- agentsListNew.Add((Agent)item);
- }
- WindowChangePriority changePriority = new WindowChangePriority(agentsListNew);
- changePriority.ShowDialog();
- listBoxAgents.Items.Refresh();
- }
- }
- private void buttomAddAgent_Click(object sender, RoutedEventArgs e)
- {
- WindowEditAgent windowEditAgent = new WindowEditAgent();
- if (Application.Current.Windows.Count < 5)
- windowEditAgent.Show();
- agents = BaseConnector.BaseConnect.Agent.ToList();
- listBoxAgents.Items.Refresh();
- }
- private void StackPanel_MouseDown(object sender, MouseButtonEventArgs e)
- {
- if (listBoxAgents.SelectedItem != null)
- {
- WindowEditAgent windowEditAgent = new WindowEditAgent((Agent)listBoxAgents.SelectedItem);
- if (Application.Current.Windows.Count < 5)
- windowEditAgent.Show();
- agents = BaseConnector.BaseConnect.Agent.ToList();
- listBoxAgents.Items.Refresh();
- }
- }
- }
- }
|