Exemplo n.º 1
0
        // having a connecting to DB function with the sqlstring as input
        private List<Team> ReadFromDB(string sqlstring)
        {
            List<Team> teams = new List<Team>();
            NpgsqlConnection conn = new NpgsqlConnection("Server=localhost;Port=5432;User Id=reader;Password=hej123;Database=guessthegame;");
            try
            {
                //connecting to the database
                conn.Open();

                // defining the sql npgsql command
                NpgsqlCommand command = new NpgsqlCommand(sqlstring, conn);
                NpgsqlDataReader dr = command.ExecuteReader();

                Team tempTeam;

                //reading all the users.
                while (dr.Read())
                {
                    tempTeam = new Team(dr.GetInt32(0), dr.GetString(1));
                    teams.Add(tempTeam);
                }
            }
            catch (Exception msg)
            {
                //do something if exception
                System.Diagnostics.Debug.WriteLine(msg.ToString());
            }
            finally
            {
                conn.Close();
            }

            return teams;
        }
Exemplo n.º 2
0
        public Game(int id, Round round_id, Team team1, Team team2, DateTime planned_date)
        {
            this.id = id;
            this.round_id = round_id;
            this.team1 = team1;
            this.team2 = team2;
            this.planned_date = planned_date;

            //wondering if games should've been played when being defined
            game_played = false;
            result = -1;
        }