diff --git a/out/production/IDB-Hue-Projekt/Hinzufügen.class b/out/production/IDB-Hue-Projekt/Hinzufügen.class index cf514d0..7f642d8 100644 Binary files a/out/production/IDB-Hue-Projekt/Hinzufügen.class and b/out/production/IDB-Hue-Projekt/Hinzufügen.class differ diff --git a/out/production/IDB-Hue-Projekt/Tabellen.class b/out/production/IDB-Hue-Projekt/Tabellen.class index 1ffb865..f4b09dc 100644 Binary files a/out/production/IDB-Hue-Projekt/Tabellen.class and b/out/production/IDB-Hue-Projekt/Tabellen.class differ diff --git a/src/Datail.java b/src/Datail.java new file mode 100644 index 0000000..41210a0 --- /dev/null +++ b/src/Datail.java @@ -0,0 +1,51 @@ +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableModel; +import java.sql.*; + +public class Datail { + public static ResultSet spieler(int verein, Connection con) { + try { + Statement s = con.createStatement(); + ResultSet r = s.executeQuery("SELECT * FROM Spieler WHERE Vereins_ID = " + verein); + return r; + } catch (SQLException e) { + throw new RuntimeException(e); + } + + } + + public static DefaultTableModel detailmodel(int verein, String url) { + String[][] temp = {{""}}; + DefaultTableModel t = new DefaultTableModel(); + System.out.println(verein); + + + try (Connection conn = DriverManager.getConnection(url, "root", "")) { + ResultSet r = spieler(verein, conn); + ResultSetMetaData rm = r.getMetaData(); + rm.getColumnCount(); + String column[] = new String[rm.getColumnCount()]; + + + for (int i = 1; i <= rm.getColumnCount(); i++) { + column[i - 1] = rm.getColumnName(i); + t.addColumn(column[i - 1]); + } + t.setDataVector(temp, column); + t.removeRow(0); + Object rows[] = new Object[rm.getColumnCount()]; + while (r.next()) { + for (int i = 1; i <= rm.getColumnCount(); i++) { + rows[i - 1] = r.getString(i); + } + t.addRow(rows); + t.fireTableDataChanged(); + + } + + } catch (SQLException e) { + throw new RuntimeException(e); + } + return t; + } +} diff --git a/src/Einzelansicht.java b/src/Einzelansicht.java index 85b9fde..b23f017 100644 --- a/src/Einzelansicht.java +++ b/src/Einzelansicht.java @@ -2,7 +2,6 @@ import javax.swing.*; import javax.swing.event.*; import javax.swing.table.DefaultTableModel; import java.awt.*; -import java.awt.Menu; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.*; @@ -35,9 +34,14 @@ public class Einzelansicht extends JFrame implements TableModelListener, ActionL JMenu adm = null; JMenuItem i1, i2, i3, i4, i5, i6, i7; + JTable detail; + JScrollPane dsc; + int vid=1; + + public Einzelansicht(String ta) { - this.setSize(500, 400); + this.setSize(600, 800); this.setResizable(false); this.setLayout(null); this.setDefaultCloseOperation(EXIT_ON_CLOSE); @@ -101,6 +105,7 @@ public class Einzelansicht extends JFrame implements TableModelListener, ActionL sql = "Select * From " + tab; r.first(); einfügen(r); + detailtab(vid); } catch (SQLException e) { throw new RuntimeException(e); @@ -140,7 +145,7 @@ public class Einzelansicht extends JFrame implements TableModelListener, ActionL this.add(a); einf = new JButton("Einfügen"); - einf.setBounds(150, 280, 100, 50); + einf.setBounds(470, 50, 100, 50); einf.setForeground(Color.BLACK); einf.setBackground(Color.white); einf.setFont(font); @@ -150,7 +155,7 @@ public class Einzelansicht extends JFrame implements TableModelListener, ActionL del = new JButton("Löschen"); - del.setBounds(300, 280, 100, 50); + del.setBounds(470, 120, 100, 50); del.setForeground(Color.BLACK); del.setBackground(Color.white); del.setFont(font); @@ -169,6 +174,10 @@ public class Einzelansicht extends JFrame implements TableModelListener, ActionL t.addTableModelListener(this); + + + + } public static void einfügen(ResultSet r) { @@ -233,6 +242,8 @@ public class Einzelansicht extends JFrame implements TableModelListener, ActionL r = s.executeQuery(sql); r.first(); einfügen(r); + vid=r.getInt("V_ID"); + detailtab(vid); sq = ""; sql = ""; @@ -290,6 +301,8 @@ public class Einzelansicht extends JFrame implements TableModelListener, ActionL try { if (r.next()) { einfügen(r); + vid=r.getInt("V_ID"); + detailtab(vid); } } catch (SQLException ex) { throw new RuntimeException(ex); @@ -299,16 +312,17 @@ public class Einzelansicht extends JFrame implements TableModelListener, ActionL try { if (r.previous()) { einfügen(r); + vid=r.getInt("V_ID"); + detailtab(vid); } } catch (SQLException ex) { throw new RuntimeException(ex); } break; case "einf": - Hinzufügen d = new Hinzufügen(r, tab); + Hinzufügen d = new Hinzufügen(r, tab,this,true); d.setVisible(true); - this.setFocusable(false); - this.setFocusableWindowState(false); + break; case "änd": break; @@ -343,4 +357,12 @@ public class Einzelansicht extends JFrame implements TableModelListener, ActionL } } + public void detailtab(int vid){ + + detail = new JTable(Datail.detailmodel(vid,url)); + dsc = new JScrollPane(detail); + dsc.setBounds(20, 250, 550, 400); + dsc.getHorizontalScrollBar(); + this.add(dsc); + } } diff --git a/src/Hinzufügen.java b/src/Hinzufügen.java index ab17097..26cc6ce 100644 --- a/src/Hinzufügen.java +++ b/src/Hinzufügen.java @@ -4,27 +4,24 @@ import java.awt.*; import java.awt.event.*; import java.sql.*; -public class Hinzufügen extends JFrame implements ActionListener { +public class Hinzufügen extends Dialog implements ActionListener { + JFrame frame; JButton a = null; ResultSetMetaData rm = null; - - JButton einf = null; - - JTable table = null; - DefaultTableModel t = null; - String url = "jdbc:mariadb://127.0.0.1:3306/bundesliga"; - String spalten = ""; String sname = ""; - Font font = new Font("Arial",Font.PLAIN,12); + Font font = new Font("Arial", Font.PLAIN, 12); + + + public Hinzufügen(ResultSet r, String tab, JFrame owner,boolean modal) { + super(owner,modal); + - public Hinzufügen(ResultSet r, String tab) { this.setSize(500, 600); this.setLayout(null); - - + owner.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); a = new JButton("Zurück"); a.setBounds(50, 30, 80, 50); @@ -64,17 +61,6 @@ public class Hinzufügen extends JFrame implements ActionListener { einf.addActionListener(e -> { for (int i = 1; i < z; i++) { try { - System.out.println(b[i].getText()); - if (b[i].getText().length() == 0) { - int response = JOptionPane.showConfirmDialog(null, "Soll der Wert für " + rm.getColumnName(i + 1) + " 'NULL' übernommen werden?", "Bestätigen", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); - System.out.println(response); - if (response == 0) { - //null - } else { - break; - } - } - if (i == z - 1) { spalten = spalten + "'" + b[i].getText() + "'"; sname = sname + rm.getColumnName(i + 1); @@ -82,6 +68,18 @@ public class Hinzufügen extends JFrame implements ActionListener { spalten = spalten + "'" + b[i].getText() + "',"; sname = sname + rm.getColumnName(i + 1) + ","; } + System.out.println(b[i].getText()); + if (b[i].getText().length() == 0) { + int response = JOptionPane.showConfirmDialog(null, "Soll der Wert für " + rm.getColumnName(i + 1) + " 'NULL' übernommen werden?", "Bestätigen", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); + System.out.println(response); + if (response == 0) { + spalten= spalten+" Null"; + } else { + break; + } + } + + } catch (Exception ex) { @@ -91,13 +89,13 @@ public class Hinzufügen extends JFrame implements ActionListener { System.out.println(sname); System.out.println(spalten); String sql = "Insert into " + tab + "(" + sname + ") Values (" + spalten + ")"; + System.out.println(sql); Connection conn = null; try { conn = DriverManager.getConnection(url, "root", ""); Statement s = conn.createStatement(); ResultSet a = s.executeQuery(sql); this.dispose(); - Tabellen.einfügen(tab); } catch (SQLException ex) { throw new RuntimeException(ex); } diff --git a/src/Tabellen.java b/src/Tabellen.java index 2ee11ef..9484fd1 100644 --- a/src/Tabellen.java +++ b/src/Tabellen.java @@ -57,7 +57,7 @@ public class Tabellen extends JFrame implements TableModelListener { einf.setBackground(Color.white); einf.setFont(font); einf.addActionListener(e -> { - Hinzufügen d = new Hinzufügen(r, tab); + Hinzufügen d = new Hinzufügen(r, tab,this,true); d.setVisible(true); this.setFocusable(false);