Löschen eingefügt

master
athar 2024-06-30 22:25:47 +02:00
parent fa6043367e
commit 2fd0462c51
3 changed files with 267 additions and 12 deletions

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Fakturama>
<Customers/>
<Articles/>
<Offers/>
<OrderConfirmations/>
<DeliveryNotes/>
<Invoices/>
</Fakturama>

View File

@ -839,5 +839,42 @@ public class Main {
}
}
public static void deleteCustomer(int index) {
if (index >= 0 && index < customers.size()) {
customers.remove(index);
}
}
public static void deleteArticle(int index) {
if (index >= 0 && index < articles.size()) {
articles.remove(index);
}
}
public static void deleteOffer(int index) {
if (index >= 0 && index < offers.size()) {
offers.remove(index);
}
}
public static void deleteOrderConfirmation(int index) {
if (index >= 0 && index < orderConfirmations.size()) {
orderConfirmations.remove(index);
}
}
public static void deleteDeliveryNote(int index) {
if (index >= 0 && index < deliveryNotes.size()) {
deliveryNotes.remove(index);
}
}
public static void deleteInvoice(int index) {
if (index >= 0 && index < invoices.size()) {
invoices.remove(index);
}
}
}

View File

@ -34,26 +34,50 @@ public class MainGUI {
menu.add(addCustomerItem);
addCustomerItem.addActionListener(e -> showAddCustomerPanel());
JMenuItem deleteCustomerItem = new JMenuItem("Kunde löschen");
menu.add(deleteCustomerItem);
deleteCustomerItem.addActionListener(e -> showDeleteCustomerPanel());
JMenuItem addArticleItem = new JMenuItem("Artikel hinzufügen");
menu.add(addArticleItem);
addArticleItem.addActionListener(e -> showAddArticlePanel());
JMenuItem deleteArticleItem = new JMenuItem("Artikel löschen");
menu.add(deleteArticleItem);
deleteArticleItem.addActionListener(e -> showDeleteArticlePanel());
JMenuItem createOfferItem = new JMenuItem("Angebot erstellen");
menu.add(createOfferItem);
createOfferItem.addActionListener(e -> showCreateOfferPanel());
JMenuItem deleteOfferItem = new JMenuItem("Angebot löschen");
menu.add(deleteOfferItem);
deleteOfferItem.addActionListener(e -> showDeleteOfferPanel());
JMenuItem createOrderConfirmationItem = new JMenuItem("Auftragsbestätigung erstellen");
menu.add(createOrderConfirmationItem);
createOrderConfirmationItem.addActionListener(e -> showCreateOrderConfirmationPanel());
JMenuItem deleteOrderConfirmationItem = new JMenuItem("Auftragsbestätigung löschen");
menu.add(deleteOrderConfirmationItem);
deleteOrderConfirmationItem.addActionListener(e -> showDeleteOrderConfirmationPanel());
JMenuItem createDeliveryNoteItem = new JMenuItem("Lieferschein erstellen");
menu.add(createDeliveryNoteItem);
createDeliveryNoteItem.addActionListener(e -> showCreateDeliveryNotePanel());
JMenuItem deleteDeliveryNoteItem = new JMenuItem("Lieferschein löschen");
menu.add(deleteDeliveryNoteItem);
deleteDeliveryNoteItem.addActionListener(e -> showDeleteDeliveryNotePanel());
JMenuItem createInvoiceItem = new JMenuItem("Rechnung erstellen");
menu.add(createInvoiceItem);
createInvoiceItem.addActionListener(e -> showCreateInvoicePanel());
JMenuItem deleteInvoiceItem = new JMenuItem("Rechnung löschen");
menu.add(deleteInvoiceItem);
deleteInvoiceItem.addActionListener(e -> showDeleteInvoicePanel());
JMenuItem saveDataItem = new JMenuItem("Daten speichern");
menu.add(saveDataItem);
saveDataItem.addActionListener(e -> {
@ -346,35 +370,220 @@ public class MainGUI {
private void updateTextArea() {
StringBuilder sb = new StringBuilder();
sb.append("Kunden:\n");
for (Main.Customer customer : Main.customers) {
sb.append(customer.name).append(" - ").append(customer.address).append(" - ").append(customer.contactPerson).append(" - ").append(customer.taxExempt ? "§ 4 UStG" : "").append(" - ").append(customer.smallBusiness ? "Kleinunternehmer" : "").append("\n");
for (int i = 0; i < Main.customers.size(); i++) {
Main.Customer customer = Main.customers.get(i);
sb.append(i + 1).append(". ").append(customer.name).append(" - ").append(customer.address).append(" - ").append(customer.contactPerson).append(" - ").append(customer.taxExempt ? "§ 4 UStG" : "").append(" - ").append(customer.smallBusiness ? "Kleinunternehmer" : "").append("\n");
}
sb.append("\nArtikel:\n");
for (Main.Article article : Main.articles) {
sb.append(article.description).append(" - ").append(article.unit).append(" - ").append(article.netPrice).append(" € - ").append(article.vatRate).append(" %").append("\n");
for (int i = 0; i < Main.articles.size(); i++) {
Main.Article article = Main.articles.get(i);
sb.append(i + 1).append(". ").append(article.description).append(" - ").append(article.unit).append(" - ").append(article.netPrice).append(" € - ").append(article.vatRate).append(" %").append("\n");
}
sb.append("\nAngebote:\n");
for (Main.Offer offer : Main.offers) {
sb.append("Angebot #").append(offer.id).append(" - ").append(offer.customer.name).append(" - ").append(offer.date).append(" - ").append(offer.status).append("\n");
for (int i = 0; i < Main.offers.size(); i++) {
Main.Offer offer = Main.offers.get(i);
sb.append(i + 1).append(". Angebot #").append(offer.id).append(" - ").append(offer.customer.name).append(" - ").append(offer.date).append(" - ").append(offer.status).append("\n");
for (Main.Article article : offer.articles) {
sb.append(" ").append(article.description).append(" - ").append(article.unit).append(" - ").append(article.netPrice).append(" € - ").append(article.vatRate).append(" %").append("\n");
}
}
sb.append("\nAuftragsbestätigungen:\n");
for (Main.OrderConfirmation orderConfirmation : Main.orderConfirmations) {
sb.append("Auftragsbestätigung #").append(orderConfirmation.id).append(" - ").append(orderConfirmation.offer.customer.name).append(" - ").append(orderConfirmation.date).append(" - ").append(orderConfirmation.status).append("\n");
for (int i = 0; i < Main.orderConfirmations.size(); i++) {
Main.OrderConfirmation orderConfirmation = Main.orderConfirmations.get(i);
sb.append(i + 1).append(". Auftragsbestätigung #").append(orderConfirmation.id).append(" - ").append(orderConfirmation.offer.customer.name).append(" - ").append(orderConfirmation.date).append(" - ").append(orderConfirmation.status).append("\n");
}
sb.append("\nLieferscheine:\n");
for (Main.DeliveryNote deliveryNote : Main.deliveryNotes) {
sb.append("Lieferschein #").append(deliveryNote.id).append(" - ").append(deliveryNote.orderConfirmation.offer.customer.name).append(" - ").append(deliveryNote.date).append(" - ").append(deliveryNote.status).append("\n");
for (int i = 0; i < Main.deliveryNotes.size(); i++) {
Main.DeliveryNote deliveryNote = Main.deliveryNotes.get(i);
sb.append(i + 1).append(". Lieferschein #").append(deliveryNote.id).append(" - ").append(deliveryNote.orderConfirmation.offer.customer.name).append(" - ").append(deliveryNote.date).append(" - ").append(deliveryNote.status).append("\n");
}
sb.append("\nRechnungen:\n");
for (Main.Invoice invoice : Main.invoices) {
sb.append("Rechnung #").append(invoice.id).append(" - ").append(invoice.deliveryNote.orderConfirmation.offer.customer.name).append(" - ").append(invoice.date).append(" - ").append(invoice.status).append("\n");
for (int i = 0; i < Main.invoices.size(); i++) {
Main.Invoice invoice = Main.invoices.get(i);
sb.append(i + 1).append(". Rechnung #").append(invoice.id).append(" - ").append(invoice.deliveryNote.orderConfirmation.offer.customer.name).append(" - ").append(invoice.date).append(" - ").append(invoice.status).append("\n");
}
textArea.setText(sb.toString());
}
private void showDeleteCustomerPanel() {
JPanel panel = new JPanel(new GridLayout(3, 2));
JLabel customerLabel = new JLabel("Kunde:");
JComboBox<String> customerBox = new JComboBox<>();
for (Main.Customer customer : Main.customers) {
customerBox.addItem(customer.name);
}
JButton deleteButton = new JButton("Löschen");
deleteButton.setBackground(new Color(255, 99, 71)); // Tomatenrot
deleteButton.addActionListener(e -> {
String customerName = (String) customerBox.getSelectedItem();
Main.customers.removeIf(c -> c.name.equals(customerName));
updateTextArea();
cardLayout.show(mainPanel, "Home");
});
JButton backButton = new JButton("Zurück");
backButton.addActionListener(e -> cardLayout.show(mainPanel, "Home"));
panel.add(customerLabel);
panel.add(customerBox);
panel.add(backButton);
panel.add(deleteButton);
mainPanel.add(panel, "DeleteCustomer");
cardLayout.show(mainPanel, "DeleteCustomer");
}
private void showDeleteArticlePanel() {
JPanel panel = new JPanel(new GridLayout(3, 2));
JLabel articleLabel = new JLabel("Artikel:");
JComboBox<String> articleBox = new JComboBox<>();
for (Main.Article article : Main.articles) {
articleBox.addItem(article.description);
}
JButton deleteButton = new JButton("Löschen");
deleteButton.setBackground(new Color(255, 99, 71)); // Tomatenrot
deleteButton.addActionListener(e -> {
String articleDescription = (String) articleBox.getSelectedItem();
Main.articles.removeIf(a -> a.description.equals(articleDescription));
updateTextArea();
cardLayout.show(mainPanel, "Home");
});
JButton backButton = new JButton("Zurück");
backButton.addActionListener(e -> cardLayout.show(mainPanel, "Home"));
panel.add(articleLabel);
panel.add(articleBox);
panel.add(backButton);
panel.add(deleteButton);
mainPanel.add(panel, "DeleteArticle");
cardLayout.show(mainPanel, "DeleteArticle");
}
private void showDeleteOfferPanel() {
JPanel panel = new JPanel(new GridLayout(3, 2));
JLabel offerLabel = new JLabel("Angebot:");
JComboBox<String> offerBox = new JComboBox<>();
for (Main.Offer offer : Main.offers) {
offerBox.addItem("Angebot #" + offer.id + " - Kunde: " + offer.customer.name);
}
JButton deleteButton = new JButton("Löschen");
deleteButton.setBackground(new Color(255, 99, 71)); // Tomatenrot
deleteButton.addActionListener(e -> {
String offerInfo = (String) offerBox.getSelectedItem();
int offerId = Integer.parseInt(offerInfo.split(" ")[1].substring(1));
Main.offers.removeIf(o -> o.id == offerId);
updateTextArea();
cardLayout.show(mainPanel, "Home");
});
JButton backButton = new JButton("Zurück");
backButton.addActionListener(e -> cardLayout.show(mainPanel, "Home"));
panel.add(offerLabel);
panel.add(offerBox);
panel.add(backButton);
panel.add(deleteButton);
mainPanel.add(panel, "DeleteOffer");
cardLayout.show(mainPanel, "DeleteOffer");
}
private void showDeleteOrderConfirmationPanel() {
JPanel panel = new JPanel(new GridLayout(3, 2));
JLabel orderConfirmationLabel = new JLabel("Auftragsbestätigung:");
JComboBox<String> orderConfirmationBox = new JComboBox<>();
for (Main.OrderConfirmation orderConfirmation : Main.orderConfirmations) {
orderConfirmationBox.addItem("Auftragsbestätigung #" + orderConfirmation.id + " - Kunde: " + orderConfirmation.offer.customer.name);
}
JButton deleteButton = new JButton("Löschen");
deleteButton.setBackground(new Color(255, 99, 71)); // Tomatenrot
deleteButton.addActionListener(e -> {
String orderConfirmationInfo = (String) orderConfirmationBox.getSelectedItem();
int orderConfirmationId = Integer.parseInt(orderConfirmationInfo.split(" ")[1].substring(1));
Main.orderConfirmations.removeIf(oc -> oc.id == orderConfirmationId);
updateTextArea();
cardLayout.show(mainPanel, "Home");
});
JButton backButton = new JButton("Zurück");
backButton.addActionListener(e -> cardLayout.show(mainPanel, "Home"));
panel.add(orderConfirmationLabel);
panel.add(orderConfirmationBox);
panel.add(backButton);
panel.add(deleteButton);
mainPanel.add(panel, "DeleteOrderConfirmation");
cardLayout.show(mainPanel, "DeleteOrderConfirmation");
}
private void showDeleteDeliveryNotePanel() {
JPanel panel = new JPanel(new GridLayout(3, 2));
JLabel deliveryNoteLabel = new JLabel("Lieferschein:");
JComboBox<String> deliveryNoteBox = new JComboBox<>();
for (Main.DeliveryNote deliveryNote : Main.deliveryNotes) {
deliveryNoteBox.addItem("Lieferschein #" + deliveryNote.id + " - Kunde: " + deliveryNote.orderConfirmation.offer.customer.name);
}
JButton deleteButton = new JButton("Löschen");
deleteButton.setBackground(new Color(255, 99, 71)); // Tomatenrot
deleteButton.addActionListener(e -> {
String deliveryNoteInfo = (String) deliveryNoteBox.getSelectedItem();
int deliveryNoteId = Integer.parseInt(deliveryNoteInfo.split(" ")[1].substring(1));
Main.deliveryNotes.removeIf(dn -> dn.id == deliveryNoteId);
updateTextArea();
cardLayout.show(mainPanel, "Home");
});
JButton backButton = new JButton("Zurück");
backButton.addActionListener(e -> cardLayout.show(mainPanel, "Home"));
panel.add(deliveryNoteLabel);
panel.add(deliveryNoteBox);
panel.add(backButton);
panel.add(deleteButton);
mainPanel.add(panel, "DeleteDeliveryNote");
cardLayout.show(mainPanel, "DeleteDeliveryNote");
}
private void showDeleteInvoicePanel() {
JPanel panel = new JPanel(new GridLayout(3, 2));
JLabel invoiceLabel = new JLabel("Rechnung:");
JComboBox<String> invoiceBox = new JComboBox<>();
for (Main.Invoice invoice : Main.invoices) {
invoiceBox.addItem("Rechnung #" + invoice.id + " - Kunde: " + invoice.deliveryNote.orderConfirmation.offer.customer.name);
}
JButton deleteButton = new JButton("Löschen");
deleteButton.setBackground(new Color(255, 99, 71)); // Tomatenrot
deleteButton.addActionListener(e -> {
String invoiceInfo = (String) invoiceBox.getSelectedItem();
int invoiceId = Integer.parseInt(invoiceInfo.split(" ")[1].substring(1));
Main.invoices.removeIf(i -> i.id == invoiceId);
updateTextArea();
cardLayout.show(mainPanel, "Home");
});
JButton backButton = new JButton("Zurück");
backButton.addActionListener(e -> cardLayout.show(mainPanel, "Home"));
panel.add(invoiceLabel);
panel.add(invoiceBox);
panel.add(backButton);
panel.add(deleteButton);
mainPanel.add(panel, "DeleteInvoice");
cardLayout.show(mainPanel, "DeleteInvoice");
}
public static void main(String[] args) {
EventQueue.invokeLater(() -> {
try {