This commit is contained in:
Paul Köster 2023-03-15 14:10:33 +01:00
parent 9e6ae9604a
commit c5a033403b
3 changed files with 22 additions and 46 deletions

View File

@ -14,9 +14,8 @@ public class Datail {
} }
public static DefaultTableModel detailmodel(int verein, String url) { public static DefaultTableModel detailmodel(DefaultTableModel t,int verein, String url) {
String[][] temp = {{""}}; String[][] temp = {{""}};
DefaultTableModel t = new DefaultTableModel();
System.out.println("test = "+verein); System.out.println("test = "+verein);
try (Connection conn = DriverManager.getConnection(url, "root", "")) { try (Connection conn = DriverManager.getConnection(url, "root", "")) {

View File

@ -36,10 +36,10 @@ public class Einzelansicht extends JFrame implements TableModelListener, ActionL
JMenu adm = null; JMenu adm = null;
JMenuItem i1, i2, i3, i4, i5, i6, i7; JMenuItem i1, i2, i3, i4, i5, i6, i7;
static JTable detail; static DefaultTableModel dtm = new DefaultTableModel();
static JTable detail = new JTable(dtm);
static JScrollPane dsc; static JScrollPane dsc;
static int vid = 1; static int vid = 1;
static DefaultTableModel dtm = new DefaultTableModel();
public Einzelansicht(String ta) { public Einzelansicht(String ta) {
@ -73,6 +73,9 @@ public class Einzelansicht extends JFrame implements TableModelListener, ActionL
i4 = new JMenuItem("Suchen"); i4 = new JMenuItem("Suchen");
i4.addActionListener(e -> { i4.addActionListener(e -> {
s.setText(JOptionPane.showInputDialog("Wonach wollen Sie suchen?")); s.setText(JOptionPane.showInputDialog("Wonach wollen Sie suchen?"));
r = Suchen.search(s.getText(), r);
s.setText("");
einfügen(r);
}); });
i5 = new JMenuItem("Einfügen"); i5 = new JMenuItem("Einfügen");
@ -102,12 +105,11 @@ public class Einzelansicht extends JFrame implements TableModelListener, ActionL
try (Connection conn = DriverManager.getConnection(url, "root", "")) { try (Connection conn = DriverManager.getConnection(url, "root", "")) {
Statement s = conn.createStatement(); Statement s = conn.createStatement();
r = s.executeQuery("Select * FROM " + tab);
rm = r.getMetaData();
sql = "Select * From " + tab; sql = "Select * From " + tab;
r = s.executeQuery(sql);
rm = r.getMetaData();
r.first(); r.first();
einfügen(r); einfügen(r);
detailtab(vid);
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
@ -176,7 +178,7 @@ public class Einzelansicht extends JFrame implements TableModelListener, ActionL
t.addTableModelListener(this); t.addTableModelListener(this);
detail = new JTable(dtm);
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);
@ -206,9 +208,10 @@ public class Einzelansicht extends JFrame implements TableModelListener, ActionL
} }
t.addRow(rows); t.addRow(rows);
t.fireTableDataChanged(); t.fireTableDataChanged();
vid = r.getInt(1); vid = r.getInt(1);
detailtab(vid); detailtab(vid);
dtm.fireTableDataChanged();
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
@ -222,16 +225,9 @@ public class Einzelansicht extends JFrame implements TableModelListener, ActionL
@Override @Override
public void keyTyped(KeyEvent e) { public void keyTyped(KeyEvent e) {
if (e.getKeyChar() == KeyEvent.VK_ENTER) { if (e.getKeyChar() == KeyEvent.VK_ENTER) {
try {
r = Suchen.search(s.getText(), r); r = Suchen.search(s.getText(), r);
s.setText(""); s.setText("");
einfügen(r); einfügen(r);
vid = r.getInt("V_ID");
detailtab(vid);
} catch (SQLException ex) {
throw new RuntimeException(ex);
}
} }
} }
@ -317,26 +313,7 @@ public class Einzelansicht extends JFrame implements TableModelListener, ActionL
case "änd": case "änd":
break; break;
case "lösch": case "lösch":
System.out.println(t.getValueAt(0, 0)); Löschen l = new Löschen(tab,t,table);
String wh = t.getValueAt(0, 0).toString();
int response = JOptionPane.showConfirmDialog(null, "Wollen Sie den Eintrag löschen?", "Bestätigen", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (response == 0) {
try (Connection conn = DriverManager.getConnection(url, "root", "")) {
Statement s = conn.createStatement();
ResultSet r = s.executeQuery("DELETE From " + tab + " WHERE " + t.getColumnName(0) + "=" + wh);
ResultSet r2 = s.executeQuery("Select * from " + tab);
r2.previous();
einfügen(r2);
} catch (SQLException ex) {
throw new RuntimeException(ex);
}
} else {
}
table.clearSelection();
t.removeRow(0);
t.fireTableDataChanged();
break; break;
case "close": case "close":
this.dispose(); this.dispose();
@ -349,11 +326,11 @@ public class Einzelansicht extends JFrame implements TableModelListener, ActionL
} }
public static void detailtab(int vid) { public static void detailtab(int vid) {
dtm = Datail.detailmodel(vid, url); Datail.detailmodel(dtm, vid, url);
dtm.fireTableDataChanged(); dtm.fireTableDataChanged();
System.out.println("detail ="+vid); System.out.println("detail =" + vid);
} }

View File

@ -9,19 +9,19 @@ public class Löschen {
String url = "jdbc:mariadb://127.0.0.1:3306/bundesliga"; String url = "jdbc:mariadb://127.0.0.1:3306/bundesliga";
public Löschen(String tab, DefaultTableModel model, JTable table) { public Löschen(String tab, DefaultTableModel model, JTable table) {
int zeile = table.getSelectedRow();
String wh = model.getValueAt(zeile, 0).toString(); 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 in Zeile " + (zeile+1) + " 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();
ResultSet r = s.executeQuery("DELETE From " + tab + " WHERE " + model.getColumnName(0) + "=" + wh); 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);
Einzelansicht.r.next();
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
Tabellen.einfügen(tab);
} else { } else {
} }