MainWindow.xaml.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 WhiteList
  16. {
  17. /// <summary>
  18. /// Логика взаимодействия для MainWindow.xaml
  19. /// </summary>
  20. public partial class MainWindow : Window
  21. {
  22. List<Agent> _listAgents;
  23. public MainWindow()
  24. {
  25. InitializeComponent();
  26. ComboBoxFilter.Items.Add("Все");
  27. foreach (AgentType at in DB.dbCon.AgentType.ToList())
  28. {
  29. ComboBoxFilter.Items.Add(at.Title);
  30. }
  31. ComboBoxFilter.SelectedIndex = 0;
  32. }
  33. public void Filt() //фильтрация данных
  34. {
  35. _listAgents = DB.dbCon.Agent.ToList();
  36. if(TextBoxSearch.Text.Length>0) //по поисковику
  37. {
  38. string searchStroke = TextBoxSearch.Text.ToLower();
  39. List<Agent> newList = new List<Agent>();
  40. foreach(Agent a in _listAgents)
  41. {
  42. if(a.Title.ToLower().Contains(searchStroke)||a.Email.ToLower().Contains(searchStroke)||a.Phone.ToLower().Contains(searchStroke)) //содержится в почте, названии или номере телефона
  43. {
  44. newList.Add(a);
  45. }
  46. }
  47. _listAgents = newList;
  48. }
  49. if(ComboBoxFilter.SelectedIndex>0)
  50. {
  51. _listAgents = _listAgents.Where(x => x.AgentType.Title == ComboBoxFilter.SelectedValue.ToString()).ToList();
  52. }
  53. ListViewDataBase.Items.Clear();
  54. foreach (Agent a in _listAgents)
  55. {
  56. ListViewDataBase.Items.Add(a);
  57. }
  58. }
  59. private void TextBoxSearch_TextChanged(object sender, TextChangedEventArgs e)
  60. {
  61. Filt();
  62. }
  63. private void ComboBoxFilter_SelectionChanged(object sender, SelectionChangedEventArgs e)
  64. {
  65. Filt();
  66. }
  67. private void ChangePriority_Click(object sender, RoutedEventArgs e)
  68. {
  69. List<Agent> selected = new List<Agent>();
  70. foreach(Agent a in ListViewDataBase.SelectedItems) //получаем из выделенных итемов обьекты таблицы
  71. {
  72. selected.Add(a);
  73. }
  74. ChangePriority w = new ChangePriority(selected);
  75. w.Owner = this;
  76. w.Visibility = Visibility.Visible;
  77. w.WindowStartupLocation = WindowStartupLocation.CenterOwner;
  78. w.ShowDialog();
  79. ListViewDataBase.Items.Refresh(); //перезагрузка
  80. }
  81. private void ListViewDataBase_SelectionChanged(object sender, SelectionChangedEventArgs e) //для видимости кнопки
  82. {
  83. if(ListViewDataBase.SelectedItems.Count>0)
  84. {
  85. BtnChangePriority.Visibility = Visibility.Visible;
  86. }
  87. else
  88. {
  89. BtnChangePriority.Visibility = Visibility.Collapsed;
  90. }
  91. }
  92. private void Add_Click(object sender, RoutedEventArgs e)
  93. {
  94. AddAndRedactAgent w = new AddAndRedactAgent();
  95. w.Owner = this;
  96. w.Visibility = Visibility.Visible;
  97. w.WindowStartupLocation = WindowStartupLocation.CenterOwner;
  98. w.ShowDialog();
  99. Filt();
  100. }
  101. }
  102. }