浏览代码

Сделан авторасчет счета матча

максим карбышев 3 年之前
父节点
当前提交
f25b0f6106

+ 25 - 30
CybersportTournament/AddWindows/AddMatchWindow.xaml.cs

@@ -16,27 +16,31 @@ namespace CybersportTournament.AddWindows
     {
         static int TeamOneID, TeamTwoID;
         List<int> teams;
-        public AddMatchWindow()
-        {
-            InitializeComponent();
-            TeamOneBox.ItemsSource = Connection.db.Teams.Select(item => item.Name).ToList();
-            TeamTwoBox.ItemsSource = Connection.db.Teams.Select(item => item.Name).ToList();
-            TournamentBox.ItemsSource = Connection.db.Tournaments.Select(item => item.Name).ToList();
-        }
-        public AddMatchWindow(int TournamentID)
+        List<int> teamsOneID;
+        List<int> teamsTwoID;
+        int NumberList;
+        public AddMatchWindow(int TournamentID, int NumberList)
         {
             InitializeComponent();
+            this.NumberList = NumberList;
             teams = Connection.db.TeamsList.Where(item => item.IDTournament == TournamentID).Select(item => item.IDTeam).ToList();
-            TeamOneBox.ItemsSource = Connection.db.Teams.Where(item => !teams.Contains(item.ID)).Select(item => item.Name).ToList();
-            TeamTwoBox.ItemsSource = Connection.db.Teams.Where(item => !teams.Contains(item.ID)).Select(item => item.Name).ToList();
+            teamsOneID = Connection.db.Teams.Where(item => !teams.Contains(item.ID)).Select(item => item.ID).ToList();
+            teamsTwoID = Connection.db.Teams.Where(item => !teams.Contains(item.ID)).Select(item => item.ID).ToList();
+
+            TeamOneBox.ItemsSource = Connection.db.Teams.Where(item => teamsOneID.Contains(item.ID)).Select(item => item.Name).ToList();
+            TeamTwoBox.ItemsSource = Connection.db.Teams.Where(item => teamsTwoID.Contains(item.ID)).Select(item => item.Name).ToList();
             TournamentBox.ItemsSource = Connection.db.Tournaments.Where(item => item.ID == TournamentID).Select(item => item.Name).ToList();
             TournamentBox.SelectedIndex = 0;
         }
-        public AddMatchWindow(int TournamentID, List<int> teamsID)
+        public AddMatchWindow(int TournamentID, List<int> teamsID, int NumberList)
         {
             InitializeComponent();
-            TeamOneBox.ItemsSource = Connection.db.Teams.Where(item => teamsID.Contains(item.ID)).Select(item => item.Name).ToList();
-            TeamTwoBox.ItemsSource = Connection.db.Teams.Where(item => teamsID.Contains(item.ID)).Select(item => item.Name).ToList();
+            this.NumberList = NumberList;
+            teamsOneID = Connection.db.Teams.Where(item => teamsID.Contains(item.ID)).Select(item => item.ID).ToList();
+            teamsTwoID = Connection.db.Teams.Where(item => teamsID.Contains(item.ID)).Select(item => item.ID).ToList();
+
+            TeamOneBox.ItemsSource = Connection.db.Teams.Where(item => teamsOneID.Contains(item.ID)).Select(item => item.Name).ToList();
+            TeamTwoBox.ItemsSource = Connection.db.Teams.Where(item => teamsTwoID.Contains(item.ID)).Select(item => item.Name).ToList();
             TournamentBox.ItemsSource = Connection.db.Tournaments.Where(item => item.ID == TournamentID).Select(item => item.Name).ToList();
             TournamentBox.SelectedIndex = 0;
         }
@@ -46,7 +50,7 @@ namespace CybersportTournament.AddWindows
             #region Выбор команд
             TeamOneID = Connection.db.Teams.Where(item => item.Name == TeamOneBox.SelectedItem.ToString()).Select(item => item.ID).FirstOrDefault();
 
-            TeamTwoBox.ItemsSource = Connection.db.Teams.Where(item => item.ID != TeamOneID && !teams.Contains(item.ID)).Select(item => item.Name).ToList();
+            TeamTwoBox.ItemsSource = Connection.db.Teams.Where(item => item.ID != TeamOneID && teamsTwoID.Contains(item.ID)).Select(item => item.Name).ToList();
 
             if (Connection.db.Teams.Where(item => item.ID == TeamOneID).Select(item => item.Logo).SingleOrDefault() == null)
             {
@@ -62,7 +66,7 @@ namespace CybersportTournament.AddWindows
         {
             TeamTwoID = Connection.db.Teams.Where(item => item.Name == TeamTwoBox.SelectedItem.ToString()).Select(item => item.ID).FirstOrDefault();
 
-            TeamOneBox.ItemsSource = Connection.db.Teams.Where(item => item.ID != TeamTwoID && !teams.Contains(item.ID)).Select(item => item.Name).ToList();
+            TeamOneBox.ItemsSource = Connection.db.Teams.Where(item => item.ID != TeamTwoID && teamsOneID.Contains(item.ID)).Select(item => item.Name).ToList();
 
             if (Connection.db.Teams.Where(item => item.ID == TeamTwoID).Select(item => item.Logo).SingleOrDefault() == null)
             {
@@ -89,6 +93,7 @@ namespace CybersportTournament.AddWindows
             {
                 Time = (DateTime)Date.SelectedDate
             };
+            match.Result = "0:0";
             Connection.db.Match.Add(match);
             Connection.db.SaveChanges();
 
@@ -102,27 +107,17 @@ namespace CybersportTournament.AddWindows
             Connection.db.MatchList.Add(matchList);
             Connection.db.SaveChanges();
 
-            int NumberTeamList;
-            if (Connection.db.TeamsList.Count() == 0)
-            {
-                NumberTeamList = 1;
-            }
-            else
-            {
-                NumberTeamList = Convert.ToInt32(Connection.db.TeamsList.Max(item => item.NumberTeamList).ToString()) + 1;
-            }
-
             TeamsList teamsListOne = new TeamsList()
             {
                 IDTournament = TournamentID,
                 IDTeam = Connection.db.Teams.Where(item => item.Name == TeamOneBox.SelectedItem.ToString()).Select(item => item.ID).FirstOrDefault(),
-                NumberTeamList = NumberTeamList
+                NumberTeamList = NumberList
             };
             TeamsList teamsListTwo = new TeamsList()
             {
                 IDTournament = TournamentID,
                 IDTeam = Connection.db.Teams.Where(item => item.Name == TeamTwoBox.SelectedItem.ToString()).Select(item => item.ID).FirstOrDefault(),
-                NumberTeamList = NumberTeamList
+                NumberTeamList = NumberList
             };
 
             Connection.db.TeamsList.Add(teamsListOne);
@@ -131,15 +126,15 @@ namespace CybersportTournament.AddWindows
             Connection.db.SaveChanges();
 
             string Name = Connection.db.Tournaments.Where(item => item.ID == TournamentID).Select(item => item.Name).FirstOrDefault();
-            int FirstTeamID = Connection.db.TeamsList.Where(item => item.NumberTeamList == NumberTeamList).Select(item => item.IDTeam).First();
-            int SecondTeamID = Connection.db.TeamsList.Where(item => item.NumberTeamList == NumberTeamList && item.IDTeam != FirstTeamID).Select(item => item.IDTeam).First();
+            int FirstTeamID = Connection.db.TeamsList.Where(item => item.NumberTeamList == NumberList).Select(item => item.IDTeam).First();
+            int SecondTeamID = Connection.db.TeamsList.Where(item => item.NumberTeamList == NumberList && item.IDTeam != FirstTeamID).Select(item => item.IDTeam).First();
 
             Name += " " + Connection.db.Teams.Where(item => item.ID == FirstTeamID).Select(item => item.Name).FirstOrDefault();
             Name += " " + Connection.db.Teams.Where(item => item.ID == SecondTeamID).Select(item => item.Name).FirstOrDefault();
             Name += " " + Connection.db.Match.Where(item => item.ID == MatchID).Select(item => item.Time).FirstOrDefault();
 
             var matchUpdate = Connection.db.Match.Where(item => item.ID == MatchID).FirstOrDefault();
-            matchUpdate.Number = NumberTeamList;
+            matchUpdate.Number = NumberList;
             matchUpdate.Name = Name;
             Connection.db.SaveChanges();
 

+ 4 - 4
CybersportTournament/AddWindows/AddRoundWindow.xaml

@@ -8,13 +8,13 @@
         Title="AddRoundWindow" Height="900" Width="1600" WindowStartupLocation="CenterScreen" ResizeMode="CanMinimize">
     <Grid>
         <Label Content="Матч:" HorizontalAlignment="Left" Margin="127,268,0,0" VerticalAlignment="Top" Height="60" Width="180" Foreground="White" FontSize="36"/>
-        <ComboBox Name="MatchesBox" HorizontalAlignment="Left" Margin="307,270,0,0" VerticalAlignment="Top" Height="60" Width="550" FontSize="36"/>
+        <Label Name="Match" HorizontalAlignment="Left" Margin="307,270,0,0" VerticalAlignment="Top" Height="60" Width="850" FontSize="36" Foreground="White"/>
         <Label Content="Раунд:" HorizontalAlignment="Left" Margin="127,350,0,0" VerticalAlignment="Top" Height="60" Width="180" Foreground="White" FontSize="36"/>
-        <TextBox Name="RoundBox" HorizontalAlignment="Left" Margin="307,350,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="60" Width="550" FontSize="36" TextChanged="RoundBoxTextChanged"/>
+        <Label Name="Round" HorizontalAlignment="Left" Margin="307,350,0,0" VerticalAlignment="Top" Height="60" Width="550" FontSize="36" Foreground="White"/>
         <Label Content="Длительность:" HorizontalAlignment="Left" Margin="59,432,0,0" VerticalAlignment="Top" Height="60" Width="248" Foreground="White" FontSize="36"/>
-        <TextBox Name="Period" HorizontalAlignment="Left" Margin="307,432,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="60" Width="550" FontSize="36" TextChanged="RoundBoxTextChanged"/>
+        <TextBox Name="Period" HorizontalAlignment="Left" Margin="307,432,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="60" Width="550" FontSize="36" TextChanged="TextChanged"/>
         <Label Content="Результат:" HorizontalAlignment="Left" Margin="127,514,0,0" VerticalAlignment="Top" Height="60" Width="180" Foreground="White" FontSize="36"/>
-        <TextBox Name="Result" HorizontalAlignment="Left" Margin="307,514,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="60" Width="550" FontSize="36" TextChanged="RoundBoxTextChanged"/>
+        <TextBox Name="Result" HorizontalAlignment="Left" Margin="307,514,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="60" Width="550" FontSize="36" TextChanged="TextChanged"/>
         <Button Name="BackButton"  Content="Назад" HorizontalAlignment="Left" Margin="20,17,0,0" VerticalAlignment="Top" Height="39" Width="140" FontSize="25" Click="BackButtonClick"/>
         <Button Name="AddButton" Content="Добавить" HorizontalAlignment="Center" Margin="0,746,0,0" VerticalAlignment="Top" Height="60" Width="180" FontSize="36" Click="AddButtonClick" />
     </Grid>

+ 51 - 29
CybersportTournament/AddWindows/AddRoundWindow.xaml.cs

@@ -4,6 +4,7 @@ using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Windows;
+using System.Windows.Controls;
 
 namespace CybersportTournament.AddWindows
 {
@@ -12,59 +13,80 @@ namespace CybersportTournament.AddWindows
     /// </summary>
     public partial class AddRoundWindow : Window
     {
-        int idMatch;
-        List<char> numbers = new List<char> { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };
-        public AddRoundWindow()
-        {
-            InitializeComponent();
-            MatchesBox.ItemsSource = Connection.db.Match.Select(item => item.Name).ToList();
-        }
+        List<char> chars = new List<char> { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', ':' };
+        Match match;
 
         public AddRoundWindow(int IDMatch)
         {
             InitializeComponent();
-            idMatch = IDMatch;
-            MatchesBox.ItemsSource = Connection.db.Match.Where(item => item.ID == IDMatch).Select(item => item.Name).ToList();
-            MatchesBox.SelectedItem = Connection.db.Match.Where(item => item.ID == IDMatch).Select(item => item.Name).FirstOrDefault();
+            match = Connection.db.Match.Where(item => item.ID == IDMatch).FirstOrDefault();
+            Match.Content = match.Name;
+            int numberRound;
+            if (Connection.db.RoundsList.Where(item => item.IDMatch == match.ID).FirstOrDefault() == null)
+                numberRound = 1;
+            else
+                numberRound = Connection.db.RoundsList.Where(item => item.IDMatch == match.ID).Max(item => item.Rounds.Name) + 1;
+            Round.Content = numberRound;
         }
 
         private void AddButtonClick(object sender, RoutedEventArgs e)
         {
-            #region Добавление раунд
-            if (MatchesBox.SelectedItem == null || RoundBox == null)
-            {
-                ErrorWindow ew = new ErrorWindow("пустые поля");
-                ew.Show();
-                return;
-            }
+            #region Добавление раундreturn;
 
             Rounds round = new Rounds()
             {
-                Name = Convert.ToInt32(RoundBox.Text)
+                Name = Convert.ToInt32(Round.Content)
             };
             if (Period.Text != null)
             {
                 int index = Period.Text.IndexOf(":");
                 round.Period = new TimeSpan(Convert.ToInt32(Period.Text.Substring(0, index)), Convert.ToInt32(Period.Text.Substring(index + 1, Period.Text.Length - index - 1)), 0);
-            }    
+            }
+            round.Result = "0:0";
+            Connection.db.Rounds.Add(round);
+            Connection.db.SaveChanges();
             if (Result.Text != null)
             {
+                #region Авто изменение счёта матча
+                int length = Result.Text.IndexOf(':');
+                int firstTeamRoundScore = Convert.ToInt32(Result.Text.Substring(0, length));
+                int secondTeamRoundScore = Convert.ToInt32(Result.Text.Substring(length + 1, Result.Text.Length - length - 1));
+                length = match.Result.IndexOf(':');
+                int firstTeamMatchScore = Convert.ToInt32(match.Result.Substring(0, length));
+                int secondTeamMatchScore = Convert.ToInt32(match.Result.Substring(length + 1, match.Result.Length - length - 1));
+
+                if (firstTeamRoundScore == secondTeamRoundScore)
+                {
+                    ErrorWindow ew = new ErrorWindow("счёт не может быть одинаковым");
+                    ew.Show();
+                    return;
+                }
+                else if (firstTeamRoundScore > secondTeamRoundScore)
+                {
+                    firstTeamMatchScore += 1; 
+                }
+                else
+                {
+                    secondTeamMatchScore += 1;
+                }
+                string matchResult = firstTeamMatchScore.ToString() + ":" + secondTeamMatchScore.ToString();
+                match.Result = matchResult;
+                #endregion
+
                 round.Result = Result.Text;
             }
-            Connection.db.Rounds.Add(round);
             Connection.db.SaveChanges();
 
 
             RoundsList roundList = new RoundsList()
             {
-                IDRound = Connection.db.Rounds.Max(item => item.ID),
-                IDMatch = Connection.db.Match.Where(item => item.Name == MatchesBox.SelectedItem.ToString()).Select(item => item.ID).FirstOrDefault()
+                IDRound = round.ID,
+                IDMatch = match.ID
             };
             Connection.db.RoundsList.Add(roundList);
             Connection.db.SaveChanges();
 
-
-            MatchWindow mw = new MatchWindow(idMatch);
+            MatchWindow mw = new MatchWindow(match.ID);
             mw.Show();
             this.Close();
             #endregion
@@ -77,17 +99,17 @@ namespace CybersportTournament.AddWindows
             this.Close();
         }
 
-        private void RoundBoxTextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
+        private void TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
         {
             #region Валидация поля номера раунда
-            if (RoundBox.Text != "" && !numbers.Contains(RoundBox.Text[RoundBox.Text.Length - 1]))
+            if (((TextBox)sender).Text != "" && !chars.Contains(((TextBox)sender).Text[((TextBox)sender).Text.Length - 1]))
             {
-                RoundBox.CaretIndex = RoundBox.Text.Length - 2;
-                RoundBox.Text = RoundBox.Text.Remove(RoundBox.Text.Length - 1, 1);
+                ((TextBox)sender).CaretIndex = ((TextBox)sender).Text.Length - 2;
+                ((TextBox)sender).Text = ((TextBox)sender).Text.Remove(((TextBox)sender).Text.Length - 1, 1);
             }
             else
             {
-                RoundBox.CaretIndex = RoundBox.Text.Length;
+                ((TextBox)sender).CaretIndex = ((TextBox)sender).Text.Length;
             }
             #endregion
         }

+ 10 - 6
CybersportTournament/CybersportTournamentModel.edmx

@@ -4,7 +4,7 @@
   <edmx:Runtime>
     <!-- SSDL content -->
     <edmx:StorageModels>
-    <Schema Namespace="Хранилище CybersportTournamentsModel" Provider="System.Data.SqlClient" ProviderManifestToken="2012" Alias="Self" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns:customannotation="http://schemas.microsoft.com/ado/2013/11/edm/customannotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm/ssdl">
+      <Schema Namespace="Хранилище CybersportTournamentsModel" Provider="System.Data.SqlClient" ProviderManifestToken="2012" Alias="Self" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns:customannotation="http://schemas.microsoft.com/ado/2013/11/edm/customannotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm/ssdl">
         <EntityType Name="Games">
           <Key>
             <PropertyRef Name="ID" />
@@ -123,6 +123,7 @@
           <Property Name="Name" Type="varchar" MaxLength="50" Nullable="false" />
           <Property Name="PrizeFund" Type="money" />
           <Property Name="Logo" Type="image" />
+          <Property Name="Winner" Type="int" />
         </EntityType>
         <EntityType Name="TournamentsResults">
           <Key>
@@ -366,7 +367,8 @@
             <End Role="Users" EntitySet="Users" />
           </AssociationSet>
         </EntityContainer>
-      </Schema></edmx:StorageModels>
+      </Schema>
+    </edmx:StorageModels>
     <!-- CSDL content -->
     <edmx:ConceptualModels>
       <Schema Namespace="CybersportTournamentsModel" Alias="Self" annotation:UseStrongSpatialTypes="false" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns:customannotation="http://schemas.microsoft.com/ado/2013/11/edm/customannotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm">
@@ -400,9 +402,9 @@
           <Property Name="Time" Type="DateTime" Nullable="false" Precision="0" />
           <Property Name="Period" Type="Time" Precision="7" />
           <Property Name="Result" Type="String" MaxLength="10" FixedLength="false" Unicode="false" />
+          <Property Name="Number" Type="Int32" Nullable="false" />
           <NavigationProperty Name="MatchList" Relationship="Self.FK_MatchList_Match" FromRole="Match" ToRole="MatchList" />
           <NavigationProperty Name="RoundsList" Relationship="Self.FK_RoundsList_Match" FromRole="Match" ToRole="RoundsList" />
-          <Property Name="Number" Type="Int32" Nullable="false" />
         </EntityType>
         <EntityType Name="MatchList">
           <Key>
@@ -455,8 +457,8 @@
           <Property Name="ID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
           <Property Name="Name" Type="Int32" Nullable="false" />
           <Property Name="Period" Type="Time" Precision="7" />
-          <NavigationProperty Name="RoundsList" Relationship="Self.FK_RoundsList_Rounds" FromRole="Rounds" ToRole="RoundsList" />
           <Property Name="Result" Type="String" MaxLength="15" FixedLength="false" Unicode="false" />
+          <NavigationProperty Name="RoundsList" Relationship="Self.FK_RoundsList_Rounds" FromRole="Rounds" ToRole="RoundsList" />
         </EntityType>
         <EntityType Name="RoundsList">
           <Key>
@@ -508,6 +510,7 @@
           <Property Name="Name" Type="String" MaxLength="50" FixedLength="false" Unicode="false" Nullable="false" />
           <Property Name="PrizeFund" Type="Decimal" Precision="19" Scale="4" />
           <Property Name="Logo" Type="Binary" MaxLength="Max" FixedLength="false" />
+          <Property Name="Winner" Type="Int32" />
           <NavigationProperty Name="Games" Relationship="Self.FK_Tournaments_Games" FromRole="Tournaments" ToRole="Games" />
           <NavigationProperty Name="MatchList" Relationship="Self.FK_MatchList_Tournaments" FromRole="Tournaments" ToRole="MatchList" />
           <NavigationProperty Name="TeamsList" Relationship="Self.FK_TeamsList_Tournaments" FromRole="Tournaments" ToRole="TeamsList" />
@@ -786,12 +789,12 @@
           <EntitySetMapping Name="Match">
             <EntityTypeMapping TypeName="CybersportTournamentsModel.Match">
               <MappingFragment StoreEntitySet="Match">
-                <ScalarProperty Name="Number" ColumnName="Number" />
                 <ScalarProperty Name="ID" ColumnName="ID" />
                 <ScalarProperty Name="Name" ColumnName="Name" />
                 <ScalarProperty Name="Time" ColumnName="Time" />
                 <ScalarProperty Name="Period" ColumnName="Period" />
                 <ScalarProperty Name="Result" ColumnName="Result" />
+                <ScalarProperty Name="Number" ColumnName="Number" />
               </MappingFragment>
             </EntityTypeMapping>
           </EntitySetMapping>
@@ -838,10 +841,10 @@
           <EntitySetMapping Name="Rounds">
             <EntityTypeMapping TypeName="CybersportTournamentsModel.Rounds">
               <MappingFragment StoreEntitySet="Rounds">
-                <ScalarProperty Name="Result" ColumnName="Result" />
                 <ScalarProperty Name="ID" ColumnName="ID" />
                 <ScalarProperty Name="Name" ColumnName="Name" />
                 <ScalarProperty Name="Period" ColumnName="Period" />
+                <ScalarProperty Name="Result" ColumnName="Result" />
               </MappingFragment>
             </EntityTypeMapping>
           </EntitySetMapping>
@@ -892,6 +895,7 @@
                 <ScalarProperty Name="Name" ColumnName="Name" />
                 <ScalarProperty Name="PrizeFund" ColumnName="PrizeFund" />
                 <ScalarProperty Name="Logo" ColumnName="Logo" />
+                <ScalarProperty Name="Winner" ColumnName="Winner" />
               </MappingFragment>
             </EntityTypeMapping>
           </EntitySetMapping>

+ 3 - 3
CybersportTournament/CybersportTournamentModel.edmx.diagram

@@ -4,15 +4,15 @@
   <edmx:Designer xmlns="http://schemas.microsoft.com/ado/2009/11/edmx">
     <!-- Diagram content (shape and connector positions) -->
     <edmx:Diagrams>
-      <Diagram DiagramId="f63be43c751644e1ab2561022016819b" Name="Diagram1">
+      <Diagram DiagramId="a79d7bf55976496586e1aae5b69eba74" Name="Diagram1">
         <EntityTypeShape EntityType="CybersportTournamentsModel.Games" Width="1.5" PointX="0.75" PointY="5.375" IsExpanded="true" />
         <EntityTypeShape EntityType="CybersportTournamentsModel.MapsGame" Width="1.5" PointX="3" PointY="3.625" IsExpanded="true" />
-        <EntityTypeShape EntityType="CybersportTournamentsModel.Match" Width="1.5" PointX="3" PointY="10.625" IsExpanded="true" />
+        <EntityTypeShape EntityType="CybersportTournamentsModel.Match" Width="1.5" PointX="3" PointY="10.5" IsExpanded="true" />
         <EntityTypeShape EntityType="CybersportTournamentsModel.MatchList" Width="1.5" PointX="5.25" PointY="6.75" IsExpanded="true" />
         <EntityTypeShape EntityType="CybersportTournamentsModel.Persons" Width="1.5" PointX="7.75" PointY="2.25" IsExpanded="true" />
         <EntityTypeShape EntityType="CybersportTournamentsModel.Players" Width="1.5" PointX="10" PointY="1.125" IsExpanded="true" />
         <EntityTypeShape EntityType="CybersportTournamentsModel.PlayersList" Width="1.5" PointX="12.25" PointY="1" IsExpanded="true" />
-        <EntityTypeShape EntityType="CybersportTournamentsModel.Rounds" Width="1.5" PointX="3" PointY="15.875" IsExpanded="true" />
+        <EntityTypeShape EntityType="CybersportTournamentsModel.Rounds" Width="1.5" PointX="3" PointY="15.75" IsExpanded="true" />
         <EntityTypeShape EntityType="CybersportTournamentsModel.RoundsList" Width="1.5" PointX="5.25" PointY="9.75" IsExpanded="true" />
         <EntityTypeShape EntityType="CybersportTournamentsModel.sysdiagrams" Width="1.5" PointX="7.75" PointY="6.75" IsExpanded="true" />
         <EntityTypeShape EntityType="CybersportTournamentsModel.Teams" Width="1.5" PointX="3" PointY="0.75" IsExpanded="true" />

+ 1 - 0
CybersportTournament/ElementsWindows/MatchWindow.xaml.cs

@@ -18,6 +18,7 @@ namespace CybersportTournament.ElementsWindows
             Name.Content = match.Name;
             Time.Content = match.Time;
             Period.Content = match.Period;
+            Result.Content = match.Result;
             int numberList = match.Number;
             int idTournament = Connection.db.MatchList.Where(item => item.IDMatch == id).Select(item => item.IDTournament).FirstOrDefault();
             int firstTeamID = Connection.db.TeamsList.Where(item => item.IDTournament == idTournament && item.NumberTeamList == numberList).Select(item => item.IDTeam).FirstOrDefault();

+ 4 - 5
CybersportTournament/ElementsWindows/TournamentWindow.xaml

@@ -46,19 +46,18 @@
             Foreground="#FF54E4FF" HorizontalContentAlignment="Center" MouseDoubleClick="FiMatchMouseDoubleClick"/>
         <Polyline Stroke="White" Points="0,60, 75,60 75,0 150,0" Height="60" Width="150" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="732,382,0,0"/>
         <Label x:Name="SiMatchFTeam" Content="" HorizontalAlignment="Left" Margin="480,540,0,0" VerticalAlignment="Top" Width="250" Height="45" FontSize="25" 
-            Foreground="#FF54E4FF" HorizontalContentAlignment="Center"/>
+            Foreground="#FF54E4FF" HorizontalContentAlignment="Center" MouseDoubleClick="SiMatchMouseDoubleClick"/>
         <Polyline Stroke="White" Points="0,0, 75,0 75,60 150,60" Height="60" Width="150" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="732,562,0,0"/>
         <Label x:Name="SiMatchSTeam" Content="" HorizontalAlignment="Left" Margin="480,660,0,0" VerticalAlignment="Top" Width="250" Height="45" FontSize="25" 
-            Foreground="#FF54E4FF" HorizontalContentAlignment="Center"/>
+            Foreground="#FF54E4FF" HorizontalContentAlignment="Center" MouseDoubleClick="SiMatchMouseDoubleClick"/>
         <Polyline Stroke="White" Points="0,60, 75,60 75,0 150,0" Height="60" Width="150" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="732,622,0,0"/>
         <Label x:Name="SeMatchFTeam" Content="" HorizontalAlignment="Left" Margin="883,360,0,0" VerticalAlignment="Top" Width="250" Height="45" FontSize="25" 
-            Foreground="#FF54E4FF" HorizontalContentAlignment="Center"/>
+            Foreground="#FF54E4FF" HorizontalContentAlignment="Center" MouseDoubleClick="SeMatchMouseDoubleClick"/>
         <Polyline Stroke="White" Points="0,0, 75,0 75,120 150,120" Height="120" Width="150" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="1135,382,0,0"/>
         <Label x:Name="SeMatchSTeam" Content="" HorizontalAlignment="Left" Margin="883,600,0,0" VerticalAlignment="Top" Width="250" Height="45" FontSize="25" 
-            Foreground="#FF54E4FF" HorizontalContentAlignment="Center"/>
+            Foreground="#FF54E4FF" HorizontalContentAlignment="Center" MouseDoubleClick="SeMatchMouseDoubleClick"/>
         <Polyline Stroke="White" Points="0,120,75,120 75,0 150,0" Height="120" Width="150" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="1135,502,0,0"/>
         <Label x:Name="Winner" Content="" HorizontalAlignment="Left" Margin="1286,480,0,0" VerticalAlignment="Top" Width="250" Height="45" FontSize="25" 
             Foreground="#FF54E4FF" HorizontalContentAlignment="Center"/>
-
     </Grid>
 </Window>

+ 59 - 9
CybersportTournament/ElementsWindows/TournamentWindow.xaml.cs

@@ -24,8 +24,8 @@ namespace CybersportTournament.ElementsWindows
             Game.Content = tournament.Games.Name;
             PrizeFund.Content = tournament.PrizeFund;
             Logo.Source = NewImage(tournament);
-            Label[,] labels = new Label[8, 2] { { FMatchFTeam, FMatchSTeam }, {SMatchFTeam, SMatchSTeam }, { TMatchFTeam, TMatchSTeam },
-                { FoMatchFTeam, FoMatchSTeam }, { FiMatchFTeam, FiMatchSTeam }, { SiMatchFTeam, SiMatchSTeam }, { SeMatchFTeam, SeMatchSTeam }, { Winner, Winner } };
+            Label[,] labels = new Label[7, 2] { { FMatchFTeam, FMatchSTeam }, {SMatchFTeam, SMatchSTeam }, { TMatchFTeam, TMatchSTeam },
+                { FoMatchFTeam, FoMatchSTeam }, { FiMatchFTeam, FiMatchSTeam }, { SiMatchFTeam, SiMatchSTeam }, { SeMatchFTeam, SeMatchSTeam } };
             for (int i = 1; i < 8; i++)
             {
                 if (Connection.db.TeamsList.Where(item => item.IDTournament == tournament.ID).Select(item => item.NumberTeamList).Contains(i))
@@ -70,7 +70,7 @@ namespace CybersportTournament.ElementsWindows
             }
             else if (FMatchFTeam.Content.ToString() == "" || FMatchSTeam.Content.ToString() == "")
             {
-                AddMatchWindow amw = new AddMatchWindow(tournament.ID);
+                AddMatchWindow amw = new AddMatchWindow(tournament.ID, 1);
                 amw.Show();
                 this.Close();
             }
@@ -87,7 +87,7 @@ namespace CybersportTournament.ElementsWindows
             }
             else if (SMatchFTeam.Content.ToString() == "" || SMatchSTeam.Content.ToString() == "")
             {
-                AddMatchWindow amw = new AddMatchWindow(tournament.ID);
+                AddMatchWindow amw = new AddMatchWindow(tournament.ID, 2);
                 amw.Show();
                 this.Close();
             }
@@ -104,7 +104,7 @@ namespace CybersportTournament.ElementsWindows
             }
             else if (TMatchFTeam.Content.ToString() == "" || TMatchSTeam.Content.ToString() == "")
             {
-                AddMatchWindow amw = new AddMatchWindow(tournament.ID);
+                AddMatchWindow amw = new AddMatchWindow(tournament.ID, 3);
                 amw.Show();
                 this.Close();
             }
@@ -121,7 +121,7 @@ namespace CybersportTournament.ElementsWindows
             }
             else if (FoMatchFTeam.Content.ToString() == "" || FoMatchFTeam.Content.ToString() == "")
             {
-                AddMatchWindow amw = new AddMatchWindow(tournament.ID);
+                AddMatchWindow amw = new AddMatchWindow(tournament.ID, 4);
                 amw.Show();
                 this.Close();
             }
@@ -130,8 +130,9 @@ namespace CybersportTournament.ElementsWindows
 
         private void FiMatchMouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
         {
-            if ((FMatchFTeam.Content.ToString() != "" && FMatchSTeam.Content.ToString() != "" 
-                && SMatchFTeam.Content.ToString() !=  "" && SMatchSTeam.Content.ToString() != "") 
+            #region Переход на матчи полуфинала и финала
+            if ((FMatchFTeam.Content.ToString() != "" && FMatchSTeam.Content.ToString() != ""
+                && SMatchFTeam.Content.ToString() != "" && SMatchSTeam.Content.ToString() != "")
                 && (FiMatchFTeam.Content.ToString() == "" && FiMatchSTeam.Content.ToString() == ""))
             {
                 List<int> teamsID = new List<int>();
@@ -139,7 +140,7 @@ namespace CybersportTournament.ElementsWindows
                 teamsID.Add(Connection.db.Teams.Where(item => item.Name == FMatchSTeam.Content.ToString()).Select(item => item.ID).FirstOrDefault());
                 teamsID.Add(Connection.db.Teams.Where(item => item.Name == SMatchFTeam.Content.ToString()).Select(item => item.ID).FirstOrDefault());
                 teamsID.Add(Connection.db.Teams.Where(item => item.Name == SMatchSTeam.Content.ToString()).Select(item => item.ID).FirstOrDefault());
-                AddMatchWindow mw = new AddMatchWindow(tournament.ID, teamsID);
+                AddMatchWindow mw = new AddMatchWindow(tournament.ID, teamsID, 5);
                 mw.Show();
                 this.Close();
             }
@@ -151,5 +152,54 @@ namespace CybersportTournament.ElementsWindows
                 this.Close();
             }
         }
+
+        private void SiMatchMouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
+        {
+            if ((TMatchFTeam.Content.ToString() != "" && TMatchSTeam.Content.ToString() != ""
+                && FoMatchFTeam.Content.ToString() != "" && FoMatchSTeam.Content.ToString() != "")
+                && (SiMatchFTeam.Content.ToString() == "" && SiMatchSTeam.Content.ToString() == ""))
+            {
+                List<int> teamsID = new List<int>();
+                teamsID.Add(Connection.db.Teams.Where(item => item.Name == TMatchFTeam.Content.ToString()).Select(item => item.ID).FirstOrDefault());
+                teamsID.Add(Connection.db.Teams.Where(item => item.Name == TMatchSTeam.Content.ToString()).Select(item => item.ID).FirstOrDefault());
+                teamsID.Add(Connection.db.Teams.Where(item => item.Name == FoMatchFTeam.Content.ToString()).Select(item => item.ID).FirstOrDefault());
+                teamsID.Add(Connection.db.Teams.Where(item => item.Name == FoMatchSTeam.Content.ToString()).Select(item => item.ID).FirstOrDefault());
+                AddMatchWindow mw = new AddMatchWindow(tournament.ID, teamsID, 6);
+                mw.Show();
+                this.Close();
+            }
+            else if (SiMatchFTeam.Content.ToString() != "" && SiMatchSTeam.Content.ToString() != "")
+            {
+                int MatchID = Connection.db.MatchList.Where(item => item.Tournaments.ID == tournament.ID && item.Match.Number == 6).Select(item => item.IDMatch).FirstOrDefault();
+                MatchWindow mw = new MatchWindow(MatchID);
+                mw.Show();
+                this.Close();
+            }
+        }
+
+        private void SeMatchMouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
+        {
+            if ((FiMatchFTeam.Content.ToString() != "" && FiMatchSTeam.Content.ToString() != ""
+                && SiMatchFTeam.Content.ToString() != "" && SiMatchSTeam.Content.ToString() != "")
+                && (SeMatchFTeam.Content.ToString() == "" && SeMatchSTeam.Content.ToString() == ""))
+            {
+                List<int> teamsID = new List<int>();
+                teamsID.Add(Connection.db.Teams.Where(item => item.Name == FiMatchFTeam.Content.ToString()).Select(item => item.ID).FirstOrDefault());
+                teamsID.Add(Connection.db.Teams.Where(item => item.Name == FiMatchSTeam.Content.ToString()).Select(item => item.ID).FirstOrDefault());
+                teamsID.Add(Connection.db.Teams.Where(item => item.Name == SiMatchFTeam.Content.ToString()).Select(item => item.ID).FirstOrDefault());
+                teamsID.Add(Connection.db.Teams.Where(item => item.Name == SiMatchSTeam.Content.ToString()).Select(item => item.ID).FirstOrDefault());
+                AddMatchWindow mw = new AddMatchWindow(tournament.ID, teamsID, 7);
+                mw.Show();
+                this.Close();
+            }
+            else if (SeMatchFTeam.Content.ToString() != "" && SeMatchSTeam.Content.ToString() != "")
+            {
+                int MatchID = Connection.db.MatchList.Where(item => item.Tournaments.ID == tournament.ID && item.Match.Number == 7).Select(item => item.IDMatch).FirstOrDefault();
+                MatchWindow mw = new MatchWindow(MatchID);
+                mw.Show();
+                this.Close();
+            }
+            #endregion
+        }
     }
 }

+ 6 - 6
CybersportTournament/ListWindows/PlayersListWindow.xaml

@@ -16,15 +16,15 @@
                 </Style>
             </DataGrid.ItemContainerStyle>
             <DataGrid.Columns>
-                <DataGridTextColumn Binding="{Binding FirstName}" Header="FirstName" Width="200" IsReadOnly="True"/>
-                <DataGridTextColumn Binding="{Binding SecondName}" Header="SecondName"  Width="200" IsReadOnly="True"/>
-                <DataGridTextColumn Binding="{Binding MiddleName}" Header="MiddleName"  Width="200" IsReadOnly="True"/>
-                <DataGridTextColumn Binding="{Binding Nickname}" Header="Nickname"  Width="200" IsReadOnly="True"/>
-                <DataGridTextColumn Binding="{Binding Team}" Header="Team"  Width="200" IsReadOnly="True"/>
+                <DataGridTextColumn Binding="{Binding Players.Persons.FirstName}" Header="FirstName" Width="200" IsReadOnly="True"/>
+                <DataGridTextColumn Binding="{Binding Players.Persons.SecondName}" Header="SecondName"  Width="200" IsReadOnly="True"/>
+                <DataGridTextColumn Binding="{Binding Players.Persons.MiddleName}" Header="MiddleName"  Width="200" IsReadOnly="True"/>
+                <DataGridTextColumn Binding="{Binding Players.Nickname}" Header="Nickname"  Width="200" IsReadOnly="True"/>
+                <DataGridTextColumn Binding="{Binding Teams.Name}" Header="Team"  Width="200" IsReadOnly="True"/>
                 <DataGridTemplateColumn Header="Photo" Width="320">
                     <DataGridTemplateColumn.CellTemplate>
                         <DataTemplate>
-                            <Image Source="{Binding Photo}" Height="150"/>
+                            <Image Source="{Binding Players.Photo}" Height="150"/>
                         </DataTemplate>
                     </DataGridTemplateColumn.CellTemplate>
                 </DataGridTemplateColumn>

+ 2 - 23
CybersportTournament/ListWindows/PlayersListWindow.xaml.cs

@@ -2,7 +2,6 @@
 using System.Linq;
 using System.Windows;
 using CybersportTournament.ElementsWindows;
-using System;
 
 namespace CybersportTournament.ListWindows
 {
@@ -15,25 +14,7 @@ namespace CybersportTournament.ListWindows
         {
             InitializeComponent();
 
-            var result = (from ID in Connection.db.PlayersList
-                          join Team in Connection.db.Teams on ID.IDTeam equals Team.ID
-                          join Player in Connection.db.Players on ID.IDPlayer equals Player.ID
-                          //join Person in Connection.db.Persons on Connection.db.Players.Select(item => item.IDPerson).FirstOrDefault() equals Person.ID
-                          from Players in Connection.db.Players
-                          join Person in Connection.db.Persons on Player.IDPerson equals Person.ID
-                          join PlayerID in Connection.db.PlayersList on Player.ID equals PlayerID.IDPlayer
-                          select new
-                          {
-                              Id = Player.ID,
-                              FirstName = Person.FirstName,
-                              SecondName = Person.SecondName,
-                              MiddleName = Person.MiddleName,
-                              Nickname = Player.Nickname,
-                              Team = Team.Name,
-                              Photo = Player.Photo
-                          }).ToList();
-
-            PlayersList.ItemsSource = result;
+            PlayersList.ItemsSource = Connection.db.PlayersList.ToList();
         }
 
         private void BackButtonClick(object sender, RoutedEventArgs e)
@@ -105,9 +86,7 @@ namespace CybersportTournament.ListWindows
 
         private void PlayersListMouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
         {
-            int startIndex = PlayersList.SelectedItem.ToString().IndexOfAny("Id = ".ToCharArray()) + 6;
-            int lastIndex = PlayersList.SelectedItem.ToString().IndexOf(",");
-            int id = Convert.ToInt32(PlayersList.SelectedItem.ToString().Substring(startIndex, lastIndex - startIndex));
+            int id = ((PlayersList)PlayersList.SelectedItem).IDPlayer;
             PlayerWindow pw = new PlayerWindow(id);
             pw.Show();
             this.Hide();

+ 4 - 5
CybersportTournament/MainWindow.xaml

@@ -19,11 +19,10 @@
             </TabItem>
             <TabItem Name="AddItem" Header="Добавить" Height="20" Width="100" Background="#FF4F5856">
                 <Grid Margin="-3,-22,-3,-2">
-                    <Button Name="AddTeam" Content="Команду" HorizontalAlignment="Left" Margin="158,192,0,0" VerticalAlignment="Top" Height="70" Width="177" Click="AddTeamClick" FontSize="36"/>
-                    <Button Name="AddPlayer" Content="Игрока" HorizontalAlignment="Left" Margin="158,284,0,0" VerticalAlignment="Top" Height="70" Width="177" FontSize="36" Click="AddPlayerClick"/>
-                    <Button Name="AddGame" Content="Игру" HorizontalAlignment="Left" Margin="158,376,0,0" VerticalAlignment="Top" Height="70" Width="177" FontSize="36" Click="AddGameClick"/>
-                    <Button Name="AddTournament" Content="Турнир" HorizontalAlignment="Left" Margin="158,468,0,0" VerticalAlignment="Top" Height="70" Width="177" FontSize="36" Click="AddTournamentClick"/>
-                    <Button Name="AddMatch" Content="Матч" HorizontalAlignment="Left" Margin="158,560,0,0" VerticalAlignment="Top" Height="70" Width="177" FontSize="36" Click="AddMatchClick"/>
+                    <Button Name="AddTeam" Content="Команду" HorizontalAlignment="Left" Margin="158,250,0,0" VerticalAlignment="Top" Height="70" Width="177" Click="AddTeamClick" FontSize="36"/>
+                    <Button Name="AddPlayer" Content="Игрока" HorizontalAlignment="Left" Margin="158,342,0,0" VerticalAlignment="Top" Height="70" Width="177" FontSize="36" Click="AddPlayerClick"/>
+                    <Button Name="AddGame" Content="Игру" HorizontalAlignment="Left" Margin="158,434,0,0" VerticalAlignment="Top" Height="70" Width="177" FontSize="36" Click="AddGameClick"/>
+                    <Button Name="AddTournament" Content="Турнир" HorizontalAlignment="Left" Margin="158,526,0,0" VerticalAlignment="Top" Height="70" Width="177" FontSize="36" Click="AddTournamentClick"/>
                 </Grid>
             </TabItem>
         </TabControl>

+ 0 - 14
CybersportTournament/MainWindow.xaml.cs

@@ -48,20 +48,6 @@ namespace CybersportTournament
             atw.Show();
             this.Close();
         }
-
-        private void AddMatchClick(object sender, RoutedEventArgs e)
-        {
-            AddMatchWindow amw = new AddMatchWindow();
-            amw.Show();
-            this.Close();
-        }
-
-        private void AddRoundClick(object sender, RoutedEventArgs e)
-        {
-            AddRoundWindow arw = new AddRoundWindow();
-            arw.Show();
-            this.Close();
-        }
         #endregion
 
         #region Окна списков

+ 1 - 0
CybersportTournament/Tournaments.cs

@@ -27,6 +27,7 @@ namespace CybersportTournament
         public string Name { get; set; }
         public Nullable<decimal> PrizeFund { get; set; }
         public byte[] Logo { get; set; }
+        public Nullable<int> Winner { get; set; }
     
         public virtual Games Games { get; set; }
         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]