private void btnIncluirActionPerformed(java.awt.event.ActionEvent evt) {
if (txtNome.getText().equals("") || jftfCpf.getText().equals("") || jftfTelefone.getText().equals("") || jftfCep.getText().equals("") || txtEndereco.getText().equals("") || txtBairro.getText().equals("") || txtCidade.getText().equals("")) {
JOptionPane.showMessageDialog(null, "Digite nos campos obrigatórios!");
txtNome.requestFocus();
return;
}
boolean cpfvalidado = cpf.validacpf(jftfCpf.getText()); //validacpf
boolean cnpjvalidado = cnpj.validaCnpj(jftfCnpj.getText()); //validacnpj
if (rbFisica.isSelected()) {
if (cpfvalidado) {
try {
bancoDados.Comando = bancoDados.Conexao.prepareStatement("INSERT INTO cadcliente(nomecliente,razaosocial,nomecontato,cpf,insest,telefone,fax,cep,endereco,bairro,cidade,estado,referencia,homepage,email,cnpj) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
bancoDados.Comando.setString(1, txtNome.getText());
bancoDados.Comando.setString(2, txtRazaoSocial.getText());
bancoDados.Comando.setString(3, txtNomeContato.getText());
bancoDados.Comando.setString(4, jftfCpf.getText());
bancoDados.Comando.setString(5, txtInsEst.getText());
bancoDados.Comando.setString(6, jftfTelefone.getText());
bancoDados.Comando.setString(7, jftfFax.getText());
bancoDados.Comando.setString(8, jftfCep.getText());
bancoDados.Comando.setString(9, txtEndereco.getText());
bancoDados.Comando.setString(10, txtBairro.getText());
bancoDados.Comando.setString(11, txtCidade.getText());
bancoDados.Comando.setString(12, jComboBoxEstado.getSelectedItem().toString());
bancoDados.Comando.setString(13, txtReferencia.getText());
bancoDados.Comando.setString(14, txtHomePage.getText());
bancoDados.Comando.setString(15, txtEmail.getText());
bancoDados.Comando.setString(16, jftfCnpj.getText());
bancoDados.Comando.executeUpdate();
JOptionPane.showMessageDialog(null, "Cadastrado com sucesso!");
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Erro: " + e.getMessage(), "Erro", JOptionPane.ERROR_MESSAGE);
}
} else {
JOptionPane.showMessageDialog(null, "Cpf inválido!");
jftfCpf.setText("");
jftfCpf.requestFocus();
}
} else if (rbJuridica.isSelected()) {
if (cnpjvalidado) {
try {
bancoDados.Comando = bancoDados.Conexao.prepareStatement("INSERT INTO cadcliente(nomecliente,razaosocial,nomecontato,cpf,insest,telefone,fax,cep,endereco,bairro,cidade,estado,referencia,homepage,email,cnpj) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
bancoDados.Comando.setString(1, txtNome.getText());
bancoDados.Comando.setString(2, txtRazaoSocial.getText());
bancoDados.Comando.setString(3, txtNomeContato.getText());
bancoDados.Comando.setString(4, jftfCpf.getText());
bancoDados.Comando.setString(5, txtInsEst.getText());
bancoDados.Comando.setString(6, jftfTelefone.getText());
bancoDados.Comando.setString(7, jftfFax.getText());
bancoDados.Comando.setString(8, jftfCep.getText());
bancoDados.Comando.setString(9, txtEndereco.getText());
bancoDados.Comando.setString(10, txtBairro.getText());
bancoDados.Comando.setString(11, txtCidade.getText());
bancoDados.Comando.setString(12, jComboBoxEstado.getSelectedItem().toString());
bancoDados.Comando.setString(13, txtReferencia.getText());
bancoDados.Comando.setString(14, txtHomePage.getText());
bancoDados.Comando.setString(15, txtEmail.getText());
bancoDados.Comando.setString(16, jftfCnpj.getText());
bancoDados.Comando.executeUpdate();
JOptionPane.showMessageDialog(null, "Cadastrado com sucesso!");
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Erro: " + e.getMessage(), "Erro", JOptionPane.ERROR_MESSAGE);
}
} else {
JOptionPane.showMessageDialog(null, "Cnpj inválido!");
jftfCnpj.setText("");
jftfCnpj.requestFocus();
}
}
}