コード例 #1
0
  public void view(ActionEvent actionEvent) {

    Alert alert = new Alert(Alert.AlertType.INFORMATION, orderArrayToString(), ButtonType.OK);
    alert.setHeaderText("View Order");
    alert.setResizable(true);
    alert.getDialogPane().setPrefWidth(alert.getDialogPane().getWidth() * 2);
    // alert.setContentText(orderString.toString());
    alert.show();
  }
コード例 #2
0
  public void finishOrder(ActionEvent actionEvent) {
    StringBuilder orderString = new StringBuilder();
    // create new alert
    Alert alert = new Alert(Alert.AlertType.INFORMATION, "", ButtonType.OK);
    // get date
    Date date = new Date();
    DateFormat format1 = new SimpleDateFormat("MM/dd/yy hh:mm:ss a z");
    DateFormat format2 = new SimpleDateFormat("yyMMddhhmmss");
    orderString.append(
        String.format(
            "%s\n\nNumber of line items:%d\n\nItem#/ID/Title/Price/Qty/Disc%%/Subtotal:\n\n%s\n\nOrder Subtotal:$%.2f\n\n"
                + "Tax Rate:\t6%%\n\nTax Amount:$%.2f\n\nOrder Total:$%.2f\n\nThanks for shopping!",
            format1.format(date),
            myOrders.size(),
            orderArrayToString(),
            Order.getRunningTotal(),
            Order.getRunningTotal() * .06,
            Order.getRunningTotal() + Order.getRunningTotal() * .06));

    // print order array
    // print subtotal
    // print 6% tax
    // add tax and generate new total
    // show alert
    // call new order

    alert.setHeaderText("Order Receipt");
    alert.setResizable(true);
    alert.getDialogPane().setPrefWidth(alert.getDialogPane().getWidth() * 2);
    alert.setContentText(orderString.toString());
    alert.show();

    // output transactions.txt
    OpenOption[] options = {
      StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.APPEND
    };
    Path file = Paths.get("transaction.txt");

    try {
      BufferedWriter writer = Files.newBufferedWriter(file, Charset.defaultCharset(), options);

      int i = 0;
      for (Order order : myOrders) {
        // String[] strArray = order.toString().split(" ");
        // System.out.println(strArray[0] + strArray[1]);
        writer.write(
            String.format(
                "%s, %s, %s, %s, %s, %s, %s, %s\n",
                format2.format(date),
                order.getOrderedBook().getBookID(),
                order.getOrderedBook().getBookTitle(),
                order.getOrderedBook().getPrice(),
                order.getQuantity(),
                order.getDiscount(),
                order.getFinalPrice(),
                format1.format(date)));
      }

      writer.close();
    } catch (IOException e) {
      System.out.println("OOPS");
      e.printStackTrace();
    }

    newOrder(new ActionEvent());
  }