Exemplo n.º 1
0
        private void btnSearchCEP_Click(object sender, EventArgs e)
        {
            try
            {
                CorreioModel    correio  = new CorreioModel();
                CorreioResponse response = correio.Endereco(txtCEP.Text);

                txtLogradouro.Text  = response.Logradouro;
                txtComplemento.Text = response.Complemento;
                txtBairro.Text      = response.Bairro;
                txtUF.Text          = response.UF;
            }
            catch (ArgumentException ex)
            {
                MessageBox.Show(ex.Message, "Black Fit LTDA", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("'nm_Usuario'"))
                {
                    MessageBox.Show("Este nome de usuário já está em uso.", "Black Fit LTDA", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show($"Ocorreu um erro não identificado: {ex.Message}", "Black Fit LTDA", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemplo n.º 2
0
        private void txtCep_Leave(object sender, EventArgs e)
        {
            try
            {
                CorreioApi      correioApi      = new CorreioApi();
                CorreioResponse correioResponse = new CorreioResponse();
                bool            encontrouCep    = correioApi.BuscarAPICorreio(txtCep.Text, out correioResponse);

                if (encontrouCep == false)
                {
                    MessageBox.Show("Cep não encontrado, por favor, tente novamente.", "NSF", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    txtEndereco.Text = correioResponse.logradouro;
                    txtCidade.Text   = correioResponse.localidade;
                    txtBairro.Text   = correioResponse.bairro;
                    cboUf.Text       = correioResponse.uf;
                }
            }
            catch (ArgumentException ex)
            {
                MessageBox.Show(ex.Message, "NSF", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception)
            {
                MessageBox.Show("Ocorreu um erro. Entre em contato com o administrador.", "NSF", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void button3_Click(object sender, EventArgs e)
        {
            CorreioApi correioApi = new CorreioApi();

            // Lê e formata o CEP do textbox
            string cep = txtcep.Text.Trim().Replace("-", "");

            // Chama função BuscarAPICorreio
            CorreioResponse correio = correioApi.Buscar(cep);

            // Altera os valores dos textbox com a resposta do correio
            txtender.Text  = correio.logradouro + " - " + correio.complemento;
            txtbairro.Text = correio.bairro;
            txtcity.Text   = correio.localidade;
            cboestado.Text = correio.uf;
        }
Exemplo n.º 4
0
        private void btnSearchCEP_Click(object sender, EventArgs e)
        {
            try
            {
                CorreioModel    correio  = new CorreioModel();
                CorreioResponse response = correio.Endereco(txtCEP.Text);

                txtLogradouro.Text  = response.Logradouro;
                txtComplemento.Text = response.Complemento;
                txtBairro.Text      = response.Bairro;
                txtUF.Text          = response.UF;
            }
            catch (ArgumentException ex)
            {
                MessageBox.Show(ex.Message, "Black Fit LTDA", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception)
            {
                MessageBox.Show("Ocorreu um erro não identificado.", "Black Fit LTDA", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }