private void btnRemove_Click(object sender, EventArgs e) { if (String.IsNullOrWhiteSpace(txtPassword.Text)) { MessageBox.Show("Enter the account's password."); return; } string passwordHash = Utils.GetMD5String(txtPassword.Text); if (passwordHash != Bank.Instance.Accounts[cbAccounts.SelectedIndex].PasswordHash) { MessageBox.Show("Invalid password."); return; } AccountManagementState state = Bank.Instance.RemoveAt(cbAccounts.SelectedIndex); if (state == AccountManagementState.Successful) { MessageBox.Show("Account has been removed."); Main.Instance.ReloadList(); Close(); Dispose(); } else { MessageBox.Show("Removing was unsuccessful!"); } }
private void btnApply_Click(object sender, EventArgs e) { if (HasError()) { return; } string firstName, lastName, address, phoneNumber, newPassword, password; firstName = txtFirstName.Text; lastName = txtLastName.Text; address = txtAddress.Text; phoneNumber = txtPhoneNumber.Text; password = txtPassword.Text; newPassword = txtNewPassword.Text; Account account = Bank.Instance.Accounts[cbAccounts.SelectedIndex]; account.FirstName = firstName; account.LastName = lastName; account.Address = address; account.PhoneNumber = phoneNumber; string passwordHash = Utils.GetMD5String(password); if (passwordHash != account.PasswordHash) { MessageBox.Show("Current password is not valid."); return; } if ((!String.IsNullOrWhiteSpace(txtNewPassword.Text) || txtNewPassword.Text != txtNewPassword.PlaceHolderText) || (!String.IsNullOrWhiteSpace(txtConfirmNewPassword.Text) || txtNewPassword.Text != txtNewPassword.PlaceHolderText)) { if (txtNewPassword.Text == txtConfirmNewPassword.Text) { account.PasswordHash = Utils.GetMD5String(txtNewPassword.Text); } } AccountManagementState state = Bank.Instance.Modify(account); if (state == AccountManagementState.Successful) { MessageBox.Show("Account has been modified."); Main.Instance.ReloadList(); Close(); Dispose(); } else { MessageBox.Show("Modifying was unsuccessful!"); } }
private void btnAdd_Click(object sender, EventArgs e) { if (HasError()) { return; } string firstName, lastName, address, phoneNumber, password; firstName = txtFirstName.Text; lastName = txtLastName.Text; address = txtAddress.Text; phoneNumber = txtPhoneNumber.Text; password = txtPassword.Text; Account account = new Account() { Id = Utils.GenerateId(), FirstName = firstName, LastName = lastName, Address = address, Balance = 0, PhoneNumber = phoneNumber, PasswordHash = Utils.GetMD5String(password) }; AccountManagementState state = Bank.Instance.Add(account); if (state == AccountManagementState.Successful) { MessageBox.Show("Account has been created."); Main.Instance.ReloadList(); Close(); Dispose(); } else { MessageBox.Show("Adding was unsuccessful!"); } }