MainWindow.xaml.cs 7.4 KB

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