MainWindow.xaml.cs 8.0 KB

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