예제 #1
0
        protected void saveButton_Click(object sender, EventArgs e)
        {
            Student aStudent = new Student();
            aStudent.name = nameTextBox.Text;
            aStudent.email = emailTextBox.Text;
            aStudent.regNo = regNoTextBox.Text;
            if (ViewState["student"] != null)
            {
                List<Student> studentList = (List < Student >) ViewState["student"];
                if (studentList.Count < 3)
                {
                    studentList.Add(aStudent);
                }
                else
                {
                    Response.Write("3 student already exists<br/><br/>");
                }

            }
            else
            {
                List<Student> list = new List<Student>();
                list.Add(aStudent);
                ViewState["student"] = list;
            }
        }
예제 #2
0
        //------------------------------------------------------------------------------------
        //Procedure: AddStudent
        //Purpose:   Provides core functionality for adding a student record
        //           Used by Insert button.
        //Accepts:   NA
        //Returns:   NA
        private void AddStudent()
        {
            Student newStudent = new Student();

            newStudent.ID = Int32.Parse(txtStudentID.Text.Trim());
            newStudent.Name = txtStudentName.Text;
            newStudent.Department = txtDepartment.Text;
            newStudent.Major = txtMajor.Text;
            newStudent.Semester = Int32.Parse(txtSemester.Text.Trim());

            aStudents.Add(newStudent);
        }
예제 #3
0
        static void Main(string[] args)
        {
            Student firstStudentObject = new Student();
          
            firstStudentObject.StudentLastName = AskForStudentName("Last");
            firstStudentObject.StudentFirstName = AskForStudentName("First");
            firstStudentObject.StudentNumber = AskForStudentNumber();
            firstStudentObject.Major = AskForMajor(firstStudentObject.StudentFirstName);
            firstStudentObject.Score1 = AskForExamScore(1);
            firstStudentObject.Score2 = AskForExamScore(2);
            firstStudentObject.Score3 = AskForExamScore(3);

            Console.Clear();
            Console.WriteLine("First Student");
            Console.WriteLine(firstStudentObject.ToString());


            Student secondStudentObject = new Student("2345");
            secondStudentObject.Score1 = 95;
            secondStudentObject.Score2 = 62;
            secondStudentObject.Score3 = 87;
            Console.WriteLine("\n\nSecond Student");
            Console.WriteLine("Student Number: " + secondStudentObject.StudentNumber +
                               "\nAverage: {0:F1}", secondStudentObject.CalculateAverage());


            Student thirdStudentObject = new Student("5432", "Randolph",  "Wonder");
            thirdStudentObject.Major = "Math";
            thirdStudentObject.Score1 = 95;
            thirdStudentObject.Score2 = 87;
            thirdStudentObject.Score3 = 72;
            Console.WriteLine("\n\nThird Student");
            Console.WriteLine(thirdStudentObject);


            Student aStudentObject = new Student("1234", "Maria", "Smith", 97, 75, 87, "CS");
            Console.WriteLine("\n\nLast Student");
            Console.WriteLine("Student Name: " + aStudentObject.StudentFirstName +
                              " " + aStudentObject.StudentLastName +
                              "\nStudent Number: " + aStudentObject.StudentNumber +
                              "\nMajor: " + aStudentObject.Major +
                              "\nExam Score 1: " + aStudentObject.Score1 +
                              "\nExam Score 2: " + aStudentObject.Score2 +
                              "\nExam Score 3: " + aStudentObject.Score3 +
                              "\nExam Average: " + aStudentObject.CalculateAverage().ToString("F1"));
            Console.ReadKey();
        }
예제 #4
0
 //------------------------------------------------------------------------------------
 //Procedure: UpdateStudent
 //Purpose:   Provides core functionality for updating a student record
 //           Used by Insert and Update buttons.
 //Accepts:   ref Student objStudent: student record to update
 //Returns:   NA
 private void UpdateStudent(ref Student objStudent)
 {
     objStudent.Name = txtStudentName.Text;
     objStudent.Department = txtDepartment.Text;
     objStudent.Major = txtMajor.Text;
     objStudent.Semester = Int32.Parse(txtSemester.Text.Trim());
 }
