public static List <Student> getStudentsFromOffering(CourseOffering courseOffering)
    {
        string selectSQL = "SELECT s.StudentNum, s.Name, s.Type FROM Student s "
                           + "JOIN Registration r ON s.StudentNum = r.Student_StudentNum  "
                           + "WHERE r.CourseOffering_Course_CourseID=@courseID "
                           + "  AND r.CourseOffering_Year = @year "
                           + "  AND r.CourseOffering_Semester = @Semester";

        SqlConnection connection = new SqlConnection(connectionString);
        SqlCommand    command    = new SqlCommand(selectSQL, connection);

        command.Parameters.AddWithValue("@courseID", courseOffering.CourseOffered.CourseNumber);
        command.Parameters.AddWithValue("@year", courseOffering.Year.ToString());
        command.Parameters.AddWithValue("@Semester", courseOffering.Semester);

        SqlDataReader reader = null;

        List <Student> studentsInOffering = new List <Student>();

        try
        {
            connection.Open();
            reader = command.ExecuteReader();

            if (reader != null && reader.HasRows)
            {
                while (reader.Read())
                {
                    string studentNumber = (string)reader["StudentNum"];
                    string studentName   = (string)reader["Name"];
                    string type          = (string)reader["Type"];

                    if (type == "Full Time")
                    {
                        Student ourStudent = new FullTimeStudent(studentNumber, studentName);
                        studentsInOffering.Add(ourStudent);
                    }
                    if (type == "Part Time")
                    {
                        Student ourStudent = new PartTimeStudent(studentNumber, studentName);
                        studentsInOffering.Add(ourStudent);
                    }
                    else
                    {
                        Student ourStudent = new CoopStudent(studentNumber, studentName);
                        studentsInOffering.Add(ourStudent);
                    }
                }
            }
        }
        catch (Exception e)
        {
            throw e;
        }
        finally
        {
            connection.Close();
        }
        return(studentsInOffering);
    }
示例#2
0
        static void Main(string[] args)
        {
            List <Employee> list = new List <Employee>();
            Company         c    = new Company(list);

            c.EmployNewEmployee(new FullTimeEmployee("a", 1000));
            c.EmployNewEmployee(new FullTimeEmployee("c", 2000));
            c.EmployNewEmployee(new FullTimeEmployee("d", 3000));
            c.EmployNewEmployee(new FullTimeEmployee("e", 4000));
            c.EmployNewEmployee(new FullTimeEmployee("f", 5000));
            c.EmployNewEmployee(new PartTimeEmployee("g", 100, 10));
            c.EmployNewEmployee(new PartTimeEmployee("h", 200, 10));
            c.EmployNewEmployee(new PartTimeEmployee("i", 300, 10));
            c.EmployNewEmployee(new PartTimeEmployee("j", 400, 10));
            c.EmployNewEmployee(new PartTimeEmployee("k", 500, 10));
            c.EmployNewEmployee(new PartTimeStudent("Signe", 110, 45, 2016));

            foreach (Employee item in list)
            {
                Console.WriteLine(item.Name);
                if (item.Name == "Signe")
                {
                    PartTimeStudent s = (PartTimeStudent)item;
                    //check year by using break points
                    s.Register(2010);
                }
            }

            Console.WriteLine("Total sum {0}", c.GetMonthlySalaryTotal());

            Console.ReadKey();
        }
 /// <summary>
 ///     Gets the student.
 /// </summary>
 /// <returns></returns>
 /// <exception cref="System.ArgumentOutOfRangeException"></exception>
 public Student GetStudent()
 {
     Student student;
     switch (_viewModel.StudentType)
     {
         case StudentTypes.FullTime:
             student = new FulltimeStudent
             {
                 Level = 1
             };
             break;
         case StudentTypes.PartTime:
             student = new PartTimeStudent
             {
                 StartDate = (DateTime.Now)
             };
             break;
         case StudentTypes.CoOp:
             student = new CoOpStudent();
             break;
         default:
             throw new ArgumentOutOfRangeException();
     }
     student.StudentName = _viewModel.StudentName;
     student.StudentNumber = _viewModel.StudentNumber;
     return student;
 }
    protected void ValidateForm()
    {
        var studentName = txtStudentName.Text;

        var studentType = pnlStudentType.Controls.OfType <RadioButton>().FirstOrDefault(r => r.Checked);

        if (studentType == null)
        {
            return;
        }

        Student student = null;


        if (studentType == btuFulltime)
        {
            student = new FullTimeStudent(studentName);
        }

        else if (studentType == btuparttime)
        {
            student = new PartTimeStudent(studentName);
        }
        else
        {
            student = new CoopStudent(studentName);
        }
        var error = false;

        for (var i = 0; i < CheckBoxList.Items.Count; i++)
        {
            if (!CheckBoxList.Items[i].Selected)
            {
                continue;
            }
            try
            {
                student.addCourse(Helper.GetCourses()[i]);//add course is taken from full time class
            }
            catch (Exception ex)
            {
                lblError.Text    = ex.Message;
                lblError.Visible = true;
                error            = true;
            }


            // lblError.Visible = false;
        }

        if (!error)
        {
            StudentInfo(student, studentType.Text);
        }
    }//validate form
