AgentsList.xaml.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. using DemoexamUser11.classes;
  16. using DemoexamUser11.windows;
  17. namespace DemoexamUser11.pages
  18. {
  19. /// <summary>
  20. /// Логика взаимодействия для AgentsList.xaml
  21. /// </summary>
  22. public partial class AgentsList : Page
  23. {
  24. List<string> sortList = new List<string>() { "Наименование", "Размер скидки", "Приоритет" };
  25. List<Agent> agents = BaseConnector.BaseConnect.Agent.ToList();
  26. List<Agent> agentsForFilters = BaseConnector.BaseConnect.Agent.ToList();
  27. List<AgentType> agentTypes = BaseConnector.BaseConnect.AgentType.ToList();
  28. public AgentsList()
  29. {
  30. InitializeComponent();
  31. listBoxAgents.ItemsSource = agents;
  32. agentTypes.Add(new AgentType { ID = 9999, Title = "Все типы" });
  33. comboBoxFilter.ItemsSource = agentTypes;
  34. comboBoxFilter.DisplayMemberPath = "Title";
  35. comboBoxFilter.SelectedValuePath = "ID";
  36. comboBoxFilter.SelectedIndex = comboBoxFilter.Items.Count - 1;
  37. comboBoxSort.ItemsSource = sortList;
  38. }
  39. private void Search(object sender, TextChangedEventArgs e)
  40. {
  41. if (textBoxSearch.Text.Replace(" ", "") != "")
  42. {
  43. try
  44. {
  45. agentsForFilters = agentsForFilters.Where(x => x.Title.Contains(textBoxSearch.Text) || x.Phone.Contains(textBoxSearch.Text) || x.Email.Contains(textBoxSearch.Text)).ToList();
  46. listBoxAgents.ItemsSource = agentsForFilters;
  47. }
  48. catch
  49. {
  50. MessageBox.Show("Не удалось выполнить поиск!");
  51. }
  52. }
  53. if (textBoxSearch.Text.Replace(" ", "") == "" && (int)comboBoxFilter.SelectedValue == 9999)
  54. {
  55. listBoxAgents.ItemsSource = agents;
  56. agentsForFilters = BaseConnector.BaseConnect.Agent.ToList();
  57. }
  58. else if (textBoxSearch.Text.Replace(" ", "") == "" && (int)comboBoxFilter.SelectedValue != 9999)
  59. {
  60. listBoxAgents.ItemsSource = agents.Where(x => x.AgentTypeID == (int)comboBoxFilter.SelectedValue).ToList();
  61. agentsForFilters = BaseConnector.BaseConnect.Agent.ToList();
  62. }
  63. }
  64. private void Filter(object sender, SelectionChangedEventArgs e)
  65. {
  66. if (comboBoxFilter.SelectedItem != null && (int)comboBoxFilter.SelectedValue != 9999)
  67. {
  68. agentsForFilters = agentsForFilters.Where(x => x.AgentTypeID == (int)comboBoxFilter.SelectedValue).ToList();
  69. }
  70. if ((int)comboBoxFilter.SelectedValue == 9999)
  71. agentsForFilters = BaseConnector.BaseConnect.Agent.ToList();
  72. if (comboBoxSort.SelectedItem != null)
  73. {
  74. switch (comboBoxSort.SelectedValue)
  75. {
  76. case "Наименование":
  77. agentsForFilters.Sort(delegate(Agent a1, Agent a2)
  78. {
  79. return a1.Title.CompareTo(a2.Title);
  80. });
  81. break;
  82. case "Размер скидки":
  83. break;
  84. case "Приоритет":
  85. agentsForFilters.Sort(delegate (Agent a1, Agent a2)
  86. {
  87. return a1.Priority.CompareTo(a2.Priority);
  88. });
  89. break;
  90. }
  91. }
  92. listBoxAgents.ItemsSource = agentsForFilters;
  93. }
  94. private void buttomBigger_Click(object sender, RoutedEventArgs e)
  95. {
  96. agentsForFilters.Reverse();
  97. listBoxAgents.ItemsSource = agentsForFilters;
  98. listBoxAgents.Items.Refresh();
  99. }
  100. private void buttomChangePriority_Click(object sender, RoutedEventArgs e)
  101. {
  102. if (listBoxAgents.SelectedItems.Count != 0)
  103. {
  104. List<Agent> agentsListNew = new List<Agent>();
  105. foreach (var item in listBoxAgents.SelectedItems)
  106. {
  107. agentsListNew.Add((Agent)item);
  108. }
  109. WindowChangePriority changePriority = new WindowChangePriority(agentsListNew);
  110. changePriority.ShowDialog();
  111. listBoxAgents.Items.Refresh();
  112. }
  113. }
  114. private void buttomAddAgent_Click(object sender, RoutedEventArgs e)
  115. {
  116. WindowEditAgent windowEditAgent = new WindowEditAgent();
  117. if (Application.Current.Windows.Count < 5)
  118. windowEditAgent.Show();
  119. agents = BaseConnector.BaseConnect.Agent.ToList();
  120. listBoxAgents.Items.Refresh();
  121. }
  122. private void StackPanel_MouseDown(object sender, MouseButtonEventArgs e)
  123. {
  124. if (listBoxAgents.SelectedItem != null)
  125. {
  126. WindowEditAgent windowEditAgent = new WindowEditAgent((Agent)listBoxAgents.SelectedItem);
  127. if (Application.Current.Windows.Count < 5)
  128. windowEditAgent.Show();
  129. agents = BaseConnector.BaseConnect.Agent.ToList();
  130. listBoxAgents.Items.Refresh();
  131. }
  132. }
  133. }
  134. }