Exemple #1
0
 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);
     }
 }
Exemple #2
0
 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);
     }
 }