示例#1
0
        public Game GetGameById(int id)
        {
            Game game = new Game();
            using (_connection)
            {
                _connection.Open();
                string selectString = "SELECT * FROM GAME WHERE GameId = @GameId";

                command.CommandText = selectString;
                command.Parameters.Add("@GameId", id);

                SqlDataReader reader = command.ExecuteReader();

                if (!reader.HasRows) return null;

                while (reader.Read())
                {
                    game.GameId = Convert.ToInt32(reader["GameId"]);
                    game.Name = reader["Name"].ToString();
                    game.ReleaseYear = Convert.ToInt32(reader["ReleaseYear"]);
                    game.Genre = reader["Genre"].ToString();
                    game.ImageUrl = reader["ImageURL"].ToString();
                    game.CreationDate = Convert.ToDateTime(reader["CreationDate"]);
                    game.GameInfo = reader["GameInfo"].ToString();

                }

                reader.Close();
                _connection.Close();
            }
            return game;
        }
示例#2
0
        public List<Game> GetAllGames()
        {
            List<Game> gameList = new List<Game>();
            using (_connection)
            {
                _connection.Open();
                string selectString = "SELECT * FROM GAME";

                command.CommandText = selectString;

                SqlDataReader reader = command.ExecuteReader();

                if (!reader.HasRows) return null;

                while (reader.Read())
                {
                    Game game = new Game();
                    game.GameId = Convert.ToInt32(reader["GameId"]);
                    game.Name = reader["Name"].ToString();
                    game.ReleaseYear = Convert.ToInt32(reader["ReleaseYear"]);
                    game.Genre = reader["Genre"].ToString();
                    game.ImageUrl = reader["ImageURL"].ToString();
                    game.CreationDate = Convert.ToDateTime(reader["CreationDate"]);
                    game.GameInfo = reader["GameInfo"].ToString();

                    gameList.Add(game);
                }
                reader.Close();

                _connection.Close();
            }
            return gameList;
        }
示例#3
0
 private void SetGame()
 {
     _game = _gameDAO.GetGameById(2);
 }
示例#4
0
 public GamePageController(IGamePage form)
 {
     _form = form;
     _gameDAO = new GameDAO();
     _game = new Game();
 }
示例#5
0
        public void UpdateGameById(Game game)
        {
            using (_connection)
            {
                _connection.Open();
                string updateString = @"UPDATE GAME SET Name = @Name,ReleaseYear = @ReleaseYear,
                                                    Genre = @Genre,
                                                    GaneInfo = @GameInfo,ImageURL = @ImageUrl
                                                    WHERE GameId = @GameId";
                command.CommandText = updateString;

                command.Parameters.Add("@GameId", game.GameId);
                command.Parameters.Add("@Name", game.Name);
                command.Parameters.Add("@ReleaseYear", game.ReleaseYear);
                command.Parameters.Add("@Genre", game.Genre);
                command.Parameters.Add("@GameInfo", game.GameInfo);
                command.Parameters.Add("@ImageUrl", game.ImageUrl);

                command.ExecuteNonQuery();

                _connection.Close();
            }
        }
示例#6
0
        public void InsertNewGame(Game game)
        {
            using (_connection)
            {
                _connection.Open();
                string insertString = @"INSERT INTO GAME(Name,ReleaseYear,Genre,
                                        CreationDate,ImageURL,GameInfo) VALUES(
                                        @Name,@ReleaseYear,GETDATE(),@ImageUrl,@GameInfo)";

                command.CommandText = insertString;

                command.Parameters.Add("@Name", game.Name);
                command.Parameters.Add("@ReleaseYear", game.ReleaseYear);
                command.Parameters.Add("@Genre", game.Genre);
                command.Parameters.Add("@GameInfo", game.GameInfo);
                command.Parameters.Add("@ImageUrl", game.ImageUrl);

                command.ExecuteNonQuery();

                _connection.Close();
            }
        }