/*
         * Pre:
         * Post: Determines whether or not the student being added is a duplicate
         * @returns true if the student is a duplicate and false otherwise
         */
        private bool studentIsDuplicate(string firstName, string lastName)
        {
            bool duplicate = false;

            DataTable duplicateStudentsTbl = DbInterfaceStudent.StudentExists(firstName, lastName);

            if (duplicateStudentsTbl != null && duplicateStudentsTbl.Rows.Count > 0)
            {
                duplicate = true;
            }

            return(duplicate);
        }
Exemple #2
0
        /*
         * Pre:
         * Post: If the user has entered valid information, the new student information is added
         *       to the database.  If no previous teacher id is entered, the value is set to "0".
         *       If the add is successful, the new student's id number will be displayed to the user,
         *       otherwise an error message will take its place.
         */
        private bool AddNewStudent()
        {
            bool result = true;

            //if the entered information is valid, add the new student
            if (verifyInformation())
            {
                int    districtId, legacyPoints = 0, currTeacherId, prevTeacherId = 0;
                string firstName, middleInitial, lastName, grade;

                firstName     = txtFirstName.Text;
                middleInitial = txtMiddleInitial.Text;
                lastName      = txtLastName.Text;
                grade         = txtGrade.Text;
                districtId    = Convert.ToInt32(cboDistrict.SelectedValue);
                currTeacherId = Convert.ToInt32(cboCurrTeacher.SelectedValue);
                if (!cboPrevTeacher.SelectedValue.ToString().Equals(""))
                {
                    prevTeacherId = Convert.ToInt32(cboPrevTeacher.SelectedValue);
                }
                if (!txtLegacyPoints.Text.Equals(""))
                {
                    legacyPoints = Convert.ToInt32(txtLegacyPoints.Text);
                }

                //check for duplicate students
                DataTable duplicateStudentsTbl = DbInterfaceStudent.StudentExists(firstName, lastName);
                if (checkedForDuplicate || duplicateStudentsTbl == null || duplicateStudentsTbl.Rows.Count <= 0)
                {
                    Student newStudent = new Student(-1, firstName, middleInitial, lastName, grade, districtId,
                                                     currTeacherId, prevTeacherId);
                    newStudent.legacyPoints = legacyPoints;

                    //add to database
                    newStudent.addToDatabase();

                    //get new id
                    if (newStudent.id != -1)
                    {
                        lblId.Text = newStudent.id.ToString();
                    }
                    else
                    {
                        lblError.Text    = "There was an error adding the new student";
                        lblError.Visible = true;
                        lblId.Text       = "Error Adding Student";
                        result           = false;
                    }

                    checkedForDuplicate = false;
                }
                else if (!checkedForDuplicate)
                {
                    pnlDuplicateStudent.Visible = true;
                    pnlFullPage.Visible         = false;
                    pnlButtons.Visible          = false;
                    result = false;
                }
            }
            else
            {
                result = false;
            }

            return(result);
        }