Agents.xaml.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. namespace User44
  16. {
  17. /// <summary>
  18. /// Логика взаимодействия для Agents.xaml
  19. /// </summary>
  20. public partial class Agents : Page
  21. {
  22. List<Agent> ServiceStart = Basa.DB.Agent.ToList();
  23. public Agents()
  24. {
  25. InitializeComponent();
  26. LVAgents.ItemsSource = ServiceStart;
  27. CbFilt.Items.Add("Все типы");
  28. List<Agent> prd = Basa.DB.Agent.ToList();
  29. for (int i = 0; i < prd.Count; i++)
  30. {
  31. CbFilt.Items.Add(prd[i].Title);
  32. }
  33. CbFilt.SelectedIndex = 0;
  34. TbCount.Text = "Записей: " + ServiceStart.Count().ToString() + " из " + ServiceStart.Count().ToString();
  35. }
  36. List<Agent> ServiceFilter = new List<Agent>();
  37. List<Agent> ServiceSearch = new List<Agent>();
  38. private void TbSearch_TextChanged(object sender, TextChangedEventArgs e)
  39. {
  40. if (TbSearch.Text != String.Empty)
  41. {
  42. ServiceSearch = ServiceStart.Where(x => x.Title.Contains(TbSearch.Text)).ToList();
  43. FliterSort();
  44. }
  45. else
  46. {
  47. FliterSort();
  48. }
  49. }
  50. private void CbFilt_SelectionChanged(object sender, SelectionChangedEventArgs e)
  51. {
  52. FliterSort();
  53. }
  54. private void CbSort_SelectionChanged(object sender, SelectionChangedEventArgs e)
  55. {
  56. FliterSort();
  57. }
  58. private void FliterSort()
  59. {
  60. int filterIndex = CbFilt.SelectedIndex;
  61. if (TbSearch.Text != String.Empty)
  62. {
  63. if (filterIndex != 0)
  64. {
  65. ServiceFilter = ServiceSearch.Where(x => x.AgentTypeID == filterIndex).ToList();
  66. }
  67. else
  68. {
  69. ServiceFilter = ServiceSearch;
  70. }
  71. }
  72. else
  73. {
  74. if (filterIndex != 0)
  75. {
  76. ServiceFilter = ServiceStart.Where(x => x.AgentTypeID == filterIndex).ToList();
  77. }
  78. else
  79. {
  80. ServiceFilter = ServiceStart;
  81. }
  82. }
  83. switch (CbSort.SelectedIndex)
  84. {
  85. case 0:
  86. ServiceFilter.Sort((x, y) => x.Title.CompareTo(y.Title));
  87. break;
  88. case 1:
  89. ServiceFilter.Sort((x, y) => x.Title.CompareTo(y.Title));
  90. ServiceFilter.Reverse();
  91. break;
  92. case 2:
  93. ServiceFilter.Sort((x, y) => x.Priority.CompareTo(y.Priority));
  94. break;
  95. case 3:
  96. ServiceFilter.Sort((x, y) => x.Priority.CompareTo(y.Priority));
  97. ServiceFilter.Reverse();
  98. break;
  99. }
  100. LVAgents.ItemsSource = ServiceFilter;
  101. LVAgents.Items.Refresh();
  102. TbCount.Text = "Записей: " + ServiceFilter.Count().ToString() + " из " + ServiceStart.Count().ToString();
  103. }
  104. private void LVAgents_SelectionChanged(object sender, SelectionChangedEventArgs e)
  105. {
  106. if (LVAgents.SelectedIndex != -1)
  107. {
  108. ButtEditPrior.Visibility = Visibility.Visible;
  109. }
  110. else
  111. {
  112. ButtEditPrior.Visibility = Visibility.Hidden;
  113. }
  114. }
  115. private void ButtEditPrior_Click(object sender, RoutedEventArgs e)
  116. {
  117. var selectedList = LVAgents.SelectedItems;
  118. int maxMc = 0;
  119. foreach (Agent mC in selectedList)
  120. {
  121. if (mC.Priority > maxMc)
  122. {
  123. maxMc = mC.Priority;
  124. }
  125. }
  126. NewPriority mCWin = new NewPriority(maxMc);
  127. mCWin.ShowDialog();
  128. if (mCWin.NewPrior > 0)
  129. {
  130. foreach (Agent mC in selectedList)
  131. {
  132. mC.Priority = mCWin.NewPrior;
  133. }
  134. LVAgents.Items.Refresh();
  135. }
  136. }
  137. }
  138. }