示例#5
0
    public static List <Student> retreiveAllStudents()
    {
        string        selectStudentsSQL = "SELECT * FROM Student";
        SqlConnection connection        = new SqlConnection(connectionString);
        SqlCommand    command           = new SqlCommand(selectStudentsSQL, connection);

        SqlDataReader reader = null;

        List <Student> students = new List <Student>();

        try
        {
            connection.Open();
            reader = command.ExecuteReader();

            if (reader != null && reader.HasRows)
            {
                while (reader.Read())
                {
                    string courseNum  = (string)reader["StudentNum"];
                    string courseName = (string)reader["Name"];
                    string type       = (string)reader["Type"];

                    if (type == "Full Time")
                    {
                        Student student = new FullTimeStudent(courseNum, courseName);

                        students.Add(student);
                    }
                    if (type == "Part Time")
                    {
                        Student student = new PartTimeStudent(courseNum, courseName);

                        students.Add(student);
                    }
                    if (type == "Co-op")
                    {
                        Student student = new CoopStudent(courseNum, courseName);

                        students.Add(student);
                    }
                }
            }
        }
        catch (Exception)
        {
            throw;
        }
        finally
        {
            connection.Close();
        }
        return(students);
    }
示例#6
0
    protected void btnAddCourseOffering_Click1(object sender, EventArgs e)
    {
        string studentNumber = txtStudentName.Text;
        string studentName   = txtStudentName.Text;

        List <CourseOffering> coursesOffered = CourseOfferingsDataAccess.retreiveAllCourses();
        int j = ddlCourseOffering.SelectedIndex;

        string test = rblStudentStatus.SelectedValue;

        if (rblStudentStatus.SelectedValue == "Full-Time")
        {
            Student ourStudents = new FullTimeStudent(studentNumber, studentName);
            StudentDataAccess.AddStudent(ourStudents);

            int selectedIndex = ddlCourseOffering.SelectedIndex;

            coursesOffered[selectedIndex].AddStudent(ourStudents);

            RegistrationDataAccess.addRegistration(ourStudents, coursesOffered[selectedIndex]);

            txtStudentName.Text   = "";
            txtStudentNumber.Text = "";
        }

        else if (rblStudentStatus.SelectedValue == "Part-Time")
        {
            Student ourStudents = new PartTimeStudent(studentNumber, studentName);
            StudentDataAccess.AddStudent(ourStudents);

            int selectedIndex = ddlCourseOffering.SelectedIndex;

            coursesOffered[selectedIndex].AddStudent(ourStudents);

            RegistrationDataAccess.addRegistration(ourStudents, coursesOffered[selectedIndex]);

            txtStudentName.Text   = "";
            txtStudentNumber.Text = "";
        }
        else if (rblStudentStatus.SelectedValue == "Co-op")
        {
            Student ourStudents = new CoopStudent(studentNumber, studentName);
            StudentDataAccess.AddStudent(ourStudents);

            int selectedIndex = ddlCourseOffering.SelectedIndex;

            coursesOffered[selectedIndex].AddStudent(ourStudents);

            RegistrationDataAccess.addRegistration(ourStudents, coursesOffered[selectedIndex]);

            txtStudentName.Text   = "";
            txtStudentNumber.Text = "";
        }
    }
