// used for connecting to the db; to remove redundancy private List<Round> ReadFromDB(string sqlstring) { List<Round> rounds = new List<Round>(); 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(); Round tempRound; // reading all the rounds. while (dr.Read()) { tempRound = new Round(dr.GetInt32(0), dr.GetInt32(1), dr.GetInt32(2)); rounds.Add(tempRound); } } catch (Exception msg) { //do something if exception System.Diagnostics.Debug.WriteLine(msg.ToString()); } finally { conn.Close(); } return rounds; }
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; }