예제 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (usuario.Text.Trim().CompareTo("") == 0 || password.Text.Trim().CompareTo("") == 0) {
                MessageBox.Show("Debe ingresar Usuario y Contraseña", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            Funciones funciones = new Funciones();

            Conexion conn = new Conexion();
            SqlCommand sp_login;

            sp_login = new SqlCommand("SASHAILO.login", conn.miConexion); // Lo inicializo
            sp_login.CommandType = CommandType.StoredProcedure; // Defino que tipo de comando es
            SqlParameter USERNAME = sp_login.Parameters.Add("@p_usuario", SqlDbType.VarChar, 15);
            SqlParameter PASSWORD = sp_login.Parameters.Add("@p_password", SqlDbType.VarChar, 64);
            SqlParameter HAY_ERROR = sp_login.Parameters.Add("@hayErr", SqlDbType.Int);
            SqlParameter ERRORES = sp_login.Parameters.Add("@errores", SqlDbType.VarChar, 200);

            USERNAME.Value = usuario.Text.Trim();
            PASSWORD.Value = funciones.encriptarClave(password.Text.Trim());
            HAY_ERROR.Direction = ParameterDirection.Output;
            ERRORES.Direction = ParameterDirection.Output;

            try
            {
                sp_login.ExecuteNonQuery();
                int hayError = Convert.ToInt16(sp_login.Parameters["@hayErr"].Value.ToString());
                if (hayError == 1)
                {
                    string errores = sp_login.Parameters["@errores"].Value.ToString();
                    MessageBox.Show(errores, null, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    conn.desconectar();
                    return;
                }

            }
            catch (Exception error)
            {
                MessageBox.Show(error.ToString(), null, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                conn.desconectar();
                return;
            }

            //se logueó correctamente, muestro las entradas de menu de los administradores
            MenuIngresar.Visible = false;
            MenuSalir.Visible = true;
            CuadroLogin.Visible = false;

            loguear(usuario.Text.Trim());
        }