Exemple #1
0
        /// <summary>
        /// Check if fields are empty
        /// if not inser new row into database
        /// if error appears, catch it
        /// </summary>
        private void btnAddSaveCandidate_Click(object sender, EventArgs e)
        {
            DataRow newCandidateRow = DM.dtCandidate.NewRow();

            if ((txtAddFirstName.Text == "") || (txtAddLastName.Text == "") || (txtAddStreetAddress.Text == "") || (txtAddSuburb.Text == "") || (txtAddPhoneNumber.Text == ""))
            {
                MessageBox.Show("You must ype in an candidate first name, last name, street address, suburb and phone number.");
            }
            else
            {
                try
                {
                    newCandidateRow["LastName"]      = txtAddLastName.Text;
                    newCandidateRow["FirstName"]     = txtAddFirstName.Text;
                    newCandidateRow["StreetAddress"] = txtAddStreetAddress.Text;
                    newCandidateRow["Suburb"]        = txtAddSuburb.Text;
                    newCandidateRow["PhoneNumber"]   = txtAddPhoneNumber.Text;
                    DM.dtCandidate.Rows.Add(newCandidateRow);
                    MessageBox.Show("Candidate Added Successfully", "Success");
                    DM.UpdateCandidate();
                }
                catch
                {
                    MessageBox.Show("Please Enter The Proper type for each fields");
                }
            }
        }