Exemplo n.º 1
0
        private void GenerateRooms(XmlWriter writer)
        {
            DataTable data = DBConnection.Select("rooms", " id ");

            ArrayList roomIds = new ArrayList();

            foreach (DataRow row in data.Rows)
            {
                roomIds.Add(row.ItemArray[0]);
            }

            Dictionary <string, string> first = new Dictionary <string, string>();
            string roomCode, buildingId, size;

            foreach (int rId in roomIds)
            {
                ArrayList rec = DBConnection.Get("rooms", rId);
                first = (Dictionary <string, string>)rec[0];
                first.TryGetValue("code", out roomCode);
                first.TryGetValue("building_id", out buildingId);
                first.TryGetValue("size", out size);

                //for every room in rooms table
                writer.WriteStartElement("room");
                writer.WriteAttributeString("id", roomCode);
                writer.WriteAttributeString("size", size);
                writer.WriteAttributeString("building", (Convert.ToInt32(buildingId) - 1).ToString());
                writer.WriteEndElement();
            }
        }
Exemplo n.º 2
0
        private void GeneralInfo(XmlWriter writer)
        {
            Dictionary <string, string> first = new Dictionary <string, string>();

            ArrayList data = DBConnection.Get("general_info", 1);

            first = (Dictionary <string, string>)data[0];

            string nrOfDays, periodsPerDay, minNrOfLectures, maxNrOfLectures;

            first.TryGetValue("number_of_days", out nrOfDays);
            first.TryGetValue("periods_per_day", out periodsPerDay);
            first.TryGetValue("min_daily_lectures", out minNrOfLectures);
            first.TryGetValue("max_daily_lectures", out maxNrOfLectures);

            writer.WriteStartElement("days");
            writer.WriteAttributeString("value", nrOfDays);
            writer.WriteEndElement();
            writer.WriteStartElement("periods_per_day");
            writer.WriteAttributeString("value", periodsPerDay);
            writer.WriteEndElement();
            writer.WriteStartElement("daily_lectures");
            writer.WriteAttributeString("min", minNrOfLectures);
            writer.WriteAttributeString("max", maxNrOfLectures);
            writer.WriteEndElement();
        }
Exemplo n.º 3
0
        private int getSemesterModule()
        {
            Dictionary <string, string> first = new Dictionary <string, string>();
            ArrayList data = DBConnection.Get("currentSemester", 1);

            first = (Dictionary <string, string>)data[0];

            string index;

            first.TryGetValue("module", out index);

            return(Convert.ToInt32(index));
        }
Exemplo n.º 4
0
        private string getCurrentSemester()
        {
            Dictionary <string, string> first = new Dictionary <string, string>();
            ArrayList data = DBConnection.Get("currentSemester", 1);

            first = (Dictionary <string, string>)data[0];

            string name;

            first.TryGetValue("name", out name);

            return(name.ToLower());
        }
Exemplo n.º 5
0
        private int getEndingPeriod()
        {
            Dictionary <string, string> first = new Dictionary <string, string>();
            string    detail, numberOfLectures;
            ArrayList rec = DBConnection.Get("courses", Course_id);

            first = (Dictionary <string, string>)rec[0];
            first.TryGetValue("detail", out detail);
            first.TryGetValue("number_of_lectures", out numberOfLectures);

            var lectures = numberOfLectures.Split('+');

            switch (detail)
            {
            case "lecture":
                numberOfLectures = lectures[0];
                break;

            case "numeric":
                numberOfLectures = lectures[1];
                break;

            case "laboratory":
                numberOfLectures = lectures[2];
                break;

            default:
                numberOfLectures = "";
                break;
            }

            int breaks = 0;

            switch (int.Parse(numberOfLectures) % 2)
            {
            case 0:
                breaks = (int.Parse(numberOfLectures) - 2) / 2;
                break;

            case 1:
                breaks = (int.Parse(numberOfLectures) - 1) / 2;
                break;
            }

            int lecturePeriods = 3 * int.Parse(numberOfLectures);
            int endPeriod = Starting_period + (3 * int.Parse(numberOfLectures)) + breaks;

            return(endPeriod);
        }
