private void prepareTestData() {

    car1 = newCar("Black", "0B6 6835", "Škoda", 200.0);
    car2 = newCar("Red", "7B4 0044", "BMW", 500.0);
    car3 = newCar("White", "8B5 0983", "Volkwagen", 300.0);

    customer1 = newCustomer("Vitalii", "Chepeliuk", "Komarov", "5-20-86", "AK 373979");
    customer2 = newCustomer("Juraj", "Kolchak", "Komarov", "5-34-86", "AK 372548");
    customer3 = newCustomer("Martin", "Jirman", "Lazhot", "5-25-87", "AK 251245");

    carManager.addCar(car1);
    carManager.addCar(car2);
    carManager.addCar(car3);

    customerManager.addCustomer(customer1);
    customerManager.addCustomer(customer2);
    customerManager.addCustomer(customer3);

    carWithoutID = newCar("Green", "8B3 9763", "Audi", 400.0);
    carNotInDB = newCar("Blue", "3B6 8463", "Peugeot", 0.0);
    carNotInDB.setID(car3.getID() + 100);

    customerWithoutID = newCustomer("Martin", "Pulec", "Brno", "5-11-24", "AK 897589");
    customerNotInDB = newCustomer("Lukas", "Rucka", "Brno", "5-21-06", "AK 256354");
    customerNotInDB.setID(customer3.getID() + 100);
    customerNotInDB.setActive(true);
  }
 public static Customer addOrdersFromDB(Customer c) {
   Customer newCustomer = new Customer(c.getID());
   List<Order> orders = orderDAO.retrieveOrders(c);
   for (Order o : orders) {
     newCustomer.addOrder(o);
   }
   return newCustomer;
 }
Esempio n. 3
0
  public static ArrayList<Reservation> getReservations(Show[] shows, Customer[] customers) {
    Logger.log("Database.getReservations");
    ArrayList<Reservation> reservations = new ArrayList<Reservation>();
    try {
      ArrayList<Reservation> tempReservations = new ArrayList<Reservation>();
      Show show = null;
      Customer customer = null;

      ResultSet rs = query("SELECT COUNT(*) FROM reservation");
      rs.next();

      rs = query("SELECT * FROM reservation");
      while (rs.next()) {
        ArrayList<Point> position = new ArrayList<Point>();
        for (Show s : shows) {
          if (s.getID() == rs.getInt("forestilling_id")) {
            show = s;
          }
        }
        position.add(new Point(rs.getInt("pos_x"), rs.getInt("pos_y")));
        for (Customer c : customers) {
          if (c.getID() == rs.getInt("kunde_id")) {
            customer = c;
          }
        }
        tempReservations.add(
            new Reservation(show, position, customer, rs.getInt("reservation_id")));
      }
      // Merge all reservations which have the same show AND customer and save them in reservations
      // list
      while (tempReservations.size() != 0) {
        Customer cus = tempReservations.get(0).getCustomer();
        Show s = tempReservations.get(0).getShow();
        ArrayList<Point> seats = new ArrayList<Point>();
        int ID = tempReservations.get(0).getID();
        for (int x = 0; x < tempReservations.size(); x++) {
          if (tempReservations.get(x).getCustomer() == cus
              && tempReservations.get(x).getShow() == s) {
            seats.add(tempReservations.get(x).getFirstPos());
            tempReservations.remove(tempReservations.get(x));
            // After deleting the object, decrease x with 1 (else one element would never be
            // reached)
            x--;
          }
        }
        reservations.add(new Reservation(s, seats, cus, ID));
      }

    } catch (SQLException exception) {
      Logger.log(exception, "Database:getReservations");
    }
    Logger.log("Database.getReservations");
    return reservations;
  }
Esempio n. 4
0
 public static boolean createReservation(Show show, Point[] points, Customer c) {
   Logger.log("Database.createReservation");
   String sql = "";
   for (Point seat : points) {
     sql =
         "INSERT INTO reservation(forestilling_id, pos_x, pos_y, kunde_id) VALUES ("
             + show.getID()
             + ","
             + seat.x
             + ","
             + seat.y
             + ","
             + c.getID()
             + ");";
     if (update(sql)) {
       continue;
     }
     return false;
   }
   Logger.log("Database.createReservation");
   return true;
 }
 public static List<Order> retrieveUnpaidOrders(Customer customer) {
   List<Order> orders = orderDAO.retrieveUnpaidOrders(customer.getID());
   return orders;
 }
Esempio n. 6
0
 public Order(Customer payerID, int orderNumber) {
   this.orderNumber = orderNumber;
   this.payerID = payerID.getID();
   date.clear(Calendar.MILLISECOND); // The milliseconds variable makes one unit test fail
 }
Esempio n. 7
0
 public Order(Customer payerID) {
   orderNumber = 0 + increment;
   increment++;
   this.payerID = payerID.getID();
   date.clear(Calendar.MILLISECOND); // The milliseconds variable makes one unit test fail
 }