private void btnSubmit_Click(object sender, EventArgs e) { validation.Clear(); info.firstName = txtFirstName.Text.Trim(); validation.Add(info.StringValidation(info.firstName, txtFirstName, epFirstName)); info.surname = txtSurname.Text.Trim(); validation.Add(info.StringValidation(info.surname, txtSurname, epSurname)); info.email = txtEmail.Text.Trim(); validation.Add(info.BlanksValidation(info.email, txtEmail, epEmail)); info.phone = txtPhone.Text.Trim(); validation.Add(info.BlanksValidation(info.phone, txtPhone, epPhone)); info.addressLine1 = txtAddress1.Text.Trim(); validation.Add(info.BlanksValidation(info.addressLine1, txtAddress1, epAddressLine1)); info.addressLine2 = txtAddress2.Text.Trim(); validation.Add(info.BlanksValidation(info.addressLine2, txtAddress2, epAddressLine2)); info.city = txtCity.Text.Trim(); validation.Add(info.BlanksValidation(info.city, txtCity, epCity)); info.county = cbCounty.Text; validation.Add(info.ComboBoxValidation(cbCounty, epCounty)); if (rbPostgrad.Checked == true) { level = "Postgraduate"; } else { level = "Undergraduate"; } info.level = level; info.course = cbCourse.Text; validation.Add(info.ComboBoxValidation(cbCourse, epCourse)); int.TryParse(txtStudentNumber.Text, out studentNumber); info.studentNumber = studentNumber; validation.Add(info.IntValidation(studentNumber, txtStudentNumber, epStudentId)); dt = opr.StudentSearch(info); if (dt.Rows.Count < 1 && !validation.Contains(false)) { //MessageBox.Show("Student does not exist"); int rows = opr.InsertData(info); if (rows > 0) { MessageBox.Show("Student entered successfully"); cbCounty.SelectedIndex = -1; cbCourse.SelectedIndex = -1; ClearTextBoxes(this.Controls); } } else if (dt.Rows.Count > 0) { MessageBox.Show("Student with id " + studentNumber + " already exists. Please try again."); } }
private void btnUpdate_Click(object sender, EventArgs e) { validation.Clear(); info.email = txtEmail.Text.Trim(); validation.Add(info.BlanksValidation(info.email, txtEmail, epEmail)); info.phone = txtPhone.Text.Trim(); validation.Add(info.BlanksValidation(info.phone, txtPhone, epPhone)); info.addressLine1 = txtAddress1.Text.Trim(); validation.Add(info.BlanksValidation(info.addressLine1, txtAddress1, epAddressLine1)); info.addressLine2 = txtAddress2.Text.Trim(); validation.Add(info.BlanksValidation(info.addressLine2, txtAddress2, epAddressLine2)); info.city = txtCity.Text.Trim(); validation.Add(info.BlanksValidation(info.city, txtCity, epCity)); info.county = cbCounty.Text; validation.Add(info.ComboBoxValidation(cbCounty, epCounty)); if (rbPostgrad.Checked == true) { level = "Postgraduate"; } else { level = "Undergraduate"; } info.level = level; if (!validation.Contains(false)) { int rows = opr.UpdateStudentDetails(info); MessageBox.Show("Student updated successfully"); gbStudentData.Visible = false; } }