/* * EventName: bttnEnroll_Click * Parameters: sender,event * Summary: this event gets called when the enroll button is clicked and enrolls the student into the requested course. * Pre-req: Only if the Zid entered is a valid one and also the course asked to * enroll is an existing course, and if student is not already enrolled in it. */ private void bttnEnroll_Click(object sender, EventArgs e) { //clearing the message ad list boxes before displaying the result rtbOutput.Clear(); lstCourse.Items.Clear(); lstStudent.Items.Clear(); Form1_Load(sender, e); Course cobj = new Course(); Student sobj = new Student(); int stcount = -1, ccount = -1; int index = 0; Program p = new Program(); string id = txtSearchZid.Text; //storing the input zid string coursenum = txtCourse.Text; //storing the input course if (id.Length != 0) { if (coursenum.Length != 0) { string c = id.Substring(0, 1); //id the zid is entered without omitting the 'Z' character. if (c == "z" || c == "Z") { id = id.Substring(1, id.Length - 1); } for (int k = 0; k < p.NewStudents.Count; k++) { if (p.NewStudents[k].Zid == Convert.ToInt32(id)) { stcount = k; break; } else { continue; } } if (stcount >= 0 && stcount < p.NewStudents.Count) { string[] details = coursenum.Split(' '); string[] cour_sec = details[1].Split('-'); for (int k = 0; k < p.NewCourses.Count; k++) { if (p.NewCourses[k].Cnum == Convert.ToUInt32(cour_sec[0])) { ccount = k; } else { continue; } } if (ccount >= 0 && ccount < p.NewCourses.Count) { for (int i = 0; i < p.NewCourses.Count; i++) { if (p.NewCourses[i].Cnum == Convert.ToUInt32(cour_sec[0])) { cobj = p.NewCourses[i]; index = i; break; } } if (!p.NewCourses[ccount].Stuenrolled.Contains(Convert.ToInt32(id))) { p.NewCourses[ccount].Stuenrolled.Add(Convert.ToInt32(id)); if (p.NewStudents[stcount].Crhours <= 18) { p.NewStudents[stcount].Crhours += cobj.Chours; } else { rtbOutput.AppendText("Student credit hours exceeds allowed limit of 18. Hence, could not enroll."); } if (p.NewCourses[ccount].Stuenrolledcount < p.NewCourses[ccount].Maxenrollment) { p.NewCourses[ccount].Stuenrolledcount++; } else { rtbOutput.AppendText("This class has reached its maximum capacity. Hence, could not enroll. Sorry!"); } rtbOutput.AppendText("z" + id + " has been successfully enrolled into " + coursenum.ToUpper() + "\n\n"); lstCourse.Items.Clear(); for (int i = 0; i < p.NewCourses.Count; i++) { lstCourse.Items.Add(p.NewCourses[i].Deptcode + " " + p.NewCourses[i].Cnum + "-" + p.NewCourses[i].Section + " (" + p.NewCourses[i].Stuenrolledcount + "/" + p.NewCourses[i].Maxenrollment + ")"); } } else { rtbOutput.AppendText("Student already enrolled into this course"); } } else { rtbOutput.AppendText("Unfortunately, there is no such course. Please enter a valid course. \n\n\n"); } } else { rtbOutput.AppendText("Unfortunately, there is no such student to proceed to enrolling\n\n\n"); } } else { rtbOutput.AppendText("Please enter a Course number-Section number"); } } else { rtbOutput.AppendText("Please enter a Z-id <omitting Z character>"); } }
/* * EventName: btnDrop_Click * Parameters: sender,event * Summary: This event gets called when drop student button gets clicked and intends to drop a student from a particular course. * Pre-req: Only if the Zid entered is a valid one and also the course asked to * has that student enrolled in it. The student has ever enrolled in that course. */ private void btnDrop_Click(object sender, EventArgs e) { rtbOutput.Clear(); lstCourse.Items.Clear(); lstStudent.Items.Clear(); Form1_Load(sender, e); int stcount = -1, ccount = -1; Course cobj = new Course(); Student sobj = new Student(); Program p = new Program(); string id = txtSearchZid.Text; string coursenum = txtCourse.Text; if (id.Length != 0) { if (coursenum.Length != 0 && coursenum.Length > 3) { string c = id.Substring(0, 1); if (c == "z" || c == "Z") //if the zid is entered without omitting the Z character. { id = id.Substring(1, id.Length - 1); } for (int k = 0; k < p.NewStudents.Count; k++) { if (p.NewStudents[k].Zid == Convert.ToInt32(id)) { stcount = k; } else { continue; } } if (stcount >= 0 && stcount < p.NewStudents.Count) { string[] details = coursenum.Split(' '); string[] cour_sec = details[1].Split('-'); for (int k = 0; k < p.NewCourses.Count; k++) { if (p.NewCourses[k].Cnum == Convert.ToUInt32(cour_sec[0])) { ccount = k; break; } else { continue; } } if (ccount >= 0 && ccount < p.NewCourses.Count) { for (int i = 0; i < p.NewCourses.Count; i++) { if (p.NewCourses[i].Cnum == Convert.ToUInt32(cour_sec[0])) { cobj = p.NewCourses[i]; break; } } if (p.NewCourses[ccount].Stuenrolled.Contains(Convert.ToInt32(id))) { p.NewCourses[ccount].Stuenrolled.Remove(Convert.ToInt32(id)); if (p.NewStudents[stcount].Crhours >= 0 && p.NewStudents[stcount].Crhours <= 18) { p.NewStudents[stcount].Crhours -= p.NewCourses[ccount].Chours; } if (p.NewCourses[ccount].Stuenrolledcount < p.NewCourses[ccount].Maxenrollment) { p.NewCourses[ccount].Stuenrolledcount--; } rtbOutput.AppendText("z" + id + " has been successfully dropped from " + coursenum.ToUpper() + "\n\n"); lstCourse.Items.Clear(); for (int i = 0; i < p.NewCourses.Count; i++) { lstCourse.Items.Add(p.NewCourses[i].Deptcode + " " + p.NewCourses[i].Cnum + "-" + p.NewCourses[i].Section + " (" + p.NewCourses[i].Stuenrolledcount + "/" + p.NewCourses[i].Maxenrollment + ")"); } } else { rtbOutput.AppendText("Student had never been enrolled in this course"); } } else { rtbOutput.AppendText("Unfortunately, there is no such course to drop \n\n"); } } else { rtbOutput.AppendText("Unfortunately, there is no such student to proceed to dropping a course\n\n"); } } else { rtbOutput.AppendText("Please enter a valid <Deptcode Course number-Section number>"); } } else { rtbOutput.AppendText("Please enter a Z-id <omitting Z character>"); } }