示例#7
0
    public static List <Student> RetrieveAllStudent()
    {
        // Define ADO.NET objects
        string selectStudentsSQL = "SELECT * FROM Student";

        SqlConnection connection = new SqlConnection(connectionString);
        SqlCommand    command    = new SqlCommand(selectStudentsSQL, connection);
        SqlDataReader reader     = null;

        List <Student> students = new List <Student>();

        try
        {
            connection.Open();
            reader = command.ExecuteReader();

            if (reader != null && reader.HasRows)
            {
                while (reader.Read())
                {
                    string  studentNum  = (string)reader["StudentNum"];
                    string  studentName = (string)reader["Name"];
                    string  studentType = (string)reader["Type"];
                    Student student     = null;

                    if (studentType == StudentType.FullTime)
                    {
                        student = new FullTimeStudent(studentNum, studentName);
                    }
                    if (studentType == StudentType.PartTime)
                    {
                        student = new PartTimeStudent(studentNum, studentName);
                    }
                    if (studentType == StudentType.Coop)
                    {
                        student = new CoopStudent(studentNum, studentName);
                    }
                    students.Add(student);
                }
            }
            return(students);
        }
        catch (Exception)
        {
            throw;
        }
        finally
        {
            connection.Close();
        }
    }
示例#8
0
    public static Student RetrieveStudentByStudentNum(string studentNum)
    {
        string selectStudentByIdSQL = "SELECT StudentNum FROM Student WHERE studentNum = StudentNum";

        SqlConnection connection = new SqlConnection(connectionString);
        SqlCommand    command    = new SqlCommand(selectStudentByIdSQL, connection);
        SqlDataReader reader     = null;

        List <Student> students = new List <Student>();

        try
        {
            connection.Open();
            reader = command.ExecuteReader();
            if (reader != null && reader.HasRows)
            {
                string  studentId   = (string)reader["StudentNum"];
                string  studentName = (string)reader["Name"];
                string  studentType = (string)reader["Type"];
                Student student     = null;

                if (studentType == StudentType.FullTime)
                {
                    student = new FullTimeStudent(studentNum, studentName);
                }
                if (studentType == StudentType.PartTime)
                {
                    student = new PartTimeStudent(studentNum, studentName);
                }
                if (studentType == StudentType.Coop)
                {
                    student = new CoopStudent(studentNum, studentName);
                }
                students.Add(student);
                return(student);
            }
        }
        catch (Exception)
        {
            throw;
        }
        finally
        {
            connection.Close();
        }
        return(null);
    }
示例#9
0
    public static Student MakeStudent(string name, string number, string type)
    {
        Student student = null;

        if (type == FullTime)
        {
            student = new FullTimeStudent(number, name);
        }
        else if (type == PartTime)
        {
            student = new PartTimeStudent(number, name);
        }
        else if (type == Coop)
        {
            student = new CoopStudent(number, name);
        }
        return(student);
    }
示例#10
0
        public void GetStudentSubjectDetails(int studentid, string courseType)
        {
            List <string> getPreviousYearSubjects = GetPreviousSubjectDetails(studentid);


            // OCP Violoation
            switch (courseType)
            {
            case "Computers":
                ComputerStudent fullTimeStudent  = new ComputerStudent();
                List <string>   fullTimeSubjects = fullTimeStudent.GetStudentSubjects();
                break;

            case "Electronic":
                PartTimeStudent partTimeStudent  = new PartTimeStudent();
                List <string>   partTimeSubjects = partTimeStudent.GetStudentSubjects();
                break;
            }
        }
    protected void btnAddToCourseOffering_Click(object sender, EventArgs e)
    {
        Student astudent = null;
        List <CourseOffering> coursesOffering = CourseOfferingDataAccess.RetrieveAllCoursesOffering();
        int indx = 1;

        try
        {
            switch (rdbStudentType.SelectedItem.Value)
            {
            case "FullTime":
                astudent = new FullTimeStudent(txtStudentNumber.Text, txtStudentName.Text);
                break;

            case "PartTime":
                astudent = new PartTimeStudent(txtStudentNumber.Text, txtStudentName.Text);
                break;

            case "Coop":
                astudent = new CoopStudent(txtStudentNumber.Text, txtStudentName.Text);
                break;
            }
            StudentDataAccess.AddNewStudent(astudent);

            if (drpRegisterStudentsList.SelectedIndex != 0)
            {
                foreach (CourseOffering courseO in coursesOffering)
                {
                    if (indx == drpRegisterStudentsList.SelectedIndex)
                    {
                        RegistrationDataAccess.AddNewRegistration(courseO, astudent);
                    }

                    indx++;
                }
                indx = 1;
            }
        }
        catch (Exception)
        {
        }
        populateTable();
    }
