예제 #1
0
        public void btnEnviar_Click(object sender, EventArgs e)
        {
            PictureBox[] pbs = { erroEmail, erroCPF, erroRG, erroCNPJ, erroInscEstadual };
            Validacoes.ValidaErro(pbs);
            if (erroEmail.Visible == true)
            {
                txtEmail.Focus();
            }
            else if (erroCPF.Visible == true)
            {
                txtCPF.Focus();
            }
            else if (erroRG.Visible == true)
            {
                txtRG.Focus();
            }
            else if (erroCNPJ.Visible == true)
            {
                txtCNPJ.Focus();
            }
            else if (erroInscEstadual.Visible == true)
            {
                txtInscEstadual.Focus();
            }
            else if (btnPFisica.Checked && (txtRG.Text.Contains(' ') || txtCPF.Text.Contains(' ') || txtEmail.Text == "" || txtNome.Text == "" || txtTelefone.Text.Contains(' ') || txtRua.Text == "" || txtBairro.Text == "" || txtCep.Text.Contains(' ') || txtCidade.Text == "" || txtNum.Text == "" || txtEstado.SelectedItem.ToString() == ""))
            {
                MessageBox.Show("Preencha todos os campos!");
            }
            else if (btnPJuridica.Checked && (txtNome.Text == "" || txtCNPJ.Text.Contains(' ') || txtRazaoSocial.Text == "" || txtInscEstadual.Text.Contains(' ') || txtTelefone.Text.Contains(' ') || txtRua.Text == "" || txtBairro.Text == "" || txtCep.Text.Contains(' ') || txtCidade.Text == "" || txtNum.Text == "" || txtEstado.SelectedItem.ToString() == ""))
            {
                MessageBox.Show("Preencha todos os campos!");
            }
            else
            {
                Cliente        cli = new Cliente();
                PessoaFisica   pf  = new PessoaFisica();
                PessoaJuridica pj  = new PessoaJuridica();
                try
                {
                    cli.Nome        = txtNome.Text;
                    cli.Email       = txtEmail.Text;
                    cli.Telefone    = txtTelefone.Text;
                    cli.Logradouro  = txtRua.Text;
                    cli.Bairro      = txtBairro.Text;
                    cli.Uf          = txtEstado.SelectedItem.ToString();
                    cli.Cidade      = txtCidade.Text;
                    cli.Cep         = txtCep.Text;
                    cli.Numero      = txtNum.Text;
                    cli.Complemento = txtComplemento.Text;
                    cli.Criar();
                    if (btnPFisica.Checked)
                    {
                        pf.Nome = txtNome.Text;
                        pf.Cpf  = txtCPF.Text;
                        pf.CarteiraIdentidade = txtRG.Text;
                        pf.CriarPF();
                    }
                    else
                    {
                        pj.RazaoSocial       = txtRazaoSocial.Text;
                        pj.Cnpj              = txtCNPJ.Text;
                        pj.InscricaoEstadual = txtInscEstadual.Text;
                        pj.CriarPJ();
                    }

                    txtNome.Text         = "";
                    txtTelefone.Text     = "";
                    txtEmail.Text        = "";
                    txtCPF.Text          = "";
                    txtCep.Text          = "";
                    txtRG.Text           = "";
                    txtRua.Text          = "";
                    txtCidade.Text       = "";
                    txtNum.Text          = "";
                    txtBairro.Text       = "";
                    txtRazaoSocial.Text  = "";
                    txtCNPJ.Text         = "";
                    txtInscEstadual.Text = "";
                    txtComplemento.Text  = "";
                }
                catch
                {
                    MessageBox.Show("Erro ao inserir.");
                }
            }
        }