MainWindow.xaml.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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 wpf_template.models;
  13. using System.Threading.Tasks;
  14. using System;
  15. namespace wpf_template
  16. {
  17. public partial class MainWindow : Window, INotifyPropertyChanged
  18. {
  19. public event PropertyChangedEventHandler PropertyChanged;
  20. private void Invalidate()
  21. {
  22. if (PropertyChanged != null)
  23. PropertyChanged(this, new PropertyChangedEventArgs("PeopleList"));
  24. }
  25. public string selectedGender = "Пол";
  26. public PeopleAge? selectedAge = null;
  27. public string selectedPlace = "Место";
  28. private IEnumerable<People> _PeopleList;
  29. public IEnumerable<People> PeopleList
  30. {
  31. get
  32. {
  33. return _PeopleList
  34. .Where(c => (c.Gender == selectedGender || selectedGender == "Пол"))
  35. .Where(c => (selectedAge == null || (c.Age >= selectedAge.AgeFrom && c.Age < selectedAge.AgeTo)))
  36. .Where(c => (c.Place == selectedPlace || selectedPlace == "Место"));
  37. }
  38. set
  39. {
  40. _PeopleList = value;
  41. }
  42. }
  43. public List<PeopleGender> PeopleGenderList { get; set; }
  44. public List<PeopleAge> PeopleAgeList { get; set; }
  45. public List<PeoplePlace> PeoplePlaceList { get; set; }
  46. public MainWindow()
  47. {
  48. InitializeComponent();
  49. DataContext = this;
  50. Globals.dataProvider = new LocalDataProvider();
  51. PeopleList = Globals.dataProvider.getPeople();
  52. PeopleGenderList = Globals.dataProvider.getGender().ToList();
  53. PeopleGenderList.Insert(0, new PeopleGender { title = "Пол" });
  54. PeopleAgeList = Globals.dataProvider.getAge().ToList();
  55. PeoplePlaceList = Globals.dataProvider.getPlace().ToList();
  56. PeoplePlaceList.Insert(0, new PeoplePlace { title = "Место" });
  57. }
  58. private void ExitButton_Click(object sender, RoutedEventArgs e)
  59. {
  60. Application.Current.Shutdown();
  61. }
  62. private void GenderFilterComboBox_SelectionChanged_1(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
  63. {
  64. selectedGender = (GenderFilterComboBox.SelectedItem as PeopleGender).title;
  65. Invalidate();
  66. }
  67. private void AgeFilterComboBox_SelectionChanged_2(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
  68. {
  69. selectedAge = AgeFilterComboBox.SelectedItem as PeopleAge;
  70. Invalidate();
  71. }
  72. private void PlaceFilterComboBox_SelectionChanged_3(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
  73. {
  74. selectedPlace = (PlaceFilterComboBox.SelectedItem as PeoplePlace).title;
  75. Invalidate();
  76. }
  77. public class LocalDataProvider : IDataProvider
  78. {
  79. public IEnumerable<PeopleGender> getGender()
  80. {
  81. return new PeopleGender[]
  82. {
  83. new PeopleGender()
  84. {
  85. title="Ж"
  86. },
  87. new PeopleGender()
  88. {
  89. title="М"
  90. }
  91. };
  92. }
  93. public IEnumerable<PeopleAge> getAge()
  94. {
  95. return new PeopleAge[]
  96. {
  97. new PeopleAge()
  98. {
  99. title="Все возраста",
  100. AgeFrom=0,
  101. AgeTo=99
  102. },
  103. new PeopleAge()
  104. {
  105. title="Подростки",
  106. AgeFrom=15,
  107. AgeTo=18
  108. },
  109. new PeopleAge()
  110. {
  111. title="Молодые",
  112. AgeFrom=18,
  113. AgeTo=30
  114. },
  115. new PeopleAge()
  116. {
  117. title="В Возврасте",
  118. AgeFrom=30,
  119. AgeTo=99
  120. }
  121. };
  122. }
  123. public IEnumerable<PeoplePlace> getPlace()
  124. {
  125. return new PeoplePlace[]
  126. {
  127. new PeoplePlace()
  128. {
  129. title="Набережная"
  130. },
  131. new PeoplePlace()
  132. {
  133. title="Йолка"
  134. },
  135. new PeoplePlace()
  136. {
  137. title="Бульвар"
  138. },
  139. new PeoplePlace()
  140. {
  141. title="ЙОТК"
  142. },
  143. new PeoplePlace()
  144. {
  145. title="Планета"
  146. },
  147. new PeoplePlace()
  148. {
  149. title="Ремзавод"
  150. },
  151. new PeoplePlace()
  152. {
  153. title="Медведево"
  154. },
  155. new PeoplePlace()
  156. {
  157. title="Пляж"
  158. },
  159. };
  160. }
  161. public IEnumerable<People> getPeople()
  162. {
  163. return new People[]{
  164. new People
  165. {
  166. Age=19,
  167. Name="Марина",
  168. Gender="Ж",
  169. Price=500,
  170. Place="Набережная"
  171. },
  172. new People
  173. {
  174. Price=9600,
  175. Name="Вика",
  176. Age=21,
  177. Gender="Ж",
  178. Place="Йолка"
  179. },
  180. new People
  181. {
  182. Price=50,
  183. Name="Кристина",
  184. Age=17,
  185. Gender="Ж",
  186. Place="Планета"
  187. },
  188. new People
  189. {
  190. Price=2000,
  191. Name="Анджелика",
  192. Age=16,
  193. Gender="Ж",
  194. Place="Бульвар"
  195. },
  196. new People
  197. {
  198. Price=1500,
  199. Name="Костя",
  200. Age=15,
  201. Gender="М",
  202. Place="Бульвар"
  203. },
  204. new People
  205. {
  206. Price=5000,
  207. Name="Вероника",
  208. Age=25,
  209. Gender="Ж",
  210. Place="Набережная"
  211. },
  212. new People
  213. {
  214. Price=1000,
  215. Name="Савелий",
  216. Age=20,
  217. Gender="М",
  218. Place="Пляж"
  219. },
  220. new People
  221. {
  222. Price=1500,
  223. Name="Александр",
  224. Age=39,
  225. Gender="М",
  226. Place="ЙОТК"
  227. },
  228. new People
  229. {
  230. Price=500,
  231. Name="Евгений",
  232. Age=18,
  233. Gender="М",
  234. Place="Медведево"
  235. },
  236. new People
  237. {
  238. Price=2500,
  239. Name="Давид",
  240. Age=18,
  241. Gender="М",
  242. Place="Ремзавод"
  243. },
  244. };
  245. }
  246. }
  247. }
  248. }