dodawanie ok
This commit is contained in:
parent
5f0fb40d46
commit
5a14e5604a
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -8,6 +8,7 @@
|
|||||||
<file>file:/D:/PROJEKT/Library/src/library/MainMenu.java</file>
|
<file>file:/D:/PROJEKT/Library/src/library/MainMenu.java</file>
|
||||||
<file>file:/D:/PROJEKT/Library/src/library/Item.java</file>
|
<file>file:/D:/PROJEKT/Library/src/library/Item.java</file>
|
||||||
<file>file:/D:/PROJEKT/Library/src/library/Validation.java</file>
|
<file>file:/D:/PROJEKT/Library/src/library/Validation.java</file>
|
||||||
|
<file>file:/D:/PROJEKT/Library/src/library/Album.java</file>
|
||||||
<file>file:/D:/PROJEKT/Library/src/library/AlbumFieldPattern.java</file>
|
<file>file:/D:/PROJEKT/Library/src/library/AlbumFieldPattern.java</file>
|
||||||
<file>file:/D:/PROJEKT/Library/src/library/Book.java</file>
|
<file>file:/D:/PROJEKT/Library/src/library/Book.java</file>
|
||||||
<file>file:/D:/PROJEKT/Library/src/library/Database.java</file>
|
<file>file:/D:/PROJEKT/Library/src/library/Database.java</file>
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
*/
|
*/
|
||||||
package library;
|
package library;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Agnieszka
|
* @author Agnieszka
|
||||||
@ -36,17 +38,21 @@ public class Album extends Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void insertToDB() {
|
public void insertToDB() throws SQLException {
|
||||||
d.insertAlbumQ(this);
|
try {
|
||||||
|
d.insertAlbumQ(this);
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
throw new SQLException("Error dodawania albumu");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delFromDB() {
|
public void delFromDB() throws SQLException {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void editInDB() {
|
public void editInDB() throws SQLException {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
package library;
|
package library;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
@ -17,7 +18,6 @@ public class AlbumFieldPattern extends javax.swing.JFrame {
|
|||||||
/**
|
/**
|
||||||
* Creates new form bookFieldPattern
|
* Creates new form bookFieldPattern
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public AlbumFieldPattern() {
|
public AlbumFieldPattern() {
|
||||||
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||||
initComponents();
|
initComponents();
|
||||||
@ -28,7 +28,7 @@ public class AlbumFieldPattern extends javax.swing.JFrame {
|
|||||||
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||||
albumTitle.setInputVerifier(new library.Validation("[a-zA-z0-9]+", required));
|
albumTitle.setInputVerifier(new library.Validation("[a-zA-z0-9]+", required));
|
||||||
}
|
}
|
||||||
public boolean add = false, delete = false, edit = false, search=false;
|
public boolean add = false, delete = false, edit = false, search = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is called from within the constructor to initialize the form.
|
* This method is called from within the constructor to initialize the form.
|
||||||
@ -174,15 +174,19 @@ public class AlbumFieldPattern extends javax.swing.JFrame {
|
|||||||
|
|
||||||
private void SaveChangesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveChangesActionPerformed
|
private void SaveChangesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveChangesActionPerformed
|
||||||
if (this.add) {
|
if (this.add) {
|
||||||
Album a = new Album(0, albumTitle.getText(), musican.getText(), Integer.parseInt(year.getText()), Category.getSelectedItem().toString());
|
try {
|
||||||
a.insertToDB();
|
Album a = new Album(0, albumTitle.getText(), musican.getText(), Integer.parseInt(year.getText()), Category.getSelectedItem().toString());
|
||||||
this.dispose();
|
a.insertToDB();
|
||||||
|
this.dispose();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.getMessage();
|
||||||
|
}
|
||||||
} else if (this.edit) {
|
} else if (this.edit) {
|
||||||
JOptionPane.showMessageDialog(null, "EDYTUJ");
|
JOptionPane.showMessageDialog(null, "EDYTUJ");
|
||||||
} else if (this.delete) {
|
} else if (this.delete) {
|
||||||
JOptionPane.showMessageDialog(null, "USUŃ");
|
JOptionPane.showMessageDialog(null, "USUŃ");
|
||||||
}
|
}
|
||||||
|
|
||||||
}//GEN-LAST:event_SaveChangesActionPerformed
|
}//GEN-LAST:event_SaveChangesActionPerformed
|
||||||
|
|
||||||
private void yearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_yearActionPerformed
|
private void yearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_yearActionPerformed
|
||||||
@ -190,7 +194,7 @@ public class AlbumFieldPattern extends javax.swing.JFrame {
|
|||||||
}//GEN-LAST:event_yearActionPerformed
|
}//GEN-LAST:event_yearActionPerformed
|
||||||
|
|
||||||
private void cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelActionPerformed
|
private void cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelActionPerformed
|
||||||
this.dispose();
|
this.dispose();
|
||||||
}//GEN-LAST:event_cancelActionPerformed
|
}//GEN-LAST:event_cancelActionPerformed
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -5,6 +5,10 @@
|
|||||||
*/
|
*/
|
||||||
package library;
|
package library;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Agnieszka
|
* @author Agnieszka
|
||||||
@ -38,21 +42,25 @@ public class Book extends Item {
|
|||||||
tab[r][5] = b.getISBN();
|
tab[r][5] = b.getISBN();
|
||||||
tab[r][6] = b.getPublishing();
|
tab[r][6] = b.getPublishing();
|
||||||
tab[r][7] = b.getCategory();
|
tab[r][7] = b.getCategory();
|
||||||
return tab ;
|
return tab;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void insertToDB() {
|
|
||||||
d.insertBookQ(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delFromDB() {
|
public void insertToDB() throws SQLException {
|
||||||
|
try {
|
||||||
|
d.insertBookQ(this);
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
throw new SQLException("Error dodawania ksiazki");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delFromDB() throws SQLException {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void editInDB() {
|
public void editInDB() throws SQLException {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,9 +251,13 @@ public class BookFieldPattern extends javax.swing.JFrame {
|
|||||||
|
|
||||||
private void SaveChangesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveChangesActionPerformed
|
private void SaveChangesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveChangesActionPerformed
|
||||||
if (this.add) {
|
if (this.add) {
|
||||||
|
try{
|
||||||
Book b = new Book(0, bookTitle.getText(), authorName.getText(), authorSurname.getText(), Integer.parseInt(year.getText()), ISBN.getText(), publishing.getText(), Category.getSelectedItem().toString());
|
Book b = new Book(0, bookTitle.getText(), authorName.getText(), authorSurname.getText(), Integer.parseInt(year.getText()), ISBN.getText(), publishing.getText(), Category.getSelectedItem().toString());
|
||||||
b.insertToDB();
|
b.insertToDB();
|
||||||
|
}
|
||||||
|
catch(SQLException e){
|
||||||
|
e.getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
} else if (this.edit) {
|
} else if (this.edit) {
|
||||||
JOptionPane.showMessageDialog(null, "EDYTUJ");
|
JOptionPane.showMessageDialog(null, "EDYTUJ");
|
||||||
|
@ -86,7 +86,7 @@ public class Database {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insertBookQ(Book b) {
|
public void insertBookQ(Book b) throws SQLException {
|
||||||
try {
|
try {
|
||||||
PreparedStatement prepStmt = conn.prepareStatement(
|
PreparedStatement prepStmt = conn.prepareStatement(
|
||||||
"INSERT INTO books VALUES (NULL, ?, ?, ?, ?, ?, ?, ?);");
|
"INSERT INTO books VALUES (NULL, ?, ?, ?, ?, ?, ?, ?);");
|
||||||
@ -99,16 +99,15 @@ public class Database {
|
|||||||
prepStmt.setString(7, b.getCategory());
|
prepStmt.setString(7, b.getCategory());
|
||||||
prepStmt.execute();
|
prepStmt.execute();
|
||||||
JOptionPane.showMessageDialog(null, "Dodano poprawnie.", "Informacja:", JOptionPane.INFORMATION_MESSAGE);
|
JOptionPane.showMessageDialog(null, "Dodano poprawnie.", "Informacja:", JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
JOptionPane.showMessageDialog(null, "Błąd przy dodawaniu do bazy", "Error:", JOptionPane.INFORMATION_MESSAGE);
|
JOptionPane.showMessageDialog(null, "Błąd przy dodawaniu do bazy", "Error:", JOptionPane.INFORMATION_MESSAGE);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
throw new SQLException("Error dodawania ksiazki");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insertAlbumQ(Album a) {
|
public void insertAlbumQ(Album a) throws SQLException {
|
||||||
try {
|
try {
|
||||||
PreparedStatement prepStmt = conn.prepareStatement(
|
PreparedStatement prepStmt = conn.prepareStatement(
|
||||||
"INSERT INTO albums VALUES (NULL, ?, ?, ?, ?);");
|
"INSERT INTO albums VALUES (NULL, ?, ?, ?, ?);");
|
||||||
@ -121,14 +120,15 @@ public class Database {
|
|||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
JOptionPane.showMessageDialog(null, "Błąd przy dodawaniu albumu do bazy", "Error:", JOptionPane.INFORMATION_MESSAGE);
|
JOptionPane.showMessageDialog(null, "Błąd przy dodawaniu albumu do bazy", "Error:", JOptionPane.INFORMATION_MESSAGE);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
throw new SQLException("Error dodawania albumu");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insertMovieQ(Movie m) {
|
public void insertMovieQ(Movie m) throws SQLException {
|
||||||
try {
|
try {
|
||||||
PreparedStatement prepStmt = conn.prepareStatement(
|
PreparedStatement prepStmt = conn.prepareStatement(
|
||||||
"INSER INTO movies VALUES (NULL, ?, ?, ?, ?);");
|
"INSERT INTO movies VALUES (NULL, ?, ?, ?, ?);");
|
||||||
prepStmt.setString(1, m.getName());
|
prepStmt.setString(1, m.getName());
|
||||||
prepStmt.setString(2, m.getDirector());
|
prepStmt.setString(2, m.getDirector());
|
||||||
prepStmt.setInt(3, m.getYear());
|
prepStmt.setInt(3, m.getYear());
|
||||||
@ -137,6 +137,8 @@ public class Database {
|
|||||||
JOptionPane.showMessageDialog(null, "Dodano poprawnie.", "Informacja:", JOptionPane.INFORMATION_MESSAGE);
|
JOptionPane.showMessageDialog(null, "Dodano poprawnie.", "Informacja:", JOptionPane.INFORMATION_MESSAGE);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
JOptionPane.showMessageDialog(null, "Błąd przy dodawaniu do bazy", "Error:", JOptionPane.INFORMATION_MESSAGE);
|
JOptionPane.showMessageDialog(null, "Błąd przy dodawaniu do bazy", "Error:", JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new SQLException("Error dodawania albumu");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -250,7 +252,7 @@ public class Database {
|
|||||||
}
|
}
|
||||||
} catch (IndexOutOfBoundsException e) {
|
} catch (IndexOutOfBoundsException e) {
|
||||||
JOptionPane.showMessageDialog(null, "Baza danych pusta", "Error:", JOptionPane.INFORMATION_MESSAGE);
|
JOptionPane.showMessageDialog(null, "Baza danych pusta", "Error:", JOptionPane.INFORMATION_MESSAGE);
|
||||||
throw new IndexOutOfBoundsException("Nie mozna dzielić przez 0");
|
throw new IndexOutOfBoundsException("Poza zakresem");
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
*/
|
*/
|
||||||
package library;
|
package library;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Agnieszka
|
* @author Agnieszka
|
||||||
@ -12,11 +14,11 @@ package library;
|
|||||||
*/
|
*/
|
||||||
public abstract class Item {
|
public abstract class Item {
|
||||||
|
|
||||||
public abstract void insertToDB();
|
public abstract void insertToDB() throws SQLException ;
|
||||||
|
|
||||||
public abstract void delFromDB();
|
public abstract void delFromDB() throws SQLException ;
|
||||||
|
|
||||||
public abstract void editInDB();
|
public abstract void editInDB() throws SQLException ;
|
||||||
|
|
||||||
public void setName(String s) {
|
public void setName(String s) {
|
||||||
this.name = s;
|
this.name = s;
|
||||||
|
@ -45,17 +45,21 @@ public class Movie extends Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void insertToDB() {
|
public void insertToDB() throws SQLException {
|
||||||
d.insertMovieQ(this);
|
try {
|
||||||
|
d.insertMovieQ(this);
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
throw new SQLException("Error dodawania filmu");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delFromDB() {
|
public void delFromDB() throws SQLException {
|
||||||
String query = "DELETE FROM books WHERE id=" + this.getId() + ";";
|
String query = "DELETE FROM books WHERE id=" + this.getId() + ";";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void editInDB() {
|
public void editInDB() throws SQLException {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
package library;
|
package library;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
@ -27,7 +28,7 @@ public class MovieFieldPattern extends javax.swing.JFrame {
|
|||||||
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||||
movieTitle.setInputVerifier(new library.Validation("[a-zA-z0-9]+", required));
|
movieTitle.setInputVerifier(new library.Validation("[a-zA-z0-9]+", required));
|
||||||
}
|
}
|
||||||
public boolean add = false, delete = false, edit = false, search=false;
|
public boolean add = false, delete = false, edit = false, search = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is called from within the constructor to initialize the form.
|
* This method is called from within the constructor to initialize the form.
|
||||||
@ -172,14 +173,19 @@ public class MovieFieldPattern extends javax.swing.JFrame {
|
|||||||
|
|
||||||
private void SaveChangesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveChangesActionPerformed
|
private void SaveChangesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveChangesActionPerformed
|
||||||
if (this.add) {
|
if (this.add) {
|
||||||
Movie m = new Movie(0, movieTitle.getText(), director.getText(), Integer.parseInt(year.getText()), Category.getSelectedItem().toString() );
|
try {
|
||||||
m.insertToDB();
|
Movie m = new Movie(0, movieTitle.getText(), director.getText(), Integer.parseInt(year.getText()), Category.getSelectedItem().toString());
|
||||||
|
m.insertToDB();
|
||||||
|
this.dispose();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.getMessage();
|
||||||
|
}
|
||||||
} else if (this.edit) {
|
} else if (this.edit) {
|
||||||
JOptionPane.showMessageDialog(null, "EDYTUJ");
|
JOptionPane.showMessageDialog(null, "EDYTUJ");
|
||||||
} else if (this.delete) {
|
} else if (this.delete) {
|
||||||
JOptionPane.showMessageDialog(null, "USUŃ");
|
JOptionPane.showMessageDialog(null, "USUŃ");
|
||||||
}
|
}
|
||||||
this.dispose();
|
|
||||||
}//GEN-LAST:event_SaveChangesActionPerformed
|
}//GEN-LAST:event_SaveChangesActionPerformed
|
||||||
|
|
||||||
private void yearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_yearActionPerformed
|
private void yearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_yearActionPerformed
|
||||||
|
Loading…
Reference in New Issue
Block a user