private void addCourse_MouseUp(object sender, MouseButtonEventArgs e)
        {
            CourseAddEdit course = new CourseAddEdit(this);

            course.Owner   = this;
            course.Closed += (s, eventarg) =>
            {
                filterCourse();
            };
            course.ShowDialog();
        }
        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);
            }
        }