Esempio n. 1
0
  public ProductStatsScreen(Session session) {
    super(session);
    headerBox = new CLIObject(WIDTH, 2);
    headerBox.setLine(
        0, " Previous (<)                 Product Statistics                            ");
    headerBox.setLine(
        1, " ---------------------------------------------------------------------------");

    listBox = new CLIObject(WIDTH, 5);
    listBox.setLine(
        0, "                                                                           ");
    listBox.setLine(1, " |X| List all products (a)");
    listBox.setLine(2, " | | List products by customer login (c)         customer: __________");
    listBox.setLine(
        3, "                                                                           ");
    listBox.setLine(
        4, " --------------------------------------------------------------------------");

    productsBox = new CLIObject(WIDTH, 13);
    productsBox.setLine(0, "");
    productsBox.setLine(1, " No products to show.");
    for (int i = 2; i < 13; i++) {
      productsBox.setLine(i, "");
    }

    listAllProducts = true;
    customerLogin = "";
    curPage = 1;

    setPreparedStatements();

    addScreenObject(headerBox, new Point(originX, originY));
    addScreenObject(listBox, new Point(originX, originY + 2));
    addScreenObject(productsBox, new Point(originX, originY + 7));
  }
Esempio n. 2
0
  public void listProducts() {
    products = new ArrayList<Product>();

    try {
      ResultSet results;

      if (listAllProducts) {
        results = listAllProductsStatement.executeQuery();
      } else {
        listByCustomerStatement.setString(1, customerLogin);
        results = listByCustomerStatement.executeQuery();
      }
      while (results.next()) {
        int auctionId = results.getInt("auction_id");
        Product product = new Product(session.getDb(), auctionId);
        products.add(product);
      }

    } catch (SQLException e) {
      while (e != null) {
        debug.println(e.toString());
        debug.flush();
        e = e.getNextException();
      }
    }

    if (products.size() <= 0) {
      productsBox.setLine(0, "");
      productsBox.setLine(1, " No products to show.");
      for (int i = 2; i < 13; i++) {
        productsBox.setLine(i, "");
      }
    } else {
      productsBox.setLine(0, "      Name | Status | Highest Bid Amount | Buyer or Highest Bidder");
      productsBox.setLine(1, "");
      ArrayList<Product> productsOnPage = paginator.paginate(products, curPage, 5);
      int lineOffset = 0;
      for (int i = 0; i < productsOnPage.size(); i++) {
        Product product = productsOnPage.get(i);
        // lineOffset works now
        lineOffset = i * 2;
        productsBox.setLine(
            lineOffset + 3,
            " "
                + product.name
                + " | "
                + product.status
                + " | $"
                + product.amount
                + " | "
                + product.getHighestBidder());
      }
      // clear the lines of productBox if there are not as many products as before
      int lastLine = productsOnPage.size() * 2 + 2;
      for (int i = lastLine; i < 12; i++) {
        productsBox.setLine(i, "");
      }
      productsBox.setLine(12, paginator.getPageMenu(products, curPage, 5));
    }
  }
Esempio n. 3
0
 public int run() {
   reset();
   draw();
   boolean finished = false;
   while (!finished) {
     String option = getInput();
     if (option.equals("<")) {
       finished = true;
     }
     if (option.equals("c")) {
       listAllProducts = false;
       listBox.setLine(1, " | | List all products (a)");
       listBox.setLine(2, " |X| List products by customer login (c)         customer: |_________");
       draw();
       String customer = getInput();
       if (customer.equals("<")) {
         finished = true;
       }
       while (!checkCustomer(customer)) {
         updateStatus(customer + " is not a valid customer login, please enter another. ");
         draw();
         customer = getInput();
         if (customer.equals("<")) {
           return ADMIN;
         }
       }
       updateStatus("");
       listBox.setLine(
           2, " |X| List products by customer login (c)         customer: " + customer);
       customerLogin = customer;
       curPage = 1;
     } else if (option.equals("a")) {
       listBox.setLine(1, " |X| List all products (a)");
       listBox.setLine(2, " | | List products by customer login (c)         customer: __________");
       listAllProducts = true;
       curPage = 1;
     } else if (option.startsWith("p")) {
       option = option.substring(1, option.length());
       curPage = Integer.parseInt(option);
     }
     listProducts();
     draw();
   }
   return ADMIN;
 }