private void loadPresidentData() { President p = new President(); try { SqlConn connect = new SqlConn(); connect.open(); SqlCommand command = new SqlCommand(); command.Connection = connect.sqlConnection; command.CommandText = "select * from dbo.President where president_id = " + p.getPresidentID(session); SqlDataReader reader = command.ExecuteReader(); if (reader.Read()) { President pred = new President(); pred.setPresidentName(reader.GetString(2)); pred.setPresidentEmail(reader.GetString(3)); pred.setPresidentGender(reader.GetString(4)); pred.setPresidentPassword(reader.GetString(5), reader.GetString(5)); // show value for edit name.Text = pred.getPresidentName(); email.Text = pred.getPresidentEmail(); gender.Text = pred.getPresidentGender(); pw.Text = pred.getPresidentPassword(); // automate value on textfield updateNameTextbox.Text = pred.getPresidentName(); pwTextbox.Text = pred.getPresidentPassword(); genderCombobox.Text = pred.getPresidentGender(); updateEmailTextbox.Text = pred.getPresidentEmail(); // close connection connect.close(); reader.Close(); } } catch (Exception ex) { MessageBox.Show("error " + ex); } }
private void updateButton_Click(object sender, EventArgs e) { validateEmptyField(); if (insertData) { President p = new President(); try { SqlConn connect = new SqlConn(); connect.open(); SqlCommand command = new SqlCommand(); command.Connection = connect.sqlConnection; command.CommandText = "update dbo.President set president_name = '" + updateNameTextbox.Text + "', president_email = '" + updateEmailTextbox.Text + "', president_gender = '" + genderCombobox.Text + "', president_password = '******' where president_id = " + p.getPresidentID(session); SqlDataReader reader = command.ExecuteReader(); reader.Close(); connect.close(); // register updated name for session on data retrieval p.setPresidentName(updateNameTextbox.Text); this.session = p.getPresidentName(); MessageBox.Show("Your account details had update successfully! "); openView(); } catch (Exception ex) { MessageBox.Show("error" + ex); } openView(); loadPresidentData(); } else { MessageBox.Show("Update action is INVALID \n because some field is empty or wrong. "); } }
private void registerButton_Click(object sender, EventArgs e) { validateEmptyField(); if (insertPresidentData) { President pred = new President(); pred.setPresidentName(nameTextbox.Text); pred.setPresidentEmail(emailTextbox.Text); pred.setPresidentGender(genderCombobox.Text); pred.setPresidentPassword(pwTextbox.Text, retypepwTextbox.Text); if (pred.getPasswordBoolean() == false) { MessageBox.Show("Your password does not match, please retype again."); } else { SqlConn connect = new SqlConn(); connect.open(); SqlCommand command = new SqlCommand(); command.Connection = connect.sqlConnection; command.CommandText = "insert into dbo.President values ('" + getClubID(posCombobox.Text) + "','" + pred.getPresidentName() + "','" + pred.getPresidentEmail() + "','" + pred.getPresidentGender() + "','" + pred.getPresidentPassword() + "');"; SqlDataReader reader = command.ExecuteReader(); reader.Close(); connect.close(); MessageBox.Show("Your account had been created successfully! "); Dashboard dashboard = new Dashboard(pred.getPresidentName(), posCombobox.Text); this.Hide(); dashboard.ShowDialog(); } } }