Ejemplo n.º 1
0
  /**
   * Handles input in the WaitingForPhoneNumber state.
   *
   * @param message The string message.
   * @param channel The channel from which the input was received.
   */
  private void handleDisplayingOrderConfirmation(String message, NewOrderInChan channel) {

    // Only one channel to get input.
    switch ((NewOrderInChan) channel) {
      case ICMenuOption:

        // Check which button was pressed.
        if (message.equalsIgnoreCase(NewOrderView.DONE_KEY)) {

          this.active = false;

          if (PizzaDeliverySystem.RUN_WITH_GUI) {
            PDSViewManager.popView();
          }
        }
        break;

      default:
        handleInputError("The input was invalid. Please try again.");
        break;
    }
  }
Ejemplo n.º 2
0
  /**
   * Handles input in the WaitingForPhoneNumber state.
   *
   * @param message The string message.
   * @param channel The channel from which the input was received.
   */
  private void handleWaitingForPhoneNumber(String message, NewOrderInChan channel) {

    // Only one channel to get input.
    switch ((NewOrderInChan) channel) {
      case ICMenuOption:
        // Do nothing
        break;

      case ICCustomerPhone:

        // Check the phone number input for validity.
        if (Customer.isValidPhoneNumber(message)) {

          // Check for the customer in the database.
          Customer foundCust = null;
          for (Customer cust : Customer.getDb().list()) {
            if (cust.getPhoneNumber().equals(message)) {
              foundCust = cust;
              break;
            }
          }

          // Search for the customer in the database.
          if (foundCust != null) {

            // Set this as the current customer for the order
            // and proceed to the displaying order state.
            _currentOrder.setCustomer(foundCust);
            gotoDisplayingOrder();

          } else {

            // If the customer is not in the database, go to the add
            // customer state.
            _currentOrder.getCustomer().setPhoneNumber(message);
            gotoWaitingForCustInfo();
          }

        } else {

          // Report an error.
          handleInputError(
              "<html>Phone numbers must be numeric and 10 characters in length.</html>");
        }
        break;

      case ICBack:

        // Check for a back button.
        if (message.equalsIgnoreCase(NewOrderView.BACK_KEY)) {

          // Set active to false.  In the GUI version, pop the current
          // view.
          this.active = false;

          if (PizzaDeliverySystem.RUN_WITH_GUI) {
            PDSViewManager.popView();
          }
        }
        break;

      default:
        handleInputError("The input was invalid. Please try again.");
        break;
    }
  }