MainWindow.xaml.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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 WpfApp4.model;
  13. using System.Threading.Tasks;
  14. using System;
  15. using WpfApp4.model;
  16. namespace WpfApp4
  17. {
  18. /// <summary>
  19. /// Interaction logic for MainWindow.xaml
  20. /// </summary>
  21. public partial class MainWindow : Window, INotifyPropertyChanged
  22. {
  23. public event PropertyChangedEventHandler PropertyChanged;
  24. private void Invalidate()
  25. {
  26. if (PropertyChanged != null)
  27. PropertyChanged(this, new PropertyChangedEventArgs("HeroList"));
  28. }
  29. public string selectedPower = "Мощь";
  30. public HeroAge? selectedAge = null;
  31. public string selectedRace = "Раса";
  32. private IEnumerable<Hero> _HeroList;
  33. public IEnumerable<Hero> HeroList
  34. {
  35. get
  36. {
  37. var res = _HeroList;
  38. res = res
  39. .Where(c => (c.power == selectedPower || selectedPower == "Мощь"))
  40. .Where(c => (selectedAge == null || (c.Age >= selectedAge.AgeFrom && c.Age < selectedAge.AgeTo)))
  41. .Where(c => (c.race == selectedRace || selectedRace == "Раса"));
  42. if (searchFilter != "")
  43. res = res.Where(c => c.name.IndexOf(
  44. searchFilter,
  45. StringComparison.OrdinalIgnoreCase) >= 0);
  46. if (sortAsc) res = res.OrderBy(c => c.Age);
  47. else res = res.OrderByDescending(c => c.Age);
  48. return res;
  49. }
  50. set
  51. {
  52. _HeroList = value;
  53. }
  54. }
  55. public List<HeroPower> HeroPowerList { get; set; }
  56. public List<HeroAge> HeroAgeList { get; set; }
  57. public List<HeroRace> HeroRaceList { get; set; }
  58. public MainWindow()
  59. {
  60. InitializeComponent();
  61. DataContext = this;
  62. Globals.dataProvider = new CSVDataProvider();
  63. HeroList = Globals.dataProvider.getHero();
  64. HeroPowerList = Globals.dataProvider.getPower().ToList();
  65. HeroPowerList.Insert(0, new HeroPower { title = "Мощь" });
  66. HeroAgeList = Globals.dataProvider.getAge().ToList();
  67. HeroRaceList = Globals.dataProvider.getRace().ToList();
  68. HeroRaceList.Insert(0, new HeroRace { title = "Раса" });
  69. }
  70. private void ExitButton_Click(object sender, RoutedEventArgs e)
  71. {
  72. Application.Current.Shutdown();
  73. }
  74. private void powerFilterComboBox_SelectionChanged_1(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
  75. {
  76. selectedPower = (powerFilterComboBox.SelectedItem as HeroPower).title;
  77. Invalidate();
  78. }
  79. private void AgeFilterComboBox_SelectionChanged_2(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
  80. {
  81. selectedAge = AgeFilterComboBox.SelectedItem as HeroAge;
  82. Invalidate();
  83. }
  84. private void RaceFilterComboBox_SelectionChanged_3(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
  85. {
  86. selectedRace = (RaceFilterComboBox.SelectedItem as HeroRace).title;
  87. Invalidate();
  88. }
  89. private string searchFilter = "";
  90. private void SearchFilter_KeyUp(object sender, KeyEventArgs e)
  91. {
  92. searchFilter = SearchFilterTextBox.Text;
  93. Invalidate();
  94. }
  95. private bool sortAsc = true;
  96. private void RadioButton_Checked(object sender, RoutedEventArgs e)
  97. {
  98. sortAsc = (sender as RadioButton).Tag.ToString() == "1";
  99. Invalidate();
  100. }
  101. }
  102. interface IDataProvider
  103. {
  104. IEnumerable<Hero> getHero();
  105. IEnumerable<HeroPower> getPower();
  106. IEnumerable<HeroAge> getAge();
  107. IEnumerable<HeroRace> getRace();
  108. }
  109. public class LocalDataProvider : IDataProvider
  110. {
  111. public IEnumerable<HeroPower> getPower()
  112. {
  113. return new HeroPower[]
  114. {
  115. new HeroPower()
  116. {
  117. title="1/10"
  118. },
  119. new HeroPower()
  120. {
  121. title="2/10"
  122. },
  123. new HeroPower()
  124. {
  125. title="3/10"
  126. },
  127. new HeroPower()
  128. {
  129. title="4/10"
  130. },
  131. new HeroPower()
  132. {
  133. title="5/10"
  134. },
  135. new HeroPower()
  136. {
  137. title="6/10"
  138. },
  139. new HeroPower()
  140. {
  141. title="7/10"
  142. },
  143. new HeroPower()
  144. {
  145. title="8/10"
  146. },
  147. new HeroPower()
  148. {
  149. title="9/10"
  150. },
  151. new HeroPower()
  152. {
  153. title="10/10"
  154. },
  155. };
  156. }
  157. public IEnumerable<HeroAge> getAge()
  158. {
  159. return new HeroAge[]
  160. {
  161. new HeroAge()
  162. {
  163. title="Все возраста",
  164. AgeFrom=0,
  165. AgeTo=2000
  166. },
  167. new HeroAge()
  168. {
  169. title="Дети",
  170. AgeFrom=1,
  171. AgeTo=100
  172. },
  173. new HeroAge()
  174. {
  175. title="Подростки",
  176. AgeFrom=100,
  177. AgeTo=500
  178. },
  179. new HeroAge()
  180. {
  181. title="Молодые",
  182. AgeFrom=500,
  183. AgeTo=700
  184. },
  185. new HeroAge()
  186. {
  187. title="Старики",
  188. AgeFrom=700,
  189. AgeTo=2000
  190. }
  191. };
  192. }
  193. public IEnumerable<HeroRace> getRace()
  194. {
  195. return new HeroRace[]
  196. {
  197. new HeroRace()
  198. {
  199. title="Человек"
  200. },
  201. new HeroRace()
  202. {
  203. title="Дракон"
  204. },
  205. new HeroRace()
  206. {
  207. title="Фея"
  208. },
  209. new HeroRace()
  210. {
  211. title="Огр"
  212. },
  213. new HeroRace()
  214. {
  215. title="Рыба"
  216. },
  217. new HeroRace()
  218. {
  219. title="Селёдка"
  220. },
  221. new HeroRace()
  222. {
  223. title="Камень"
  224. },
  225. new HeroRace()
  226. {
  227. title="Гоблин"
  228. },
  229. };
  230. }
  231. public IEnumerable<Hero> getHero()
  232. {
  233. return new Hero[]{
  234. new Hero{
  235. race="Человек",
  236. name="Invoker",
  237. Age = 1000,
  238. power= "10/10"},
  239. new Hero{
  240. race="Человек",
  241. name="Juggernaut",
  242. Age=450,
  243. power="9/10"},
  244. new Hero{
  245. race="Человек",
  246. name="Lina",
  247. Age = 300,
  248. power="8/10"},
  249. new Hero{
  250. race="Гоблин",
  251. name="Troll Warloard",
  252. Age = 100,
  253. power= "7/10"},
  254. new Hero{
  255. race="Рыба",
  256. name="Slark",
  257. Age = 120,
  258. power="6/10"},
  259. new Hero{
  260. race="Селёдка",
  261. name="Slardar",
  262. Age = 200,
  263. power= "5/10"},
  264. new Hero{
  265. race="Камень",
  266. name="Tiny",
  267. Age = 20000,
  268. power="4/10"},
  269. new Hero{
  270. race="Фея",
  271. name="Dark Willow",
  272. Age = 700,
  273. power="3/10"},
  274. new Hero{
  275. race="Огр",
  276. name="Orge Magi",
  277. Age = 1400,
  278. power="2/10"},
  279. new Hero{
  280. race="Дракон",
  281. name="Viper",
  282. Age = 1900,
  283. power="1/10"},
  284. };
  285. }
  286. }
  287. }