Exemple #1
0
        public static List <Person> ExtractPersons(MySqlConnectionReader connectionReader)
        {
            MySqlDataReader reader  = connectionReader.Reader;
            List <Person>   persons = new List <Person>();

            while (reader.HasRows && reader.Read())
            {
                uint   id   = reader.GetUInt32(reader.GetOrdinal("ID"));
                string name = reader.GetString(reader.GetOrdinal("Name"));
                string type = reader.GetString(reader.GetOrdinal("Type"));
                switch (type)
                {
                case "Student":
                    persons.Add(new Student(id, name));
                    break;

                case "Teacher":
                    persons.Add(new Teacher(id, name));
                    break;

                case "Secretary":
                    persons.Add(new Secretary(id, name));
                    break;

                default:
                    throw new InvalidPersonTypeException();
                }
            }
            connectionReader.Connection.Close();
            return(persons);
        }
Exemple #2
0
        public static List <Assignment> ExtractAssignments(MySqlConnectionReader connectionReader)
        {
            MySqlDataReader   reader      = connectionReader.Reader;
            List <Assignment> assignments = new List <Assignment>();

            while (reader.HasRows && reader.Read())
            {
                uint     id = reader.GetUInt32(reader.GetOrdinal("ID"));
                uint     assignmentdescriptionID = reader.GetUInt32(reader.GetOrdinal("AssignmentDescriptionID"));
                uint     studentid = reader.GetUInt32(reader.GetOrdinal("StudentID"));
                string   comment   = reader.GetString(reader.GetOrdinal("Comment"));
                DateTime date      = reader.GetDateTime(reader.GetOrdinal("DateTime"));
                if (Commands.CheckNull("Assignment", id, "GradeID"))
                {
                    assignments.Add(new Assignment(id, assignmentdescriptionID, studentid, comment, date));
                }
                else
                {
                    uint gradeid = reader.GetUInt32(reader.GetOrdinal("GradeID"));
                    assignments.Add(new Assignment(id, assignmentdescriptionID, studentid, comment, gradeid, date));
                }
            }
            connectionReader.Connection.Close();
            return(assignments);
        }
Exemple #3
0
        public static List <string> ExtractFilepaths(MySqlConnectionReader connectionReader)
        {
            MySqlDataReader reader    = connectionReader.Reader;
            List <string>   filepaths = new List <string>();

            while (reader.HasRows && reader.Read())
            {
                filepaths.Add(reader.GetString(reader.GetOrdinal("Filepath")));
            }
            connectionReader.Connection.Close();
            return(filepaths);
        }
Exemple #4
0
        public static uint[] ExtractIDs(MySqlConnectionReader connectionReader, string field)
        {
            MySqlDataReader reader = connectionReader.Reader;
            List <uint>     ids    = new List <uint>();

            while (reader.HasRows && reader.Read())
            {
                ids.Add(reader.GetUInt32(reader.GetOrdinal(field)));
            }
            connectionReader.Connection.Close();
            return(ids.ToArray());
        }
Exemple #5
0
        public void ExecuteNonReader()
        {
            MySqlConnectionReader connectionReader = new MySqlConnectionReader(new MySqlConnection(ConnectionString));

            using (MySqlCommand command = connectionReader.Connection.CreateCommand())
            {
                connectionReader.Connection.Open();
                command.CommandText = QueryString;
                command.ExecuteNonQuery();
                connectionReader.Connection.Close();
            }
        }
Exemple #6
0
        public MySqlConnectionReader Execute()
        {
            MySqlConnectionReader connectionReader = new MySqlConnectionReader(new MySqlConnection(ConnectionString));

            using (MySqlCommand command = connectionReader.Connection.CreateCommand())
            {
                connectionReader.Connection.Open();
                command.CommandText     = QueryString;
                connectionReader.Reader = command.ExecuteReader();
            }
            return(connectionReader);
        }
Exemple #7
0
        public static List <Room> ExtractRooms(MySqlConnectionReader connectionReader)
        {
            MySqlDataReader reader = connectionReader.Reader;
            List <Room>     rooms  = new List <Room>();

            while (reader.HasRows && reader.Read())
            {
                uint   id   = reader.GetUInt32(reader.GetOrdinal("ID"));
                string name = reader.GetString(reader.GetOrdinal("Name"));
                rooms.Add(new Room(id, name));
            }
            connectionReader.Connection.Close();
            return(rooms);
        }
Exemple #8
0
        public static List <Course> ExtractCourses(MySqlConnectionReader connectionReader)
        {
            MySqlDataReader reader  = connectionReader.Reader;
            List <Course>   courses = new List <Course>();

            while (reader.HasRows && reader.Read())
            {
                uint   id          = reader.GetUInt32(reader.GetOrdinal("ID"));
                string name        = reader.GetString(reader.GetOrdinal("Name"));
                string description = reader.GetString(reader.GetOrdinal("Description"));
                courses.Add(new Course(id, name, description));
            }
            connectionReader.Connection.Close();
            return(courses);
        }
Exemple #9
0
        public static bool CheckNull(string tableName, uint id, string variable)
        {
            Common.EnsureNotNull(tableName, variable);
            Query query = new Query("SELECT * FROM " + tableName + " WHERE ID='" + id + "';");
            MySqlConnectionReader connectionReader = query.Execute();
            MySqlDataReader       reader           = connectionReader.Reader;

            if (reader.HasRows && reader.Read())
            {
                bool isNull = reader.IsDBNull(reader.GetOrdinal(variable));
                connectionReader.Connection.Close();
                return(isNull);
            }
            connectionReader.Connection.Close();
            throw new InvalidIDException();
        }
