public Dictionary <uint, DatabaseGameModel> GetAllGames()
        {
            Dictionary <uint, DatabaseGameModel> gameContainer = new Dictionary <uint, DatabaseGameModel>();

            using (MySqlConnection sqlConnection = new MySqlConnection(connectString)) {
                sqlConnection.Open();
                MySqlCommand sqlCommand = sqlConnection.CreateCommand();
                sqlCommand.CommandText = "SELECT * FROM Games;";
                using (MySqlDataReader reader = sqlCommand.ExecuteReader()) {
                    while (reader.Read())
                    {
                        uint gameID         = (uint)reader["gID"];
                        uint duration       = (uint)reader["Duration"];
                        DatabaseGameModel g = new DatabaseGameModel(gameID, duration);
                        gameContainer.Add(gameID, g);
                    }
                }

                foreach (DatabaseGameModel g in gameContainer.Values)
                {
                    string selectBygIDCommandText = "SELECT * FROM Players NATURAL JOIN GamesPlayed WHERE gID = " + g.ID + ";";
                    sqlCommand.CommandText = selectBygIDCommandText;
                    using (MySqlDataReader reader = sqlCommand.ExecuteReader()) {
                        while (reader.Read())
                        {
                            string name     = (string)reader["Name"];
                            uint   score    = (uint)reader["Score"];
                            uint   accuracy = (uint)reader["Accuracy"];
                            g.AddPlayer(name, score, accuracy);
                        }
                    }
                }
            }
            return(gameContainer);
        }
Exemple #2
0
        private Dictionary <uint, DatabaseGameModel> GetDummyAllGamesDictionary()
        {
            // create a fake dictionary for now while we code sql stuff
            // delete all this stuff later
            Dictionary <uint, DatabaseGameModel> dummyGames = new Dictionary <uint, DatabaseGameModel>();
            // definitely delete this random uint typecast. very bad.
            DatabaseGameModel dummyGame1 = new DatabaseGameModel(111, 4201);

            dummyGame1.AddPlayer("dummy player 1.1", 420, 69);
            dummyGame1.AddPlayer("dummy player 1.2", 420, 69);
            dummyGame1.AddPlayer("dummy player 1.3", 420, 69);
            dummyGames[dummyGame1.ID] = dummyGame1;
            DatabaseGameModel dummyGame2 = new DatabaseGameModel(222, 4202);

            dummyGame2.AddPlayer("dummy player 2.1", 420, 69);
            dummyGame2.AddPlayer("dummy player 2.2", 420, 69);
            dummyGame2.AddPlayer("dummy player 2.3", 420, 69);
            dummyGames[dummyGame2.ID] = dummyGame2;
            DatabaseGameModel dummyGame3 = new DatabaseGameModel(333, 4203);

            dummyGame3.AddPlayer("dummy player 3.1", 420, 69);
            dummyGame3.AddPlayer("dummy player 3.2", 420, 69);
            dummyGame3.AddPlayer("dummy player 3.3", 420, 69);
            dummyGames[dummyGame3.ID] = dummyGame3;
            return(dummyGames);
        }