public bool DoIt()
        {
            BDConexao conexao = new BDConexao();

            conexao.connection.Open();
            conexao.command.Parameters.Clear();
            conexao.command.CommandText = "SELECT idCliente,nome FROM Cliente WHERE EMAIL = @EMAIL AND SENHA = @SENHA";
            conexao.command.Parameters.Add("@EMAIL", SqlDbType.VarChar).Value = Email;
            conexao.command.Parameters.Add("@SENHA", SqlDbType.VarChar).Value = StatueStoreEncrypt.Encrypt(Senha);


            System.Data.SqlClient.SqlDataReader dr = conexao.command.ExecuteReader();

            if (dr.HasRows)
            {
                dr.Read();
                HttpContext.Current.Session["idUsuario"]   = dr.GetInt32(0);
                HttpContext.Current.Session["nomeUsuario"] = dr.GetString(1);
                conexao.connection.Close();
                return(true);
            }

            conexao.connection.Close();
            return(false);
        }
        public int BdSetClient()
        {
            BDConexao conexao = new BDConexao();

            conexao.connection.Open();
            conexao.command.CommandText = "INSERT INTO CLIENTE OUTPUT INSERTED.IDCLIENTE VALUES " +
                                          "(@EMAIL, @SENHA, @NOME, @SOBRENOME, @SEXO, @CPF, @DATANASC, @DATAINSC, null)";
            conexao.command.Parameters.Clear();
            conexao.command.Parameters.Add("@EMAIL", SqlDbType.VarChar).Value     = Email;
            conexao.command.Parameters.Add("@SENHA", SqlDbType.VarChar).Value     = StatueStoreEncrypt.Encrypt(Senha);
            conexao.command.Parameters.Add("@NOME", SqlDbType.VarChar).Value      = Nome;
            conexao.command.Parameters.Add("@SOBRENOME", SqlDbType.VarChar).Value = Sobrenome;
            conexao.command.Parameters.Add("@SEXO", SqlDbType.VarChar).Value      = TrataSexo(Sexo);
            conexao.command.Parameters.Add("@CPF", SqlDbType.VarChar).Value       = Cpf.Trim().Replace(".", "").Replace("-", "").Replace(" ", "");
            conexao.command.Parameters.Add("@DATANASC", SqlDbType.Date).Value     = DataNascimento;
            conexao.command.Parameters.Add("@DATAINSC", SqlDbType.Date).Value     = DataInscricao;

            int idCliente = (int)conexao.command.ExecuteScalar();

            conexao.connection.Close();

            EnviarEmailParaCliente(Email, Nome);

            return(idCliente);
        }
        public void AlterarSenha(string novaSenha)
        {
            BDConexao conexao = new BDConexao();

            conexao.connection.Open();
            conexao.command.Parameters.Clear();
            conexao.command.CommandText = "UPDATE CLIENTE SET SENHA = @NOVASENHA WHERE IDCLIENTE = @IDCLIENTE";
            conexao.command.Parameters.Add("@IDCLIENTE", SqlDbType.Int).Value     = (int)HttpContext.Current.Session["idUsuario"];
            conexao.command.Parameters.Add("@NOVASENHA", SqlDbType.VarChar).Value = StatueStoreEncrypt.Encrypt(novaSenha);

            conexao.command.ExecuteNonQuery();
            conexao.connection.Close();
        }
        public void RedefinirSenhaPorkey(string key, string novaSenha)
        {
            BDConexao conexao = new BDConexao();

            conexao.connection.Open();
            conexao.command.Parameters.Clear();
            conexao.command.CommandText = "UPDATE CLIENTE SET senha = @SENHA WHERE codSenha = @CODSENHA";
            conexao.command.Parameters.Add("@SENHA", SqlDbType.VarChar).Value    = StatueStoreEncrypt.Encrypt(novaSenha);
            conexao.command.Parameters.Add("@CODSENHA", SqlDbType.VarChar).Value = key;

            conexao.command.ExecuteNonQuery();
            conexao.connection.Close();
        }
        public void CadastraCartao()
        {
            BDConexao conexao = new BDConexao();

            conexao.connection.Open();

            conexao.command.CommandText = "DELETE FROM CARTAOCREDITO WHERE IDCLIENTE = @ID";
            conexao.command.Parameters.Clear();
            conexao.command.Parameters.Add("@ID", SqlDbType.VarChar).Value = IdCliente;
            conexao.command.ExecuteNonQuery();

            conexao.command.CommandText = "INSERT INTO CARTAOCREDITO VALUES(@BANDEIRA, @NUMCARTAO, @CVV, @VALIDADE, @IDCLIENTE, @TITULAR)";
            conexao.command.Parameters.Clear();
            conexao.command.Parameters.Add("@BANDEIRA", SqlDbType.VarChar).Value  = StatueStoreEncrypt.Encrypt(Bandeira);
            conexao.command.Parameters.Add("@NUMCARTAO", SqlDbType.VarChar).Value = StatueStoreEncrypt.Encrypt(NumeroCartao.ToString().Trim().Replace(".", "").Replace("-", "").Replace(" ", ""));
            conexao.command.Parameters.Add("@CVV", SqlDbType.VarChar).Value       = StatueStoreEncrypt.Encrypt(CVV.Trim().Replace(".", "").Replace("-", "").Replace(" ", ""));
            conexao.command.Parameters.Add("@VALIDADE", SqlDbType.VarChar).Value  = StatueStoreEncrypt.Encrypt(Validade);
            conexao.command.Parameters.Add("@IDCLIENTE", SqlDbType.VarChar).Value = IdCliente;
            conexao.command.Parameters.Add("@TITULAR", SqlDbType.VarChar).Value   = StatueStoreEncrypt.Encrypt(Titular);
            conexao.command.ExecuteNonQuery();
            conexao.connection.Close();
        }
        public bool verificaSenha(string senha)
        {
            BDConexao conexao = new BDConexao();

            conexao.connection.Open();
            conexao.command.Parameters.Clear();
            conexao.command.CommandText = "SELECT COUNT(*) FROM CLIENTE WHERE IDCLIENTE = @IDCLIENTE AND SENHA = @SENHA";
            conexao.command.Parameters.Add("@IDCLIENTE", SqlDbType.Int).Value = (int)HttpContext.Current.Session["idUsuario"];;
            conexao.command.Parameters.Add("@SENHA", SqlDbType.VarChar).Value = StatueStoreEncrypt.Encrypt(senha);

            int ok = (int)conexao.command.ExecuteScalar();

            conexao.connection.Close();

            if (ok == 0)
            {
                return(false);
            }

            else
            {
                return(true);
            }
        }
        public string UltimosDigitos()
        {
            BDConexao conexao = new BDConexao();

            conexao.connection.Open();
            conexao.command.CommandText = "SELECT numCartao FROM CARTAOCREDITO WHERE IDCLIENTE = @ID";
            conexao.command.Parameters.Clear();
            conexao.command.Parameters.Add("@ID", SqlDbType.Int).Value = (int)HttpContext.Current.Session["idUsuario"];

            string numero = string.Empty;

            System.Data.SqlClient.SqlDataReader dr = conexao.command.ExecuteReader();

            if (dr.HasRows)
            {
                dr.Read();
                numero = StatueStoreEncrypt.Decrypt(dr.GetString(0));
            }


            conexao.connection.Close();
            dr.Close();
            return(numero.Substring(numero.Length - 4, 4));
        }