예제 #5
0
 //------------------------------------------------------------------------------------
 //Procedure: GetCurrentStudent
 //Purpose:   Gets the student record for the currently entered ID
 //           Used by Search, Next and Previous buttons.
 //Accepts:   out Student objStudent: Student object that was found
 //Returns:   True if success, False if not
 private Boolean GetCurrentStudent(out Student objStudent)
 {
     if (ValidateID(txtStudentID.Text) == true)
     {
         if (FindStudent(txtStudentID.Text, out objStudent) == true)
         {
             return true;
         }
         else
         {
             MessageBox.Show(this, String.Format("An existing student record was not found for ID: {0}", txtStudentID.Text),"Student Not Found", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             return false;
         }
     }
     else
     {
         objStudent = null;
         return false;
     }
 }
예제 #6
0
        //------------------------------------------------------------------------------------
        //Procedure: FindStudent
        //Purpose:   Provides core functionality for finding a student record
        //           Used by Insert, Update, Delete and Search buttons.
        //Accepts:   string strID: ID of student record to find
        //           out Student objStudent: Student object that was found
        //Returns:   True if Student was found, False if not
        private Boolean FindStudent(string strID, out Student objStudent)
        {
            int intID;

            intID = Int32.Parse(strID.Trim());

            foreach (Student s in aStudents)
            {
                if (s.ID == intID)
                {
                    objStudent = s;
                    return true;
                }
            }

            objStudent = null;
            return false;
        }
예제 #7
0
 //------------------------------------------------------------------------------------
 //Procedure: DisplayStudent
 //Purpose:   Provides core functionality for displaying a student record
 //           Used by Search, Next and Previous buttons.
 //Accepts:   ref Student objStudent: student record to update
 //Returns:   NA
 private void DisplayStudent(ref Student objStudent)
 {
     txtStudentID.Text = objStudent.ID.ToString();
     txtStudentName.Text = objStudent.Name;
     txtDepartment.Text = objStudent.Department;
     txtMajor.Text = objStudent.Major;
     txtSemester.Text = objStudent.Semester.ToString();
 }
예제 #8
0
 //------------------------------------------------------------------------------------
 //Procedure: DeleteStudent
 //Purpose:   Deletes a student record
 //           Used by Delete button.
 //Accepts:   ref Student objStudent: student record to delete
 //Returns:   NA
 private void DeleteStudent(ref Student objStudent)
 {
     aStudents.Remove(objStudent);
 }
예제 #9
0
        private void btnPrevious_Click(object sender, EventArgs e)
        {
            Student objStudent;
            Student previousStudent;
            int intPreviousIndex;

            if (GetCurrentStudent(out objStudent))
            {
                intPreviousIndex = aStudents.IndexOf(objStudent);
                intPreviousIndex--;

                //Check if index is before BOF
                if (intPreviousIndex < 0)
                {
                    //just display the current record
                    DisplayStudent(ref objStudent);
                    MessageBox.Show(this, "The beginning of the file has been reached.", "BOF Reached", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                }
                else
                {
                    //Display the previous record
                    previousStudent = new Student();
                    previousStudent = (Student)aStudents[intPreviousIndex];
                    DisplayStudent(ref previousStudent);
                }
            }
        }
예제 #10
0
        private void btnNext_Click(object sender, EventArgs e)
        {
            Student objStudent;
            Student nextStudent;
            int intNextIndex;

            if (GetCurrentStudent(out objStudent))
            {
                intNextIndex = aStudents.IndexOf(objStudent);
                intNextIndex++;

                //Check if index is past EOF
                if (intNextIndex > (aStudents.Count - 1))
                {
                    //just display the current record
                    DisplayStudent(ref objStudent);
                    MessageBox.Show(this, "The end of the file has been reached.", "EOF Reached", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                }
                else
                {
                    //Display the next record
                    nextStudent = new Student();
                    nextStudent = (Student)aStudents[intNextIndex];
                    DisplayStudent(ref nextStudent);
                }
            }
        }
예제 #11
0
        static void Main()
        {
            // Create a student object, populating its StudentFirstName, StudentLastName, and StudentNumber properties from static prompt methods of StudentApp class. 
            Student firstStudentObject = new Student
            {
                StudentFirstName = AskForStudentName("First"),
                StudentLastName = AskForStudentName("Last"),
                StudentNumber = AskForStudentNumber()
            };
            firstStudentObject.Major = AskForMajor(firstStudentObject.StudentFirstName);
            firstStudentObject.Score1 = AskForExamScore(1);
            firstStudentObject.Score2 = AskForExamScore(2);
            firstStudentObject.Score3 = AskForExamScore(3);

            // Working with added property.
            while (true)
            {
                WriteLine("Enter your expected date of graduation");
                string graduationDateString = ReadLine();
                if (DateTime.TryParse(graduationDateString, out DateTime graduationDate))
                {
                    firstStudentObject.GraduationDate = graduationDate;
                    break;
                }
                else
                {
                    WriteLine("You must enter a valid month, day, and year. Try again");
                }
            }

            // Clear the screen
            Clear();

            // Using the override of the ToString() method, write a student's information. 
            WriteLine("First Student");
            WriteLine(firstStudentObject.ToString());

            // Create a second student object using one-argument constructor. 
            Student secondStudentObject = new Student("2345")
            {
                Score1 = 95,
                Score2 = 62,
                Score3 = 87
            };
            // Use the Console.WriteLine method, concatenation, and the second student's ID number and average to one decimal point into a string displayed on the console."
            WriteLine("\n\nSecond Student");
            WriteLine("Student Number: " + secondStudentObject.StudentNumber +
                               "\nAverage: {0:F1}", secondStudentObject.CalculateAverage());


            // Create a third object using three-argument constructor.
            Student thirdStudentObject = new Student("5432", "Randolph", "Wonder")
            {
                Major = "Math",
                Score1 = 95,
                Score2 = 87,
                Score3 = 72
            };
            WriteLine("\n\nThird Student");
            WriteLine(thirdStudentObject);

            // Create an object using a seven-argument constructor, then write each of its properties to the console using string concatenation.
            Student aStudentObject = new Student("1234", "Maria", "Smith", 97, 75, 87, "CS");
            WriteLine("\n\nLast Student");
            WriteLine("Student Name: " + aStudentObject.StudentFirstName +
                              " " + aStudentObject.StudentLastName +
                              "\nStudent Number: " + aStudentObject.StudentNumber +
                              "\nMajor: " + aStudentObject.Major +
                              "\nExam Score 1: " + aStudentObject.Score1 +
                              "\nExam Score 2: " + aStudentObject.Score2 +
                              "\nExam Score 3: " + aStudentObject.Score3 +
                              "\nExam Average: " + aStudentObject.CalculateAverage().ToString("F1"));
            ReadKey();
        }
예제 #12
0
 public void AddStudents(Student student)
 {
     _studentList.Add(student);
     Save();
 }