Agents.xaml.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 BuzuevaDemo.Classes;
  16. namespace BuzuevaDemo.Pages
  17. {
  18. /// <summary>
  19. /// Логика взаимодействия для Agents.xaml
  20. /// </summary>
  21. public partial class Agents : Page
  22. {
  23. ViewModel view = new ViewModel();
  24. List<Agent> filter;
  25. List<Agent> sortirov;
  26. List<Agent> filtrasia;
  27. List<Agent> agents = new List<Agent>();
  28. public string[] typelist = new string[6];
  29. public Agents()
  30. {
  31. InitializeComponent();
  32. AllAgent.ItemsSource = view.agent.ToList();
  33. AllAgent.Items.Refresh();
  34. filter = view.agent.ToList();
  35. sortirov = view.agent.ToList();
  36. filtrasia = view.agent.ToList();
  37. List<AgentType> type = DataBase.BaseModel.AgentType.ToList();
  38. int i = 0;
  39. foreach (AgentType tps in type)
  40. {
  41. typelist[i] = tps.Title;
  42. i++;
  43. }
  44. tb2.Text = typelist[0];
  45. tb3.Text = typelist[1];
  46. tb4.Text = typelist[2];
  47. tb5.Text = typelist[3];
  48. tb6.Text = typelist[4];
  49. tb7.Text = typelist[5];
  50. }
  51. private void Changeg(object sender, TextChangedEventArgs e)
  52. {
  53. filter = view.agent;
  54. if (poisk.Text != "")
  55. {
  56. filter = filter.Where(x => x.Title.Contains(poisk.Text) || x.Email.Contains(poisk.Text) || x.Phone.Contains(poisk.Text)).ToList();
  57. }
  58. AllAgent.ItemsSource = filter.ToList();
  59. }
  60. private void PerexodCreate(object sender, MouseButtonEventArgs e)
  61. {
  62. StackPanel zapis = (StackPanel)sender;
  63. int id = Convert.ToInt32(zapis.Uid);
  64. Agent agent = DataBase.BaseModel.Agent.FirstOrDefault(x => x.ID == id);
  65. new CreateChange(agent, 0).ShowDialog();
  66. }
  67. private void PerexodСhange(object sender, RoutedEventArgs e)
  68. {
  69. new CreateChange(null, 1).ShowDialog();
  70. }
  71. private void sortSelectionChanged(object sender, SelectionChangedEventArgs e)
  72. {
  73. switch (sort.SelectedIndex)
  74. {
  75. case 0:
  76. sortirov = sortirov.OrderBy(x => x.Title).ToList();
  77. AllAgent.ItemsSource = sortirov.ToList();
  78. break;
  79. case 1:
  80. sortirov = sortirov.OrderBy(x => x.Title).ToList();
  81. sortirov.Reverse();
  82. AllAgent.ItemsSource = sortirov.ToList();
  83. break;
  84. case 2:
  85. sortirov = sortirov.ToList();
  86. break;
  87. case 3:
  88. sortirov = sortirov.ToList();
  89. break;
  90. case 4:
  91. sortirov = sortirov.OrderBy(x => x.Priority).ToList();
  92. AllAgent.ItemsSource = sortirov.ToList();
  93. break;
  94. case 5:
  95. sortirov = sortirov.OrderBy(x => x.Priority).ToList();
  96. sortirov.Reverse();
  97. AllAgent.ItemsSource = sortirov.ToList();
  98. break;
  99. default:
  100. sortirov = sortirov.ToList();
  101. break;
  102. }
  103. AllAgent.ItemsSource = sortirov.ToList();
  104. }
  105. private void filtSelectionChanged(object sender, SelectionChangedEventArgs e)
  106. {
  107. filtrasia = view.agent;
  108. switch (filt.SelectedIndex)
  109. {
  110. case 0:
  111. break;
  112. case 1:
  113. filtrasia = filtrasia.Where(x => x.TitleType == typelist[0]).ToList();
  114. break;
  115. case 2:
  116. filtrasia = filtrasia.Where(x => x.TitleType == typelist[1]).ToList();
  117. break;
  118. case 3:
  119. filtrasia = filtrasia.Where(x => x.TitleType == typelist[2]).ToList();
  120. break;
  121. case 4:
  122. filtrasia = filtrasia.Where(x => x.TitleType == typelist[3]).ToList();
  123. break;
  124. case 5:
  125. filtrasia = filtrasia.Where(x => x.TitleType == typelist[4]).ToList();
  126. break;
  127. case 6:
  128. filtrasia = filtrasia.Where(x => x.TitleType == typelist[5]).ToList();
  129. break;
  130. }
  131. AllAgent.ItemsSource = filtrasia.ToList();
  132. }
  133. }
  134. }