0

I have a login button doing the validation of users, but I need this code to check on the table that has a "function id" like 0 and 1, where 1 = show delete button and 0 = hide delete. So, I need the login button to check the function id and return one value for me and change the visibility of the button. Thanks!

private void btnLogin_Click(object sender, EventArgs e)
 {

   //chamo o método já testando seu retorno
  //preenchendo os parâmetros necessários
  //se retorna true
 if (ValidaUsuario(txtUsuario.Text, txtSenha.Text))
  {
    //retorno o diálogo ok, abre o form1
    this.DialogResult = DialogResult.OK;
  }
  else
  {
    //Senão retorno o dialogo cancel,message de login invalido
      MessageBox.Show("login e senha invalido");
  }

 }

//metodo para validar com 2 string  
//parametros usuario e senha
private bool ValidaUsuario(string usuario, string senha)

{
  //variável que será testada para
  //informar o retorno
  int retorno = -1;
  ////instância para conectar
  MySqlConnection conn = new MySqlConnection("server=localhost;user id=root;database=appouschool;Allow Zero Datetime=true");
  //comando sql que dá um count 
  //na tabela se existirem usuario e senha
  //com os dados informados
  string comando = "SELECT COUNT(*) FROM funcionarios WHERE Usuario=@Usuario AND Senha=@Senha";  
  //instância do comando
  MySqlCommand cmd = new MySqlCommand(comando, conn);
  //preenchimento dos parâmetros
  cmd.Parameters.AddWithValue("@Usuario", usuario);
  cmd.Parameters.AddWithValue("@Senha", senha);
  //abro conexão
  conn.Open();
  //retorno recebe o resultado do execute 
  retorno = Convert.ToInt32(cmd.ExecuteScalar());
  //fecho conexão
  conn.Close();
  //retorno true se retorno for maior que zero
  return retorno > 0;

}
Drewness
  • 5,004
  • 4
  • 32
  • 50
  • Where is the button to render visible or invisible? From the code above the login button, when the check is succesfull terminates the form setting the DialogResult to OK. Is the button to hide in another form? If yes then check the DialogResult returned from this form – Steve Mar 10 '14 at 22:35
  • yeah, the butto its on form, on inicialization "btnReady.vissible = false;" he started vissible false, the code need button that makes the check of users on table, need to check the "function id" 1 or 0, if are "function id" = 1 , the application need to change the value to SHOW btnReady, understand? thanks! – Thiago Freitas Mar 11 '14 at 17:28
  • What is "function id"? – Steve Mar 11 '14 at 17:33
  • its one collum on the table, its one code, if the user have funcition id = 1, he will need to see the 'btnReady' that are on my form, and start on "visible = false" – Thiago Freitas Mar 11 '14 at 17:36

1 Answers1

0

From the code you have posted it looks like you are using some kind of windows form application.

You may want to search for existing StackOverflow responses: Binding a Button's visibility to a bool value in ViewModel

Community
  • 1
  • 1
Doolali
  • 956
  • 9
  • 13