private void ValidarCPF(string cpf) { if (!ValidadorCPF.ValidaCPF(cpf)) { notificationContext.AddNotification(Constantes.sChaveErroCPFInvalido, Constantes.sMensagemErroCPFInvalido); } }
private void BtnBuscarCliente_Click(object sender, RoutedEventArgs e) { c = new Cliente(); try { c.Cpf = txtCliente.Text; ValidadorCPF.validaCpf(c.Cpf); c = ClienteDAO.BuscarClientePorCPF(c); if (c != null) //Cliente encontrado { MessageBox.Show("Cliente Encontrado!"); txtClienteNome.Text = c.Nome; txtCliente.IsEnabled = false; btnBuscarCliente.IsEnabled = false; btnAdicionar.IsEnabled = false; } else { //Cliente não encontrado txtCliente.Text = ""; throw new Exception("CLIENTE NÃO encontrado!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void BtnCadastrarCliente_Click(object sender, RoutedEventArgs e) { try { Cliente c = new Cliente(); c.Nome = txtNome.Text; c.Cpf = txtCPF.Text; ValidadorCPF.validaCpf(c.Cpf); if (txtNome.Text.Equals("") || txtCPF.Text.Equals("")) { throw new Exception("É Obrigatório preencher todos os campos"); } if (ClienteDAO.BuscarClientePorCPF(c) != null) { throw new Exception("Cliente já cadastrado!"); } ValidadorCPF.validaCpf(c.Cpf); PessoaDAO.CadastrarPessoa(c); MessageBox.Show("Cliente cadastrado com sucesso"); LimparFormulario(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void BtnBuscarFuncionario_Click(object sender, RoutedEventArgs e) { func = new Funcionario(); try { func.Cpf = txtFuncionario.Text; ValidadorCPF.validaCpf(func.Cpf); func = FuncionarioDAO.BuscarFuncionarioPorCPF(func); if (func != null) //Funcionario encontrado { MessageBox.Show("Funcionario Encontrado!"); txtFuncionarioNome.Text = func.Nome; txtFuncionario.IsEnabled = false; btnBuscarFuncionario.IsEnabled = false; } else { //Funcionario não encontrado txtFuncionario.Text = ""; throw new Exception("FUNCIONARIO NÃO encontrado!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public async Task <IActionResult> Create([Bind("IdCliente,Nome,Cpf,Status,Sexo,CriadoEm,Tipo")] Pessoa pessoa) { if (ValidadorCPF.validaCpf(pessoa.Cpf) != true) { ModelState.AddModelError("", "CPF inválido!"); } else { if (_pessoaDAO.BuscarPorCpf(pessoa.Cpf, pessoa.Tipo)) { string tipo = ""; tipo = pessoa.Tipo == 'C' ? "Cliente" : "Funcionario"; ModelState.AddModelError("", string.Format("Cpf já cadastrado para este {0}", tipo)); } else { if (ModelState.IsValid) { _context.Add(pessoa); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } } return(View(pessoa)); }
public void dado_um_cpf_valido_deve_retornar_valido(long cpfValido) { var cadastro = new AvaliacaoCore.DB.Model.Cadastro(); cadastro.CPF = cpfValido; var validador = new ValidadorCPF(); var resultado = validador.Validar(cadastro); Assert.IsTrue(resultado.Valido); Assert.IsNull(resultado.Mensagem); }
public void dado_um_cpf_invalido_deve_retornar_invalido(long cpfInvalido) { var cadastro = new AvaliacaoCore.DB.Model.Cadastro(); cadastro.CPF = cpfInvalido; var validador = new ValidadorCPF(); var resultado = validador.Validar(cadastro); Assert.IsFalse(resultado.Valido); StringAssert.Contains(resultado.Mensagem, "CPF"); StringAssert.Contains(resultado.Mensagem, "inválido"); }
public void CPFFormatadoInvalidoMaiorQue14() { string CPF = "035.989.666-951"; ValidadorCPF validadorCPF = null; try { validadorCPF = new ValidadorCPF(); validadorCPF.ValidarCPF(CPF); Assert.IsTrue(false); } catch (Exception ex) { Assert.IsTrue(ex.Message.Contains("CPF inválido")); } }
public void CPFInválidoMaiorQue11() { string CPF = "000000000000"; ValidadorCPF validadorCPF = null; try { validadorCPF = new ValidadorCPF(); validadorCPF.ValidarCPF(CPF); Assert.IsTrue(false); } catch (Exception ex) { Assert.IsTrue(ex.Message.Contains("CPF inválido")); } }
public void CPFFormatadoValido() { string CPF = "035.989.666-95"; ValidadorCPF validadorCPF = null; try { validadorCPF = new ValidadorCPF(); validadorCPF.ValidarCPF(CPF); Assert.IsTrue(true); } catch (Exception ex) { Assert.IsTrue(false); } }
public void CPFValido() { string CPF = "37400260227"; ValidadorCPF validadorCPF = null; try { validadorCPF = new ValidadorCPF(); validadorCPF.ValidarCPF(CPF); Assert.IsTrue(true); } catch (Exception ex) { Assert.IsTrue(false); } }
private void btnSalvar_Click(object sender, EventArgs e) { var cliente = new Clientes(); cliente.Nome = txtNome.Text; cliente.CPF = txtCPF.Text; cliente.DataNascimento = txtDataNascimento.Value; //Mando para o BD - Salvar Dados if (!ValidadorCPF.eValido(cliente.CPF)) { MessageBox.Show("CPF inválido. ", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { MessageBox.Show("CPF válido. ", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void CPFClienteMaskedBox_Leave(object sender, EventArgs e) { if (ValidadorCPF.ValidarCPF(CPFClienteMaskedBox.Text.Replace("_", "")) || CPFClienteMaskedBox.Text.Equals("___.___.___-__")) { } else { MessageBox.Show("Verifique o CPF informado!", "CPF inválido", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); if (CPFClienteMaskedBox.Text.Contains("_")) { CPFClienteMaskedBox.Text = ""; } } }
private void BtnCadastrarFunc_Click(object sender, RoutedEventArgs e) { try { Funcionario f = new Funcionario(); f.Nome = txtNomeFunc.Text; f.Cpf = txtCPFFunc.Text; ValidadorCPF.validaCpf(f.Cpf); f.Salario = Convert.ToDouble(txtSalarioFunc.Text); f.Comissao = Convert.ToDouble(txtComissaoFunc.Text); if (txtNomeFunc.Text.Equals("") || txtCPFFunc.Text.Equals("") || txtSalarioFunc.Text.Equals("") || txtComissaoFunc.Text.Equals("")) { throw new Exception("É Obrigatório preencher todos os campos"); } if (FuncionarioDAO.BuscarFuncionarioPorCPF(f) != null) { throw new Exception("Funcionario já cadastrado!"); } if (f.Comissao > 10) { txtComissaoFunc.Clear(); txtComissaoFunc.Focus(); throw new Exception("A comissão é de no máximo 10%.\nFavor corrigir."); } ValidadorCPF.validaCpf(f.Cpf); PessoaDAO.CadastrarPessoa(f); MessageBox.Show("Funcionario cadastrado com sucesso"); LimparFormulario(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void CPFFormatacaoValida() { string CPF = "37400260227"; ValidadorCPF validadorCPF = null; try { validadorCPF = new ValidadorCPF(); if (validadorCPF.FormatarCPF(CPF).Length == 14) { Assert.IsTrue(true); } else { Assert.IsTrue(false); } } catch (Exception ex) { Assert.IsTrue(false); } }
public void CPFFormatacaoInValida() { string CPF = "374002602271"; ValidadorCPF validadorCPF = null; try { validadorCPF = new ValidadorCPF(); if (validadorCPF.FormatarCPF(CPF).Length > 14) { Assert.IsTrue(true); } else { Assert.IsTrue(false); } } catch (Exception ex) { Assert.IsTrue(ex.Message.Contains("CPF inválido")); } }
public void CPFRetirarFormatacaoValida() { string CPF = "035.989.666-95"; ValidadorCPF validadorCPF = null; try { validadorCPF = new ValidadorCPF(); if (validadorCPF.RetirarFormatacaoCPF(CPF).Length == 11) { Assert.IsTrue(true); } else { Assert.IsTrue(false); } } catch (Exception ex) { Assert.IsTrue(false); } }
public void CPFRetirarFormatacaoInValida() { string CPF = "035.989.666-951"; ValidadorCPF validadorCPF = null; try { validadorCPF = new ValidadorCPF(); if (validadorCPF.RetirarFormatacaoCPF(CPF).Length > 14) { Assert.IsTrue(false); } else { Assert.IsTrue(true); } } catch (Exception ex) { Assert.IsTrue(ex.Message.Contains("CPF inválido")); } }
public void TestarValidadorCPFValido() { var cpf = "33214080822"; Assert.True(ValidadorCPF.ValidaCPF(cpf)); }
public void TestarValidadorCPFInvalido() { var cpf = "33210080822"; Assert.False(ValidadorCPF.ValidaCPF(cpf)); }