示例#12
0
 /**
  * Create the student object
  */
 protected void CreateStudent(string type, string name)
 {
     IStudent student;
     switch (type)
     {
         case "Full Time":
             student = new FullTimeStudent(name);
             break;
         case "Part Time":
             student = new PartTimeStudent(name);
             break;
         case "Co-Op":
             student = new CoopStudent(name);
             break;
         default:
             student = new FullTimeStudent(name);
             break;
     }
     _student = student;
 }
示例#13
0
    protected void AddStudent_Click(object sender, EventArgs e)
    {
        if (drpCourseOfferingList.SelectedValue != "-1")
        {
            using (StudentRegistrationEntities entityContext = new StudentRegistrationEntities())
            {
                List <Student> studentList = entityContext.Students.ToList <Student>();
                var            student     = (from c in studentList
                                              where c.StudentNum == txtStudentNumber.Text
                                              select c).FirstOrDefault <Student>();

                if (student == null)
                {
                    if (rbFullTime.Checked)
                    {
                        student = new FullTimeStudent(txtStudentNumber.Text, txtStudentName.Text);
                    }
                    else if (rbPartTime.Checked)
                    {
                        student = new PartTimeStudent(txtStudentNumber.Text, txtStudentName.Text);
                    }
                    else if (rbCoop.Checked)
                    {
                        student = new CoopStudent(txtStudentNumber.Text, txtStudentName.Text);
                    }

                    entityContext.Students.Add(student);
                    entityContext.SaveChanges();
                }

                CourseOffering courseOffering     = GetCourseOfferingFromDropdown(entityContext);
                List <Student> registeredStudents = courseOffering.Students.ToList <Student>();
                if (!registeredStudents.Exists(x => x.Number == student.Number))
                {
                    courseOffering.Students.Add(student);
                    entityContext.SaveChanges();
                }
            }
        }
    }
示例#14
0
    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 btnAddStudent_OnClick(object sender, EventArgs e)
    {
        Student student = null;
            try
            {
                var courseOffering = Helpers.GetCourseOffering(drpCourses.SelectedValue, context);

                if (courseOffering.Students.Any())
                {

                    //checking if the student has already been added
                    if (Helpers.StudentExists(Helpers.GetCourseOffering(drpCourses.SelectedValue,context), txtStudentId.Text, context))
                    {
                        Title = "This Student has already been registered for this course";
                    }
                    //add the student to the courseOffering
                    else
                    {
                        switch (lstOrderBy.SelectedIndex)
                        {
                            case 0: //full time
                                student = new FullTimeStudent(txtStudentName.Text, txtStudentId.Text);
                                break;
                            case 1: //part time
                                student = new PartTimeStudent(txtStudentName.Text, txtStudentId.Text);
                                break;
                            case 2: //coop
                                student = new CoopStudent(txtStudentName.Text, txtStudentId.Text);

                                break;
                        }

                    }
                    student.CourseOfferings.Add(courseOffering);
                    courseOffering.Students.Add(student);
                    context.Students.Add(student);
                    context.SaveChanges();

            }

                //if courseOffering list is empty add the course
                else
                {
                    switch (lstOrderBy.SelectedIndex)
                    {
                        case 0: //full time
                            student = new FullTimeStudent(txtStudentName.Text, txtStudentId.Text);
                            break;
                        case 1: //part time
                            student = new PartTimeStudent(txtStudentName.Text, txtStudentId.Text);
                            break;
                        case 2: //coop
                            student = new CoopStudent(txtStudentName.Text, txtStudentId.Text);

                            break;
                    }
                    student.CourseOfferings.Add(courseOffering);
                    courseOffering.Students.Add(student);
                    context.Students.Add(student);
                    context.SaveChanges();

                }

            }
            catch (Exception err)
            {

            }
    }
示例#16
0
    protected void ValidateForm()
    {
        // Get the student name
        var studentName = txtStudentName.Text;

        // Get the type of student from radio button
        var studentType = pnlStudentType.Controls.OfType<RadioButton>().FirstOrDefault(r => r.Checked);
        if (studentType == null) return;

        Student student = null;

        // Create a new student instance of the appropriate type
        switch (studentType.Text)
        {
            case "Full Time" :
                student = new FullTimeStudent(studentName);
                break;
            case "Part Time" :
                student = new PartTimeStudent(studentName);
                break;
            case "Co-op" :
                student = new CoopStudent(studentName);
                break;
        }

        var error = false;

        // Iterate through the checkbox list
        for (var i = 0; i < _cblAvailableCourses.Items.Count; i++)
        {
            // If an item is selected
            if (!_cblAvailableCourses.Items[i].Selected) continue;

            // Attempt to register the student in the course
            try
            {
                student.addCourse((Course) Helper.GetCourses()[i]);
            }
            catch (Exception e) // Handle any exceptions
            {
                // Display error
                lblError.Text = e.Message;
                lblError.Visible = true;
                error = true;
            }
        }

        if (!error)
        {
            // If validation passes, display the results in a table
            DisplayStudentInfo(student, studentType.Text);
        }
    }
