@Override public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals("i")) { try { this.cep = Utilitarios.campoSemCaracteres(this.txtCep.getText()); this.uf = Utilitarios.campoSemCaracteres(this.txtUf.getText()); FormularioExcecoes.campoVazio("Campo CEP", this.cep); FormularioExcecoes.campoVazio("Campo RUA", this.txtRua.getText()); FormularioExcecoes.campoVazio("Campo NÚMERO", this.txtNumero.getText()); FormularioExcecoes.validarCampoNumerico(this.txtNumero.getText().trim(), "NÚMERO"); FormularioExcecoes.campoVazio( "Campo BAIRRO", Utilitarios.campoSemCaracteres(this.txtBairro.getText())); FormularioExcecoes.campoVazio( "Campo CIDADE", Utilitarios.campoSemCaracteres(this.txtCidade.getText())); FormularioExcecoes.campoVazio("Campo UF", this.uf); FormularioExcecoes.validarTamanho( "Para o campo UF digite apenas a sigla correspondente:\n" + "Ex.: SP, RJ, CE, entre outros.", this.uf, 2); Endereco end = new Endereco(); end.setIdEndereco(0); end.setCep(this.cep); end.setRua(this.txtRua.getText()); end.setNumero(Integer.parseInt(this.txtNumero.getText())); end.setComplemento(this.txtComplemento.getText()); end.setBairro(this.txtBairro.getText()); end.setCidade(this.txtCidade.getText()); end.setUf(this.uf); Agencia ag = new Agencia(); ag.setCodBanco(Integer.parseInt(this.txtcodBanco.getText())); ag.setCodAgencia(0); ag.setEndereco(end); AgenciaDAO.inserirAg(ag); Agencia a = AgenciaDAO.ultimaAg(); txtCodAgencia.setText(String.valueOf(a.getCodAgencia())); this.painetTab = new JPanel(new BorderLayout()); super.add(this.painetTab, BorderLayout.CENTER); FabricaComponentes fb3 = new FabricaComponentes(this.painetTab); fb3.addTabelaAg(); } catch (NumberFormatException ex) { JOptionPane.showMessageDialog( null, "Campo NÚMERO contem espaços em branco!", "Erro", JOptionPane.ERROR_MESSAGE); } catch (Excecoes ex) { JOptionPane.showMessageDialog(null, ex.getMessage(), "Erro", JOptionPane.ERROR_MESSAGE); } catch (Exception ex) { JOptionPane.showMessageDialog(null, ex.getMessage(), "Erro", JOptionPane.ERROR_MESSAGE); } } if (e.getActionCommand().equals("c")) { try { this.cep = Utilitarios.campoSemCaracteres(this.txtCep.getText()); this.uf = Utilitarios.campoSemCaracteres(this.txtUf.getText()); FormularioExcecoes.campoVazio("Campo AGÊNCIA", this.txtCodAgencia.getText()); FormularioExcecoes.validarCampoNumerico(this.txtCodAgencia.getText(), "AGÊNCIA"); Agencia ag = AgenciaDAO.consultaAg(Integer.parseInt(this.txtCodAgencia.getText())); this.txtCep.setText(ag.getEndereco().getCep()); this.txtRua.setText(ag.getEndereco().getRua()); this.txtNumero.setText(String.valueOf(ag.getEndereco().getNumero())); this.txtComplemento.setText(ag.getEndereco().getComplemento()); this.txtBairro.setText(ag.getEndereco().getBairro()); this.txtCidade.setText(ag.getEndereco().getCidade()); this.txtUf.setText(ag.getEndereco().getUf()); } catch (IndexOutOfBoundsException ex) { JOptionPane.showMessageDialog( null, "AGÊNCIA não encontrada!", "Erro", JOptionPane.ERROR_MESSAGE); } catch (Excecoes ex) { JOptionPane.showMessageDialog(null, ex.getMessage(), "Erro", JOptionPane.ERROR_MESSAGE); } } if (e.getActionCommand().equals("a")) { try { this.cep = Utilitarios.campoSemCaracteres(this.txtCep.getText()); this.uf = Utilitarios.campoSemCaracteres(this.txtUf.getText()); FormularioExcecoes.campoVazio("Campo AGÊNCIA", this.txtCodAgencia.getText()); FormularioExcecoes.validarCampoNumerico(this.txtCodAgencia.getText(), "AGÊNCIA"); FormularioExcecoes.campoVazio("Campo CEP", this.cep); FormularioExcecoes.campoVazio("Campo RUA", this.txtRua.getText()); FormularioExcecoes.campoVazio("Campo NÚMERO", this.txtNumero.getText()); FormularioExcecoes.validarCampoNumerico(this.txtNumero.getText(), "NÚMERO"); FormularioExcecoes.campoVazio( "Campo BAIRRO", Utilitarios.campoSemCaracteres(this.txtBairro.getText())); FormularioExcecoes.campoVazio( "Campo CIDADE", Utilitarios.campoSemCaracteres(this.txtCidade.getText())); FormularioExcecoes.campoVazio("Campo UF", this.uf); FormularioExcecoes.validarTamanho( "Para o campo UF digite apenas a sigla correspondente:\n" + "Ex.: SP, RJ, CE, entre outros.", this.uf, 2); Agencia a = AgenciaDAO.consultaAg(Integer.parseInt(this.txtCodAgencia.getText())); Endereco end = new Endereco(); end.setIdEndereco(a.getEndereco().getIdEndereco()); end.setCep(this.cep); end.setRua(this.txtRua.getText()); end.setNumero(Integer.parseInt(this.txtNumero.getText())); end.setComplemento(this.txtComplemento.getText()); end.setBairro(this.txtBairro.getText()); end.setCidade(this.txtCidade.getText()); end.setUf(this.uf); Agencia ag = new Agencia(); ag.setEndereco(end); ag.setCodBanco(Integer.parseInt(this.txtcodBanco.getText())); ag.setCodAgencia(Integer.parseInt(this.txtCodAgencia.getText())); GenericoDAO.atualizar(ag); this.painetTab = new JPanel(new BorderLayout()); super.add(this.painetTab, BorderLayout.CENTER); FabricaComponentes fb3 = new FabricaComponentes(this.painetTab); fb3.addTabelaAg(); JOptionPane.showMessageDialog(null, "Atualizado com sucesso!"); } catch (NumberFormatException ex) { JOptionPane.showMessageDialog( null, "Campo NÚMERO contem espaços em branco!", "Erro", JOptionPane.ERROR_MESSAGE); } catch (Excecoes ex) { JOptionPane.showMessageDialog(null, ex.getMessage(), "Erro", JOptionPane.ERROR_MESSAGE); } catch (Exception ex) { JOptionPane.showMessageDialog(null, ex.getMessage(), "Erro", JOptionPane.ERROR_MESSAGE); } } if (e.getActionCommand().equals("e")) { try { this.cep = Utilitarios.campoSemCaracteres(this.txtCep.getText()); this.uf = Utilitarios.campoSemCaracteres(this.txtUf.getText()); FormularioExcecoes.campoVazio("Campo AGÊNCIA", this.txtCodAgencia.getText()); FormularioExcecoes.validarCampoNumerico(this.txtCodAgencia.getText(), "AGÊNCIA"); AgenciaDAO.excluirAg(Integer.parseInt(this.txtCodAgencia.getText())); this.painetTab = new JPanel(new BorderLayout()); super.add(this.painetTab, BorderLayout.CENTER); FabricaComponentes fb3 = new FabricaComponentes(this.painetTab); fb3.addTabelaAg(); } catch (IndexOutOfBoundsException ex) { JOptionPane.showMessageDialog( null, "AGÊNCIA não encontrada!", "Erro", JOptionPane.ERROR_MESSAGE); } catch (Excecoes ex) { JOptionPane.showMessageDialog(null, ex.getMessage(), "Erro", JOptionPane.ERROR_MESSAGE); } catch (Exception ex) { JOptionPane.showMessageDialog( null, "Essa AGÊNCIA possui CLIENTES!", "Erro", JOptionPane.ERROR_MESSAGE); } } if (e.getActionCommand().equals("lp")) { this.txtCodAgencia.setText(""); this.txtCep.setText(""); this.txtRua.setText(""); this.txtNumero.setText(""); this.txtComplemento.setText(""); this.txtBairro.setText(""); this.txtCidade.setText(""); this.txtUf.setText(""); } }