Example #1
0
        //=======================================
        //
        // <Summary>
        //      Method for updating the student
        //  record
        //
        //=======================================
        private void UpdateStudent()
        {
            string studentNumber = StudentNumber.Text;
            string lastName      = LastName.Text;
            string firstName     = FirstName.Text;
            string middleName    = MiddleName.Text;

            int    gender = -1;
            string g      = Gender.SelectedItem.ToString();

            if ("Male" == g)
            {
                gender = 1;
            }
            else
            {
                gender = 0;
            }

            string course = Courses.SelectedItem.ToString();
            string phone  = PhoneNumber.Text;
            string email  = EmailAddress.Text;

            if (AddStudentValidations.Validate(firstName, lastName, middleName, gender, course))
            {
                StudentsController.UpdateStudent(studentNumber, lastName, firstName, middleName, course, g);
                StudentsController.UpdateStudentContact(studentNumber, phone, email);
                this.DialogResult = DialogResult.OK;
            }
        }
Example #2
0
        private void studNo1_KeyDown(object sender, KeyEventArgs e)
        {
            string studentNumber = studNo1.Text;

            if (e.KeyCode == Keys.Enter)
            {
                if (AddStudentValidations.CheckStudentNumber(studentNumber))
                {
                    DisplayRecord(studentNumber);
                }
                else
                {
                    MessageBox.Show("Student Number not found");
                }
            }
        }
Example #3
0
        // Adding a student method
        private void AddStudent()
        {
            string studentNumber  = studnumbox.Text;
            string lastName       = lastNameBox.Text;
            string firstName      = firstNameBox.Text;
            string middleInitials = midNameBox.Text;
            int    gender         = GetGender();
            string courseCode     = course.Text;

            if (AddStudentValidations.Validate(studentNumber, firstName, lastName, middleInitials, gender, courseCode))
            {
                try
                {
                    StudentsController.AddStudentRecord(studentNumber, lastName, firstName, middleInitials, gender, courseCode);
                    this.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }
        //=====================================================
        // <Summary>
        //      Method for adding student's record
        //  then save it in the database
        //=====================================================
        #region AddStudentRecord(string studentNumber, string lastName, string firstName, string middleInitials, int gender, string courseCode, string phone, string email)
        public static void AddStudentRecord(string studentNumber, string lastName, string firstName, string middleInitials, int gender, string courseCode, string phone, string email)
        {
            Connection.OpenConnection();

            using (SqlCommand cmd = Connection.conn.CreateCommand())
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "Add_Students_StudentsInfo";

                cmd.Parameters.AddWithValue("@studentId", SqlDbType.VarChar).Value      = studentNumber;
                cmd.Parameters.AddWithValue("@lastName", SqlDbType.VarChar).Value       = lastName;
                cmd.Parameters.AddWithValue("@firstName", SqlDbType.VarChar).Value      = firstName;
                cmd.Parameters.AddWithValue("@middleInitials", SqlDbType.VarChar).Value = middleInitials;
                cmd.Parameters.AddWithValue("@gender", SqlDbType.Bit).Value             = gender;
                cmd.Parameters.AddWithValue("@courseCode", SqlDbType.VarChar).Value     = courseCode;
                cmd.Parameters.AddWithValue("@phone", SqlDbType.VarChar).Value          = phone;
                cmd.Parameters.AddWithValue("@email", SqlDbType.VarChar).Value          = email;

                if (Connection.conn.State == ConnectionState.Closed)
                {
                    Connection.conn.Open();
                }

                try
                {
                    if (AddStudentValidations.Validate(studentNumber, firstName, lastName, middleInitials, gender, courseCode))
                    {
                        cmd.ExecuteNonQuery();
                        MessageBox.Show("Student's record added successfully");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                Connection.conn.Close();
            }
        }
Example #5
0
        //=====================================
        //
        // <Sumarry>
        //      Method to Add Student records
        //
        //=====================================
        private void AddStudent()
        {
            string studentNumber = StudentNumber.Text;
            string lastName      = LastName.Text;
            string firstName     = FirstName.Text;
            string middleName    = MiddleName.Text;
            int    gender        = GetGender();
            string course        = "";

            if (Courses.SelectedItem != null)
            {
                course = Courses.SelectedItem.ToString();
            }

            // For the contacts field
            string phone = PhoneNumber.Text;
            string email = EmailAddress.Text;

            if (AddStudentValidations.Validate(studentNumber, firstName, lastName, middleName, gender, course))
            {
                StudentsController.AddStudentRecord(studentNumber, lastName, firstName, middleName, gender, course, phone, email);
                this.DialogResult = DialogResult.OK;
            }
        }