示例#17
0
    public static List<Student> getStudentsByCourseID(string id)
    {
        List<Student> student = new List<Student>();
        Student s;
        try
        {
            connection.Open();
            string selectCoursesIDSQL = "SELECT s.StudentNum, s.Name, s.Type FROM Student s "
                              + "JOIN Registration r ON s.StudentNum = r.Student_StudentNum  "
                              + "WHERE r.CourseOffering_Course_CourseID=@courseID "
                              + "  AND r.CourseOffering_Year = @year"
                              + "  AND r.CourseOffering_Semester = @semester"
                              + " ORDER BY s.Name DESC";

            SqlCommand getStudents = new SqlCommand(selectCoursesIDSQL, connection);
            getStudents.Parameters.AddWithValue("@courseID", id);
            getStudents.Parameters.AddWithValue("@year", Convert.ToInt32(getCourseOfferingByID(getCourseById(id)).Year));
            getStudents.Parameters.AddWithValue("@semester", "Summer");
            rdr = getStudents.ExecuteReader();

            while (rdr.Read())
            {
                // get the results of each column
                string number = (string)rdr["StudentNum"];
                string name = (string)rdr["Name"];
                string type = (string)rdr["Type"];

                //set student types
                if (type == "Full Time")
                {
                    s = new FullTimeStudent(number, name);

                }
                else if (type == "Part Time")
                {
                    s = new PartTimeStudent(number, name);
                }
                else
                {
                    s = new CoopStudent(number, name);
                }
                //add student to the list

                student.Add(s);
            }
        }
        catch (Exception err)
        {
            var page = (Page)HttpContext.Current.Handler;
            page.Title = err.Message + " h";
        }
        finally
        {
            if (rdr != null)
            {
                rdr.Close();
            }
            connection.Close();
        }
        //student.Sort(new StudentSorter().Compare);
        return student;
    }
    protected void Submit_Click(object sender, EventArgs e)
    {
        try
        {
            if (!string.IsNullOrEmpty(StudentName.Text))
            {
                List <Course> courses = Helper.GetCourses();
                Student       student;

                if (RadioButtonListStudentType.SelectedValue.Any())
                {
                    switch (RadioButtonListStudentType.SelectedItem.Value)
                    {
                    case "Full Time":
                        student = new FullTimeStudent(StudentName.Text);
                        break;

                    case "Part Time":
                        student = new PartTimeStudent(StudentName.Text);
                        break;

                    case "Co-op":
                        student = new CoopStudent(StudentName.Text);
                        break;

                    default:
                        student = new FullTimeStudent(StudentName.Text);
                        break;
                    }
                }
                else
                {
                    throw new Exception("Please select the student's status (full‑time, part‑time, co-op).");
                }

                if (CheckBoxListCourses.SelectedValue.Any())
                {
                    foreach (ListItem item in CheckBoxListCourses.Items)
                    {
                        if (item.Selected)
                        {
                            int courseNumber = int.Parse(item.Value);
                            student.addCourse(courses[courseNumber]);
                            ErrorMessage.Visible = false;
                        }
                    }
                }
                else
                {
                    throw new Exception("Please select the course.");
                }

                // Course Confirmation Panel:
                CourseRegistrationPanel.Visible = false;
                CourseConfirmationPanel.Visible = true;

                ConfirmationMessage1.Text = string.Format("Thank you {0} for using our online registration system.", student.Name);
                ConfirmationMessage2.Text = string.Format("You have been registered as a {0} for the following courses:", student.ToString());

                foreach (Course course in student.getEnrolledCourses())
                {
                    TableRow  tableRow          = new TableRow();
                    TableCell tableCourseCode   = new TableCell();
                    TableCell tabledCourseTitle = new TableCell();
                    TableCell tableWeeklyHours  = new TableCell();
                    TableCell tableFeePayable   = new TableCell();

                    tableCourseCode.Text = course.Code;
                    tableRow.Cells.Add(tableCourseCode);
                    tabledCourseTitle.Text = course.Title;
                    tableRow.Cells.Add(tabledCourseTitle);
                    tableWeeklyHours.Text = course.WeeklyHours.ToString();
                    tableRow.Cells.Add(tableWeeklyHours);
                    tableFeePayable.Text = "$" + course.Fee.ToString();
                    tableRow.Cells.Add(tableFeePayable);
                    ConfirmationTable.Rows.Add(tableRow);
                }

                TableFooterRow tableFooterRow        = new TableFooterRow();
                TableCell      tableTotal            = new TableCell();
                TableCell      tableTotalWeeklyHours = new TableCell();
                TableCell      tableTotalFeePayable  = new TableCell();

                tableTotal.ColumnSpan = 2;

                tableTotal.Text            = "Total:";
                tableTotalWeeklyHours.Text = student.totalWeeklyHours().ToString();
                tableTotalFeePayable.Text  = "$" + student.feePayable().ToString();

                tableFooterRow.Cells.Add(tableTotal);
                tableFooterRow.Cells.Add(tableTotalWeeklyHours);
                tableFooterRow.Cells.Add(tableTotalFeePayable);

                ConfirmationTable.Rows.Add(tableFooterRow);
            }
            else
            {
                throw new Exception("Please enter student name.");
            }
        }

        catch (Exception ex)
        {
            ErrorMessage.Visible = true;
            ErrorMessage.Text    = ex.Message;
        }
    }
    public static List <Student> GetRegistedStudentsByCourseOffering(CourseOffering courseOffering)
    {
        // Define ADO.NET objects
        string selectSQL = "SELECT s.StudentNum, s.Name, s.Type FROM Student s"
                           + " JOIN Registration r ON s.StudentNum = r.Student_StudentNum"
                           + " WHERE r.CourseOffering_Course_CourseID = @CourseID"
                           + " AND r.CourseOffering_Year = @Year "
                           + " AND r.CourseOffering_Semester = @Semester";

        SqlConnection connection       = new SqlConnection(connectionString);
        SqlCommand    SqlCoursecommand = new SqlCommand(selectSQL, connection);

        // Add the parameters
        SqlCoursecommand.Parameters.AddWithValue("@CourseID", courseOffering.CourseOffered.courseNumber);
        SqlCoursecommand.Parameters.AddWithValue("@Year", courseOffering.Year);
        SqlCoursecommand.Parameters.AddWithValue("@Semester", courseOffering.Semester);

        SqlDataReader reader = null;

        List <Student> students = new List <Student>();

        try
        {
            connection.Open();
            reader = SqlCoursecommand.ExecuteReader();

            if (reader != null && reader.HasRows)
            {
                while (reader.Read())
                {
                    string  studentNum  = (string)reader["StudentNum"];
                    string  studentName = (string)reader["Name"];
                    string  studentType = (string)reader["Type"];
                    Student student     = null;

                    if (studentType == "Full" || studentType == "full")
                    {
                        student = new FullTimeStudent(studentNum, studentName);
                    }
                    if (studentType == "Part" || studentType == "part")
                    {
                        student = new PartTimeStudent(studentNum, studentName);
                    }
                    if (studentType == "Coop" || studentType == "coop")
                    {
                        student = new CoopStudent(studentNum, studentName);
                    }
                    students.Add(student);
                }
                //return students;
            }
        }
        catch (Exception)
        {
            throw;
        }
        finally
        {
            if (reader != null)
            {
                reader.Close();
            }
            connection.Close();
        }
        return(students);
    }
    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
