Input Verifier wszystko okej

This commit is contained in:
Agnieszka Janicka 2016-06-09 22:19:01 +02:00
parent 264b557d48
commit fa5c2eec24
12 changed files with 149 additions and 152 deletions

Binary file not shown.

View File

@ -47,11 +47,7 @@
<Component id="lcategory" min="-2" pref="92" max="-2" attributes="0"/> <Component id="lcategory" min="-2" pref="92" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/> <EmptySpace type="unrelated" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0"> <Component id="SaveChanges" min="-2" pref="220" max="-2" attributes="0"/>
<Component id="SaveChanges" min="-2" pref="220" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="37" max="-2" attributes="0"/>
<Component id="cancel" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="Category" min="-2" pref="220" max="-2" attributes="0"/> <Component id="Category" min="-2" pref="220" max="-2" attributes="0"/>
</Group> </Group>
</Group> </Group>
@ -86,11 +82,8 @@
<Component id="Category" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="Category" alignment="3" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<EmptySpace type="separate" max="-2" attributes="0"/> <EmptySpace type="separate" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0"> <Component id="SaveChanges" min="-2" max="-2" attributes="0"/>
<Component id="SaveChanges" alignment="3" min="-2" max="-2" attributes="0"/> <EmptySpace pref="14" max="32767" attributes="0"/>
<Component id="cancel" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group> </Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
@ -193,13 +186,5 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="SaveChangesActionPerformed"/> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="SaveChangesActionPerformed"/>
</Events> </Events>
</Component> </Component>
<Component class="javax.swing.JButton" name="cancel">
<Properties>
<Property name="text" type="java.lang.String" value="Anuluj"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cancelActionPerformed"/>
</Events>
</Component>
</SubComponents> </SubComponents>
</Form> </Form>

View File

@ -19,13 +19,22 @@ 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);
initComponents(); initComponents();
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
} }
public AlbumFieldPattern(boolean required) { public AlbumFieldPattern(boolean required) {
initComponents(); initComponents();
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
Validation verify;
if (required) {
verify = new Validation(true);
} else {
verify = new Validation();
}
albumTitle.setInputVerifier(verify);
musican.setInputVerifier(verify);
year.setInputVerifier(verify);
} }
public boolean add = false, delete = false, edit = false, search = false; public boolean add = false, delete = false, edit = false, search = false;
@ -48,7 +57,6 @@ public class AlbumFieldPattern extends javax.swing.JFrame {
Category = new javax.swing.JComboBox<>(); Category = new javax.swing.JComboBox<>();
mainlabel = new javax.swing.JLabel(); mainlabel = new javax.swing.JLabel();
SaveChanges = new javax.swing.JButton(); SaveChanges = new javax.swing.JButton();
cancel = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
@ -94,13 +102,6 @@ public class AlbumFieldPattern extends javax.swing.JFrame {
} }
}); });
cancel.setText("Anuluj");
cancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout); getContentPane().setLayout(layout);
layout.setHorizontalGroup( layout.setHorizontalGroup(
@ -125,10 +126,7 @@ public class AlbumFieldPattern extends javax.swing.JFrame {
.addComponent(lcategory, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(lcategory, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup() .addComponent(SaveChanges, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(SaveChanges, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(37, 37, 37)
.addComponent(cancel))
.addComponent(Category, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addComponent(Category, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addContainerGap(26, Short.MAX_VALUE)) .addContainerGap(26, Short.MAX_VALUE))
); );
@ -154,10 +152,8 @@ public class AlbumFieldPattern extends javax.swing.JFrame {
.addComponent(lcategory) .addComponent(lcategory)
.addComponent(Category, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(Category, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18) .addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(SaveChanges)
.addComponent(SaveChanges) .addContainerGap(14, Short.MAX_VALUE))
.addComponent(cancel))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
); );
pack(); pack();
@ -192,10 +188,6 @@ public class AlbumFieldPattern extends javax.swing.JFrame {
// TODO add your handling code here: // TODO add your handling code here:
}//GEN-LAST:event_yearActionPerformed }//GEN-LAST:event_yearActionPerformed
private void cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelActionPerformed
this.dispose();
}//GEN-LAST:event_cancelActionPerformed
/** /**
* @param args the command line arguments * @param args the command line arguments
*/ */
@ -240,7 +232,6 @@ public class AlbumFieldPattern extends javax.swing.JFrame {
private javax.swing.JButton SaveChanges; private javax.swing.JButton SaveChanges;
private javax.swing.JLabel Title; private javax.swing.JLabel Title;
private javax.swing.JTextField albumTitle; private javax.swing.JTextField albumTitle;
private javax.swing.JButton cancel;
private javax.swing.JLabel lcategory; private javax.swing.JLabel lcategory;
private javax.swing.JLabel lmusican; private javax.swing.JLabel lmusican;
private javax.swing.JLabel lyear; private javax.swing.JLabel lyear;

View File

@ -22,12 +22,18 @@ public class Book extends Item {
//nothing to do //nothing to do
} }
Book(int id, String n, String an, String asn, int y, String isbn, String p, String c) { Book(int id, String n, String an, String asn, String y, String isbn, String p, String c) {
this.setId(id); this.setId(id);
this.setName(n); this.setName(n);
this.authorName = an; this.authorName = an;
this.authorSurname = asn; this.authorSurname = asn;
this.setYear(y); try{
this.setYear(Integer.parseInt(y));
}
catch(NumberFormatException e){
this.setYear(0);
}
this.setCategory(c); this.setCategory(c);
this.ISBN = isbn; this.ISBN = isbn;
this.publishing = p; this.publishing = p;

View File

@ -56,10 +56,7 @@
<Component id="SaveChanges" alignment="0" min="-2" pref="220" max="-2" attributes="0"/> <Component id="SaveChanges" alignment="0" min="-2" pref="220" max="-2" attributes="0"/>
</Group> </Group>
<EmptySpace type="separate" max="-2" attributes="0"/> <EmptySpace type="separate" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0"> <Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<Component id="cancel" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/> <EmptySpace max="32767" attributes="0"/>
</Group> </Group>
</Group> </Group>
@ -113,11 +110,8 @@
<Component id="Category" min="-2" max="-2" attributes="0"/> <Component id="Category" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<EmptySpace type="separate" max="-2" attributes="0"/> <EmptySpace type="separate" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0"> <Component id="SaveChanges" min="-2" max="-2" attributes="0"/>
<Component id="SaveChanges" alignment="3" min="-2" max="-2" attributes="0"/> <EmptySpace pref="33" max="32767" attributes="0"/>
<Component id="cancel" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="32" max="32767" attributes="0"/>
</Group> </Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
@ -242,15 +236,16 @@
<Component class="javax.swing.JComboBox" name="Category"> <Component class="javax.swing.JComboBox" name="Category">
<Properties> <Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor"> <Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="8"> <StringArray count="9">
<StringItem index="0" value="Przygodowe"/> <StringItem index="0" value=" "/>
<StringItem index="1" value="Naukowe"/> <StringItem index="1" value="Przygodowe"/>
<StringItem index="2" value="Powie&#x15b;&#x107;"/> <StringItem index="2" value="Naukowe"/>
<StringItem index="3" value="Poezja"/> <StringItem index="3" value="Powie&#x15b;&#x107;"/>
<StringItem index="4" value="Krymina&#x142;"/> <StringItem index="4" value="Poezja"/>
<StringItem index="5" value="Dla dzieci"/> <StringItem index="5" value="Krymina&#x142;"/>
<StringItem index="6" value="Psychologiczne"/> <StringItem index="6" value="Dla dzieci"/>
<StringItem index="7" value="Podr&#x119;czniki"/> <StringItem index="7" value="Psychologiczne"/>
<StringItem index="8" value="Podr&#x119;czniki"/>
</StringArray> </StringArray>
</Property> </Property>
</Properties> </Properties>
@ -295,13 +290,5 @@
<AuxValue name="JavaCodeGenerator_AddingCodePost" type="java.lang.String" value="jLabel1.setVisible(false);"/> <AuxValue name="JavaCodeGenerator_AddingCodePost" type="java.lang.String" value="jLabel1.setVisible(false);"/>
</AuxValues> </AuxValues>
</Component> </Component>
<Component class="javax.swing.JButton" name="cancel">
<Properties>
<Property name="text" type="java.lang.String" value="Anuluj"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cancelActionPerformed"/>
</Events>
</Component>
</SubComponents> </SubComponents>
</Form> </Form>

View File

@ -7,6 +7,8 @@ package library;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Arrays; import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.swing.JFrame; import javax.swing.JFrame;
@ -18,12 +20,13 @@ import javax.swing.JOptionPane;
*/ */
public class BookFieldPattern extends javax.swing.JFrame { public class BookFieldPattern extends javax.swing.JFrame {
/** public boolean add = false, delete = false, edit = false, search = false;
* Creates new form bookFieldPattern private Database d = new Database();
*/
public BookFieldPattern() { public BookFieldPattern() {
initComponents(); initComponents();
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
Validation verify = new Validation();
year.setInputVerifier(verify); year.setInputVerifier(verify);
ISBN.setInputVerifier(verify); ISBN.setInputVerifier(verify);
@ -32,6 +35,12 @@ public class BookFieldPattern extends javax.swing.JFrame {
public BookFieldPattern(boolean required) { public BookFieldPattern(boolean required) {
initComponents(); initComponents();
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
Validation verify;
if (required) {
verify = new Validation(true);
} else {
verify = new Validation();
}
bookTitle.setInputVerifier(verify); bookTitle.setInputVerifier(verify);
authorName.setInputVerifier(verify); authorName.setInputVerifier(verify);
authorSurname.setInputVerifier(verify); authorSurname.setInputVerifier(verify);
@ -40,9 +49,6 @@ public class BookFieldPattern extends javax.swing.JFrame {
publishing.setInputVerifier(verify); publishing.setInputVerifier(verify);
} }
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. * 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 * WARNING: Do NOT modify this code. The content of this method is always
@ -69,7 +75,6 @@ public class BookFieldPattern extends javax.swing.JFrame {
mainlabel = new javax.swing.JLabel(); mainlabel = new javax.swing.JLabel();
SaveChanges = new javax.swing.JButton(); SaveChanges = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel(); jLabel1 = new javax.swing.JLabel();
cancel = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
@ -132,7 +137,7 @@ public class BookFieldPattern extends javax.swing.JFrame {
lcategory.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N lcategory.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
lcategory.setText("Kategoria:"); lcategory.setText("Kategoria:");
Category.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Przygodowe", "Naukowe", "Powieść", "Poezja", "Kryminał", "Dla dzieci", "Psychologiczne", "Podręczniki" })); Category.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { " ", "Przygodowe", "Naukowe", "Powieść", "Poezja", "Kryminał", "Dla dzieci", "Psychologiczne", "Podręczniki" }));
Category.addActionListener(new java.awt.event.ActionListener() { Category.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) { public void actionPerformed(java.awt.event.ActionEvent evt) {
CategoryActionPerformed(evt); CategoryActionPerformed(evt);
@ -157,13 +162,6 @@ public class BookFieldPattern extends javax.swing.JFrame {
jLabel1.setDoubleBuffered(true); jLabel1.setDoubleBuffered(true);
jLabel1.setName(""); // NOI18N jLabel1.setName(""); // NOI18N
cancel.setText("Anuluj");
cancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout); getContentPane().setLayout(layout);
layout.setHorizontalGroup( layout.setHorizontalGroup(
@ -196,9 +194,7 @@ public class BookFieldPattern extends javax.swing.JFrame {
.addComponent(Category, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(Category, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(SaveChanges, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(SaveChanges, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18) .addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1)
.addComponent(jLabel1)
.addComponent(cancel))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
@ -240,10 +236,8 @@ public class BookFieldPattern extends javax.swing.JFrame {
.addComponent(lcategory) .addComponent(lcategory)
.addComponent(Category, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(Category, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18) .addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(SaveChanges)
.addComponent(SaveChanges) .addContainerGap(33, Short.MAX_VALUE))
.addComponent(cancel))
.addContainerGap(32, Short.MAX_VALUE))
); );
jLabel1.setVisible(false); jLabel1.setVisible(false);
@ -263,14 +257,34 @@ 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 { 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(), year.getText(), ISBN.getText(), publishing.getText(), Category.getSelectedItem().toString());
b.insertToDB(); b.insertToDB();
} catch (SQLException e) { } catch (SQLException e) {
e.getMessage(); e.getMessage();
} }
} else if (this.edit) { } else if (this.edit) {
JOptionPane.showMessageDialog(null, "EDYTUJ"); try {
Book b = new Book(0, bookTitle.getText(), authorName.getText(), authorSurname.getText(), year.getText(), ISBN.getText(), publishing.getText(), Category.getSelectedItem().toString());
List<Book> books = new LinkedList<>();
//books = d.selectBooks(b);
d.selectBooks(b);
/*Object[][] data = d.convertToTable(books);
String[] columnNames = {"ID",
"Tytuł",
"Imię Autora",
"Nazwisko Autora",
"Rok",
"ISBN",
"Wydawnictwo",
"Kategoria"};
ListResult table = new ListResult(data, columnNames);
table.setVisible(true);*/
} catch (IndexOutOfBoundsException e) {
//nothing to do here
}
// ListResult l = new ListResult();
} else if (this.delete) { } else if (this.delete) {
JOptionPane.showMessageDialog(null, "USUŃ"); JOptionPane.showMessageDialog(null, "USUŃ");
} else if (this.search) { } else if (this.search) {
@ -299,10 +313,6 @@ public class BookFieldPattern extends javax.swing.JFrame {
jLabel1.setVisible(false); jLabel1.setVisible(false);
}//GEN-LAST:event_ISBNFocusLost }//GEN-LAST:event_ISBNFocusLost
private void cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelActionPerformed
this.dispose();
}//GEN-LAST:event_cancelActionPerformed
/** /**
* @param args the command line arguments * @param args the command line arguments
*/ */
@ -350,7 +360,6 @@ public class BookFieldPattern extends javax.swing.JFrame {
private javax.swing.JLabel authorname; private javax.swing.JLabel authorname;
private javax.swing.JLabel authorsurname; private javax.swing.JLabel authorsurname;
javax.swing.JTextField bookTitle; javax.swing.JTextField bookTitle;
private javax.swing.JButton cancel;
private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel1;
private javax.swing.JLabel lISBN; private javax.swing.JLabel lISBN;
private javax.swing.JLabel lcategory; private javax.swing.JLabel lcategory;

View File

@ -135,11 +135,11 @@ public class Database {
List<Book> books = new ArrayList<Book>(); List<Book> books = new ArrayList<Book>();
try { try {
ResultSet result = stat.executeQuery("SELECT * FROM books"); ResultSet result = stat.executeQuery("SELECT * FROM books");
int id, year; int id;
String name, authorName, authorSurname, isbn, category, publishing; String name, authorName, authorSurname, isbn, category, publishing, year;
while (result.next()) { while (result.next()) {
id = result.getInt("id"); id = result.getInt("id");
year = result.getInt("year"); year = result.getString("year");
name = result.getString("name"); name = result.getString("name");
authorName = result.getString("author_name"); authorName = result.getString("author_name");
authorSurname = result.getString("author_surname"); authorSurname = result.getString("author_surname");
@ -154,48 +154,51 @@ public class Database {
return books; return books;
} }
public List<Book> selectBooks(Book searchData) { //public List<Book> selectBooks(Book searchData) {
public void selectBooks(Book searchData) {
List<Book> books = new ArrayList<>(); List<Book> books = new ArrayList<>();
try { boolean EmptyAll = true;
List<String> wheres = new ArrayList<>(); //try {
if (searchData.getName().length() > 0) { List<String> wheres = new ArrayList<>();
wheres.add("WHERE name LIKE " + searchData.getName()); if (searchData.getName().length() > 0) {
System.out.println("WHERE name LIKE " + searchData.getName()); wheres.add("WHERE name LIKE '" + searchData.getName() + "'");
} System.out.println("WHERE name LIKE '" + searchData.getName() + "'");
if (searchData.getAuthorName().length() > 0) { EmptyAll = false;
wheres.add("WHERE author_name LIKE " + searchData.getAuthorName()); }
System.out.println("WHERE author_name LIKE " + searchData.getAuthorName()); if (searchData.getAuthorName().length() > 0) {
} wheres.add("WHERE author_name LIKE '" + searchData.getAuthorName() + "'");
if (searchData.getPublishing().length() > 0) { System.out.println("WHERE author_name LIKE '" + searchData.getAuthorName() + "'");
wheres.add("WHERE publishing LIKE " + searchData.getPublishing()); EmptyAll = false;
System.out.println("WHERE publishing LIKE " + searchData.getPublishing()); }
} if (searchData.getPublishing().length() > 0) {
if (searchData.getYear() > 0) { wheres.add("WHERE publishing LIKE '" + searchData.getPublishing() + "'");
wheres.add("WHERE year = " + searchData.getYear()); System.out.println("WHERE publishing LIKE '" + searchData.getPublishing() + "'");
System.out.println("WHERE year = " + searchData.getYear()); EmptyAll = false;
} }
if (searchData.getName().length() > 0) { if (searchData.getYear() > 0) {
wheres.add("WHERE name LIKE " + searchData.getName()); wheres.add("WHERE year = " + searchData.getYear());
System.out.println("WHERE name LIKE " + searchData.getName()); System.out.println("WHERE year = " + searchData.getYear());
} EmptyAll = false;
if (searchData.getName().length() > 0) { }
wheres.add("WHERE name LIKE " + searchData.getName()); if (searchData.getISBN().length() > 0) {
System.out.println("WHERE name LIKE " + searchData.getName()); wheres.add("WHERE isbn LIKE " + searchData.getISBN());
} System.out.println("WHERE isbn LIKE '" + searchData.getISBN() + "'");
if (searchData.getISBN().length() > 0) { EmptyAll = false;
wheres.add("WHERE isbn LIKE " + searchData.getISBN()); }
System.out.println("WHERE isbn LIKE " + searchData.getISBN()); if (searchData.getCategory().length() > 1) {
} wheres.add("WHERE category LIKE '" + searchData.getCategory() + "'");
if (searchData.getCategory().length() > 0) { System.out.println("WHERE category LIKE '" + searchData.getCategory() + "'");
wheres.add("WHERE category LIKE " + searchData.getCategory()); EmptyAll = false;
System.out.println("WHERE category LIKE " + searchData.getCategory()); }
} if (EmptyAll) {
System.out.println("PUSTO");
}
String query = "SELECT * FROM books"; String query = "SELECT * FROM books";
if (query.length() == 19) { if (query.length() == 19) {
} }
ResultSet result = stat.executeQuery("SELECT * FROM books"); /*ResultSet result = stat.executeQuery("SELECT * FROM books");
int id, year; int id, year;
String name, authorName, authorSurname, isbn, category, publishing; String name, authorName, authorSurname, isbn, category, publishing;
while (result.next()) { while (result.next()) {
@ -212,7 +215,7 @@ public class Database {
} catch (SQLException e) { } catch (SQLException e) {
JOptionPane.showMessageDialog(null, "Błąd przy odczycie z bazy.", "Error:", JOptionPane.INFORMATION_MESSAGE); JOptionPane.showMessageDialog(null, "Błąd przy odczycie z bazy.", "Error:", JOptionPane.INFORMATION_MESSAGE);
} }
return books; return books;*/
} }
public List<Album> selectAlbums() { public List<Album> selectAlbums() {

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo"> <Form version="1.6" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<Properties> <Properties>
<Property name="defaultCloseOperation" type="int" value="3"/> <Property name="defaultCloseOperation" type="int" value="3"/>
</Properties> </Properties>
@ -72,10 +72,15 @@
<Property name="autoCreateColumnsFromModel" type="boolean" editor="org.netbeans.modules.form.RADConnectionPropertyEditor" postCode="table.setModel(new javax.swing.table.DefaultTableModel(&#xa; rows,&#xa; columnsNames&#xa;));"> <Property name="autoCreateColumnsFromModel" type="boolean" editor="org.netbeans.modules.form.RADConnectionPropertyEditor" postCode="table.setModel(new javax.swing.table.DefaultTableModel(&#xa; rows,&#xa; columnsNames&#xa;));">
<Connection code="false" type="code"/> <Connection code="false" type="code"/>
</Property> </Property>
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor"> <Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor" postCode="table.setRowSelectionInterval(0, 0);">
<Connection code="new javax.swing.table.DefaultTableModel(&#xa; rows,&#xa; columnsNames&#xa;)" type="code"/> <Connection code="new javax.swing.table.DefaultTableModel(&#xa; rows,&#xa; columnsNames&#xa;)" type="code"/>
</Property> </Property>
<Property name="rowHeight" type="int" value="25"/> <Property name="rowHeight" type="int" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="25" type="code"/>
</Property>
<Property name="selectionModel" type="javax.swing.ListSelectionModel" editor="org.netbeans.modules.form.editors2.JTableSelectionModelEditor">
<JTableSelectionModel selectionMode="0"/>
</Property>
</Properties> </Properties>
<AuxValues> <AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new javax.swing.JTable(rows, columnsNames)"/> <AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new javax.swing.JTable(rows, columnsNames)"/>

View File

@ -57,7 +57,9 @@ public class ListResult extends javax.swing.JFrame {
rows, rows,
columnsNames columnsNames
)); ));
table.setRowSelectionInterval(0, 0);
table.setRowHeight(25); table.setRowHeight(25);
table.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
jScrollPane1.setViewportView(table); jScrollPane1.setViewportView(table);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

View File

@ -387,7 +387,7 @@ public class MainMenu extends javax.swing.JFrame {
private void bAlbumActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bAlbumActionPerformed private void bAlbumActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bAlbumActionPerformed
if (radioBAdd.getModel().isSelected()) { if (radioBAdd.getModel().isSelected()) {
AlbumFieldPattern b = new AlbumFieldPattern(); AlbumFieldPattern b = new AlbumFieldPattern(true);
b.setVisible(true); b.setVisible(true);
b.add = true; b.add = true;
} }
@ -440,7 +440,6 @@ public class MainMenu extends javax.swing.JFrame {
private void allBooksShowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_allBooksShowActionPerformed private void allBooksShowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_allBooksShowActionPerformed
try { try {
List<Book> books = new LinkedList<>(); List<Book> books = new LinkedList<>();
books = d.selectBooks(); books = d.selectBooks();
Object[][] data = d.convertToTable(books); Object[][] data = d.convertToTable(books);
@ -504,7 +503,7 @@ public class MainMenu extends javax.swing.JFrame {
n = ""; n = "";
n = Integer.toString(d.countAll("albums")); n = Integer.toString(d.countAll("albums"));
numberOfAlbums.setText(n); numberOfAlbums.setText(n);
n = ""; n = "";
n = Integer.toString(d.countAll("movies")); n = Integer.toString(d.countAll("movies"));
numberOfMovies.setText(n); numberOfMovies.setText(n);
}//GEN-LAST:event_refreshNumbersOfItemsActionPerformed }//GEN-LAST:event_refreshNumbersOfItemsActionPerformed

View File

@ -19,13 +19,22 @@ public class MovieFieldPattern extends javax.swing.JFrame {
* Creates new form bookFieldPattern * Creates new form bookFieldPattern
*/ */
public MovieFieldPattern() { public MovieFieldPattern() {
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
initComponents(); initComponents();
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
} }
public MovieFieldPattern(boolean required) { public MovieFieldPattern(boolean required) {
initComponents(); initComponents();
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
Validation verify;
if (required) {
verify = new Validation(true);
} else {
verify = new Validation();
}
movieTitle.setInputVerifier(verify);
director.setInputVerifier(verify);
year.setInputVerifier(verify);
} }
public boolean add = false, delete = false, edit = false, search = false; public boolean add = false, delete = false, edit = false, search = false;

View File

@ -18,6 +18,7 @@ import javax.swing.JTextField;
*/ */
public class Validation extends InputVerifier { public class Validation extends InputVerifier {
public final int nowadays = 2016;
String expression; String expression;
boolean required = false; boolean required = false;
int year; int year;
@ -37,7 +38,7 @@ public class Validation extends InputVerifier {
public boolean checkField(JComponent input) { public boolean checkField(JComponent input) {
JTextField tf = (JTextField) input; JTextField tf = (JTextField) input;
if (required) { if (required) {
if ((tf.getText().equals(""))) { if ("".equals(tf.getText())) {
JOptionPane.showMessageDialog(null, "Pole wymagane!", "Błąd wprowadzanych danych", JOptionPane.INFORMATION_MESSAGE); JOptionPane.showMessageDialog(null, "Pole wymagane!", "Błąd wprowadzanych danych", JOptionPane.INFORMATION_MESSAGE);
return false; return false;
} }
@ -47,7 +48,7 @@ public class Validation extends InputVerifier {
if (!"".equals(tf.getText())) { if (!"".equals(tf.getText())) {
try { try {
year = Integer.parseInt(tf.getText()); year = Integer.parseInt(tf.getText());
if (year > 2016 || year < 1900) { if (year > nowadays || year < 1900) {
JOptionPane.showMessageDialog(null, "Data spoza zakresu.", "Błąd wprowadzanych danych", JOptionPane.INFORMATION_MESSAGE); JOptionPane.showMessageDialog(null, "Data spoza zakresu.", "Błąd wprowadzanych danych", JOptionPane.INFORMATION_MESSAGE);
return false; return false;
} }
@ -64,7 +65,7 @@ public class Validation extends InputVerifier {
if (m.matches()) { if (m.matches()) {
return true; return true;
} else { } else {
JOptionPane.showMessageDialog(null, "Niepoprawne dane!", "Sprawdzenie pola:", JOptionPane.INFORMATION_MESSAGE); JOptionPane.showMessageDialog(null, "Wpisz ISBN we właściwym formacie", "Sprawdzenie pola:", JOptionPane.INFORMATION_MESSAGE);
return false; return false;
} }
} }