private void insert_btn_Click(object sender, EventArgs e) { string gender = ""; if (male_button.Checked == true) { gender = "Male"; } else { gender = "Female"; } string check_data_exit = "SELECT student_id from student_data where student_id = '" + student_id_box.Text + "'"; MySqlDataReader data = curd.SelectQ(check_data_exit); string student_id_exits = ""; while (data.Read()) { student_id_exits = data.GetString(0); } if (student_id_box.Text != "" && batch_no_box.Text != "" && firstname_box.Text != "" && lastname_box.Text != "" && gender != "" && department_box.Text != "" && phone__box.Text != "") { if (student_id_exits == "") { string sqlcode = "INSERT INTO student_data VALUES('','" + student_id_box.Text + "', '" + firstname_box.Text + "','" + lastname_box.Text + "','" + born_date.Text + "','" + gender + "','" + email__box.Text + "','" + phone__box.Text + "','" + department_box.Text + "','" + batch_no_box.Text + "','" + remarks__box.Text + "')"; curd.CUD(sqlcode); DataViwer(); clearboxes(); gender = ""; MessageBox.Show("Data inserted successfully"); } else { MessageBox.Show("This student ID '" + student_id_exits + "' already exits!.", "Insertion Error", MessageBoxButtons.OK, MessageBoxIcon.Error); student_id_box.Clear(); } student_id_exits = ""; } else { MessageBox.Show("Please fill up all necessary fields", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void insert_btn_Click(object sender, EventArgs e) { string selectCurrrentPassowrdSQL = "SELECT password from user_account"; MySqlDataReader data = curd.SelectQ(selectCurrrentPassowrdSQL); string current_password_from_server = ""; while (data.Read()) { current_password_from_server = data.GetString(0); } string current_password_from_user = current_password.Text; if (new_password.Text.Length >= 8) { if (current_password_from_user == current_password_from_server) { string NewPassword = new_password.Text; string ConfirmPassowrd = confirm_password.Text; if (NewPassword == ConfirmPassowrd) { string update_code = "UPDATE user_account SET password = '******'"; curd.CUD(update_code); MessageBox.Show("Password has been updated successfully."); current_password.Clear(); new_password.Clear(); confirm_password.Clear(); this.Hide(); } else { MessageBox.Show("Confirm password does not match.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); current_password.Clear(); new_password.Clear(); confirm_password.Clear(); } } else { MessageBox.Show("Current password is wrong.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); current_password.Clear(); new_password.Clear(); confirm_password.Clear(); } } else { MessageBox.Show("Password must be at least 8 characters long.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); current_password.Clear(); new_password.Clear(); confirm_password.Clear(); } }