diff --git a/biblioteka.db b/biblioteka.db
index 3c6f13f..67eb5ae 100644
Binary files a/biblioteka.db and b/biblioteka.db differ
diff --git a/src/library/AlbumFieldPattern.java b/src/library/AlbumFieldPattern.java
index 0d0ce3e..c828364 100644
--- a/src/library/AlbumFieldPattern.java
+++ b/src/library/AlbumFieldPattern.java
@@ -26,7 +26,6 @@ public class AlbumFieldPattern extends javax.swing.JFrame {
public AlbumFieldPattern(boolean required) {
initComponents();
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
- albumTitle.setInputVerifier(new library.Validation("[a-zA-z0-9]+", required));
}
public boolean add = false, delete = false, edit = false, search = false;
diff --git a/src/library/BookFieldPattern.form b/src/library/BookFieldPattern.form
index ad9bb3d..ebdd0e5 100644
--- a/src/library/BookFieldPattern.form
+++ b/src/library/BookFieldPattern.form
@@ -205,6 +205,7 @@
+
@@ -221,6 +222,7 @@
+
diff --git a/src/library/BookFieldPattern.java b/src/library/BookFieldPattern.java
index f337725..6aa0c1f 100644
--- a/src/library/BookFieldPattern.java
+++ b/src/library/BookFieldPattern.java
@@ -24,6 +24,9 @@ public class BookFieldPattern extends javax.swing.JFrame {
public BookFieldPattern() {
initComponents();
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
+ year.setInputVerifier(verify);
+ ISBN.setInputVerifier(verify);
+
}
public BookFieldPattern(boolean required) {
@@ -32,7 +35,8 @@ public class BookFieldPattern extends javax.swing.JFrame {
//bookTitle.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;
+ private Validation verify = new Validation();
/**
* This method is called from within the constructor to initialize the form.
@@ -98,12 +102,14 @@ public class BookFieldPattern extends javax.swing.JFrame {
lyear.setText("Rok wydania:");
year.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
+ year.setName("year"); // NOI18N
lISBN.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
lISBN.setText("ISBN:");
ISBN.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
ISBN.setToolTipText("XXX-X-XXXX-X");
+ ISBN.setName("isbn"); // NOI18N
ISBN.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusGained(java.awt.event.FocusEvent evt) {
ISBNFocusGained(evt);
@@ -251,11 +257,10 @@ public class BookFieldPattern extends javax.swing.JFrame {
private void SaveChangesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveChangesActionPerformed
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());
- b.insertToDB();
- }
- catch(SQLException e){
+ try {
+ Book b = new Book(0, bookTitle.getText(), authorName.getText(), authorSurname.getText(), Integer.parseInt(year.getText()), ISBN.getText(), publishing.getText(), Category.getSelectedItem().toString());
+ b.insertToDB();
+ } catch (SQLException e) {
e.getMessage();
}
@@ -263,6 +268,8 @@ public class BookFieldPattern extends javax.swing.JFrame {
JOptionPane.showMessageDialog(null, "EDYTUJ");
} else if (this.delete) {
JOptionPane.showMessageDialog(null, "USUŃ");
+ } else if (this.search) {
+
}
dispose();
}//GEN-LAST:event_SaveChangesActionPerformed
@@ -284,7 +291,7 @@ public class BookFieldPattern extends javax.swing.JFrame {
}//GEN-LAST:event_ISBNFocusGained
private void ISBNFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_ISBNFocusLost
- jLabel1.setVisible(false);
+ jLabel1.setVisible(false);
}//GEN-LAST:event_ISBNFocusLost
private void cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelActionPerformed
diff --git a/src/library/Database.java b/src/library/Database.java
index ecd7be0..97d97b2 100644
--- a/src/library/Database.java
+++ b/src/library/Database.java
@@ -11,8 +11,9 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
-import java.util.LinkedList;
+import java.util.ArrayList;
import java.util.List;
+import static javafx.scene.input.KeyCode.T;
import javax.swing.JOptionPane;
/**
@@ -58,19 +59,6 @@ public class Database {
createTables();
}
- public void selectAllFromBooks() {
- try {
- ResultSet result = stat.executeQuery("SELECT * FROM books");
-
- while (result.next()) {
- System.out.println("WYniki");
- System.out.println(result.getInt("id") + " " + result.getInt("year") + result.getString("name") + result.getString("author_name") + result.getString("author_surname") + result.getString("publishing") + result.getString("isbn") + result.getString("category"));
- }
- } catch (SQLException e) {
- JOptionPane.showMessageDialog(null, "Błąd przy odczycie z bazy.", "Error:", JOptionPane.INFORMATION_MESSAGE);
- }
- }
-
public boolean createTables() {
String createBooks = "CREATE TABLE IF NOT EXISTS books (id INTEGER PRIMARY KEY AUTOINCREMENT, name varchar(255), author_name varchar(50), author_surname varchar(50), publishing varchar(50), year int, isbn varchar(20), category varchar(100))";
String createAlbums = "CREATE TABLE IF NOT EXISTS albums (id INTEGER PRIMARY KEY AUTOINCREMENT, name varchar(255), musican varchar(50), year int, category varchar(100))";
@@ -119,8 +107,8 @@ public class Database {
JOptionPane.showMessageDialog(null, "Dodano poprawnie.", "Informacja:", JOptionPane.INFORMATION_MESSAGE);
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "Błąd przy dodawaniu albumu do bazy", "Error:", JOptionPane.INFORMATION_MESSAGE);
- e.printStackTrace();
- throw new SQLException("Error dodawania albumu");
+ e.printStackTrace();
+ throw new SQLException("Error dodawania albumu");
}
}
@@ -137,14 +125,14 @@ public class Database {
JOptionPane.showMessageDialog(null, "Dodano poprawnie.", "Informacja:", JOptionPane.INFORMATION_MESSAGE);
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "Błąd przy dodawaniu do bazy", "Error:", JOptionPane.INFORMATION_MESSAGE);
- e.printStackTrace();
- throw new SQLException("Error dodawania albumu");
+ e.printStackTrace();
+ throw new SQLException("Error dodawania albumu");
}
}
public List selectBooks() {
- List books = new LinkedList();
+ List books = new ArrayList();
try {
ResultSet result = stat.executeQuery("SELECT * FROM books");
int id, year;
@@ -166,8 +154,69 @@ public class Database {
return books;
}
+ public List selectBooks(Book searchData) {
+ List books = new ArrayList<>();
+ try {
+ List wheres = new ArrayList<>();
+ if (searchData.getName().length() > 0) {
+ wheres.add("WHERE name LIKE " + searchData.getName());
+ System.out.println("WHERE name LIKE " + searchData.getName());
+ }
+ if (searchData.getAuthorName().length() > 0) {
+ wheres.add("WHERE author_name LIKE " + searchData.getAuthorName());
+ System.out.println("WHERE author_name LIKE " + searchData.getAuthorName());
+ }
+ if (searchData.getPublishing().length() > 0) {
+ wheres.add("WHERE publishing LIKE " + searchData.getPublishing());
+ System.out.println("WHERE publishing LIKE " + searchData.getPublishing());
+ }
+ if (searchData.getYear() > 0) {
+ wheres.add("WHERE year = " + searchData.getYear());
+ System.out.println("WHERE year = " + searchData.getYear());
+ }
+ if (searchData.getName().length() > 0) {
+ wheres.add("WHERE name LIKE " + searchData.getName());
+ System.out.println("WHERE name LIKE " + searchData.getName());
+ }
+ if (searchData.getName().length() > 0) {
+ wheres.add("WHERE name LIKE " + searchData.getName());
+ System.out.println("WHERE name LIKE " + searchData.getName());
+ }
+ if (searchData.getISBN().length() > 0) {
+ wheres.add("WHERE isbn LIKE " + searchData.getISBN());
+ System.out.println("WHERE isbn LIKE " + searchData.getISBN());
+ }
+ if (searchData.getCategory().length() > 0) {
+ wheres.add("WHERE category LIKE " + searchData.getCategory());
+ System.out.println("WHERE category LIKE " + searchData.getCategory());
+ }
+
+ String query = "SELECT * FROM books";
+ if (query.length() == 19) {
+
+ }
+ ResultSet result = stat.executeQuery("SELECT * FROM books");
+ int id, year;
+ String name, authorName, authorSurname, isbn, category, publishing;
+ while (result.next()) {
+ id = result.getInt("id");
+ year = result.getInt("year");
+ name = result.getString("name");
+ authorName = result.getString("author_name");
+ authorSurname = result.getString("author_surname");
+ publishing = result.getString("publishing");
+ isbn = result.getString("isbn");
+ category = result.getString("category");
+ books.add(new Book(id, name, authorName, authorSurname, year, isbn, publishing, category));
+ }
+ } catch (SQLException e) {
+ JOptionPane.showMessageDialog(null, "Błąd przy odczycie z bazy.", "Error:", JOptionPane.INFORMATION_MESSAGE);
+ }
+ return books;
+ }
+
public List selectAlbums() {
- List albums = new LinkedList();
+ List albums = new ArrayList();
try {
ResultSet result = stat.executeQuery("SELECT * FROM albums");
int id, year;
@@ -188,7 +237,7 @@ public class Database {
}
public List selectMovies() {
- List movies = new LinkedList();
+ List movies = new ArrayList();
try {
ResultSet result = stat.executeQuery("SELECT * FROM movies");
int id, year;
diff --git a/src/library/MainMenu.java b/src/library/MainMenu.java
index 1f7c31f..953e8bc 100644
--- a/src/library/MainMenu.java
+++ b/src/library/MainMenu.java
@@ -443,10 +443,6 @@ public class MainMenu extends javax.swing.JFrame {
List books = new LinkedList<>();
books = d.selectBooks();
- /*System.out.println("Lista książek:");
- for (Book k : books) {
- //
- }*/
Object[][] data = d.convertToTable(books);
String[] columnNames = {"ID",
"Tytuł",
@@ -457,7 +453,6 @@ public class MainMenu extends javax.swing.JFrame {
"Wydawnictwo",
"Kategoria"};
ListResult table = new ListResult(data, columnNames);
-
table.setVisible(true);
} catch (IndexOutOfBoundsException e) {
//nothing to do here
@@ -476,7 +471,6 @@ public class MainMenu extends javax.swing.JFrame {
"Rok",
"Kategoria"};
ListResult table = new ListResult(data, columnNames);
-
table.setVisible(true);
} catch (IndexOutOfBoundsException e) {
//nothing to do here
diff --git a/src/library/MovieFieldPattern.java b/src/library/MovieFieldPattern.java
index 14c7aab..5c0fa7d 100644
--- a/src/library/MovieFieldPattern.java
+++ b/src/library/MovieFieldPattern.java
@@ -26,7 +26,6 @@ public class MovieFieldPattern extends javax.swing.JFrame {
public MovieFieldPattern(boolean required) {
initComponents();
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
- movieTitle.setInputVerifier(new library.Validation("[a-zA-z0-9]+", required));
}
public boolean add = false, delete = false, edit = false, search = false;
diff --git a/src/library/Validation.java b/src/library/Validation.java
index fbd6e81..97e7807 100644
--- a/src/library/Validation.java
+++ b/src/library/Validation.java
@@ -14,39 +14,64 @@ import javax.swing.JTextField;
/**
*
- * @author Agnieszka walitator używający wyrażeń regularnych do sprawdzania pól
- * formularzy wyrażenia regularne jako parametr konstuktora
+ * @author Agnieszka
*/
public class Validation extends InputVerifier {
- public Validation(String ex, boolean rq) {
- expression = ex;
+ String expression;
+ boolean required = false;
+ int year;
+
+ public Validation(boolean rq) {
required = rq;
}
+ public Validation() {
+ }
+
+ public boolean checkField(JComponent input) {
+ JTextField tf = (JTextField) input;
+ if(required){
+ if("".equals(tf.getText())){
+ JOptionPane.showMessageDialog(null, "Pole wymagane!", "Błąd wprowadzanych danych", JOptionPane.INFORMATION_MESSAGE);
+ return false;
+ }
+ }
+ if (input.getName().equals("year")) {
+
+ if (!"".equals(tf.getText())) {
+ try {
+ year = Integer.parseInt(tf.getText());
+ if (year > 2016 || year < 1900) {
+ JOptionPane.showMessageDialog(null, "Data spoza zakresu.", "Błąd wprowadzanych danych", JOptionPane.INFORMATION_MESSAGE);
+ return false;
+ }
+ } catch (NumberFormatException e) {
+ JOptionPane.showMessageDialog(null, "Wpisz datę w formacie: YYYY", "Błąd wprowadzanych danych", JOptionPane.INFORMATION_MESSAGE);
+ return false;
+ }
+ }
+ }
+ if (input.getName().equals("isbn")) {
+ if (!"".equals(tf.getText())) {
+ Pattern p = Pattern.compile("[0-9][0-9][0-9]-[0-9]-[0-9][0-9][0-9][0-9]-[0-9]");
+ Matcher m = p.matcher(tf.getText());
+ if (m.matches()) {
+ return true;
+ } else {
+ JOptionPane.showMessageDialog(null, "Niepoprawne dane!", "Sprawdzenie pola:", JOptionPane.INFORMATION_MESSAGE);
+ return false;
+ }
+ }
+ return true;
+ }
+
+ return true;
+ }
+
@Override
public boolean verify(JComponent input) {
- JTextField tf = (JTextField) input;
- Pattern p = Pattern.compile(expression);
- Matcher m = p.matcher(tf.getText());
- if (required) {
- if (m.matches()) {
- return true;
- } else {
- if ("".equals(tf.getText())) {
- JOptionPane.showMessageDialog(null, "Pole wymagane!", "Sprawdzenie pola:", JOptionPane.INFORMATION_MESSAGE);
- } else {
- JOptionPane.showMessageDialog(null, "Niepoprawne dane!", "Sprawdzenie pola:", JOptionPane.INFORMATION_MESSAGE);
- }
- return false;
- }
- } else if (m.matches() || "".equals(tf.getText())) {
- return true;
- } else {
- JOptionPane.showMessageDialog(null, "Niepoprawne dane!", "Sprawdzenie pola:", JOptionPane.INFORMATION_MESSAGE);
- return false;
- }
+ return checkField(input);
}
- String expression;
- boolean required = false;
+
}