FreakOut.classes.DatabaseConnector.GetGame C# (CSharp) Method

GetGame() public method

public GetGame ( int GameID ) : Game
GameID int
return Game
        public Game GetGame(int GameID)
        {
            //Same as above, but this time try to get the game via the ID
            LogInstance.WriteToFile(1, "Trying to fetch the game with ID " + GameID + " from the database.", LogSource);
            if (!connectionopen)
            {
                DBConnector.Open();
                connectionopen = true;
            }
            FbTransaction DBTransaction = DBConnector.BeginTransaction();
            FbCommand DBCommand = new FbCommand("SELECT * FROM games WHERE ID=" + GameID, DBConnector, DBTransaction);
            FbDataReader DBReader = DBCommand.ExecuteReader();

            int x = 0;
            Game Result = new Game();
            Result.ID = GameID;
            Result.InfoXML = new XmlDocument();

            while (DBReader.Read())
            {
                x++;
                if (x == 1)
                {
                    Result.Name = DBReader.GetString(1);
                    Result.InfoXML.LoadXml(DBReader.GetString(2));
                    Result.ReleaseDate = DateTime.Parse(DBReader.GetString(6));
                    Result.InstallPath = DBReader.GetString(7);
                    Result.scraper_gdb_id = DBReader.GetInt32(8);
                    Result.Platform = DBReader.GetString(9);

                    if (DBReader.GetInt32(3) != 0)
                        Result.Downloaded = true;
                    else
                        Result.Downloaded = false;

                    if (DBReader.GetInt32(4) != 0)
                        Result.Snatched = true;
                    else
                        Result.Snatched = false;

                    if (DBReader.GetInt32(5) != 0)
                        Result.Wanted = true;
                    else
                        Result.Wanted = false;
                }
            }

            if (x == 0)
                return null;

            DBConnector.Close();
            connectionopen = false;
            return Result;
        }

Same methods

DatabaseConnector::GetGame ( string GameName ) : Game

Usage Example

Beispiel #1
0
        public ModifyGame(int GameID, Logger Logfacility)
        {
            InitializeComponent();
            LogInstance = Logfacility;
            DBConnection = new DatabaseConnector(LogInstance);
            LogInstance.WriteToFile(1, "Modify game with the ID " + GameID, "Database:Connector");
            GameToModify = DBConnection.GetGame(GameID);
            lblmod_GameName.Text = GameToModify.Name;

            if (GameToModify.Snatched)
                chkmod_Snatched.Checked = true;
            else
                chkmod_Snatched.Checked = false;

            if (GameToModify.Wanted)
                chkmod_Wanted.Checked = true;
            else
                chkmod_Wanted.Checked = false;

            if (GameToModify.Downloaded)
                chkmod_Downloaded.Checked = true;
            else
                chkmod_Downloaded.Checked = false;

            if (GameToModify.InstallPath != null)
                txtmod_InstallPath.Text = GameToModify.InstallPath;
        }