示例#1
0
  private void btnSalvarActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnSalvarActionPerformed
    // Salvar Livro

    try {
      Livro book = new Livro();
      book.setId(id);
      book.setTitulo(txtTitulo.getText());
      book.setAutor(txtAutor.getText());
      book.setIsbn(txtISBN.getText());
      book.setDescricao(txtDescricao.getText());
      book.setAno(Integer.parseInt(txtAno.getText()));

      book.setCategoria(vetorCAT.get(jcomboCategoria.getSelectedIndex()));

      LivroRN bookRN = new LivroRN();

      if (!txtTitulo.getText().isEmpty()
          && !txtAutor.getText().isEmpty()
          && !txtISBN.getText().isEmpty()) {
        String mensagem =
            book.getId() == null ? "Livro incluído com sucesso!" : "Livro alterado com sucesso!";
        bookRN.salvar(book);
        JOptionPane.showMessageDialog(
            this,
            mensagem,
            "Cadastro Livro - Sistema Biblioteca ROS",
            JOptionPane.INFORMATION_MESSAGE);

        // adicionou saio
        this.dispose();
      }

      if (gerenciarLivros != null) {
        gerenciarLivros.populaTabela();
      }

    } catch (Exception e) {
      JOptionPane.showMessageDialog(
          this,
          "Livro não cadastrado!" + "\nPor favor, preencha todos os dados.",
          "Erro - Sistema Biblioteca ROS",
          JOptionPane.ERROR_MESSAGE);
    }
  } // GEN-LAST:event_btnSalvarActionPerformed
示例#2
0
 private void btnExcluirActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnExcluirActionPerformed
   // TODO add your handling code here:
   Livro book = new Livro();
   book.setId(id);
   if (book.getId() == null) {
     JOptionPane.showMessageDialog(this, "O livro deve existir para excluir!");
   } else {
     if (JOptionPane.showConfirmDialog(this, "Deseja mesmo excluir este livro?")
         == JOptionPane.OK_OPTION) {
       try {
         LivroRN bookRN = new LivroRN();
         bookRN.excluir(book);
         JOptionPane.showMessageDialog(this, "Livro excluído com sucesso!");
         this.dispose();
       } catch (Exception e) {
         JOptionPane.showMessageDialog(this, e.getMessage());
       }
     }
     if (gerenciarLivros != null) {
       gerenciarLivros.populaTabela();
     }
   }
 } // GEN-LAST:event_btnExcluirActionPerformed