private void LoadRating(string userName) { ProgressForm frmProgress = ProgressForm.Show(this, "Loading Rating..."); UserElo ue = null; if (userName == "") { ue = new UserElo(userID); } else { ue = new UserElo(userName); } DataTable dt = UserElo.UserGamesRating; int tabs = tabControl1.TabCount; tabs--; if (dt != null && dt.Rows.Count > 0) { isRated = true; this.userID = Convert.ToInt32(dt.Rows[0]["UserID"]); this.userName = dt.Rows[0]["UserName"].ToString(); tabControl1.TabPages.RemoveAt(tabs); var gameTypes = (from DataRow dr in dt.Rows select new { ChessTypeID = dr["ChessTypeID"], GameTypeID = dr["GameTypeID"] }).Distinct(); var centaurGameType = (from DataRow dr in dt.Rows select new { ChessTypeID = 3 }).Distinct(); int ChessTypeID = 0; int GameTypeID = 0; bool isCentaurTabOpened = false; foreach (var item in gameTypes) { ChessTypeID = Convert.ToInt32(item.ChessTypeID); GameTypeID = Convert.ToInt32(item.GameTypeID); ChessTypeE chessType = (ChessTypeE)ChessTypeID; GameType gameType = (GameType)GameTypeID; #region ChessType switch (chessType) { case ChessTypeE.Human: switch (gameType) { case GameType.Bullet: tabControl1.TabPages.Add("Bullet"); RatedGameResultUc ratedGameResultUc1 = new RatedGameResultUc(); ratedGameResultUc1.UserID = UserID; ratedGameResultUc1.chessTypeID = ChessTypeID; ratedGameResultUc1.gameTypeID = GameTypeID; ratedGameResultUc1.UserElo = ue; ratedGameResultUc1.SetRating(); tabControl1.TabPages[tabs].Controls.Add(ratedGameResultUc1); tabs++; break; case GameType.Blitz: tabControl1.TabPages.Add("Blitz"); RatedGameResultUc ratedGameResultUc2 = new RatedGameResultUc(); ratedGameResultUc2.UserID = UserID; ratedGameResultUc2.chessTypeID = ChessTypeID; ratedGameResultUc2.gameTypeID = GameTypeID; ratedGameResultUc2.UserElo = ue; ratedGameResultUc2.SetRating(); tabControl1.TabPages[tabs].Controls.Add(ratedGameResultUc2); tabs++; break; case GameType.Rapid: tabControl1.TabPages.Add("Rapid"); RatedGameResultUc ratedGameResultUc3 = new RatedGameResultUc(); ratedGameResultUc3.UserID = UserID; ratedGameResultUc3.chessTypeID = ChessTypeID; ratedGameResultUc3.gameTypeID = GameTypeID; ratedGameResultUc3.UserElo = ue; ratedGameResultUc3.SetRating(); tabControl1.TabPages[tabs].Controls.Add(ratedGameResultUc3); tabs++; break; case GameType.Long: tabControl1.TabPages.Add("Long"); RatedGameResultUc ratedGameResultUc4 = new RatedGameResultUc(); ratedGameResultUc4.UserID = UserID; ratedGameResultUc4.chessTypeID = ChessTypeID; ratedGameResultUc4.gameTypeID = GameTypeID; ratedGameResultUc4.UserElo = ue; ratedGameResultUc4.SetRating(); tabControl1.TabPages[tabs].Controls.Add(ratedGameResultUc4); tabs++; break; } break; case ChessTypeE.Engine: switch (gameType) { case GameType.Bullet: tabControl1.TabPages.Add("Computer/Bullet"); RatedGameResultUc ratedGameResultUc5 = new RatedGameResultUc(); ratedGameResultUc5.UserID = UserID; ratedGameResultUc5.chessTypeID = ChessTypeID; ratedGameResultUc5.gameTypeID = GameTypeID; ratedGameResultUc5.UserElo = ue; ratedGameResultUc5.SetRating(); tabControl1.TabPages[tabs].Controls.Add(ratedGameResultUc5); tabs++; break; case GameType.Blitz: tabControl1.TabPages.Add("Computer/Blitz"); RatedGameResultUc ratedGameResultUc6 = new RatedGameResultUc(); ratedGameResultUc6.UserID = UserID; ratedGameResultUc6.chessTypeID = ChessTypeID; ratedGameResultUc6.gameTypeID = GameTypeID; ratedGameResultUc6.UserElo = ue; ratedGameResultUc6.SetRating(); tabControl1.TabPages[tabs].Controls.Add(ratedGameResultUc6); tabs++; break; case GameType.Rapid: tabControl1.TabPages.Add("Computer/Rapid"); RatedGameResultUc ratedGameResultUc7 = new RatedGameResultUc(); ratedGameResultUc7.UserID = UserID; ratedGameResultUc7.chessTypeID = ChessTypeID; ratedGameResultUc7.gameTypeID = GameTypeID; ratedGameResultUc7.UserElo = ue; ratedGameResultUc7.SetRating(); tabControl1.TabPages[tabs].Controls.Add(ratedGameResultUc7); tabs++; break; case GameType.Long: tabControl1.TabPages.Add("Computer/Long"); RatedGameResultUc ratedGameResultUc8 = new RatedGameResultUc(); ratedGameResultUc8.UserID = UserID; ratedGameResultUc8.chessTypeID = ChessTypeID; ratedGameResultUc8.gameTypeID = GameTypeID; ratedGameResultUc8.UserElo = ue; ratedGameResultUc8.SetRating(); tabControl1.TabPages[tabs].Controls.Add(ratedGameResultUc8); tabs++; break; } break; case ChessTypeE.Centaur: if (!isCentaurTabOpened) { tabControl1.TabPages.Add("Centaur"); RatedGameResultUc ratedGameResultUc9 = new RatedGameResultUc(); ratedGameResultUc9.UserID = UserID; ratedGameResultUc9.chessTypeID = 3; ratedGameResultUc9.gameTypeID = 0; ratedGameResultUc9.UserElo = ue; ratedGameResultUc9.SetRating(); tabControl1.TabPages[tabs].Controls.Add(ratedGameResultUc9); tabs++; isCentaurTabOpened = true; } break; case ChessTypeE.Correspondence: tabControl1.TabPages.Add("Correspondence"); RatedGameResultUc ratedGameResultUc10 = new RatedGameResultUc(); ratedGameResultUc10.UserID = UserID; ratedGameResultUc10.chessTypeID = ChessTypeID; ratedGameResultUc10.gameTypeID = GameTypeID; ratedGameResultUc10.UserElo = ue; ratedGameResultUc10.SetRating(); tabControl1.TabPages[tabs].Controls.Add(ratedGameResultUc10); tabs++; break; default: break; } } #endregion } else { RatedGameResultUc ratedGameResultUc = new RatedGameResultUc(); tabControl1.TabPages[tabs].Controls.Add(ratedGameResultUc); isRated = false; } frmProgress.Close(); }
private bool Save() { int player1 = 0, player2 = 0; if (!IsWhiteBlackPlayer) { MessageForm.Error(Msg.GetMsg(MsgE.ErrorWhiteAndBlackBye)); return(false); } if (IsChildRound) { MessageForm.Error(Msg.GetMsg(MsgE.ErrorTieBreakMatchStart)); return(false); } player1 = Player1; player2 = Player2; if (cbColorA.SelectedIndex == 1) { player1 = Player2; player2 = Player1; } Kv kv = new Kv(); if (this.Tournament != null) { kv.Set("TournamentID", this.Tournament.TournamentID); } kv.Set("WhiteUserID", player1); kv.Set("BlackUserID", player2); kv.Set("Round", round); if (cmbMin.SelectedItem != null) { kv.Set("TimeMin", cmbMin.SelectedItem.ToString()); } else { kv.Set("TimeMin", 1); } if (cmbSec.SelectedItem != null) { kv.Set("TimeSec", cmbSec.SelectedItem.ToString()); } else { kv.Set("TimeSec", 0); } kv.Set("MatchStartDate", DateTime.Now); kv.Set("MatchStartTime", DateTime.Now); kv.Set("ParentMatchID", this.ParentMatchID); kv.Set("TournamentMatchStatusID", (int)TournamentMatchStatusE.Scheduled); kv.Set("TournamentMatchTypeID", (int)TournamentMatchTypeE.TieBreak); ProgressForm frmProgress = ProgressForm.Show(this, "Saving Match..."); DataSet ds = SocketClient.SaveTournamentMatch(kv); frmProgress.Close(); return(true); }
private void RestartTournamentMatch(bool isRound, bool isFromLastMove) { if (this.Tournament == null) { return; } if (this.Tournament.TournamentID == 0) { return; } int senderUserID = 0; int receiverUserID = 0; int tournamentDirectorID = 0; string matchIDs = string.Empty; string msg = string.Empty; ProgressForm frmProgress = null; if (IsTournamentDirector) { #region TournamentDirector if (isRound) { msg = "Restarting Round Matches..."; tournamentDirectorID = Ap.CurrentUserID; senderUserID = tournamentDirectorID; } else { tournamentDirectorID = Ap.CurrentUserID; matchIDs = GetSelectedMatchIDs(); if (!String.IsNullOrEmpty(matchIDs)) { msg = "Restarting Selected Matches..."; } else { MessageForm.Error(this.ParentForm, MsgE.ErrorTournamentMatchRestart, ""); return; } } if (MessageForm.Confirm(this.ParentForm, MsgE.ConfirmRestartTournamentMatch) != DialogResult.Yes) { return; } #endregion } else { #region Player msg = "Restarting Match..."; TournamentMatch tm = GetCurrentPlayerInProgressMatch(); if (tm == null) { MessageForm.Error(this.ParentForm, MsgE.ErrorTournamentMatchNotInprogress, ""); return; } matchIDs = tm.TournamentMatchID.ToString(); senderUserID = Ap.CurrentUserID; receiverUserID = tm.OpponentUserID(Ap.CurrentUserID); if (MessageForm.Confirm(this.ParentForm, MsgE.ConfirmRestartTournamentMatch) != DialogResult.Yes) { return; } if (Ap.Game != null) { Ap.Game.Pause(); } #endregion } frmProgress = ProgressForm.Show(this, msg); SocketClient.RestartGame(this.Tournament.TournamentID, matchIDs, tournamentDirectorID, senderUserID, receiverUserID, ResetGameE.Asked, isFromLastMove, string.Empty); if (Ap.Game != null && Ap.Game.GameId.Length > 0) { ChatClient.Write(ChatTypeE.GameWindow, ChatMessageTypeE.Info, ChatTypeE.GameWindow, MsgE.InfoTournamentMatchRestartRequest, Convert.ToInt32(Ap.Game.GameId)); } frmProgress.Close(); RefreshGrid(); }
private void SaveTournament() { Kv kv = new Kv(); if (Tournament != null) { kv.Set("TournamentID", this.Tournament.TournamentID); } if (cmbType.SelectedValue != null) { kv.Set("TournamentTypeID", cmbType.SelectedValue.ToString()); } if (cmbChessType.SelectedValue != null) { kv.Set("ChessTypeID", cmbChessType.SelectedValue.ToString()); } if (cmbRound.SelectedItem != null) { kv.Set("Round", cmbRound.SelectedItem.ToString()); } else { kv.Set("Round", 1); } if (cmbDblRound.SelectedItem != null) { kv.Set("DoubleRoundNo", Convert.ToInt32(cmbDblRound.Text)); } else { kv.Set("DoubleRoundNo", 0); } if (cmbType.SelectedValue != null && cmbType.SelectedValue.ToString() == "3") // if knock-out tournament. { chkAllowTieBreak.Checked = numTieBreaks.Value > 0; } kv.Set("Rated", chkRated.Checked); kv.Set("DoubleRound", chkDoubleRound.Checked); kv.Set("IsTieBreak", chkAllowTieBreak.Checked); if (cmbMin.SelectedItem != null) { kv.Set("TimeControlMin", cmbMin.SelectedItem.ToString()); } else { kv.Set("TimeControlMin", 1); } if (cmbSec.SelectedItem != null) { kv.Set("TimeControlSec", cmbSec.SelectedItem.ToString()); } else { kv.Set("TimeControlSec", 1); } kv.Set("RegistrationStartDate", dtpRegStartDate.Value.ToString()); kv.Set("RegistrationStartTime", dtpRegStartTime.Value.ToShortTimeString()); kv.Set("RegistrationEndDate", dtpRegEndDate.Value.ToString()); kv.Set("RegistrationEndTime", dtpRegEndTime.Value.ToShortTimeString()); kv.Set("TournamentStartDate", dtpTournamentStartDate.Value.ToString()); kv.Set("TournamentStartTime", dtpTournamentStartTime.Value.ToShortTimeString()); kv.Set("TournamentStatusID", (int)TournamentStatusE.Scheduled); kv.Set("StatusID", (int)StatusE.Active); kv.Set("TournamentStartTime", dtpTournamentStartTime.Value.ToString()); kv.Set("Name", txtTitle.Text); kv.Set("Description", txtInvitation.Text); if (cmbTbMin.SelectedItem != null) { kv.Set("TieBreakMin", cmbTbMin.SelectedItem.ToString()); } else { kv.Set("TieBreakMin", 1); } if (cmbTbSec.SelectedItem != null) { kv.Set("TieBreakSec", cmbTbSec.SelectedItem.ToString()); } else { kv.Set("TieBreakSec", 1); } kv.Set("NoOfGamesPerRound", numGames.Value); kv.Set("NoOfTieBreaks", numTieBreaks.Value); kv.Set("SuddenDeathWhiteMin", cmbWhiteMin.SelectedItem.ToString()); kv.Set("SuddenDeathBlackMin", cmbBlackMin.SelectedItem.ToString()); kv.Set("SuddenDeathSec", cmbSdSec.SelectedItem.ToString()); if (chkAllowMultipleWinners.Checked) { kv.Set("MaxWinners", numMaxWinners.Value); } else { kv.Set("MaxWinners", 0); } ProgressForm frmProgress = ProgressForm.Show(this, "Saving Tournament..."); DataSet ds = SocketClient.SaveTournament(kv); frmProgress.Close(); if (ds.Tables.Count > 0) { if (ds.Tables[0].Rows.Count > 0) { kv = new Kv(ds.Tables[0]); this.Tournament = new App.Model.Db.Tournament(Ap.Cxt, ds.Tables[0].Rows[0]); } } else { return; } if (this.Tournament == null) { return; } if (OnTournamentSave != null) { OnTournamentSave(this, EventArgs.Empty); } if (this.Tournament != null) { if (this.Tournament.TournamentID > 0) { MessageForm.Show(this.ParentForm, MsgE.ConfirmTournamentSaved, this.Tournament.Name); cmbChessType.Enabled = false; } } if (OnVisibleTab != null) { OnVisibleTab(this, EventArgs.Empty); } ViewStartTournamentButton(); }
private void RefreshGrid() { if (this.Tournament == null) { return; } if (this.Tournament.TournamentID == 0) { return; } this.panel1.Visible = false; dgvWinners.Visible = false; if (this.Tournament.TournamentTypeIDE == TournamentTypeE.Scheveningen) { dgvSchTeamResult.AutoGenerateColumns = false; dgvTeamPoint.AutoGenerateColumns = false; this.panel1.Visible = true; } ProgressForm frmProgress = ProgressForm.Show(this, "Loading Standings..."); try { DataSet ds = SocketClient.GetTournamentResultById(this.Tournament.TournamentID); if (ds != null) { if (ds.Tables.Count > 0) { table = ds.Tables[0]; RefreshGrid(table); FillWinners(table); if (ds.Tables.Count > 1) { FillSchTeamResult(ds.Tables[1]); } if (ds.Tables.Count > 2) { FillTeamUserPoint(ds.Tables[3]); } } else { dgvResult.DataSource = null; dgvSchTeamResult.DataSource = null; dgvTeamPoint.DataSource = null; } } else { dgvResult.DataSource = null; dgvSchTeamResult.DataSource = null; dgvTeamPoint.DataSource = null; } foreach (DataGridViewRow row in dgvResult.Rows) { if (row.Cells["CountryId"].Value.ToString() == "0") { Image item = Image.FromFile(Ap.FolderFlags + "244.png"); row.Cells["Flag"].Value = item; } else { Image item = Image.FromFile(Ap.FolderFlags + row.Cells["CountryId"].Value + ".png"); row.Cells["Flag"].Value = item; } } } catch (Exception ex) { TestDebugger.Instance.WriteError(ex); } FormatGrid(); frmProgress.Close(); }
void frmProgress_FormClosed(object sender, FormClosedEventArgs e) { frmProgress = null; }