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 handleWaitingForCustInfo(String message, NewOrderInChan channel) {

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

      case ICCustomerPhone:

        // Check if the string is a valid phone number.  If so, set
        // it as the new phone number.
        if (Customer.isValidPhoneNumber(message)) {

          _currentOrder.getCustomer().setPhoneNumber(message);
        }
        break;

      case ICCustomerName:

        // Set the new string as the name.
        _currentOrder.getCustomer().setName(message);
        break;

      case ICCustomerAddress:

        // Check that the address is valid.
        Address addr = Address.getAddressForAlias(message);
        if (null == addr) {

          // Do nothing.

        } else {

          _currentOrder.getCustomer().setStreetAddress(addr);

          // If we got a valid address, the customer should
          // be done being detailed.  Add this new customer
          // to the database and proceed to the order construction
          // state.
          Customer.getDb().add(_currentOrder.getCustomer());
          gotoDisplayingOrder();
        }
        break;

      case ICBack:

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

          // Go back to the customer phone number prompt.
          gotoWaitingForPhoneNumber();
        }
        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;
    }
  }