public void orderSorting() {
   for (int i = 0; i < this.order.size(); i++) {
     Order order1 = this.order.get(i);
     for (int p = 0; p < this.order.size(); p++) {
       Order order2 = this.order.get(p);
       int compare = order1.compareTo(order2);
       if (compare % 10 < 2) {
         int order1Index = this.order.indexOf(order1);
         this.order.remove(p);
         this.order.add(p, order1);
         this.order.remove(order1Index);
         this.order.add(order1Index, order2);
         order1 = order2;
       }
     }
   }
   for (int i = 0; i < this.order.size(); i++) {
     Order order1 = this.order.get(i);
     for (int p = 0; p < this.order.size(); p++) {
       Order order2 = this.order.get(p);
       int compare = order1.compareTo(order2);
       if ((compare / 1000 < 2) && (compare % 10 == 0)) {
         int order1Index = this.order.indexOf(order1);
         this.order.remove(p);
         this.order.add(p, order1);
         this.order.remove(order1Index);
         this.order.add(order1Index, order2);
         order1 = order2;
       }
     }
   }
 }
  public void testChanged() throws Exception {

    Order po = OrderMother.makeOrder();
    save(po.getRestaurant());
    save(po);
    final Serializable orderId = po.getId();

    Order detachedOrder = am.detach(po);

    doWithTransaction(
        new TxnCallback() {
          public void execute() throws Exception {
            Order po = (Order) load(Order.class, orderId.toString());
            po.noteSent("msgid", new Date());
            po.accept("x");
          }
        });

    try {
      Order attachedOrder = am.attach(detachedOrder);
      fail("Expected exception");
    } catch (OptimisticLockingFailureException e) {

    }
  }
Example #3
0
  private String buildInvoice() {
    double taxRate = 6;
    String message;

    this.grandTotal = ((taxRate / 100) * this.subtotal) + this.subtotal;

    DateFormat dateFormat = new SimpleDateFormat("dd/MM/YY HH:mm:ss z");
    this.transDate = new Date();

    message = "Date: " + dateFormat.format(this.transDate) + "\n\n";
    message += "Number of line items: " + this.totalItems + "\n\n";
    message += "Item# / ID / Title / Price / Qty / Disc % / Subtotal:\n\n";
    int counter = 0;
    for (Item i : order.getOrder()) {
      counter++;
      message += counter + ". " + i.toString() + "\n";
    }
    message += "\n";
    message += "Order subtotal: " + formatter.format(this.subtotal) + "\n\n";
    message += "Tax rate: " + taxRate + "%\n\n";
    message += "Tax amount: " + formatter.format(((taxRate / 100) * this.subtotal)) + "\n\n";
    message += "Order total: " + formatter.format(this.grandTotal) + "\n\n";
    message += "Thanks for shopping at Funky Town Books\n\n";

    return message;
  }
  public void test() throws Exception {

    Order po = OrderMother.makeOrder();
    save(po.getRestaurant());
    save(po);

    Order detachedOrder = am.detach(po);
    detachedOrder.getVersion();
    detachedOrder.noteSent("msgid", new Date());
    detachedOrder.accept("x");

    Order attachedOrder = am.attach(detachedOrder);
    assertFalse(attachedOrder.isAcknowledgable());
  }
Example #5
0
  /**
   * Get an order to put in the database
   *
   * @param id for the order
   * @param warehouse for the order
   * @param station for the order
   * @param customer for the the order
   * @return order
   */
  public Order getOrder(int id, Warehouse warehouse, Station station, Customer customer) {
    Order order = new Order();

    order.setOrderID(id);
    order.setCustomerID(customer.getCustomerID());
    order.setWarehouseID(warehouse.getWarehouseID());
    order.setStationID(station.getStationID());
    order.setDateOrdered(randDate());
    order.setCompleted(1); // set as completed by default
    order.setNumLineItems(randInt(3, 10)); // number of line items per order

    customer.setDeliveriesReceived(customer.getDeliveriesReceived() + 1);
    customer.setNumPayments(customer.getNumPayments() + 1);

    return order;
  }
