steve_rm
Mar 30th, 2005, 03:07 AM
Hello
I have a very difficult problem to explain. I have a password dialog box so that people can change there password. The dialog box will request for their current password, anc check that is is valid. Then request them to enter their new password and then re-enter their new password. The passwords are checked using the tab button when they leave a text box on the (leave event). When they have done all this they click the ok button and the new password is set. If however, they cancel using the cancel button. Then the dialog box will not close. This is the code below so you can better understand my problem.
This is the code for when the user enters the password, and presses the tab key to go to the next text box. When this event fires it will check the password is correct. Enter new password and re-enter password uses the same idea. I will not post it here as the code is the same.
private void txtEnterPassword_Leave(object sender, System.EventArgs e)
{
string queryValidatePwd = "SELECT Username, Password FROM AdminUsers WHERE Username = '" + lblLoginName.Text + "' AND Password = '" + txtEnterPassword.Text + "' ";
try
{
OleDbCommand cmdValidatePwd = cnnChangePassword.CreateCommand();
cmdValidatePwd.CommandType = CommandType.Text;
cmdValidatePwd.CommandText = queryValidatePwd;
OleDbDataAdapter daValidatePwd = new OleDbDataAdapter(cmdValidatePwd);
DataTable dtValidatePwd = new DataTable("AdminUsers");
int count = daValidatePwd.Fill(dtValidatePwd);
if ( daValidatePwd.Fill(dtValidatePwd) == 1 ) //Password is correct
{
txtEnterNewPassword.Visible = true;
txtEnterNewPassword.Focus(); //Get focus of next text box.
}
else
{
MessageBox.Show("Password is incorrect for this username - please try again","Incorrect Password",MessageBoxButtons.OK,MessageBoxIcon.Warning);
txtEnterPassword.Clear();
txtEnterPassword.Focus();
}
dtValidatePwd.Dispose();
daValidatePwd.Dispose();
}
catch ( OleDbException ex )
{
MessageBox.Show(ex.Message);
}
catch ( Exception ex )
{
MessageBox.Show(ex.Message);
}
}
Code for when the user closes the dialog box. The the other textboxes have focus you cannot close this form. I have tired using this.close() as well, but still does not work.
private void btnCancel_Click(object sender, System.EventArgs e)
{
this.Dispose();
}
Thanks for you help in advance,
Steve
I have a very difficult problem to explain. I have a password dialog box so that people can change there password. The dialog box will request for their current password, anc check that is is valid. Then request them to enter their new password and then re-enter their new password. The passwords are checked using the tab button when they leave a text box on the (leave event). When they have done all this they click the ok button and the new password is set. If however, they cancel using the cancel button. Then the dialog box will not close. This is the code below so you can better understand my problem.
This is the code for when the user enters the password, and presses the tab key to go to the next text box. When this event fires it will check the password is correct. Enter new password and re-enter password uses the same idea. I will not post it here as the code is the same.
private void txtEnterPassword_Leave(object sender, System.EventArgs e)
{
string queryValidatePwd = "SELECT Username, Password FROM AdminUsers WHERE Username = '" + lblLoginName.Text + "' AND Password = '" + txtEnterPassword.Text + "' ";
try
{
OleDbCommand cmdValidatePwd = cnnChangePassword.CreateCommand();
cmdValidatePwd.CommandType = CommandType.Text;
cmdValidatePwd.CommandText = queryValidatePwd;
OleDbDataAdapter daValidatePwd = new OleDbDataAdapter(cmdValidatePwd);
DataTable dtValidatePwd = new DataTable("AdminUsers");
int count = daValidatePwd.Fill(dtValidatePwd);
if ( daValidatePwd.Fill(dtValidatePwd) == 1 ) //Password is correct
{
txtEnterNewPassword.Visible = true;
txtEnterNewPassword.Focus(); //Get focus of next text box.
}
else
{
MessageBox.Show("Password is incorrect for this username - please try again","Incorrect Password",MessageBoxButtons.OK,MessageBoxIcon.Warning);
txtEnterPassword.Clear();
txtEnterPassword.Focus();
}
dtValidatePwd.Dispose();
daValidatePwd.Dispose();
}
catch ( OleDbException ex )
{
MessageBox.Show(ex.Message);
}
catch ( Exception ex )
{
MessageBox.Show(ex.Message);
}
}
Code for when the user closes the dialog box. The the other textboxes have focus you cannot close this form. I have tired using this.close() as well, but still does not work.
private void btnCancel_Click(object sender, System.EventArgs e)
{
this.Dispose();
}
Thanks for you help in advance,
Steve