Use the database class name in any other file to be able to call its methods. Example:
database.fetch_item_ids(); //returns an array of all itemIDs
database.get_item_price_by_id(itemID); //returns the price of the item with ID "itemID"
database.insert_item(item_name, cost_price, selling_price); //creates an item with the arguments as attributes - Arguments: None
- Returns:
Stringarray of item IDs of all items
- Arguments: String itemID of 1 item
- Returns:
doublevalue of the price of that item
- Arguments: None
- Returns:
Stringarray of names of all transport methods
Creates 1 item in your database.
- Arguments: Item name, Item cost price, Item selling price
- Returns: Nothing
Fetches the price of 1 transport method. Searches for transport name and returns its price.
- Arguments: Transport Name (String)
- Returns: Transport price (double)
Updates 1 item in your database. The item name is searched in the database and the prices are modified.
- Arguments: Item name, Item cost price, Item selling price
- Returns: Nothing
Deletes 1 item in your database which has the item name.
- Arguments: Item name, Item cost price, Item selling price
- Returns: Nothing
Creates an a customer, an invoice for the customer, and the invoice's orders, in that exact order.
- Arguments: Customer object, Invoice object
- Returns: Nothing
Your salesperson frame will be the frame where a customer object will be created. Pretty straightforward ad explained below.
String first_name = "Tanoo";
String last_name = "Joy";
String contactDetails = "62763526";
String email = "tanoo@joy.com";
String address = "Trianon";
String transportPreference = "DHL";
//new customer object
Customer customer1 = new Customer(first_name, last_name, contact_details, email, address, transportPreference);This customer object can now be used like this:
String name = customer1.first_name + " " +customer1.last_name;
System.out.println(name); //outputs "Tanoo Joy"- buying 2 shirts = 1 order
- buying 2 shirts, 3 hoodies = 2 orders
The salesperson frame is also where a list or orders will be created. Include in Salesperson frame class variables:
private List<Order> order_list = new ArrayList<>();Create a orders:
//this can be in your ActionListener
//fetch data from your GUI
int item_id;
int quantity;
double unitPrice;
double totalPrice;
String backorderstatus;
Order order1 = new Order(item_id, quantity, unitPrice, totalPrice, backorderstatus);
order_list.add(order1); //added order 1 to order_list
//everytime the button is clicked, a new order is created and added to "order_list"
//Another actionlistener for your checkout button executes this:
new Checkout(customer1, order_list);
//this takes the customer object and their order listAll of the above happen before payment is done. After a payment method is chosen, and a checkout is confirmed, an invoice can now be created with the customer and their orders.
//new invoice object
Invoice invoice1 = new Invoice();
for (Order order : order_list) { //for every "order" in "order_list"
invoice.AddOrder(order); //add that order to the invoice
}
String transportPreference = customer1.transportPreference; //from customer object
invoice.AddTransportPreference(transportPreference) //added Transport Name to invoice
double transport_charge = database.get_transport_charge(transportPreference); //from database class
invoice.AddTransportCharge(transport_charge); //added Transport charge to invoice
//the invoice, orders and the customer are now ready to be inserted in the database:
database.create_order(invoice1, customer1);
//doneString first_name = "Tanoo";
String last_name = "Joy";
String contactDetails = "62763526";
String email = "tanoo@joy.com";
String address = "Trianon";
String transportPreference = "DHL";
//new customer object
Customer customer1 = new Customer(first_name, last_name, contact_details, email, address, transportPreference);
int item_id;
int quantity;
double unitPrice;
double totalPrice;
String backorderstatus;
//new order objects
Order order1 = new Order(item_id, quantity, unitPrice, totalPrice, backorderstatus); //shirts
Order order2 = new Order(item_id, quantity, unitPrice, totalPrice, backorderstatus); //hoodies
//new invoice object
Invoice invoice1 = new Invoice();
//add the 2 orders
invoice1.AddOrder(order1); //added shirts to invoice
invoice.AddOrder(order2); //added hoodies to invoice
//the invoice object now CONTAINS the 2 order objects
String transportPreference = customer1.transportPreference; //from customer object
invoice.AddTransportPreference(transportPreference) //added Transport Name to invoice
double transport_charge = database.get_transport_charge(transportPreference); //from database class
invoice.AddTransportCharge(transport_charge); //added Transport charge to invoice
//the invoice, orders and the customer are now ready to be inserted in the database:
database.create_order(invoice1, customer1);
//done