dodane usuwanie - WERSJA BETA GOTOWA
This commit is contained in:
parent
71cf6237aa
commit
0d3d99d8ce
BIN
biblioteka.db
BIN
biblioteka.db
Binary file not shown.
@ -390,7 +390,6 @@ public class Database {
|
||||
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) {
|
||||
@ -408,7 +407,6 @@ public class Database {
|
||||
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) {
|
||||
@ -426,7 +424,6 @@ public class Database {
|
||||
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) {
|
||||
@ -437,6 +434,49 @@ public class Database {
|
||||
}
|
||||
}
|
||||
|
||||
public <T> void deleteQ(T obj) throws SQLException {
|
||||
if (obj instanceof Book) {
|
||||
try {
|
||||
Book b = (Book) obj;
|
||||
PreparedStatement prepStmt = conn.prepareStatement(
|
||||
"DELETE FROM books WHERE id = ?;");
|
||||
prepStmt.setInt(1, b.getId());
|
||||
prepStmt.executeUpdate();
|
||||
JOptionPane.showMessageDialog(null, "Usunięto.", "Informacja:", JOptionPane.INFORMATION_MESSAGE);
|
||||
} catch (SQLException e) {
|
||||
JOptionPane.showMessageDialog(null, "Błąd przy usuwaniu z bazy", "Error:", JOptionPane.INFORMATION_MESSAGE);
|
||||
e.printStackTrace();
|
||||
throw new SQLException("Error usuwania ksiazki");
|
||||
}
|
||||
} else if (obj instanceof Album) {
|
||||
Album a = (Album) obj;
|
||||
try {
|
||||
PreparedStatement prepStmt = conn.prepareStatement(
|
||||
"DELETE FROM albums WHERE id = ?;");
|
||||
prepStmt.setInt(1, a.getId());
|
||||
prepStmt.executeUpdate();
|
||||
JOptionPane.showMessageDialog(null, "Usunięto.", "Informacja:", JOptionPane.INFORMATION_MESSAGE);
|
||||
} catch (SQLException e) {
|
||||
JOptionPane.showMessageDialog(null, "Błąd przy usuwaniu z bazy", "Error:", JOptionPane.INFORMATION_MESSAGE);
|
||||
e.printStackTrace();
|
||||
throw new SQLException("Error usuwania albumu");
|
||||
}
|
||||
} else if (obj instanceof Movie) {
|
||||
Movie m = (Movie) obj;
|
||||
try {
|
||||
PreparedStatement prepStmt = conn.prepareStatement(
|
||||
"DELETE FROM movies WHERE id = ?;");
|
||||
prepStmt.setInt(1, m.getId());
|
||||
prepStmt.executeUpdate();
|
||||
JOptionPane.showMessageDialog(null, "Usunięto.", "Informacja:", JOptionPane.INFORMATION_MESSAGE);
|
||||
} catch (SQLException e) {
|
||||
JOptionPane.showMessageDialog(null, "Błąd przy usuwaniu z bazy", "Error:", JOptionPane.INFORMATION_MESSAGE);
|
||||
e.printStackTrace();
|
||||
throw new SQLException("Error usuwania filmu");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Object[][] convertToTable(List<?> l) {
|
||||
try {
|
||||
Object first = l.get(0);
|
||||
|
@ -33,16 +33,15 @@
|
||||
<EmptySpace min="-2" pref="23" max="-2" attributes="0"/>
|
||||
<Component id="jScrollPane1" min="-2" pref="1180" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace min="-2" pref="529" max="-2" attributes="0"/>
|
||||
<Component id="editButton" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace type="separate" max="-2" attributes="0"/>
|
||||
<Component id="deleteButton" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<EmptySpace pref="26" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
|
||||
<Component id="editButton" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace type="separate" max="-2" attributes="0"/>
|
||||
<Component id="deleteButton" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="548" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
@ -51,13 +50,13 @@
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="mainlabel" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="13" max="-2" attributes="0"/>
|
||||
<Component id="jScrollPane1" min="-2" pref="473" max="-2" attributes="0"/>
|
||||
<EmptySpace type="separate" max="-2" attributes="0"/>
|
||||
<Component id="jScrollPane1" min="-2" pref="422" max="-2" attributes="0"/>
|
||||
<EmptySpace type="unrelated" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="editButton" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="deleteButton" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace pref="47" max="32767" attributes="0"/>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
|
@ -5,8 +5,11 @@
|
||||
*/
|
||||
package library;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
@ -24,6 +27,7 @@ public class ListResult extends javax.swing.JFrame {
|
||||
public String dataType;
|
||||
private final Object[][] rows;
|
||||
private final Object[] columnsNames;
|
||||
private Database d = new Database();
|
||||
|
||||
public ListResult(Object[][] rowData, Object[] colNam, String dataT) {
|
||||
rows = rowData;
|
||||
@ -96,14 +100,13 @@ 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)))
|
||||
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 1180, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(529, 529, 529)
|
||||
.addComponent(editButton)
|
||||
.addGap(18, 18, 18)
|
||||
.addComponent(deleteButton)))
|
||||
.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)
|
||||
@ -111,12 +114,12 @@ public class ListResult extends javax.swing.JFrame {
|
||||
.addContainerGap()
|
||||
.addComponent(mainlabel)
|
||||
.addGap(13, 13, 13)
|
||||
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 473, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(18, 18, 18)
|
||||
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 422, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(editButton)
|
||||
.addComponent(deleteButton))
|
||||
.addContainerGap(47, Short.MAX_VALUE))
|
||||
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
);
|
||||
|
||||
pack();
|
||||
@ -166,7 +169,32 @@ public class ListResult extends javax.swing.JFrame {
|
||||
private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteButtonActionPerformed
|
||||
int selectedRowIndex = table.getSelectedRow();
|
||||
System.out.println(selectedRowIndex);
|
||||
|
||||
if (dataType.equals("book")) {
|
||||
Book b = new Book();
|
||||
b.setId((Integer) table.getValueAt(selectedRowIndex, 0));
|
||||
try {
|
||||
d.deleteQ(b);
|
||||
} catch (SQLException ex) {
|
||||
System.out.println("błąd usuwania SQL");
|
||||
}
|
||||
} else if (dataType.equals("movie")) {
|
||||
Movie m = new Movie();
|
||||
m.setId((Integer) table.getValueAt(selectedRowIndex, 0));
|
||||
try {
|
||||
d.deleteQ(m);
|
||||
} catch (SQLException ex) {
|
||||
System.out.println("błąd usuwania SQL");
|
||||
}
|
||||
} else if (dataType.equals("album")) {
|
||||
Album a = new Album();
|
||||
a.setId((Integer) table.getValueAt(selectedRowIndex, 0));
|
||||
try {
|
||||
d.deleteQ(a);
|
||||
} catch (SQLException ex) {
|
||||
System.out.println("błąd usuwania SQL");
|
||||
}
|
||||
}
|
||||
dispose();
|
||||
}//GEN-LAST:event_deleteButtonActionPerformed
|
||||
|
||||
public void setEnabledButton(String which) {
|
||||
|
@ -406,6 +406,11 @@ public class MainMenu extends javax.swing.JFrame {
|
||||
b.setVisible(true);
|
||||
b.delete = true;
|
||||
}
|
||||
if (radioBDelete.getModel().isSelected()) {
|
||||
AlbumFieldPattern b = new AlbumFieldPattern();
|
||||
b.setVisible(true);
|
||||
b.delete = true;
|
||||
}
|
||||
}//GEN-LAST:event_bAlbumActionPerformed
|
||||
|
||||
private void radioBEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioBEditActionPerformed
|
||||
|
Loading…
Reference in New Issue
Block a user