private void deleteCourseTeacherRel_MouseUp(object sender, MouseButtonEventArgs e)
        {
            DataRowView row = (DataRowView)courseteacherGrid.SelectedItem;

            if (row != null)
            {
                MessageBoxResult messageBoxResult = MessageBox.Show("Are you sure to delete?", "Delete Confirmation", System.Windows.MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (messageBoxResult == MessageBoxResult.Yes)
                {
                    int teacher_id = (int)row["Teacher_ID"],
                        course_id  = (int)row["Course_ID"];
                    int result     = DBConnection.Delete("course_teacher_rel", 0, " course_id = '" + course_id + "' AND teacher_id = '" + teacher_id + "'");
                    if (result > 0)
                    {
                        MessageBox.Show("Successfully deleted Course Teacher Relation!", "Information", MessageBoxButton.OK);
                    }

                    courseTeacherRel_Initialized(sender, e);
                }
            }
            else
            {
                MessageBox.Show("Please select a row to delete!", "Information", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
예제 #2
0
        public void insertSolutionOnSystem(string path)
        {
            //clean timetable_temp
            string currentSemester = getCurrentSemester();

            DBConnection.Delete("timetable_" + currentSemester);

            // Open document
            List <string> myValues = new List <string>();
            string        line;
            // Read the file and display it line by line.
            StreamReader file = new StreamReader("Output/" + path);

            while ((line = file.ReadLine()) != null)
            {
                myValues.Add(line);
            }

            foreach (string item in myValues)
            {
                string   row   = string.Join(" ", item.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
                string[] items = row.Split(' ');

                if ((items.Count() != 4) || !items[0].StartsWith("c") || !items[1].StartsWith("r"))
                {
                    throw new Exception("Selected file is not on the correct format!");
                }

                string values = "'" + items[0] + "', '" + items[1] + "', '" + items[2] + "', '" + items[3] + "'";

                int res = DBConnection.Create("timetable_" + currentSemester, "course_code, room_code, day, start_period", values);
            }
        }
        private void deleteCourseDepartmentRel_MouseUp(object sender, MouseButtonEventArgs e)
        {
            DataRowView row = (DataRowView)courseDepartmentRelGrid.SelectedItem;

            if (row != null)
            {
                MessageBoxResult messageBoxResult = MessageBox.Show("Are you sure to delete?", "Delete Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (messageBoxResult == MessageBoxResult.Yes)
                {
                    int department_id = (int)row["Department_ID"],
                        course_id     = (int)row["Course_ID"];
                    int result        = DBConnection.Delete("course_department_rel", 0, " course_id = '" + course_id + "' AND department_id = '" + department_id + "'");
                    if (result > 0)
                    {
                        MessageBox.Show("Successfully deleted course department assignment!", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                    }

                    courseDepartmentRel_Initialized(sender, e);
                }
            }
            else
            {
                MessageBox.Show("Please select a row to delete!", "Information", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
예제 #4
0
        public void main()
        {
            try
            {
                Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();

                // Set filter for file extension and default file extension
                dlg.DefaultExt = ".txt";
                dlg.Filter     = "TXT Files (*.txt)|*.txt";

                // Display OpenFileDialog by calling ShowDialog method
                Nullable <bool> result = dlg.ShowDialog();

                // Get the selected file name and display in a TextBox
                if (result == true)
                {
                    //clean timetable_temp
                    DBConnection.Delete("timetable_temp");

                    // Open document
                    string        filename = dlg.FileName;
                    List <string> myValues = new List <string>();
                    string        line;
                    // Read the file and display it line by line.
                    StreamReader file = new StreamReader(filename);
                    while ((line = file.ReadLine()) != null)
                    {
                        myValues.Add(line);
                    }

                    foreach (string item in myValues)
                    {
                        string   row   = string.Join(" ", item.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
                        string[] items = row.Split(' ');

                        if ((items.Count() != 4) || !items[0].StartsWith("c") || !items[1].StartsWith("r"))
                        {
                            throw new Exception("Selected file is not on the correct format!");
                        }

                        string values = "'" + items[0] + "', '" + items[1] + "', '" + items[2] + "', '" + items[3] + "'";

                        int res = DBConnection.Create("timetable_temp", "course_code, room_code, day, start_period", values);
                    }

                    TimetablingResultDisplay display = new TimetablingResultDisplay();
                    display.Show();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
        private void deleteTeacher_MouseUp(object sender, MouseButtonEventArgs e)
        {
            DataRowView row = (DataRowView)teachersGrid.SelectedItem;

            if (row != null)
            {
                MessageBoxResult messageBoxResult = MessageBox.Show("Are you sure to delete this teacher?", "Delete Confirmation", System.Windows.MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (messageBoxResult == MessageBoxResult.Yes)
                {
                    int id     = (int)row["ID"];
                    int result = DBConnection.Delete("teachers", id);
                    if (result > 0)
                    {
                        MessageBox.Show("Successfully deleted Teacher!", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                    }

                    teachers_Initialized(sender, e);
                }
            }
            else
            {
                MessageBox.Show("Please select a row to delete!", "Warning", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
        }
        private void deleteDepartment_MouseUp(object sender, MouseButtonEventArgs e)
        {
            DataRowView row = (DataRowView)departmentsGrid.SelectedItem;

            if (row != null)
            {
                MessageBoxResult messageBoxResult = MessageBox.Show("Are you sure to delete this study program?", "Delete Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (messageBoxResult == MessageBoxResult.Yes)
                {
                    int id     = (int)row["ID"];
                    int result = DBConnection.Delete("departments", id);
                    if (result > 0)
                    {
                        MessageBox.Show("Selected study program has been successfully deleted!", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                    }

                    departments_Initialized(sender, e);
                }
            }
            else
            {
                MessageBox.Show("Please select a row to delete!", "Information", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
        }
        private void deleteCoursePeriodPreference_MouseUp(object sender, MouseButtonEventArgs e)
        {
            DataRowView row = (DataRowView)courseperiodGrid.SelectedItem;

            if (row != null)
            {
                MessageBoxResult messageBoxResult = MessageBox.Show("Are you sure to delete?", "Delete Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (messageBoxResult == MessageBoxResult.Yes)
                {
                    int id     = (int)row["ID"];
                    int result = DBConnection.Delete("course_periods_preferences", id);
                    if (result > 0)
                    {
                        MessageBox.Show("Successfully deleted Course Period Preferences!", "Information", MessageBoxButton.OK);
                    }

                    coursePeriodPreferences_Initialized(sender, e);
                }
            }
            else
            {
                MessageBox.Show("Please select a row to delete!", "Information");
            }
        }
        public void deleteCoursesCascade(int id, bool hideMessage = false)
        {
            ArrayList codes           = new ArrayList();
            DataTable childCourses    = DBConnection.Select("courses", " id, code, semester_id ", " parent_id = " + id);
            ArrayList childCoursesIds = new ArrayList();
            int       semester        = 0;

            foreach (DataRow childCourse in childCourses.Rows)
            {
                childCoursesIds.Add(childCourse.ItemArray[0]);
                codes.Add(childCourse.ItemArray[1]);
                semester = int.Parse(childCourse.ItemArray[2].ToString());
            }

            //Get all numeric exercises groups of the course
            DataTable numExerciseGroups   = DBConnection.Select("courses", " id, code ", " parent_id IN ( " + String.Join(",", childCoursesIds.ToArray()) + ") AND detail = 'numeric'");
            ArrayList numExerciseGroupIds = new ArrayList();

            foreach (DataRow numExerciseRow in numExerciseGroups.Rows)
            {
                numExerciseGroupIds.Add(numExerciseRow.ItemArray[0]);
                codes.Add(numExerciseRow.ItemArray[1]);
            }

            //Get all laboratory exercises groups of the course
            DataTable labExerciseGroups = DBConnection.Select("courses", " id, code ", " parent_id IN ( " +
                                                              String.Join(",", (numExerciseGroupIds.Count > 0) ? numExerciseGroupIds.ToArray() : childCoursesIds.ToArray()) + ") AND detail = 'laboratory'");
            ArrayList labExerciseGroupIds = new ArrayList();

            foreach (DataRow labExerciseRow in labExerciseGroups.Rows)
            {
                labExerciseGroupIds.Add(labExerciseRow.ItemArray[0]);
                codes.Add(labExerciseRow.ItemArray[1]);
            }

            foreach (int lab in labExerciseGroupIds)
            {
                DBConnection.Delete("courses", lab);
            }

            foreach (int num in numExerciseGroupIds)
            {
                DBConnection.Delete("courses", num);
            }

            foreach (int lect in childCoursesIds)
            {
                DBConnection.Delete("courses", lect);
            }

            int result = DBConnection.Delete("courses", id);

            if (result > 0)
            {
                //Delete all course assignment
                string table = "timetable_" + (((semester % 2) == 0) ? "spring" : "autumn");
                foreach (string code in codes)
                {
                    DBConnection.Delete(table, 0, " course_code='" + code + "'");
                }

                if (!hideMessage)
                {
                    MessageBox.Show("Successfully deleted Course!", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
        }
예제 #9
0
        private void pnlBackground_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                var day    = int.Parse(lblColumn.Text);
                var period = int.Parse(lblRow.Text);

                if (lblClicked.Text == "false")
                {
                    if ((Parent.GetType() == typeof(Grid)) && ((Parent as Grid).Parent.GetType() == typeof(Grid)) && (((Parent as Grid).Parent as Grid).Parent.GetType() == typeof(PreferencesWindow)))
                    {
                        if (!(((Parent as Grid).Parent as Grid).Parent as PreferencesWindow).validatePreference())
                        {
                            MessageBox.Show("Teacher should be available at least half of the week! In order to add other constraints, please remove some existing constraints!", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                            return;
                        }
                    }

                    lblClicked.Text = "true";
                    PanelBackground = "#5E716A";

                    if (TeacherId > 0)
                    {
                        DataTable preferences = DBConnection.Select("teacher_periods_preferences", "day, period", "teacher_id=" + TeacherId + " AND day=" + day + " AND period=" + period);
                        if (preferences.Rows.Count == 0)
                        {
                            string values = "'" + TeacherId + "', '" + day + "', '" + period + "'";
                            int    result = DBConnection.Create("teacher_periods_preferences", "teacher_id, day, period", values);
                        }
                    }

                    if (CourseIds.Count > 0)
                    {
                        foreach (int cId in CourseIds)
                        {
                            DataView data = DBConnection.Select("course_periods_preferences", "'*'", " course_id = " + cId + " AND day=" + day + " AND period=" + period).DefaultView;
                            if (data.Count == 0)
                            {
                                string values = "'" + cId + "', '" + day + "', '" + period + "'";
                                int    result = DBConnection.Create("course_periods_preferences", "course_id, day, period", values);
                            }
                        }
                    }
                }
                else
                {
                    lblClicked.Text = "false";
                    PanelBackground = "#EEEEEE";

                    if (TeacherId > 0)
                    {
                        int result = DBConnection.Delete("teacher_periods_preferences", 0, " teacher_id=" + TeacherId + " AND day=" + day + " AND period=" + period);
                    }

                    if (CourseIds.Count > 0)
                    {
                        foreach (int cId in CourseIds)
                        {
                            int result = DBConnection.Delete("course_periods_preferences", 0, " course_id=" + cId + " AND day=" + day + " AND period=" + period);
                        }
                    }
                }
            }
        }