예제 #1
0
    public static void AddStudent(Student student)
    {
        string        insertStudentSQL = "INSERT INTO Student (StudentNum, Name, Type) VALUES (@studentNum, @name, @type)";
        SqlConnection connection       = new SqlConnection(connectionString);
        SqlCommand    sqlCourseCommand = new SqlCommand(insertStudentSQL, connection);
        string        type             = StudentType.getStudentType(student);

        sqlCourseCommand.Parameters.AddWithValue("@studentNum", student.Number);
        sqlCourseCommand.Parameters.AddWithValue("@name", student.Name);
        sqlCourseCommand.Parameters.AddWithValue("@type", type);

        int added = 0;

        try
        {
            connection.Open();
            added = sqlCourseCommand.ExecuteNonQuery();
        }
        catch (Exception)
        {
            throw;
        }
        finally
        {
            connection.Close();
        }
    }
예제 #2
0
    public static void addRegistration(Student student, CourseOffering courseOffering)
    {
        string insertRegistrationSQL = "INSERT INTO Registration " + "(Student_StudentNum, CourseOffering_Course_CourseID, CourseOffering_Year, CourseOffering_Semester) " + "VALUES (@studentNum, @courseID, @year, @semester)";

        SqlConnection connection       = new SqlConnection(connectionString);
        SqlCommand    sqlCourseCommand = new SqlCommand(insertRegistrationSQL, connection);
        string        type             = StudentType.getStudentType(student);

        sqlCourseCommand.Parameters.AddWithValue("@studentNum", student.Number);
        sqlCourseCommand.Parameters.AddWithValue("@courseID", courseOffering.CourseOffered.CourseNumber);
        sqlCourseCommand.Parameters.AddWithValue("@year", courseOffering.Year);
        sqlCourseCommand.Parameters.AddWithValue("@semester", courseOffering.Semester);

        int added = 0;

        try
        {
            connection.Open();
            added = sqlCourseCommand.ExecuteNonQuery();
        }
        catch (Exception)
        {
            throw;
        }
        finally
        {
            connection.Close();
        }
    }
예제 #3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        List <Course> userCourse = CourseDataAccess.retreiveAllCourses();

        int j = userCourse.Count - 1;

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

        List <Student> getStudents = StudentDataAccess.retreiveAllStudents();

        if (coursesOffered.Count == 0)
        {
            Panel1.Visible = true;
            Panel2.Visible = false;
        }
        else
        {
            CourseOffering workingCourse = new CourseOffering(userCourse[j], coursesOffered[i].Year, coursesOffered[i].Semester);
            workingCourse.AddStudents(getStudents);
            workingCourse.GetStudents().Sort();
            workingCourse.GetStudents().Sort(sortBy);
            string courseNumber = workingCourse.CourseOffered.CourseNumber;

            userCourse[j] = CourseDataAccess.retreiveCourseByCourseID(courseNumber);
            Page.Title    = userCourse[j].ToString();

            Panel1.Visible = false;
            Panel2.Visible = true;

            if (workingCourse.GetStudents().Count == 0)
            {
                TableRow  lastRow     = new TableRow();
                TableCell lastRowCell = new TableCell();
                lastRowCell.Text            = "There are currently no students enlisted";
                lastRowCell.ForeColor       = System.Drawing.Color.Red;
                lastRowCell.ColumnSpan      = 4;
                lastRowCell.HorizontalAlign = HorizontalAlign.Center;
                lastRow.Cells.Add(lastRowCell);
                tblStudentRecords.Rows.Add(lastRow);
            }
            else
            {
                foreach (Student student in workingCourse.GetStudents())
                {
                    {
                        TableRow row = new TableRow();

                        TableCell cell = new TableCell();
                        cell.Text = student.Number;
                        row.Cells.Add(cell);

                        cell      = new TableCell();
                        cell.Text = student.Name;
                        row.Cells.Add(cell);

                        string studentType = student.ToString();

                        cell      = new TableCell();
                        cell.Text = StudentType.getStudentType(student);
                        row.Cells.Add(cell);

                        cell = new TableCell();
                        double tuitonToPay        = student.TuitionPayable();
                        string stringTuitionToPay = tuitonToPay.ToString();
                        cell.Text = stringTuitionToPay;
                        row.Cells.Add(cell);

                        tblStudentRecords.Rows.Add(row);
                    }
                }
            }
        }
    }
예제 #4
0
    protected void Page_PreRender(object sender, EventArgs e)

    {
        if (!IsPostBack)
        {
            List <CourseOffering> ourCourses = CourseOfferingsDataAccess.retreiveAllCourses();
            ourCourses.Sort(sortOffering);

            foreach (CourseOffering course in ourCourses)
            {
                ListItem item = new ListItem(course.ToString(), course.CourseOffered.CourseNumber);
                ddlCourseOffering.Items.Add(item);
            }
        }

        if (IsPostBack)
        {
            List <CourseOffering> coursesOffered = CourseOfferingsDataAccess.retreiveAllCourses();
            int selectedIndex = ddlCourseOffering.SelectedIndex;

            List <Student> studentsInOfferingList = RegistrationDataAccess.getStudentsFromOffering(coursesOffered[selectedIndex]);
            studentsInOfferingList.Sort(sortBy);

            if (studentsInOfferingList.Count == 0)
            {
                TableRow  lastRow     = new TableRow();
                TableCell lastRowCell = new TableCell();
                lastRowCell.Text            = "There are currently no students enlisted";
                lastRowCell.ForeColor       = System.Drawing.Color.Red;
                lastRowCell.ColumnSpan      = 4;
                lastRowCell.HorizontalAlign = HorizontalAlign.Center;
                lastRow.Cells.Add(lastRowCell);
                tblStudentRecords.Rows.Add(lastRow);
            }
            else
            {
                foreach (Student student in studentsInOfferingList)
                {
                    {
                        TableRow row = new TableRow();

                        TableCell cell = new TableCell();
                        cell.Text = student.Number;
                        row.Cells.Add(cell);

                        cell      = new TableCell();
                        cell.Text = student.Name;
                        row.Cells.Add(cell);

                        string studentType = student.ToString();

                        cell      = new TableCell();
                        cell.Text = StudentType.getStudentType(student);
                        row.Cells.Add(cell);

                        tblStudentRecords.Rows.Add(row);
                    }
                }
            }
        }
    }