Class Main

java.lang.Object
javafx.application.Application
Main

public class Main extends javafx.application.Application
The main class for the Panda Express Point-of-Sale application. This class extends the Application class and serves as the entry point for the application. It initializes the primary stage, connects to the database, and manages scene navigation and user interactions throughout the application.

Key Responsibilities:

  • Initializes the main application window.
  • Establishes a connection to the database.
  • Handles scene transitions using FXML files.
  • Manages navigation between different application screens (e.g., cashier, manager, reports).
  • Loads and displays images in the user interface.

Usage:

To run the application, invoke the start(Stage primaryStage) method.

The following FXML files are utilized for different screens:

  • pages/Main.fxml
  • pages/Cashier.fxml
  • pages/Manager.fxml
  • pages/Template.fxml
  • pages/Report.fxml

Instance Variables:

  • Stage primaryStage - The main window of the application.
  • Database database - The database connection for the application.
  • Cart cart - The shopping cart to manage user selections.
  • Nested Class Summary

    Nested classes/interfaces inherited from class javafx.application.Application

    javafx.application.Application.Parameters
  • Field Summary

    Fields inherited from class javafx.application.Application

    STYLESHEET_CASPIAN, STYLESHEET_MODENA
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Generates a form to add a new employee to the system.
    void
    Generates a form to add a new food item to the system.
    void
    Generates a form to add a new inventory item to the system.
    void
    Generates a form to add a new menu item to the system.
    void
    Displays an alert indicating that adding an order cannot be done at the current time.
    void
    Manages the logic for the cashier interface, including displaying menu items and handling interactions when items are added to or removed from the cart.
    void
    createAlert(String title, String message, String type)
    Creates and displays an alert dialog based on the specified type.
    createFoodForm(MenuItem item, ResultSet foods, String title)
     
    void
    Generates a form to delete an employee from the system.
    void
    Generates a form to delete a food item from the system.
    void
    Generates a form to delete an inventory item from the system.
    void
    Initiates the deletion of a menu item by generating a form to gather input.
    void
    Displays an alert indicating that deleting an order cannot be done at the current time.
    void
    editDatabase(ArrayList<String> results, String action)
    Edits the database based on the specified action and the provided results.
    void
    Generates a form for editing an employee's details.
    void
    Generates a form for editing a food item's details.
    void
    Generates a form for editing an inventory item's details.
    void
    Generates a form for editing a menu item's details.
    void
    Displays an alert informing the user that editing an order is not allowed at this time.
    void
    Generates the employee management page.
    void
    Generates the food item management page.
    void
    generateForm(ArrayList<String> parameters, String action)
    Generates a dynamic form based on the provided parameters and action.
    void
    Generates the inventory management page.
    void
    Generates the menu item management page.
    void
    Generates the order management page.
    void
     
    void
    Navigates to the cashier screen of the application.
    void
    Navigates to the main screen of the application.
    void
    Navigates to the manager screen of the application.
    void
    Navigates to the report screen of the application.
    void
    Navigates to the Sales Report view by setting its style to visible and hiding the X Report and Z Report views.
    void
    Navigates to the database viewer screen of the application.
    void
    Navigates to the X Report view by setting its style to visible, applying a translation effect, and hiding the Sales Report and Z Report views.
    void
    Navigates to the Z Report view by setting its style to visible, applying a translation effect, and hiding the Sales Report and X Report views.
    void
    Navigates to the previous employee in the list, decrementing the table offset if possible.
    void
    Navigates to the previous food item in the list, decrementing the table offset if possible.
    void
    Navigates to the previous inventory item in the list, decrementing the table offset if possible.
    void
    Navigates to the previous menu item in the list, decrementing the table offset if possible.
    void
    Navigates to the previous order in the list, decrementing the table offset if possible.
    void
    Loads the back button image if the back button is not null.
    void
    Loads the panda image into the GUI.
    void
    Loads the question button image from the specified resource path and sets it to the questionButton if it is not null.
    static void
    main(String[] args)
    The entry point of the application.
    void
    Navigates to the next employee in the list by incrementing the table offset.
    void
    Navigates to the next food item in the list by incrementing the table offset.
    void
    Navigates to the next inventory item in the list by incrementing the table offset.
    void
    Navigates to the next menu item in the list by incrementing the table offset.
    void
    Navigates to the next order in the list by incrementing the table offset.
    void
    Displays an informational alert to guide users on how to enter dates for generating reports.
    selectFood(MenuItem item, String type)
     
     
    void
    Sends the current order to the database if the food item form is not open and the cart contains items.
    void
    start(javafx.stage.Stage primaryStage)
     
    void
    Submits a sales report based on the specified date range.
    void
    Submits a request to generate an X report based on the date provided in the `currentDate` text field.
    void
    Submits a request to generate a Z report based on the date provided in the `currentDate2` text field.

    Methods inherited from class javafx.application.Application

    getHostServices, getParameters, getUserAgentStylesheet, init, launch, launch, notifyPreloader, setUserAgentStylesheet, stop

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Main

      public Main()
  • Method Details

    • start

      public void start(javafx.stage.Stage primaryStage)
      Specified by:
      start in class javafx.application.Application
    • goToMain

      public void goToMain()
      Navigates to the main screen of the application. Empties the current cart and switches to the main scene unless the food item window is currently open.
    • goToCashier

      public void goToCashier()
      Navigates to the cashier screen of the application. Initializes the cashier logic and loads the back button functionality for navigation.
    • goToManager

      public void goToManager()
      Navigates to the manager screen of the application. Resets the table offset to 0 and initializes the back button functionality for navigation.
    • goToTemplate

      public void goToTemplate()
      Navigates to the database viewer screen of the application. Initializes the back button functionality for navigation.
    • goToReport

      public void goToReport()
      Navigates to the report screen of the application. Initializes the back button functionality for navigation.
    • loadPanda

      public void loadPanda()
      Loads the panda image into the GUI.

      This method checks if the pandaImage object is not null and sets its image to the predefined resource "panda.png".

    • loadBackButton

      public void loadBackButton()
      Loads the back button image if the back button is not null. Sets the image of the back button to a predefined "back.png" resource.
    • loadQuestionButton

      public void loadQuestionButton()
      Loads the question button image from the specified resource path and sets it to the questionButton if it is not null.

      This method retrieves the image asset from the "/assets/question.png" path and applies it to the questionButton UI element. If the questionButton is null, no action is taken.

    • cashierLogic

      public void cashierLogic()
      Manages the logic for the cashier interface, including displaying menu items and handling interactions when items are added to or removed from the cart. This method retrieves the menu items from the database, creates buttons for each item, and adds event handlers for adding items to the cart and removing them from the cart. The total cost is updated dynamically as items are added or removed. The method first clears any existing buttons in the button container. Then it queries the database to get the list of menu items and iteratively creates buttons for each item. When a button is clicked, it adds the corresponding item to the cart. A separate handler is set up to allow the user to remove items from the cart.
    • selectFoodItem

      public String selectFoodItem(MenuItem item) throws SQLException
      Parameters:
      item - a MenuItem that we will add foodItems to
      Returns:
      formatted foodItems that will be displayed in a label
      Throws:
      SQLException - When a menu item is selected, this method is called to call necessary methods and allow the user to add the necessary foodItems to their order. The following logic will generate the required amount of Drink, Entree, Appetizer, Side, and Dessert pages, adding the foodItem objects to the menuItem via the database addFoodItem() method and add the food items under the text label for each menu item in the cart.
    • selectFood

      public String selectFood(MenuItem item, String type) throws SQLException
      Parameters:
      item - MenuItem parameter
      type - String parameter
      Returns:
      formatted foodItems that will be displayed in a label
      Throws:
      SQLException - Helper method that generates the different types of foodItem forms based off the type. Queries database to get accurate foodItems. If someone closed the food item form, createFoodForm() will return null. If this happens, the while loop repeats until a response is received. Once every response is received, we can set foodItemOpen to false, which means we can leave the page and submit orders.
    • createFoodForm

      public String createFoodForm(MenuItem item, ResultSet foods, String title)
      Parameters:
      item - item parameter
      foods - foods parameter
      title - title parameter
      Returns:
      formatted foodItems that will be displayed in a label Helper method that generates the different types of foodItem forms based off the type. Queries database to get accurate foodItems. Generates food form for foodItem selection when a menuItem is pressed. Basic JavaFX stuff, has some CSS to add button effects on hover etc.
    • sendOrder

      public void sendOrder() throws SQLException
      Sends the current order to the database if the food item form is not open and the cart contains items. This method checks if the cart has items and if so, it attempts to place the order with the current timestamp. If the order is successfully placed, a confirmation alert is shown. If the cart is empty, an error alert is displayed. After the order attempt, the cart is cleared, and the total is reset.

      If an SQL exception occurs while attempting to place the order, an error alert is displayed to inform the user of the failure.

      Throws:
      SQLException - if a database access error occurs while placing the order.
    • createAlert

      public void createAlert(String title, String message, String type)
      Creates and displays an alert dialog based on the specified type.

      Generates a food form for food item selection when a menu item is pressed. This method uses JavaFX to create the alert and apply CSS for button effects on hover, depending on the type of alert specified.

      Parameters:
      title - the title of the alert dialog
      message - the message to display in the alert dialog
      type - the type of alert (e.g., "confirmation", "error", "information", "warning", "none")
      Throws:
      IllegalArgumentException - if the specified type is unexpected
    • generatePage

      public void generatePage(String type)
      Parameters:
      type - an input for the type of page generated (orders, employee, etc) This method loads the Template.fxml file and modifies the title, onAction elements of the add / delete buttons, and adds a table to the main body. Basically, it uses the Template FXML file and builds up the employee, menu item, food item, order history, and inventory pages.
    • submitSalesReport

      public void submitSalesReport()
      Submits a sales report based on the specified date range.

      This method retrieves the start and end dates from the text fields, parses them into SQL date objects, and generates a sales report by querying the database. It then creates a bar chart to visualize the total sales for each menu item within the specified date range.

      If the date parsing or database query fails, an error message is printed to the standard error stream.

    • submitXReport

      public void submitXReport() throws ParseException, SQLException
      Submits a request to generate an X report based on the date provided in the `currentDate` text field.

      The method retrieves the current date from the text field, parses it to ensure it is in the format "yyyy-MM-dd", and then uses this date to query the database for total sales by hour of the day. A bar chart is created to visualize the results, displaying hours on the x-axis and total sales on the y-axis.

      Throws:
      ParseException - if the date format is invalid.
      SQLException - if a database access error occurs.
    • submitZReport

      public void submitZReport() throws ParseException, SQLException
      Submits a request to generate a Z report based on the date provided in the `currentDate2` text field.

      Similar to the X report, this method retrieves the current date from the text field, parses it to ensure it is in the "yyyy-MM-dd" format, and then queries the database for total sales by hour of the day. The results are visualized in a bar chart, with hours on the x-axis and total sales on the y-axis.

      Throws:
      ParseException - if the date format is invalid.
      SQLException - if a database access error occurs.
    • goToSalesReport

      public void goToSalesReport()
      Navigates to the Sales Report view by setting its style to visible and hiding the X Report and Z Report views.
    • goToXReport

      public void goToXReport()
      Navigates to the X Report view by setting its style to visible, applying a translation effect, and hiding the Sales Report and Z Report views.
    • goToZReport

      public void goToZReport()
      Navigates to the Z Report view by setting its style to visible, applying a translation effect, and hiding the Sales Report and X Report views.
    • reportInfo

      public void reportInfo()
      Displays an informational alert to guide users on how to enter dates for generating reports.

      This method creates an alert with the title "Report Help" and provides instructions to ensure that dates are entered in the YYYY-MM-DD format. It also suggests trying a different date if no results are returned.

    • generateEmployees

      public void generateEmployees()
      Generates the employee management page. This method sets up the interface for managing employees, including adding, deleting, and navigating through the list of employees. It registers event handlers for buttons found in the scene.
    • generateInventory

      public void generateInventory()
      Generates the inventory management page. This method sets up the interface for managing inventory items, including adding, deleting, and navigating through the list of inventory items. It registers event handlers for buttons found in the scene.
    • generateMenuItems

      public void generateMenuItems()
      Generates the menu item management page. This method sets up the interface for managing menu items, including adding, deleting, and navigating through the list of menu items. It registers event handlers for buttons found in the scene.
    • generateFoodItems

      public void generateFoodItems()
      Generates the food item management page. This method sets up the interface for managing food items, including adding, deleting, and navigating through the list of food items. It registers event handlers for buttons found in the scene.
    • generateOrders

      public void generateOrders()
      Generates the order management page. This method sets up the interface for managing orders, including adding, deleting, and navigating through the list of orders. It registers event handlers for buttons found in the scene.
    • lastOrder

      public void lastOrder()
      Navigates to the previous order in the list, decrementing the table offset if possible. If already at the beginning of the list, an alert is displayed indicating navigation is not possible.
    • nextOrder

      public void nextOrder()
      Navigates to the next order in the list by incrementing the table offset. Updates the displayed list of orders accordingly.
    • lastEmployee

      public void lastEmployee()
      Navigates to the previous employee in the list, decrementing the table offset if possible. If already at the beginning of the list, an alert is displayed indicating navigation is not possible.
    • nextEmployee

      public void nextEmployee()
      Navigates to the next employee in the list by incrementing the table offset. Updates the displayed list of employees accordingly.
    • lastInventory

      public void lastInventory()
      Navigates to the previous inventory item in the list, decrementing the table offset if possible. If already at the beginning of the list, an alert is displayed indicating navigation is not possible.
    • nextInventory

      public void nextInventory()
      Navigates to the next inventory item in the list by incrementing the table offset. Updates the displayed list of inventory items accordingly.
    • lastMenuItem

      public void lastMenuItem()
      Navigates to the previous menu item in the list, decrementing the table offset if possible. If already at the beginning of the list, an alert is displayed indicating navigation is not possible.
    • nextMenuItem

      public void nextMenuItem()
      Navigates to the next menu item in the list by incrementing the table offset. Updates the displayed list of menu items accordingly.
    • lastFoodItem

      public void lastFoodItem()
      Navigates to the previous food item in the list, decrementing the table offset if possible. If already at the beginning of the list, an alert is displayed indicating navigation is not possible.
    • nextFoodItem

      public void nextFoodItem()
      Navigates to the next food item in the list by incrementing the table offset. Updates the displayed list of food items accordingly.
    • addEmployee

      public void addEmployee()
      Generates a form to add a new employee to the system. The form requires the first name, last name, hours worked, and schedule start and end time.
    • deleteEmployee

      public void deleteEmployee()
      Generates a form to delete an employee from the system. The form requires the employee's ID.
    • addMenuItem

      public void addMenuItem()
      Generates a form to add a new menu item to the system. The form requires the item name, price, and associated food and inventory item IDs.
    • deleteMenuItem

      public void deleteMenuItem()
      Initiates the deletion of a menu item by generating a form to gather input.

      This method creates a form to collect the necessary input for deleting a menu item, specifically requiring the "Menu Item Name". Once the form is generated, the user can submit the name of the menu item they wish to delete.

      The form is generated using the generateForm method, and is labeled as "DELETE MENUITEM".

      See Also:
    • addFoodItem

      public void addFoodItem()
      Generates a form to add a new food item to the system. The form requires the food item name, type, and associated inventory item IDs and amounts.
    • deleteFoodItem

      public void deleteFoodItem()
      Generates a form to delete a food item from the system. The form requires the food item name.
    • addInventoryItem

      public void addInventoryItem()
      Generates a form to add a new inventory item to the system. The form requires the inventory item name, quantity, and last restocked date.
    • deleteInventoryItem

      public void deleteInventoryItem()
      Generates a form to delete an inventory item from the system. The form requires the inventory item name.
    • addOrder

      public void addOrder()
      Displays an alert indicating that adding an order cannot be done at the current time.
    • deleteOrder

      public void deleteOrder()
      Displays an alert indicating that deleting an order cannot be done at the current time.
    • editEmployee

      public void editEmployee()
      Generates a form for editing an employee's details.

      This method creates a form that allows the user to edit the details of an employee. The input fields include:

      • Employee ID (Required)
      • Edit First Name (Optional)
      • Edit Last Name (Optional)
      • Edit Hours Worked (Float, Optional)
      • Edit Schedule Start and End Time (HH:MM:SS,HH:MM:SS, Optional)

      After gathering the input, the form is labeled as "EDIT EMPLOYEE".

      See Also:
    • editMenuItem

      public void editMenuItem()
      Generates a form for editing a menu item's details.

      This method creates a form that allows the user to edit the details of a menu item. The input fields include:

      • Menu Item ID (Required)
      • Edit Menu Item Name (Optional)
      • Edit Price (Double, Optional)
      • Edit Food Item IDs (Comma Separated, Optional)
      • Edit Inventory Item IDs (Comma Separated, Optional)

      After gathering the input, the form is labeled as "EDIT MENUITEM".

      See Also:
    • editFoodItem

      public void editFoodItem()
      Generates a form for editing a food item's details.

      This method creates a form that allows the user to edit the details of a food item. The input fields include:

      • Food Item ID (Required)
      • Edit Food Item Name (Optional)
      • Edit Type (Optional)
      • Edit Inventory Item IDs (Comma Separated, Optional)
      • Edit Inventory Amounts (Comma Separated, Optional)

      After gathering the input, the form is labeled as "EDIT FOODITEM".

      See Also:
    • editInventory

      public void editInventory()
      Generates a form for editing an inventory item's details.

      This method creates a form that allows the user to edit the details of an inventory item. The input fields include:

      • Inventory Item ID (Required)
      • Edit Inventory Item Name (Optional)
      • Edit Quantity (Double, Optional)
      • Edit Last Restocked Date (YYYY-MM-DD, Optional)

      After gathering the input, the form is labeled as "EDIT INVENTORY".

      See Also:
    • editOrder

      public void editOrder()
      Displays an alert informing the user that editing an order is not allowed at this time.

      This method creates an alert box with the message "You cannot do that at this time" to inform the user that the functionality for editing an order is currently unavailable.

      See Also:
    • generateForm

      public void generateForm(ArrayList<String> parameters, String action) throws SQLException
      Generates a dynamic form based on the provided parameters and action. This form is displayed in a new stage and allows users to input data corresponding to the specified parameters. Upon submission, the entered data is collected and passed to the editDatabase method along with the action identifier.

      The form consists of labeled text fields for each parameter. Once the user clicks the "Submit" button, the method collects the data from the text fields, closes the form, and attempts to update the database with the provided information.

      Parameters:
      parameters - a list of parameter labels to be displayed on the form.
      action - a string that represents the action to be performed with the input data (e.g., "ADD EMPLOYEE", "EDIT MENUITEM").
      Throws:
      SQLException - if a database access error occurs while updating the database.
    • editDatabase

      public void editDatabase(ArrayList<String> results, String action) throws SQLException
      Edits the database based on the specified action and the provided results.

      This method processes various actions such as adding, deleting, or editing employees, food items, menu items, and inventory items in the database. It takes an action string that determines the specific database operation to perform and an ArrayList of results containing the necessary data for the operation.

      The method uses a switch-case statement to handle different actions and performs the corresponding database operations using the appropriate methods from the database object. After each operation, it regenerates the relevant lists (e.g., employees, food items, menu items, inventory) to reflect the changes in the database.

      Parameters:
      results - an ArrayList of strings containing data needed for the specified action. The contents and format of this list depend on the action being performed.
      action - a string that specifies the type of database operation to perform, such as "ADD EMPLOYEE", "DELETE EMPLOYEE", "ADD FOODITEM", etc.
      Throws:
      SQLException - if there is an error executing any database operation
    • main

      public static void main(String[] args)
      The entry point of the application. Launches the JavaFX application by invoking the launch method with the provided arguments.
      Parameters:
      args - command-line arguments passed to the application