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) {
|
||||
|
||||
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;
|
||||
}
|
||||
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
|
||||
@ -150,23 +152,21 @@ public class AlbumFieldPattern extends javax.swing.JFrame {
|
||||
|
||||
public void ChangeOkButtonText(String s) {
|
||||
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){
|
||||
JOptionPane.showMessageDialog(null, "DODAJ");
|
||||
if (this.add) {
|
||||
JOptionPane.showMessageDialog(null, "DODAJ");
|
||||
} else if (this.edit) {
|
||||
JOptionPane.showMessageDialog(null, "EDYTUJ");
|
||||
} else if (this.delete) {
|
||||
JOptionPane.showMessageDialog(null, "USUŃ");
|
||||
}
|
||||
else if(this.edit){
|
||||
JOptionPane.showMessageDialog(null, "EDYTUJ");
|
||||
}
|
||||
else if(this.delete){
|
||||
JOptionPane.showMessageDialog(null, "USUŃ");
|
||||
}
|
||||
dispose();
|
||||
dispose();
|
||||
}//GEN-LAST:event_SaveChangesActionPerformed
|
||||
|
||||
private void yearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_yearActionPerformed
|
||||
@ -209,9 +209,7 @@ public class AlbumFieldPattern extends javax.swing.JFrame {
|
||||
new AlbumFieldPattern().setVisible(false);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
|
@ -9,62 +9,77 @@ package library;
|
||||
*
|
||||
* @author Agnieszka
|
||||
*/
|
||||
public class Book extends Item{
|
||||
Book(){
|
||||
//nothing to do
|
||||
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);
|
||||
this.authorName = an;
|
||||
this.authorSurname = asn;
|
||||
this.setYear(y);
|
||||
this.setCategory(c);
|
||||
this.ISBN = isbn;
|
||||
this.publishing = p;
|
||||
}
|
||||
|
||||
|
||||
Book(int id, String n, String an, String asn, int y, String isbn, String p, String c) {
|
||||
this.setId(id);
|
||||
this.setName(n);
|
||||
this.authorName = an;
|
||||
this.authorSurname = asn;
|
||||
this.setYear(y);
|
||||
this.setCategory(c);
|
||||
this.ISBN = isbn;
|
||||
this.publishing = p;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertToDB() {
|
||||
db.insertBookQ(this);
|
||||
}
|
||||
|
||||
;
|
||||
@Override
|
||||
public void insertToDB(){
|
||||
db.insertBookQ(this);
|
||||
};
|
||||
@Override
|
||||
public void delFromDB(){
|
||||
public void delFromDB() {
|
||||
String query = "DELETE FROM books WHERE id=" + this.getId() + ";";
|
||||
};
|
||||
}
|
||||
|
||||
;
|
||||
@Override
|
||||
public void editInDB(){
|
||||
|
||||
};
|
||||
public void editInDB() {
|
||||
|
||||
}
|
||||
|
||||
;
|
||||
/*public void insertQuery(){
|
||||
System.out.println("INSERT INTO books VALUES('NULL', '" +name + "', '" + authorName + "', '" + authorSurname + "', '"+ publishing + "', '"+ year + "', '"+ ISBN + "', '"+ category + "');");
|
||||
}*/
|
||||
|
||||
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;
|
||||
}
|
||||
private String authorName, authorSurname, publishing, ISBN;
|
||||
private Database db = new Database();
|
||||
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.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) {
|
||||
|
||||
public BookFieldPattern(boolean required) {
|
||||
initComponents();
|
||||
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
bookTitle.setInputVerifier(new library.Validation("[a-zA-z0-9]+", required));
|
||||
}
|
||||
|
||||
|
||||
public boolean add= false, delete = false, edit = false;
|
||||
//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:");
|
||||
@ -202,33 +210,24 @@ public class BookFieldPattern extends javax.swing.JFrame {
|
||||
private void CategoryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CategoryActionPerformed
|
||||
// TODO add your handling code here:
|
||||
}//GEN-LAST:event_CategoryActionPerformed
|
||||
|
||||
|
||||
public void ChangeOkButtonText(String s) {
|
||||
this.SaveChanges.setText(s);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
*/
|
||||
if (this.add) {
|
||||
|
||||
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) {
|
||||
JOptionPane.showMessageDialog(null, "USUŃ");
|
||||
}
|
||||
else if(this.edit){
|
||||
JOptionPane.showMessageDialog(null, "EDYTUJ");
|
||||
}
|
||||
else if(this.delete){
|
||||
JOptionPane.showMessageDialog(null, "USUŃ");
|
||||
}
|
||||
dispose();
|
||||
dispose();
|
||||
}//GEN-LAST:event_SaveChangesActionPerformed
|
||||
|
||||
private void authorSurnameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_authorSurnameActionPerformed
|
||||
@ -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
|
||||
*/
|
||||
@ -273,9 +276,7 @@ public class BookFieldPattern extends javax.swing.JFrame {
|
||||
new BookFieldPattern().setVisible(false);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// 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,27 +14,27 @@ 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 {
|
||||
|
||||
|
||||
public static final String DRIVER = "org.sqlite.JDBC";
|
||||
public static final String DB_URL = "jdbc:sqlite:biblioteka.db"; // ścieżka do bazy
|
||||
|
||||
|
||||
private Connection conn;
|
||||
private Statement stat;
|
||||
|
||||
|
||||
public Database() {
|
||||
try {
|
||||
Class.forName(Database.DRIVER);
|
||||
} catch (ClassNotFoundException e) {
|
||||
System.err.println("Brak sterownika JDBC");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
conn = DriverManager.getConnection(DB_URL);
|
||||
stat = conn.createStatement();
|
||||
@ -41,27 +42,40 @@ public class Database {
|
||||
System.err.println("Problem z otwarciem polaczenia");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
createTables();
|
||||
}
|
||||
|
||||
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 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))";
|
||||
|
||||
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), 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 {
|
||||
stat.execute(createBooks);
|
||||
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;
|
||||
}
|
||||
|
||||
public void insertBookQ(Book b){
|
||||
try {
|
||||
|
||||
public void insertBookQ(Book b) {
|
||||
try {
|
||||
PreparedStatement prepStmt = conn.prepareStatement(
|
||||
"INSERT INTO books VALUES (NULL, ?, ?, ?, ?, ?, ?, ?);");
|
||||
prepStmt.setString(1, b.getName());
|
||||
@ -71,10 +85,10 @@ public class Database {
|
||||
prepStmt.setInt(5, b.getYear());
|
||||
prepStmt.setString(6, b.getISBN());
|
||||
prepStmt.setString(7, b.getCategory());
|
||||
|
||||
|
||||
prepStmt.execute();
|
||||
|
||||
/* String sel = "SELECT * FROM books WHERE name LIKE ? AND author_name LIKE ? AND author_surname LIKE ? AND publishing LIKE ? AND year = ? AND isbn LIKE ? AND category LIKE ? ;";
|
||||
|
||||
/* String sel = "SELECT * FROM books WHERE name LIKE ? AND author_name LIKE ? AND author_surname LIKE ? AND publishing LIKE ? AND year = ? AND isbn LIKE ? AND category LIKE ? ;";
|
||||
PreparedStatement prepStmt2 = conn.prepareStatement(sel);
|
||||
prepStmt.setString(1, b.getName());
|
||||
prepStmt.setString(2, b.getAuthorName());
|
||||
@ -86,20 +100,36 @@ public class Database {
|
||||
|
||||
ResultSet rs = stat.executeQuery(sel);
|
||||
b = new Book(rs.getInt("id"), rs.getString("name"), rs.getString("author_name"), rs.getString("suthor_surname"), rs.getInt("year"), rs.getString("isbn"), rs.getString("publishing"), rs.getString("category"));
|
||||
*/
|
||||
*/
|
||||
} catch (SQLException e) {
|
||||
JOptionPane.showMessageDialog(null, "Błąd przy dodawaniu do bazy", "Error:", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
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 {
|
||||
ResultSet result = stat.executeQuery("SELECT * FROM books");
|
||||
int id, year;
|
||||
String name, authorName, authorSurname, isbn, category, publishing;
|
||||
while(result.next()) {
|
||||
while (result.next()) {
|
||||
id = result.getInt("id");
|
||||
year = result.getInt("year");
|
||||
name = result.getString("name");
|
||||
@ -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) {
|
||||
@ -123,13 +152,13 @@ public class Database {
|
||||
ResultSet result = stat.executeQuery("SELECT * FROM albums");
|
||||
int id, year;
|
||||
String name, musican, category;
|
||||
while(result.next()) {
|
||||
while (result.next()) {
|
||||
id = result.getInt("id");
|
||||
year = result.getInt("year");
|
||||
name = result.getString("name");
|
||||
musican = result.getString("musican");
|
||||
category = result.getString("category");
|
||||
|
||||
|
||||
albums.add(new Album(id, name, musican, year, category));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
@ -137,27 +166,28 @@ public class Database {
|
||||
}
|
||||
return albums;
|
||||
}
|
||||
|
||||
|
||||
public List<Movie> selectMovies() {
|
||||
List<Movie> movies = new LinkedList<Movie>();
|
||||
try {
|
||||
ResultSet result = stat.executeQuery("SELECT * FROM movies");
|
||||
int id, year;
|
||||
String name, category, director;
|
||||
while(result.next()) {
|
||||
while (result.next()) {
|
||||
id = result.getInt("id");
|
||||
year = result.getInt("year");
|
||||
name = result.getString("name");
|
||||
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);
|
||||
}
|
||||
return movies;
|
||||
}
|
||||
|
||||
|
||||
public void closeConnection() {
|
||||
try {
|
||||
conn.close();
|
||||
@ -167,4 +197,3 @@ public class Database {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,41 +8,48 @@ 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){
|
||||
|
||||
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){
|
||||
|
||||
public void setCategory(String s) {
|
||||
this.category = s;
|
||||
}
|
||||
public void setYear(int i){
|
||||
|
||||
public void setYear(int i) {
|
||||
this.year = i;
|
||||
}
|
||||
public void setId(int 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;
|
||||
}
|
||||
|
||||
private String name, category;
|
||||
private int year, id;
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getCategory() {
|
||||
return this.category;
|
||||
}
|
||||
|
||||
public int getYear() {
|
||||
return this.year;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
private String name, category;
|
||||
private int year, id;
|
||||
}
|
||||
|
@ -92,9 +92,7 @@ public class ListResult extends javax.swing.JFrame {
|
||||
new ListResult().setVisible(true);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
|
@ -203,40 +203,40 @@ public class MainMenu extends javax.swing.JFrame {
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void bMovieActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bMovieActionPerformed
|
||||
if(radioBAdd.getModel().isSelected()){
|
||||
if (radioBAdd.getModel().isSelected()) {
|
||||
MovieFieldPattern b = new MovieFieldPattern(true);
|
||||
b.setVisible(true);
|
||||
b.add=true;
|
||||
}
|
||||
if(radioBEdit.getModel().isSelected()){
|
||||
b.add = true;
|
||||
}
|
||||
if (radioBEdit.getModel().isSelected()) {
|
||||
MovieFieldPattern b = new MovieFieldPattern();
|
||||
b.setVisible(true);
|
||||
b.edit=true;
|
||||
}
|
||||
if(radioBSearch.getModel().isSelected()){
|
||||
b.edit = true;
|
||||
}
|
||||
if (radioBSearch.getModel().isSelected()) {
|
||||
MovieFieldPattern b = new MovieFieldPattern();
|
||||
b.setVisible(true);
|
||||
b.delete=true;
|
||||
}
|
||||
b.delete = true;
|
||||
}
|
||||
}//GEN-LAST:event_bMovieActionPerformed
|
||||
|
||||
private void bAlbumActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bAlbumActionPerformed
|
||||
|
||||
if(radioBAdd.getModel().isSelected()){
|
||||
if (radioBAdd.getModel().isSelected()) {
|
||||
AlbumFieldPattern b = new AlbumFieldPattern(true);
|
||||
b.setVisible(true);
|
||||
b.add=true;
|
||||
}
|
||||
if(radioBEdit.getModel().isSelected()){
|
||||
b.add = true;
|
||||
}
|
||||
if (radioBEdit.getModel().isSelected()) {
|
||||
AlbumFieldPattern b = new AlbumFieldPattern();
|
||||
b.setVisible(true);
|
||||
b.edit=true;
|
||||
}
|
||||
if(radioBSearch.getModel().isSelected()){
|
||||
b.edit = true;
|
||||
}
|
||||
if (radioBSearch.getModel().isSelected()) {
|
||||
MovieFieldPattern b = new MovieFieldPattern();
|
||||
b.setVisible(true);
|
||||
b.delete=true;
|
||||
}
|
||||
b.delete = true;
|
||||
}
|
||||
}//GEN-LAST:event_bAlbumActionPerformed
|
||||
|
||||
private void bUserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bUserActionPerformed
|
||||
@ -256,22 +256,22 @@ public class MainMenu extends javax.swing.JFrame {
|
||||
}//GEN-LAST:event_radioBAddActionPerformed
|
||||
|
||||
private void bBookActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bBookActionPerformed
|
||||
if(radioBAdd.getModel().isSelected()){
|
||||
if (radioBAdd.getModel().isSelected()) {
|
||||
BookFieldPattern b = new BookFieldPattern(true);
|
||||
b.setVisible(true);
|
||||
b.add=true;
|
||||
}
|
||||
if(radioBEdit.getModel().isSelected()){
|
||||
b.add = true;
|
||||
}
|
||||
if (radioBEdit.getModel().isSelected()) {
|
||||
BookFieldPattern b = new BookFieldPattern();
|
||||
b.setVisible(true);
|
||||
b.edit=true;
|
||||
}
|
||||
if(radioBSearch.getModel().isSelected()){
|
||||
b.edit = true;
|
||||
}
|
||||
if (radioBSearch.getModel().isSelected()) {
|
||||
BookFieldPattern b = new BookFieldPattern();
|
||||
b.setVisible(true);
|
||||
b.delete=true;
|
||||
}
|
||||
|
||||
b.delete = true;
|
||||
}
|
||||
|
||||
}//GEN-LAST:event_bBookActionPerformed
|
||||
|
||||
private void radioBDelete1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioBDelete1ActionPerformed
|
||||
@ -279,15 +279,18 @@ public class MainMenu extends javax.swing.JFrame {
|
||||
}//GEN-LAST:event_radioBDelete1ActionPerformed
|
||||
|
||||
private void allBooksShowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_allBooksShowActionPerformed
|
||||
|
||||
|
||||
ListResult n = new ListResult();
|
||||
n.setVisible(true);
|
||||
Database d = new Database();
|
||||
List<Book> books = new LinkedList<>();
|
||||
books = d.selectBooks();
|
||||
System.out.println("Lista książek:");
|
||||
for(Book k: books)
|
||||
System.out.println(k);
|
||||
List<Book> books = new LinkedList<>();
|
||||
books = d.selectBooks();
|
||||
System.out.println("Lista książek:");
|
||||
for (Book k : books) {
|
||||
System.out.println(k);
|
||||
}
|
||||
|
||||
d.selectAllFromBooks();
|
||||
}//GEN-LAST:event_allBooksShowActionPerformed
|
||||
|
||||
/**
|
||||
@ -321,7 +324,7 @@ public class MainMenu extends javax.swing.JFrame {
|
||||
/* Create and display the form */
|
||||
java.awt.EventQueue.invokeLater(() -> {
|
||||
new MainMenu().setVisible(true);
|
||||
/* java.awt.EventQueue.invokeLater(() ->*/ });
|
||||
/* java.awt.EventQueue.invokeLater(() ->*/ });
|
||||
}
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
|
@ -21,12 +21,14 @@ public class MovieFieldPattern extends javax.swing.JFrame {
|
||||
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
initComponents();
|
||||
}
|
||||
public MovieFieldPattern(boolean required) {
|
||||
|
||||
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;
|
||||
}
|
||||
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
|
||||
@ -167,23 +169,21 @@ public class MovieFieldPattern extends javax.swing.JFrame {
|
||||
|
||||
public void ChangeOkButtonText(String s) {
|
||||
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){
|
||||
JOptionPane.showMessageDialog(null, "DODAJ");
|
||||
if (this.add) {
|
||||
JOptionPane.showMessageDialog(null, "DODAJ");
|
||||
} else if (this.edit) {
|
||||
JOptionPane.showMessageDialog(null, "EDYTUJ");
|
||||
} else if (this.delete) {
|
||||
JOptionPane.showMessageDialog(null, "USUŃ");
|
||||
}
|
||||
else if(this.edit){
|
||||
JOptionPane.showMessageDialog(null, "EDYTUJ");
|
||||
}
|
||||
else if(this.delete){
|
||||
JOptionPane.showMessageDialog(null, "USUŃ");
|
||||
}
|
||||
dispose();
|
||||
dispose();
|
||||
}//GEN-LAST:event_SaveChangesActionPerformed
|
||||
|
||||
private void scriptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_scriptActionPerformed
|
||||
@ -228,9 +228,7 @@ public class MovieFieldPattern extends javax.swing.JFrame {
|
||||
new MovieFieldPattern().setVisible(false);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
|
@ -14,44 +14,39 @@ 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;
|
||||
|
||||
public Validation(String ex, boolean rq) {
|
||||
expression = ex;
|
||||
required = rq;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
}
|
||||
String expression;
|
||||
boolean required = false;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
String expression;
|
||||
boolean required = false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user