Advertising
- Untitled
- Wednesday, May 16th, 2012 at 10:02:23am MDT
- 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");
- }
- }
- }
- }
advertising
Update the Post
Either update this post and resubmit it with changes, or make a new post.
You may also comment on this post.
Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.