示例#21
0
    protected void ValidateForm()
    {
        // Get the student name
        var studentName = txtStudentName.Text;

        // Get the type of student from radio button
        var studentType = pnlStudentType.Controls.OfType <RadioButton>().FirstOrDefault(r => r.Checked);

        if (studentType == null)
        {
            return;
        }

        Student student = null;

        // Create a new student instance of the appropriate type
        switch (studentType.Text)
        {
        case "Full Time":
            student = new FullTimeStudent(studentName);
            break;

        case "Part Time":
            student = new PartTimeStudent(studentName);
            break;

        case "Co-op":
            student = new CoopStudent(studentName);
            break;
        }

        var error = false;

        // Iterate through the checkbox list
        for (var i = 0; i < _cblAvailableCourses.Items.Count; i++)
        {
            // If an item is selected
            if (!_cblAvailableCourses.Items[i].Selected)
            {
                continue;
            }

            // Attempt to register the student in the course
            try
            {
                student.addCourse((Course)Helper.GetCourses()[i]);
            }
            catch (Exception e) // Handle any exceptions
            {
                // Display error
                lblError.Text    = e.Message;
                lblError.Visible = true;
                error            = true;
            }
        }

        if (!error)
        {
            // If validation passes, display the results in a table
            DisplayStudentInfo(student, studentType.Text);
        }
    }
    protected void submit_Click(object sender, System.EventArgs e)
    {
        if (name.Text == "")
        {
            error.Visible = true;
            error.Text    = "<strong class='error'>You have not entered a name</strong>";
        }
        else
        {
            try
            {
                // Student Type
                Student student;
                if (studentType.Items[0].Selected == true)
                {
                    student = new FullTimeStudent(name.Text);
                }
                else if (studentType.Items[1].Selected == true)
                {
                    student = new PartTimeStudent(name.Text);
                }
                else
                {
                    student = new CoopStudent(name.Text);
                }

                // Courses
                for (int i = 0; i < courses.Count; i++)
                {
                    if (chklst.Items[i].Selected)
                    {
                        student.addCourse(courses[i]);
                    }
                }
                form1.Visible = false;

                studentName.Text = "<p>Thank you <i class='emphsis'>" + student.Name + "</i>, for using our online registration system.</p>";

                studentStatus.Text = "<p>You have been registered as a <strong class='distinct'>" + student.ToString() + "</strong> for the following courses</p>";

                // Enrolled Courses
                ArrayList enrolledCourses = student.getEnrolledCourses();

                // Table
                table.Controls.Clear();
                TableHeaderRow newHeaderRow = new TableHeaderRow(); // Create table row
                table.Controls.Add(newHeaderRow);                   // Insert table row in table

                // Course Code
                TableHeaderCell cellHeaderNew = new TableHeaderCell(); // New table cell
                Label           lblNew        = new Label()
                {
                    Text = "Course Code"
                };                                        // New label object text
                cellHeaderNew.Controls.Add(lblNew);       // Put label in cell
                newHeaderRow.Controls.Add(cellHeaderNew); // Put Cell in table row

                // Course Title
                cellHeaderNew = new TableHeaderCell(); // New table cell
                lblNew        = new Label()
                {
                    Text = "Course Title"
                };                                        // New label object text
                cellHeaderNew.Controls.Add(lblNew);       // Put label in cell
                newHeaderRow.Controls.Add(cellHeaderNew); // Put Cell in table row

                // Course Title
                cellHeaderNew = new TableHeaderCell(); // New table cell
                lblNew        = new Label()
                {
                    Text = "Weekly Hours"
                };                                        // New label object text
                cellHeaderNew.Controls.Add(lblNew);       // Put label in cell
                newHeaderRow.Controls.Add(cellHeaderNew); // Put Cell in table row

                // Fee Payable
                cellHeaderNew = new TableHeaderCell(); // New table cell
                lblNew        = new Label()
                {
                    Text = "Fee Payable"
                };                                        // New label object text
                cellHeaderNew.Controls.Add(lblNew);       // Put label in cell
                newHeaderRow.Controls.Add(cellHeaderNew); // Put Cell in table row

                foreach (Course course in enrolledCourses)
                {
                    // Table
                    TableRow newRow = new TableRow(); // Create table row
                    table.Controls.Add(newRow);       // Insert table row in table

                    // Course Code
                    TableCell cellNew = new TableCell(); // New table cell
                    lblNew = new Label()
                    {
                        Text = course.Code
                    };                            // New label object text
                    cellNew.Controls.Add(lblNew); // Put label in cell
                    newRow.Controls.Add(cellNew); // Put Cell in table row

                    // Course Title
                    cellNew = new TableCell(); // New table cell
                    lblNew  = new Label()
                    {
                        Text = course.Title
                    };                            // New label object text
                    cellNew.Controls.Add(lblNew); // Put label in cell
                    newRow.Controls.Add(cellNew); // Put Cell in table row

                    // Course Title
                    cellNew = new TableCell(); // New table cell
                    lblNew  = new Label()
                    {
                        Text = course.WeeklyHours.ToString()
                    };                            // New label object text
                    cellNew.Controls.Add(lblNew); // Put label in cell
                    newRow.Controls.Add(cellNew); // Put Cell in table row

                    // Fee Payable
                    cellNew = new TableCell(); // New table cell
                    lblNew  = new Label()
                    {
                        Text = course.Fee.ToString()
                    };                            // New label object text
                    cellNew.Controls.Add(lblNew); // Put label in cell
                    newRow.Controls.Add(cellNew); // Put Cell in table row
                }

                // Table
                TableRow lastRow = new TableRow(); // Create table row
                table.Controls.Add(lastRow);       // Insert table row in table

                // Blank
                TableCell lastCell = new TableCell(); // New table cell
                lblNew = new Label()
                {
                    Text = ""
                };                              // New label object text
                lastCell.Controls.Add(lblNew);  // Put label in cell
                lastRow.Controls.Add(lastCell); // Put Cell in table row

                // Total
                lastCell = new TableCell(); // New table cell
                lblNew   = new Label()
                {
                    Text = "Total"
                };                              // New label object text
                lastCell.Style.Add("text-align", "right");
                lastCell.Controls.Add(lblNew);  // Put label in cell
                lastRow.Controls.Add(lastCell); // Put Cell in table row

                // Weekly Hours
                lastCell = new TableCell(); // New table cell
                lblNew   = new Label()
                {
                    Text = student.totalWeeklyHours().ToString()
                };                              // New label object text
                lastCell.Controls.Add(lblNew);  // Put label in cell
                lastRow.Controls.Add(lastCell); // Put Cell in table row

                // Fee Payable
                lastCell = new TableCell(); // New table cell
                lblNew   = new Label()
                {
                    Text = student.feePayable().ToString()
                };                              // New label object text
                lastCell.Controls.Add(lblNew);  // Put label in cell
                lastRow.Controls.Add(lastCell); // Put Cell in table row
            }
            catch (Exception ex)
            {
                error.Text    = ex.Message;
                error.Visible = true;
            }
        }
    }
