private void dataTeamsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if(this.Match.MatchId != 0)
            {
                FrmAddTeam dataAddTeam = new FrmAddTeam(this.HomeClub.ClubId, this.GuestClub.ClubId);
                dataAddTeam.ShowDialog();

                if (dataAddTeam.TeamsSelected)
                {
                    Thread loadingThread = new Thread(new ThreadStart(showLoadingForm));
                    loadingThread.Start();

                    this.HomeClub = dataAddTeam.HomeTeam;
                    this.GuestClub = dataAddTeam.GuestTeam;

                    this.HomeTeam = new Team(this.Match.MatchId, this.HomeClub.ClubId);
                    this.GuestTeam = new Team(this.Match.MatchId, this.GuestClub.ClubId);
                    this.HomeTeam.JerseyColor = this.HomeClub.JerseyColorHome;
                    this.GuestTeam.JerseyColor = this.GuestClub.JerseyColorGuest;

                    this.lblTeamA.Text = HomeClub.Name;
                    this.lblTeamB.Text = GuestClub.Name;

                    if (dataAddTeam.TeamSelectionChanged)
                    {
                        this.HomePlayers = new BindingList<Player>();
                        this.GuestPlayers = new BindingList<Player>();

                        this.HomeTeamPlayers = new BindingList<TeamPlayer>();
                        this.GuestTeamPlayers = new BindingList<TeamPlayer>();

                        dgvHomeTeam.DataSource = HomeTeamPlayers;
                        dgvHomeTeam.Refresh();
                        dgvGuestTeam.DataSource = GuestTeamPlayers;
                        dgvGuestTeam.Refresh();

                        this.HomePlays = new BindingList<Play>();
                        this.GuestPlays = new BindingList<Play>();

                        this.HomeClubOfficials = new BindingList<ClubOfficial>();
                        this.GuestClubOfficials = new BindingList<ClubOfficial>();

                        this.HomeTeamOfficials = new BindingList<TeamOfficial>();
                        this.GuestTeamOfficials = new BindingList<TeamOfficial>();

                        dgvHomeOfficials.DataSource = this.HomeTeamOfficials;
                        dgvHomeOfficials.Refresh();
                        dgvGuestOfficials.DataSource = this.GuestTeamOfficials;
                        dgvGuestOfficials.Refresh();

                        this.HomeManages = new BindingList<Manage>();
                        this.GuestManages = new BindingList<Manage>();

                        using (var db = new MatchReporterEntities())
                        {
                            List<Team> previousTeams = new List<Team>(db.Team.Where<Team>(t => t.MatchId == this.Match.MatchId).ToList<Team>());
                            foreach (Team team in previousTeams)
                            {
                                db.Team.Remove(team);
                            }
                            db.SaveChanges();
                        }
                    }

                    using (var db = new MatchReporterEntities())
                    {
                        db.Entry(this.HomeTeam).State = dataAddTeam.TeamSelectionChanged == true ? EntityState.Added : EntityState.Modified;
                        db.Entry(this.GuestTeam).State = dataAddTeam.TeamSelectionChanged == true ? EntityState.Added : EntityState.Modified;
                        db.SaveChanges();

                        this.SavedTeams = true;
                    }

                    btnTeamATTO1.Enabled = true;
                    btnTeamATTO2.Enabled = true;
                    btnTeamATTO3.Enabled = true;

                    btnTeamBTTO1.Enabled = true;
                    btnTeamBTTO2.Enabled = true;
                    btnTeamBTTO3.Enabled = true;

                    loadingThread.Abort();
                }
                //dataAddTeam.Dispose();
            }
            else
            {
                MessageBox.Show(this, "Da biste dodali momčadi, prvo je potrebno unijeti podatke o utakmici.", "Greška",
                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        private void matchSaveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Thread savingDataThread = new Thread(new ThreadStart(showSavingForm));
            savingDataThread.Start();

            try
            {
                // HomeTeamPlayers > HomePlays, GuestTeamPlayers > GuestPlays

                foreach(TeamPlayer teamPlayer in HomeTeamPlayers)
                {
                    Play play = HomePlays
                        .Where(p => p.MatchId == this.Match.MatchId)
                        .Where(p => p.PlayerId == teamPlayer.TeamPlayerId)
                        .FirstOrDefault();

                    if(play != null)
                    {
                        play.Goals = teamPlayer.Goals;
                        play.Goals7m = teamPlayer.Goals7m;
                        play.Warning = teamPlayer.Warning;
                        play.SuspensionFirst = teamPlayer.Suspension1st;
                        play.SuspensionSecond = teamPlayer.Suspension2nd;
                        play.SuspensionThird = teamPlayer.Suspension3rd;
                        play.Disqualification = teamPlayer.Disqualification;
                        play.DisqualificationAdnReport = teamPlayer.DisqualificationReport;
                    }
                }

                foreach (TeamPlayer teamPlayer in GuestTeamPlayers)
                {
                    Play play = GuestPlays
                        .Where(p => p.MatchId == this.Match.MatchId)
                        .Where(p => p.PlayerId == teamPlayer.TeamPlayerId)
                        .FirstOrDefault();

                    if (play != null)
                    {
                        play.Goals = teamPlayer.Goals;
                        play.Goals7m = teamPlayer.Goals7m;
                        play.Warning = teamPlayer.Warning;
                        play.SuspensionFirst = teamPlayer.Suspension1st;
                        play.SuspensionSecond = teamPlayer.Suspension2nd;
                        play.SuspensionThird = teamPlayer.Suspension3rd;
                        play.Disqualification = teamPlayer.Disqualification;
                        play.DisqualificationAdnReport = teamPlayer.DisqualificationReport;
                    }
                }

                // HomeTeamOfficials > HomeManages, GuestTeamOfficials > GuestManages
                foreach(TeamOfficial teamOfficial in HomeTeamOfficials)
                {
                    Manage manage = HomeManages
                        .Where(m => m.MatchId == this.Match.MatchId)
                        .Where(m => m.ClubOfficialId == teamOfficial.TeamOfficialId)
                        .FirstOrDefault();

                    if(manage != null)
                    {
                        manage.Warning = teamOfficial.Warning;
                        manage.Suspension = teamOfficial.Suspension;
                        manage.Disqualification = teamOfficial.Disqualification;
                    }
                }

                foreach (TeamOfficial teamOfficial in GuestTeamOfficials)
                {
                    Manage manage = GuestManages
                        .Where(m => m.MatchId == this.Match.MatchId)
                        .Where(m => m.ClubOfficialId == teamOfficial.TeamOfficialId)
                        .FirstOrDefault();

                    if (manage != null)
                    {
                        manage.Warning = teamOfficial.Warning;
                        manage.Suspension = teamOfficial.Suspension;
                        manage.Disqualification = teamOfficial.Disqualification;
                    }
                }

                // Saving data
                using (var db = new MatchReporterEntities())
                {
                    db.Entry(this.Match).State = this.Match.MatchId == 0 ? EntityState.Added : EntityState.Modified;

                    db.Entry(this.HomeTeam).State = this.SavedTeams == false ? EntityState.Added : EntityState.Modified;
                    db.Entry(this.GuestTeam).State = this.SavedTeams == false ? EntityState.Added : EntityState.Modified;
                    this.SavedTeams = true;

                    foreach (Play play in HomePlays)
                    {
                        db.Entry(play).State = this.SavedPlays == false ? EntityState.Added : EntityState.Modified;
                    }
                    foreach (Play play in GuestPlays)
                    {
                        db.Entry(play).State = this.SavedPlays == false ? EntityState.Added : EntityState.Modified;
                    }
                    this.SavedPlays = true;

                    foreach (Manage manage in HomeManages)
                    {
                        db.Entry(manage).State = this.SavedManages == false ? EntityState.Added : EntityState.Modified;
                    }
                    foreach (Manage manage in GuestManages)
                    {
                        db.Entry(manage).State = this.SavedManages == false ? EntityState.Added : EntityState.Modified;
                    }
                    this.SavedManages = true;

                    db.SaveChanges();
                }
                savingDataThread.Abort();

                MessageBox.Show(this, "Podaci su uspješno spremljeni.", "Spremanje podataka",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch
            {
                savingDataThread.Abort();
                MessageBox.Show(this, "Došlo je do pogreške.\nPodaci nisu spremljeni.", "Spremanje podataka",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void dataMatchDetailsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmAddMatchDetails dataAddMatchDetails = new FrmAddMatchDetails(this.Match);
            dataAddMatchDetails.ShowDialog();

            if (dataAddMatchDetails.MatchDetailsAddSuccess)
            {
                this.Match.LeagueId = dataAddMatchDetails.LeagueId;
                this.Match.Round = dataAddMatchDetails.Round;
                this.Match.Date = dataAddMatchDetails.Date;
                this.Match.Time = dataAddMatchDetails.Time;
                this.Match.HallId = dataAddMatchDetails.HallId;
                this.Match.Spectators = dataAddMatchDetails.Spectators;
                this.Match.RefereePairId = dataAddMatchDetails.RefereePairId;
                this.Match.DelegateId = dataAddMatchDetails.DelegateId;
                this.Match.TimeKeeper = dataAddMatchDetails.TimeKeeper;
                this.Match.Scorer = dataAddMatchDetails.Scorer;
                this.RefereePairName = dataAddMatchDetails.RefereePairName;

                using (var db = new MatchReporterEntities())
                {
                    db.Entry(this.Match).State = this.Match.MatchId == 0 ? EntityState.Added : EntityState.Modified;
                    db.SaveChanges();
                }
            }
            //dataAddMatchDetails.Dispose();
        }
        private void matchConcludeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if(int.Parse(lblTimeMinutes.Text) == 60)
            {
                if (MessageBox.Show(this, "Jeste li sigurni da želite zaključiti utakmicu? \nViše neće biti moguće mijenjati podatke o utakmici.",
                "Zaključi utakmicu", MessageBoxButtons.YesNo, MessageBoxIcon.Question).Equals(DialogResult.Yes))
                {
                    try
                    {
                        this.Match.Concluded = 1;

                        panelMain.Enabled = false;

                        this.dataMatchDetailsToolStripMenuItem.Enabled = false;
                        this.dataTeamsToolStripMenuItem.Enabled = false;
                        this.dataPlayersToolStripMenuItem.Enabled = false;
                        this.dataOfficialsToolStripMenuItem.Enabled = false;

                        this.matchSaveToolStripMenuItem.Enabled = false;
                        this.matchConcludeToolStripMenuItem.Enabled = false;

                        using (var db = new MatchReporterEntities())
                        {
                            db.Entry(this.Match).State = this.Match.MatchId == 0 ? EntityState.Added : EntityState.Modified;
                            db.SaveChanges();
                        }
                    }
                    catch
                    {
                        MessageBox.Show(this, "Došlo je do greške. \nUtakmica nije zaključena.", "Greška",
                            MessageBoxButtons.YesNo, MessageBoxIcon.Error);
                    }
                }
            }
            else
            {
                MessageBox.Show(this, "Ne možete zaključiti utakmicu jer \nutakmica nije završena.", "Greška",
                    MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
        }