Example #1
0
        public Game Load(int gameID)
        {
            Game game = new Game();

            SqlConnection sqlConnection = new SqlConnection(connString);
            sqlConnection.Open();

            SqlCommand cmd = new SqlCommand();
            cmd.Connection = sqlConnection;
            string sql = string.Format("SELECT TOP 1 * FROM {0} WHERE GameID = {1}", Constants.Table.GameInfo, gameID.ToString());
            cmd.CommandText = sql;
            SqlDataReader dtr = cmd.ExecuteReader();

            try
            {
                while (dtr.Read())
                {
                    game.gameId = (int)dtr["GameID"];
                    game.invalid = (bool)dtr["Invalid"];
                    game.gameMode = (string)dtr["GameMode"];
                    game.gameType = (string)dtr["GameType"];
                    game.subType = (string)dtr["SubType"];
                    game.mapId = (int)dtr["MapID"];
                    game.teamId = (int)dtr["TeamID"];
                    game.championId = (int)dtr["ChampionID"];
                    game.spell1 = (int)dtr["Spell1"];
                    game.spell2 = (int)dtr["Spell2"];
                    game.createDate = (long)dtr["CreateDate"];
                    game.createDateStr = (long)dtr["CreateDateStr"];
                    game.level = (int)dtr["Level"];

                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                dtr.Close();
                sqlConnection.Close();
            }

            return game;
        }
Example #2
0
        public void SaveLoadGameTest()
        {
            DatabaseManager manager = new DatabaseManager(myConnection);
            Game gameTestData = new Game();
            gameTestData.gameId = 2;
            gameTestData.invalid = false;
            gameTestData.gameMode = "Test Game Mode";
            gameTestData.gameType = "Test Game Type";
            gameTestData.subType = "Test Sub Type";
            gameTestData.mapId = 1;
            gameTestData.teamId = 1;
            gameTestData.championId = 1;
            gameTestData.spell1 = 1;
            gameTestData.spell2 = 1;
            gameTestData.level = 1;
            gameTestData.createDate = 1;
            gameTestData.createDateStr = 1;

            manager.Save(gameTestData);
            Game gameLoadData = manager.Load(gameTestData.gameId);
            AreGamesEqual(gameTestData, gameLoadData);
        }
Example #3
0
        public void AreGamesEqual(Game game1, Game game2)
        {
            Assert.AreEqual(game1.gameId, game2.gameId);
            Assert.AreEqual(game1.invalid, game2.invalid);
            Assert.AreEqual(game1.gameMode, game2.gameMode);
            Assert.AreEqual(game1.gameType, game2.gameType);
            Assert.AreEqual(game1.subType, game2.subType);
            Assert.AreEqual(game1.mapId, game2.mapId);
            Assert.AreEqual(game1.teamId, game2.teamId);
            Assert.AreEqual(game1.championId, game2.championId);
            Assert.AreEqual(game1.spell1, game2.spell2);
            Assert.AreEqual(game1.spell2, game2.spell2);
            Assert.AreEqual(game1.level, game2.level);
            Assert.AreEqual(game1.createDate, game2.createDate);
            Assert.AreEqual(game1.createDateStr, game2.createDateStr);

            //Assert.AreEqual(game1.statistics.Length, game2.statistics.Length);

            //foreach (Statistic stat in game1.statistics)
            //{
            //    game2.statistics.GetValue(
            //}
            //TODO: Implement Stats Compare
        }
Example #4
0
 public void Save(Game game)
 {
     //CreateStatColumns(game);
     string sql = string.Format(@"IF NOT EXISTS(SELECT * FROM GameStats WHERE GameID = {1})
                                 INSERT INTO {0} (GameID, Invalid, GameMode, GameType, SubType, MapID, TeamID, ChampionID, Spell1, Spell2, CreateDate, CreateDateStr, Level)
                                 VALUES ({1}, {2}, '{3}', '{4}', '{5}', {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13})", Constants.Table.GameInfo,
             game.gameId, game.invalid ? 1 : 0, game.gameMode, game.gameType, game.subType, game.mapId, game.teamId, game.championId, game.spell1, game.spell2, game.level, game.createDate, game.createDateStr, game.level);
     this.RunSQL(sql);
     SaveStats(game.gameId, game.statistics);
 }