Beispiel #1
0
        private void button7_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow d_row in dataGridView1.Rows)
            {
                object ischecked = d_row.Cells[0].Value;

                if (ischecked == null)
                {
                }
                else
                {
                    var addCourse = true;
                    foreach (DataGridViewRow d_row_2 in dataGridView2.Rows)
                    {
                        if (addCourse && d_row.Cells[1].Value == d_row_2.Cells[1].Value)
                        {
                            if (!LogInScreen.admin_perms)
                            {
                                addCourse = false;
                            }
                            System.Windows.Forms.MessageBox.Show("Already enrolled in course");
                        }
                        if (addCourse)
                        {
                            string        new_course_id         = (string)d_row.Cells[1].Value;
                            string        old_course_id         = (string)d_row_2.Cells[1].Value;
                            string[]      new_course_split      = new_course_id.Split('-');
                            List <string> new_course_split_list = new List <string>(new_course_split);
                            string[]      old_course_split      = old_course_id.Split('-');
                            List <string> old_course_split_list = new List <string>(old_course_split);
                            if (new_course_split_list[0] == old_course_split_list[0] && new_course_split_list[1] == old_course_split_list[1])
                            {
                                if (!LogInScreen.admin_perms)
                                {
                                    addCourse = false;
                                }
                                System.Windows.Forms.MessageBox.Show("Already enrolled in different section of course");
                            }
                        }
                        if (addCourse)
                        {
                            if ((int)d_row.Cells[5].Value < 0.0)
                            {
                                if (!LogInScreen.admin_perms)
                                {
                                    addCourse = false;
                                }
                                System.Windows.Forms.MessageBox.Show("No Seats Available");
                            }
                        }
                    }
                    if (addCourse)
                    {
                        if (Convert.ToSingle(d_row.Cells[4].Value) + current_user.GetCurrentCourseCredits() >= 5.0)
                        {
                            if (!LogInScreen.admin_perms)
                            {
                                addCourse = false;
                            }
                            System.Windows.Forms.MessageBox.Show("Too many credits");
                        }
                    }
                    if (addCourse)
                    {
                        foreach (DataGridViewRow d_row_3 in dataGridView3.Rows)
                        {
                            string        new_course_id         = (string)d_row.Cells[1].Value;
                            string        old_course_id         = (string)d_row_3.Cells[0].Value;
                            string[]      new_course_split      = new_course_id.Split('-');
                            List <string> new_course_split_list = new List <string>(new_course_split);
                            string[]      old_course_split      = old_course_id.Split('-');
                            List <string> old_course_split_list = new List <string>(old_course_split);
                            if (new_course_split_list[0] == old_course_split_list[0] && new_course_split_list[1] == old_course_split_list[1])
                            {
                                System.Windows.Forms.MessageBox.Show("Warning! Previously enrolled in " + new_course_id);
                            }
                        }
                    }
                    if (addCourse)
                    {
                        try
                        {
                            current_user.AddCourse((string)d_row.Cells[1].Value);
                            var student_course_array = from row in current_user.GetCourses()
                                                       select new
                            {
                                Id      = row.Value.GetCourseID(),
                                Name    = row.Value.GetCourseName(),
                                Faculty = row.Value.GetFaculty().GetUserName(),
                                Credits = row.Value.GetCourseCredit(),
                                Seats   = row.Value.GetNumSeats(),
                                Dates   = String.Join(", ", row.Value.GetDayBlocks()),
                                Times   = String.Join(", ", row.Value.GetTimeBlocks())
                            };
                            dataGridView2.DataSource = student_course_array.ToArray();
                            current_user.VerifyNextSchedule();
                        }
                        catch
                        {
                            System.Windows.Forms.MessageBox.Show("Error adding course");
                        }
                    }
                }
            }
            Form2_Load(sender, e);
        }
Beispiel #2
0
 //adds courseName to enrolledCourses of the given professor
 public void AddStudentCourse(string courseName, Student studentName)
 {
     studentName.AddCourse(courseName);
 }