public List <Admins> Enter() { NpgsqlConnection conexao = null; try { conexao = new ConectaDB().getConexao(); string sql = "SELECT * from Admins"; NpgsqlCommand cmd = new NpgsqlCommand(sql, conexao); NpgsqlDataReader dr = cmd.ExecuteReader(); List <Admins> listaAdmins = new List <Admins>(); while (dr.Read()) { Admins novoAdmin = new Admins(); novoAdmin.ID = Convert.ToInt16(dr["id"]); novoAdmin.login = dr["Nome"].ToString(); novoAdmin.login = dr["login"].ToString(); novoAdmin.senha = dr["senha"].ToString(); listaAdmins.Add(novoAdmin); } return(listaAdmins); } catch (Exception ex) { throw new Exception(" Erro! " + ex.Message); } finally { if (conexao != null) { conexao.Close(); } } }
public void btnEntrar_Click(object sender, EventArgs e) { string login = txtLogin.Text; string senha = txtSenha.Text; Admins Admin = new Admins(); List <Admins> x = Admin.Enter(); foreach (var z in x) { if (z.login == login && z.senha == senha) { this.Visible = false; Menu n = new Menu(); n.Show(); } else { MessageBox.Show("Login ou senha inválidos", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }