private void btnDelete_Click(object sender, EventArgs e) { try { manageStudent mys = new manageStudent(); managestudentdetails mysd = new managestudentdetails(); mys.getStudentId(this.enId); DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete " + mys.firstName + " " + mys.lastName, "Confirm Option", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.Yes) { if (mysd.deleteStudent(this.enId.ToString()) == true) { if (mys.deleteStudent(this.enId) == true) { MessageBox.Show("student deleted success", "input error", MessageBoxButtons.OK, MessageBoxIcon.Information); string sql = "SELECT enrolmentId,firstName,lastName,gender FROM wizstudents ORDER BY systemId DESC "; this.fillStudents(sql); } else { MessageBox.Show("failed to delete student", "input error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } catch (Exception ex) { MessageBox.Show("application error dgvStudents_CellDoubleClick() " + ex); } }
private void frmStudentDetails_Load(object sender, EventArgs e) { try { //this.ta.Focus(); this.fillClass(); this.Student.SelectedIndex = 0; this.txtFirstName.Focus(); if (this.update == true) { this.btnSave.Enabled = false; this.btnGenerate.Enabled = false; this.txtEnroiD.Text = this.enrollmentId.ToString(); manageStudent myS = new manageStudent(); managestudentdetails mySd = new managestudentdetails(); manageClassrooms myC = new manageClassrooms(); myS.getStudentId(this.enrollmentId); mySd.getStudentDetails(Convert.ToString(this.enrollmentId)); myC.getClass(myS.classId); this.txtFirstName.Text = myS.firstName; this.txtMidName.Text = myS.middleName; this.tXTSurname.Text = myS.lastName; this.cmbClassRoom.SelectedValue = myS.classId.ToString(); string bday = myS.DOB.Replace("/", "."); this.txtDob.Value = Convert.ToDateTime(bday); //this.txtDob.Text = ; // this.cmbClassRoom.Text = myC.className; if (myS.gender == "M") { this.rdbMale.Checked = true; } else if (myS.gender == "F") { this.metroRadioButton2.Checked = true; } this.txtAddress.Text = mySd.address; this.txtEmail.Text = mySd.email; this.txtGuardianSurname.Text = mySd.guardianSname; this.txtGuardianFname.Text = mySd.guardianFname; this.txtRel.Text = mySd.relationship; this.txtPhone.Text = mySd.mobileNumber; } else { manageControl myC = new manageControl(); myC.getCntrl(); this.txtEnroiD.Text = myC.enrollmentId.ToString(); } } catch (Exception ex) { MessageBox.Show("application error frmStudentDetails_Load()" + ex); } }
private void btnUpdate_Click(object sender, EventArgs e) { try { var enrID = Convert.ToInt32(this.txtEnroiD.Text); var firstName = this.txtFirstName.Text; var mdlName = this.txtMidName.Text; var lastName = this.tXTSurname.Text; var DOB = this.txtDob.Value.ToShortDateString(); string sex = ""; var classId = Convert.ToInt32(this.cmbClassRoom.SelectedValue); if (this.rdbMale.Checked == true) { sex = "M"; } if (this.metroRadioButton2.Checked == true) { sex = "F"; } /*other information*/ var address = this.txtAddress.Text; var phone = this.txtPhone.Text; var gurdFname = this.txtGuardianFname.Text; var gurdSname = this.txtGuardianSurname.Text; var gurdPhone = this.txtMobileNumbe.Text; var email = this.txtEmail.Text; var rel = this.txtRel.Text; /*validate required field*/ if (enrID.ToString() == "") { MessageBox.Show("Enrollmend Id is required", "input error", MessageBoxButtons.OK, MessageBoxIcon.Error); this.txtEnroiD.Focus(); } else if (firstName == "") { MessageBox.Show("firstName is required", "input error", MessageBoxButtons.OK, MessageBoxIcon.Error); this.txtFirstName.Focus(); } else if (lastName == "") { MessageBox.Show("lastName is required", "input error", MessageBoxButtons.OK, MessageBoxIcon.Error); this.tXTSurname.Focus(); } else { manageStudent myS = new manageStudent(); managestudentdetails mydetails = new managestudentdetails(); if (myS.checkExists(enrID) == 1) { if (mydetails.checkExists(enrID) == 1) { myS.getStudentId(enrID); myS.firstName = firstName; myS.DOB = DOB; myS.lastName = lastName; myS.classId = classId; myS.gender = sex; myS.middleName = txtMidName.Text; if (myS.updateStudent(enrID) == true) { mydetails.getStudentDetails(enrID.ToString()); mydetails.address = address; mydetails.guardianFname = gurdFname; mydetails.guardianSname = gurdSname; mydetails.relationship = rel; mydetails.mobileNumber = phone; if (mydetails.updateStudentDetails(enrID.ToString()) == true) { MessageBox.Show("student updated success ", "System notifification", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } else { if (mydetails.setStudentDetails(enrID, address, gurdFname, gurdSname, rel, gurdPhone, email) == true) { myS.getStudentId(enrID); myS.firstName = firstName; myS.DOB = DOB; myS.lastName = lastName; myS.classId = classId; myS.gender = sex; if (myS.updateStudent(enrID) == true) { MessageBox.Show("student updated success ", "System notifification", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } } else { MessageBox.Show("student not in the system", "System notifification", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } catch (Exception ex) { MessageBox.Show("application error " + ex); } }
private void btnSave_Click(object sender, EventArgs e) { try { var enrID = Convert.ToInt32(this.txtEnroiD.Text); var firstName = this.txtFirstName.Text; var mdlName = this.txtMidName.Text; var lastName = this.tXTSurname.Text; var DOB = this.txtDob.Value.ToShortDateString(); string sex = ""; var classId = Convert.ToInt32(this.cmbClassRoom.SelectedValue); if (this.rdbMale.Checked == true) { sex = "M"; } if (this.metroRadioButton2.Checked == true) { sex = "F"; } /*other information*/ var address = this.txtAddress.Text; var phone = this.txtPhone.Text; var gurdFname = this.txtGuardianFname.Text; var gurdSname = this.txtGuardianSurname.Text; var gurdPhone = this.txtMobileNumbe.Text; var email = this.txtEmail.Text; var rel = this.txtRel.Text; /*validate required field*/ if (enrID.ToString() == "") { MessageBox.Show("Enrollmend Id is required", "input error", MessageBoxButtons.OK, MessageBoxIcon.Error); this.txtEnroiD.Focus(); } else if (firstName == "") { MessageBox.Show("firstName is required", "input error", MessageBoxButtons.OK, MessageBoxIcon.Error); this.txtFirstName.Focus(); } else if (lastName == "") { MessageBox.Show("lastName is required", "input error", MessageBoxButtons.OK, MessageBoxIcon.Error); this.tXTSurname.Focus(); } else { manageStudent myS = new manageStudent(); if (myS.checkExists(enrID) == 0) { if (myS.setStudent(enrID, firstName, mdlName, lastName, classId, DOB, sex) == true) { managestudentdetails mydetails = new managestudentdetails(); if (mydetails.setStudentDetails(enrID, address, gurdFname, gurdSname, rel, gurdPhone, email) == true) { MessageBox.Show("student enrolled succesifully", "System notifification", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { myS.deleteStudent(enrID); MessageBox.Show("failed to add student to system try again ", "System notifification", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } else { MessageBox.Show("enrollmentId already in system", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (Exception ex) { MessageBox.Show("application error frmStudentDetails_Load()" + ex); } }