private static void buttonCancel_Click(object sender, EventArgs e) { hideSomeComponents(); StudentProfileForm.showAllComponents(); StudentProfileForm.updateStudentInformation(); }
private static void buttonSave_Click(object sender, EventArgs e) { Student student = (Student)User.getCurrentUser(); if (student == null) { MessageBox.Show("An error occurred while doing this process."); return; } if (textBoxStudentName.Text == "" || textBoxStudentName.Text.Replace(" ", "") == "") { err.SetError(textBoxStudentName, "Student name cannot be empty."); return; } bool changePassword = false; if ((textBoxOldPassword.Text != "" || textBoxOldPassword.Text.Replace(" ", "") != "") && (textBoxNewPassword.Text != "" || textBoxNewPassword.Text.Replace(" ", "") != "") && (textBoxConfirmPassword.Text != "" || textBoxConfirmPassword.Text.Replace(" ", "") != "")) { if (Md5Converter.encrypt(textBoxOldPassword.Text) != student.Password) { err.SetError(textBoxOldPassword, "Wrong password."); MessageBox.Show("Old password is wrong!"); return; } else { err.SetError(textBoxOldPassword, ""); } if (textBoxNewPassword.Text != textBoxConfirmPassword.Text) { err.SetError(textBoxConfirmPassword, "New Password is not match."); MessageBox.Show("New Password is not match.!"); return; } else { err.SetError(textBoxConfirmPassword, ""); } changePassword = true; } else if (textBoxOldPassword.Text != "" || textBoxOldPassword.Text.Replace(" ", "") != "" || (textBoxNewPassword.Text != "" || textBoxNewPassword.Text.Replace(" ", "") != "") || textBoxConfirmPassword.Text != "" || textBoxConfirmPassword.Text.Replace(" ", "") != "") { MessageBox.Show("You must fill in the passwords to change the new password!"); return; } student.Password = Md5Converter.encrypt(textBoxNewPassword.Text); student.Name = textBoxStudentName.Text; student.Gender = radioButtonMale.Checked ? EnumGender.Male : EnumGender.Female; student.DateOfBirth = dateTimePicker1.Value.Date; student.Email = textBoxEmail.Text; student.Contact = textBoxContact.Text; student.Address = textBoxAddress.Text; Program.getDatabaseUtils().updateStudentInformation(student, changePassword); hideSomeComponents(); StudentProfileForm.showAllComponents(); StudentProfileForm.updateStudentInformation(); Program.getStudentForm().initProfileName(); }