public List <Spoor> GetAllSporen() { List <Spoor> returnList = new List <Spoor>(); string query = "SELECT S.ID, S.NUMMER, S.LENGTE, S.BESCHIKBAAR, S.INUITRIJSPOOR FROM SPOOR S"; using (SqlConnection connection = DatabaseManager.Connection) { using (SqlCommand command = new SqlCommand(query, connection)) { using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { decimal spoorid = reader.GetDecimal(0); decimal spoornummer = reader.GetDecimal(1); int lengte = Convert.ToInt32(reader.GetDecimal(2)); bool beschikbaar = reader.GetBoolean(3); bool inuitrij = reader.GetBoolean(4); Spoor newSpoor = new Spoor(spoorid, spoornummer, lengte, beschikbaar, inuitrij); returnList.Add(newSpoor); } } } } return(returnList); }
public Sector GetDriveInSector() { Sector returnSector = null; string query = "SELECT TOP 1 SP.NUMMER, S.NUMMER FROM SECTOR S JOIN SPOOR SP ON SP.ID = S.SPOOR_ID WHERE S.BESCHIKBAAR = 1 AND SP.BESCHIKBAAR = 1 AND S.BLOKKADE = 0 AND S.TRAM_ID IS NULL ORDER BY SP.ID ASC"; using (SqlConnection connection = DatabaseManager.Connection) { using (SqlCommand command = new SqlCommand(query, connection)) { using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { int spoornummer = Convert.ToInt32(reader.GetDecimal(0)); int sectornummer = Convert.ToInt32(reader.GetDecimal(1)); Spoor spoor = new Spoor(spoornummer); returnSector = new Sector(sectornummer, spoor, null); } } } } return(returnSector); }
public Sector(decimal?nummer, Spoor spoor, Tram tram) { Spoor = spoor; Tram = tram; Nummer = nummer; }