// Used to get a dictionary of timetable details from the database public Dictionary<string, TimetableDetails> GetTimetableDetails(DateTime date) { string query = string.Format("Date = '{0}'", string.Format("{0:MM-dd-yy}", date)); ResultSet timetableResults = new ResultSet(GetDataReader("[BusTripTable]", query)); // Search the database for all details relating to the specified date CloseConnection(); Dictionary<string, TimetableDetails> details = new Dictionary<string, TimetableDetails>(); string[] timeSlots = { "8.30 - 10.15", "2.00 - 3.45 ", "10.45 - 1.45", "4.00 - 7.00 " }; for(int i = 0; i < timeSlots.Length; i++){ // Go through each possible timeslot and add the details about it to the details Dictionary TimetableDetails timetableDetails = new TimetableDetails(); int row = timetableResults.FindRow<string>(2, timeSlots[i]); // Find the row which stores the data for this time slot if (row == -1) // If there is no-one registered for this time slot use the small bus { timetableDetails.busUsed = "9 Person"; timetableDetails.seatsLeft = 24; details.Add(timeSlots[i], timetableDetails); continue; } if(timetableResults.GetData<int>(4, row) < 9) // If there are less than 9 people registered for this bus use the small bus { timetableDetails.busUsed = "9 Person"; } else if (timetableResults.GetData<int>(4, row) < 17) // If there are >= 9 and < 17 people use the bigger bus { timetableDetails.busUsed = "17 Person"; } else // If there are >= 17 people use both busses { timetableDetails.busUsed = "Both"; } timetableDetails.seatsLeft = 24 - timetableResults.GetData<int>(4, row); // calculate the seats left now that we have found the number of seats details.Add(timeSlots[i], timetableDetails); // Add these details to the dictionary } // End of the loop through all of the time slots return details; }