using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApplication1
{
public partial class frmLogin : Form
{
public frmLogin()
{
InitializeComponent();
}
public static string usuarioConectado;
public static string nivelAcesso;
private void frmLogin_Load(object sender, EventArgs e)
{
}
private void btnSair_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void btnConectar_Click(object sender, EventArgs e)
{
/* ligação a base de dados*/
SqlConnection cn = new SqlConnection(Properties.Settings.Default.nivelacessoConnectionString);
/*destino onde o comando vai ser executado + connection string */
SqlCommand cmd = new SqlCommand("SELECT * FROM tbUsuario WHERE usuario = @usuario and senha = @senha and nivelAcesso = @nivelAcesso", cn);
cmd.Parameters.Add("@usuario", SqlDbType.VarChar).Value = usuarioComboBox;
cmd.Parameters.Add("@senha", SqlDbType.VarChar).Value = senhaTextBox;
cmd.Parameters.Add("@nivelAcesso", SqlDbType.VarChar).Value = nivelAcessoComboBox;
cn.Open();
SqlDataReader le = null;
le = cmd.ExecuteReader();
if (le.Read())
{
this.Hide();
usuarioConectado = usuarioComboBox.Text;
nivelAcesso = nivelAcessoComboBox.Text;
frmMain tela = new frmMain();
tela.Show();
}
else
{
MessageBox.Show("Usuario e/ou senha invalida");
}
}
}
}