private void StudentForm_Load(object sender, EventArgs e) { clsStudent objStudent = new clsStudent(); ComboBox[] cmb = new ComboBox[] { cmbSuburbID, cmbSuburbName, cmbPostCode, cmbCountryID, cmbCountryName }; objStudent.Load(cmb); objStudent.ViewAll(dgvStudent); }
/// <summary> /// When the Delete menu item is clicked, a student object is created with only the ID field. /// This ID is passed to the DeleteStudent method which will run the procedure for deleting the student from the database. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void mnuDelete_Click(object sender, EventArgs e) { if (!clsValidation.ValidateTextBoxForNumeric(txtStudentID)) { txtStudentID.Focus(); return; } clsStudent objStudent = new clsStudent(Convert.ToInt32(txtStudentID.Text)); objStudent.Delete(); MessageBox.Show("Student record successfully deleted"); objStudent.ViewAll(dgvStudent); }
/// <summary> /// When the Update menu item is clicked, a student object is created with only the ID field. /// The SearchStudent method will use the ID from this object in the procedure in the database to find the right student. /// The values that are changed in the student class are passed to the form and all the fields are filled in. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSearch_Click(object sender, EventArgs e) { if (!clsValidation.ValidateTextBoxForNumeric(txtStudentID)) { txtStudentID.Focus(); return; } clsStudent objStudent = new clsStudent(Convert.ToInt32(txtStudentID.Text)); bool valid = objStudent.Search(); if (valid) { txtStudentFirstName.Text = objStudent.FirstName; txtStudentLastName.Text = objStudent.LastName; if (objStudent.Gender == "m" || objStudent.Gender == "M") { rdbMale.Checked = true; } else if (objStudent.Gender == "f" || objStudent.Gender == "F") { rdbFemale.Checked = true; } dtpDateOfBirth.Value = DateTime.Parse(objStudent.DateOfBirth); txtStudStreetAddress.Text = objStudent.StreetAddress; cmbSuburbID.Text = objStudent.SuburbID.ToString(); cmbSuburbName.Text = objStudent.SuburbName; cmbPostCode.Text = objStudent.PostCode; //txtStudPostCode.Text = objStudent.PostCode; txtStudentPhoneNum.Text = objStudent.PhoneNumber; txtStudentEmail.Text = objStudent.Email; cmbCountryID.Text = objStudent.CountryID.ToString(); cmbCountryName.Text = objStudent.CountryName; if (objStudent.Disability == "Yes") { rdbDisabilityYes.Checked = true; } else if (objStudent.Disability == "No") { rdbDisabilityNo.Checked = true; } txtDisabilityDescription.Text = objStudent.DisabilityDescription; } else { MessageBox.Show("This student code does not exist."); } }
/// <summary> /// Connects to the database and selects all the students from the table. /// Fills in the DataGridView with students with the amount within the table. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void mnuViewAll_Click(object sender, EventArgs e) { clsStudent objStudent = new clsStudent(); objStudent.ViewAll(dgvStudent); }
/// <summary> /// When the Add menu item is clicked, a student object is made with all the fields except ID. /// These values are passed to the AddStudent method which will run the procedure for adding the student into the database table. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void mnuAdd_Click(object sender, EventArgs e) { #region ValidationArea if (!clsValidation.ValidateTextBox(txtStudentFirstName)) { txtStudentFirstName.Focus(); return; } if (!clsValidation.ValidateForAlphabet(txtStudentFirstName)) { txtStudentFirstName.Focus(); return; } if (!clsValidation.ValidateNameFormat(txtStudentFirstName)) { txtStudentFirstName.Focus(); return; } if (!clsValidation.ValidateTextBox(txtStudentLastName)) { txtStudentLastName.Focus(); return; } if (!clsValidation.ValidateForAlphabet(txtStudentLastName)) { txtStudentLastName.Focus(); return; } if (!clsValidation.ValidateNameFormat(txtStudentLastName)) { txtStudentLastName.Focus(); return; } dtpDateOfBirth.Format = DateTimePickerFormat.Custom; dtpDateOfBirth.CustomFormat = "yyyy-MM-dd"; if (!clsValidation.ValidateDate(dtpDateOfBirth)) { return; } if (!clsValidation.ValidateRadioButton(rdbMale, rdbFemale)) { return; } if (!clsValidation.ValidateTextBox(txtStudStreetAddress)) { txtStudStreetAddress.Focus(); return; } if (!clsValidation.ValidateStreetAddress(txtStudStreetAddress)) { txtStudStreetAddress.Focus(); return; } if (!clsValidation.ValidateComboBox(cmbSuburbName)) { return; } //if (!clsValidation.ValidateTextBox(txtStudPostCode)) //{ // txtStudPostCode.Focus(); // return; //} //if(!clsValidation.ValidateComboBox(cmbPostCode)) //{ // return; //} //if (!clsValidation.ValidateTextBoxForNumeric(cmbPostCode)) //{ // txtStudPostCode.Focus(); // return; //} if (!clsValidation.ValidatePostCode(cmbPostCode.Text)) { return; } if (!clsValidation.ValidateTextBox(txtStudentPhoneNum)) { txtStudentPhoneNum.Focus(); return; } if (!clsValidation.ValidatePhoneNumber(txtStudentPhoneNum)) { txtStudentPhoneNum.Focus(); return; } if (!clsValidation.ValidateTextBox(txtStudentEmail)) { txtStudentEmail.Focus(); return; } if (!clsValidation.ValidateEmail(txtStudentEmail)) { txtStudentEmail.Focus(); return; } if (!clsValidation.ValidateComboBox(cmbCountryName)) { return; } if (!clsValidation.ValidateRadioButton(rdbDisabilityYes, rdbDisabilityNo)) { return; } #endregion #region Radio buttons string genderText = String.Empty; if (rdbMale.Checked) { genderText = "M"; } else if (rdbFemale.Checked) { genderText = "F"; } if (rdbDisabilityYes.Checked == true) { txtDisabilityDescription.ReadOnly = false; if (!clsValidation.ValidateTextBox(txtDisabilityDescription)) { return; } } if (rdbDisabilityNo.Checked == true) { txtDisabilityDescription.Text = String.Empty; txtDisabilityDescription.ReadOnly = true; } string disabilityText = String.Empty; if (rdbDisabilityYes.Checked) { disabilityText = "Yes"; } else if (rdbDisabilityNo.Checked) { disabilityText = "No"; } if (rdbDisabilityYes.Checked == true) { // txtDisabilityDescription.ReadOnly = false; if (!clsValidation.ValidateTextBox(txtDisabilityDescription)) { return; } } if (rdbDisabilityNo.Checked == true) { txtDisabilityDescription.Text = String.Empty; txtDisabilityDescription.ReadOnly = true; } #endregion clsStudent objStudent = new clsStudent(txtStudentFirstName.Text, txtStudentLastName.Text, genderText, dtpDateOfBirth.Value.ToString("yyyy-MM-dd"), txtStudStreetAddress.Text, Convert.ToInt32(cmbSuburbID.Text), cmbPostCode.Text, txtStudentPhoneNum.Text, txtStudentEmail.Text, Convert.ToInt32(cmbCountryID.Text), disabilityText, txtDisabilityDescription.Text); objStudent.Add(); MessageBox.Show("Student record successfully added!"); objStudent.ViewAll(dgvStudent); }