public void limparCampos()
 {
     TXTCPF.Clear();
     TXTEmail.Clear();
     TXTId.Clear();
     TXTNome.Clear();
     DTPNascimento.Text   = "";
     CB_Sexo.SelectedItem = null;
 }
 public void LimparCampos()
 {
     TXTNome.Clear();
     CB_Sexo.SelectedItem = null;
     DTPNascimento.Text   = "";
     TXTEND.Clear();
     TXTEmail.Clear();
     TXTCPF.Clear();
     TXTTEL.Clear();
     TXTID.Clear();
     TXTDescricao.Clear();
 }
 private void BTNLimpaCPF_Click(object sender, EventArgs e)
 {
     TXTCPF.Clear();
 }
Exemple #4
0
        protected void BtGravar_Click1(object sender, EventArgs e)
        {
            //Verifica nome
            if (txtNome.Text == "")
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "Erro!", "alert('Campo nome tem preenchimento obrigatório.');", true);
                plnPopUp_Cliente.Show();
                txtNome.Focus();
                return;
            }

            if (txtNome.Text.Length > 35)
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "Erro!", "alert('Campo nome não pode ter mais que 35 caractéres.');", true);
                plnPopUp_Cliente.Show();
                txtNome.Focus();
                return;
            }

            //Verificação endereço.
            if (TXTEndereco.Text == "")
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "Erro!", "alert('Campo endereço tem seu preenchiemnto obrigatório.');", true);
                plnPopUp_Cliente.Show();
                TXTEndereco.Focus();
                return;
            }

            if (TXTEndereco.Text.Length > 40)
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "Erro!", "alert('Campo endereço não pode ter mais que 40 caracteres.');", true);
                plnPopUp_Cliente.Show();
                TXTEndereco.Focus();
                return;
            }

            //Verificação CPF

            if (TXTCPF.Text == "")
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "Erro!", "alert('Campo CPF/CNPJ tem preenchimento obrigatório.');", true);
                plnPopUp_Cliente.Show();
                TXTCPF.Focus();
                return;
            }

            if (TXTCPF.Text.Length == 14)
            {
                if (!(new Uteis().validaCPF(TXTCPF.Text)))
                {
                    Page.ClientScript.RegisterStartupScript(Page.GetType(), "Erro!", "alert('CPF inválido!');", true);
                    plnPopUp_Cliente.Show();
                    TXTCPF.Focus();
                    return;
                }
            }
            else if (TXTCPF.Text.Length == 18)
            {
                if (!(new Uteis().validaCNPJ(TXTCPF.Text)))
                {
                    Page.ClientScript.RegisterStartupScript(Page.GetType(), "Erro!", "alert('CNPJ inválido!');", true);
                    plnPopUp_Cliente.Show();
                    TXTCPF.Focus();
                    return;
                }
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "Erro!", "alert('CPF ou CNPJ inválido ou preenchido incorretamente.');", true);
                plnPopUp_Cliente.Show();
                TXTCPF.Focus();
                return;
            }

            //Verifica  ponto de referencia

            if (TXTreferencia.Text == "" || TXTreferencia.Text.Length <= 10)
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "Erro!", "alert('Campo ponto de referência não foi preenchido ou contém uma quantidade de informações muito baixa.');", true);
                plnPopUp_Cliente.Show();
                TXTreferencia.Focus();
                return;
            }

            //Verifica Bairro

            if (TXTBairro.Text.Length > 35)
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "Erro!", "alert('Campo bairro não pode ter mais que 35 caracteres.');", true);
                plnPopUp_Cliente.Show();
                TXTBairro.Focus();
                return;
            }



            Cliente clienteNovo;

            try
            {
                if (codSelecionado == 0)
                {
                    clienteNovo = new Cliente(new Conexao().getDb4());
                    clienteNovo.setDataCadastro(new DateTime().Date);
                    //dados dos pais não preenchidos no cadastro rápido
                    clienteNovo.setPai(" ");
                    clienteNovo.setMae(" ");
                    clienteNovo.setEndPais(" ");
                    clienteNovo.setLimite(0);
                }
                else
                {
                    clienteNovo = new Cliente(codSelecionado, new Conexao().getDb4());
                }
                clienteNovo.setNone(txtNome.Text);
                clienteNovo.setEnd(TXTEndereco.Text);
                clienteNovo.setBairro(TXTBairro.Text);
                clienteNovo.setUF(CobUF.SelectedValue);
                clienteNovo.setCidade(CobCidade.SelectedValue);
                clienteNovo.setCPFCNPJ(TXTCPF.Text);

                if (TXTDtNascimento.Text != "")
                {
                    clienteNovo.setDataNascimento(Convert.ToDateTime(TXTDtNascimento.Text));
                }

                clienteNovo.setReferecia(TXTreferencia.Text);
                clienteNovo.setTelefone(TXTTelefone.Text);
                clienteNovo.setOperadora(CobOperadora.SelectedValue);
                if (TXTBairro.Text == "")
                {
                    clienteNovo.setBairro(" ");
                }

                if (TXTEmail.Text == "")
                {
                    clienteNovo.setEmail(" ");
                }
                else
                {
                    clienteNovo.setEmail(TXTEmail.Text);
                }


                if (TXTCep.Text != "")
                {
                    clienteNovo.setCep(TXTCep.Text);
                }

                clienteNovo.setMala(true);
                //Verificando se é um CPF
                Uteis util = new Uteis();
                if (util.validaCNPJ(TXTCPF.Text))
                {
                    clienteNovo.setPessoaJuridica(true);
                }
                else
                {
                    if (util.validaCPF(TXTCPF.Text))
                    {
                        clienteNovo.setPessoaJuridica(false);
                    }
                    else
                    {
                        Page.ClientScript.RegisterStartupScript(Page.GetType(), "Erro!", "alert('CPF ou CNPJ inválido!');", true);
                        return;
                    }
                }

                if (TXTDOC1.Text != "")
                {
                    clienteNovo.setIE(TXTDOC1.Text);
                }
                else
                {
                    clienteNovo.setIE("Isento");
                }

                clienteNovo.setRestrito(false);
                clienteNovo.salvar();
                Master.setClienteSelecionado(clienteNovo);
                txtDoc.Text = TXTCPF.Text;
                bt_buscar_Click(sender, e);
            }
            catch (Exception erro)
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "Erro!", "alert('" + erro.Message + "');", true);
                plnPopUp_Cliente.Show();
            }
        }