MainWindow.xaml.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. Invalidate();
  95. }
  96. private bool sortAsc = true;
  97. private void RadioButton_Checked(object sender, RoutedEventArgs e)
  98. {
  99. sortAsc = (sender as RadioButton).Tag.ToString() == "1";
  100. Invalidate();
  101. }
  102. }
  103. interface IDataProvider
  104. {
  105. IEnumerable<Worker> getWorker();
  106. IEnumerable<WorkerPos> getPos();
  107. IEnumerable<WorkerAge> getAge();
  108. IEnumerable<WorkerSex> getSex();
  109. }
  110. public class LocalDataProvider : IDataProvider
  111. {
  112. public IEnumerable<WorkerPos> getPos()
  113. {
  114. return new WorkerPos[]
  115. {
  116. new WorkerPos()
  117. {
  118. title="Директор"
  119. },
  120. new WorkerPos()
  121. {
  122. title="Продавец"
  123. },
  124. new WorkerPos()
  125. {
  126. title="Механик"
  127. },
  128. new WorkerPos()
  129. {
  130. title="Уборщик"
  131. },
  132. new WorkerPos()
  133. {
  134. title="Стажер"
  135. },
  136. new WorkerPos()
  137. {
  138. title="Оператор"
  139. },
  140. };
  141. }
  142. public IEnumerable<WorkerAge> getAge()
  143. {
  144. return new WorkerAge[]
  145. {
  146. new WorkerAge()
  147. {
  148. title="Все возраста",
  149. AgeFrom=0,
  150. AgeTo=110
  151. },
  152. new WorkerAge()
  153. {
  154. title="Дети",
  155. AgeFrom=1,
  156. AgeTo=6
  157. },
  158. new WorkerAge()
  159. {
  160. title="Подростки",
  161. AgeFrom=7,
  162. AgeTo=21
  163. },
  164. new WorkerAge()
  165. {
  166. title="Молодые",
  167. AgeFrom=22,
  168. AgeTo=50
  169. },
  170. new WorkerAge()
  171. {
  172. title="Старики",
  173. AgeFrom=51,
  174. AgeTo=110
  175. }
  176. };
  177. }
  178. public IEnumerable<WorkerSex> getSex()
  179. {
  180. return new WorkerSex[]
  181. {
  182. new WorkerSex()
  183. {
  184. title="Человек"
  185. },
  186. new WorkerSex()
  187. {
  188. title="Женщина"
  189. }
  190. };
  191. }
  192. public IEnumerable<Worker> getWorker()
  193. {
  194. return new Worker[]{
  195. new Worker{
  196. Sex="Человек",
  197. name="Вася",
  198. Age=25,
  199. Pos="Директор"},
  200. new Worker{
  201. Sex="Человек",
  202. name="Петя",
  203. Age=45,
  204. Pos="Продавец"},
  205. new Worker{
  206. Sex="Человек",
  207. name="Степа",
  208. Age = 30,
  209. Pos="Механик"},
  210. new Worker{
  211. Sex="Человек",
  212. name="Миша",
  213. Age = 100,
  214. Pos="Стажер"},
  215. new Worker{
  216. Sex="Женщина",
  217. name="Лена",
  218. Age = 12,
  219. Pos="Оператор"}
  220. };
  221. }
  222. }
  223. }