protected void txtCEP_TextChanged(object sender, EventArgs e) { try { string digitadoCEP = txtCEP.Text.Replace(".", string.Empty).Replace("-", string.Empty); if (digitadoCEP.Length == 8) { TLogradouroVO logradouro = ControllerLogradouro.ListarPorCEP(Convert.ToInt32(digitadoCEP)); if (logradouro == null) { throw new CABTECException("CEP Inválido!"); } trMensagemPageCadastro.Visible = false; PreencheTelaLogradouro(logradouro); } else { throw new CABTECException("CEP Inválido!"); } } catch (CABTECException ex) { this.MostrarMensagem(ex.Message); } catch (Exception exception) { this.MostrarMensagem(exception.Message); } }
private void PesquisarCEP(string numeroTextCEP) { int numeroCEP = Convert.ToInt32(numeroTextCEP); DataTable tableEndereco = ControllerLogradouro.PesquisaCEP(numeroCEP); if (tableEndereco.Rows.Count > 0) { txtAba2Endereco.Text = tableEndereco.Rows[0]["NomeLogradouro"].ToString(); txtAba2Bairro.Text = tableEndereco.Rows[0]["NomeBairro"].ToString(); txtAba2Cidade.Text = tableEndereco.Rows[0]["NomeCidade"].ToString(); cmbAba2UF.SelectedValue = tableEndereco.Rows[0]["IDEstado"].ToString(); } }
private void PesquisarCEP(string numeroTextCEP) { try { int numeroCEP = Convert.ToInt32(numeroTextCEP); DataTable tableEndereco = ControllerLogradouro.PesquisaCEP(numeroCEP); if (tableEndereco.Rows.Count > 0) { txtAba4Endereco.Text = tableEndereco.Rows[0]["NomeLogradouro"].ToString(); txtAba4Bairro.Text = tableEndereco.Rows[0]["NomeBairro"].ToString(); txtAba4Cidade.Text = tableEndereco.Rows[0]["NomeCidade"].ToString(); cmbAba4UF.SelectedValue = tableEndereco.Rows[0]["IDEstado"].ToString(); } else { txtAba4Endereco.Text = string.Empty; txtAba4Bairro.Text = string.Empty; txtAba4Cidade.Text = string.Empty; if (cmbAba4UF.Items.Count > 0) { cmbAba4UF.SelectedIndex = 0; } } } catch (Exception) { txtAba4Endereco.Text = string.Empty; txtAba4Bairro.Text = string.Empty; txtAba4Cidade.Text = string.Empty; if (cmbAba4UF.Items.Count > 0) { cmbAba4UF.SelectedIndex = 0; } } }