Gruppe I: Benutzeroberfläche hinzugefuegt
parent
3c0f1cee07
commit
0968eea111
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,227 @@
|
|||
package ui;
|
||||
|
||||
import belegworkflow.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.*;
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DokumentePanel extends JPanel {
|
||||
|
||||
private BelegworkflowService service;
|
||||
private JTable tabelle;
|
||||
private DefaultTableModel tabellenModell;
|
||||
|
||||
public DokumentePanel() {
|
||||
try { service = new BelegworkflowService(); }
|
||||
catch (IOException e) { e.printStackTrace(); }
|
||||
|
||||
setLayout(new BorderLayout(10, 10));
|
||||
setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));
|
||||
setBackground(new Color(244, 247, 255));
|
||||
|
||||
add(erstelleKopf(), BorderLayout.NORTH);
|
||||
add(erstelleTabelle(), BorderLayout.CENTER);
|
||||
add(erstelleAktionen(), BorderLayout.SOUTH);
|
||||
}
|
||||
|
||||
private JPanel erstelleKopf() {
|
||||
JPanel kopf = new JPanel(new BorderLayout());
|
||||
kopf.setBackground(new Color(244, 247, 255));
|
||||
|
||||
JLabel titel = new JLabel("Dokumentenübersicht");
|
||||
titel.setFont(new Font("Cambria", Font.BOLD, 20));
|
||||
titel.setForeground(new Color(30, 39, 97));
|
||||
kopf.add(titel, BorderLayout.WEST);
|
||||
|
||||
JButton refresh = erstelleButton("Aktualisieren", new Color(74, 144, 217));
|
||||
refresh.addActionListener(e -> ladeDokumente());
|
||||
JPanel rechts = new JPanel(new FlowLayout(FlowLayout.RIGHT));
|
||||
rechts.setBackground(new Color(244, 247, 255));
|
||||
rechts.add(refresh);
|
||||
kopf.add(rechts, BorderLayout.EAST);
|
||||
return kopf;
|
||||
}
|
||||
|
||||
private JScrollPane erstelleTabelle() {
|
||||
String[] spalten = {"Belegnummer", "Typ", "Kunde", "Datum", "Status", "Brutto"};
|
||||
tabellenModell = new DefaultTableModel(spalten, 0) {
|
||||
public boolean isCellEditable(int r, int c) { return false; }
|
||||
};
|
||||
tabelle = new JTable(tabellenModell);
|
||||
tabelle.setRowHeight(28);
|
||||
tabelle.setFont(new Font("Calibri", Font.PLAIN, 13));
|
||||
tabelle.getTableHeader().setFont(new Font("Calibri", Font.BOLD, 13));
|
||||
tabelle.getTableHeader().setBackground(new Color(30, 39, 97));
|
||||
tabelle.getTableHeader().setForeground(Color.WHITE);
|
||||
tabelle.setSelectionBackground(new Color(202, 220, 252));
|
||||
tabelle.setGridColor(new Color(209, 217, 240));
|
||||
ladeDokumente();
|
||||
return new JScrollPane(tabelle);
|
||||
}
|
||||
|
||||
private JPanel erstelleAktionen() {
|
||||
JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 10));
|
||||
panel.setBackground(Color.WHITE);
|
||||
panel.setBorder(BorderFactory.createCompoundBorder(
|
||||
BorderFactory.createLineBorder(new Color(202, 220, 252)),
|
||||
BorderFactory.createEmptyBorder(10, 10, 10, 10)
|
||||
));
|
||||
|
||||
JLabel aktLabel = new JLabel("Aktionen: ");
|
||||
aktLabel.setFont(new Font("Calibri", Font.BOLD, 13));
|
||||
panel.add(aktLabel);
|
||||
|
||||
JButton angebotBtn = erstelleButton("Neues Angebot", new Color(30, 39, 97));
|
||||
angebotBtn.addActionListener(e -> neuesAngebotDialog());
|
||||
panel.add(angebotBtn);
|
||||
|
||||
JButton rechnungBtn = erstelleButton("Rechnung aus Angebot", new Color(74, 144, 217));
|
||||
rechnungBtn.addActionListener(e -> rechnungAusAngebotDialog());
|
||||
panel.add(rechnungBtn);
|
||||
|
||||
JButton festschreibenBtn = erstelleButton("Rechnung festschreiben", new Color(100, 100, 100));
|
||||
festschreibenBtn.addActionListener(e -> rechnungFestschreibenDialog());
|
||||
panel.add(festschreibenBtn);
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
private void neuesAngebotDialog() {
|
||||
JDialog dialog = new JDialog((Frame) SwingUtilities.getWindowAncestor(this),
|
||||
"Neues Angebot erstellen", true);
|
||||
dialog.setSize(400, 300);
|
||||
dialog.setLocationRelativeTo(this);
|
||||
dialog.setLayout(new BorderLayout(10, 10));
|
||||
|
||||
JPanel form = new JPanel(new GridLayout(0, 2, 5, 5));
|
||||
form.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));
|
||||
|
||||
form.add(new JLabel("Kunden-ID:"));
|
||||
JTextField kundenIdField = new JTextField();
|
||||
form.add(kundenIdField);
|
||||
|
||||
form.add(new JLabel("Produkt-ID:"));
|
||||
JTextField produktIdField = new JTextField();
|
||||
form.add(produktIdField);
|
||||
|
||||
form.add(new JLabel("Menge:"));
|
||||
JTextField mengeField = new JTextField("1");
|
||||
form.add(mengeField);
|
||||
|
||||
form.add(new JLabel("Gueltig bis (YYYY-MM-DD):"));
|
||||
JTextField gueltigBisField = new JTextField(
|
||||
LocalDate.now().plusDays(30).toString());
|
||||
form.add(gueltigBisField);
|
||||
|
||||
dialog.add(form, BorderLayout.CENTER);
|
||||
|
||||
JButton erstellenBtn = erstelleButton("Angebot erstellen", new Color(30, 39, 97));
|
||||
erstellenBtn.addActionListener(e -> {
|
||||
try {
|
||||
bestandsmanagement.ProduktServiceImpl ps =
|
||||
new bestandsmanagement.ProduktServiceImpl();
|
||||
bestandsmanagement.Produkt produkt =
|
||||
ps.findeProdukt(produktIdField.getText());
|
||||
if (produkt == null) {
|
||||
JOptionPane.showMessageDialog(dialog, "Produkt nicht gefunden.");
|
||||
return;
|
||||
}
|
||||
int menge = Integer.parseInt(mengeField.getText().trim());
|
||||
List<Dokumentposition> positionen = new ArrayList<>();
|
||||
positionen.add(new Dokumentposition(
|
||||
produkt.getProduktId(), produkt.getBezeichnung(),
|
||||
menge, produkt.getNettoEinzelpreis(), produkt.getMehrwertsteuersatz()
|
||||
));
|
||||
Angebot a = service.erstelleAngebot(kundenIdField.getText(),
|
||||
positionen, LocalDate.parse(gueltigBisField.getText()));
|
||||
if (a != null) {
|
||||
JOptionPane.showMessageDialog(dialog,
|
||||
"Angebot wurde erfolgreich erstellt: " + a.getBelegnummer(),
|
||||
"Erfolg", JOptionPane.INFORMATION_MESSAGE);
|
||||
ladeDokumente();
|
||||
dialog.dispose();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
JOptionPane.showMessageDialog(dialog,
|
||||
"Fehler: " + ex.getMessage(), "Fehler", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
});
|
||||
|
||||
JPanel btnPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
|
||||
btnPanel.add(erstellenBtn);
|
||||
btnPanel.add(erstelleButton("Abbrechen", Color.GRAY));
|
||||
dialog.add(btnPanel, BorderLayout.SOUTH);
|
||||
dialog.setVisible(true);
|
||||
}
|
||||
|
||||
private void rechnungAusAngebotDialog() {
|
||||
String angebotsNr = JOptionPane.showInputDialog(this,
|
||||
"Angebotsnummer eingeben:", "Rechnung aus Angebot",
|
||||
JOptionPane.QUESTION_MESSAGE);
|
||||
if (angebotsNr == null || angebotsNr.isBlank()) return;
|
||||
|
||||
Rechnung r = service.erstelleRechnungAusAngebot(
|
||||
angebotsNr, LocalDate.now(), LocalDate.now(),
|
||||
LocalDate.now().plusDays(14));
|
||||
|
||||
if (r != null) {
|
||||
JOptionPane.showMessageDialog(this,
|
||||
"Rechnung wurde erfolgreich erzeugt: " + r.getBelegnummer(),
|
||||
"Erfolg", JOptionPane.INFORMATION_MESSAGE);
|
||||
ladeDokumente();
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(this,
|
||||
"Rechnung konnte nicht erstellt werden.",
|
||||
"Fehler", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
private void rechnungFestschreibenDialog() {
|
||||
String rechnungsNr = JOptionPane.showInputDialog(this,
|
||||
"Rechnungsnummer eingeben:", "Rechnung festschreiben",
|
||||
JOptionPane.QUESTION_MESSAGE);
|
||||
if (rechnungsNr == null || rechnungsNr.isBlank()) return;
|
||||
service.finalisiereRechnung(rechnungsNr);
|
||||
ladeDokumente();
|
||||
JOptionPane.showMessageDialog(this,
|
||||
"Rechnung wurde festgeschrieben.",
|
||||
"Erfolg", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
|
||||
private JButton erstelleButton(String text, Color farbe) {
|
||||
JButton btn = new JButton(text);
|
||||
btn.setBackground(farbe);
|
||||
btn.setForeground(Color.WHITE);
|
||||
btn.setFocusPainted(false);
|
||||
btn.setBorderPainted(false);
|
||||
btn.setFont(new Font("Calibri", Font.BOLD, 12));
|
||||
btn.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
return btn;
|
||||
}
|
||||
|
||||
private void ladeDokumente() {
|
||||
tabellenModell.setRowCount(0);
|
||||
if (service == null) return;
|
||||
|
||||
for (Angebot a : service.alleAngebote()) {
|
||||
tabellenModell.addRow(new Object[]{
|
||||
a.getBelegnummer(), "Angebot",
|
||||
a.getKundenReferenz(), a.getDatum(),
|
||||
a.getStatus(), String.format("%.2f EUR", a.getSummeBrutto())
|
||||
});
|
||||
}
|
||||
for (Rechnung r : service.alleRechnungen()) {
|
||||
tabellenModell.addRow(new Object[]{
|
||||
r.getBelegnummer(), "Rechnung",
|
||||
r.getKundenReferenz(), r.getDatum(),
|
||||
r.isFestgeschrieben() ? "FESTGESCHRIEBEN" : r.getStatus(),
|
||||
String.format("%.2f EUR", r.getSummeBrutto())
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,175 @@
|
|||
package ui;
|
||||
|
||||
import kundenverwaltung.Kunde;
|
||||
import kundenverwaltung.KundenServiceImpl;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.*;
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class KundenPanel extends JPanel {
|
||||
|
||||
private KundenServiceImpl service;
|
||||
private JTable tabelle;
|
||||
private DefaultTableModel tabellenModell;
|
||||
private JTextField suchfeld;
|
||||
|
||||
public KundenPanel() {
|
||||
try { service = new KundenServiceImpl(); }
|
||||
catch (IOException e) { e.printStackTrace(); }
|
||||
|
||||
setLayout(new BorderLayout(10, 10));
|
||||
setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));
|
||||
setBackground(new Color(244, 247, 255));
|
||||
|
||||
add(erstelleKopf(), BorderLayout.NORTH);
|
||||
add(erstelleTabelle(), BorderLayout.CENTER);
|
||||
add(erstelleFormular(), BorderLayout.EAST);
|
||||
}
|
||||
|
||||
private JPanel erstelleKopf() {
|
||||
JPanel kopf = new JPanel(new BorderLayout());
|
||||
kopf.setBackground(new Color(244, 247, 255));
|
||||
|
||||
JLabel titel = new JLabel("Kundenverwaltung");
|
||||
titel.setFont(new Font("Cambria", Font.BOLD, 20));
|
||||
titel.setForeground(new Color(30, 39, 97));
|
||||
kopf.add(titel, BorderLayout.WEST);
|
||||
|
||||
JPanel suchPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
|
||||
suchPanel.setBackground(new Color(244, 247, 255));
|
||||
suchfeld = new JTextField(15);
|
||||
JButton suchenBtn = erstelleButton("Suchen", new Color(74, 144, 217));
|
||||
suchenBtn.addActionListener(e -> sucheKunden());
|
||||
JButton alleBtn = erstelleButton("Alle anzeigen", new Color(30, 39, 97));
|
||||
alleBtn.addActionListener(e -> ladeKunden());
|
||||
suchPanel.add(new JLabel("Suche: "));
|
||||
suchPanel.add(suchfeld);
|
||||
suchPanel.add(suchenBtn);
|
||||
suchPanel.add(alleBtn);
|
||||
kopf.add(suchPanel, BorderLayout.EAST);
|
||||
return kopf;
|
||||
}
|
||||
|
||||
private JScrollPane erstelleTabelle() {
|
||||
String[] spalten = {"Kunden-ID", "Name", "PLZ", "Ort", "E-Mail", "Telefon"};
|
||||
tabellenModell = new DefaultTableModel(spalten, 0) {
|
||||
public boolean isCellEditable(int r, int c) { return false; }
|
||||
};
|
||||
tabelle = new JTable(tabellenModell);
|
||||
tabelle.setRowHeight(28);
|
||||
tabelle.setFont(new Font("Calibri", Font.PLAIN, 13));
|
||||
tabelle.getTableHeader().setFont(new Font("Calibri", Font.BOLD, 13));
|
||||
tabelle.getTableHeader().setBackground(new Color(30, 39, 97));
|
||||
tabelle.getTableHeader().setForeground(Color.WHITE);
|
||||
tabelle.setSelectionBackground(new Color(202, 220, 252));
|
||||
tabelle.setGridColor(new Color(209, 217, 240));
|
||||
ladeKunden();
|
||||
return new JScrollPane(tabelle);
|
||||
}
|
||||
|
||||
private JPanel erstelleFormular() {
|
||||
JPanel form = new JPanel();
|
||||
form.setLayout(new BoxLayout(form, BoxLayout.Y_AXIS));
|
||||
form.setBackground(Color.WHITE);
|
||||
form.setBorder(BorderFactory.createCompoundBorder(
|
||||
BorderFactory.createLineBorder(new Color(202, 220, 252)),
|
||||
BorderFactory.createEmptyBorder(15, 15, 15, 15)
|
||||
));
|
||||
form.setPreferredSize(new Dimension(280, 0));
|
||||
|
||||
JLabel formTitel = new JLabel("Neuen Kunden anlegen");
|
||||
formTitel.setFont(new Font("Cambria", Font.BOLD, 14));
|
||||
formTitel.setForeground(new Color(30, 39, 97));
|
||||
formTitel.setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||
form.add(formTitel);
|
||||
form.add(Box.createVerticalStrut(15));
|
||||
|
||||
JTextField nameField = erstelleFeld(form, "Name / Firmenname *");
|
||||
JTextField strasseField = erstelleFeld(form, "Strasse *");
|
||||
JTextField plzField = erstelleFeld(form, "PLZ *");
|
||||
JTextField ortField = erstelleFeld(form, "Ort *");
|
||||
JTextField steuerField = erstelleFeld(form, "Steuernummer *");
|
||||
JTextField emailField = erstelleFeld(form, "E-Mail *");
|
||||
JTextField telefonField = erstelleFeld(form, "Telefon *");
|
||||
|
||||
form.add(Box.createVerticalStrut(15));
|
||||
|
||||
JButton speichernBtn = erstelleButton("Speichern", new Color(30, 39, 97));
|
||||
speichernBtn.setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||
speichernBtn.setMaximumSize(new Dimension(Integer.MAX_VALUE, 35));
|
||||
speichernBtn.addActionListener(e -> {
|
||||
if (nameField.getText().isBlank() || strasseField.getText().isBlank() ||
|
||||
plzField.getText().isBlank() || ortField.getText().isBlank() ||
|
||||
steuerField.getText().isBlank() || emailField.getText().isBlank() ||
|
||||
telefonField.getText().isBlank()) {
|
||||
JOptionPane.showMessageDialog(this,
|
||||
"Bitte füllen Sie alle Pflichtfelder aus.",
|
||||
"Pflichtfeld fehlt", JOptionPane.WARNING_MESSAGE);
|
||||
return;
|
||||
}
|
||||
service.kundeAnlegen(nameField.getText(), strasseField.getText(),
|
||||
plzField.getText(), ortField.getText(), steuerField.getText(),
|
||||
emailField.getText(), telefonField.getText());
|
||||
nameField.setText(""); strasseField.setText(""); plzField.setText("");
|
||||
ortField.setText(""); steuerField.setText(""); emailField.setText("");
|
||||
telefonField.setText("");
|
||||
ladeKunden();
|
||||
JOptionPane.showMessageDialog(this, "Kunde wurde erfolgreich gespeichert.",
|
||||
"Erfolg", JOptionPane.INFORMATION_MESSAGE);
|
||||
});
|
||||
form.add(speichernBtn);
|
||||
return form;
|
||||
}
|
||||
|
||||
private JTextField erstelleFeld(JPanel panel, String label) {
|
||||
JLabel lbl = new JLabel(label);
|
||||
lbl.setFont(new Font("Calibri", Font.PLAIN, 12));
|
||||
lbl.setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||
panel.add(lbl);
|
||||
panel.add(Box.createVerticalStrut(3));
|
||||
JTextField feld = new JTextField();
|
||||
feld.setMaximumSize(new Dimension(Integer.MAX_VALUE, 30));
|
||||
feld.setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||
panel.add(feld);
|
||||
panel.add(Box.createVerticalStrut(8));
|
||||
return feld;
|
||||
}
|
||||
|
||||
private JButton erstelleButton(String text, Color farbe) {
|
||||
JButton btn = new JButton(text);
|
||||
btn.setBackground(farbe);
|
||||
btn.setForeground(Color.WHITE);
|
||||
btn.setFocusPainted(false);
|
||||
btn.setBorderPainted(false);
|
||||
btn.setFont(new Font("Calibri", Font.BOLD, 12));
|
||||
btn.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
return btn;
|
||||
}
|
||||
|
||||
private void ladeKunden() {
|
||||
tabellenModell.setRowCount(0);
|
||||
if (service == null) return;
|
||||
List<Kunde> kunden = service.alleKunden();
|
||||
for (Kunde k : kunden) {
|
||||
tabellenModell.addRow(new Object[]{
|
||||
k.getKundenId(), k.getName(), k.getPlz(),
|
||||
k.getOrt(), k.getEmail(), k.getTelefon()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void sucheKunden() {
|
||||
tabellenModell.setRowCount(0);
|
||||
if (service == null) return;
|
||||
List<Kunde> kunden = service.sucheNachName(suchfeld.getText());
|
||||
for (Kunde k : kunden) {
|
||||
tabellenModell.addRow(new Object[]{
|
||||
k.getKundenId(), k.getName(), k.getPlz(),
|
||||
k.getOrt(), k.getEmail(), k.getTelefon()
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
package ui;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class MainWindow extends JFrame {
|
||||
|
||||
private JPanel contentPanel;
|
||||
private KundenPanel kundenPanel;
|
||||
private ProduktPanel produktPanel;
|
||||
private DokumentePanel dokumentePanel;
|
||||
|
||||
public MainWindow() {
|
||||
setTitle("Fakturierungsanwendung – Team 3");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setSize(1000, 650);
|
||||
setLocationRelativeTo(null);
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
// Navigation oben
|
||||
add(erstelleNavigation(), BorderLayout.NORTH);
|
||||
|
||||
// Content Bereich
|
||||
contentPanel = new JPanel(new CardLayout());
|
||||
kundenPanel = new KundenPanel();
|
||||
produktPanel = new ProduktPanel();
|
||||
dokumentePanel = new DokumentePanel();
|
||||
|
||||
contentPanel.add(kundenPanel, "KUNDEN");
|
||||
contentPanel.add(produktPanel, "PRODUKTE");
|
||||
contentPanel.add(dokumentePanel, "DOKUMENTE");
|
||||
|
||||
add(contentPanel, BorderLayout.CENTER);
|
||||
|
||||
// Statusleiste unten
|
||||
JLabel status = new JLabel(" Fakturierungsanwendung | Team 3 | Gruppe J, K, L, I");
|
||||
status.setBorder(BorderFactory.createEtchedBorder());
|
||||
status.setFont(new Font("Calibri", Font.PLAIN, 11));
|
||||
status.setForeground(Color.GRAY);
|
||||
add(status, BorderLayout.SOUTH);
|
||||
|
||||
zeigePanel("KUNDEN");
|
||||
}
|
||||
|
||||
private JPanel erstelleNavigation() {
|
||||
JPanel nav = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
|
||||
nav.setBackground(new Color(30, 39, 97));
|
||||
nav.setBorder(BorderFactory.createEmptyBorder(8, 10, 8, 10));
|
||||
|
||||
JLabel logo = new JLabel(" Fakturierung ");
|
||||
logo.setFont(new Font("Cambria", Font.BOLD, 16));
|
||||
logo.setForeground(Color.WHITE);
|
||||
nav.add(logo);
|
||||
|
||||
nav.add(Box.createHorizontalStrut(20));
|
||||
nav.add(erstelleNavButton("Kunden", "KUNDEN"));
|
||||
nav.add(erstelleNavButton("Produkte", "PRODUKTE"));
|
||||
nav.add(erstelleNavButton("Dokumente", "DOKUMENTE"));
|
||||
|
||||
return nav;
|
||||
}
|
||||
|
||||
private JButton erstelleNavButton(String text, String panel) {
|
||||
JButton btn = new JButton(text);
|
||||
btn.setFont(new Font("Calibri", Font.PLAIN, 13));
|
||||
btn.setForeground(Color.WHITE);
|
||||
btn.setBackground(new Color(30, 39, 97));
|
||||
btn.setBorderPainted(false);
|
||||
btn.setFocusPainted(false);
|
||||
btn.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
btn.setBorder(BorderFactory.createEmptyBorder(5, 15, 5, 15));
|
||||
|
||||
btn.addMouseListener(new java.awt.event.MouseAdapter() {
|
||||
public void mouseEntered(java.awt.event.MouseEvent e) {
|
||||
btn.setBackground(new Color(74, 144, 217));
|
||||
}
|
||||
public void mouseExited(java.awt.event.MouseEvent e) {
|
||||
btn.setBackground(new Color(30, 39, 97));
|
||||
}
|
||||
});
|
||||
|
||||
btn.addActionListener(e -> zeigePanel(panel));
|
||||
return btn;
|
||||
}
|
||||
|
||||
private void zeigePanel(String name) {
|
||||
CardLayout cl = (CardLayout) contentPanel.getLayout();
|
||||
cl.show(contentPanel, name);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
try {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
} catch (Exception ignored) {}
|
||||
new MainWindow().setVisible(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,186 @@
|
|||
package ui;
|
||||
|
||||
import bestandsmanagement.Produkt;
|
||||
import bestandsmanagement.ProduktServiceImpl;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.*;
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
public class ProduktPanel extends JPanel {
|
||||
|
||||
private ProduktServiceImpl service;
|
||||
private JTable tabelle;
|
||||
private DefaultTableModel tabellenModell;
|
||||
private JTextField suchfeld;
|
||||
|
||||
public ProduktPanel() {
|
||||
try { service = new ProduktServiceImpl(); }
|
||||
catch (IOException e) { e.printStackTrace(); }
|
||||
|
||||
setLayout(new BorderLayout(10, 10));
|
||||
setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));
|
||||
setBackground(new Color(244, 247, 255));
|
||||
|
||||
add(erstelleKopf(), BorderLayout.NORTH);
|
||||
add(erstelleTabelle(), BorderLayout.CENTER);
|
||||
add(erstelleFormular(), BorderLayout.EAST);
|
||||
}
|
||||
|
||||
private JPanel erstelleKopf() {
|
||||
JPanel kopf = new JPanel(new BorderLayout());
|
||||
kopf.setBackground(new Color(244, 247, 255));
|
||||
|
||||
JLabel titel = new JLabel("Bestandsmanagement");
|
||||
titel.setFont(new Font("Cambria", Font.BOLD, 20));
|
||||
titel.setForeground(new Color(30, 39, 97));
|
||||
kopf.add(titel, BorderLayout.WEST);
|
||||
|
||||
JPanel suchPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
|
||||
suchPanel.setBackground(new Color(244, 247, 255));
|
||||
suchfeld = new JTextField(15);
|
||||
JButton suchenBtn = erstelleButton("Suchen", new Color(74, 144, 217));
|
||||
suchenBtn.addActionListener(e -> sucheProdukte());
|
||||
JButton alleBtn = erstelleButton("Alle anzeigen", new Color(30, 39, 97));
|
||||
alleBtn.addActionListener(e -> ladeProdukte());
|
||||
suchPanel.add(new JLabel("Suche: "));
|
||||
suchPanel.add(suchfeld);
|
||||
suchPanel.add(suchenBtn);
|
||||
suchPanel.add(alleBtn);
|
||||
kopf.add(suchPanel, BorderLayout.EAST);
|
||||
return kopf;
|
||||
}
|
||||
|
||||
private JScrollPane erstelleTabelle() {
|
||||
String[] spalten = {"Produkt-ID", "Bezeichnung", "Preis (Netto)", "MwSt", "Bestand", "Status"};
|
||||
tabellenModell = new DefaultTableModel(spalten, 0) {
|
||||
public boolean isCellEditable(int r, int c) { return false; }
|
||||
};
|
||||
tabelle = new JTable(tabellenModell);
|
||||
tabelle.setRowHeight(28);
|
||||
tabelle.setFont(new Font("Calibri", Font.PLAIN, 13));
|
||||
tabelle.getTableHeader().setFont(new Font("Calibri", Font.BOLD, 13));
|
||||
tabelle.getTableHeader().setBackground(new Color(30, 39, 97));
|
||||
tabelle.getTableHeader().setForeground(Color.WHITE);
|
||||
tabelle.setSelectionBackground(new Color(202, 220, 252));
|
||||
tabelle.setGridColor(new Color(209, 217, 240));
|
||||
ladeProdukte();
|
||||
return new JScrollPane(tabelle);
|
||||
}
|
||||
|
||||
private JPanel erstelleFormular() {
|
||||
JPanel form = new JPanel();
|
||||
form.setLayout(new BoxLayout(form, BoxLayout.Y_AXIS));
|
||||
form.setBackground(Color.WHITE);
|
||||
form.setBorder(BorderFactory.createCompoundBorder(
|
||||
BorderFactory.createLineBorder(new Color(202, 220, 252)),
|
||||
BorderFactory.createEmptyBorder(15, 15, 15, 15)
|
||||
));
|
||||
form.setPreferredSize(new Dimension(280, 0));
|
||||
|
||||
JLabel formTitel = new JLabel("Neuen Artikel anlegen");
|
||||
formTitel.setFont(new Font("Cambria", Font.BOLD, 14));
|
||||
formTitel.setForeground(new Color(30, 39, 97));
|
||||
formTitel.setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||
form.add(formTitel);
|
||||
form.add(Box.createVerticalStrut(15));
|
||||
|
||||
JTextField bezeichnungField = erstelleFeld(form, "Bezeichnung *");
|
||||
JTextField preisField = erstelleFeld(form, "Netto-Preis (z.B. 19.99) *");
|
||||
JTextField mwstField = erstelleFeld(form, "MwSt-Satz (z.B. 0.19) *");
|
||||
JTextField bestandField = erstelleFeld(form, "Bestand *");
|
||||
JTextField beschField = erstelleFeld(form, "Beschreibung (optional)");
|
||||
|
||||
form.add(Box.createVerticalStrut(15));
|
||||
|
||||
JButton speichernBtn = erstelleButton("Speichern", new Color(30, 39, 97));
|
||||
speichernBtn.setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||
speichernBtn.setMaximumSize(new Dimension(Integer.MAX_VALUE, 35));
|
||||
speichernBtn.addActionListener(e -> {
|
||||
try {
|
||||
if (bezeichnungField.getText().isBlank() || preisField.getText().isBlank() ||
|
||||
mwstField.getText().isBlank() || bestandField.getText().isBlank()) {
|
||||
JOptionPane.showMessageDialog(this,
|
||||
"Bitte füllen Sie alle Pflichtfelder aus.",
|
||||
"Pflichtfeld fehlt", JOptionPane.WARNING_MESSAGE);
|
||||
return;
|
||||
}
|
||||
BigDecimal preis = new BigDecimal(preisField.getText().replace(",", "."));
|
||||
BigDecimal mwst = new BigDecimal(mwstField.getText().replace(",", "."));
|
||||
int bestand = Integer.parseInt(bestandField.getText().trim());
|
||||
String beschreibung = beschField.getText().isBlank() ? null : beschField.getText();
|
||||
|
||||
service.produktAnlegen(bezeichnungField.getText(), preis, mwst, bestand, beschreibung);
|
||||
bezeichnungField.setText(""); preisField.setText(""); mwstField.setText("");
|
||||
bestandField.setText(""); beschField.setText("");
|
||||
ladeProdukte();
|
||||
JOptionPane.showMessageDialog(this, "Produkt wurde erfolgreich gespeichert.",
|
||||
"Erfolg", JOptionPane.INFORMATION_MESSAGE);
|
||||
} catch (NumberFormatException ex) {
|
||||
JOptionPane.showMessageDialog(this,
|
||||
"Bitte gültige Zahlen für Preis, MwSt und Bestand eingeben.",
|
||||
"Ungültige Eingabe", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
});
|
||||
form.add(speichernBtn);
|
||||
return form;
|
||||
}
|
||||
|
||||
private JTextField erstelleFeld(JPanel panel, String label) {
|
||||
JLabel lbl = new JLabel(label);
|
||||
lbl.setFont(new Font("Calibri", Font.PLAIN, 12));
|
||||
lbl.setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||
panel.add(lbl);
|
||||
panel.add(Box.createVerticalStrut(3));
|
||||
JTextField feld = new JTextField();
|
||||
feld.setMaximumSize(new Dimension(Integer.MAX_VALUE, 30));
|
||||
feld.setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||
panel.add(feld);
|
||||
panel.add(Box.createVerticalStrut(8));
|
||||
return feld;
|
||||
}
|
||||
|
||||
private JButton erstelleButton(String text, Color farbe) {
|
||||
JButton btn = new JButton(text);
|
||||
btn.setBackground(farbe);
|
||||
btn.setForeground(Color.WHITE);
|
||||
btn.setFocusPainted(false);
|
||||
btn.setBorderPainted(false);
|
||||
btn.setFont(new Font("Calibri", Font.BOLD, 12));
|
||||
btn.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
return btn;
|
||||
}
|
||||
|
||||
private void ladeProdukte() {
|
||||
tabellenModell.setRowCount(0);
|
||||
if (service == null) return;
|
||||
List<Produkt> produkte = service.alleProdukte();
|
||||
for (Produkt p : produkte) {
|
||||
tabellenModell.addRow(new Object[]{
|
||||
p.getProduktId(), p.getBezeichnung(),
|
||||
String.format("%.2f EUR", p.getNettoEinzelpreis()),
|
||||
String.format("%.0f%%", p.getMehrwertsteuersatz().multiply(new BigDecimal("100"))),
|
||||
p.getBestand(),
|
||||
p.isVerfuegbar() ? "VERFUEGBAR" : "NICHT VERFUEGBAR"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void sucheProdukte() {
|
||||
tabellenModell.setRowCount(0);
|
||||
if (service == null) return;
|
||||
List<Produkt> produkte = service.sucheNachBezeichnung(suchfeld.getText());
|
||||
for (Produkt p : produkte) {
|
||||
tabellenModell.addRow(new Object[]{
|
||||
p.getProduktId(), p.getBezeichnung(),
|
||||
String.format("%.2f EUR", p.getNettoEinzelpreis()),
|
||||
String.format("%.0f%%", p.getMehrwertsteuersatz().multiply(new BigDecimal("100"))),
|
||||
p.getBestand(),
|
||||
p.isVerfuegbar() ? "VERFUEGBAR" : "NICHT VERFUEGBAR"
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue