示例#1
0
        // When the user presses a key, determine whether to add a new student to a class, remove a student from a class, or modify the details of a student
        private void studentsList_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
                // If the user pressed Enter, edit the details for the currently selected student
                case Key.Enter: Student student = this.studentsList.SelectedItem as Student;

                    // Use the StudentsForm to display and edit the details of the student
                    StudentForm sf = new StudentForm();

                    // Set the title of the form and populate the fields on the form with the details of the student
                    sf.Title = "Edit Student Details";
                    sf.firstName.Text = student.FirstName;
                    sf.lastName.Text = student.LastName;
                    sf.dateOfBirth.Text = student.DateOfBirth.ToString("d"); // Format the date to omit the time element

                    // Display the form
                    if (sf.ShowDialog().Value)
                    {
                        // When the user closes the form, copy the details back to the student
                        student.FirstName = sf.firstName.Text;
                        student.LastName = sf.lastName.Text;
                        student.DateOfBirth = DateTime.Parse(sf.dateOfBirth.Text);

                        // Enable saving (changes are not made permanent until they are written back to the database)
                        saveChanges.IsEnabled = true;
                    }
                    break;

                // If the user pressed Insert, add a new student
                case Key.Insert:

                    // Use the StudentsForm to get the details of the student from the user
                    sf = new StudentForm();

                    // Set the title of the form to indicate which class the student will be added to (the class for the currently selected teacher)
                    sf.Title = "New Student for Class " + teacher.Class;

                    // Display the form and get the details of the new student
                    if (sf.ShowDialog().Value)
                    {
                        // When the user closes the form, retrieve the details of the student from the form
                        // and use them to create a new Student object
                        Student newStudent = new Student();
                        newStudent.FirstName = sf.firstName.Text;
                        newStudent.LastName = sf.lastName.Text;
                        newStudent.DateOfBirth = DateTime.Parse(sf.dateOfBirth.Text);

                        // Assign the new student to the current teacher
                        this.teacher.Students.Add(newStudent);

                        // Add the student to the list displayed on the form
                        this.studentsInfo.Add(newStudent);

                        // Enable saving (changes are not made permanent until they are written back to the database)
                        saveChanges.IsEnabled = true;
                    }
                    break;
            }
        }
示例#2
0
        // When the user presses a key, determine whether to add a new student to a class, remove a student from a class, or modify the details of a student
        private void studentsList_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
                // If the user pressed Enter, edit the details for the currently selected student
                case Key.Enter: Student student = this.studentsList.SelectedItem as Student;

                    // Use the StudentsForm to display and edit the details of the student
                    StudentForm sf = new StudentForm();

                    // Set the title of the form and populate the fields on the form with the details of the student
                    sf.Title = "Edit Student Details";
                    sf.firstName.Text = student.FirstName;
                    sf.lastName.Text = student.LastName;
                    sf.dateOfBirth.Text = student.DateOfBirth.ToString("d"); // Format the date to omit the time element

                    // Display the form
                    if (sf.ShowDialog().Value)
                    {
                        // When the user closes the form, copy the details back to the student
                        student.FirstName = sf.firstName.Text;
                        student.LastName = sf.lastName.Text;
                        student.DateOfBirth = DateTime.Parse(sf.dateOfBirth.Text);

                        // Enable saving (changes are not made permanent until they are written back to the database)
                        saveChanges.IsEnabled = true;
                    }
                    break;
            }
        }
示例#3
0
        // When the user presses a key, determine whether to add a new student to a class, remove a student from a class, or modify the details of a student
        private void studentsList_KeyDown(object sender, KeyEventArgs e)
        {
            Student student;
            StudentForm sf = new StudentForm();

            switch(e.Key)
            {
                case Key.Enter: // TODO: Exercise 1: Task 1a: If the user pressed Enter, edit the details for the currently selected student
                    student = this.studentsList.SelectedItem as Student;

                    sf.Title = "Edit Student Details";
                    sf.firstName.Text = student.FirstName;
                    sf.lastName.Text = student.LastName;
                    sf.dateOfBirth.Text = student.DateOfBirth.ToString("d");

                    if(sf.ShowDialog().Value)
                    {
                        student.FirstName = sf.firstName.Text;
                        student.FirstName = sf.lastName.Text;
                        sf.dateOfBirth.Text = student.DateOfBirth.ToString("d");

                        saveChanges.IsEnabled = true;
                    }
                    break;
                case Key.Insert:
                    student = new Student();

                    break;
                case Key.Delete:
                    student = this.studentsList.SelectedItem as Student;

                    break;
            // TODO: Exercise 1: Task 2a: Use the StudentsForm to display and edit the details of the student
            // TODO: Exercise 1: Task 2b: Set the title of the form and populate the fields on the form with the details of the student
            // TODO: Exercise 1: Task 3a: Display the form
            // TODO: Exercise 1: Task 3b: When the user closes the form, copy the details back to the student
            // TODO: Exercise 1: Task 3c: Enable saving (changes are not made permanent until they are written back to the database)
            }
        }
