AgentInfoFrame.xaml.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 UP2022Ex.FrameFolder
  16. {
  17. public partial class AgentInfoFrame : Page
  18. {
  19. List<Agent> _StartFilter = ClassFolder.BD.data.Agent.ToList();
  20. List<Agent> _TemporraryFilter;
  21. int _UpAndDown =1;
  22. public AgentInfoFrame()
  23. {
  24. InitializeComponent();
  25. _TemporraryFilter = _StartFilter;
  26. LVAgent.ItemsSource = _StartFilter;
  27. CBSort.SelectedIndex = 0;
  28. CBFilt.SelectedIndex = 0;
  29. }
  30. public void Sort()
  31. {
  32. switch (CBSort.SelectedIndex)
  33. {
  34. case 0:
  35. _TemporraryFilter.Sort((x, y) => x.Title.CompareTo(y.Title));
  36. break;
  37. case 1:
  38. _TemporraryFilter.Sort((x, y) => x.Sale.CompareTo(y.Sale));
  39. break;
  40. case 2:
  41. _TemporraryFilter.Sort((x, y) => x.Priority.CompareTo(y.Priority));
  42. break;
  43. }
  44. }
  45. public void Filt()
  46. {
  47. switch (CBFilt.SelectedIndex)
  48. {
  49. case 0:
  50. _TemporraryFilter = _StartFilter;
  51. break;
  52. case 1:
  53. _TemporraryFilter = _StartFilter.Where(x => x.AgentTypeID == 1).ToList();
  54. break;
  55. case 2:
  56. _TemporraryFilter = _StartFilter.Where(x => x.AgentTypeID == 2).ToList();
  57. break;
  58. case 3:
  59. _TemporraryFilter = _StartFilter.Where(x => x.AgentTypeID == 3).ToList();
  60. break;
  61. case 4:
  62. _TemporraryFilter = _StartFilter.Where(x => x.AgentTypeID == 4).ToList();
  63. break;
  64. case 5:
  65. _TemporraryFilter = _StartFilter.Where(x => x.AgentTypeID == 5).ToList();
  66. break;
  67. case 6:
  68. _TemporraryFilter = _StartFilter.Where(x => x.AgentTypeID == 6).ToList();
  69. break;
  70. }
  71. string SearchStr = TBOXSearch.Text;
  72. if (!string.IsNullOrWhiteSpace(TBOXSearch.Text))
  73. {
  74. _TemporraryFilter = _StartFilter.Where(x => x.Title.Contains(SearchStr)|| x.Title.ToLower().Contains(SearchStr) || x.Email.Contains(SearchStr) || x.Email.ToLower().Contains(SearchStr) || x.Phone.Contains(SearchStr) || x.Phone.ToLower().Contains(SearchStr)).ToList();
  75. }
  76. if (_UpAndDown == 1)
  77. {
  78. _UpAndDown *= -1;
  79. Sort();
  80. }
  81. else
  82. {
  83. _UpAndDown *= -1;
  84. Sort();
  85. _TemporraryFilter.Reverse();
  86. }
  87. LVAgent.ItemsSource = _TemporraryFilter;
  88. }
  89. private void CBSort_SelectionChanged(object sender, SelectionChangedEventArgs e)
  90. {
  91. Sort();
  92. LVAgent.Items.Refresh();
  93. }
  94. private void BUP_Click(object sender, RoutedEventArgs e)
  95. {
  96. if (_UpAndDown != 1)
  97. {
  98. _UpAndDown *= -1;
  99. _TemporraryFilter.Reverse();
  100. }
  101. LVAgent.Items.Refresh();
  102. }
  103. private void BDown_Click(object sender, RoutedEventArgs e)
  104. {
  105. if (_UpAndDown != -1)
  106. {
  107. _UpAndDown *= -1;
  108. Sort();
  109. }
  110. LVAgent.Items.Refresh();
  111. }
  112. private void CBFilt_SelectionChanged(object sender, SelectionChangedEventArgs e)
  113. {
  114. Filt();
  115. LVAgent.Items.Refresh();
  116. }
  117. private void BAdd_Click(object sender, RoutedEventArgs e)
  118. {
  119. WindowFolder.AddWindow NewWindow = new WindowFolder.AddWindow();
  120. NewWindow.Show();
  121. }
  122. private void TBOXSearch_TextChanged(object sender, TextChangedEventArgs e)
  123. {
  124. Filt();
  125. LVAgent.Items.Refresh();
  126. }
  127. }
  128. }