You are on page 1of 3

//---------------------------------------------------------

//TODO: Copiar estas asignaciones de evento en el constructor:

// después de InitializeComponents.

// Comprobar que los delegados usados son los correctos.

//---------------------------------------------------------

/*

btnentrar.Click += new System.EventHandler(btnentrar_Click);

btnsalir.Click += new System.EventHandler(btnsalir_Click);

TXTCLAVE.KeyPress += new System.Windows.Forms.KeyPressEventHandler(TXTCLAVE_KeyPress);

TXTUSUARIO.KeyPress += new
System.Windows.Forms.KeyPressEventHandler(TXTUSUARIO_KeyPress);

*/

//---------------------------------------------------------

public class Login{

private void btnentrar_Click(System.Object sender, System.EventArgs e) {

string usu = TXTUSUARIO.Text;

string cont = TXTCLAVE.Text;

if( usu == "" | cont == "" ){

MsgBox("Asegúrese de llenar sus Datos Correctamente");

}else{

SqlCommand cmd = new SqlCommand("InicioSesion", conexion);

try{

abrir();

cmd.CommandType = 4;

cmd.Parameters.AddWithValue("@Usu", usu);

cmd.Parameters.AddWithValue("@Contra", cont);

cmd.Parameters.Add("@msj", SqlDbType.VarChar, 60).Direction = 2;

cmd.ExecuteNonQuery();
usuario = TXTUSUARIO.Text;

string msj = cmd.Parameters("@msj").Value;

MsgBox(msj, vbInformation);

if( msj == "Datos Incorrectos" ){

TXTCLAVE.Clear();

TXTUSUARIO.Focus();

}else{

MenuPrincipal f = new MenuPrincipal();

this.Hide();

f.ShowDialog();

}catch(Exception ex){MsgBox(ex.Message);

conexion.Close();

private void btnsalir_Click(System.Object sender, System.EventArgs e) {

confirma = MsgBox("Está seguro que Desea Salir?", vbYesNo + vbExclamation, "Atención!!");

if( confirma == vbYes ){

this.Close();

private void TXTCLAVE_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) {

if( Char.IsDigit(e.KeyChar) ){
e.Handled = false;

}else if( Char.IsControl(e.KeyChar) ){

e.Handled = false;

}else{

e.Handled = true;

private void TXTUSUARIO_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs


e) {

if( Char.IsLetter(e.KeyChar) ){

e.Handled = false;

}else if( Char.IsControl(e.KeyChar) ){

e.Handled = false;

}else{

e.Handled = true;

You might also like