MainWindow.xaml.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. using System.Windows;
  2. using System.ComponentModel;
  3. using System.Collections.Generic;
  4. using WpfApp1.SQL;
  5. using System;
  6. using System.Linq;
  7. using System.Windows.Input;
  8. using System.Windows.Controls;
  9. using WpfApp1.AddEdit;
  10. namespace WpfApp1
  11. {
  12. /// <summary>
  13. /// Логика взаимодействия для MainWindow.xaml
  14. /// </summary>
  15. public partial class MainWindow : Window, INotifyPropertyChanged
  16. {
  17. public event PropertyChangedEventHandler PropertyChanged;
  18. public List<string> sortList
  19. {
  20. get => Items.sortList.ToList();
  21. }
  22. private List<Agent> _AgentList;
  23. public List<Agent> AgentList
  24. {
  25. get
  26. {
  27. List<Agent> agentList = _AgentList;
  28. if (SearchText != null)
  29. agentList = agentList.Where(item => item.Title.IndexOf(SearchText, StringComparison.OrdinalIgnoreCase) != -1).ToList();
  30. if (SortList && ChooseSortItem == 0)
  31. return agentList.OrderBy(items => items.Title).ToList();
  32. else if (SortList && ChooseSortItem == 1)
  33. return agentList.OrderBy(items => items.Title).ToList();
  34. else if (SortList && ChooseSortItem == 2)
  35. return agentList.OrderBy(items => items.Priority).ToList();
  36. else if (!SortList && ChooseSortItem == 0)
  37. return agentList.OrderBy(items => items.Title).ToList();
  38. else if (!SortList && ChooseSortItem == 1)
  39. return agentList.OrderBy(items => items.Title).ToList();
  40. else
  41. return agentList.OrderByDescending(items => items.Priority).ToList();
  42. }
  43. set
  44. {
  45. _AgentList = value;
  46. if (PropertyChanged != null)
  47. {
  48. PropertyChanged(this, new PropertyChangedEventArgs("AgentList"));
  49. PropertyChanged(this, new PropertyChangedEventArgs("SortList"));
  50. }
  51. }
  52. }
  53. private string _SearchText;
  54. public string SearchText
  55. {
  56. get => _SearchText;
  57. set
  58. {
  59. _SearchText = value;
  60. if (PropertyChanged != null)
  61. {
  62. PropertyChanged(this, new PropertyChangedEventArgs("AgentList"));
  63. PropertyChanged(this, new PropertyChangedEventArgs("SearchText"));
  64. }
  65. }
  66. }
  67. private byte _ChooseSortItem;
  68. public byte ChooseSortItem
  69. {
  70. get => _ChooseSortItem;
  71. set
  72. {
  73. _ChooseSortItem = value;
  74. if (PropertyChanged != null)
  75. {
  76. PropertyChanged(this, new PropertyChangedEventArgs("ChooseSortItem"));
  77. PropertyChanged(this, new PropertyChangedEventArgs("AgentList"));
  78. }
  79. }
  80. }
  81. private bool _SortList = false;
  82. public bool SortList
  83. {
  84. get => _SortList;
  85. set
  86. {
  87. _SortList = value;
  88. if (PropertyChanged != null)
  89. {
  90. PropertyChanged(this, new PropertyChangedEventArgs("SortList"));
  91. PropertyChanged(this, new PropertyChangedEventArgs("AgentList"));
  92. PropertyChanged(this, new PropertyChangedEventArgs("GetContentButtonSort"));
  93. }
  94. }
  95. }
  96. public string GetContentButtonSort
  97. {
  98. get => SortList ? "По возрастанию" : "По убыванию";
  99. }
  100. public MainWindow()
  101. {
  102. InitializeComponent();
  103. AgentList = Base.EM.Agent.ToList();
  104. DataContext = this;
  105. }
  106. private void TextBox_Name_KeyUp(object sender, KeyEventArgs e)
  107. {
  108. SearchText = TextBox_Name.Text;
  109. }
  110. private void Button_Sort_Click(object sender, RoutedEventArgs e)
  111. {
  112. if (SortList)
  113. SortList = false;
  114. else SortList = true;
  115. }
  116. private void ComboBox_Sort_SelectionChanged(object sender, SelectionChangedEventArgs e)
  117. {
  118. ChooseSortItem = (byte)ComboBox_Sort.SelectedIndex;
  119. }
  120. private void DataView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
  121. {
  122. Agent item = ListView_Agent.SelectedItem as Agent;
  123. AddEditItems aei = new AddEditItems(item);
  124. if (aei.ShowDialog() == true)
  125. {
  126. AgentList = Base.EM.Agent.ToList();
  127. PropertyChanged(this, new PropertyChangedEventArgs("AgentList"));
  128. }
  129. }
  130. private void Button_Add_Click(object sender, RoutedEventArgs e)
  131. {
  132. Agent item = new Agent();
  133. AddEditItems aei = new AddEditItems(item);
  134. if (aei.ShowDialog() == true)
  135. {
  136. AgentList = Base.EM.Agent.ToList();
  137. PropertyChanged(this, new PropertyChangedEventArgs("AgentList"));
  138. }
  139. }
  140. private void Button_Exit_Click(object sender, RoutedEventArgs e) => Application.Current.Shutdown();
  141. }
  142. }