pgAgentsOutput.xaml.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 DemoExam
  16. {
  17. /// <summary>
  18. /// Логика взаимодействия для pgAgentsOutput.xaml
  19. /// </summary>
  20. public partial class pgAgentsOutput : Page
  21. {
  22. DBConnect dbConnect = new DBConnect();
  23. List<Agent> agents = new List<Agent>();
  24. List<AgentType> agentTypes = new List<AgentType>();
  25. public pgAgentsOutput()
  26. {
  27. InitializeComponent();
  28. agents = dbConnect.agentEntities.Agent.ToList();
  29. lbAgents.ItemsSource = agents;
  30. agentTypes = dbConnect.agentEntities.AgentType.ToList();
  31. cbFilter.Items.Add("Все типы");
  32. cbFilter.SelectedIndex = 0;
  33. cbSort.Items.Add("Без сортировки");
  34. cbSort.Items.Add("Наименование (по возрастанию)");
  35. cbSort.Items.Add("Наименование (по убыванию)");
  36. cbSort.Items.Add("Размер скидки (по возрастанию)");
  37. cbSort.Items.Add("Размер скидки (по убыванию)");
  38. cbSort.Items.Add("Приоритет (по возрастанию)");
  39. cbSort.Items.Add("Приоритет (по убыванию)");
  40. cbSort.SelectedIndex = 0;
  41. foreach (var type in agentTypes)
  42. {
  43. cbFilter.Items.Add(type.Title);
  44. }
  45. }
  46. private void Filters()
  47. {
  48. if (cbFilter.SelectedIndex != 0)
  49. {
  50. agents = dbConnect.agentEntities.Agent.Where(x => x.AgentType.Title == cbFilter.SelectedItem.ToString()).ToList();
  51. }
  52. else
  53. {
  54. agents = dbConnect.agentEntities.Agent.ToList();
  55. }
  56. if (tbSearch.Text.Length > 0)
  57. {
  58. agents = agents.Where(x => x.Title.Contains(tbSearch.Text) || x.Email.Contains(tbSearch.Text) || x.Phone.Contains(tbSearch.Text)).ToList();
  59. }
  60. switch (cbSort.SelectedIndex)
  61. {
  62. case 0:
  63. {
  64. if (cbFilter.SelectedIndex != 0)
  65. {
  66. agents = dbConnect.agentEntities.Agent.Where(x => x.AgentType.Title == cbFilter.SelectedItem.ToString()).ToList();
  67. }
  68. break;
  69. }
  70. case 1:
  71. {
  72. agents = agents.OrderBy(x => x.Title).ToList();
  73. break;
  74. }
  75. case 2:
  76. {
  77. agents = agents.OrderByDescending(x => x.Title).ToList();
  78. break;
  79. }
  80. case 3:
  81. {
  82. agents = agents.OrderBy(x => x.Discount).ToList();
  83. break;
  84. }
  85. case 4:
  86. {
  87. agents = agents.OrderByDescending(x => x.Discount).ToList();
  88. break;
  89. }
  90. case 5:
  91. {
  92. agents = agents.OrderBy(x => x.Priority).ToList();
  93. break;
  94. }
  95. case 6:
  96. {
  97. agents = agents.OrderByDescending(x => x.Priority).ToList();
  98. break;
  99. }
  100. }
  101. lbAgents.ItemsSource = agents;
  102. }
  103. private void cbChanged(object sender, SelectionChangedEventArgs e)
  104. {
  105. Filters();
  106. }
  107. private void tbSearch_TextChanged(object sender, TextChangedEventArgs e)
  108. {
  109. Filters();
  110. }
  111. private void lbAgents_SelectionChanged(object sender, SelectionChangedEventArgs e)
  112. {
  113. if(lbAgents.SelectedItems.Count >= 2)
  114. {
  115. btnChangePriority.Visibility = Visibility.Visible;
  116. }
  117. }
  118. private void btnChangePriority_Click(object sender, RoutedEventArgs e)
  119. {
  120. List<Agent> selectedAgents = new List<Agent>();
  121. List<int> ids = new List<int>();
  122. foreach(var item in lbAgents.SelectedItems)
  123. {
  124. selectedAgents.Add(item as Agent);
  125. }
  126. windChangePriority windChangePriority = new windChangePriority(selectedAgents);
  127. windChangePriority.ShowDialog();
  128. lbAgents.Items.Refresh();
  129. }
  130. }
  131. }