123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- 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 User44
- {
- /// <summary>
- /// Логика взаимодействия для Agents.xaml
- /// </summary>
- public partial class Agents : Page
- {
- List<Agent> ServiceStart = Basa.DB.Agent.ToList();
- public Agents()
- {
- InitializeComponent();
- LVAgents.ItemsSource = ServiceStart;
- CbFilt.Items.Add("Все типы");
- List<Agent> prd = Basa.DB.Agent.ToList();
- for (int i = 0; i < prd.Count; i++)
- {
- CbFilt.Items.Add(prd[i].Title);
- }
- CbFilt.SelectedIndex = 0;
- TbCount.Text = "Записей: " + ServiceStart.Count().ToString() + " из " + ServiceStart.Count().ToString();
- }
- List<Agent> ServiceFilter = new List<Agent>();
- List<Agent> ServiceSearch = new List<Agent>();
- private void TbSearch_TextChanged(object sender, TextChangedEventArgs e)
- {
- if (TbSearch.Text != String.Empty)
- {
- ServiceSearch = ServiceStart.Where(x => x.Title.Contains(TbSearch.Text)).ToList();
- FliterSort();
- }
- else
- {
- FliterSort();
- }
- }
- private void CbFilt_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- FliterSort();
- }
- private void CbSort_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- FliterSort();
- }
- private void FliterSort()
- {
- int filterIndex = CbFilt.SelectedIndex;
- if (TbSearch.Text != String.Empty)
- {
- if (filterIndex != 0)
- {
- ServiceFilter = ServiceSearch.Where(x => x.AgentTypeID == filterIndex).ToList();
- }
- else
- {
- ServiceFilter = ServiceSearch;
- }
- }
- else
- {
- if (filterIndex != 0)
- {
- ServiceFilter = ServiceStart.Where(x => x.AgentTypeID == filterIndex).ToList();
- }
- else
- {
- ServiceFilter = ServiceStart;
- }
- }
- switch (CbSort.SelectedIndex)
- {
- case 0:
- ServiceFilter.Sort((x, y) => x.Title.CompareTo(y.Title));
- break;
- case 1:
- ServiceFilter.Sort((x, y) => x.Title.CompareTo(y.Title));
- ServiceFilter.Reverse();
- break;
- case 2:
- ServiceFilter.Sort((x, y) => x.Priority.CompareTo(y.Priority));
- break;
- case 3:
- ServiceFilter.Sort((x, y) => x.Priority.CompareTo(y.Priority));
- ServiceFilter.Reverse();
- break;
- }
- LVAgents.ItemsSource = ServiceFilter;
- LVAgents.Items.Refresh();
- TbCount.Text = "Записей: " + ServiceFilter.Count().ToString() + " из " + ServiceStart.Count().ToString();
- }
- private void LVAgents_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (LVAgents.SelectedIndex != -1)
- {
- ButtEditPrior.Visibility = Visibility.Visible;
- }
- else
- {
- ButtEditPrior.Visibility = Visibility.Hidden;
- }
- }
- private void ButtEditPrior_Click(object sender, RoutedEventArgs e)
- {
- var selectedList = LVAgents.SelectedItems;
- int maxMc = 0;
- foreach (Agent mC in selectedList)
- {
- if (mC.Priority > maxMc)
- {
- maxMc = mC.Priority;
- }
- }
- NewPriority mCWin = new NewPriority(maxMc);
- mCWin.ShowDialog();
- if (mCWin.NewPrior > 0)
- {
- foreach (Agent mC in selectedList)
- {
- mC.Priority = mCWin.NewPrior;
- }
- LVAgents.Items.Refresh();
- }
- }
- }
- }
|