ApplicationWindow.xaml.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Windows;
  5. using System.Windows.Controls.Primitives;
  6. using System.Windows.Input;
  7. using System.Windows.Media;
  8. using Курсовой_проект_3._1.Windows;
  9. namespace Курсовой_проект_3._1
  10. {
  11. /// <summary>
  12. /// Логика взаимодействия для ApplicationWindow.xaml
  13. /// </summary>
  14. public partial class ApplicationWindow : Window
  15. {
  16. List<Item> countryList = new List<Item>();
  17. List<Item> disciplineList = new List<Item>();
  18. MyTeamContext _context;
  19. public ApplicationWindow()
  20. {
  21. InitializeComponent();
  22. _context = new MyTeamContext();
  23. PlayerListShowButton.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
  24. foreach (Countries country in _context.Countries)
  25. {
  26. countryList.Add(CountryToItem(country));
  27. }
  28. foreach (Disciplines discipline in _context.Disciplines)
  29. {
  30. disciplineList.Add(DisciplineToItem(discipline));
  31. }
  32. CountryFilterPlayersLB.ItemsSource = countryList;
  33. DiciplineFilterPlayersLB.ItemsSource = disciplineList;
  34. }
  35. private Item CountryToItem(Countries country)
  36. {
  37. return new Item() {ItemName = country.Name, IsSelected = false, ItemId = country.Id };
  38. }
  39. private Item DisciplineToItem(Disciplines discipline)
  40. {
  41. return new Item() { ItemName = discipline.Name, IsSelected = false, ItemId = discipline.Id };
  42. }
  43. // NavigationBtns
  44. private void SearchBtn_Click(object sender, RoutedEventArgs e)
  45. {
  46. SearchWindow wnd = new SearchWindow();
  47. wnd.ShowDialog();
  48. }
  49. private void ProfileBtn_Click(object sender, RoutedEventArgs e)
  50. {
  51. MainWindow wnd = new MainWindow(App.UserId);
  52. wnd.Show();
  53. Close();
  54. }
  55. // ListShowBtns
  56. private void PlayerListShowButton_Click(object sender, RoutedEventArgs e)
  57. {
  58. var bc = new BrushConverter();
  59. PlayerListShowButton.Background = (Brush)bc.ConvertFrom("#68A4C8");
  60. TeamListShowButton.Background = (Brush)bc.ConvertFrom("#FFDDDDDD");
  61. TournamentListShowButton.Background = (Brush)bc.ConvertFrom("#FFDDDDDD");
  62. PlayersFilter.Visibility = Visibility.Visible;
  63. TeamsFilter.Visibility = Visibility.Hidden;
  64. TournamentsFilter.Visibility = Visibility.Hidden;
  65. PlayerAppAddBtn.Visibility = Visibility.Visible;
  66. TeamAppAddBtn.Visibility = Visibility.Hidden;
  67. TournamentAddBtn.Visibility = Visibility.Hidden;
  68. TeamAddBtn.Visibility = Visibility.Collapsed;
  69. applicationsLB.ItemsSource = new List<string>();
  70. ApplyFilterPlayersButton.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
  71. }
  72. private void TeamListShowButton_Click(object sender, RoutedEventArgs e)
  73. {
  74. var bc = new BrushConverter();
  75. PlayerListShowButton.Background = (Brush)bc.ConvertFrom("#FFDDDDDD");
  76. TeamListShowButton.Background = (Brush)bc.ConvertFrom("#68A4C8");
  77. TournamentListShowButton.Background = (Brush)bc.ConvertFrom("#FFDDDDDD");
  78. PlayersFilter.Visibility = Visibility.Hidden;
  79. TeamsFilter.Visibility = Visibility.Visible;
  80. TournamentsFilter.Visibility = Visibility.Hidden;
  81. PlayerAppAddBtn.Visibility = Visibility.Hidden;
  82. TeamAppAddBtn.Visibility = Visibility.Visible;
  83. TournamentAddBtn.Visibility = Visibility.Hidden;
  84. TeamAddBtn.Visibility = Visibility.Visible;
  85. // очищаем фильтры
  86. LowerDataPickerPlayers.Text = "";
  87. UpperDataPickerPlayers.Text = "";
  88. LowerAgePlayersTBox.Text = "";
  89. UpperAgePlayersTBox.Text = "";
  90. applicationsLB.ItemsSource = new List<byte>();
  91. ApplyFilterTeamsButton.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
  92. }
  93. private void TournamentListShowButton_Click(object sender, RoutedEventArgs e)
  94. {
  95. var bc = new BrushConverter();
  96. PlayerListShowButton.Background = (Brush)bc.ConvertFrom("#FFDDDDDD");
  97. TeamListShowButton.Background = (Brush)bc.ConvertFrom("#FFDDDDDD");
  98. TournamentListShowButton.Background = (Brush)bc.ConvertFrom("#68A4C8");
  99. PlayersFilter.Visibility = Visibility.Hidden;
  100. TeamsFilter.Visibility = Visibility.Hidden;
  101. TournamentsFilter.Visibility = Visibility.Visible;
  102. PlayerAppAddBtn.Visibility = Visibility.Hidden;
  103. TeamAppAddBtn.Visibility = Visibility.Hidden;
  104. TournamentAddBtn.Visibility = Visibility.Visible;
  105. TeamAddBtn.Visibility = Visibility.Collapsed;
  106. // очищаем фильтры
  107. LowerDataPickerPlayers.Text = "";
  108. UpperDataPickerPlayers.Text = "";
  109. LowerAgePlayersTBox.Text = "";
  110. UpperAgePlayersTBox.Text = "";
  111. CountryFilterPlayersLB.ItemsSource = new List<byte>();
  112. DiciplineFilterPlayersLB.ItemsSource = new List<byte>();
  113. applicationsLB.ItemsSource = new List<byte>();
  114. ApplyFilterTournamentsButton.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
  115. }
  116. // ApplyFilterBtns
  117. private void ApplyFilterPlayersButton_Click(object sender, RoutedEventArgs e)
  118. {
  119. // обновляем шаблон для заявок
  120. templateSelector.Text = "PlayersItemTemplate";
  121. // инициализируем переменные
  122. DateTime lowerDate, upperDate;
  123. int lowerAge, upperAge;
  124. List<int> countries = new List<int>();
  125. List<int> disciplines = new List<int>();
  126. lowerDate = String.IsNullOrWhiteSpace(LowerDataPickerPlayers.Text) ? Convert.ToDateTime("01.12.2021") : Convert.ToDateTime(LowerDataPickerPlayers.Text.Trim());
  127. upperDate = String.IsNullOrWhiteSpace(UpperDataPickerPlayers.Text) ? DateTime.Now : Convert.ToDateTime(UpperDataPickerPlayers.Text.Trim());
  128. lowerAge = String.IsNullOrWhiteSpace(LowerAgePlayersTBox.Text) ? 0 : Convert.ToInt32(LowerAgePlayersTBox.Text.Trim());
  129. upperAge = String.IsNullOrWhiteSpace(UpperAgePlayersTBox.Text) ? 99 : Convert.ToInt32(UpperAgePlayersTBox.Text.Trim());
  130. foreach (Item item in CountryFilterPlayersLB.Items)
  131. {
  132. if (item.IsSelected)
  133. {
  134. countries.Add(item.ItemId);
  135. }
  136. }
  137. foreach(Item item in DiciplineFilterPlayersLB.Items)
  138. {
  139. if (item.IsSelected)
  140. {
  141. disciplines.Add(item.ItemId);
  142. }
  143. }
  144. string countriesString = countries.Count == 0 ? "*" : string.Join(",", countries);
  145. string disciplinesString = disciplines.Count == 0 ? "*" : string.Join(",", disciplines);
  146. // проверка на корректность введенных значений
  147. if (Convert.ToInt32(lowerAge) > Convert.ToInt32(upperAge))
  148. {
  149. MessageBox.Show("Некорректно введен возвраст!");
  150. return;
  151. }
  152. if (DateTime.Compare(Convert.ToDateTime(lowerDate), Convert.ToDateTime(upperDate)) > 0)
  153. {
  154. MessageBox.Show("Некорректно введены даты!");
  155. return;
  156. }
  157. // очищаем текущий список
  158. applicationsLB.ItemsSource = new List<string>();
  159. List<PlayerApps> apps = new List<PlayerApps>();
  160. List<PlayerApps> beforeApps = new List<PlayerApps>();
  161. // получаем список заявок (lowerAgeParam, upperAgeParam, lowerDateParam, upperDateParam, countriesParam, disciplinesParam)
  162. if (countriesString == "*" || disciplinesString == "*")
  163. {
  164. if (countriesString == "*" && disciplinesString == "*")
  165. {
  166. beforeApps = _context.PlayerApps.Where(app => app.AppDate >= lowerDate && app.AppDate <= upperDate).ToList();
  167. foreach (PlayerApps beforeApp in beforeApps)
  168. {
  169. if (Func.CalculateAge(beforeApp.Users.Birthday) >= lowerAge && Func.CalculateAge(beforeApp.Users.Birthday) <= upperAge)
  170. {
  171. apps.Add(beforeApp);
  172. }
  173. }
  174. }
  175. else if (countriesString == "*")
  176. {
  177. foreach (int discipline in disciplines)
  178. {
  179. beforeApps.AddRange(_context.PlayerApps.Where(app => app.AppDate >= lowerDate && app.AppDate <= upperDate && app.Users.FK_Discipline_Id == discipline).ToList());
  180. }
  181. foreach (PlayerApps beforeApp in beforeApps)
  182. {
  183. if (Func.CalculateAge(beforeApp.Users.Birthday) >= lowerAge && Func.CalculateAge(beforeApp.Users.Birthday) <= upperAge)
  184. {
  185. apps.Add(beforeApp);
  186. }
  187. }
  188. }
  189. else
  190. {
  191. foreach (int country in countries)
  192. {
  193. beforeApps.AddRange(_context.PlayerApps.Where(app => app.AppDate >= lowerDate && app.AppDate <= upperDate && app.Users.FK_Country_Id == country).ToList());
  194. }
  195. foreach (PlayerApps beforeApp in beforeApps)
  196. {
  197. if (Func.CalculateAge(beforeApp.Users.Birthday) >= lowerAge && Func.CalculateAge(beforeApp.Users.Birthday) <= upperAge)
  198. {
  199. apps.Add(beforeApp);
  200. }
  201. }
  202. }
  203. }
  204. else
  205. {
  206. foreach (int country in countries)
  207. {
  208. foreach (int discipline in disciplines)
  209. {
  210. beforeApps.AddRange(_context.PlayerApps.Where(app => app.AppDate >= lowerDate && app.AppDate <= upperDate && app.Users.FK_Country_Id == country && app.Users.FK_Discipline_Id == discipline).ToList());
  211. }
  212. }
  213. foreach (PlayerApps beforeApp in beforeApps)
  214. {
  215. if (Func.CalculateAge(beforeApp.Users.Birthday) >= lowerAge && Func.CalculateAge(beforeApp.Users.Birthday) <= upperAge)
  216. {
  217. apps.Add(beforeApp);
  218. }
  219. }
  220. }
  221. // заполняем список заявок
  222. List<PlayerApplication> playerApps = new List<PlayerApplication>();
  223. foreach (PlayerApps app in apps)
  224. {
  225. PlayerApplication playerApp = new PlayerApplication();
  226. playerApp.Name = app.Users.LName + " " + app.Users.FName + " " + app.Users.MName;
  227. playerApp.Nickname = app.Users.Nickname;
  228. playerApp.Age = Func.CalculateAge(app.Users.Birthday).ToString();
  229. if (string.IsNullOrEmpty(app.Users.PhotoPath))
  230. {
  231. playerApp.PhotoURL = @"C:\Users\nikich4523\source\repos\Курсовой проект 3.1\Images\WithoutPhoto.png";
  232. }
  233. else
  234. {
  235. playerApp.PhotoURL = app.Users.PhotoPath;
  236. }
  237. playerApp.CountryName = app.Users.Countries.Name;
  238. if (string.IsNullOrEmpty(app.Users.Countries.IconPath))
  239. {
  240. playerApp.CountryURL = @"C:\Users\nikich4523\source\repos\Курсовой проект 3.1\Курсовой проект 3.1\img\countrys - 24\_unknown.png";
  241. }
  242. else
  243. {
  244. playerApp.CountryURL = app.Users.Countries.IconPath;
  245. }
  246. playerApp.DisciplineName = app.Users.Disciplines != null ? app.Users.Disciplines.Name : "Не указано";
  247. playerApp.Email = app.Users.Email;
  248. playerApp.PhoneNumber = "+" + app.Users.PhoneNumber;
  249. playerApp.Title = app.Title;
  250. playerApp.Text = app.AppText;
  251. playerApp.Date = app.AppDate.ToString("D");
  252. playerApp.PlayerId = app.Users.Id.ToString();
  253. playerApps.Add(playerApp);
  254. }
  255. applicationsLB.ItemsSource = playerApps;
  256. }
  257. private void ApplyFilterTeamsButton_Click(object sender, RoutedEventArgs e)
  258. {
  259. // обновляем шаблон для заявок
  260. templateSelector.Text = "TeamsItemTemplate";
  261. // очищаем текущий список
  262. applicationsLB.ItemsSource = new List<string>();
  263. // инициализируем переменные
  264. DateTime lowerDate, upperDate;
  265. List<int> countries = new List<int>();
  266. List<int> disciplines = new List<int>();
  267. lowerDate = string.IsNullOrWhiteSpace(LowerDataPickerTeams.Text) ? Convert.ToDateTime("01.12.2021") : Convert.ToDateTime(LowerDataPickerTeams.Text.Trim());
  268. upperDate = string.IsNullOrWhiteSpace(UpperDataPickerTeams.Text) ? DateTime.Now : Convert.ToDateTime(UpperDataPickerTeams.Text.Trim());
  269. foreach (Item item in CountryFilterTeamsLB.Items)
  270. {
  271. if (item.IsSelected)
  272. {
  273. countries.Add(item.ItemId);
  274. }
  275. }
  276. foreach (Item item in DiciplineFilterTeamsLB.Items)
  277. {
  278. if (item.IsSelected)
  279. {
  280. disciplines.Add(item.ItemId);
  281. }
  282. }
  283. string countriesString = countries.Count == 0 ? "*" : string.Join(",", countries);
  284. string disciplinesString = disciplines.Count == 0 ? "*" : string.Join(",", disciplines);
  285. // проверка на корректность введенных значений
  286. if (DateTime.Compare(lowerDate, upperDate) > 0)
  287. {
  288. MessageBox.Show("Некорректно введены даты!");
  289. return;
  290. }
  291. List<TeamApps> apps = new List<TeamApps>();
  292. // получаем список заявок (lowerAgeParam, upperAgeParam, lowerDateParam, upperDateParam, countriesParam, disciplinesParam)
  293. if (countriesString == "*" || disciplinesString == "*")
  294. {
  295. if (countriesString == "*" && disciplinesString == "*")
  296. {
  297. apps = _context.TeamApps.Where(app => app.AppDate >= lowerDate && app.AppDate <= upperDate).ToList();
  298. }
  299. else if (countriesString == "*")
  300. {
  301. foreach (int discipline in disciplines)
  302. {
  303. apps.AddRange(_context.TeamApps.Where(app => app.AppDate >= lowerDate && app.AppDate <= upperDate && app.Teams.Users.FK_Discipline_Id == discipline).ToList());
  304. }
  305. }
  306. else
  307. {
  308. foreach (int country in countries)
  309. {
  310. apps.AddRange(_context.TeamApps.Where(app => app.AppDate >= lowerDate && app.AppDate <= upperDate && app.Teams.Users.FK_Country_Id == country).ToList());
  311. }
  312. }
  313. }
  314. else
  315. {
  316. foreach (int country in countries)
  317. {
  318. foreach (int discipline in disciplines)
  319. {
  320. apps.AddRange(_context.TeamApps.Where(app => app.AppDate >= lowerDate && app.AppDate <= upperDate && app.Teams.Users.FK_Discipline_Id == discipline
  321. && app.Teams.Users.FK_Country_Id == country).ToList());
  322. }
  323. }
  324. }
  325. // заполняем список заявок
  326. List<TeamApplication> teamApps = new List<TeamApplication>();
  327. foreach (TeamApps app in apps)
  328. {
  329. TeamApplication teamApp = new TeamApplication();
  330. teamApp.Name = app.Teams.Name;
  331. teamApp.DateOfFoundation = app.Teams.FoundationDate.ToString("d");
  332. if (string.IsNullOrEmpty(app.Teams.LogoPath))
  333. {
  334. teamApp.LogoURL = @"C:\Users\nikich4523\source\repos\Курсовой проект 3.1\Images\WithoutPhoto.png";
  335. }
  336. else
  337. {
  338. teamApp.LogoURL = app.Teams.LogoPath;
  339. }
  340. teamApp.CountryName = app.Teams.Users.Countries.Name;
  341. if (string.IsNullOrEmpty(app.Teams.Users.Countries.IconPath))
  342. {
  343. teamApp.CountryURL = @"C:\Users\nikich4523\source\repos\Курсовой проект 3.1\Курсовой проект 3.1\img\countrys - 24\_unknown.png";
  344. }
  345. else
  346. {
  347. teamApp.CountryURL = app.Teams.Countries.IconPath;
  348. }
  349. teamApp.DisciplineName = app.Teams.Users.Disciplines.Name;
  350. teamApp.Title = app.Title;
  351. teamApp.Text = app.AppText;
  352. teamApp.Date = app.AppDate.ToString("D");
  353. teamApp.TeamId = app.Teams.Id.ToString();
  354. teamApps.Add(teamApp);
  355. }
  356. applicationsLB.ItemsSource = teamApps;
  357. }
  358. private void ApplyFilterTournamentsButton_Click(object sender, RoutedEventArgs e)
  359. {
  360. // обновляем шаблон для заявок
  361. templateSelector.Text = "TournamentsItemTemplate";
  362. // очищаем текущий список
  363. applicationsLB.ItemsSource = new List<string>();
  364. // инициализируем переменные
  365. DateTime lowerDate, upperDate;
  366. int lowerPrize, upperPrize;
  367. bool withFreePlace;
  368. List<int> disciplines = new List<int>();
  369. lowerDate = string.IsNullOrWhiteSpace(LowerDataPickerTournaments.Text) ? Convert.ToDateTime("01.01.2021") : Convert.ToDateTime(LowerDataPickerTournaments.Text.Trim());
  370. upperDate = string.IsNullOrWhiteSpace(UpperDataPickerTournaments.Text) ? DateTime.Now : Convert.ToDateTime(UpperDataPickerTournaments.Text.Trim());
  371. lowerPrize = string.IsNullOrWhiteSpace(LowerPrizeTournamentsTBox.Text) ? 0 : Convert.ToInt32(LowerPrizeTournamentsTBox.Text.Trim());
  372. upperPrize = string.IsNullOrWhiteSpace(UpperPrizeTournamentsTBox.Text) ? 99999999 : Convert.ToInt32(UpperPrizeTournamentsTBox.Text.Trim());
  373. withFreePlace = (bool)FreePlaceTournamentsCB.IsChecked;
  374. foreach (Item item in DiciplineFilterTournamentsLB.Items)
  375. {
  376. if (item.IsSelected)
  377. {
  378. disciplines.Add(item.ItemId);
  379. }
  380. }
  381. string disciplinesString = disciplines.Count == 0 ? "*" : string.Join(",", disciplines);
  382. // проверка на корректность введенных значений
  383. if (DateTime.Compare(Convert.ToDateTime(lowerDate), Convert.ToDateTime(upperDate)) > 0)
  384. {
  385. MessageBox.Show("Некорректно введены даты!");
  386. return;
  387. }
  388. // получаем список заявок
  389. List<Tournaments> apps = new List<Tournaments>();
  390. if (disciplinesString == "*")
  391. {
  392. if (withFreePlace)
  393. {
  394. apps = _context.Tournaments.Where(app => app.DateStart >= lowerDate && app.DateStart <= upperDate && app.PrizeFond >= lowerPrize && app.PrizeFond <= upperPrize
  395. && app.MaxTeamsCount > _context.Matches.Where(m => m.FK_Tournament_Id == app.Id && m.RoundNum == 1).Count()).ToList();
  396. }
  397. else
  398. {
  399. apps = _context.Tournaments.Where(app => app.DateStart >= lowerDate && app.DateStart <= upperDate && app.PrizeFond >= lowerPrize && app.PrizeFond <= upperPrize).ToList();
  400. }
  401. }
  402. else
  403. {
  404. foreach (int discipline in disciplines)
  405. {
  406. if (withFreePlace)
  407. {
  408. apps.AddRange(_context.Tournaments.Where(app => app.DateStart >= lowerDate && app.DateStart <= upperDate && app.PrizeFond >= lowerPrize && app.PrizeFond <= upperPrize
  409. && app.Users.FK_Discipline_Id == discipline && app.MaxTeamsCount > _context.Matches.Where(m => m.FK_Tournament_Id == app.Id && m.RoundNum == 1).Count()).ToList());
  410. }
  411. else
  412. {
  413. apps.AddRange(_context.Tournaments.Where(app => app.DateStart >= lowerDate && app.DateStart <= upperDate && app.PrizeFond >= lowerPrize && app.PrizeFond <= upperPrize
  414. && app.Users.FK_Discipline_Id == discipline).ToList());
  415. }
  416. }
  417. }
  418. // заполняем список заявок
  419. List<TournamentApplication> tournamentApps = new List<TournamentApplication>();
  420. foreach (Tournaments app in apps)
  421. {
  422. TournamentApplication tournamentApp = new TournamentApplication();
  423. tournamentApp.TournamentId = app.Id.ToString();
  424. tournamentApp.Title = app.Name;
  425. tournamentApp.Date = app.DateStart.ToString("d") + " - " + app.DateEnd.ToString("d");
  426. tournamentApp.PrizeFond = app.PrizeFond.ToString();
  427. tournamentApp.PhoneNumber = app.Users.PhoneNumber;
  428. tournamentApp.Email = app.Users.Email;
  429. if (string.IsNullOrEmpty(app.LogoPath))
  430. {
  431. tournamentApp.LogoPath = @"C:\Users\nikich4523\source\repos\Курсовой проект 3.1\Images\WithoutPhoto.png";
  432. }
  433. else
  434. {
  435. tournamentApp.LogoPath = app.LogoPath;
  436. }
  437. tournamentApp.Venue = app.Venue;
  438. if (app.Users.Disciplines != null)
  439. {
  440. tournamentApp.DisciplineName = app.Users.Disciplines.Name;
  441. tournamentApp.IconPath = app.Users.Disciplines.IconPath;
  442. }
  443. int teamCount = _context.Matches.Where(m => m.FK_Tournament_Id == app.Id && m.RoundNum == 1).Count() * 2;
  444. tournamentApp.TeamCount = teamCount.ToString() + " / " + app.MaxTeamsCount.ToString();
  445. tournamentApp.Format = app.TournamentFormats.Name;
  446. if (withFreePlace)
  447. {
  448. if (teamCount < app.MaxTeamsCount)
  449. {
  450. tournamentApps.Add(tournamentApp);
  451. }
  452. }
  453. else
  454. {
  455. tournamentApps.Add(tournamentApp);
  456. }
  457. }
  458. applicationsLB.ItemsSource = tournamentApps;
  459. }
  460. // AddAppBtns
  461. private void PlayerAppAddBtn_Click(object sender, RoutedEventArgs e)
  462. {
  463. PlayerApplicationAddWindow wnd = new PlayerApplicationAddWindow();
  464. wnd.ShowDialog();
  465. }
  466. private void TeamAppAddBtn_Click(object sender, RoutedEventArgs e)
  467. {
  468. TeamApplicationAddWindow wnd = new TeamApplicationAddWindow();
  469. wnd.ShowDialog();
  470. }
  471. private void TeamAddBtn_Click(object sender, RoutedEventArgs e)
  472. {
  473. if (_context.TeamsUsers.Where(tu => tu.FK_User_Id == App.UserId && tu.DateEnd == null).Count() == 0)
  474. {
  475. CreateTeamWindow wnd = new CreateTeamWindow();
  476. wnd.Show();
  477. Close();
  478. }
  479. else
  480. {
  481. MessageBox.Show("У вас уже есть команда!");
  482. }
  483. }
  484. private void TournamentAddBtn_Click(object sender, RoutedEventArgs e)
  485. {
  486. CreateTournamentWindow wnd = new CreateTournamentWindow();
  487. wnd.ShowDialog();
  488. }
  489. // applicationsLB
  490. private void applicationsLB_MouseDoubleClick(object sender, MouseButtonEventArgs e)
  491. {
  492. if (applicationsLB.SelectedItem != null)
  493. {
  494. if (applicationsLB.SelectedItem is PlayerApplication)
  495. {
  496. PlayerApplication player = (PlayerApplication)applicationsLB.SelectedItem;
  497. MainWindow wnd = new MainWindow(Convert.ToInt32(player.PlayerId));
  498. wnd.Show();
  499. }
  500. else if (applicationsLB.SelectedItem is PlayerApplication)
  501. {
  502. TeamApplication team = (TeamApplication)applicationsLB.SelectedItem;
  503. TeamProfileWindow wnd = new TeamProfileWindow(Convert.ToInt32(team.TeamId));
  504. wnd.Show();
  505. }
  506. else
  507. {
  508. TournamentApplication tournament = (TournamentApplication)applicationsLB.SelectedItem;
  509. TournamentWindow wnd = new TournamentWindow(Convert.ToInt32(tournament.TournamentId));
  510. wnd.Show();
  511. }
  512. Close();
  513. }
  514. }
  515. // Players filter expander
  516. private void CountryExpanderPlayers_Expanded(object sender, RoutedEventArgs e)
  517. {
  518. CountryFilterExpanderRowPlayers.Height = new GridLength(2, GridUnitType.Star);
  519. BuffExpanderRowPlayers.Height = new GridLength(0.2, GridUnitType.Star);
  520. DiciplineExpanderPlayers.IsExpanded = false;
  521. }
  522. private void DiciplineExpanderPlayers_Expanded(object sender, RoutedEventArgs e)
  523. {
  524. DiciplineFilterExpanderRowPlayers.Height = new GridLength(2, GridUnitType.Star);
  525. BuffExpanderRowPlayers.Height = new GridLength(0.2, GridUnitType.Star);
  526. CountryExpanderPlayers.IsExpanded = false;
  527. }
  528. private void CountryExpanderPlayers_Collapsed(object sender, RoutedEventArgs e)
  529. {
  530. CountryFilterExpanderRowPlayers.Height = new GridLength(0.2, GridUnitType.Star);
  531. BuffExpanderRowPlayers.Height = new GridLength(0.8, GridUnitType.Star);
  532. }
  533. private void DiciplineExpanderPlayers_Collapsed(object sender, RoutedEventArgs e)
  534. {
  535. DiciplineFilterExpanderRowPlayers.Height = new GridLength(0.2, GridUnitType.Star);
  536. BuffExpanderRowPlayers.Height = new GridLength(0.8, GridUnitType.Star);
  537. }
  538. // Teams filter expander
  539. private void CountryExpanderTeams_Expanded(object sender, RoutedEventArgs e)
  540. {
  541. CountryFilterExpanderRowTeams.Height = new GridLength(2, GridUnitType.Star);
  542. BuffExpanderRowTeams.Height = new GridLength(0.2, GridUnitType.Star);
  543. DiciplineExpanderTeams.IsExpanded = false;
  544. }
  545. private void DiciplineExpanderTeams_Expanded(object sender, RoutedEventArgs e)
  546. {
  547. DiciplineFilterExpanderRowTeams.Height = new GridLength(2, GridUnitType.Star);
  548. BuffExpanderRowTeams.Height = new GridLength(0.2, GridUnitType.Star);
  549. CountryExpanderTeams.IsExpanded = false;
  550. }
  551. private void CountryExpanderTeams_Collapsed(object sender, RoutedEventArgs e)
  552. {
  553. CountryFilterExpanderRowTeams.Height = new GridLength(0.2, GridUnitType.Star);
  554. BuffExpanderRowTeams.Height = new GridLength(0.8, GridUnitType.Star);
  555. }
  556. private void DiciplineExpanderTeams_Collapsed(object sender, RoutedEventArgs e)
  557. {
  558. DiciplineFilterExpanderRowTeams.Height = new GridLength(0.2, GridUnitType.Star);
  559. BuffExpanderRowTeams.Height = new GridLength(0.8, GridUnitType.Star);
  560. }
  561. // Tournaments filter expander
  562. private void VenueExpanderTournaments_Expanded(object sender, RoutedEventArgs e)
  563. {
  564. VenueFilterExpanderRowTournaments.Height = new GridLength(2, GridUnitType.Star);
  565. BuffExpanderRowTournaments.Height = new GridLength(0.1, GridUnitType.Star);
  566. DiciplineExpanderTournaments.IsExpanded = false;
  567. }
  568. private void DiciplineExpanderTournaments_Expanded(object sender, RoutedEventArgs e)
  569. {
  570. DiciplineFilterExpanderRowTournaments.Height = new GridLength(2, GridUnitType.Star);
  571. BuffExpanderRowTournaments.Height = new GridLength(0.1, GridUnitType.Star);
  572. VenueExpanderTournaments.IsExpanded = false;
  573. }
  574. private void VenueExpanderTournaments_Collapsed(object sender, RoutedEventArgs e)
  575. {
  576. VenueFilterExpanderRowTournaments.Height = new GridLength(0.2, GridUnitType.Star);
  577. BuffExpanderRowTournaments.Height = new GridLength(0.8, GridUnitType.Star);
  578. }
  579. private void DiciplineExpanderTournaments_Collapsed(object sender, RoutedEventArgs e)
  580. {
  581. DiciplineFilterExpanderRowTournaments.Height = new GridLength(0.2, GridUnitType.Star);
  582. BuffExpanderRowTeams.Height = new GridLength(0.8, GridUnitType.Star);
  583. }
  584. }
  585. // Класс, описывающий элементы для фильтрации (Страна, Дисциплина, Место проведения) (ListBox)
  586. public class Item
  587. {
  588. public string ItemName { get; set;}
  589. public bool IsSelected { get; set; }
  590. public int ItemId { get; set; }
  591. }
  592. // Класс, описывающий заявку от игрока
  593. public class PlayerApplication
  594. {
  595. public string Name { get; set; }
  596. public string Nickname { get; set; }
  597. public string Age { get; set; }
  598. public string DisciplineName { get; set; }
  599. public string PhotoURL { get; set; }
  600. public string CountryName { get; set; }
  601. public string CountryURL { get; set; }
  602. public string PhoneNumber { get; set; }
  603. public string Email { get; set; }
  604. public string Title { get; set; }
  605. public string Text { get; set; }
  606. public string Date { get; set; }
  607. public string PlayerId { get; set; }
  608. }
  609. // Класс, описывающий заявку от команды
  610. public class TeamApplication
  611. {
  612. public string Name { get; set; }
  613. public string DateOfFoundation { get; set; }
  614. public string DisciplineName { get; set; }
  615. public string LogoURL { get; set; }
  616. public string CountryName { get; set; }
  617. public string CountryURL { get; set; }
  618. public string Title { get; set; }
  619. public string Text { get; set; }
  620. public string Date { get; set; }
  621. public string TeamId { get; set; }
  622. }
  623. // Класс, описывающий заявку от команды
  624. public class TournamentApplication
  625. {
  626. public string Name { get; set; }
  627. public string Date { get; set; }
  628. public string DisciplineName { get; set; }
  629. public string IconPath { get; set; }
  630. public string LogoPath { get; set; }
  631. public string Venue { get; set; }
  632. public string Email { get; set; }
  633. public string PhoneNumber { get; set; }
  634. public string PrizeFond { get; set; }
  635. public string Format { get; set; }
  636. public string TeamCount { get; set; }
  637. public string Title { get; set; }
  638. public string TournamentId { get; set; }
  639. }
  640. }