protected void Submit_Click(object sender, EventArgs e) { try { List <Course> course = Helper.GetCourses(); Student student = null; //Choses the type of student switch (studentType.SelectedItem.Value) { case "full-time": student = new FullTimeStudent(txtName.Text); break; case "part-time": student = new PartTimeStudent(txtName.Text); break; case "co-op": student = new PartTimeStudent(txtName.Text); break; } //Add the couses to the student foreach (ListItem item in liCourses.Items) { if (item.Selected) { int selected = int.Parse(item.Value); student.addCourse(course[selected] as Course); } } //Throw Errors if (txtName.Text == "") { throw new Exception("You need to type your name in the space provided"); } if (student.getEnrolledCourses().Count == 0) { throw new Exception("You need to select a cource"); } //Makes table from selected courses foreach (Course courses in student.getEnrolledCourses()) { TableRow row = new TableRow(); TableCell cell = new TableCell(); cell.Text = courses.Code; row.Cells.Add(cell); cell = new TableCell(); cell.Text = courses.Title; row.Cells.Add(cell); cell = new TableCell(); cell.Text = courses.WeeklyHours.ToString(); row.Cells.Add(cell); cell = new TableCell(); cell.Text = "$" + courses.Fee.ToString(); row.Cells.Add(cell); Table.Rows.Add(row); } //Makes the Total of the table TableRow rowTotal = new TableRow(); TableCell cellTotal = new TableCell(); cellTotal.Text = "Total:"; cellTotal.ColumnSpan = 2; rowTotal.Cells.Add(cellTotal); cellTotal = new TableCell(); cellTotal.Text = student.totalWeeklyHours().ToString(); rowTotal.Cells.Add(cellTotal); cellTotal = new TableCell(); cellTotal.Text = "$" + student.feePayable().ToString(); rowTotal.Cells.Add(cellTotal); Table.Rows.Add(rowTotal); Name.Text = txtName.Text; Type.Text = studentType.SelectedItem.Text; Regestration.Visible = false; Results.Visible = true; } catch (Exception x) { error.Text = x.Message; } }
protected void btnSubmit_Click(object sender, EventArgs e) { if (RadioButton1.Checked) { FullTimeStudent ftStudent = new FullTimeStudent(txtName.Text); studentType.Add(ftStudent); // Add the student to list foreach (ListItem chosenCourse in CheckBoxList.Items) { // if a course is selected do the following if (chosenCourse.Selected) { try { // Add each selected course to the student's enrolled courses foreach (Course course in Helper.GetCourses()) { if (course.ToString() == chosenCourse.Text) { ftStudent.addCourse(course); } } } catch (Exception ex) { // Display error message if courses exceed 8 hours lblError.Text = ex.Message; // Continue with rest of code if there is no error return; } } // End of btn selection } // End of foreach // Display confirmation page for full-time student displayConfirmationPage(ftStudent); } // End of condition else if (RadioButton2.Checked) { PartTimeStudent ptStudent = new PartTimeStudent(txtName.Text); studentType.Add(ptStudent); foreach (ListItem chosenCourse in CheckBoxList.Items) { if (chosenCourse.Selected) { try { foreach (Course course in Helper.GetCourses()) { if (course.ToString() == chosenCourse.Text) { ptStudent.addCourse(course); } } } catch (Exception ex) { lblError.Text = ex.Message; return; } } // end of btn selection } // end of foreach // Display confirmation page for part-time student displayConfirmationPage(ptStudent); } // end of condition else if (RadioButton3.Checked) { CoopStudent cpStudent = new CoopStudent(txtName.Text); studentType.Add(cpStudent); foreach (ListItem chosenCourse in CheckBoxList.Items) { if (chosenCourse.Selected) { try { foreach (Course course in Helper.GetCourses()) { if (course.ToString() == chosenCourse.Text) { cpStudent.addCourse(course); } } } catch (Exception ex) { lblError.Text = ex.Message; return; } } // end of btn selection } // End of foreach // Display confirmation page for co-op student displayConfirmationPage(cpStudent); } // End of condition } // End of btn submit method