diff --git a/biblioteka.db b/biblioteka.db index 08e4013..be59963 100644 Binary files a/biblioteka.db and b/biblioteka.db differ diff --git a/sqlite-sterownik.jar b/sqlite-sterownik.jar index 70be427..3977122 100644 Binary files a/sqlite-sterownik.jar and b/sqlite-sterownik.jar differ diff --git a/src/library/AlbumFieldPattern.form b/src/library/AlbumFieldPattern.form index a39815d..fddb3e5 100644 --- a/src/library/AlbumFieldPattern.form +++ b/src/library/AlbumFieldPattern.form @@ -30,8 +30,9 @@ + - + @@ -59,9 +60,17 @@ - - - + + + + + + + + + + + @@ -182,5 +191,10 @@ + + + + + diff --git a/src/library/AlbumFieldPattern.java b/src/library/AlbumFieldPattern.java index 91203e2..736ac65 100644 --- a/src/library/AlbumFieldPattern.java +++ b/src/library/AlbumFieldPattern.java @@ -17,7 +17,7 @@ import javax.swing.JOptionPane; */ public class AlbumFieldPattern extends javax.swing.JFrame { - public boolean add = false, delete = false, edit = false, search = false; + public boolean add = false, delete = false, edit = false, search = false, update = false; private Database d = new Database(); /** @@ -28,7 +28,7 @@ public class AlbumFieldPattern extends javax.swing.JFrame { this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); } - public AlbumFieldPattern(boolean required) { + public AlbumFieldPattern(boolean required, Album... a) { initComponents(); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); Validation verify; @@ -40,9 +40,25 @@ public class AlbumFieldPattern extends javax.swing.JFrame { albumTitle.setInputVerifier(verify); musican.setInputVerifier(verify); year.setInputVerifier(verify); + try { + if (a[0].getId() >= 0) { + fillField(a[0]); + update = true; + } + } catch (ArrayIndexOutOfBoundsException e) { + //when only one parameter is defined + } } - public void search(Album a) { + public void fillField(Album a) { + idValue.setText(Integer.toString(a.getId())); + albumTitle.setText(a.getName()); + musican.setText(a.getMusican()); + year.setText(Integer.toString(a.getYear())); + Category.setSelectedItem(a.getCategory()); + } + + public void search(Album a, String... mode) { try { List albums = new LinkedList<>(); albums = d.selectAlbums(a); @@ -53,8 +69,14 @@ public class AlbumFieldPattern extends javax.swing.JFrame { "Muzyk/Zespół", "Rok", "Kategoria"}; - ListResult table = new ListResult(data, columnNames); + ListResult table = new ListResult(data, columnNames, "album"); table.setVisible(true); + if (mode[0].equals("edit")) { + table.setEnabledButton("edit"); + } + if (mode[0].equals("delete")) { + table.setEnabledButton("delete"); + } } catch (IndexOutOfBoundsException e) { //nothing to do here @@ -80,6 +102,7 @@ public class AlbumFieldPattern extends javax.swing.JFrame { Category = new javax.swing.JComboBox<>(); mainlabel = new javax.swing.JLabel(); SaveChanges = new javax.swing.JButton(); + idValue = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); @@ -116,6 +139,8 @@ public class AlbumFieldPattern extends javax.swing.JFrame { } }); + idValue.setText("."); + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( @@ -126,8 +151,9 @@ public class AlbumFieldPattern extends javax.swing.JFrame { .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(Title) - .addComponent(lmusican)) - .addGap(56, 56, 56) + .addComponent(lmusican) + .addComponent(idValue, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(49, 49, 49) .addComponent(mainlabel, javax.swing.GroupLayout.PREFERRED_SIZE, 289, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addComponent(lyear, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE) @@ -148,8 +174,13 @@ public class AlbumFieldPattern extends javax.swing.JFrame { layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() - .addComponent(mainlabel) - .addGap(18, 18, 18) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(mainlabel) + .addGap(18, 18, 18)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addComponent(idValue) + .addGap(7, 7, 7))) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(Title) .addComponent(albumTitle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) @@ -188,11 +219,22 @@ public class AlbumFieldPattern extends javax.swing.JFrame { } } else if (this.edit) { Album a = new Album(0, albumTitle.getText(), musican.getText(), year.getText(), Category.getSelectedItem().toString()); - this.search(a); + this.search(a, "edit"); } else if (this.delete) { - JOptionPane.showMessageDialog(null, "USUŃ"); + Album a = new Album(0, albumTitle.getText(), musican.getText(), year.getText(), Category.getSelectedItem().toString()); + this.search(a, "delete"); + } else if (this.search) { + Album a = new Album(0, albumTitle.getText(), musican.getText(), year.getText(), Category.getSelectedItem().toString()); + this.search(a); + } else if (this.update) { + Album a = new Album(Integer.parseInt(idValue.getText()), albumTitle.getText(), musican.getText(), year.getText(), Category.getSelectedItem().toString()); + try { + d.updateQ(a); + } catch (SQLException e) { + e.printStackTrace(); + } } - + dispose(); }//GEN-LAST:event_SaveChangesActionPerformed /** @@ -239,6 +281,7 @@ public class AlbumFieldPattern extends javax.swing.JFrame { private javax.swing.JButton SaveChanges; private javax.swing.JLabel Title; private javax.swing.JTextField albumTitle; + private javax.swing.JLabel idValue; private javax.swing.JLabel lcategory; private javax.swing.JLabel lmusican; private javax.swing.JLabel lyear; diff --git a/src/library/BookFieldPattern.form b/src/library/BookFieldPattern.form index ac45a4c..dadbf79 100644 --- a/src/library/BookFieldPattern.form +++ b/src/library/BookFieldPattern.form @@ -26,18 +26,6 @@ - - - - - - - - - - - - @@ -59,20 +47,39 @@ + + + + + + + + + + + + + + + + + + + + + - - - - - - + + + + @@ -290,5 +297,10 @@ + + + + + diff --git a/src/library/BookFieldPattern.java b/src/library/BookFieldPattern.java index a003997..e8efd02 100644 --- a/src/library/BookFieldPattern.java +++ b/src/library/BookFieldPattern.java @@ -20,7 +20,8 @@ import javax.swing.JOptionPane; */ public class BookFieldPattern extends javax.swing.JFrame { - public boolean add = false, delete = false, edit = false, search = false; + public boolean add = false, delete = false, edit = false, search = false, update = false; + public Book b; private Database d = new Database(); public BookFieldPattern() { @@ -32,7 +33,7 @@ public class BookFieldPattern extends javax.swing.JFrame { } - public BookFieldPattern(boolean required) { + public BookFieldPattern(boolean required, Book... b) { initComponents(); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); Validation verify; @@ -47,9 +48,28 @@ public class BookFieldPattern extends javax.swing.JFrame { year.setInputVerifier(verify); ISBN.setInputVerifier(verify); publishing.setInputVerifier(verify); + try { + if (b[0].getId() >= 0) { + fillField(b[0]); + update = true; + } + } catch (ArrayIndexOutOfBoundsException e) { + //when only one parameter is defined + } } - public void search(Book b) { + public void fillField(Book b) { + idValue.setText(Integer.toString(b.getId())); + bookTitle.setText(b.getName()); + authorName.setText(b.getAuthorName()); + authorSurname.setText(b.getAuthorSurname()); + publishing.setText(b.getPublishing()); + year.setText(Integer.toString(b.getYear())); + ISBN.setText(b.getISBN()); + Category.setSelectedItem(b.getCategory()); + } + + public void search(Book b, String... mode) { try { List books = new LinkedList<>(); books = d.selectBooks(b); @@ -62,8 +82,14 @@ public class BookFieldPattern extends javax.swing.JFrame { "ISBN", "Wydawnictwo", "Kategoria"}; - ListResult table = new ListResult(data, columnNames); + ListResult table = new ListResult(data, columnNames, "book"); table.setVisible(true); + if (mode[0].equals("edit")) { + table.setEnabledButton("edit"); + } + if (mode[0].equals("delete")) { + table.setEnabledButton("delete"); + } } catch (IndexOutOfBoundsException e) { } } @@ -94,6 +120,7 @@ public class BookFieldPattern extends javax.swing.JFrame { mainlabel = new javax.swing.JLabel(); SaveChanges = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); + idValue = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); @@ -181,6 +208,8 @@ public class BookFieldPattern extends javax.swing.JFrame { jLabel1.setDoubleBuffered(true); jLabel1.setName(""); // NOI18N + idValue.setText("."); + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( @@ -188,15 +217,6 @@ public class BookFieldPattern extends javax.swing.JFrame { .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(Title) - .addComponent(authorname)) - .addGap(35, 35, 35) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(authorName, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(bookTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 363, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(0, 20, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(lcategory, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) @@ -214,17 +234,30 @@ public class BookFieldPattern extends javax.swing.JFrame { .addComponent(SaveChanges, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addComponent(jLabel1) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(mainlabel, javax.swing.GroupLayout.PREFERRED_SIZE, 289, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(71, 71, 71)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(Title) + .addComponent(authorname)) + .addGap(35, 35, 35) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(authorName, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(bookTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 363, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addGroup(layout.createSequentialGroup() + .addComponent(idValue, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(mainlabel, javax.swing.GroupLayout.PREFERRED_SIZE, 289, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addGap(0, 20, Short.MAX_VALUE)))) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() - .addComponent(mainlabel) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(mainlabel) + .addComponent(idValue)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(Title) @@ -281,13 +314,22 @@ public class BookFieldPattern extends javax.swing.JFrame { } catch (SQLException e) { e.getMessage(); } - } else if (this.edit) { - Book b = new Book(0, bookTitle.getText(), authorName.getText(), authorSurname.getText(), year.getText(), ISBN.getText(), publishing.getText(), Category.getSelectedItem().toString()); - this.search(b); + Book b = new Book(0, bookTitle.getText(), authorName.getText(), authorSurname.getText(), year.getText(), ISBN.getText(), publishing.getText(), Category.getSelectedItem().toString()); + this.search(b, "edit"); } else if (this.delete) { - JOptionPane.showMessageDialog(null, "USUŃ"); + Book b = new Book(0, bookTitle.getText(), authorName.getText(), authorSurname.getText(), year.getText(), ISBN.getText(), publishing.getText(), Category.getSelectedItem().toString()); + this.search(b, "delete"); } else if (this.search) { + Book b = new Book(0, bookTitle.getText(), authorName.getText(), authorSurname.getText(), year.getText(), ISBN.getText(), publishing.getText(), Category.getSelectedItem().toString()); + this.search(b); + } else if (this.update) { + Book b = new Book(Integer.parseInt(idValue.getText()), bookTitle.getText(), authorName.getText(), authorSurname.getText(), year.getText(), ISBN.getText(), publishing.getText(), Category.getSelectedItem().toString()); + try { + d.updateQ(b); + } catch (SQLException e) { + e.printStackTrace(); + } } dispose(); @@ -327,16 +369,24 @@ public class BookFieldPattern extends javax.swing.JFrame { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; + } } } catch (ClassNotFoundException ex) { - java.util.logging.Logger.getLogger(BookFieldPattern.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + java.util.logging.Logger.getLogger(BookFieldPattern.class + .getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { - java.util.logging.Logger.getLogger(BookFieldPattern.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + java.util.logging.Logger.getLogger(BookFieldPattern.class + .getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { - java.util.logging.Logger.getLogger(BookFieldPattern.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + java.util.logging.Logger.getLogger(BookFieldPattern.class + .getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { - java.util.logging.Logger.getLogger(BookFieldPattern.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + java.util.logging.Logger.getLogger(BookFieldPattern.class + .getName()).log(java.util.logging.Level.SEVERE, null, ex); } // // @@ -360,6 +410,7 @@ public class BookFieldPattern extends javax.swing.JFrame { private javax.swing.JLabel authorname; private javax.swing.JLabel authorsurname; javax.swing.JTextField bookTitle; + private javax.swing.JLabel idValue; private javax.swing.JLabel jLabel1; private javax.swing.JLabel lISBN; private javax.swing.JLabel lcategory; diff --git a/src/library/Database.java b/src/library/Database.java index d49b74a..02517df 100644 --- a/src/library/Database.java +++ b/src/library/Database.java @@ -126,7 +126,7 @@ public class Database { } catch (SQLException e) { JOptionPane.showMessageDialog(null, "Błąd przy dodawaniu do bazy", "Error:", JOptionPane.INFORMATION_MESSAGE); e.printStackTrace(); - throw new SQLException("Error dodawania albumu"); + throw new SQLException("Error dodawania filmu"); } } @@ -308,7 +308,7 @@ public class Database { public List selectMovies(Movie searchData) { List movies = new ArrayList<>(); - String query = ""; + String query = new String(); try { List wheres = new ArrayList<>(); if (searchData.getName().length() > 0) { @@ -324,6 +324,7 @@ public class Database { wheres.add("category LIKE '" + searchData.getCategory() + "'"); } if (!wheres.isEmpty()) { + System.out.println(wheres.size()); if (wheres.size() == 1) { query = "SELECT * FROM movies WHERE " + wheres.get(0) + ";"; } else if (wheres.size() > 1) { @@ -336,18 +337,18 @@ public class Database { query += " AND " + wheres.get(i) + ";"; } } - System.out.println(query); - ResultSet result = stat.executeQuery(query); - int id; - String name, category, director, year; - while (result.next()) { - id = result.getInt("id"); - year = result.getString("year"); - name = result.getString("name"); - director = result.getString("director"); - category = result.getString("category"); - movies.add(new Movie(id, name, director, year, category)); - } + } + System.out.println(query); + ResultSet result = stat.executeQuery(query); + int id; + String name, category, director, year; + while (result.next()) { + id = result.getInt("id"); + year = result.getString("year"); + name = result.getString("name"); + director = result.getString("director"); + category = result.getString("category"); + movies.add(new Movie(id, name, director, year, category)); } } @@ -375,24 +376,84 @@ public class Database { return 0; } + public void updateQ(T obj) throws SQLException { + if (obj instanceof Book) { + try { + Book b = (Book) obj; + PreparedStatement prepStmt = conn.prepareStatement( + "UPDATE books SET name = ?, author_name = ?, author_surname = ?, publishing = ?, year = ?, isbn = ?, category = ? WHERE id = ?;"); + prepStmt.setString(1, b.getName()); + prepStmt.setString(2, b.getAuthorName()); + prepStmt.setString(3, b.getAuthorSurname()); + prepStmt.setString(4, b.getPublishing()); + prepStmt.setInt(5, b.getYear()); + prepStmt.setString(6, b.getISBN()); + prepStmt.setString(7, b.getCategory()); + prepStmt.setInt(8, b.getId()); + System.out.println(prepStmt.toString()); + prepStmt.executeUpdate(); + JOptionPane.showMessageDialog(null, "Zaktualizowano książkę poprawnie.", "Informacja:", JOptionPane.INFORMATION_MESSAGE); + } catch (SQLException e) { + JOptionPane.showMessageDialog(null, "Błąd przy aktualiacji bazy", "Error:", JOptionPane.INFORMATION_MESSAGE); + e.printStackTrace(); + throw new SQLException("Error aktualizacji ksiazki"); + } + } else if (obj instanceof Album) { + try { + Album a = (Album) obj; + PreparedStatement prepStmt = conn.prepareStatement( + "UPDATE albums SET name = ?, musican = ?, year = ?, category = ? WHERE id = ?;"); + prepStmt.setString(1, a.getName()); + prepStmt.setString(2, a.getMusican()); + prepStmt.setInt(3, a.getYear()); + prepStmt.setString(4, a.getCategory()); + prepStmt.setInt(5, a.getId()); + System.out.println(prepStmt.toString()); + prepStmt.executeUpdate(); + JOptionPane.showMessageDialog(null, "Zaktualizowano album poprawnie.", "Informacja:", JOptionPane.INFORMATION_MESSAGE); + } catch (SQLException e) { + JOptionPane.showMessageDialog(null, "Błąd przy aktualiacji bazy", "Error:", JOptionPane.INFORMATION_MESSAGE); + e.printStackTrace(); + throw new SQLException("Error aktualizacji albumu"); + } + } else if (obj instanceof Movie) { + try { + Movie m = (Movie) obj; + PreparedStatement prepStmt = conn.prepareStatement( + "UPDATE movies SET name = ?, director = ?, year = ?, category = ? WHERE id = ?;"); + prepStmt.setString(1, m.getName()); + prepStmt.setString(2, m.getDirector()); + prepStmt.setInt(3, m.getYear()); + prepStmt.setString(4, m.getCategory()); + prepStmt.setInt(5, m.getId()); + System.out.println(prepStmt.toString()); + prepStmt.executeUpdate(); + JOptionPane.showMessageDialog(null, "Zaktualizowano film poprawnie.", "Informacja:", JOptionPane.INFORMATION_MESSAGE); + } catch (SQLException e) { + JOptionPane.showMessageDialog(null, "Błąd przy aktualiacji bazy", "Error:", JOptionPane.INFORMATION_MESSAGE); + e.printStackTrace(); + throw new SQLException("Error aktualizacji filmu"); + } + } + } + public Object[][] convertToTable(List l) { try { Object first = l.get(0); - String type = first.getClass().getName(); int i = l.size(); - if (type.equals("library.Book")) { + if (first instanceof Book) { Object tab[][] = new Object[i][8]; for (int y = 0; y < i; y++) { //kolejne wiersze danych tab = Book.insertRowToTable(tab, y, (Book) l.get(y)); } return tab; - } else if (type.equals("library.Album")) { + } else if (first instanceof Album) { Object tab[][] = new Object[i][5]; for (int y = 0; y < i; y++) { //kolejne wiersze danych tab = Album.insertRowToTable(tab, y, (Album) l.get(y)); } return tab; - } else if (type.equals("library.Movie")) { + } else if (first instanceof Movie) { Object tab[][] = new Object[i][5]; for (int y = 0; y < i; y++) { //kolejne wiersze danych tab = Movie.insertRowToTable(tab, y, (Movie) l.get(y)); @@ -401,7 +462,7 @@ public class Database { } } catch (IndexOutOfBoundsException e) { JOptionPane.showMessageDialog(null, "Brak danych.", "Error:", JOptionPane.INFORMATION_MESSAGE); - throw new IndexOutOfBoundsException("Poza zakresem"); + throw new IndexOutOfBoundsException("dł.tablicy = 0"); } return null; diff --git a/src/library/ListResult.form b/src/library/ListResult.form index 8a1fcb1..5a7be6c 100644 --- a/src/library/ListResult.form +++ b/src/library/ListResult.form @@ -33,13 +33,16 @@ - - - - + + + + + + + @@ -49,9 +52,12 @@ - - - + + + + + + @@ -75,12 +81,10 @@ - + - - - + @@ -89,21 +93,29 @@ + - + - + + - + + + + + + + + + + - - - diff --git a/src/library/ListResult.java b/src/library/ListResult.java index 28ed1dd..e45c10a 100644 --- a/src/library/ListResult.java +++ b/src/library/ListResult.java @@ -10,6 +10,7 @@ import java.util.List; import javax.swing.JFrame; import javax.swing.ListSelectionModel; import javax.swing.event.ListSelectionEvent; +import javax.swing.table.DefaultTableModel; /** * @@ -20,15 +21,16 @@ public class ListResult extends javax.swing.JFrame { /** * Creates new form NewJFrame */ - private Object[][] rows; - private Object[] columnsNames; + public String dataType; + private final Object[][] rows; + private final Object[] columnsNames; - public ListResult(Object[][] rowData, Object[] colNam) { + public ListResult(Object[][] rowData, Object[] colNam, String dataT) { rows = rowData; columnsNames = colNam; + dataType = dataT; initComponents(); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - } /** @@ -43,7 +45,8 @@ public class ListResult extends javax.swing.JFrame { mainlabel = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); table = new javax.swing.JTable(rows, columnsNames); - OK = new javax.swing.JButton(); + editButton = new javax.swing.JButton(); + deleteButton = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); @@ -52,36 +55,35 @@ public class ListResult extends javax.swing.JFrame { mainlabel.setText("Tabela danych"); table.setAutoCreateColumnsFromModel(false); - table.setModel(new javax.swing.table.DefaultTableModel( - rows, - columnsNames - )); - table.setModel(new javax.swing.table.DefaultTableModel( - rows, - columnsNames - )); table.setRowSelectionInterval(0, 0); table.setRowHeight(25); table.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); jScrollPane1.setViewportView(table); + DefaultTableModel tableModel = new DefaultTableModel(rows, columnsNames) { - OK.setText("Wybierz pozycję..."); - OK.addActionListener(new java.awt.event.ActionListener() { + @Override + public boolean isCellEditable(int row, int column) { + //all cells false + return false; + } + }; + table.setModel(tableModel); + + editButton.setText("Edytuj"); + editButton.setEnabled(false); + editButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { - OKActionPerformed(evt); + editButtonActionPerformed(evt); } }); - int row = table.getSelectedRow(); - if(row == -1) - { - OK.setVisible(false); - } - else - { - - // do whatever you need to do with the data from the row - } + deleteButton.setText("Usuń"); + deleteButton.setEnabled(false); + deleteButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + deleteButtonActionPerformed(evt); + } + }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); @@ -94,11 +96,14 @@ public class ListResult extends javax.swing.JFrame { .addComponent(mainlabel, javax.swing.GroupLayout.PREFERRED_SIZE, 289, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addGap(23, 23, 23) - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 1180, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(layout.createSequentialGroup() - .addGap(496, 496, 496) - .addComponent(OK, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 1180, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(26, Short.MAX_VALUE)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .addComponent(editButton) + .addGap(18, 18, 18) + .addComponent(deleteButton) + .addGap(548, 548, 548)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -107,17 +112,70 @@ public class ListResult extends javax.swing.JFrame { .addComponent(mainlabel) .addGap(13, 13, 13) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 473, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(32, 32, 32) - .addComponent(OK) - .addContainerGap(33, Short.MAX_VALUE)) + .addGap(18, 18, 18) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(editButton) + .addComponent(deleteButton)) + .addContainerGap(47, Short.MAX_VALUE)) ); pack(); }// //GEN-END:initComponents - private void OKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OKActionPerformed - // TODO add your handling code here: - }//GEN-LAST:event_OKActionPerformed + public boolean isCellEditable(int row, int col) { + return false; + } + private void editButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editButtonActionPerformed + int selectedRowIndex = table.getSelectedRow(); + System.out.println(selectedRowIndex); + if (dataType.equals("book")) { + Book b = new Book( + (Integer) table.getValueAt(selectedRowIndex, 0), + (String) table.getValueAt(selectedRowIndex, 1), + (String) table.getValueAt(selectedRowIndex, 2), + (String) table.getValueAt(selectedRowIndex, 3), + Integer.toString((Integer) table.getValueAt(selectedRowIndex, 4)), + (String) table.getValueAt(selectedRowIndex, 5), + (String) table.getValueAt(selectedRowIndex, 6), + (String) table.getValueAt(selectedRowIndex, 7)); + + BookFieldPattern bookPattern = new BookFieldPattern(true, b); + bookPattern.setVisible(true); + } else if (dataType.equals("movie")) { + Movie m = new Movie( + (Integer) table.getValueAt(selectedRowIndex, 0), + (String) table.getValueAt(selectedRowIndex, 1), + (String) table.getValueAt(selectedRowIndex, 2), + Integer.toString((Integer) table.getValueAt(selectedRowIndex, 3)), + (String) table.getValueAt(selectedRowIndex, 4)); + MovieFieldPattern moviePattern = new MovieFieldPattern(true, m); + moviePattern.setVisible(true); + } else if (dataType.equals("album")) { + Album a = new Album( + (Integer) table.getValueAt(selectedRowIndex, 0), + (String) table.getValueAt(selectedRowIndex, 1), + (String) table.getValueAt(selectedRowIndex, 2), + Integer.toString((Integer) table.getValueAt(selectedRowIndex, 3)), + (String) table.getValueAt(selectedRowIndex, 4)); + AlbumFieldPattern albumPattern = new AlbumFieldPattern(true, a); + albumPattern.setVisible(true); + } + dispose(); + }//GEN-LAST:event_editButtonActionPerformed + + private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteButtonActionPerformed + int selectedRowIndex = table.getSelectedRow(); + System.out.println(selectedRowIndex); + + }//GEN-LAST:event_deleteButtonActionPerformed + + public void setEnabledButton(String which) { + if (which.equals("edit")) { + editButton.setEnabled(true); + } else if (which.equals("delete")) { + deleteButton.setEnabled(true); + } + } /** * @param args the command line arguments @@ -165,7 +223,8 @@ public class ListResult extends javax.swing.JFrame { } // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton OK; + private javax.swing.JButton deleteButton; + private javax.swing.JButton editButton; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JLabel mainlabel; private javax.swing.JTable table; diff --git a/src/library/MainMenu.form b/src/library/MainMenu.form index 5138dfa..40a2bed 100644 --- a/src/library/MainMenu.form +++ b/src/library/MainMenu.form @@ -31,32 +31,31 @@ - + + + + + + - - - - + - - - - - - - - - - + + + - + + + + + @@ -64,17 +63,18 @@ - + - - - - + + + + + - + @@ -116,12 +116,12 @@ - + - + @@ -135,7 +135,7 @@ - + @@ -196,7 +196,7 @@ - + @@ -204,7 +204,7 @@ - + diff --git a/src/library/MainMenu.java b/src/library/MainMenu.java index 8cc8d7e..212cbd4 100644 --- a/src/library/MainMenu.java +++ b/src/library/MainMenu.java @@ -41,7 +41,7 @@ public class MainMenu extends javax.swing.JFrame { bBook = new javax.swing.JButton(); radioBAdd = new javax.swing.JRadioButton(); radioBEdit = new javax.swing.JRadioButton(); - radioBDelete1 = new javax.swing.JRadioButton(); + radioBDelete = new javax.swing.JRadioButton(); radioBSearch = new javax.swing.JRadioButton(); jPanel1 = new javax.swing.JPanel(); allMovieShow = new javax.swing.JButton(); @@ -108,11 +108,11 @@ public class MainMenu extends javax.swing.JFrame { } }); - mode.add(radioBDelete1); - radioBDelete1.setText("Usuwanie"); - radioBDelete1.addActionListener(new java.awt.event.ActionListener() { + mode.add(radioBDelete); + radioBDelete.setText("Usuwanie"); + radioBDelete.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { - radioBDelete1ActionPerformed(evt); + radioBDeleteActionPerformed(evt); } }); @@ -141,12 +141,12 @@ public class MainMenu extends javax.swing.JFrame { .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(searchButtonsPanelLayout.createSequentialGroup() .addComponent(radioBSearch) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 61, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 133, Short.MAX_VALUE) .addComponent(radioBAdd) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(radioBEdit) .addGap(18, 18, 18) - .addComponent(radioBDelete1) + .addComponent(radioBDelete) .addGap(78, 78, 78)))) ); searchButtonsPanelLayout.setVerticalGroup( @@ -156,7 +156,7 @@ public class MainMenu extends javax.swing.JFrame { .addGroup(searchButtonsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(radioBAdd) .addComponent(radioBEdit) - .addComponent(radioBDelete1) + .addComponent(radioBDelete) .addComponent(radioBSearch)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(searchButtonsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) @@ -327,40 +327,40 @@ public class MainMenu extends javax.swing.JFrame { .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() - .addComponent(programTitle, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addComponent(programTitle, javax.swing.GroupLayout.DEFAULT_SIZE, 817, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() + .addGap(359, 359, 359) + .addComponent(jLabel1)) + .addGroup(layout.createSequentialGroup() + .addGap(19, 19, 19) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jToggleButton1) .addGroup(layout.createSequentialGroup() - .addGap(359, 359, 359) - .addComponent(jLabel1)) - .addGroup(layout.createSequentialGroup() - .addGap(26, 26, 26) - .addComponent(searchButtonsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(layout.createSequentialGroup() - .addGap(19, 19, 19) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jToggleButton1)))) - .addGap(0, 0, Short.MAX_VALUE))) + .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))) .addContainerGap()) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .addComponent(searchButtonsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGap(141, 141, 141)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(24, 24, 24) .addComponent(programTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(13, 13, 13) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(searchButtonsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(18, 18, 18) .addComponent(jToggleButton1) - .addContainerGap(43, Short.MAX_VALUE)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); pack(); @@ -382,6 +382,11 @@ public class MainMenu extends javax.swing.JFrame { b.setVisible(true); b.delete = true; } + if (radioBDelete.getModel().isSelected()) { + MovieFieldPattern b = new MovieFieldPattern(); + b.setVisible(true); + b.delete = true; + } }//GEN-LAST:event_bMovieActionPerformed private void bAlbumActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bAlbumActionPerformed @@ -431,12 +436,17 @@ public class MainMenu extends javax.swing.JFrame { b.setVisible(true); b.search = true; } + if (radioBDelete.getModel().isSelected()) { + BookFieldPattern b = new BookFieldPattern(); + b.setVisible(true); + b.delete = true; + } }//GEN-LAST:event_bBookActionPerformed - private void radioBDelete1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioBDelete1ActionPerformed + private void radioBDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioBDeleteActionPerformed // TODO add your handling code here: - }//GEN-LAST:event_radioBDelete1ActionPerformed + }//GEN-LAST:event_radioBDeleteActionPerformed private void allBooksShowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_allBooksShowActionPerformed try { @@ -451,7 +461,7 @@ public class MainMenu extends javax.swing.JFrame { "ISBN", "Wydawnictwo", "Kategoria"}; - ListResult table = new ListResult(data, columnNames); + ListResult table = new ListResult(data, columnNames, "book"); table.setVisible(true); } catch (IndexOutOfBoundsException e) { //nothing to do here @@ -469,7 +479,7 @@ public class MainMenu extends javax.swing.JFrame { "Reżyser", "Rok", "Kategoria"}; - ListResult table = new ListResult(data, columnNames); + ListResult table = new ListResult(data, columnNames, "movie"); table.setVisible(true); } catch (IndexOutOfBoundsException e) { //nothing to do here @@ -488,7 +498,7 @@ public class MainMenu extends javax.swing.JFrame { "Muzyk/Zespół", "Rok", "Kategoria"}; - ListResult table = new ListResult(data, columnNames); + ListResult table = new ListResult(data, columnNames, "album"); table.setVisible(true); } catch (IndexOutOfBoundsException e) { @@ -568,7 +578,7 @@ public class MainMenu extends javax.swing.JFrame { private javax.swing.JLabel numberOfMovies; private javax.swing.JLabel programTitle; private javax.swing.JRadioButton radioBAdd; - private javax.swing.JRadioButton radioBDelete1; + private javax.swing.JRadioButton radioBDelete; private javax.swing.JRadioButton radioBEdit; private javax.swing.JRadioButton radioBSearch; private javax.swing.JButton refreshNumbersOfItems; diff --git a/src/library/MovieFieldPattern.form b/src/library/MovieFieldPattern.form index 7712900..0b11876 100644 --- a/src/library/MovieFieldPattern.form +++ b/src/library/MovieFieldPattern.form @@ -30,8 +30,9 @@ + - + @@ -47,11 +48,7 @@ - - - - - + @@ -63,7 +60,10 @@ - + + + + @@ -85,11 +85,8 @@ - - - - - + + @@ -139,9 +136,6 @@ - - - @@ -154,22 +148,55 @@ - + - - - - - + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - @@ -194,13 +221,10 @@ - + - + - - - diff --git a/src/library/MovieFieldPattern.java b/src/library/MovieFieldPattern.java index 0bbadda..8b99c2b 100644 --- a/src/library/MovieFieldPattern.java +++ b/src/library/MovieFieldPattern.java @@ -17,7 +17,7 @@ import javax.swing.JOptionPane; */ public class MovieFieldPattern extends javax.swing.JFrame { - public boolean add = false, delete = false, edit = false, search = false; + public boolean add = false, delete = false, edit = false, search = false, update = false; private Database d = new Database(); /** @@ -28,7 +28,7 @@ public class MovieFieldPattern extends javax.swing.JFrame { this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); } - public MovieFieldPattern(boolean required) { + public MovieFieldPattern(boolean required, Movie... m) { initComponents(); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); Validation verify; @@ -40,6 +40,47 @@ public class MovieFieldPattern extends javax.swing.JFrame { movieTitle.setInputVerifier(verify); director.setInputVerifier(verify); year.setInputVerifier(verify); + try { + if (m[0].getId() >= 0) { + fillField(m[0]); + update = true; + } + } catch (ArrayIndexOutOfBoundsException e) { + //when only one parameter is defined + } + + } + + public void fillField(Movie m) { + idValue.setText(Integer.toString(m.getId())); + movieTitle.setText(m.getName()); + director.setText(m.getDirector()); + year.setText(Integer.toString(m.getYear())); + Category.setSelectedItem(m.getCategory()); + } + + public void search(Movie m, String... mode) { + try { + List movies = new LinkedList<>(); + movies = d.selectMovies(m); + Object[][] data = d.convertToTable(movies); + String[] columnNames = { + "ID", + "Tytuł", + "Reżyser", + "Rok", + "Kategoria"}; + ListResult table = new ListResult(data, columnNames, "movie"); + table.setVisible(true); + if (mode[0].equals("edit")) { + table.setEnabledButton("edit"); + } + if (mode[0].equals("delete")) { + table.setEnabledButton("delete"); + } + } catch (IndexOutOfBoundsException e) { + //nothing to do here + } } /** @@ -61,7 +102,7 @@ public class MovieFieldPattern extends javax.swing.JFrame { Category = new javax.swing.JComboBox<>(); mainlabel = new javax.swing.JLabel(); SaveChanges = new javax.swing.JButton(); - cancel = new javax.swing.JButton(); + idValue = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); @@ -79,21 +120,11 @@ public class MovieFieldPattern extends javax.swing.JFrame { lyear.setText("Rok:"); year.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N - year.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - yearActionPerformed(evt); - } - }); lcategory.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N lcategory.setText("Kategoria:"); - Category.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { " ", "Kryminał", "Thriller", "Przygodowy", "Animowany", "Akcji", "Dla dzieci", "Komedia", "Horror" })); - Category.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - CategoryActionPerformed(evt); - } - }); + Category.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { " ", "Akcji", "Anime", "Animowany", "Baśń", "Biograficzny", "Dla dzieci", "Dla młodzieży", "Dokument", "Dokumentalizowany", "Dramat", "Edukacyjny", "Etiuda", "Fabularyzowany dokument", "Familijny", "Fantastyka", "Fantasy", "Historyczny", "Horror", "Karate", "Katastroficzny", "Komedia", "Komedia romantyczna", "Komediodramat", "Kostiumowy", "Kryminał", "Kung-fu", "Melodramat", "Musical", "Obyczajowy", "Parodia", "Przygodowy", "Przyrodniczy", "Psychologiczny", "Religijny", "Romans", "Satyra", "Science fiction", "Sensacja", "Sportowy", "Surrealistyczny", "Sztuki walki", "Thriller", "Western", "Wojenny" })); mainlabel.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N mainlabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); @@ -107,12 +138,7 @@ public class MovieFieldPattern extends javax.swing.JFrame { } }); - cancel.setText("Anuluj"); - cancel.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - cancelActionPerformed(evt); - } - }); + idValue.setText("."); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); @@ -124,8 +150,9 @@ public class MovieFieldPattern extends javax.swing.JFrame { .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(Title) - .addComponent(directorrname)) - .addGap(56, 56, 56) + .addComponent(directorrname) + .addComponent(idValue, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(52, 52, 52) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(director, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(movieTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 362, javax.swing.GroupLayout.PREFERRED_SIZE) @@ -138,17 +165,16 @@ public class MovieFieldPattern extends javax.swing.JFrame { .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(year, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(Category, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGroup(layout.createSequentialGroup() - .addComponent(SaveChanges, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(18, 18, 18) - .addComponent(cancel))))) + .addComponent(SaveChanges, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addContainerGap(21, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() - .addComponent(mainlabel) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(mainlabel) + .addComponent(idValue)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(Title) @@ -166,10 +192,8 @@ public class MovieFieldPattern extends javax.swing.JFrame { .addComponent(lcategory) .addComponent(Category, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(33, 33, 33) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(SaveChanges) - .addComponent(cancel)) - .addContainerGap(25, Short.MAX_VALUE)) + .addComponent(SaveChanges) + .addContainerGap(26, Short.MAX_VALUE)) ); pack(); @@ -179,10 +203,6 @@ public class MovieFieldPattern extends javax.swing.JFrame { this.SaveChanges.setText(s); } - private void CategoryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CategoryActionPerformed - // TODO add your handling code here: - }//GEN-LAST:event_CategoryActionPerformed - private void SaveChangesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveChangesActionPerformed if (this.add) { try { @@ -193,36 +213,25 @@ public class MovieFieldPattern extends javax.swing.JFrame { e.getMessage(); } } else if (this.edit) { - try { - List movies = new LinkedList<>(); - Movie m = new Movie(0, movieTitle.getText(), director.getText(), year.getText(), Category.getSelectedItem().toString()); - movies = d.selectMovies(m); - Object[][] data = d.convertToTable(movies); - String[] columnNames = { - "ID", - "Tytuł", - "Reżyser", - "Rok", - "Kategoria"}; - ListResult table = new ListResult(data, columnNames); - table.setVisible(true); - } catch (IndexOutOfBoundsException e) { - //nothing to do here - } + Movie m = new Movie(0, movieTitle.getText(), director.getText(), year.getText(), Category.getSelectedItem().toString()); + this.search(m, "edit"); } else if (this.delete) { - JOptionPane.showMessageDialog(null, "USUŃ"); + Movie m = new Movie(0, movieTitle.getText(), director.getText(), year.getText(), Category.getSelectedItem().toString()); + this.search(m, "delete"); + } else if (this.search) { + Movie m = new Movie(0, movieTitle.getText(), director.getText(), year.getText(), Category.getSelectedItem().toString()); + this.search(m); + } else if (this.update) { + Movie m = new Movie(Integer.parseInt(idValue.getText()), movieTitle.getText(), director.getText(), year.getText(), Category.getSelectedItem().toString()); + try { + d.updateQ(m); + } catch (SQLException e) { + e.printStackTrace(); + } } - + dispose(); }//GEN-LAST:event_SaveChangesActionPerformed - private void yearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_yearActionPerformed - // TODO add your handling code here: - }//GEN-LAST:event_yearActionPerformed - - private void cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelActionPerformed - this.dispose(); - }//GEN-LAST:event_cancelActionPerformed - /** * @param args the command line arguments */ @@ -264,9 +273,9 @@ public class MovieFieldPattern extends javax.swing.JFrame { private javax.swing.JComboBox Category; private javax.swing.JButton SaveChanges; private javax.swing.JLabel Title; - private javax.swing.JButton cancel; private javax.swing.JTextField director; private javax.swing.JLabel directorrname; + private javax.swing.JLabel idValue; private javax.swing.JLabel lcategory; private javax.swing.JLabel lyear; private javax.swing.JLabel mainlabel;