zapis i już

This commit is contained in:
Agnieszka Janicka 2016-06-07 12:36:43 +02:00
parent b8c4e12d6f
commit 3f474500ab
15 changed files with 37 additions and 115 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -42,12 +42,10 @@
<Group type="103" groupAlignment="1" max="-2" attributes="0"> <Group type="103" groupAlignment="1" max="-2" attributes="0">
<Component id="lcategory" max="32767" attributes="0"/> <Component id="lcategory" max="32767" attributes="0"/>
<Component id="lyear" pref="92" max="32767" attributes="0"/> <Component id="lyear" pref="92" max="32767" attributes="0"/>
<Component id="authorsurname" alignment="0" max="32767" attributes="0"/>
</Group> </Group>
<EmptySpace min="-2" pref="17" max="-2" attributes="0"/> <EmptySpace min="-2" pref="17" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Component id="year" alignment="0" min="-2" pref="76" max="-2" attributes="0"/> <Component id="year" alignment="0" min="-2" pref="76" max="-2" attributes="0"/>
<Component id="script" min="-2" pref="220" max="-2" attributes="0"/>
<Component id="Category" min="-2" pref="220" max="-2" attributes="0"/> <Component id="Category" min="-2" pref="220" max="-2" attributes="0"/>
<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>
@ -73,11 +71,6 @@
<Component id="director" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="director" alignment="3" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="authorsurname" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="script" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0"> <Group type="103" groupAlignment="3" attributes="0">
<Component id="lyear" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="lyear" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="year" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="year" alignment="3" min="-2" max="-2" attributes="0"/>
@ -125,24 +118,6 @@
</Property> </Property>
</Properties> </Properties>
</Component> </Component>
<Component class="javax.swing.JTextField" name="script">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Tahoma" size="14" style="0"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="scriptActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="authorsurname">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Tahoma" size="14" style="0"/>
</Property>
<Property name="text" type="java.lang.String" value="Scenariusz:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lyear"> <Component class="javax.swing.JLabel" name="lyear">
<Properties> <Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">

View File