Example #6
0
  public void viewOrder() {
    String currentOrder = "";
    int counter = 0;
    for (Item i : order.getOrder()) {
      counter++;
      currentOrder += counter + ". " + i.toString() + "\n";
    }
    Alert alert = new Alert(Alert.AlertType.INFORMATION);
    alert.setTitle("Current Order");
    alert.setHeaderText("Your current order is as follows:");
    alert.setContentText(currentOrder);
    alert.getDialogPane().setStyle(" -fx-max-width:500px; -fx-pref-width: 500px;");

    alert.showAndWait();
  }
Example #7
0
  private String buildTransaction() {
    String transaction = "";
    DateFormat dateFormat;

    for (Item i : order.getOrder()) {
      dateFormat = new SimpleDateFormat("YYMMddHHmmss");
      transaction += dateFormat.format(this.transDate) + ", ";
      transaction +=
          i.getBook().getId() + ", " + i.getBook().getTitle() + ", " + i.getBook().getPriceStr();
      transaction +=
          ", " + i.getQuantity() + ", " + i.getPercentStr() + ", " + i.getTotalStr() + ", ";
      dateFormat = new SimpleDateFormat("dd/MM/YY HH:mm:ss z");
      transaction += dateFormat.format(this.transDate) + newLine;
    }
    return transaction;
  }
Example #8
0
  public void confirmItem() {
    this.subtotal += item.getTotal();
    String subtotalStr = formatter.format(this.subtotal);
    text_bookID.setText("");
    text_quantity.setText("");
    text_subtotal.setText(subtotalStr);

    confirmAlert();

    order.addItem(item);
    this.totalQuantity += item.getQuantity();
    changeItemNumber();
    btn_confirm.setDisable(true);
    btn_view.setDisable(false);
    text_totalItems.setDisable(true);
    item = null;
  }
Example #9
0
  /**
   * Get a line item to put in the database
   *
   * @param id for the line item
   * @param warehouse for the station
   * @param Station station
   * @param Customer customer
   * @param Order order
   * @param ArrayList<Item> itemList
   * @return lineItem
   */
  public LineItem getLineItem(
      int id,
      Warehouse warehouse,
      Station station,
      Customer customer,
      Order order,
      ArrayList<Item> itemList) {
    LineItem lineItem = new LineItem();

    Item item = itemList.get(randInt(0, itemList.size()));

    int numOrdered = randInt(1, 5);

    if (item.getCurrentStock() < numOrdered) return null;

    lineItem.setLineItemID(id);
    lineItem.setOrderID(order.getOrderID());
    lineItem.setItemID(item.getItemID());
    lineItem.setCustomerID(customer.getCustomerID());
    lineItem.setWarehouseID(warehouse.getWarehouseID());
    lineItem.setStationID(station.getStationID());
    lineItem.setNumOrdered(numOrdered);
    lineItem.setAmountDue(item.getPrice().multiply(new BigDecimal(lineItem.getNumOrdered())));
    lineItem.setAmountDue(
        lineItem.getAmountDue().add(station.getSalesTax().multiply(lineItem.getAmountDue())));
    lineItem.setAmountDue(
        lineItem.getAmountDue().subtract(customer.getDiscount().multiply(lineItem.getAmountDue())));
    lineItem.setDateDelivered(randDate());

    item.setNumLineItems(item.getNumLineItems() + 1);
    item.setNumSold(item.getNumSold() + lineItem.getNumOrdered());
    // item.setCurrentStock(item.getCurrentStock() - lineItem.getNumOrdered()); don't modify stock
    // counts for random generation

    customer.setTotalPaid(customer.getTotalPaid().add(lineItem.getAmountDue()));
    station.setTotalSales(station.getTotalSales().add(lineItem.getAmountDue()));
    warehouse.setTotalSales(warehouse.getTotalSales().add(lineItem.getAmountDue()));

    return lineItem;
  }
 // Returns how many request remains
 public int completed(R request) {
   return orderer.completed(request);
 }
 public void start() {
   orderer.start();
 }
 public void add(R request) {
   orderer.add(request);
 }
