0
I’m having a serious recurrence problem with Dialogresult.
This is the Login screen, thanks to the use of Dialogresult, there is a strange error, you have to press Login twice. The first one picks up that Dialogresult is OK but for there, it does not return and tests, you have to click a second time for it to proceed.
Here’s the button code:
private void btnLogar_Click(object sender, EventArgs e)
{
DALConexao cx = new DALConexao(DadosDaConexao.StringDeConexao);
ModeloLogin.Login = txtLogin.Text;
ModeloLogin.Senha = txtSenha.Text;
SqlConnection conexao = new SqlConnection(cx.StringConexao);
SqlCommand cmd = new SqlCommand("Select login, senha FROM registro WHERE login = '" + ModeloLogin.Login + "'AND senha = '" + ModeloLogin.Senha + "'",conexao);
conexao.Open();
bool Verifica = cmd.ExecuteReader().HasRows;
if (Verifica == true)
{
btnLogar.DialogResult = DialogResult.OK;
count = count + 1;
if (count > 1)
{
conexao.Close();
MessageBox.Show("Login efetuado com sucesso! Bem-vindo.", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Exclamation );
this.IsNewLogged = true;
conexao.Open();
SqlCommand cmd2 = new SqlCommand("select nome from registro where login = '"+ ModeloLogin.Login + "'",conexao);
ModeloLogin.Nome = Convert.ToString(cmd2.ExecuteScalar());
conexao.Close();
SqlCommand cmd3 = new SqlCommand("select permissao from registro where login = '" + ModeloLogin.Login + "'",conexao);
conexao.Open();
ModeloLogin.Permissao = Convert.ToString(cmd3.ExecuteScalar());
}
}
else
{
MessageBox.Show("Login ou senha incorretos! Tente novamente.", "Erro", MessageBoxButtons.OK,MessageBoxIcon.Error);
}
conexao.Close();
}
And here’s the code to Program.Cs:
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
frmLogin f = new frmLogin();
if (f.ShowDialog() == DialogResult.OK)
{
frmDecisao d = new frmDecisao();
if(d.ShowDialog() == DialogResult.Yes)
{
Application.Run(new frmPrincipal());
f.Dispose();
d.Dispose();
}
if (d.ShowDialog() == DialogResult.No)
{
Application.Run(new frmPrincipal2());
f.Dispose();
d.Dispose();
}
}
}
}
Originally he was supposed to make the Login click a Dialogresult OK and return to Program.Cs and test it on condition,however the first time he is clicked he stops in Dialogresult OK and in the second he continues and returns to the program.Cs someone knows tell me what is happening?
Thank you so much for the help,.
– UnbornHexa