public void AddTime(Score score) { string player = EscapeString(score.getPlayer()); string mode = EscapeString(score.getMode()); string realTimeString = EscapeString(score.getRealTimeString()); string gameTimeString = EscapeString(score.getGameTimeString()); int realTimeSeconds = score.getRealTimeSeconds(); int gameTimeSeconds = score.getGameTimeSeconds() * 60; string videoURL = EscapeString(score.getVideoURL()); string comment = EscapeString(score.getComment()); SqlCeDataReader reader = ExecuteQuery("SELECT * FROM Scores WHERE Player = '" + player + "' AND Mode = '" + mode + "';"); if (reader.Read()) { //delete existing record ExecuteUpdate("DELETE FROM Scores WHERE Player = '" + player + "' AND Mode = '" + mode + "';"); //insert new record ExecuteUpdate("INSERT INTO Scores (Mode, Player, RealTimeSeconds, RealTimeString, GameTimeSeconds, GameTimeString, Comment, VideoURL)" + "VALUES ('" + mode + "', '" + player + "', " + realTimeSeconds + ", '" + realTimeString + "', " + gameTimeSeconds + ", " + "'" + gameTimeString + "', '" + comment + "', '" + videoURL + "');"); } else { ExecuteUpdate("INSERT INTO Scores (Mode, Player, RealTimeSeconds, RealTimeString, GameTimeSeconds, GameTimeString, Comment, VideoURL)" + "VALUES ('" + mode + "', '" + player + "', " + realTimeSeconds + ", '" + realTimeString + "', " + gameTimeSeconds + ", " + "'" + gameTimeString + "', '" + comment + "', '" + videoURL + "');"); } }
public List<Score> GetTimes(string mode) { SqlCeDataReader reader; List<Score> scoreList = new List<Score>(); int rank = 1; EscapeString(mode); if (mode == "Any%GT") { reader = ExecuteQuery("SELECT * FROM Scores WHERE Mode = '" + mode + "' ORDER BY GameTimeSeconds, RealTimeSeconds;"); } else { reader = ExecuteQuery("SELECT * FROM Scores WHERE Mode = '" + mode + "' ORDER BY RealTimeSeconds;"); } while (reader.Read()) { string player = (string)reader["Player"]; string realTimeString = (string)reader["RealTimeString"]; string gameTimeString = (string)reader["GameTimeString"]; int realTimeSeconds = (int)reader["RealTimeSeconds"]; int gameTimeSeconds = (int)reader["GameTimeSeconds"] * 60; string comment = HttpUtility.HtmlEncode((string)reader["Comment"]); string videoURL = (string)reader["VideoURL"]; Score score = new Score(mode, player, realTimeString, realTimeSeconds, gameTimeString, gameTimeSeconds, videoURL, comment); score.setRank(rank); scoreList.Add(score); rank++; } return scoreList; }
void submitButton_Click(object sender, EventArgs e) { string realTimeString = realTimeTextBox.Text; string gameTimeString = gameTimeTextBox.Text; string comment = commentTextBot.Text; string videoURL = videoLinkTextBox.Text; string player = Session["username"].ToString(); int realTimeSeconds; int gameTimeSeconds; if (leaderboardType == "Any%GameTime") { if (realTimeString == "" || gameTimeString == "") { StatusLiteral.Text = "Please fill out the time fields"; } else { FormattedTime formattedRealTime = TimeValidator.GetFormattedTime(realTimeString); FormattedTime formattedGameTime = TimeValidator.GetFormattedTime(gameTimeString); if (formattedRealTime.getTimeSeconds() == -1 || formattedGameTime.getTimeSeconds() == -1) { StatusLiteral.Text = "Invalid times"; } else { realTimeSeconds = formattedRealTime.getTimeSeconds(); gameTimeSeconds = formattedGameTime.getTimeSeconds(); realTimeString = formattedRealTime.getTimeString(); gameTimeString = formattedGameTime.getTimeString(); Score score = new Score(mode, player, realTimeString, realTimeSeconds, gameTimeString, gameTimeSeconds, videoURL, comment); Database db = new Database(); db.Connect(); db.AddTime(score); db.Close(); StatusLiteral.Text = "Successfully added time"; Response.Redirect("SuccessPage.aspx?successCode=addGameTime"); } } } else if (leaderboardType == "Any%RealTime" || leaderboardType == "100%" || leaderboardType == "Low%Ice" || leaderboardType == "Low%Speed" || leaderboardType == "100%Map" || leaderboardType == "Any%GTCode" || leaderboardType == "RBO" || leaderboardType == "PowerBombsAny%") { if (realTimeString == "") { StatusLiteral.Text = "Please fill out the time field"; } else { FormattedTime formattedRealTime = TimeValidator.GetFormattedTime(realTimeString); if (formattedRealTime.getTimeSeconds() == -1) { StatusLiteral.Text = "Invalid time"; } else { realTimeSeconds = formattedRealTime.getTimeSeconds(); realTimeString = formattedRealTime.getTimeString(); Score score = new Score(mode, player, realTimeString, realTimeSeconds, videoURL, comment); Database db = new Database(); db.Connect(); db.AddTime(score); db.Close(); StatusLiteral.Text = "Successfully added time"; Response.Redirect("SuccessPage.aspx?successCode=addRealTime"); } } } }