Beispiel #1
0
        private void pesquisaCep_Click(object sender, EventArgs e)
        {
            textResultado.Clear();

            string requiString;

            this.inputUser = textCep.Text;
            if (!String.IsNullOrEmpty(inputUser))
            {
                requisicao.UrlBase(inputUser);
            }
            else
            {
                MessageBox.Show("Preencha o campo de pesquisa", "Informativo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            var requi = requisicao.Obter();

            try
            {
                if (requi.Cep == null)
                {
                    if (enderecoButton.Checked)
                    {
                        requisicao.UrlEnd(estadoBox.SelectedItem.ToString(), cidadeBox.SelectedItem.ToString(), inputUser);
                        var requiEnd = requisicao.ObterEnd();
                        foreach (var requiE in requiEnd)
                        {
                            var requiStringEnd = $"CEP: {requiE.Cep} \r\nLogradouro: {requiE.Logradouro} \r\nComplemento: {requiE.Complemento} \r\nBairro: {requiE.Bairro} \r\nLocalidade: {requiE.Localidade} \r\nUF: {requiE.Uf} \r\nDDD: {requiE.Ddd} \r\n-\r\n";
                            textResultado.AppendText(requiStringEnd);
                        }
                    }
                    else
                    {
                        textResultado.Font      = new Font("Arial", 18, FontStyle.Bold);
                        textResultado.ForeColor = System.Drawing.Color.DarkRed;
                        textResultado.AppendText("CEP não encontrado");
                    }
                    return;
                }
                else
                {
                    requiString             = $"CEP: {requi.Cep} \r\nLogradouro: {requi.Logradouro} \r\nComplemento: {requi.Complemento} \r\nBairro: {requi.Bairro} \r\nLocalidade: {requi.Localidade} \r\nUF: {requi.Uf} \r\nDDD: {requi.Ddd}";
                    textResultado.Font      = new Font("Microsoft Sans Serif", 12, FontStyle.Regular);
                    textResultado.ForeColor = System.Drawing.Color.Black;
                    textResultado.AppendText(requiString);
                }
            }
            catch
            {
                textResultado.Font      = new Font("Arial", 18, FontStyle.Bold);
                textResultado.ForeColor = System.Drawing.Color.DarkRed;
                textResultado.AppendText("CEP não encontrado");
            }
        }