Example #13
0
  public void run() {
    try {

      DbConnection.dbConn();
      // =============================================================================
      int zalogowany = 0;

      System.out.println("Klient sie podlaczyl");

      // LOG
      Pomoc.writeToFile(
          Serwer.LOGDIRECTORY,
          "threadSerwer.log." + d.toLocaleString().substring(0, 10),
          d.toLocaleString() + ": Watek:" + this.getName() + " " + " -> Klient sie podlaczyl");
      // LOG_END

      while (true) { // glowna petla watka

        // wiadomosc = przychodzace.readObject();
        this.reciveObject();
        wiadomosc = this.getPackage();
        Thread.sleep(2000);

        System.out.println("Sprawdzam parafianina");

        if (wiadomosc instanceof User) {

          System.out.println("Przyszla wiadomosc 1");
          if (((User) wiadomosc).getKindQuery() == 0) {

            // LOG
            Pomoc.writeToFile(
                Serwer.LOGDIRECTORY,
                "threadSerwer.log." + d.toLocaleString().substring(0, 10),
                d.toLocaleString()
                    + ": Watek:"
                    + this.getName()
                    + " "
                    + " -> Klient proboje sie zalogowac");
            // LOG_END

            Statement s = null;
            System.out.println("patrze w baze\n");
            try {
              s =
                  DbConnection.conn
                      .createStatement(); // tworzenie obiektu Statement przesylajacego zapytania do
                                          // bazy conn
              ResultSet dane, u;
              u =
                  s.executeQuery(
                      "Select * from Userr"); // wykonanie kwerendy i przeslanie wynikow do obiektu
                                              // ResultSet

              System.out.println(
                  "przyslane: "
                      + ((User) wiadomosc).getLogin()
                      + " "
                      + ((User) wiadomosc).getPassword());
              while (u.next()) {

                String userr = u.getString("LOGIN");
                String passs = u.getString("PASSWORD");
                String userID = u.getString("ID_USERR");

                System.out.println("pobrane z bazy: " + userr + " " + passs);

                Thread.sleep(2000);

                if (((User) wiadomosc).getLogin().equals(userr)
                    && ((User) wiadomosc).getPassword().equals(passs)) { // tymczasowo

                  System.out.println("dane sie zgadzaja\n ZALOGOWANO");

                  ((User) wiadomosc).setRestriction(1);
                  clientRestriction = 1;

                  ((User) wiadomosc).setQuery("OK+");
                  this.sendObject(wiadomosc); // odpowiedz klasĀ¹ user

                  System.out.println("pobieram dane\n");
                  dane = s.executeQuery("Select * from Parishioner where id_userr=" + userID);
                  dane.next();
                  String name = dane.getString("NAME");
                  String surname = dane.getString("SURNAME");
                  String pesel = dane.getString("PESEL");

                  // System.out.println("pobrane dane "+name+""+surname);

                  Parishioner p = new Parishioner();
                  p.setName(name);
                  p.setSurName(surname);
                  p.setPesel(pesel);
                  p.setAdress(new Adress());
                  p.setRestriction(clientRestriction);
                  p.setQuery("OK+");

                  Thread.sleep(2000);
                  this.sendObject(p); // odpowiedz klasĀ¹ parishioner

                  // LOG
                  Pomoc.writeToFile(
                      Serwer.LOGDIRECTORY,
                      "threadSerwer.log." + d.toLocaleString().substring(0, 10),
                      d.toLocaleString()
                          + ": Watek:"
                          + this.getName()
                          + " "
                          + " -> Klient sie zalogowal");
                  // LOG_END

                  zalogowany = 1;
                }
              }
              if (zalogowany == 0) { // kiedy haslo/login jest zly
                System.out.println("doszlo do konca i wysyla err");
                ((User) wiadomosc).setQuery("ERR");
                this.sendObject(wiadomosc);
              }
            } catch (SQLException e) {
              System.out.println("Blad odczytu z bazy! " + e.toString());
              System.exit(3);
            }
          } // koniec logowania
        } else // konice usera
        if (wiadomosc instanceof Parishioner) {

          if (((Parishioner) wiadomosc).getKindQuery() == -1) {

            ((Parishioner) wiadomosc).setRestriction(0);
            ((Parishioner) wiadomosc).setData("Wylogowano CIE");
            ((Parishioner) wiadomosc).setQuery("OK+");
            this.sendObject(wiadomosc);

            // LOG
            Pomoc.writeToFile(
                Serwer.LOGDIRECTORY,
                "threadSerwer.log." + d.toLocaleString().substring(0, 10),
                d.toLocaleString()
                    + ": Watek:"
                    + this.getName()
                    + " "
                    + " -> Klient sie wylogowal");
            // LOG_END

          } // koniec wylogowywania
        } else if (wiadomosc instanceof Order) {

          /*---------------*/ if (((Order) wiadomosc).getKindQuery() == 1) { // dodanie do bazy
            System.out.println("Przyszla wiadomosc 2"); // tymczasem
            System.out.println(
                "Zamowienie zlozyl: "
                    + ((Order) wiadomosc).getSenderPesel()
                    + " "
                    + ((Order) wiadomosc).getEvent()
                    + "\n"
                    + "Odprawia "
                    + ((Order) wiadomosc).getExecutroPesel()
                    + " Kiedy: "
                    + ((Order) wiadomosc).getBeginDate());

            String sPesel = ((Order) wiadomosc).getSenderPesel();
            String ePesel = ((Order) wiadomosc).getExecutroPesel();
            String event = ((Order) wiadomosc).getEvent();
            String describe = ((Order) wiadomosc).getDescribe();
            Date bDate = ((Order) wiadomosc).getBeginDate();
            Date eDate = ((Order) wiadomosc).getEndDate();

            Statement dod = null;
            dod = DbConnection.conn.createStatement();
            // String dodaj=("insert into orderr values
            // (6,"+event+","+ePesel+","+sPesel+","+describe+"," +
            // "to_date('2003/05/03 21:02:44', 'yyyy/mm/dd hh24:mi:ss'),to_date('2003/05/04
            // 21:02:44', 'yyyy/mm/dd hh24:mi:ss'))");

            String dodaj =
                "INSERT INTO orderr (id_orderr,id_event,odprawiajacy_pesel,zamawiajacy_pesel,describe) VALUES"
                    + "(4,"
                    + event
                    + ","
                    + ePesel
                    + ","
                    + sPesel
                    + ",'"
                    + describe
                    + "')"; // ,to_date('2003/05/03 21:02:44', 'yyyy/mm/dd)";

            // int nr=6;
            // String dodaj="Insert into test1 (id) values"+"("+nr+")";
            System.out.println("zapisuje dane\n");
            try {
              int insertedRows = dod.executeUpdate(dodaj);
              if (insertedRows != 0) System.out.println("dodano");
              else System.out.println("nie dodano");
            } catch (SQLException e1) {

              e1.printStackTrace();
            }

            ((Order) wiadomosc).setData("ZAMOWIENIE ZLOZONE");
            ((Order) wiadomosc).setQuery("OK+");
            Thread.sleep(2000);
            this.sendObject(wiadomosc);

            // LOG
            Pomoc.writeToFile(
                Serwer.LOGDIRECTORY,
                "threadSerwer.log." + d.toLocaleString().substring(0, 10),
                d.toLocaleString()
                    + ": Watek:"
                    + this.getName()
                    + " "
                    + " -> Klient zlozyl zamowienie (wyslano)");
            // LOG_END
          } // koniec skladania zamowienia

          /*--------------*/ if (((Order) wiadomosc).getKindQuery() == 4) { // select z bazy

            LinkedList<Order> orderList = new LinkedList<Order>();

            for (int i = 0; i < 50; i++) orderList.add(new Order());
            orderList.getFirst().setQuery("OK+");
            this.sendObject(orderList);

            Pomoc.writeToFile(
                Serwer.LOGDIRECTORY,
                "threadSerwer.log." + d.toLocaleString().substring(0, 10),
                d.toLocaleString()
                    + ": Watek:"
                    + this.getName()
                    + " "
                    + " -> Klient pobral liste zamowien");
          } // koniec wysylania listy zamowien (docelowo po odczycie z bazy)

        } else System.out.println("Nie rozpoznano");
      }
    } catch (Exception e) {
      System.out.println("Klient sie --odlaczyl");
    } finally {

      try {

        socket.close(); // zamkniecie polaczenia

      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }