SelectTeamsInMatchWindow.xaml.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.Entity;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Shapes;
  15. namespace Курсовой_проект_3._1.Windows
  16. {
  17. /// <summary>
  18. /// Логика взаимодействия для SelectTeamsInMatchWindow.xaml
  19. /// </summary>
  20. public partial class SelectTeamsInMatchWindow : Window
  21. {
  22. MyTeamContext _context;
  23. int nowTournamentId;
  24. int roundNum;
  25. public SelectTeamsInMatchWindow(int tournamentId, int roundNum)
  26. {
  27. InitializeComponent();
  28. _context = new MyTeamContext();
  29. nowTournamentId = tournamentId;
  30. this.roundNum = roundNum;
  31. }
  32. private void TeamList_MouseDoubleClick(object sender, MouseButtonEventArgs e)
  33. {
  34. ListBox listBox = (ListBox)sender;
  35. if (listBox.SelectedItem != null)
  36. {
  37. if (listBox.Name == "FrstList")
  38. {
  39. Item item = (Item)listBox.SelectedItem;
  40. FrstTitleTBlock.Text = item.TeamName;
  41. }
  42. else
  43. {
  44. Item item = (Item)listBox.SelectedItem;
  45. ScndTitleTBlock.Text = item.TeamName;
  46. }
  47. }
  48. }
  49. private void AcceptBtn_Click(object sender, RoutedEventArgs e)
  50. {
  51. // если команды не выбраны
  52. if (FrstTitleTBlock.Text == "Команда №1" || ScndTitleTBlock.Text == "Команда №2")
  53. {
  54. MessageBox.Show("Выберите обе команды!");
  55. return;
  56. }
  57. // если выбраны одинаковые команды
  58. if (FrstTitleTBlock.Text == ScndTitleTBlock.Text)
  59. {
  60. MessageBox.Show("Выберите разные команды!");
  61. return;
  62. }
  63. MatchWindow wnd = new MatchWindow(nowTournamentId, FrstTitleTBlock.Text, ScndTitleTBlock.Text, roundNum);
  64. wnd.Show();
  65. Close();
  66. }
  67. private void FrstSearchTBox_KeyDown(object sender, KeyEventArgs e)
  68. {
  69. if (e.Key == Key.Enter)
  70. {
  71. List<Matches> matchList = new List<Matches>();
  72. List<Teams> teamList = new List<Teams>();
  73. if (roundNum != 1)
  74. {
  75. matchList = _context.Matches.Where(t => (DbFunctions.Like(t.Teams.Name, "%" + FrstSearchTBox.Text + "%") || DbFunctions.Like(t.Teams1.Name, "%" + FrstSearchTBox.Text + "%"))
  76. && t.RoundNum == 1 && t.FK_Tournament_Id == nowTournamentId ).ToList();
  77. }
  78. else
  79. {
  80. teamList = _context.Teams.Where(t => DbFunctions.Like(t.Name, "%" + FrstSearchTBox.Text + "%")).ToList();
  81. }
  82. foreach (Matches match in matchList)
  83. {
  84. teamList.Add(match.Teams);
  85. teamList.Add(match.Teams1);
  86. }
  87. List<Item> itemList = new List<Item>();
  88. foreach (Teams team in teamList)
  89. {
  90. if (team.DissolationDate == null && team.Users.Disciplines.Id == _context.Users.Find(App.UserId).Disciplines.Id)
  91. {
  92. Item item = new Item()
  93. {
  94. TeamName = team.Name,
  95. LogoPath = team.LogoPath
  96. //Country = team.Countries.Name,
  97. //Discipline = team.Users.Disciplines.Name,
  98. //DateOfFoundation = team.FoundationDate.ToString("d")
  99. };
  100. itemList.Add(item);
  101. }
  102. }
  103. FrstList.ItemsSource = new List<byte>();
  104. FrstList.ItemsSource = itemList;
  105. }
  106. }
  107. private void ScndSearchTBox_KeyDown(object sender, KeyEventArgs e)
  108. {
  109. if (e.Key == Key.Enter)
  110. {
  111. List<Matches> matchList = new List<Matches>();
  112. List<Teams> teamList = new List<Teams>();
  113. if (roundNum != 1)
  114. {
  115. matchList = _context.Matches.Where(t => (DbFunctions.Like(t.Teams.Name, "%" + ScndSearchTBox.Text + "%") || DbFunctions.Like(t.Teams1.Name, "%" + ScndSearchTBox.Text + "%"))
  116. && t.RoundNum == 1 && t.FK_Tournament_Id == nowTournamentId).ToList();
  117. }
  118. else
  119. {
  120. teamList = _context.Teams.Where(t => DbFunctions.Like(t.Name, "%" + ScndSearchTBox.Text + "%")).ToList();
  121. }
  122. foreach (Matches match in matchList)
  123. {
  124. teamList.Add(match.Teams);
  125. teamList.Add(match.Teams1);
  126. }
  127. List<Item> itemList = new List<Item>();
  128. foreach (Teams team in teamList)
  129. {
  130. if (team.DissolationDate == null && team.Users.Disciplines.Id == _context.Users.Find(App.UserId).Disciplines.Id)
  131. {
  132. Item item = new Item()
  133. {
  134. TeamName = team.Name,
  135. LogoPath = team.LogoPath
  136. //Country = team.Countries.Name,
  137. //Discipline = team.Users.Disciplines.Name,
  138. //DateOfFoundation = team.FoundationDate.ToString("d")
  139. };
  140. itemList.Add(item);
  141. }
  142. }
  143. ScndList.ItemsSource = new List<byte>();
  144. ScndList.ItemsSource = itemList;
  145. }
  146. }
  147. }
  148. class Item
  149. {
  150. public string TeamName { get; set; }
  151. public string LogoPath { get; set; }
  152. public string Discipline { get; set; }
  153. public string Country { get; set; }
  154. public string DateOfFoundation { get; set; }
  155. }
  156. }