Exemple #10
0
        public static List <AssignmentGrade> ExtractAssignmentGrades(MySqlConnectionReader connectionReader)
        {
            MySqlDataReader        reader           = connectionReader.Reader;
            List <AssignmentGrade> assignmentgrades = new List <AssignmentGrade>();

            while (reader.HasRows && reader.Read())
            {
                uint   id           = reader.GetUInt32(reader.GetOrdinal("ID"));
                uint   assignmentID = reader.GetUInt32(reader.GetOrdinal("AssignmentID"));
                string grade        = reader.GetString(reader.GetOrdinal("Grade"));
                string comment      = reader.GetString(reader.GetOrdinal("Comment"));
                assignmentgrades.Add(new AssignmentGrade(id, assignmentID, grade, comment));
            }
            connectionReader.Connection.Close();
            return(assignmentgrades);
        }
Exemple #11
0
        public static List <News> ExtractNews(MySqlConnectionReader connectionReader)
        {
            MySqlDataReader reader = connectionReader.Reader;
            List <News>     news   = new List <News>();

            while (reader.HasRows && reader.Read())
            {
                uint     id       = reader.GetUInt32(reader.GetOrdinal("ID"));
                uint     authorID = reader.GetUInt32(reader.GetOrdinal("AuthorID"));
                string   title    = reader.GetString(reader.GetOrdinal("Title"));
                string   text     = reader.GetString(reader.GetOrdinal("Text"));
                DateTime dateTime = reader.GetDateTime(reader.GetOrdinal("DateTime"));
                news.Add(new News(id, authorID, title, text, dateTime));
            }
            connectionReader.Connection.Close();
            return(news);
        }
Exemple #12
0
        public static List <AssignmentDescription> ExtractAssignmentDescriptions(MySqlConnectionReader connectionReader)
        {
            MySqlDataReader reader = connectionReader.Reader;
            List <AssignmentDescription> assignmentdescriptions = new List <AssignmentDescription>();

            while (reader.HasRows && reader.Read())
            {
                uint     id          = reader.GetUInt32(reader.GetOrdinal("ID"));
                uint     courseID    = reader.GetUInt32(reader.GetOrdinal("CourseID"));
                string   description = reader.GetString(reader.GetOrdinal("Description"));
                bool     cancelled   = reader.GetBoolean(reader.GetOrdinal("Cancelled"));
                DateTime deadline    = reader.GetDateTime(reader.GetOrdinal("Deadline"));
                assignmentdescriptions.Add(new AssignmentDescription(id, courseID, description, cancelled, deadline));
            }
            connectionReader.Connection.Close();
            return(assignmentdescriptions);
        }
Exemple #13
0
        public static List <Message> ExtractMessages(MySqlConnectionReader connectionReader)
        {
            MySqlDataReader reader   = connectionReader.Reader;
            List <Message>  messages = new List <Message>();

            while (reader.HasRows && reader.Read())
            {
                uint     id       = reader.GetUInt32(reader.GetOrdinal("ID"));
                uint     senderID = reader.GetUInt32(reader.GetOrdinal("SenderID"));
                string   title    = reader.GetString(reader.GetOrdinal("Title"));
                string   text     = reader.GetString(reader.GetOrdinal("Text"));
                DateTime dateTime = reader.GetDateTime(reader.GetOrdinal("DateTime"));
                messages.Add(new Message(id, senderID, title, text, dateTime));
            }
            connectionReader.Connection.Close();
            return(messages);
        }
Exemple #14
0
        public static List <CourseGrade> ExtractCourseGrades(MySqlConnectionReader connectionReader)
        {
            MySqlDataReader    reader       = connectionReader.Reader;
            List <CourseGrade> coursegrades = new List <CourseGrade>();

            while (reader.HasRows && reader.Read())
            {
                uint   id        = reader.GetUInt32(reader.GetOrdinal("ID"));
                uint   courseID  = reader.GetUInt32(reader.GetOrdinal("CourseID"));
                uint   studentID = reader.GetUInt32(reader.GetOrdinal("StudentID"));
                string grade     = reader.GetString(reader.GetOrdinal("Grade"));
                string comment   = reader.GetString(reader.GetOrdinal("Comment"));
                coursegrades.Add(new CourseGrade(id, courseID, studentID, grade, comment));
            }
            connectionReader.Connection.Close();
            return(coursegrades);
        }
Exemple #15
0
        public static List <Lesson> ExtractLessons(MySqlConnectionReader connectionReader)
        {
            MySqlDataReader reader  = connectionReader.Reader;
            List <Lesson>   lessons = new List <Lesson>();

            while (reader.HasRows && reader.Read())
            {
                uint     id          = reader.GetUInt32(reader.GetOrdinal("ID"));
                uint     courseID    = reader.GetUInt32("CourseID");
                string   description = reader.GetString(reader.GetOrdinal("Description"));
                bool     online      = reader.GetBoolean(reader.GetOrdinal("Online"));
                bool     cancelled   = reader.GetBoolean(reader.GetOrdinal("Cancelled"));
                DateTime dateTime    = reader.GetDateTime(reader.GetOrdinal("DateTime"));
                lessons.Add(new Lesson(id, courseID, description, online, cancelled, dateTime));
            }
            connectionReader.Connection.Close();
            return(lessons);
        }
Exemple #16
0
 public static List <Secretary> ExtractSecretaries(MySqlConnectionReader connectionReader) =>
 ExtractPersons(connectionReader).Cast <Secretary>().ToList();
Exemple #17
0
 public static List <Teacher> ExtractTeachers(MySqlConnectionReader connectionReader) =>
 ExtractPersons(connectionReader).Cast <Teacher>().ToList();
Exemple #18
0
 public static List <Student> ExtractStudents(MySqlConnectionReader connectionReader) =>
 ExtractPersons(connectionReader).Cast <Student>().ToList();