Agents.xaml.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 Demoexample
  16. {
  17. /// <summary>
  18. /// Логика взаимодействия для Agents.xaml
  19. /// </summary>
  20. public partial class Agents : Page
  21. {
  22. ViewModel viewModel = new ViewModel();
  23. List<Agent> change;
  24. public Agents()
  25. {
  26. InitializeComponent();
  27. lbAllAgent.ItemsSource = viewModel.agents.ToList();
  28. lbAllAgent.Items.Refresh();
  29. change = viewModel.agents;
  30. Filter.ItemsSource = DataBase.BaseModel.AgentType.ToList();
  31. Filter.SelectedValuePath = "ID";
  32. Filter.DisplayMemberPath = "Title";
  33. Filter.SelectedIndex = 0;
  34. }
  35. public void ChangeList(object sender, RoutedEventArgs e)
  36. {
  37. change = viewModel.agents;
  38. if (Filter.SelectedIndex == 0)
  39. {
  40. change = viewModel.agents;
  41. }
  42. else
  43. {
  44. change = change.Where(x => x.AgentTypeID == Filter.SelectedIndex).ToList();
  45. }
  46. lbAllAgent.ItemsSource = change;
  47. switch (Sort.SelectedIndex)
  48. {
  49. case 0:
  50. change = change.OrderBy(x => x.Title).ToList();
  51. break;
  52. case 1:
  53. change = change.OrderBy(x => x.Title).ToList();
  54. change.Reverse();
  55. break;
  56. case 2:
  57. change = change.OrderBy(x => x.Sale).ToList();
  58. break;
  59. case 3:
  60. change = change.OrderBy(x => x.Sale).ToList();
  61. change.Reverse();
  62. break;
  63. case 4:
  64. change = change.OrderBy(x => x.Priority).ToList();
  65. break;
  66. case 5:
  67. change = change.OrderBy(x => x.Priority).ToList();
  68. change.Reverse();
  69. break;
  70. }
  71. lbAllAgent.ItemsSource = change;
  72. if(Scan.Text != "")
  73. {
  74. change = change.Where(x => x.Title.Contains(Scan.Text)).ToList();
  75. }
  76. lbAllAgent.ItemsSource = change;
  77. }
  78. private void newAgent_Click(object sender, RoutedEventArgs e)
  79. {
  80. new NewAgent().ShowDialog();
  81. }
  82. private void StackPanel_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  83. {
  84. StackPanel stackPanel = (StackPanel)sender;
  85. int id = Convert.ToInt32(stackPanel.Uid);
  86. Agent agent = DataBase.BaseModel.Agent.FirstOrDefault(x => x.ID == id);
  87. new Redaction(agent).ShowDialog();
  88. }
  89. }
  90. }