@ -25,7 +25,7 @@ public class Album extends Item {
}; };
@Override @Override
public void delFromDB(){ public void delFromDB(){
String query = "DELETE FROM albums WHERE id=" + this.getId() + ";";
}; };
@Override @Override
public void editInDB(){ public void editInDB(){

View File

@ -11,6 +11,9 @@ package library;
*/ */
public class Book extends Item { public class Book extends Item {
private String authorName, authorSurname, publishing, ISBN;
private Database d = new Database();
Book() { Book() {
//nothing to do //nothing to do
} }
@ -31,24 +34,17 @@ public class Book extends Item {
d.insertBookQ(this); d.insertBookQ(this);
} }
; @Override
@Override
public void delFromDB() { public void delFromDB() {
String query = "DELETE FROM books WHERE id=" + this.getId() + ";";
} }
; @Override
@Override
public void editInDB() { public void editInDB() {
} }
; public void setPublishing(String s) {
/*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; this.publishing = s;
} }
@ -79,7 +75,5 @@ public void setPublishing(String s) {
public String getISBN() { public String getISBN() {
return this.ISBN; return this.ISBN;
} }
private String authorName, authorSurname, publishing, ISBN;
private Database d = new Database();
} }

View File

@ -85,9 +85,8 @@ public class Database {
prepStmt.setInt(5, b.getYear()); prepStmt.setInt(5, b.getYear());
prepStmt.setString(6, b.getISBN()); prepStmt.setString(6, b.getISBN());
prepStmt.setString(7, b.getCategory()); prepStmt.setString(7, b.getCategory());
prepStmt.execute(); prepStmt.execute();
JOptionPane.showMessageDialog(null, "Dodano poprawnie.", "Informacja:", JOptionPane.INFORMATION_MESSAGE);
/* 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); PreparedStatement prepStmt2 = conn.prepareStatement(sel);
prepStmt.setString(1, b.getName()); prepStmt.setString(1, b.getName());
@ -115,14 +114,14 @@ public class Database {
prepStmt.setString(2, a.getMusican()); prepStmt.setString(2, a.getMusican());
prepStmt.setInt(3, a.getYear()); prepStmt.setInt(3, a.getYear());
prepStmt.setString(4, a.getCategory()); prepStmt.setString(4, a.getCategory());
prepStmt.execute(); prepStmt.execute();
JOptionPane.showMessageDialog(null, "Dodano poprawnie.", "Informacja:", JOptionPane.INFORMATION_MESSAGE);
} catch (SQLException e) { } catch (SQLException e) {
JOptionPane.showMessageDialog(null, "Błąd przy dodawaniu do bazy", "Error:", JOptionPane.INFORMATION_MESSAGE); JOptionPane.showMessageDialog(null, "Błąd przy dodawaniu do bazy", "Error:", JOptionPane.INFORMATION_MESSAGE);
} }
} }
public void insertMovieQ(Movie m) { public void insertMovieQ(Movie m) {
try { try {
PreparedStatement prepStmt = conn.prepareStatement( PreparedStatement prepStmt = conn.prepareStatement(
@ -132,6 +131,7 @@ public class Database {
prepStmt.setInt(3, m.getYear()); prepStmt.setInt(3, m.getYear());
prepStmt.setString(4, m.getCategory()); prepStmt.setString(4, m.getCategory());
prepStmt.execute(); prepStmt.execute();
JOptionPane.showMessageDialog(null, "Dodano poprawnie.", "Informacja:", JOptionPane.INFORMATION_MESSAGE);
} catch (SQLException e) { } catch (SQLException e) {
JOptionPane.showMessageDialog(null, "Błąd przy dodawaniu do bazy", "Error:", JOptionPane.INFORMATION_MESSAGE); JOptionPane.showMessageDialog(null, "Błąd przy dodawaniu do bazy", "Error:", JOptionPane.INFORMATION_MESSAGE);
} }

View File

@ -15,43 +15,44 @@ import javax.swing.JOptionPane;
* *
* @author Agnieszka * @author Agnieszka
*/ */
public class Movie extends Item{ public class Movie extends Item {
public Connection conn; public Connection conn;
public Statement stat; public Statement stat;
private String director; private String director;
private Database d = new Database(); private Database d = new Database();
Movie(){ Movie() {
//nothing to do there //nothing to do there
} }
Movie(int id, String n, String d, int y, String c){ Movie(int id, String n, String d, int y, String c) {
this.setId(id); this.setId(id);
this.setName(n); this.setName(n);
this.director = d; this.director = d;
this.setYear(y); this.setYear(y);
this.setCategory(c); this.setCategory(c);
} }
@Override
public void insertToDB(){
d.insertMovieQ(this);
};
public String getDirector(){ @Override
return this.director; public void insertToDB() {
} d.insertMovieQ(this);
@Override }
public void delFromDB(){
@Override
public void delFromDB() {
String query = "DELETE FROM books WHERE id=" + this.getId() + ";"; String query = "DELETE FROM books WHERE id=" + this.getId() + ";";
}; }
@Override @Override
public void editInDB(){ public void editInDB() {
};
}
public String getDirector() {
return this.director;
}
} }
/*public void insertQuery(){ /*public void insertQuery(){
System.out.println("INSERT INTO books VALUES('NULL', '" +name + "', '" + authorName + "', '" + authorSurname + "', '"+ publishing + "', '"+ year + "', '"+ ISBN + "', '"+ category + "');"); System.out.println("INSERT INTO books VALUES('NULL', '" +name + "', '" + authorName + "', '" + authorSurname + "', '"+ publishing + "', '"+ year + "', '"+ ISBN + "', '"+ category + "');");
}*/ }*/

View File

@ -42,12 +42,10 @@
<Group type="103" groupAlignment="1" max="-2" attributes="0"> <Group type="103" groupAlignment="1" max="-2" attributes="0">
<Component id="lcategory" max="32767" attributes="0"/> <Component id="lcategory" max="32767" attributes="0"/>
<Component id="lyear" pref="92" max="32767" attributes="0"/> <Component id="lyear" pref="92" max="32767" attributes="0"/>
<Component id="authorsurname" alignment="0" max="32767" attributes="0"/>
</Group> </Group>
<EmptySpace min="-2" pref="17" max="-2" attributes="0"/> <EmptySpace min="-2" pref="17" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Component id="year" alignment="0" min="-2" pref="76" max="-2" attributes="0"/> <Component id="year" alignment="0" min="-2" pref="76" max="-2" attributes="0"/>
<Component id="script" min="-2" pref="220" max="-2" attributes="0"/>
<Component id="Category" min="-2" pref="220" max="-2" attributes="0"/> <Component id="Category" min="-2" pref="220" max="-2" attributes="0"/>
<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>
@ -73,11 +71,6 @@
<Component id="director" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="director" alignment="3" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="authorsurname" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="script" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0"> <Group type="103" groupAlignment="3" attributes="0">
<Component id="lyear" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="lyear" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="year" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="year" alignment="3" min="-2" max="-2" attributes="0"/>
@ -125,24 +118,6 @@
</Property> </Property>
</Properties> </Properties>
</Component> </Component>
<Component class="javax.swing.JTextField" name="script">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Tahoma" size="14" style="0"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="scriptActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="authorsurname">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Tahoma" size="14" style="0"/>
</Property>
<Property name="text" type="java.lang.String" value="Scenariusz:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lyear"> <Component class="javax.swing.JLabel" name="lyear">
<Properties> <Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">

View File

@ -42,8 +42,6 @@ public class MovieFieldPattern extends javax.swing.JFrame {
movieTitle = new javax.swing.JTextField(); movieTitle = new javax.swing.JTextField();
directorrname = new javax.swing.JLabel(); directorrname = new javax.swing.JLabel();
director = new javax.swing.JTextField(); director = new javax.swing.JTextField();
script = new javax.swing.JTextField();
authorsurname = new javax.swing.JLabel();
lyear = new javax.swing.JLabel(); lyear = new javax.swing.JLabel();
year = new javax.swing.JTextField(); year = new javax.swing.JTextField();
lcategory = new javax.swing.JLabel(); lcategory = new javax.swing.JLabel();
@ -63,16 +61,6 @@ public class MovieFieldPattern extends javax.swing.JFrame {
director.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N director.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
script.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
script.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
scriptActionPerformed(evt);
}
});
authorsurname.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
authorsurname.setText("Scenariusz:");
lyear.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N lyear.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
lyear.setText("Rok:"); lyear.setText("Rok:");
@ -124,12 +112,10 @@ public class MovieFieldPattern extends javax.swing.JFrame {
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(lcategory, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(lcategory, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(lyear, javax.swing.GroupLayout.DEFAULT_SIZE, 92, Short.MAX_VALUE) .addComponent(lyear, javax.swing.GroupLayout.DEFAULT_SIZE, 92, Short.MAX_VALUE))
.addComponent(authorsurname, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(17, 17, 17) .addGap(17, 17, 17)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(year, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(year, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(script, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
.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)
.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))))
.addContainerGap(21, Short.MAX_VALUE)) .addContainerGap(21, Short.MAX_VALUE))
@ -148,10 +134,6 @@ public class MovieFieldPattern extends javax.swing.JFrame {
.addComponent(directorrname) .addComponent(directorrname)
.addComponent(director, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(director, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(authorsurname)
.addComponent(script, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lyear) .addComponent(lyear)
.addComponent(year, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(year, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
@ -177,7 +159,8 @@ public class MovieFieldPattern extends javax.swing.JFrame {
private void SaveChangesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveChangesActionPerformed private void SaveChangesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveChangesActionPerformed
if (this.add) { if (this.add) {
JOptionPane.showMessageDialog(null, "DODAJ"); Movie m = new Movie(0, movieTitle.getText(), director.getText(), Integer.parseInt(year.getText()), Category.getSelectedItem().toString() );
m.insertToDB();
} else if (this.edit) { } else if (this.edit) {
JOptionPane.showMessageDialog(null, "EDYTUJ"); JOptionPane.showMessageDialog(null, "EDYTUJ");
} else if (this.delete) { } else if (this.delete) {
@ -186,10 +169,6 @@ public class MovieFieldPattern extends javax.swing.JFrame {
dispose(); dispose();
}//GEN-LAST:event_SaveChangesActionPerformed }//GEN-LAST:event_SaveChangesActionPerformed
private void scriptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_scriptActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_scriptActionPerformed
private void yearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_yearActionPerformed private void yearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_yearActionPerformed
// TODO add your handling code here: // TODO add your handling code here:
}//GEN-LAST:event_yearActionPerformed }//GEN-LAST:event_yearActionPerformed
@ -235,14 +214,12 @@ public class MovieFieldPattern extends javax.swing.JFrame {
private javax.swing.JComboBox<String> Category; private javax.swing.JComboBox<String> Category;
private javax.swing.JButton SaveChanges; private javax.swing.JButton SaveChanges;
private javax.swing.JLabel Title; private javax.swing.JLabel Title;
private javax.swing.JLabel authorsurname;
private javax.swing.JTextField director; private javax.swing.JTextField director;
private javax.swing.JLabel directorrname; private javax.swing.JLabel directorrname;
private javax.swing.JLabel lcategory; private javax.swing.JLabel lcategory;
private javax.swing.JLabel lyear; private javax.swing.JLabel lyear;
private javax.swing.JLabel mainlabel; private javax.swing.JLabel mainlabel;
private javax.swing.JTextField movieTitle; private javax.swing.JTextField movieTitle;
private javax.swing.JTextField script;
private javax.swing.JTextField year; private javax.swing.JTextField year;
// End of variables declaration//GEN-END:variables // End of variables declaration//GEN-END:variables
} }