MainWindow.xaml.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. using System.ComponentModel;
  2. using System.Text;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. using System.Windows.Data;
  6. using System.Windows.Documents;
  7. using System.Windows.Input;
  8. using System.Windows.Media;
  9. using System.Windows.Media.Imaging;
  10. using System.Windows.Navigation;
  11. using System.Windows.Shapes;
  12. using WpfApp1.model;
  13. using System.Threading.Tasks;
  14. using System;
  15. using WpfApp1.model;
  16. using WpfApp1.model;
  17. using WpfApp1.model;
  18. namespace WpfApp1
  19. {
  20. /// <summary>
  21. /// Interaction logic for MainWindow.xaml
  22. /// </summary>
  23. public partial class MainWindow : Window, INotifyPropertyChanged
  24. {
  25. public event PropertyChangedEventHandler PropertyChanged;
  26. private void Invalidate()
  27. {
  28. if (PropertyChanged != null)
  29. PropertyChanged(this, new PropertyChangedEventArgs("WorkerList"));
  30. }
  31. public string selectedPos = "Должность";
  32. public WorkerAge? selectedAge = null;
  33. public string selectedSex = "Пол";
  34. private IEnumerable<Worker> _WorkerList;
  35. public IEnumerable<Worker> WorkerList
  36. {
  37. get
  38. {
  39. var res = _WorkerList;
  40. res = res
  41. .Where(c => (c.Pos == selectedPos || selectedPos == "Должность"))
  42. .Where(c => (selectedAge == null || (c.Age >= selectedAge.AgeFrom && c.Age < selectedAge.AgeTo)))
  43. .Where(c => (c.Sex == selectedSex || selectedSex == "Пол"));
  44. if (searchFilter != "")
  45. res = res.Where(c => c.name.IndexOf(
  46. searchFilter,
  47. StringComparison.OrdinalIgnoreCase) >= 0);
  48. if (sortAsc) res = res.OrderBy(c => c.Age);
  49. else res = res.OrderByDescending(c => c.Age);
  50. return res;
  51. }
  52. set
  53. {
  54. _WorkerList = value;
  55. }
  56. }
  57. public List<WorkerPos> WorkerPosList { get; set; }
  58. public List<WorkerAge> WorkerAgeList { get; set; }
  59. public List<WorkerSex> WorkerSexList { get; set; }
  60. public MainWindow()
  61. {
  62. InitializeComponent();
  63. DataContext = this;
  64. Globals.dataProvider = new LocalDataProvider();
  65. WorkerList = Globals.dataProvider.getWorker();
  66. WorkerPosList = Globals.dataProvider.getPos().ToList();
  67. WorkerPosList.Insert(0, new WorkerPos { title = "Должность" });
  68. WorkerAgeList = Globals.dataProvider.getAge().ToList();
  69. WorkerSexList = Globals.dataProvider.getSex().ToList();
  70. WorkerSexList.Insert(0, new WorkerSex { title = "Пол" });
  71. }
  72. private void ExitButton_Click(object sender, RoutedEventArgs e)
  73. {
  74. Application.Current.Shutdown();
  75. }
  76. private void PosFilterComboBox_SelectionChanged_1(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
  77. {
  78. selectedPos = (PosFilterComboBox.SelectedItem as WorkerPos).title;
  79. Invalidate();
  80. }
  81. private void AgeFilterComboBox_SelectionChanged_2(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
  82. {
  83. selectedAge = (AgeFilterComboBox.SelectedItem as WorkerAge);
  84. Invalidate();
  85. }
  86. private void SexFilterComboBox_SelectionChanged_3(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
  87. {
  88. selectedSex = (SexFilterComboBox.SelectedItem as WorkerSex).title;
  89. Invalidate();
  90. }
  91. private string searchFilter = "";
  92. private void SearchFilter_KeyUp(object sender, KeyEventArgs e)
  93. {
  94. searchFilter = SearchFilterTextBox.Text;
  95. Invalidate();
  96. }
  97. private bool sortAsc = true;
  98. private void RadioButton_Checked(object sender, RoutedEventArgs e)
  99. {
  100. sortAsc = (sender as RadioButton).Tag.ToString() == "1";
  101. Invalidate();
  102. }
  103. }
  104. interface IDataProvider
  105. {
  106. IEnumerable<Worker> getWorker();
  107. IEnumerable<WorkerPos> getPos();
  108. IEnumerable<WorkerAge> getAge();
  109. IEnumerable<WorkerSex> getSex();
  110. }
  111. public class LocalDataProvider : IDataProvider
  112. {
  113. public IEnumerable<WorkerPos> getPos()
  114. {
  115. return new WorkerPos[]
  116. {
  117. new WorkerPos()
  118. {
  119. title="Директор"
  120. },
  121. new WorkerPos()
  122. {
  123. title="Продавец"
  124. },
  125. new WorkerPos()
  126. {
  127. title="Механик"
  128. },
  129. new WorkerPos()
  130. {
  131. title="Уборщик"
  132. },
  133. new WorkerPos()
  134. {
  135. title="Стажер"
  136. },
  137. new WorkerPos()
  138. {
  139. title="Оператор"
  140. },
  141. };
  142. }
  143. public IEnumerable<WorkerAge> getAge()
  144. {
  145. return new WorkerAge[]
  146. {
  147. new WorkerAge()
  148. {
  149. title="Все возраста",
  150. AgeFrom=0,
  151. AgeTo=110
  152. },
  153. new WorkerAge()
  154. {
  155. title="Дети",
  156. AgeFrom=1,
  157. AgeTo=6
  158. },
  159. new WorkerAge()
  160. {
  161. title="Подростки",
  162. AgeFrom=7,
  163. AgeTo=21
  164. },
  165. new WorkerAge()
  166. {
  167. title="Молодые",
  168. AgeFrom=22,
  169. AgeTo=50
  170. },
  171. new WorkerAge()
  172. {
  173. title="Старики",
  174. AgeFrom=51,
  175. AgeTo=110
  176. }
  177. };
  178. }
  179. public IEnumerable<WorkerSex> getSex()
  180. {
  181. return new WorkerSex[]
  182. {
  183. new WorkerSex()
  184. {
  185. title="Человек"
  186. },
  187. new WorkerSex()
  188. {
  189. title="Женщина"
  190. }
  191. };
  192. }
  193. public IEnumerable<Worker> getWorker()
  194. {
  195. return new Worker[]{
  196. new Worker{
  197. Sex="Человек",
  198. name="Вася",
  199. Age=25,
  200. Pos="Директор"},
  201. new Worker{
  202. Sex="Человек",
  203. name="Петя",
  204. Age=45,
  205. Pos="Продавец"},
  206. new Worker{
  207. Sex="Человек",
  208. name="Степа",
  209. Age = 30,
  210. Pos="Механик"},
  211. new Worker{
  212. Sex="Человек",
  213. name="Миша",
  214. Age = 100,
  215. Pos="Стажер"},
  216. new Worker{
  217. Sex="Женщина",
  218. name="Лена",
  219. Age = 12,
  220. Pos="Оператор"}
  221. };
  222. }
  223. }
  224. }