MainWindow.xaml.cs 9.1 KB

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