Пример #1
0
        private void BuscarCEP(object sender, EventArgs args)
        {
            string cep = CEP.Text.Trim();

            if (isValidCEP(cep))
            {
                try
                {
                    Endereco end = ViaCEPServico.BuscarEndercoViaCEP(cep);

                    if (end != null)
                    {
                        RESULTADO.Text = string.Format("Endereço: {2},{3},{0},{1}", end.localidade, end.uf, end.logradouro, end.bairro);
                    }
                    else
                    {
                        DisplayAlert("ERRO", "O endereço não foi encontrado para o CEP: " + cep, "OK");
                    }
                }
                catch (Exception e)
                {
                    DisplayAlert("ERRO CRÍTICO", e.Message, "OK");
                }
            }
        }
        private void BuscarCEP(object sender, EventArgs args)
        {
            //todo lógica do programa
            //toto validações

            String cep = (CEP.Text + "").Trim();

            try
            {
                if (isValidCEP(cep))
                {
                    Endereco end = ViaCEPServico.BuscarEndercoViaCEP(cep);

                    Resultado.Text = string.Format("Endereço: {0}, {1}, {2}", end.localidade, end.uf, end.logradouro);
                }
            } catch (Exception ex)
            {
            }
        }
        private void BuscarCEP(object sender, EventArgs args)
        {
            //TODO -- Lógica do programa.

            //TODO - Validações

            string cep = "";

            if (EDT_CEP.Text != null)
            {
                cep = EDT_CEP.Text.Trim();
            }



            foreach (var chr in new string[] { "(", ")", "-", " " })
            {
                cep = cep.Replace(chr, "");
            }

            if (isValidCEP(cep))
            {
                try
                {
                    Endereco end = ViaCEPServico.BuscarEndercoViaCEP(cep);

                    if (end != null)
                    {
                        LBL_CEP.Text = string.Format("Endereço: {2} - {3} {0}, {1}", end.localidade, end.uf, end.logradouro, end.bairro);
                    }
                    else
                    {
                        DisplayAlert("ERRO CRÍTICO", "O endereço não foi encontrado para o CEP informado: " + cep, "OK");
                    }

                    EDT_CEP.Text = "";
                }catch (Exception e)
                {
                    DisplayAlert("ERRO CRÍTICO", e.Message, "OK");
                }
            }
        }