Exemplo n.º 6
0
        private string getCurrentPeriod(UControl position, int courseId)
        {
            string returnText = "";

            Dictionary <string, string> first = new Dictionary <string, string>();
            string    name;
            ArrayList rec = DBConnection.Get("subPeriods", int.Parse(position.Row));

            first = (Dictionary <string, string>)rec[0];
            first.TryGetValue("name", out name);

            returnText = name + " to " + TimetablingResultDisplay.getEndingPeriod(name, courseId);

            return(returnText);
        }
Exemplo n.º 7
0
        private void GeneratePeriodConstraints(XmlWriter writer)
        {
            DataTable courseData = DBConnection.Select("course_periods_preferences cp JOIN courses c ON cp.course_id = c.id ", " Distinct cp.course_id ", " (c.semester_id % 2) =" + semesterModule + " AND c.parent_id IS NOT NULL ");

            ArrayList courseIds = new ArrayList();

            foreach (DataRow row in courseData.Rows)
            {
                courseIds.Add(row.ItemArray[0]);
            }

            foreach (int cId in courseIds)
            {
                Dictionary <string, string> course = (Dictionary <string, string>)DBConnection.Get("courses", cId)[0];
                string courseCode;
                course.TryGetValue("code", out courseCode);
                writer.WriteStartElement("constraint");
                writer.WriteAttributeString("type", "period");
                writer.WriteAttributeString("course", courseCode);


                DataTable data = DBConnection.Select("course_periods_preferences", " id ", " course_id= " + cId);

                ArrayList recIds = new ArrayList();
                foreach (DataRow row in data.Rows)
                {
                    recIds.Add(row.ItemArray[0]);
                }

                Dictionary <string, string> first = new Dictionary <string, string>();
                string timeslotDay, timeslotPeriod;
                foreach (int pId in recIds)
                {
                    ArrayList preferenceRec = DBConnection.Get("course_periods_preferences", pId);

                    first = (Dictionary <string, string>)preferenceRec[0];
                    first.TryGetValue("day", out timeslotDay);
                    first.TryGetValue("period", out timeslotPeriod);

                    //for every preference in rooms table
                    writer.WriteStartElement("timeslot");
                    writer.WriteAttributeString("day", (Convert.ToInt32(timeslotDay) - 1).ToString());
                    writer.WriteAttributeString("period", (Convert.ToInt32(timeslotPeriod) - 1).ToString());
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();//period constraint
            }
        }
Exemplo n.º 8
0
        public string getCourseTextPeriod()
        {
            string name1, name2;
            Dictionary <string, string> startPeriod = new Dictionary <string, string>();
            ArrayList startSubPeriod = DBConnection.Get("subPeriods", Starting_period + 1);

            startPeriod = (Dictionary <string, string>)startSubPeriod[0];
            startPeriod.TryGetValue("name", out name1);

            Dictionary <string, string> endPeriod = new Dictionary <string, string>();
            ArrayList endSubPeriod = DBConnection.Get("subPeriods", Ending_period + 1);

            endPeriod = (Dictionary <string, string>)endSubPeriod[0];
            endPeriod.TryGetValue("name", out name2);

            return(name1 + " to " + name2);
        }
Exemplo n.º 9
0
        private void GenerateRoomConstraints(XmlWriter writer)
        {
            DataTable courseData = DBConnection.Select("courses_rooms_rel crr JOIN courses c ON crr.course_id = c.id ", " Distinct crr.course_id ", " (c.semester_id % 2) =" + semesterModule + " AND c.parent_id IS NOT NULL");

            ArrayList courseIds = new ArrayList();

            foreach (DataRow row in courseData.Rows)
            {
                courseIds.Add(row.ItemArray[0]);
            }

            foreach (int cId in courseIds)
            {
                Dictionary <string, string> course = (Dictionary <string, string>)DBConnection.Get("courses", cId)[0];
                string courseCode;
                course.TryGetValue("code", out courseCode);
                writer.WriteStartElement("constraint");
                writer.WriteAttributeString("type", "room");
                writer.WriteAttributeString("course", courseCode);


                DataTable data = DBConnection.Select("courses_rooms_rel", " room_id ", " course_id= " + cId);

                ArrayList recIds = new ArrayList();
                foreach (DataRow row in data.Rows)
                {
                    recIds.Add(row.ItemArray[0]);
                }

                Dictionary <string, string> first = new Dictionary <string, string>();
                string roomRef;
                foreach (int rId in recIds)
                {
                    ArrayList roomRec = DBConnection.Get("rooms", rId);

                    first = (Dictionary <string, string>)roomRec[0];
                    first.TryGetValue("code", out roomRef);

                    //for every room in courses_rooms_rel table
                    writer.WriteStartElement("room");
                    writer.WriteAttributeString("ref", roomRef);
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
            }
        }
Exemplo n.º 10
0
        private bool SlotRoomConstraint(UControl child, List <Assignment> assignments, ref string msg)
        {
            bool RoomContraintViolated = true;

            int roomId = int.Parse(comboBoxRooms.SelectedValue.ToString());
            Dictionary <string, string> first = new Dictionary <string, string>();

            ArrayList data = DBConnection.Get("rooms", roomId);

            first = (Dictionary <string, string>)data[0];

            string code;

            first.TryGetValue("code", out code);

            int row    = int.Parse(child.Row) - 1;
            int column = int.Parse(child.Column) - 1;

            //check if room is busy on that slot
            List <Assignment> allBusyPeriods = assignments.FindAll(x => x.Room_code == code).ToList();

            if (allBusyPeriods == null)
            {
                RoomContraintViolated = false;
            }
            else
            {
                var checkGivenPeriod = allBusyPeriods.Find(x => x.Day == column && x.Starting_period <= row && x.Ending_period > row);
                if (checkGivenPeriod == null)
                {
                    RoomContraintViolated = false;
                }
                else
                {
                    msg += ((msg == "") ? "" : ", ") + " Room is busy\n (Class " + checkGivenPeriod.Course_name.Replace("_", ", ") +
                           " \nfrom " + checkGivenPeriod.getCourseTextPeriod() + ")";
                    RoomContraintViolated = true;
                }
            }

            return(RoomContraintViolated);
        }
Exemplo n.º 11
0
        private int checkRoomCapacity()
        {
            int penalty = 0;
            int roomId  = int.Parse(comboBoxRooms.SelectedValue.ToString());
            Dictionary <string, string> first = new Dictionary <string, string>();

            ArrayList data = DBConnection.Get("rooms", roomId);

            first = (Dictionary <string, string>)data[0];

            string size;

            first.TryGetValue("size", out size);

            int difference = int.Parse(txtNumberofStudents.Text) - int.Parse(size);

            if (difference > 0)
            {
                penalty = difference;
            }
            return(penalty);
        }
Exemplo n.º 12
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Dictionary <string, string> first = new Dictionary <string, string>();

            ArrayList data = DBConnection.Get("general_info", 1);

            first = (Dictionary <string, string>)data[0];

            string nrOfDays, periodsPerDay, minNrOfLectures, maxNrOfLectures, editor;

            first.TryGetValue("number_of_days", out nrOfDays);
            first.TryGetValue("periods_per_day", out periodsPerDay);
            first.TryGetValue("min_daily_lectures", out minNrOfLectures);
            first.TryGetValue("max_daily_lectures", out maxNrOfLectures);
            first.TryGetValue("editor", out editor);

            comboBoxNrDays.SelectedValue         = int.Parse(nrOfDays);
            cmbPeriodsperDay.SelectedValue       = int.Parse(periodsPerDay);
            cmbMinNrLecturesperDay.SelectedValue = int.Parse(minNrOfLectures);
            cmbMaxNrLecturesperDay.SelectedValue = int.Parse(maxNrOfLectures);
            txtEditor.Text = editor;
        }
Exemplo n.º 13
0
        public void addRowColumnDefinitions()
        {
            Dictionary <string, string> first = new Dictionary <string, string>();

            ArrayList data = DBConnection.Get("general_info", 1);

            first = (Dictionary <string, string>)data[0];

            string nrOfDays, periodsPerDay;

            first.TryGetValue("number_of_days", out nrOfDays);
            first.TryGetValue("periods_per_day", out periodsPerDay);

            for (int i = 0; i < Convert.ToInt32(nrOfDays); i++)
            {
                GridMain.ColumnDefinitions.Add(new ColumnDefinition());
            }

            for (int j = 0; j < Convert.ToInt32(periodsPerDay); j++)
            {
                GridMain.RowDefinitions.Add(new RowDefinition());
            }
        }
Exemplo n.º 14
0
        public void initInfo(object[] row)
        {
            txtClassId.Text     = row[0].ToString();
            txtClass.Text       = row[1].ToString();
            txtTeacherId.Text   = row[3].ToString();
            txtTeacher.Text     = row[4].ToString();
            txbDepartments.Text = row[8].ToString();
            if (row[5].ToString() != "-" && row[6].ToString() != "-" && row[7].ToString() != "-")
            {
                txbInfo.Text = row[5].ToString().Replace(" ", "") + " " + row[7].ToString() + ", " + row[6].ToString();
            }
            else
            {
                txbInfo.Visibility   = Visibility.Hidden;
                labelInfo.Visibility = Visibility.Hidden;
            }

            Dictionary <string, string> first = new Dictionary <string, string>();

            ArrayList data = DBConnection.Get("courses", int.Parse(row[0].ToString()));

            first = (Dictionary <string, string>)data[0];

            string nrOfStudents, nrOfLectures, detail, code, departmentIds = "", departments = "", semester, lectureGroup = "", numericGroup = "", laboratoryGroup = "";

            first.TryGetValue("number_of_students", out nrOfStudents);
            first.TryGetValue("number_of_lectures", out nrOfLectures);
            first.TryGetValue("detail", out detail);
            first.TryGetValue("code", out code);
            first.TryGetValue("semester_id", out semester);
            first.TryGetValue("lecture_group", out lectureGroup);
            first.TryGetValue("numeric_group", out numericGroup);
            first.TryGetValue("laboratory_group", out laboratoryGroup);

            txtCode.Text             = code;
            txtSemester.Text         = semester;
            txtLectureGroup.Text     = lectureGroup;
            txtNumericGroup.Text     = numericGroup;
            txtLaboratoryGroup.Text  = laboratoryGroup;
            txtNumberofStudents.Text = nrOfStudents;
            txtDetail.Text           = detail;
            var std = nrOfLectures.Split('+');

            txtNumberofLectures.Text = detail == "lecture" ? std[0].ToString() : (detail == "numeric" ? std[1].ToString() : std[2].ToString());

            string Columns = " DISTINCT(d.id) AS departmentId, d.name AS departmentName";
            string From    = " departments d" +
                             " JOIN course_department_rel cd ON d.id=cd.department_id ";
            string Conditions = " cd.course_id =" + Int32.Parse(row[0].ToString());

            DataTable res = DBConnection.Select(From, Columns, Conditions);


            ArrayList result = new ArrayList();

            foreach (DataRow r in res.Rows)
            {
                departments   += r.ItemArray[1].ToString() + "\n";
                departmentIds += departmentIds != "" ? (", " + r.ItemArray[0].ToString()) : r.ItemArray[0].ToString();
            }

            txbDepartments.Text   = departments;
            txtDepartmentIds.Text = departmentIds;
        }
Exemplo n.º 15
0
        private int GetWindowViolation(UControl child, List <Assignment> assignments, ref string message)
        {
            //Each time window in a curriculum counts as many violation as its length (in periods).
            int window = 0;

            int row    = int.Parse(child.Row) - 1;
            int column = int.Parse(child.Column) - 1;

            int breaks = 0;

            switch (int.Parse(txtNumberofLectures.Text) % 2)
            {
            case 0:
                breaks = (int.Parse(txtNumberofLectures.Text) - 2) / 2;
                break;

            case 1:
                breaks = (int.Parse(txtNumberofLectures.Text) - 1) / 2;
                break;
            }

            int lecturePeriods = 3 * int.Parse(txtNumberofLectures.Text);
            int endPeriod      = int.Parse(child.Row) + (3 * int.Parse(txtNumberofLectures.Text)) + breaks - 1;

            string columns = " c.id, c.code ";
            string from    = "courses c" +
                             " LEFT JOIN course_department_rel cdr ON c.id = cdr.course_id ";
            string conditions = "";

            switch (txtDetail.Text)
            {
            case "lecture":
                conditions = "c.parent_id IS NOT null AND c.semester_id=" + int.Parse(txtSemester.Text) + " AND cdr.department_id IN (" + txtDepartmentIds.Text + ") AND c.lecture_group='" + txtLectureGroup.Text + "' ";
                break;

            case "numeric":
                conditions = "c.parent_id IS NOT null AND c.semester_id=" + int.Parse(txtSemester.Text) + " AND cdr.department_id IN (" + txtDepartmentIds.Text + ") AND c.lecture_group='" + txtLectureGroup.Text +
                             "' AND c.id IN (SELECT c1.id FROM courses c1 WHERE (c1.numeric_group='" + txtNumericGroup.Text +
                             "' OR c1.numeric_group IS NULL) AND c1.lecture_group = c.lecture_group) ";
                break;

            case "laboratory":
                conditions = "c.parent_id IS NOT null AND c.semester_id=" + int.Parse(txtSemester.Text) + " AND cdr.department_id IN (" + txtDepartmentIds.Text + ") AND c.lecture_group='" + txtLectureGroup.Text +
                             "' AND c.id IN (SELECT c1.id FROM courses c1 WHERE (c1.laboratory_group='" + txtLaboratoryGroup.Text + "' OR c1.laboratory_group IS NULL) AND(c1.numeric_group='" + txtNumericGroup.Text +
                             "' OR c1.numeric_group IS NULL) AND c1.lecture_group = c.lecture_group) ";
                break;
            }

            DataTable         curricula    = DBConnection.Select(from, columns, conditions);
            List <Assignment> beforeAssign = new List <Assignment>();
            List <Assignment> afterAssign  = new List <Assignment>();

            if (curricula != null && curricula.Rows.Count > 0)
            {
                foreach (DataRow c in curricula.Rows)
                {
                    //check if students are busy on that slot
                    var before = assignments.FindAll(x => x.Course_code == c.ItemArray[1].ToString() && x.Day == column && x.Ending_period < int.Parse(child.Row)).FirstOrDefault();
                    if (before != null)
                    {
                        beforeAssign.Add(before);
                    }

                    var after = assignments.FindAll(x => x.Course_code == c.ItemArray[1].ToString() && x.Day == column && x.Starting_period > row).FirstOrDefault();
                    if (after != null)
                    {
                        afterAssign.Add(after);
                    }
                }
                Assignment beforeAssign1;
                if (beforeAssign.Count > 0)
                {
                    beforeAssign1 = beforeAssign.OrderByDescending(x => x.Ending_period).FirstOrDefault();
                    window       += (row - beforeAssign1.Ending_period);
                }

                Assignment afterAssign1;
                if (afterAssign.Count > 0)
                {
                    afterAssign1 = afterAssign.OrderBy(x => x.Starting_period).FirstOrDefault();

                    int difference = (afterAssign1.Starting_period - endPeriod);
                    if (difference < 0) //for same period result = 0
                    {
                        window += 100;
                    }
                    else
                    {
                        window += difference;
                    }
                }
                else
                {
                    UControl        otherAfterItem = childs.FindAll(x => x.Column == child.Column && int.Parse(x.Row) > row && x.ControlAssigned == "true").OrderBy(x => int.Parse(x.Row)).FirstOrDefault();
                    List <UControl> dayItems       = childs.FindAll(x => x.Column == child.Column);
                    int             assignedDiff   = 0;
                    if (otherAfterItem != null)
                    {
                        assignedDiff = (int.Parse(otherAfterItem.Row) - (endPeriod + 1));
                    }

                    int difference = (dayItems.Count - endPeriod);
                    if ((difference < 0) || assignedDiff < 0)
                    {
                        window += 100;
                    }
                }

                // Calculate room busy periods
                if (comboBoxRooms.SelectedIndex >= 0)
                {
                    Dictionary <string, string> first = new Dictionary <string, string>();

                    ArrayList data = DBConnection.Get("rooms", int.Parse(comboBoxRooms.SelectedValue.ToString()));
                    first = (Dictionary <string, string>)data[0];

                    string roomCode;
                    first.TryGetValue("code", out roomCode);
                    List <Assignment> roomAssign = assignments.FindAll(x => x.Room_code == roomCode && x.Day == column && (x.Starting_period <endPeriod && x.Starting_period> row));
                    if (roomAssign.Count > 0)
                    {
                        window += 100;
                    }
                }

                // Calculate teacher busy periods
                if (txtTeacherId.Text != "" && txtTeacherId.Text != null)
                {
                    List <Assignment> teacherAssign = assignments.FindAll(x => x.Teacher_id == int.Parse(txtTeacherId.Text) && x.Day == column && (x.Starting_period <endPeriod && x.Starting_period> row));
                    if (teacherAssign.Count > 0)
                    {
                        window += 100;
                    }
                }
            }
            if (window > 0 && window < 100)
            {
                int      minutes = window * 15;
                TimeSpan ts      = TimeSpan.FromMinutes(minutes);
                var      res     = (((int)ts.TotalHours > 0) ? ((int)ts.TotalHours + "h ") : "") + ((ts.Minutes > 0) ? (ts.Minutes + "mins") : "");
                message += ", \nbut students will wait for " + res;
            }
            else if (window >= 100)
            {
                message = " \n(Class " + txtClass.Text.Replace("_", ", ") + " \nfrom " + getCurrentPeriod(child, int.Parse(txtClassId.Text)) + ")";
            }
            return(window);
        }
Exemplo n.º 16
0
        private void GenerateCourses(XmlWriter writer)
        {
            DataTable data = DBConnection.Select(" courses ", " id ", " parent_id IS NOT NULL AND (semester_id % 2) = " + semesterModule);

            ArrayList baseCourseGroupIds = new ArrayList();

            foreach (DataRow lectureRow in data.Rows)
            {
                baseCourseGroupIds.Add(lectureRow.ItemArray[0]);
            }

            Dictionary <string, string> first = new Dictionary <string, string>();
            string courseCode, teacher = "", numberOfLectures, detail, minDays, students, doubleLectures;

            foreach (int cId in baseCourseGroupIds)
            {
                ArrayList rec = DBConnection.Get("courses", cId);
                first = (Dictionary <string, string>)rec[0];
                first.TryGetValue("code", out courseCode);
                first.TryGetValue("number_of_lectures", out numberOfLectures);
                first.TryGetValue("min_days", out minDays);
                first.TryGetValue("number_of_students", out students);
                first.TryGetValue("double_lectures", out doubleLectures);
                first.TryGetValue("detail", out detail);

                string table = " course_teacher_rel ctr" +
                               " JOIN teachers t ON ctr.teacher_id=t.id ";
                DataTable teacherRec = DBConnection.Select(table, " t.code AS teacher_code", " ctr.course_id=" + cId);
                foreach (DataRow teacherRow in teacherRec.Rows)
                {
                    teacher = teacherRow.ItemArray[0].ToString();
                }

                var lectures = numberOfLectures.Split('+');
                switch (detail)
                {
                case "lecture":
                    numberOfLectures = lectures[0];
                    break;

                case "numeric":
                    numberOfLectures = lectures[1];
                    break;

                case "laboratory":
                    numberOfLectures = lectures[2];
                    break;

                default:
                    numberOfLectures = "";
                    break;
                }

                //for every course in courses table
                writer.WriteStartElement("course");
                writer.WriteAttributeString("id", courseCode);
                writer.WriteAttributeString("teacher", teacher);
                writer.WriteAttributeString("lectures", numberOfLectures);
                writer.WriteAttributeString("min_days", minDays);
                writer.WriteAttributeString("students", students);
                writer.WriteAttributeString("double_lectures", doubleLectures);
                writer.WriteEndElement();
            }
        }
Exemplo n.º 17
0
        private void editCourse_MouseUp(object sender, MouseButtonEventArgs e)
        {
            DataRowView row = (DataRowView)coursesGrid.SelectedItem;

            if (row != null)
            {
                int id         = (int)row["ID"];
                var courseData = DBConnection.Get("courses", id);
                var item       = (Dictionary <string, string>)courseData[0];

                string parent;
                item.TryGetValue("parent_id", out parent);
                if (parent != "")
                {
                    MessageBox.Show("Only main course can be edited!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }

                string   name     = (string)row["Name"];
                string   code     = (string)row["Code"];
                string   ects     = row["Ects"].ToString();
                string   semester = row["Semester"].ToString();
                string   type; item.TryGetValue("type", out type);
                string[] number_of_lectures  = ((string)row["Lectures"]).Split('+');
                string   nr_lectures         = number_of_lectures.Length >= 0 ? number_of_lectures[0] : "0";
                string   numeric_lectures    = number_of_lectures.Length >= 1 ? number_of_lectures[1] : "0";
                string   laboratory_lectures = number_of_lectures.Length >= 2 ? number_of_lectures[2] : "0";
                string   min_days            = row["Min_Days"].ToString();
                string   degree; item.TryGetValue("degree", out degree);
                string   double_lectures    = row["Double_Lectures"].ToString();
                string   number_of_students = row["Students"].ToString();

                string groups = row["Groups"].ToString();

                DataTable semestersData    = DBConnection.Select("semesters", "*", " name = '" + semester + "'");
                var       selectedSemester = semestersData.Rows[0].ItemArray;

                //Get all lecture groups of the course
                DataTable lectureGroups      = DBConnection.Select("courses", "*", " parent_id = " + id + " AND detail = 'lecture'");
                ArrayList baseCourseGroupIds = new ArrayList();
                foreach (DataRow lectureRow in lectureGroups.Rows)
                {
                    //First column is ID
                    baseCourseGroupIds.Add(lectureRow.ItemArray[0]);
                }
                //Get all room added for lectures
                DataTable lectureRooms = getRooms(baseCourseGroupIds);

                //Get all numeric exercises groups of the course
                DataTable numExerciseGroups   = DBConnection.Select("courses", "*", " parent_id IN ( " + String.Join(",", baseCourseGroupIds.ToArray()) + ") AND detail = 'numeric'");
                ArrayList numExerciseGroupIds = new ArrayList();
                DataTable numericExRooms      = new DataTable();
                if (numExerciseGroups.Rows.Count != 0)
                {
                    foreach (DataRow numExerciseRow in numExerciseGroups.Rows)
                    {
                        //First column is ID
                        numExerciseGroupIds.Add(numExerciseRow.ItemArray[0]);
                    }
                    //Get all room added for numeric exercises
                    numericExRooms = getRooms(numExerciseGroupIds);
                }
                //Get all laboratory exercises groups of the course
                DataTable labExerciseGroups = DBConnection.Select("courses", "*", " parent_id IN ( " +
                                                                  String.Join(",", (numExerciseGroupIds.Count > 0) ? numExerciseGroupIds.ToArray() : baseCourseGroupIds.ToArray()) + ") AND detail = 'laboratory'");
                ArrayList labExerciseGroupIds = new ArrayList();
                DataTable laboratoryExRooms   = new DataTable();
                if (labExerciseGroups.Rows.Count != 0)
                {
                    foreach (DataRow labExerciseRow in labExerciseGroups.Rows)
                    {
                        //First column is ID
                        labExerciseGroupIds.Add(labExerciseRow.ItemArray[0]);
                    }
                    //Get all room added for laboratory exercises
                    laboratoryExRooms = getRooms(labExerciseGroupIds);
                }
                ArrayList allCourseIds = new ArrayList();
                allCourseIds.AddRange(baseCourseGroupIds);
                allCourseIds.AddRange(numExerciseGroupIds);
                allCourseIds.AddRange(labExerciseGroupIds);

                ArrayList teachersDetails = getTeachers(allCourseIds);
                ArrayList departments     = getDepartments(allCourseIds);

                CourseAddEdit course = new CourseAddEdit(this);
                course.Owner   = this;
                course.Closed += (s, eventarg) =>
                {
                    filterCourse();
                };
                course.txtId.Text   = id.ToString();
                course.txtName.Text = name;
                course.comboBoxMinDays.SelectedValue = min_days;
                course.comboBoxEcts.SelectedValue    = ects;
                course.txtCode.Text = code;
                course.comboBoxNrLectures.SelectedValue         = nr_lectures;
                course.comboBoxNrNumExercLectures.SelectedValue = numeric_lectures;
                course.comboBoxNrLabExercLectures.SelectedValue = laboratory_lectures;
                course.txtNrStudents.Text                       = number_of_students;
                course.comboBoxGroups.SelectedValue             = groups;
                course.comboBoxSemester.SelectedValue           = selectedSemester[0];
                course.comboBoxType.SelectedValue               = type.Trim();
                course.comboBoxDegree.SelectedValue             = degree.Trim();
                course.comboBoxNrExerciseGroups.SelectedValue   = numExerciseGroupIds.Count.ToString();
                course.comboBoxLabExercisesGroups.SelectedValue = labExerciseGroupIds.Count.ToString();
                course.comboBoxDoubleLectures.SelectedValue     = (double_lectures == "True" || double_lectures == "1") ? 1 : 0;
                foreach (DataRow l in lectureRooms.Rows)
                {
                    course.courseRoomRelationLecturesGrid.Items.Add(new CourseRooms()
                    {
                        RoomID = Int32.Parse(l.ItemArray[0].ToString()), RoomName = l.ItemArray[1].ToString()
                    });
                }

                if (numericExRooms != null)
                {
                    foreach (DataRow n in numericExRooms.Rows)
                    {
                        course.courseRoomRelationNumExGrid.Items.Add(new CourseRooms()
                        {
                            RoomID = Int32.Parse(n.ItemArray[0].ToString()), RoomName = n.ItemArray[1].ToString()
                        });
                    }
                }
                if (laboratoryExRooms != null)
                {
                    foreach (DataRow la in laboratoryExRooms.Rows)
                    {
                        course.courseRoomRelationLabExGrid.Items.Add(new CourseRooms()
                        {
                            RoomID = Int32.Parse(la.ItemArray[0].ToString()), RoomName = la.ItemArray[1].ToString()
                        });
                    }
                }
                foreach (CourseTeachers t in teachersDetails)
                {
                    course.courseTeacherRelationGrid.Items.Add(t);
                }

                foreach (ComboDepartments d in departments)
                {
                    course.courseDepartmentsGrid.Items.Add(d);
                }
                course.ShowDialog();
            }
            else
            {
                MessageBox.Show("Please select a row to edit!", "Warinig", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }