private void BtnBuscarCEP_Clicked(object sender, EventArgs e)
        {
            if ((txtCEP.Text == null) || (txtCEP.Text.Length < 8))
            {
                DisplayAlert("Erro", "CEP Inválido!", "CEP não posso ser vazio ou deve conter no minimo 8 caracteres.", "OK");
                txtCEP.Focus();
            }
            else
            {
                try
                {
                    Endereco endereco = ViaCepService.BuscarEnderecoViaCEP(txtCEP.Text.Trim());


                    if (endereco != null)
                    {
                        txtEndereco.Text = string.Format("Endereço: {0} , {1} , {2}, {3}", endereco.logradouro, endereco.bairro, endereco.localidade, endereco.uf);
                    }
                    else
                    {
                        DisplayAlert("Aviso!", "Endereço não foi encontrado para o cep digitado: " + txtCEP.Text, "OK");
                        txtCEP.Text = "";
                        txtCEP.Focus();
                    }
                }
                catch (Exception ex)
                {
                    DisplayAlert("Erro Crítico", ex.Message, "Ok");
                }
            }
        }
Exemplo n.º 2
0
        private void BuscarCep(object sender, EventArgs args)
        {
            var cep = Cep.Text.Trim();

            if (isValidCEP(cep))
            {
                try
                {
                    Endereco endereco = ViaCepService.BuscarEnderecoViaCEP(cep);

                    if (endereco != null)
                    {
                        lbResultado.Text = string.Format("Endereço: {0}, {1}, {2}", endereco.Localidade, endereco.Uf, endereco.Logradouro);
                    }
                    else
                    {
                        DisplayAlert("ERRO", "Endereço não encontrado para o cepe informado: " + cep, "ok");
                    }
                }
                catch (Exception e)
                {
                    DisplayAlert("ERRO", "Erro Crítico", "ok");
                }
            }
        }
Exemplo n.º 3
0
        }                                              // utlizando comando para o botao Entrar
        public PesquisaViewModel()
        {
            this.Pesquisa = new Pesquisa();

            PesquisarCommand = new Command(async() =>
            {
                var viaCepService = new ViaCepService();
                try
                {
                    this.Pesquisa = ViaCepService.BuscarEnderecoViaCEP(Pesquisa.Cep);

                    if (Pesquisa.Cep != null)
                    {
                        MessagingCenter.Send(this.Pesquisa, "Pesquisar"); // ENVIA O OBJETO PARA PROXIMA PAGINA
                    }
                }
                catch
                {
                    await Application.Current.MainPage.Navigation.PopAsync();
                }
            }, () =>
            {
                return(!string.IsNullOrEmpty(this.Cep)); // não habilita o botão entrar se o campo n estiver preenchido
            });
        }
Exemplo n.º 4
0
        private async void BuscarViaCEP(object sender, EventArgs args)
        {
            aparece();
            await Task.Delay(1000);

            if (CEP.Text.Length != 9)
            {
                some();
                await DisplayAlert("ERRO", "CEP Inválido", "OK");
            }
            else
            {
                if (CrossConnectivity.Current.IsConnected)
                {
                    Endereco end = ViaCepService.BuscarEnderecoViaCEP(CEP.Text);
                    Resultado.Text = $"Endereço: {end.Localidade}-{end.Uf} \n" +
                                     (string.IsNullOrWhiteSpace(end.Logradouro) ? "" : $"Rua: {end.Logradouro}\n") +
                                     (string.IsNullOrWhiteSpace(end.Bairro) ? "" : $"Bairro: {end.Bairro}\n");
                }
                else
                {
                    await DisplayAlert("ERRO", "Sem internet, verifique sua conexão e tente novamente", "OK");
                }
            }
            some();
        }
Exemplo n.º 5
0
        private void BuscarCEP(object sender, EventArgs args)
        {
            string cep = xCep.Text.Trim();

            if (isValidCEP(cep))
            {
                try
                {
                    Endereco end = ViaCepService.BuscarEnderecoViaCEP(cep);
                    if (end != null)
                    {
                        xResult.Text = string.Format("Endereço: {0}, {1}, {2}, {3}", end.Logradouro, end.Bairro, end.Localidade, end.UF);
                    }
                    else
                    {
                        DisplayAlert("ERRO", "O endereço não foi encontrado para o cep informado: " + cep, "OK");
                    }
                }
                catch (Exception e)
                {
                    DisplayAlert("ERRO CRÍTICO", e.Message, "OK");
                }
            }
        }