public static Event GetEvent(int id) { Event evnt = null; using (SqlConnection connection = new SqlConnection(Properties.Settings.Default.DatabaseConnectionString)) { connection.Open(); string sql = "SELECT Event.Description, EventChoice.Description, Target FROM Event LEFT JOIN EventChoice ON ID = Source WHERE ID = @id"; SqlCommand command = new SqlCommand(sql, connection); command.Parameters.AddWithValue("@id", id); SqlDataReader reader = command.ExecuteReader(); string desc = null; List<Choice> choices = new List<Choice>(); while (reader.Read()) { desc = reader.GetString(0); try { choices.Add(new Choice(reader.GetString(1), reader.GetInt32(2))); } catch (Exception) { } } evnt = new Event(desc, choices); connection.Close(); } return evnt; }
public static void ChangeEvent(int eventId) { Event ev = DataStore.GetEvent(eventId); if (ev != null) _event = ev; }