start
This commit is contained in:
parent
ae4339c077
commit
ccd7960a2d
Binary file not shown.
Binary file not shown.
@ -1,12 +1,12 @@
|
|||||||
import javax.swing.table.DefaultTableModel;
|
import javax.swing.table.DefaultTableModel;
|
||||||
import javax.swing.table.TableModel;
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
|
|
||||||
public class Datail {
|
public class Datail {
|
||||||
public static ResultSet spieler(int verein, Connection con) {
|
public static ResultSet spieler(int verein, Connection con) {
|
||||||
|
//liefert das Resulset mit allen Spielern des Vereins
|
||||||
try {
|
try {
|
||||||
Statement s = con.createStatement();
|
Statement s = con.createStatement();
|
||||||
ResultSet r = s.executeQuery("SELECT * FROM Spieler WHERE Vereins_ID = " + verein);
|
ResultSet r = s.executeQuery("SELECT * FROM Spieler WHERE Vereins_ID = " + verein +" ORDER BY Spieler_Name");
|
||||||
return r;
|
return r;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
@ -15,10 +15,11 @@ public class Datail {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static DefaultTableModel detailmodel(DefaultTableModel t,int verein, String url) {
|
public static DefaultTableModel detailmodel(DefaultTableModel t,int verein, String url) {
|
||||||
|
//Füllt das mitgegebene Tabelmodel mit den Daten der Spieler
|
||||||
String[][] temp = {{""}};
|
String[][] temp = {{""}};
|
||||||
System.out.println("test = "+verein);
|
|
||||||
|
|
||||||
try (Connection conn = DriverManager.getConnection(url, "root", "")) {
|
try (Connection conn = DriverManager.getConnection(url, "root", "")) {
|
||||||
|
|
||||||
ResultSet r = spieler(verein, conn);
|
ResultSet r = spieler(verein, conn);
|
||||||
ResultSetMetaData rm = r.getMetaData();
|
ResultSetMetaData rm = r.getMetaData();
|
||||||
rm.getColumnCount();
|
rm.getColumnCount();
|
||||||
@ -44,6 +45,7 @@ public class Datail {
|
|||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
//Gibt das Tabelmodel zurück
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,33 +9,31 @@ import java.awt.event.KeyEvent;
|
|||||||
import java.awt.event.KeyListener;
|
import java.awt.event.KeyListener;
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
|
|
||||||
public class Einzelansicht extends JFrame implements TableModelListener, ActionListener {
|
public class Einzelansicht extends JFrame implements ActionListener {
|
||||||
|
|
||||||
JScrollPane sc = null;
|
JScrollPane sc = null;
|
||||||
JButton a = null;
|
JButton a = null;
|
||||||
JButton einf = null;
|
JButton einf = null;
|
||||||
JButton del = null;
|
JButton del = null;
|
||||||
static JButton zur = null;
|
JButton zur = null;
|
||||||
static JButton vor = null;
|
JButton vor = null;
|
||||||
|
JButton ch = null;
|
||||||
|
JButton sz = null;
|
||||||
static ResultSetMetaData rm = null;
|
static ResultSetMetaData rm = null;
|
||||||
static DefaultTableModel t = new DefaultTableModel();
|
static DefaultTableModel t = new DefaultTableModel();
|
||||||
static JTable table = new JTable(t);
|
static JTable table = new JTable(t);
|
||||||
static ResultSet r = null;
|
static ResultSet r = null;
|
||||||
static String url = "jdbc:mariadb://127.0.0.1:3306/bundesliga";
|
static String url = "jdbc:mariadb://127.0.0.1:3306/bundesliga";
|
||||||
|
|
||||||
JTextField s = null;
|
JTextField s = null;
|
||||||
String tab = null;
|
static String tab = null;
|
||||||
|
|
||||||
JLabel such = null;
|
JLabel such = null;
|
||||||
|
|
||||||
Font font = new Font("Arial", Font.PLAIN, 12);
|
Font font = new Font("Arial", Font.PLAIN, 12);
|
||||||
String sql = null;
|
static String sql = null;
|
||||||
JMenuBar bar = null;
|
JMenuBar bar = null;
|
||||||
JMenu dat = null;
|
JMenu dat = null;
|
||||||
JMenu bew = null;
|
JMenu bew = null;
|
||||||
JMenu adm = null;
|
JMenu adm = null;
|
||||||
JMenuItem i1, i2, i3, i4, i5, i6, i7;
|
JMenuItem i1, i2, i3, i4, i5, i6, i7;
|
||||||
|
|
||||||
static DefaultTableModel dtm = new DefaultTableModel();
|
static DefaultTableModel dtm = new DefaultTableModel();
|
||||||
static JTable detail = new JTable(dtm);
|
static JTable detail = new JTable(dtm);
|
||||||
static JScrollPane dsc;
|
static JScrollPane dsc;
|
||||||
@ -43,6 +41,7 @@ public class Einzelansicht extends JFrame implements TableModelListener, ActionL
|
|||||||
|
|
||||||
|
|
||||||
public Einzelansicht(String ta) {
|
public Einzelansicht(String ta) {
|
||||||
|
//Frameeigenschaften werden deklariert
|
||||||
this.setSize(600, 800);
|
this.setSize(600, 800);
|
||||||
this.setResizable(false);
|
this.setResizable(false);
|
||||||
this.setLayout(null);
|
this.setLayout(null);
|
||||||
@ -50,10 +49,13 @@ public class Einzelansicht extends JFrame implements TableModelListener, ActionL
|
|||||||
tab = ta;
|
tab = ta;
|
||||||
this.setTitle(tab);
|
this.setTitle(tab);
|
||||||
|
|
||||||
|
//Menüs für Menüleiste deklarieren
|
||||||
bar = new JMenuBar();
|
bar = new JMenuBar();
|
||||||
dat = new JMenu("Datei");
|
dat = new JMenu("Datei");
|
||||||
bew = new JMenu("Bewegen");
|
bew = new JMenu("Bewegen");
|
||||||
adm = new JMenu("Administration");
|
adm = new JMenu("Administration");
|
||||||
|
|
||||||
|
//Menüitems mit Namen versehen und aAtionen hinterlegen
|
||||||
i1 = new JMenuItem("Programm schließen");
|
i1 = new JMenuItem("Programm schließen");
|
||||||
i1.addActionListener(e -> {
|
i1.addActionListener(e -> {
|
||||||
this.dispose();
|
this.dispose();
|
||||||
@ -68,7 +70,7 @@ public class Einzelansicht extends JFrame implements TableModelListener, ActionL
|
|||||||
|
|
||||||
i3 = new JMenuItem("Vorheriger Datensatz");
|
i3 = new JMenuItem("Vorheriger Datensatz");
|
||||||
i3.addActionListener(this);
|
i3.addActionListener(this);
|
||||||
i3.setActionCommand("zur");
|
i3.setActionCommand("rück");
|
||||||
|
|
||||||
i4 = new JMenuItem("Suchen");
|
i4 = new JMenuItem("Suchen");
|
||||||
i4.addActionListener(e -> {
|
i4.addActionListener(e -> {
|
||||||
@ -90,6 +92,7 @@ public class Einzelansicht extends JFrame implements TableModelListener, ActionL
|
|||||||
i7.addActionListener(this);
|
i7.addActionListener(this);
|
||||||
i7.setActionCommand("lösch");
|
i7.setActionCommand("lösch");
|
||||||
|
|
||||||
|
//Menüitems an Menüs binden
|
||||||
dat.add(i1);
|
dat.add(i1);
|
||||||
bew.add(i2);
|
bew.add(i2);
|
||||||
bew.add(i3);
|
bew.add(i3);
|
||||||
@ -103,19 +106,8 @@ public class Einzelansicht extends JFrame implements TableModelListener, ActionL
|
|||||||
this.setJMenuBar(bar);
|
this.setJMenuBar(bar);
|
||||||
|
|
||||||
|
|
||||||
try (Connection conn = DriverManager.getConnection(url, "root", "")) {
|
//Buttons
|
||||||
Statement s = conn.createStatement();
|
vor = new JButton("Vorwärts");
|
||||||
sql = "Select * From " + tab;
|
|
||||||
r = s.executeQuery(sql);
|
|
||||||
rm = r.getMetaData();
|
|
||||||
r.first();
|
|
||||||
einfügen(r);
|
|
||||||
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
vor = new JButton("Weiter");
|
|
||||||
vor.setBounds(350, 150, 90, 50);
|
vor.setBounds(350, 150, 90, 50);
|
||||||
vor.setFont(font);
|
vor.setFont(font);
|
||||||
vor.setBackground(Color.white);
|
vor.setBackground(Color.white);
|
||||||
@ -124,23 +116,17 @@ public class Einzelansicht extends JFrame implements TableModelListener, ActionL
|
|||||||
vor.setActionCommand("vor");
|
vor.setActionCommand("vor");
|
||||||
this.add(vor);
|
this.add(vor);
|
||||||
|
|
||||||
zur = new JButton("Letzte");
|
zur = new JButton("Rückwärts");
|
||||||
zur.setBounds(80, 150, 90, 50);
|
zur.setBounds(80, 150, 90, 50);
|
||||||
zur.setFont(font);
|
zur.setFont(font);
|
||||||
zur.setBackground(Color.white);
|
zur.setBackground(Color.white);
|
||||||
zur.setForeground(Color.black);
|
zur.setForeground(Color.black);
|
||||||
zur.addActionListener(this);
|
zur.addActionListener(this);
|
||||||
zur.setActionCommand("zur");
|
zur.setActionCommand("rück");
|
||||||
this.add(zur);
|
this.add(zur);
|
||||||
|
|
||||||
|
|
||||||
sc = new JScrollPane(Einzelansicht.table);
|
|
||||||
sc.setBounds(50, 100, 400, 50);
|
|
||||||
sc.getHorizontalScrollBar();
|
|
||||||
this.add(sc);
|
|
||||||
|
|
||||||
a = new JButton("Zurück");
|
a = new JButton("Zurück");
|
||||||
a.setBounds(50, 30, 80, 50);
|
a.setBounds(50, 30, 80, 30);
|
||||||
a.setForeground(Color.BLACK);
|
a.setForeground(Color.BLACK);
|
||||||
a.setBackground(Color.white);
|
a.setBackground(Color.white);
|
||||||
a.setFont(font);
|
a.setFont(font);
|
||||||
@ -149,7 +135,7 @@ public class Einzelansicht extends JFrame implements TableModelListener, ActionL
|
|||||||
this.add(a);
|
this.add(a);
|
||||||
|
|
||||||
einf = new JButton("Einfügen");
|
einf = new JButton("Einfügen");
|
||||||
einf.setBounds(470, 50, 100, 50);
|
einf.setBounds(470, 20, 80, 30);
|
||||||
einf.setForeground(Color.BLACK);
|
einf.setForeground(Color.BLACK);
|
||||||
einf.setBackground(Color.white);
|
einf.setBackground(Color.white);
|
||||||
einf.setFont(font);
|
einf.setFont(font);
|
||||||
@ -157,9 +143,18 @@ public class Einzelansicht extends JFrame implements TableModelListener, ActionL
|
|||||||
einf.setActionCommand("einf");
|
einf.setActionCommand("einf");
|
||||||
this.add(einf);
|
this.add(einf);
|
||||||
|
|
||||||
|
ch = new JButton("Ändern");
|
||||||
|
ch.setBounds(470, 80, 80, 30);
|
||||||
|
ch.setFont(font);
|
||||||
|
ch.setBackground(Color.white);
|
||||||
|
ch.setForeground(Color.black);
|
||||||
|
ch.addActionListener(this);
|
||||||
|
ch.setActionCommand("änd");
|
||||||
|
this.add(ch);
|
||||||
|
|
||||||
|
|
||||||
del = new JButton("Löschen");
|
del = new JButton("Löschen");
|
||||||
del.setBounds(470, 120, 100, 50);
|
del.setBounds(470, 140, 80, 30);
|
||||||
del.setForeground(Color.BLACK);
|
del.setForeground(Color.BLACK);
|
||||||
del.setBackground(Color.white);
|
del.setBackground(Color.white);
|
||||||
del.setFont(font);
|
del.setFont(font);
|
||||||
@ -167,6 +162,26 @@ public class Einzelansicht extends JFrame implements TableModelListener, ActionL
|
|||||||
del.setActionCommand("lösch");
|
del.setActionCommand("lösch");
|
||||||
this.add(del);
|
this.add(del);
|
||||||
|
|
||||||
|
sz = new JButton("Zurücksetzen");
|
||||||
|
sz.setBounds(185, 10, 105, 30);
|
||||||
|
sz.setForeground(Color.BLACK);
|
||||||
|
sz.setBackground(Color.white);
|
||||||
|
sz.setFont(font);
|
||||||
|
sz.addActionListener(e -> {
|
||||||
|
standart(1);
|
||||||
|
this.remove(sz);
|
||||||
|
this.repaint();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
//Mastertabelle in Scrollbar
|
||||||
|
table.setCellEditor(null);
|
||||||
|
sc = new JScrollPane(Einzelansicht.table);
|
||||||
|
sc.setBounds(50, 100, 400, 50);
|
||||||
|
sc.getHorizontalScrollBar();
|
||||||
|
this.add(sc);
|
||||||
|
|
||||||
|
//Jlabel und JTextfield für die Suche
|
||||||
such = new JLabel("Suchen");
|
such = new JLabel("Suchen");
|
||||||
such.setBounds(300, 10, 50, 20);
|
such.setBounds(300, 10, 50, 20);
|
||||||
this.add(such);
|
this.add(such);
|
||||||
@ -176,19 +191,34 @@ public class Einzelansicht extends JFrame implements TableModelListener, ActionL
|
|||||||
this.add(s);
|
this.add(s);
|
||||||
suchen();
|
suchen();
|
||||||
|
|
||||||
t.addTableModelListener(this);
|
//Detailtabelle in Scrollpane
|
||||||
|
|
||||||
|
|
||||||
detail.setAutoCreateRowSorter(true);
|
detail.setAutoCreateRowSorter(true);
|
||||||
dsc = new JScrollPane(detail);
|
dsc = new JScrollPane(detail);
|
||||||
dsc.setBounds(20, 250, 550, 400);
|
dsc.setBounds(20, 250, 550, 400);
|
||||||
dsc.getHorizontalScrollBar();
|
dsc.getHorizontalScrollBar();
|
||||||
this.add(dsc);
|
this.add(dsc);
|
||||||
|
|
||||||
|
standart(1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void standart(int row) {
|
||||||
|
//Alle Datensätze in das Resultset und an bestimmter Position anzeigen
|
||||||
|
try (Connection conn = DriverManager.getConnection(url, "root", "")) {
|
||||||
|
Statement s = conn.createStatement();
|
||||||
|
sql = "Select * From " + tab;
|
||||||
|
r = s.executeQuery(sql);
|
||||||
|
rm = r.getMetaData();
|
||||||
|
r.absolute(row);
|
||||||
|
einfügen(r);
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void einfügen(ResultSet r) {
|
public static void einfügen(ResultSet r) {
|
||||||
|
//Datensatz an bestimmter Position des Resultsets in die Tabele einfügen
|
||||||
String[][] temp = {{""}};
|
String[][] temp = {{""}};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -209,6 +239,7 @@ public class Einzelansicht extends JFrame implements TableModelListener, ActionL
|
|||||||
t.addRow(rows);
|
t.addRow(rows);
|
||||||
t.fireTableDataChanged();
|
t.fireTableDataChanged();
|
||||||
|
|
||||||
|
//Methode für die Detailtabelle
|
||||||
vid = r.getInt(1);
|
vid = r.getInt(1);
|
||||||
detailtab(vid);
|
detailtab(vid);
|
||||||
|
|
||||||
@ -220,7 +251,7 @@ public class Einzelansicht extends JFrame implements TableModelListener, ActionL
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void suchen() {
|
public void suchen() {
|
||||||
|
//Bei dem bestätigen der Suchanfrage mit Enter wird die Suche gestartet und die ergebnisse als Resultset angezeigt
|
||||||
s.addKeyListener(new KeyListener() {
|
s.addKeyListener(new KeyListener() {
|
||||||
@Override
|
@Override
|
||||||
public void keyTyped(KeyEvent e) {
|
public void keyTyped(KeyEvent e) {
|
||||||
@ -228,6 +259,8 @@ public class Einzelansicht extends JFrame implements TableModelListener, ActionL
|
|||||||
r = Suchen.search(s.getText(), r);
|
r = Suchen.search(s.getText(), r);
|
||||||
s.setText("");
|
s.setText("");
|
||||||
einfügen(r);
|
einfügen(r);
|
||||||
|
Einzelansicht.this.add(sz);
|
||||||
|
Einzelansicht.this.repaint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,47 +276,12 @@ public class Einzelansicht extends JFrame implements TableModelListener, ActionL
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void tableChanged(TableModelEvent e) {
|
|
||||||
int zeile = table.getSelectedRow();
|
|
||||||
int spalte = table.getSelectedColumn();
|
|
||||||
if (spalte > 0) {
|
|
||||||
int response = 0;
|
|
||||||
try {
|
|
||||||
response = JOptionPane.showConfirmDialog(null, "Wollen Sie dein Eintrag in Zeile " + (zeile + 1) + ", Spalte :" + (rm.getColumnName(spalte + 1)) + " ändern?", "Bestätigen", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
|
||||||
} catch (SQLException ex) {
|
|
||||||
throw new RuntimeException(ex);
|
|
||||||
}
|
|
||||||
if (response == 0) {
|
|
||||||
try (Connection conn = DriverManager.getConnection(url, "root", "")) {
|
|
||||||
Statement s = conn.createStatement();
|
|
||||||
System.out.println(t.getColumnName(spalte) + "\n" + rm.getColumnTypeName(spalte + 1));
|
|
||||||
if (rm.getColumnTypeName(spalte + 1).equalsIgnoreCase("Varchar")) {
|
|
||||||
ResultSet r = s.executeQuery("Update " + tab + " set " + t.getColumnName(spalte) + "= '" + t.getValueAt(zeile, spalte).toString() + "' WHERE " + t.getColumnName(0) + " = " + t.getValueAt(zeile, 0));
|
|
||||||
|
|
||||||
} else if (rm.getColumnTypeName(spalte + 1).equalsIgnoreCase("Date")) {
|
|
||||||
ResultSet r = s.executeQuery("Update " + tab + " set " + t.getColumnName(spalte) + "= '" + t.getValueAt(zeile, spalte).toString() + "' WHERE " + t.getColumnName(0) + " = " + t.getValueAt(zeile, 0));
|
|
||||||
|
|
||||||
} else {
|
|
||||||
ResultSet r = s.executeQuery("Update " + tab + " set " + t.getColumnName(spalte) + "= " + t.getValueAt(zeile, spalte).toString() + " WHERE " + t.getColumnName(0) + " = " + t.getValueAt(zeile, 0));
|
|
||||||
|
|
||||||
}
|
|
||||||
table.clearSelection();
|
|
||||||
} catch (SQLException f) {
|
|
||||||
throw new RuntimeException(f);
|
|
||||||
}
|
|
||||||
t.fireTableDataChanged();
|
|
||||||
} else {
|
|
||||||
table.clearSelection();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
String command = e.getActionCommand();
|
String command = e.getActionCommand();
|
||||||
|
|
||||||
|
//Aktionen des Menüs und der Buttons
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case "vor":
|
case "vor":
|
||||||
try {
|
try {
|
||||||
@ -295,27 +293,52 @@ public class Einzelansicht extends JFrame implements TableModelListener, ActionL
|
|||||||
throw new RuntimeException(ex);
|
throw new RuntimeException(ex);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "zur":
|
case "rück":
|
||||||
try {
|
try {
|
||||||
if (r.previous()) {
|
if (r.previous()) {
|
||||||
einfügen(r);
|
einfügen(r);
|
||||||
vid = r.getInt("V_ID");
|
|
||||||
}
|
}
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
throw new RuntimeException(ex);
|
throw new RuntimeException(ex);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "einf":
|
case "einf":
|
||||||
|
//Ein Objekt der Klasse Hinzufügen wird erzeugt und ein Modaler Dialog wird angezeigt
|
||||||
Hinzufügen d = new Hinzufügen(r, tab, this, true);
|
Hinzufügen d = new Hinzufügen(r, tab, this, true);
|
||||||
d.setVisible(true);
|
d.setVisible(true);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "änd":
|
case "änd":
|
||||||
|
int spalte = table.getSelectedColumn();
|
||||||
|
//ist die ausgewählte Spalte > 0 dann wird der Datensatz nach bestätigung geändert
|
||||||
|
if (spalte > 0) {
|
||||||
|
try (Connection conn = DriverManager.getConnection(url, "root", "")) {
|
||||||
|
Statement s = conn.createStatement();
|
||||||
|
String eingabe = JOptionPane.showInputDialog(t.getColumnName(spalte), r.getString(spalte + 1));
|
||||||
|
if (eingabe != null) {
|
||||||
|
System.out.println("test");
|
||||||
|
ResultSet ra = s.executeQuery("Update " + tab + " set " + t.getColumnName(spalte) + "= '" + eingabe + "' WHERE " + t.getColumnName(0) + " = " + r.getString(1));
|
||||||
|
standart(r.getRow());
|
||||||
|
}
|
||||||
|
table.clearSelection();
|
||||||
|
} catch (SQLException f) {
|
||||||
|
JOptionPane.showMessageDialog(null, "Da hat etwas nicht geklappt", "Fehler!", JOptionPane.ERROR_MESSAGE);
|
||||||
|
table.clearSelection();
|
||||||
|
throw new RuntimeException(f);
|
||||||
|
}
|
||||||
|
t.fireTableDataChanged();
|
||||||
|
} else {
|
||||||
|
JOptionPane.showMessageDialog(null, "Wählen Sie bitte eine Zelle der Tabelle aus. \n Die " + t.getColumnName(0) + " ist nicht veränderbar.");
|
||||||
|
table.clearSelection();
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "lösch":
|
case "lösch":
|
||||||
Löschen l = new Löschen(tab,t,table);
|
//Ein Objekt der Klasse Löschen wird erzeugt
|
||||||
|
Löschen l = new Löschen(tab, t, table);
|
||||||
break;
|
break;
|
||||||
case "close":
|
case "close":
|
||||||
|
//Die Einzelansicht schließt sich und man kehr tins Hauptmenü zurück
|
||||||
this.dispose();
|
this.dispose();
|
||||||
Menü m = new Menü();
|
Menü m = new Menü();
|
||||||
m.setVisible(true);
|
m.setVisible(true);
|
||||||
@ -326,10 +349,10 @@ public class Einzelansicht extends JFrame implements TableModelListener, ActionL
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void detailtab(int vid) {
|
public static void detailtab(int vid) {
|
||||||
|
//Tabelmodel wird an die Methode weitergegeben und für die ansicht der Spieler verändert
|
||||||
Datail.detailmodel(dtm, vid, url);
|
Datail.detailmodel(dtm, vid, url);
|
||||||
dtm.fireTableDataChanged();
|
dtm.fireTableDataChanged();
|
||||||
|
|
||||||
|
|
||||||
System.out.println("detail =" + vid);
|
System.out.println("detail =" + vid);
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,10 +3,7 @@ import java.awt.*;
|
|||||||
import java.awt.event.*;
|
import java.awt.event.*;
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
|
|
||||||
import static javax.swing.WindowConstants.DISPOSE_ON_CLOSE;
|
|
||||||
|
|
||||||
public class Hinzufügen extends Dialog implements ActionListener {
|
public class Hinzufügen extends Dialog implements ActionListener {
|
||||||
JFrame frame;
|
|
||||||
JButton a = null;
|
JButton a = null;
|
||||||
ResultSetMetaData rm = null;
|
ResultSetMetaData rm = null;
|
||||||
JButton einf = null;
|
JButton einf = null;
|
||||||
@ -17,12 +14,14 @@ public class Hinzufügen extends Dialog implements ActionListener {
|
|||||||
|
|
||||||
|
|
||||||
public Hinzufügen(ResultSet r, String tab, JFrame owner, boolean modal) {
|
public Hinzufügen(ResultSet r, String tab, JFrame owner, boolean modal) {
|
||||||
|
//Ein Modaler Dialog braucht einen Owner, in dme Fall der Frame
|
||||||
super(owner, modal);
|
super(owner, modal);
|
||||||
|
|
||||||
|
//Framesettings
|
||||||
this.setSize(500, 600);
|
this.setSize(500, 600);
|
||||||
this.setLayout(null);
|
this.setLayout(null);
|
||||||
|
|
||||||
|
//Button um den Vorgang abzubrechen
|
||||||
a = new JButton("Zurück");
|
a = new JButton("Zurück");
|
||||||
a.setBounds(50, 30, 80, 50);
|
a.setBounds(50, 30, 80, 50);
|
||||||
a.setFont(font);
|
a.setFont(font);
|
||||||
@ -33,6 +32,7 @@ public class Hinzufügen extends Dialog implements ActionListener {
|
|||||||
});
|
});
|
||||||
this.add(a);
|
this.add(a);
|
||||||
|
|
||||||
|
//Es wird für jede Spalte der Tabelle ein Textfeld und ein Bezeichner (JLabel) erzeugt
|
||||||
try {
|
try {
|
||||||
rm = r.getMetaData();
|
rm = r.getMetaData();
|
||||||
int x = 10;
|
int x = 10;
|
||||||
@ -53,29 +53,38 @@ public class Hinzufügen extends Dialog implements ActionListener {
|
|||||||
y = 300;
|
y = 300;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//Der Button zum Bestätigen der Eingabe
|
||||||
einf = new JButton("Einfügen");
|
einf = new JButton("Einfügen");
|
||||||
einf.setBounds(50, 480, 100, 50);
|
einf.setBounds(50, 480, 100, 50);
|
||||||
einf.setFont(font);
|
einf.setFont(font);
|
||||||
einf.setForeground(Color.black);
|
einf.setForeground(Color.black);
|
||||||
einf.setBackground(Color.white);
|
einf.setBackground(Color.white);
|
||||||
einf.addActionListener(e -> {
|
einf.addActionListener(e -> {
|
||||||
|
//Erst wird jedes Textfeld durchgegangen und unterschieden, ob die eingabe Null ist oder nicht
|
||||||
for (int i = 1; i < z; i++) {
|
for (int i = 1; i < z; i++) {
|
||||||
try {
|
try {
|
||||||
|
//Ist die letze Spalte bzw Textfeld erreicht dann wird Folgendes ausgeführt
|
||||||
if (i == z - 1) {
|
if (i == z - 1) {
|
||||||
|
//Wenn ein Textfeld Null ist, dann wird der User gefragt, ob er dies so übernehmen möchte
|
||||||
if (b[i].getText().length() == 0) {
|
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);
|
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);
|
System.out.println(response);
|
||||||
if (response == 0) {
|
if (response == 0) {
|
||||||
|
//Der Wert Null wird übernommen
|
||||||
spalten = spalten + " Null";
|
spalten = spalten + " Null";
|
||||||
sname = sname + rm.getColumnName(i + 1);
|
sname = sname + rm.getColumnName(i + 1);
|
||||||
} else {
|
} else {
|
||||||
einf.setAction(null);
|
//Der Wert Null wird nicht übernommen
|
||||||
|
spalten ="";
|
||||||
|
sname="";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
//Um dem SQL-Syntax gerecht zu werden hat der letzte Wert kein ','
|
||||||
spalten = spalten + "'" + b[i].getText() + "'";
|
spalten = spalten + "'" + b[i].getText() + "'";
|
||||||
sname = sname + rm.getColumnName(i + 1);
|
sname = sname + rm.getColumnName(i + 1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
//Liefert das Textfeld Text bzw Werte, dann werden Strings gefült
|
||||||
spalten = spalten + "'" + b[i].getText() + "',";
|
spalten = spalten + "'" + b[i].getText() + "',";
|
||||||
sname = sname + rm.getColumnName(i + 1) + ",";
|
sname = sname + rm.getColumnName(i + 1) + ",";
|
||||||
}
|
}
|
||||||
@ -90,12 +99,20 @@ public class Hinzufügen extends Dialog implements ActionListener {
|
|||||||
String sql = "Insert into " + tab + "(" + sname + ") Values (" + spalten + ")";
|
String sql = "Insert into " + tab + "(" + sname + ") Values (" + spalten + ")";
|
||||||
System.out.println(sql);
|
System.out.println(sql);
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
|
|
||||||
|
//Der Eintrag wird in die Datenbank eingefügt
|
||||||
try {
|
try {
|
||||||
conn = DriverManager.getConnection(url, "root", "");
|
conn = DriverManager.getConnection(url, "root", "");
|
||||||
Statement s = conn.createStatement();
|
Statement s = conn.createStatement();
|
||||||
ResultSet a = s.executeQuery(sql);
|
ResultSet a = s.executeQuery(sql);
|
||||||
this.dispose();
|
this.dispose();
|
||||||
|
//Der eingefügte Datensatz wird angezeigt
|
||||||
|
Einzelansicht.r.last();
|
||||||
|
Einzelansicht.standart(Einzelansicht.r.getRow() + 1);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
|
JOptionPane.showMessageDialog(null, "Da hat etwas nicht geklappt", "Fehler!", JOptionPane.ERROR_MESSAGE);
|
||||||
|
sname = "";
|
||||||
|
spalten = "";
|
||||||
throw new RuntimeException(ex);
|
throw new RuntimeException(ex);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -103,6 +120,7 @@ public class Hinzufügen extends Dialog implements ActionListener {
|
|||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,15 +10,25 @@ public class Löschen {
|
|||||||
|
|
||||||
public Löschen(String tab, DefaultTableModel model, JTable table) {
|
public Löschen(String tab, DefaultTableModel model, JTable table) {
|
||||||
|
|
||||||
|
//Bestätigung des Users
|
||||||
int response = JOptionPane.showConfirmDialog(null, "Wollen Sie dein Eintrag löschen?", "Bestätigen", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
int response = JOptionPane.showConfirmDialog(null, "Wollen Sie dein Eintrag löschen?", "Bestätigen", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
||||||
if (response == 0) {
|
if (response == 0) {
|
||||||
try (Connection conn = DriverManager.getConnection(url, "root", "")) {
|
try (Connection conn = DriverManager.getConnection(url, "root", "")) {
|
||||||
Statement s = conn.createStatement();
|
Statement s = conn.createStatement();
|
||||||
|
|
||||||
|
//Backup erstellen und Datensatz löschen
|
||||||
//SELECT *, CURRENT_TIMESTAMP FROM spiel WHERE spiel.Heim =1 or spiel.Gast =1 AND spiel.Spiel_ID NOT IN (SELECT b.Spiel_ID FROM bundesliga_archiv.spiel as b);
|
//SELECT *, CURRENT_TIMESTAMP FROM spiel WHERE spiel.Heim =1 or spiel.Gast =1 AND spiel.Spiel_ID NOT IN (SELECT b.Spiel_ID FROM bundesliga_archiv.spiel as b);
|
||||||
ResultSet r = s.executeQuery("INSERT into bundesliga_archiv.verein SELECT * ,CURRENT_TIMESTAMP FROM `verein` WHERE V_ID = " + Einzelansicht.vid);
|
ResultSet r = s.executeQuery("INSERT into bundesliga_archiv.verein SELECT * ,CURRENT_TIMESTAMP FROM `verein` WHERE V_ID = " + Einzelansicht.vid);
|
||||||
r = s.executeQuery("DELETE From " + tab + " WHERE " + model.getColumnName(0) + "=" + Einzelansicht.vid);
|
r = s.executeQuery("DELETE From " + tab + " WHERE " + model.getColumnName(0) + "=" + Einzelansicht.vid);
|
||||||
|
|
||||||
Einzelansicht.r.next();
|
//In den vorherigen oder nächsten Datensatz wechseln
|
||||||
|
if (Einzelansicht.r.previous()) {
|
||||||
|
Einzelansicht.standart(Einzelansicht.r.getRow());
|
||||||
|
} else if (Einzelansicht.r.next()) {
|
||||||
|
Einzelansicht.standart(Einzelansicht.r.getRow());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ public class Menü extends JFrame implements ActionListener {
|
|||||||
JList list = null;
|
JList list = null;
|
||||||
String url = "jdbc:mariadb://127.0.0.1:3306/bundesliga";
|
String url = "jdbc:mariadb://127.0.0.1:3306/bundesliga";
|
||||||
String table = null;
|
String table = null;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Menü m = new Menü();
|
Menü m = new Menü();
|
||||||
m.setVisible(true);
|
m.setVisible(true);
|
||||||
@ -25,7 +26,7 @@ public class Menü extends JFrame implements ActionListener {
|
|||||||
JLabel lbl = new JLabel("");
|
JLabel lbl = new JLabel("");
|
||||||
ImageIcon img = new ImageIcon(new ImageIcon(Menü.class.getResource("/image/Bundesiga.jfif")).getImage());
|
ImageIcon img = new ImageIcon(new ImageIcon(Menü.class.getResource("/image/Bundesiga.jfif")).getImage());
|
||||||
lbl.setIcon(img);
|
lbl.setIcon(img);
|
||||||
lbl.setBounds(150, 50, 200,202);
|
lbl.setBounds(150, 50, 200, 202);
|
||||||
this.getContentPane().add(lbl);
|
this.getContentPane().add(lbl);
|
||||||
this.add(lbl);
|
this.add(lbl);
|
||||||
|
|
||||||
@ -69,7 +70,7 @@ public class Menü extends JFrame implements ActionListener {
|
|||||||
DefaultListModel liste = new DefaultListModel();
|
DefaultListModel liste = new DefaultListModel();
|
||||||
list = new JList(liste);
|
list = new JList(liste);
|
||||||
list.addListSelectionListener(e -> {
|
list.addListSelectionListener(e -> {
|
||||||
if (list.getSelectedValue().toString().equalsIgnoreCase("Verein") || list.getSelectedValue().toString().equalsIgnoreCase("spieler")) {
|
if (list.getSelectedValue().toString().equalsIgnoreCase("Verein")) {
|
||||||
this.add(v);
|
this.add(v);
|
||||||
|
|
||||||
} else
|
} else
|
||||||
|
@ -15,8 +15,6 @@ public class Suchen {
|
|||||||
static JList list;
|
static JList list;
|
||||||
static JScrollPane sc;
|
static JScrollPane sc;
|
||||||
static int index = 0;
|
static int index = 0;
|
||||||
static boolean auswahl = false;
|
|
||||||
static boolean fertig = false;
|
|
||||||
|
|
||||||
|
|
||||||
public static ResultSet search(String st, ResultSet rs) {
|
public static ResultSet search(String st, ResultSet rs) {
|
||||||
@ -48,14 +46,17 @@ public class Suchen {
|
|||||||
liste.addElement(r.getString("Name"));
|
liste.addElement(r.getString("Name"));
|
||||||
}
|
}
|
||||||
r.first();
|
r.first();
|
||||||
frame = new JFrame("Suchergebnis");
|
System.out.println(liste.getSize());
|
||||||
frame.setSize(300, 300);
|
if (liste.getSize() > 1) {
|
||||||
frame.setVisible(true);
|
frame = new JFrame("Suchergebnis");
|
||||||
|
frame.setSize(300, 300);
|
||||||
|
frame.setVisible(true);
|
||||||
|
|
||||||
sc = new JScrollPane();
|
sc = new JScrollPane();
|
||||||
sc.setViewportView(list);
|
sc.setViewportView(list);
|
||||||
sc.setBounds(30, 100, 150, 200);
|
sc.setBounds(30, 100, 150, 200);
|
||||||
frame.add(sc);
|
frame.add(sc);
|
||||||
|
}
|
||||||
|
|
||||||
//Auswahl durch Doppelklick
|
//Auswahl durch Doppelklick
|
||||||
list.addMouseListener(new MouseAdapter() {
|
list.addMouseListener(new MouseAdapter() {
|
||||||
@ -73,7 +74,8 @@ public class Suchen {
|
|||||||
System.out.println("index =" + index);
|
System.out.println("index =" + index);
|
||||||
Einzelansicht.einfügen(r);
|
Einzelansicht.einfügen(r);
|
||||||
Einzelansicht.r = r;
|
Einzelansicht.r = r;
|
||||||
auswahl = true;
|
|
||||||
|
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
throw new RuntimeException(ex);
|
throw new RuntimeException(ex);
|
||||||
}
|
}
|
||||||
@ -83,7 +85,6 @@ public class Suchen {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
System.out.println(auswahl);
|
|
||||||
return r;
|
return r;
|
||||||
} else {
|
} else {
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user