Działa dodawanie książek, praca nad dodawaniem reszty
This commit is contained in:
parent
ab0325b065
commit
f7ae927511
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.
Binary file not shown.
@ -127,9 +127,6 @@
|
||||
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
|
||||
<Font name="Tahoma" size="14" style="0"/>
|
||||
</Property>
|
||||
<Property name="inputVerifier" type="javax.swing.InputVerifier" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||
<Connection code="new library.Validation("[a-zA-z0-9]+", this.add)" type="code"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="bookTitleActionPerformed"/>
|
||||
@ -215,6 +212,9 @@
|
||||
<Font name="Tahoma" size="14" style="0"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="ISBNActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="lcategory">
|
||||
<Properties>
|
||||
|
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.
@ -21,7 +21,7 @@ public class Album extends Item {
|
||||
}
|
||||
@Override
|
||||
public void insertToDB(){
|
||||
String query = "INSERT INTO albums VALUES(NULL, '" +this.getName() + "', '" + this.getMusican() + "', '" + this.getYear() + "', '"+ this.getCategory() + "');";
|
||||
// String query = "INSERT INTO albums VALUES(NULL, '" +this.getName() + "', '" + this.getMusican() + "', '" + this.getYear() + "', '"+ this.getCategory() + "');";
|
||||
};
|
||||
@Override
|
||||
public void delFromDB(){
|
||||
|
@ -21,12 +21,14 @@ public class AlbumFieldPattern extends javax.swing.JFrame {
|
||||
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
initComponents();
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* This method is called from within the constructor to initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is always
|
||||
@ -159,11 +161,9 @@ public class AlbumFieldPattern extends javax.swing.JFrame {
|
||||
private void SaveChangesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveChangesActionPerformed
|
||||
if (this.add) {
|
||||
JOptionPane.showMessageDialog(null, "DODAJ");
|
||||
}
|
||||
else if(this.edit){
|
||||
} else if (this.edit) {
|
||||
JOptionPane.showMessageDialog(null, "EDYTUJ");
|
||||
}
|
||||
else if(this.delete){
|
||||
} else if (this.delete) {
|
||||
JOptionPane.showMessageDialog(null, "USUŃ");
|
||||
}
|
||||
dispose();
|
||||
@ -210,8 +210,6 @@ public class AlbumFieldPattern extends javax.swing.JFrame {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
|
@ -10,9 +10,11 @@ package library;
|
||||
* @author Agnieszka
|
||||
*/
|
||||
public class Book extends Item {
|
||||
|
||||
Book() {
|
||||
//nothing to do
|
||||
}
|
||||
|
||||
Book(int id, String n, String an, String asn, int y, String isbn, String p, String c) {
|
||||
this.setId(id);
|
||||
this.setName(n);
|
||||
@ -27,15 +29,21 @@ public class Book extends Item{
|
||||
@Override
|
||||
public void insertToDB() {
|
||||
db.insertBookQ(this);
|
||||
};
|
||||
}
|
||||
|
||||
;
|
||||
@Override
|
||||
public void delFromDB() {
|
||||
String query = "DELETE FROM books WHERE id=" + this.getId() + ";";
|
||||
};
|
||||
}
|
||||
|
||||
;
|
||||
@Override
|
||||
public void editInDB() {
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
;
|
||||
/*public void insertQuery(){
|
||||
System.out.println("INSERT INTO books VALUES('NULL', '" +name + "', '" + authorName + "', '" + authorSurname + "', '"+ publishing + "', '"+ year + "', '"+ ISBN + "', '"+ category + "');");
|
||||
}*/
|
||||
@ -43,26 +51,33 @@ public void editInDB(){
|
||||
public void setPublishing(String s) {
|
||||
this.publishing = s;
|
||||
}
|
||||
|
||||
public void setAuthorName(String s) {
|
||||
this.authorName = s;
|
||||
}
|
||||
|
||||
public void setAuthorSurname(String s) {
|
||||
this.authorSurname = s;
|
||||
}
|
||||
|
||||
public void setISBN(String s) {
|
||||
this.ISBN = s;
|
||||
}
|
||||
|
||||
public String getAuthorName() {
|
||||
return this.authorName;
|
||||
}
|
||||
|
||||
public String getAuthorSurname() {
|
||||
return this.authorSurname;
|
||||
}
|
||||
|
||||
public String getPublishing() {
|
||||
return this.publishing;
|
||||
}
|
||||
|
||||
public String getISBN() {
|
||||
return this.publishing;
|
||||
return this.ISBN;
|
||||
}
|
||||
private String authorName, authorSurname, publishing, ISBN;
|
||||
private Database db = new Database();
|
||||
|
@ -127,9 +127,6 @@
|
||||
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
|
||||
<Font name="Tahoma" size="14" style="0"/>
|
||||
</Property>
|
||||
<Property name="inputVerifier" type="javax.swing.InputVerifier" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||
<Connection code="new library.Validation("[a-zA-z0-9]+", this.add)" type="code"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="bookTitleActionPerformed"/>
|
||||
@ -215,6 +212,9 @@
|
||||
<Font name="Tahoma" size="14" style="0"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="ISBNActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="lcategory">
|
||||
<Properties>
|
||||
|
@ -5,7 +5,10 @@
|
||||
*/
|
||||
package library;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
@ -22,14 +25,15 @@ public class BookFieldPattern extends javax.swing.JFrame {
|
||||
initComponents();
|
||||
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
}
|
||||
|
||||
public BookFieldPattern(boolean required) {
|
||||
initComponents();
|
||||
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
bookTitle.setInputVerifier(new library.Validation("[a-zA-z0-9]+", required));
|
||||
//bookTitle.setInputVerifier(new library.Validation("[a-zA-z0-9]+", required));
|
||||
}
|
||||
|
||||
|
||||
public boolean add = false, delete = false, edit = false;
|
||||
|
||||
/**
|
||||
* This method is called from within the constructor to initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is always
|
||||
@ -62,7 +66,6 @@ public class BookFieldPattern extends javax.swing.JFrame {
|
||||
Title.setText("Tytuł:");
|
||||
|
||||
bookTitle.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
bookTitle.setInputVerifier(new library.Validation("[a-zA-z0-9]+", this.add));
|
||||
bookTitle.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
bookTitleActionPerformed(evt);
|
||||
@ -98,6 +101,11 @@ public class BookFieldPattern extends javax.swing.JFrame {
|
||||
lISBN.setText("ISBN:");
|
||||
|
||||
ISBN.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
ISBN.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
ISBNActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
lcategory.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
lcategory.setText("Kategoria:");
|
||||
@ -210,22 +218,13 @@ public class BookFieldPattern extends javax.swing.JFrame {
|
||||
|
||||
private void SaveChangesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveChangesActionPerformed
|
||||
if (this.add) {
|
||||
Book b = new Book();
|
||||
/*
|
||||
b.name = bookTitle.getText();
|
||||
b.authorName = authorName.getText();
|
||||
b.authorSurname = authorSurname.getText();
|
||||
b.publishing = publishing.getText();
|
||||
b.year = Integer.parseInt(year.getText());
|
||||
b.ISBN = ISBN.getText();
|
||||
b.category = Category.getSelectedItem().toString();
|
||||
b.insertQuery();
|
||||
*/
|
||||
}
|
||||
else if(this.edit){
|
||||
|
||||
Book b = new Book(0, bookTitle.getText(), authorName.getText(), authorSurname.getText(), Integer.parseInt(year.getText()), ISBN.getText(), publishing.getText(), Category.getSelectedItem().toString());
|
||||
b.insertToDB();
|
||||
|
||||
} else if (this.edit) {
|
||||
JOptionPane.showMessageDialog(null, "EDYTUJ");
|
||||
}
|
||||
else if(this.delete){
|
||||
} else if (this.delete) {
|
||||
JOptionPane.showMessageDialog(null, "USUŃ");
|
||||
}
|
||||
dispose();
|
||||
@ -239,6 +238,10 @@ public class BookFieldPattern extends javax.swing.JFrame {
|
||||
// TODO add your handling code here:
|
||||
}//GEN-LAST:event_bookTitleActionPerformed
|
||||
|
||||
private void ISBNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ISBNActionPerformed
|
||||
// TODO add your handling code here:
|
||||
}//GEN-LAST:event_ISBNActionPerformed
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
@ -274,8 +277,6 @@ public class BookFieldPattern extends javax.swing.JFrame {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
|
@ -4,6 +4,7 @@
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package library;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
@ -13,10 +14,10 @@ import java.sql.Statement;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Agnieszka
|
||||
* insert, delete i update do przeniesienia tutaj (9metod)
|
||||
* @author Agnieszka insert, delete i update do przeniesienia tutaj (9metod)
|
||||
*/
|
||||
public class Database {
|
||||
|
||||
@ -45,8 +46,21 @@ 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(12), category varchar(100))";
|
||||
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), author_surname varchar(50), year int, category varchar(100))";
|
||||
String createMovies = "CREATE TABLE IF NOT EXISTS movies (id INTEGER PRIMARY KEY AUTOINCREMENT, name varchar(255), director varchar(50), year int, category varchar(100))";
|
||||
try {
|
||||
@ -54,7 +68,7 @@ public class Database {
|
||||
stat.execute(createAlbums);
|
||||
stat.execute(createMovies);
|
||||
} catch (SQLException e) {
|
||||
JOptionPane.showMessageDialog(null, "Błąd przy tworzeniu tabel bazy danych.", "Error:", JOptionPane.INFORMATION_MESSAGE);
|
||||
JOptionPane.showMessageDialog(null, "Błąd przy odczycie zbazy danych.", "Error:", JOptionPane.INFORMATION_MESSAGE);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -93,6 +107,22 @@ public class Database {
|
||||
|
||||
}
|
||||
|
||||
public void insertAlbumQ(Album a) {
|
||||
try {
|
||||
PreparedStatement prepStmt = conn.prepareStatement(
|
||||
"INSERT INTO albums VALUES (NULL, ?, ?, ?, ?);");
|
||||
prepStmt.setString(1, a.getName());
|
||||
prepStmt.setString(2, a.getMusican());
|
||||
prepStmt.setInt(3, a.getYear());
|
||||
prepStmt.setString(4, a.getCategory());
|
||||
|
||||
prepStmt.execute();
|
||||
} catch (SQLException e) {
|
||||
JOptionPane.showMessageDialog(null, "Błąd przy dodawaniu do bazy", "Error:", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public List<Book> selectBooks() {
|
||||
List<Book> books = new LinkedList<Book>();
|
||||
try {
|
||||
@ -108,7 +138,6 @@ public class Database {
|
||||
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) {
|
||||
@ -151,6 +180,7 @@ public class Database {
|
||||
director = result.getString("director");
|
||||
category = result.getString("category");
|
||||
movies.add(new Movie(id, name, director, year, category));
|
||||
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
JOptionPane.showMessageDialog(null, "Błąd przy odczycie z bazy.", "Error:", JOptionPane.INFORMATION_MESSAGE);
|
||||
@ -167,4 +197,3 @@ public class Database {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,37 +8,44 @@ package library;
|
||||
/**
|
||||
*
|
||||
* @author Agnieszka
|
||||
|
||||
*
|
||||
*/
|
||||
public abstract class Item {
|
||||
|
||||
public abstract void insertToDB();
|
||||
|
||||
public abstract void delFromDB();
|
||||
|
||||
public abstract void editInDB();
|
||||
|
||||
public void setName(String s) {
|
||||
this.name = s;
|
||||
}
|
||||
|
||||
public void setCategory(String s) {
|
||||
this.category = s;
|
||||
}
|
||||
|
||||
public void setYear(int i) {
|
||||
this.year = i;
|
||||
}
|
||||
|
||||
public void setId(int i) {
|
||||
this.id = i;
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getCategory() {
|
||||
return this.category;
|
||||
}
|
||||
|
||||
public int getYear() {
|
||||
return this.year;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
@ -93,8 +93,6 @@ public class ListResult extends javax.swing.JFrame {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
|
@ -286,8 +286,11 @@ public class MainMenu extends javax.swing.JFrame {
|
||||
List<Book> books = new LinkedList<>();
|
||||
books = d.selectBooks();
|
||||
System.out.println("Lista książek:");
|
||||
for(Book k: books)
|
||||
for (Book k : books) {
|
||||
System.out.println(k);
|
||||
}
|
||||
|
||||
d.selectAllFromBooks();
|
||||
}//GEN-LAST:event_allBooksShowActionPerformed
|
||||
|
||||
/**
|
||||
|
@ -21,12 +21,14 @@ public class MovieFieldPattern extends javax.swing.JFrame {
|
||||
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
initComponents();
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* This method is called from within the constructor to initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is always
|
||||
@ -176,11 +178,9 @@ public class MovieFieldPattern extends javax.swing.JFrame {
|
||||
private void SaveChangesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveChangesActionPerformed
|
||||
if (this.add) {
|
||||
JOptionPane.showMessageDialog(null, "DODAJ");
|
||||
}
|
||||
else if(this.edit){
|
||||
} else if (this.edit) {
|
||||
JOptionPane.showMessageDialog(null, "EDYTUJ");
|
||||
}
|
||||
else if(this.delete){
|
||||
} else if (this.delete) {
|
||||
JOptionPane.showMessageDialog(null, "USUŃ");
|
||||
}
|
||||
dispose();
|
||||
@ -229,8 +229,6 @@ public class MovieFieldPattern extends javax.swing.JFrame {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
|
@ -14,15 +14,16 @@ 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 walitator używający wyrażeń regularnych do sprawdzania pól
|
||||
* formularzy wyrażenia regularne jako parametr konstuktora
|
||||
*/
|
||||
public class Validation extends InputVerifier {
|
||||
|
||||
public Validation(String ex, boolean rq) {
|
||||
expression = ex;
|
||||
required = rq;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean verify(JComponent input) {
|
||||
JTextField tf = (JTextField) input;
|
||||
@ -31,27 +32,21 @@ public class Validation extends InputVerifier {
|
||||
if (required) {
|
||||
if (m.matches()) {
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
if ("".equals(tf.getText())) {
|
||||
JOptionPane.showMessageDialog(null, "Pole wymagane!", "Sprawdzenie pola:", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "Niepoprawne dane!", "Sprawdzenie pola:", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (m.matches() || "".equals(tf.getText())){
|
||||
} else if (m.matches() || "".equals(tf.getText())) {
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "Niepoprawne dane!", "Sprawdzenie pola:", JOptionPane.INFORMATION_MESSAGE);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
String expression;
|
||||
boolean required = false;
|
||||
}
|
Loading…
Reference in New Issue
Block a user