AgentPage.xaml.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16. namespace ShabaninDemoEkz
  17. {
  18. /// <summary>
  19. /// Логика взаимодействия для AgentPage.xaml
  20. /// </summary>
  21. public partial class AgentPage : Page
  22. {
  23. VModel VM = new VModel();
  24. List<Agent> agents;
  25. public AgentPage()
  26. {
  27. InitializeComponent();
  28. DataContext = VM;
  29. agents = VM.agent;
  30. AgentList.ItemsSource = agents;
  31. SortCMB.SelectedIndex = 0;
  32. FilterCmb.ItemsSource = BaseConnect.BaseModel.AgentType.ToList();
  33. FilterCmb.SelectedValuePath = "ID";
  34. FilterCmb.DisplayMemberPath = "Title";
  35. FilterCmb.SelectedIndex = 0;
  36. }
  37. private void FilterCmb_SelectionChanged(object sender, SelectionChangedEventArgs e)
  38. {
  39. Filter();
  40. }
  41. private void SortCMB_SelectionChanged(object sender, SelectionChangedEventArgs e)
  42. {
  43. Filter();
  44. }
  45. public void Filter()
  46. {
  47. agents = VM.agent;
  48. try
  49. {
  50. switch (SortCMB.SelectedIndex)
  51. {
  52. case 0:
  53. break;
  54. case 1:
  55. agents = agents.OrderBy(x => x.Title).ToList();
  56. break;
  57. case 2:
  58. agents = agents.OrderBy(x => x.Title).ToList();
  59. agents.Reverse();
  60. break;
  61. case 3:
  62. agents = agents.OrderBy(x => x.skidka).ToList();
  63. break;
  64. case 4:
  65. agents = agents.OrderBy(x => x.skidka).ToList();
  66. agents.Reverse();
  67. break;
  68. case 5:
  69. agents = agents.OrderBy(x => x.Priority).ToList();
  70. break;
  71. case 6:
  72. agents = agents.OrderBy(x => x.Priority).ToList();
  73. agents.Reverse();
  74. break;
  75. }
  76. }
  77. catch
  78. {
  79. }
  80. try
  81. {
  82. if (FilterCmb.SelectedIndex != 0)
  83. agents = agents.Where(x => x.AgentTypeID == FilterCmb.SelectedIndex).ToList();
  84. }
  85. catch { }
  86. try
  87. {
  88. agents = agents.Where(x => x.Title.Contains(searchBar.Text) || x.Email.Contains(searchBar.Text) || x.Phone.Contains(searchBar.Text)).ToList();
  89. }
  90. catch { }
  91. AgentList.ItemsSource = agents;
  92. }
  93. private void searchBar_TextChanged(object sender, TextChangedEventArgs e)
  94. {
  95. Filter();
  96. }
  97. private void AgentList_SelectionChanged(object sender, SelectionChangedEventArgs e)
  98. {
  99. if (AgentList.SelectedItems.Count > 1)
  100. {
  101. ChangePrior.Visibility = Visibility.Visible;
  102. }
  103. else
  104. {
  105. ChangePrior.Visibility = Visibility.Collapsed;
  106. }
  107. }
  108. private void ChangePrior_Click(object sender, RoutedEventArgs e)
  109. {
  110. IList ls = AgentList.SelectedItems;
  111. new ChangedPrior(ls).ShowDialog();
  112. }
  113. }
  114. }