示例#23
0
    protected void btnAddCourse_Click(object sender, EventArgs e)
    {
        string studentNumber = txtStudentNumber.Text;
        string studentName   = txtStudentName.Text;

        List <CourseOffering> coursesOffered = CourseOfferingsDataAccess.retreiveAllCourses();
        int j = coursesOffered.Count - 1;

        if (rblSortOptions.SelectedValue == "fullTime")
        {
            Student ourStudents = new FullTimeStudent(studentNumber, studentName);
            StudentDataAccess.AddStudent(ourStudents);

            List <Course> userCourse = CourseDataAccess.retreiveAllCourses();
            int           i          = userCourse.Count() - 1;


            CourseOffering courseOfferedCourses = new CourseOffering(userCourse[i], coursesOffered[j].Year, coursesOffered[j].Semester);

            courseOfferedCourses.AddStudent(ourStudents);
            courseOfferedCourses.GetStudents().Sort(sortBy);

            RegistrationDataAccess.addRegistration(ourStudents, courseOfferedCourses);

            txtStudentName.Text   = "";
            txtStudentNumber.Text = "";

            Response.Redirect(Request.RawUrl);
        }

        else if (rblSortOptions.SelectedValue == "partTime")
        {
            Student ourStudents = new PartTimeStudent(studentNumber, studentName);
            StudentDataAccess.AddStudent(ourStudents);

            List <Course> userCourse = CourseDataAccess.retreiveAllCourses();
            int           i          = userCourse.Count() - 1;

            CourseOffering courseOfferedCourses = new CourseOffering(userCourse[i], coursesOffered[j].Year, coursesOffered[j].Semester);

            courseOfferedCourses.AddStudent(ourStudents);
            courseOfferedCourses.GetStudents().Sort(sortBy);

            txtStudentName.Text   = "";
            txtStudentNumber.Text = "";

            Response.Redirect(Request.RawUrl);
        }
        else if (rblSortOptions.SelectedValue == "coop")
        {
            Student ourStudents = new CoopStudent(studentNumber, studentName);
            StudentDataAccess.AddStudent(ourStudents);

            List <Course> userCourse = CourseDataAccess.retreiveAllCourses();
            int           i          = userCourse.Count() - 1;

            CourseOffering courseOfferedCourses = new CourseOffering(userCourse[i], coursesOffered[j].Year, coursesOffered[j].Semester);

            courseOfferedCourses.AddStudent(ourStudents);
            courseOfferedCourses.GetStudents().Sort(sortBy);

            txtStudentName.Text   = "";
            txtStudentNumber.Text = "";

            Response.Redirect(Request.RawUrl);
        }
    }