private void btnFind_Click(object sender, EventArgs e) { string doc = txtDocFind.Text, Error = string.Empty; if (doc.Length == 11)//TAMANHO DO CPF { if (NaturalPerson.VerifyCPF(doc)) { isCPF = true; if (NaturalPersonBLL.HasCPF(doc)) { var person = NaturalPersonBLL.GetUserByCPF(doc); txtName.Text = person.Nome; txtDoc.Text = person.CPF; txtPass.Text = txtConfirmPass.Text = txtGeneratedPass.Text = string.Empty; btnChangePass.Enabled = true; } else { Error += "CPF não encontrado na base de dados."; } } else { Error += "CPF Inválido."; } } else { if (doc.Length == 14)//TAMANHO DO CNPJ { if (LegalPerson.VerifyCNPJ(doc)) { isCPF = false; if (LegalPersonBLL.HasCNPJ(doc)) { var person = LegalPersonBLL.GetUserByCNPJ(doc); txtName.Text = person.NomeFantasia; txtDoc.Text = person.CNPJ; txtPass.Text = txtConfirmPass.Text = txtGeneratedPass.Text = string.Empty; btnChangePass.Enabled = true; } else { Error += "CNPJ não encontrado na base de dados."; } } else { Error += "CNPJ Inválido."; } } else { //NÃO É NEM CPF NEM CNPJ Error += "Não é um CPF ou CNPJ válido."; } } if (!(string.IsNullOrEmpty(Error)) && !(string.IsNullOrWhiteSpace(Error))) { MessageBox.Show(Error); } }
private void btnFind_Click(object sender, EventArgs e) { string doc = textBox1.Text, Error = string.Empty; string[] date; if (doc.Length == 11)//TAMANHO DO CPF { if (NaturalPerson.VerifyCPF(doc)) { isCPF = true; if (NaturalPersonBLL.HasCPF(doc)) { var person = NaturalPersonBLL.GetUserByCPF(doc); person.Contatos = UserBLL.ListContacts(person.UserID); date = person.DataNascimento.Date.ToString().Substring(0, 10).Split('/'); lblDate.Text = "Data de Nasc.:"; lblDOC.Text = "CPF:"; lblNome.Text = "Nome:"; dateTimePicker1.Value = person.DataNascimento; txtName.Text = person.Nome; txtDOC.Text = person.CPF; txtEmail.Text = person.Email; txtBirthDate.Text = $"{date[0]}/{date[1]}/{date[2]}"; txtContact.Text = person.Contatos[0].Contact; lblFirstContact.Text = person.Contatos[0].ID; lblFirstContact.Visible = false; txtContactSecundary.Text = person.Contatos[1].Contact; lblSecondaryContact.Text = person.Contatos[1].ID; lblSecondaryContact.Visible = false; txtCEP.Text = person.CEP; txtDistrict.Text = person.Bairro; txtStreet.Text = person.Rua; txtNumber.Text = person.Numero; txtTown.Text = person.Cidade; txtEstado.Text = person.Estado; txtComplement.Text = person.Complemento; btnRefresh.Enabled = true; } else { Error += "CPF não encontrado na base de dados."; } } else { Error += "CPF Inválido."; } } else { if (doc.Length == 14)//TAMANHO DO CNPJ { if (LegalPerson.VerifyCNPJ(doc)) { isCPF = false; if (LegalPersonBLL.HasCNPJ(doc)) { var person = LegalPersonBLL.GetUserByCNPJ(doc); person.Contatos = UserBLL.ListContacts(person.UserID); date = person.DataFundacao.Date.ToString().Substring(0, 10).Split('/'); lblDate.Text = "Data de Fund.:"; lblDOC.Text = "CNPJ:"; lblNome.Text = "Nome Fantasia:"; dateTimePicker1.Value = person.DataFundacao; txtName.Text = person.NomeFantasia; txtDOC.Text = person.CNPJ; txtEmail.Text = person.Email; txtBirthDate.Text = $"{date[0]}/{date[1]}/{date[2]}"; txtContact.Text = person.Contatos[0].Contact; lblFirstContact.Text = person.Contatos[0].ID; lblFirstContact.Visible = false; txtContactSecundary.Text = person.Contatos[1].Contact; lblSecondaryContact.Text = person.Contatos[1].ID; lblSecondaryContact.Visible = false; txtCEP.Text = person.CEP; txtDistrict.Text = person.Bairro; txtStreet.Text = person.Rua; txtNumber.Text = person.Numero; txtTown.Text = person.Cidade; txtEstado.Text = person.Estado; txtComplement.Text = person.Complemento; btnRefresh.Enabled = true; } else { Error += "CNPJ não encontrado na base de dados."; } } else { Error += "CNPJ Inválido."; } } else { //NÃO É NEM CPF NEM CNPJ Error += "Não é um CPF ou CNPJ válido."; } } if (!(string.IsNullOrEmpty(Error)) && !(string.IsNullOrWhiteSpace(Error))) { MessageBox.Show(Error); } }