public static List <YogaWorkshop> LoadBookedWorkshops(string username, int wStatus) {//method used to load booked workshops from data base in lists List <YogaWorkshop> workshop = new List <YogaWorkshop>(); List <YogaNames> teachers = ListTeachers(); OleDbConnection myConnection = GetConnection(); string myQuery = "SELECT * FROM YogaWorkshop LEFT JOIN YogaWorkshopReservation ON YogaWorkshop.WorkshopID=YogaWorkshopReservation.YogaWorkshopID WHERE WClientUsername = '******' AND WorkshopWaitinglistStatus =" + wStatus + ";"; OleDbCommand myCommand = new OleDbCommand(myQuery, myConnection); try { myConnection.Open(); OleDbDataReader myReader = myCommand.ExecuteReader(); while (myReader.Read()) { YogaNames currentTeacher = FindTeacher(teachers, int.Parse(myReader["StaffID"].ToString())); YogaWorkshop w = new YogaWorkshop((int.Parse(myReader["WorkshopID"].ToString())), DateTime.Parse(myReader["WorkshopTime"].ToString()), myReader["WorkshopName"].ToString(), currentTeacher, (myReader["WorkshopDuration"].ToString()), myReader["WorkshopDescription"].ToString(), (int.Parse(myReader["WorkshopPlacesAvailable"].ToString()))); workshop.Add(w); } return(workshop); } catch (Exception ex) { Console.WriteLine("Exception in DBHandler", ex); return(null); } finally { myConnection.Close(); } }
public static List <YogaWorkshop> LoadAllWorkshops() {//method used to load workshops from data base in lists List <YogaWorkshop> workshop = new List <YogaWorkshop>(); List <YogaNames> teachers = ListTeachers(); OleDbConnection myConnection = GetConnection(); string myQuery = "SELECT * FROM YogaWorkshop WHERE NOW() <= WorkshopTime ORDER BY WorkshopTime"; OleDbCommand myCommand = new OleDbCommand(myQuery, myConnection); try { myConnection.Open(); OleDbDataReader myReader = myCommand.ExecuteReader(); while (myReader.Read()) { YogaNames currentTeacher = FindTeacher(teachers, int.Parse(myReader["StaffID"].ToString())); YogaWorkshop w = new YogaWorkshop((int.Parse(myReader["WorkshopID"].ToString())), DateTime.Parse(myReader["WorkshopTime"].ToString()), myReader["WorkshopName"].ToString(), currentTeacher, (myReader["WorkshopDuration"].ToString()), myReader["WorkshopDescription"].ToString(), (int.Parse(myReader["WorkshopPlacesAvailable"].ToString()))); workshop.Add(w); } return(workshop); } catch (Exception ex) { Console.WriteLine("Exception in DBHandler", ex); return(null); } finally { myConnection.Close(); } }