Exemplo n.º 1
0
        public static List <YogaClass> LoadAllClasses()
        {//method used to load clases from data base in lists
            List <YogaClass> classes  = new List <YogaClass>();
            List <YogaNames> teachers = ListTeachers();

            OleDbConnection myConnection = GetConnection();
            string          myQuery      = "SELECT * FROM YogaClass WHERE NOW() <= ClassStartingTime ORDER BY ClassStartingTime";
            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()));

                    YogaClass c = new YogaClass((int.Parse(myReader["ClassID"].ToString())), DateTime.Parse(myReader["ClassStartingTime"].ToString()), myReader["ClassName"].ToString(), currentTeacher, (int.Parse(myReader["ClassLevel"].ToString())), (myReader["ClassDuration"].ToString()), myReader["ClassDescription"].ToString(), (int.Parse(myReader["ClassPlacesAvailable"].ToString())));
                    classes.Add(c);
                }
                return(classes);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception in DBHandler", ex);
                return(null);
            }
            finally
            {
                myConnection.Close();
            }
        }
Exemplo n.º 2
0
        public static List <YogaClass> LoadBookedClasses(string username, int wStatus)
        {//method used to load  booked clases from data base in lists
            List <YogaClass> classes      = new List <YogaClass>();
            List <YogaNames> teachers     = ListTeachers();
            OleDbConnection  myConnection = GetConnection();
            string           myQuery      = "SELECT * FROM YogaClass LEFT JOIN YogaClassReservation ON YogaClass.ClassID=YogaClassReservation.YogaClassID WHERE CClientUsername = '******' AND ClassWaitinglistStatus =" + 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()));
                    YogaClass c = new YogaClass((int.Parse(myReader["ClassID"].ToString())), DateTime.Parse(myReader["ClassStartingTime"].ToString()), myReader["ClassName"].ToString(), currentTeacher, (int.Parse(myReader["ClassLevel"].ToString())), (myReader["ClassDuration"].ToString()), myReader["ClassDescription"].ToString(), (int.Parse(myReader["ClassPlacesAvailable"].ToString())));
                    classes.Add(c);
                }
                return(classes);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception in DBHandler", ex);
                return(null);
            }
            finally
            {
                myConnection.Close();
            }
        }