amin first commit

test
Aminos061 2024-06-11 16:33:42 +02:00
parent 215163e7db
commit 035ed24295
17 changed files with 829 additions and 0 deletions

17
.gitignore vendored 100644
View File

@ -0,0 +1,17 @@
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
.mvn/wrapper/maven-wrapper.jar
# Eclipse m2e generated files
# Eclipse Core
.project
# JDT-specific (Eclipse Java Development Tools)
.classpath

1
KI_Projekt/.gitignore vendored 100644
View File

@ -0,0 +1 @@
/bin/

View File

@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8

View File

@ -0,0 +1,14 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=17

View File

@ -0,0 +1,62 @@
import java.io.Serializable;
public class Company implements Serializable{
private String name;
private String address;
private String phone;
private String email;
private boolean isSmallBusiness;
public Company() {
}
public Company(String name, String address, String phone, String email, boolean isSmallBusiness) {
this.name = name;
this.address = address;
this.phone = phone;
this.email = email;
this.isSmallBusiness = isSmallBusiness;
}
// Getter und Setter
@Override
public String toString() {
return "Company{" +
"name='" + name + '\'' +
", address='" + address + '\'' +
", phone='" + phone + '\'' +
", email='" + email + '\'' +
", isSmallBusiness=" + isSmallBusiness +
'}';
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public boolean isSmallBusiness() {
return isSmallBusiness;
}
public void setSmallBusiness(boolean isSmallBusiness) {
this.isSmallBusiness = isSmallBusiness;
}
}

View File

@ -0,0 +1,46 @@
import java.io.Serializable;
public class Customer implements Serializable {
private String address;
private String contactPerson;
private boolean smallBusiness;
public Customer(String address, String contactPerson, boolean smallBusiness) {
this.address = address;
this.contactPerson = contactPerson;
this.smallBusiness = smallBusiness;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getContactPerson() {
return contactPerson;
}
public void setContactPerson(String contactPerson) {
this.contactPerson = contactPerson;
}
public boolean isSmallBusiness() {
return smallBusiness;
}
public void setSmallBusiness(boolean smallBusiness) {
this.smallBusiness = smallBusiness;
}
@Override
public String toString() {
return "Customer [address=" + address + ", contactPerson=" + contactPerson + ", smallBusiness=" + smallBusiness
+ "]";
}
// Getter und Setter
}

View File

@ -0,0 +1,347 @@
import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Scanner;
public class DataManager {
private List<Company> companies;
private List<Product> products;
private List<Customer> customers;
private List<Offer> offers;
private List<OrderConfirmation> orderConfirmations;
private List<DeliveryNote> deliveryNotes;
private List<Invoice> invoices;
public DataManager() {
this.companies = new ArrayList<>();
this.products = new ArrayList<>();
this.customers = new ArrayList<>();
this.offers = new ArrayList<>();
this.orderConfirmations = new ArrayList<>();
this.deliveryNotes = new ArrayList<>();
this.invoices = new ArrayList<>();
}
public void showMenu() {
Scanner scanner = new Scanner(System.in);
int choice;
do {
System.out.println("1. Neue Firma eingeben");
System.out.println("2. Neues Produkt eingeben");
System.out.println("3. Neuer Kunde eingeben");
System.out.println("4. Angebot erstellen");
System.out.println("5. Auftragsbestätigung erstellen");
System.out.println("6. Lieferschein erstellen");
System.out.println("7. Rechnung erstellen");
System.out.println("8. Angebote anzeigen");
System.out.println("9. Auftragsbestätigungen anzeigen");
System.out.println("10. Lieferscheine anzeigen");
System.out.println("11. Rechnungen anzeigen");
System.out.println("12. Firmen anzeigen");
System.out.println("13. Produkte anzeigen");
System.out.println("14. Kunden anzeigen");
System.out.println("15. XML-Daten laden");
System.out.println("16. Beenden");
System.out.print("Wählen Sie eine Option: ");
choice = scanner.nextInt();
scanner.nextLine(); // Consume newline
switch (choice) {
case 1:
enterCompany(scanner);
break;
case 2:
enterProduct(scanner);
break;
case 3:
enterCustomer(scanner);
break;
case 4:
createOffer(scanner);
break;
case 5:
createOrderConfirmation(scanner);
break;
case 6:
createDeliveryNote(scanner);
break;
case 7:
createInvoice(scanner);
break;
case 8:
displayOffers();
break;
case 9:
displayOrderConfirmations();
break;
case 10:
displayDeliveryNotes();
break;
case 11:
displayInvoices();
break;
case 12:
displayCompanies();
break;
case 13:
displayProducts();
break;
case 14:
displayCustomers();
break;
case 15:
loadFromXML();
System.out.println("XML-Daten erfolgreich geladen.");
break;
case 16:
System.out.println("Programm wird beendet.");
break;
default:
System.out.println("Ungültige Auswahl. Bitte erneut versuchen.");
}
} while (choice != 16);
}
public void enterCompany(Scanner scanner) {
System.out.print("Geben Sie den Firmennamen ein: ");
String name = scanner.nextLine();
System.out.print("Geben Sie die Adresse ein: ");
String address = scanner.nextLine();
System.out.print("Geben Sie die Telefonnummer ein: ");
String phone = scanner.nextLine();
System.out.print("Geben Sie die E-Mail-Adresse ein: ");
String email = scanner.nextLine();
System.out.print("Ist die Firma ein Kleinunternehmen? (ja/nein): ");
boolean isSmallBusiness = scanner.nextLine().equalsIgnoreCase("ja");
Company company = new Company(name, address, phone, email, isSmallBusiness);
companies.add(company);
XMLUtils.serializeObjectToXML( company, "xml_data/" + "company_" + name + ".xml");
System.out.println("Firma erfolgreich hinzugefügt und in XML gespeichert.");
}
public void enterProduct(Scanner scanner) {
System.out.print("Geben Sie die Einheit des Produkts ein: ");
String unit = scanner.nextLine();
System.out.print("Geben Sie die Bezeichnung des Produkts ein: ");
String name = scanner.nextLine();
System.out.print("Geben Sie den Nettopreis des Produkts ein: ");
double netPrice = Double.parseDouble(scanner.nextLine());
System.out.print("Geben Sie den Mehrwertsteuersatz des Produkts ein: ");
double taxRate = Double.parseDouble(scanner.nextLine());
Product product = new Product(unit, name, netPrice, taxRate);
products.add(product);
XMLUtils.serializeObjectToXML(product, "xml_data/" + "product_" + name + ".xml");
System.out.println("Produkt erfolgreich hinzugefügt und in XML gespeichert.");
}
public void enterCustomer(Scanner scanner) {
System.out.print("Geben Sie die Adresse des Kunden ein: ");
String address = scanner.nextLine();
System.out.print("Geben Sie den Ansprechpartner des Kunden ein: ");
String contactPerson = scanner.nextLine();
System.out.print("Ist der Kunde ein Kleinunternehmen? (ja/nein): ");
boolean isSmallBusiness = scanner.nextLine().equalsIgnoreCase("ja");
Customer customer = new Customer(address, contactPerson, isSmallBusiness);
customers.add(customer);
XMLUtils.serializeObjectToXML(customer, "xml_data/" + "customer_" + contactPerson + ".xml");
System.out.println("Kunde erfolgreich hinzugefügt und in XML gespeichert.");
}
public void createOffer(Scanner scanner) {
System.out.println("Neues Angebot erstellen:");
displayCustomers();
System.out.print("Wählen Sie einen Kunden aus (Index): ");
int customerIndex = scanner.nextInt();
Customer customer = customers.get(customerIndex);
// Eingabe des Datums durch den Benutzer
System.out.print("Geben Sie das Datum des Angebots ein (Format: dd-MM-yyyy): ");
String dateString = scanner.next();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
Date date = null;
try {
date = dateFormat.parse(dateString);
} catch (ParseException e) {
e.printStackTrace();
}
int offerId = offers.size() + 1;
Offer offer = new Offer(offerId, date, customer); // Hier wird das Datum gesetzt
boolean addingProducts = true;
while (addingProducts) {
displayProducts();
System.out.print("Wählen Sie ein Produkt aus (Index) oder -1 zum Beenden: ");
int productIndex = scanner.nextInt();
if (productIndex == -1) {
addingProducts = false;
} else {
Product product = products.get(productIndex);
System.out.print("Geben Sie die Menge ein: ");
int quantity = scanner.nextInt();
offer.addProduct(product, quantity);
}
}
offers.add(offer);
System.out.println("Angebot erfolgreich erstellt.");
// Angebot serialisieren
String offerFileName = "offer_" + offers.size() + ".xml";
XMLUtils.serializeObjectToXML(offer, "xml_data/" + offerFileName);
System.out.println("Angebot als XML-Datei gespeichert: " + offerFileName);
}
public void displayCompanies() {
System.out.println("Firmen:");
for (Company company : companies) {
System.out.println(company);
}
}
public void displayProducts() {
System.out.println("Produkte:");
for (Product product : products) {
System.out.println(product);
}
}
public void displayCustomers() {
System.out.println("Kunden:");
for (Customer customer : customers) {
System.out.println(customer);
}
}
public void displayOffers() {
System.out.println("Angebote:");
for (int i = 0; i < offers.size(); i++) {
System.out.println("Angebot " + (i + 1) + ":");
System.out.println(offers.get(i));
}
if (offers.isEmpty()) {
System.out.println("Keine Angebote vorhanden.");
}
}
public void createOrderConfirmation(Scanner scanner) {
System.out.println("Neue Auftragsbestätigung erstellen:");
displayOffers();
System.out.print("Wählen Sie ein Angebot aus (Index): ");
int offerIndex = scanner.nextInt();
Offer offer = offers.get(offerIndex);
System.out.print("Geben Sie das Datum der Auftragsbestätigung ein (Format: dd-MM-yyyy): ");
String dateString = scanner.next();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
Date date = null;
try {
date = dateFormat.parse(dateString);
} catch (ParseException e) {
e.printStackTrace();
}
int confirmationId = orderConfirmations.size() + 1;
OrderConfirmation orderConfirmation = new OrderConfirmation(confirmationId, date, offer);
orderConfirmations.add(orderConfirmation);
System.out.println("Auftragsbestätigung erfolgreich erstellt.");
// Auftragsbestätigung serialisieren
String confirmationFileName = "order_confirmation_" + orderConfirmations.size() + ".xml";
XMLUtils.serializeObjectToXML(orderConfirmation, "xml_data/" + confirmationFileName);
System.out.println("Auftragsbestätigung als XML-Datei gespeichert: " + confirmationFileName);
}
public void createDeliveryNote(Scanner scanner) {
System.out.println("Neuen Lieferschein erstellen:");
displayOrderConfirmations();
System.out.print("Wählen Sie eine Auftragsbestätigung aus (Index): ");
int confirmationIndex = scanner.nextInt();
OrderConfirmation orderConfirmation = orderConfirmations.get(confirmationIndex);
System.out.print("Geben Sie das Datum des Lieferscheins ein (Format: dd-MM-yyyy): ");
String dateString = scanner.next();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
Date date = null;
try {
date = dateFormat.parse(dateString);
} catch (ParseException e) {
e.printStackTrace();
}
int deliveryNoteId = deliveryNotes.size() + 1;
DeliveryNote deliveryNote = new DeliveryNote(deliveryNoteId, date, orderConfirmation);
deliveryNotes.add(deliveryNote);
System.out.println("Lieferschein erfolgreich erstellt.");
// Lieferschein serialisieren
String deliveryNoteFileName = "delivery_note_" + deliveryNotes.size() + ".xml";
XMLUtils.serializeObjectToXML(deliveryNote, "xml_data/" + deliveryNoteFileName);
System.out.println("Lieferschein als XML-Datei gespeichert: " + deliveryNoteFileName);
}
public void createInvoice(Scanner scanner) {
System.out.println("Neue Rechnung erstellen:");
displayDeliveryNotes();
System.out.print("Wählen Sie einen Lieferschein aus (Index): ");
int deliveryNoteIndex = scanner.nextInt();
DeliveryNote deliveryNote = deliveryNotes.get(deliveryNoteIndex);
System.out.print("Geben Sie das Datum der Rechnung ein (Format: dd-MM-yyyy): ");
String dateString = scanner.next();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
Date date = null;
try {
date = dateFormat.parse(dateString);
} catch (ParseException e) {
e.printStackTrace();
}
int invoiceId = invoices.size() + 1;
Invoice invoice = new Invoice(invoiceId, date, deliveryNote);
invoices.add(invoice);
System.out.println("Rechnung erfolgreich erstellt.");
// Rechnung serialisieren
String invoiceFileName = "invoice_" + invoices.size() + ".xml";
XMLUtils.serializeObjectToXML(invoice, "xml_data/" + invoiceFileName);
System.out.println("Rechnung als XML-Datei gespeichert: " + invoiceFileName);
}
public void displayOrderConfirmations() {
System.out.println("Auftragsbestätigungen:");
for (int i = 0; i < orderConfirmations.size(); i++) {
System.out.println(i + ": " + orderConfirmations.get(i));
}
}
public void displayDeliveryNotes() {
System.out.println("Lieferscheine:");
for (int i = 0; i < deliveryNotes.size(); i++) {
System.out.println(i + ": " + deliveryNotes.get(i));
}
}
public void displayInvoices() {
System.out.println("Rechnungen:");
for (int i = 0; i < invoices.size(); i++) {
System.out.println(i + ": " + invoices.get(i));
}
}
public void loadFromXML() {
// Existierende Daten laden
companies = XMLUtils.deserializeObjectFromXML("xml_data/companies.xml");
products = XMLUtils.deserializeObjectFromXML("xml_data/products.xml");
customers = XMLUtils.deserializeObjectFromXML("xml_data/customers.xml");
offers = XMLUtils.deserializeObjectFromXML("xml_data/offers.xml");
orderConfirmations = XMLUtils.deserializeObjectFromXML("xml_data/order_confirmations.xml");
deliveryNotes = XMLUtils.deserializeObjectFromXML("xml_data/delivery_notes.xml");
invoices = XMLUtils.deserializeObjectFromXML("xml_data/invoices.xml");
}
}

View File

@ -0,0 +1,46 @@
import java.util.Date;
public class DeliveryNote {
private int deliveryNoteId;
private Date date;
private OrderConfirmation orderConfirmation;
public DeliveryNote(int deliveryNoteId, Date date, OrderConfirmation orderConfirmation) {
this.deliveryNoteId = deliveryNoteId;
this.date = date;
this.orderConfirmation = orderConfirmation;
}
public int getDeliveryNoteId() {
return deliveryNoteId;
}
public void setDeliveryNoteId(int deliveryNoteId) {
this.deliveryNoteId = deliveryNoteId;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public OrderConfirmation getOrderConfirmation() {
return orderConfirmation;
}
public void setOrderConfirmation(OrderConfirmation orderConfirmation) {
this.orderConfirmation = orderConfirmation;
}
@Override
public String toString() {
return "DeliveryNote{" +
"deliveryNoteId=" + deliveryNoteId +
", date=" + date +
", orderConfirmation=" + orderConfirmation +
'}';
}
}

View File

@ -0,0 +1,46 @@
import java.util.Date;
public class Invoice {
private int invoiceId;
private Date date;
private DeliveryNote deliveryNote;
public Invoice(int invoiceId, Date date, DeliveryNote deliveryNote) {
this.invoiceId = invoiceId;
this.date = date;
this.deliveryNote = deliveryNote;
}
public int getInvoiceId() {
return invoiceId;
}
public void setInvoiceId(int invoiceId) {
this.invoiceId = invoiceId;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public DeliveryNote getDeliveryNote() {
return deliveryNote;
}
public void setDeliveryNote(DeliveryNote deliveryNote) {
this.deliveryNote = deliveryNote;
}
@Override
public String toString() {
return "Invoice{" +
"invoiceId=" + invoiceId +
", date=" + date +
", deliveryNote=" + deliveryNote +
'}';
}
}

View File

@ -0,0 +1,8 @@
public class Main {
public static void main(String[] args) {
DataManager manager = new DataManager();
manager.showMenu();
}
}

View File

@ -0,0 +1,63 @@
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
public class Offer {
private int offerId;
private Date date; // Neues Date-Attribut für das Erstellungsdatum des Angebots
private Customer customer;
private Map<Product, Integer> products;
public Offer(int offerId, Date date, Customer customer) {
this.offerId = offerId;
this.date = date;
this.customer = customer;
this.products = new HashMap<>();
}
public int getOfferId() {
return offerId;
}
public void setOfferId(int offerId) {
this.offerId = offerId;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public Map<Product, Integer> getProducts() {
return products;
}
public void setProducts(Map<Product, Integer> products) {
this.products = products;
}
public void addProduct(Product product, int quantity) {
products.put(product, quantity);
}
@Override
public String toString() {
return "Offer{" +
"offerId=" + offerId +
", date=" + date +
", customer=" + customer +
", products=" + products +
'}';
}
}

View File

@ -0,0 +1,46 @@
import java.util.Date;
public class OrderConfirmation {
private int confirmationId;
private Date date;
private Offer offer;
public OrderConfirmation(int confirmationId, Date date, Offer offer) {
this.confirmationId = confirmationId;
this.date = date;
this.offer = offer;
}
public int getConfirmationId() {
return confirmationId;
}
public void setConfirmationId(int confirmationId) {
this.confirmationId = confirmationId;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public Offer getOffer() {
return offer;
}
public void setOffer(Offer offer) {
this.offer = offer;
}
@Override
public String toString() {
return "OrderConfirmation{" +
"confirmationId=" + confirmationId +
", date=" + date +
", offer=" + offer +
'}';
}
}

View File

@ -0,0 +1,47 @@
import java.io.Serializable;
public class Product implements Serializable {
public static int getNextProductNumber() {
return nextProductNumber;
}
public static void setNextProductNumber(int nextProductNumber) {
Product.nextProductNumber = nextProductNumber;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "Product [number=" + number + ", unit=" + unit + ", name=" + name + ", netPrice=" + netPrice
+ ", taxRate=" + taxRate + "]";
}
private static int nextProductNumber = 1;
private String number;
private String unit;
private String name;
private double netPrice;
private double taxRate;
public Product(String unit, String name, double netPrice, double taxRate) {
this.number = generateProductNumber();
this.unit = unit;
this.name = name;
this.netPrice = netPrice;
this.taxRate = taxRate;
}
// Getter und Setter
private String generateProductNumber() {
return "ART-" + nextProductNumber++;
}
}

View File

@ -0,0 +1,48 @@
import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;
public class XMLUtils {
public static void serializeObjectToXML(Object obj, String filePath) {
try {
FileOutputStream fos = new FileOutputStream(filePath);
XMLEncoder encoder = new XMLEncoder(fos);
encoder.writeObject(obj);
encoder.close();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static <T> T deserializeObjectFromXML(String filePath) {
T obj = null;
try {
FileInputStream fis = new FileInputStream(filePath);
XMLDecoder decoder = new XMLDecoder(fis);
obj = (T) decoder.readObject();
decoder.close();
fis.close();
} catch (Exception e) {
e.printStackTrace();
}
return obj;
}
public static <T> List<T> deserializeListFromXML(String filePath) {
List<T> list = new ArrayList<>();
try {
FileInputStream fis = new FileInputStream(filePath);
XMLDecoder decoder = new XMLDecoder(fis);
list = (List<T>) decoder.readObject();
decoder.close();
fis.close();
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
}

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<java version="17.0.8" class="java.beans.XMLDecoder">
<string>address</string>
<string>Ahash</string>
<string>contactPerson</string>
<string>das</string>
<string>smallBusiness</string>
<boolean>true</boolean>
</java>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<java version="17.0.8" class="java.beans.XMLDecoder">
<string>offerId</string>
<int>1</int>
<string>date</string>
<object class="java.util.Date">
<long>1713736800000</long>
</object>
<string>customer</string>
<string>products</string>
<object class="java.util.HashMap"/>
</java>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<java version="17.0.8" class="java.beans.XMLDecoder">
<string>nextProductNumber</string>
<int>2</int>
<string>number</string>
<string>ART-1</string>
<string>unit</string>
<string>mas</string>
<string>name</string>
<string>ham</string>
<string>netPrice</string>
<double>122.0</double>
<string>taxRate</string>
<double>1.0</double>
</java>