示例#4
0
        // Edit the details of a student
        private void editStudent(Student student)
        {
            // Use the StudentsForm to display and edit the details of the student
            StudentForm sf = new StudentForm();

            // Set the title of the form and populate the fields on the form with the details of the student
            sf.Title            = "Edit Student Details";
            sf.firstName.Text   = student.FirstName;
            sf.lastName.Text    = student.LastName;
            sf.dateOfBirth.Text = student.DateOfBirth.ToString("d"); // Format the date to omit the time element

            // Display the form
            if (sf.ShowDialog().Value)
            {
                // When the user closes the form, copy the details back to the student
                student.FirstName   = sf.firstName.Text;
                student.LastName    = sf.lastName.Text;
                student.DateOfBirth = DateTime.Parse(sf.dateOfBirth.Text);

                // Enable saving (changes are not made permanent until they are written back to the database)
                saveChanges.IsEnabled = true;
            }
        }
        // When the user presses a key, determine whether to add a new student to a class, remove a student from a class, or modify the details of a student
        private void studentsList_KeyDown(object sender, KeyEventArgs e)
        {
            Student student = null;
            // TODO: Exercise 1: Task 1a: If the user pressed Enter, edit the details for the currently selected student
            switch (e.Key)
            {
                case Key.Enter:
                    student = this.studentsList.SelectedItem as Student;  //(Student)studentsList.SelectedItem;//(Student)((ListView)sender).SelectedItem;
                    break;

                default:
                    break;
            }
            // TODO: Exercise 1: Task 2a: Use the StudentsForm to display and edit the details of the student
            StudentForm sf = new StudentForm();
            sf.firstName.Text = student.FirstName;
            sf.lastName.Text = student.LastName;
            sf.dateOfBirth.Text = student.DateOfBirth.ToString("d");

            // TODO: Exercise 1: Task 2b: Set the title of the form and populate the fields on the form with the details of the student
            sf.Title = "Edit Student Details";

            // TODO: Exercise 1: Task 3a: Display the form
            //sf.ShowDialog();
            // TODO: Exercise 1: Task 3b: When the user closes the form, copy the details back to the student
            if (sf.ShowDialog().Value)
            {
                student.FirstName = sf.firstName.Text;
                student.LastName = sf.lastName.Text;
                student.DateOfBirth = DateTime.Parse(sf.dateOfBirth.Text);
                saveChanges.IsEnabled = true;
            }
            // TODO: Exercise 1: Task 3c: Enable saving (changes are not made permanent until they are written back to the database)
            //saveChanges.IsEnabled = true;
            
        }
示例#6
0
        private void AddNewStudent()
        {
            Student     studentNew = new Student();
            StudentForm sfNew      = new StudentForm();

            sfNew.Title            = "Edit Student Details";
            sfNew.firstName.Text   = studentNew.FirstName;
            sfNew.lastName.Text    = studentNew.LastName;
            sfNew.dateOfBirth.Text = studentNew.DateOfBirth.ToString("d"); // Format the date to omit the time element
            if (sfNew.ShowDialog().Value)
            {
                if (sfNew.firstName.Text == "")
                {
                    MessageBox.Show("U moet een naam ingeven");
                    AddNewStudent();
                }
                studentNew.FirstName   = sfNew.firstName.Text;
                studentNew.LastName    = sfNew.lastName.Text;
                studentNew.DateOfBirth = DateTime.Parse(sfNew.dateOfBirth.Text, CultureInfo.InvariantCulture);
                // Enable saving (changes are not made permanent until they are written back to the database)
                saveChanges.IsEnabled = true;
                studentsInfo.Add(studentNew);
            }
        }
示例#7
0
        // When the user presses a key, determine whether to add a new student to a class, remove a student from a class, or modify the details of a student
        private void studentsList_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
            // If the user pressed Enter, edit the details for the currently selected student
            case Key.Enter: Student student = this.studentsList.SelectedItem as Student;
                // Use the StudentsForm to display and edit the details of the student
                StudentForm sf = new StudentForm();
                // Set the title of the form and populate the fields on the form with the details of the student
                sf.Title            = "Edit Student Details";
                sf.firstName.Text   = student.FirstName;
                sf.lastName.Text    = student.LastName;
                sf.dateOfBirth.Text = student.DateOfBirth.ToString("d");     // Format the date to omit the time element
                // Display the form
                if (sf.ShowDialog().Value)
                {
                    // When the user closes the form, copy the details back to the student
                    student.FirstName   = sf.firstName.Text;
                    student.LastName    = sf.lastName.Text;
                    student.DateOfBirth = DateTime.Parse(sf.dateOfBirth.Text, CultureInfo.InvariantCulture);
                    // Enable saving (changes are not made permanent until they are written back to the database)
                    saveChanges.IsEnabled = true;
                }
                break;

            // If the user pressed Insert, add a new student
            case Key.Insert:
                // Use the StudentsForm to get the details of the student from the user
                sf = new StudentForm();
                // Set the title of the form to indicate which class the student will be added to (the class for the currently selected teacher)
                sf.Title = "New Student for Class " + teacher.Class;
                // Display the form and get the details of the new student
                if (sf.ShowDialog().Value)
                {
                    // When the user closes the form, retrieve the details of the student from the form
                    // and use them to create a new Student object
                    Student newStudent = new Student();
                    newStudent.FirstName   = sf.firstName.Text;
                    newStudent.LastName    = sf.lastName.Text;
                    newStudent.DateOfBirth = DateTime.Parse(sf.dateOfBirth.Text, CultureInfo.InvariantCulture);
                    // Assign the new student to the current teacher
                    this.teacher.Students.Add(newStudent);

                    // Add the student to the list displayed on the form
                    this.studentsInfo.Add(newStudent);

                    // Enable saving (changes are not made permanent until they are written back to the database)
                    saveChanges.IsEnabled = true;
                }
                break;

            // TODO: Exercise 3: Task 1a: If the user pressed Delete, remove the currently selected student
            case Key.Delete: student = this.studentsList.SelectedItem as Student;
                // TODO: Exercise 3: Task 2a: Prompt the user to confirm that the student should be removed
                MessageBoxResult response = MessageBox.Show(
                    string.Format("Remove {0}", student.FirstName + " " + student.LastName),
                    "Confirm",
                    MessageBoxButton.YesNo,
                    MessageBoxImage.Question,
                    MessageBoxResult.No);
                // TODO: Exercise 3: Task 3a: If the user clicked Yes, remove the student from the database
                if (response == MessageBoxResult.Yes)
                {
                    this.schoolContext.Students.DeleteObject(student);
                    // TODO: Exercise 3: Task 3b: Enable saving (changes are not made permanent until they are written back to the database)
                    saveChanges.IsEnabled = true;
                }
                break;
            }
        }
示例#8
0
        // When the user presses a key, determine whether to add a new student to a class, remove a student from a class, or modify the details of a student
        private void studentsList_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
                // If the user pressed Enter, edit the details for the currently selected student
                case Key.Enter: Student student = this.studentsList.SelectedItem as Student;

                    // Use the StudentsForm to display and edit the details of the student
                    StudentForm sf = new StudentForm();

                    // Set the title of the form and populate the fields on the form with the details of the student
                    sf.Title = "Edit Student Details";
                    sf.firstName.Text = student.FirstName;
                    sf.lastName.Text = student.LastName;
                    sf.dateOfBirth.Text = student.DateOfBirth.ToString("d"); // Format the date to omit the time element

                    // Display the form
                    if (sf.ShowDialog().Value)
                    {
                        // When the user closes the form, copy the details back to the student
                        student.FirstName = sf.firstName.Text;
                        student.LastName = sf.lastName.Text;
                        student.DateOfBirth = DateTime.Parse(sf.dateOfBirth.Text);

                        // Enable saving (changes are not made permanent until they are written back to the database)
                        saveChanges.IsEnabled = true;
                    }
                    break;

                // If the user pressed Insert, add a new student
                case Key.Insert:

                    // Use the StudentsForm to get the details of the student from the user
                    sf = new StudentForm();

                    // Set the title of the form to indicate which class the student will be added to (the class for the currently selected teacher)
                    sf.Title = "New Student for Class " + teacher.Class;

                    // Display the form and get the details of the new student
                    if (sf.ShowDialog().Value)
                    {
                        // When the user closes the form, retrieve the details of the student from the form
                        // and use them to create a new Student object
                        Student newStudent = new Student();
                        newStudent.FirstName = sf.firstName.Text;
                        newStudent.LastName = sf.lastName.Text;
                        newStudent.DateOfBirth = DateTime.Parse(sf.dateOfBirth.Text);

                        // Assign the new student to the current teacher
                        this.teacher.Students.Add(newStudent);

                        // Add the student to the list displayed on the form
                        this.studentsInfo.Add(newStudent);

                        // Enable saving (changes are not made permanent until they are written back to the database)
                        saveChanges.IsEnabled = true;
                    }
                    break;

                // If the user pressed Delete, remove the currently selected student
                case Key.Delete: student = this.studentsList.SelectedItem as Student;

                    // Prompt the user to confirm that the student should be removed
                    MessageBoxResult response = MessageBox.Show(
                        String.Format("Remove {0}", student.FirstName + " " + student.LastName),
                        "Confirm", MessageBoxButton.YesNo, MessageBoxImage.Question,
                        MessageBoxResult.No);

                    // If the user clicked Yes, remove the student from the database
                    if (response == MessageBoxResult.Yes)
                    {
                        this.schoolContext.Students.DeleteObject(student);

                        // Enable saving (changes are not made permanent until they are written back to the database)
                        saveChanges.IsEnabled = true;
                    }
                    break;
            }
        }
示例#9
0
        // When the user presses a key, determine whether to add a new student to a class, remove a student from a class, or modify the details of a student
        private void studentsList_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
            // If the user pressed Enter, edit the details for the currently selected student
            case Key.Enter: Student student = this.studentsList.SelectedItem as Student;

                // Use the StudentsForm to display and edit the details of the student
                StudentForm sf = new StudentForm();

                // Set the title of the form and populate the fields on the form with the details of the student
                sf.Title            = "Edit Student Details";
                sf.firstName.Text   = student.FirstName;
                sf.lastName.Text    = student.LastName;
                sf.dateOfBirth.Text = student.DateOfBirth.ToString("d");     // Format the date to omit the time element

                // Display the form
                if (sf.ShowDialog().Value)
                {
                    // When the user closes the form, copy the details back to the student
                    student.FirstName   = sf.firstName.Text;
                    student.LastName    = sf.lastName.Text;
                    student.DateOfBirth = DateTime.Parse(sf.dateOfBirth.Text);

                    // Enable saving (changes are not made permanent until they are written back to the database)
                    saveChanges.IsEnabled = true;
                }
                break;

            // TODO: Exercise 2: Task 1a: If the user pressed Insert, add a new student
            case Key.Insert:

                // TODO: Exercise 2: Task 2a: Use the StudentsForm to get the details of the student from the user
                sf = new StudentForm();

                // TODO: Exercise 2: Task 2b: Set the title of the form to indicate which class the student will be added to (the class for the currently selected teacher)
                sf.Title = "New Student for Class" + teacher.Class;

                // TODO: Exercise 2: Task 3a: Display the form and get the details of the new student
                if (sf.ShowDialog().Value)
                {
                    // TODO: Exercise 2: Task 3b: When the user closes the form, retrieve the details of the student from the form and use them to create a new Student object
                    Student newStudent = new Student();
                    newStudent.FirstName   = sf.firstName.Text;
                    newStudent.LastName    = sf.lastName.Text;
                    newStudent.DateOfBirth = DateTime.Parse(sf.dateOfBirth.Text);

                    // TODO: Exercise 2: Task 4a: Assign the new student to the current teacher
                    this.teacher.Students.Add(newStudent);

                    // TODO: Exercise 2: Task 4b: Add the student to the list displayed on the form
                    this.studentsInfo.Add(newStudent);

                    // TODO: Exercise 2: Task 4c: Enable saving (changes are not made permanent until they are written back to the database)
                    saveChanges.IsEnabled = true;
                }


                break;
            }
        }