示例#1
0
文件: PersonDAO.java 项目: pkkann/his
  public int saveGuest(Person p, Guest g) throws SQLException {
    conn = DBTool.getInstance();

    System.out.println("Saving guest...");
    if (conn.isValid(10000)) {
      Statement s = conn.createStatement();

      int idPerson = p.getId();

      String guestFirstname = g.getFirstname();
      String guestMiddlename = g.getMiddlename();
      String guestLastname = g.getLastname();
      String guestBirthday = ADate.formatADate(g.getBirthday(), "");
      String guestCreationdate = ADate.formatADate(g.getCreationDate(), "");

      s.execute(
          "INSERT INTO guest (firstname, middlename, lastname, creationdate, birthday, idperson) VALUES('"
              + guestFirstname
              + "', '"
              + guestMiddlename
              + "', '"
              + guestLastname
              + "', '"
              + guestCreationdate
              + "', '"
              + guestBirthday
              + "', '"
              + idPerson
              + "');");
      ResultSet rs = s.executeQuery("SELECT LAST_INSERT_ID();");
      rs.next();
      int returnId = rs.getInt(1);
      System.out.println("Save complete!");
      rs.close();
      s.close();
      conn.close();
      return returnId;
    } else {
      System.out.println("Connection not valid");
      conn.close();
      return -1;
    }
  }
示例#2
0
  /**
   * *@purpose : To create a new guest *@param : Guest guestobject, Strig cineplexname *@return :
   * void
   */
  @SuppressWarnings("unchecked")
  public void createNewGuest(Guest guest, String cineplexName) {
    JSONArray jsonGuests = (JSONArray) jsonObject.get("guests");
    boolean exists = false;
    for (int i = 0; i < this.guests.size(); i++) {
      if (this.guests.get(i).getEmail().equalsIgnoreCase(guest.getEmail())
          && this.guests.get(i).getMobileNo() == guest.getMobileNo()
          && this.guests.get(i).getCineplexName().equals(cineplexName)) {
        // System.out.println("Account already exists");
        exists = true;
        break;
      }
    }
    if (!exists) {
      JSONObject jsonGuest = new JSONObject();
      jsonGuest.put("id", guest.getId().toLowerCase());
      jsonGuest.put("name", guest.getName());
      jsonGuest.put("mobileno", guest.getMobileNo());
      jsonGuest.put("email", guest.getEmail().toLowerCase());
      jsonGuest.put("cineplexname", cineplexName);

      jsonGuests.add(jsonGuest);
    }
    updateFile(JSONDAO.guestPath, this.jsonObject);
  }
示例#3
0
  private void parseJSON(JSONObject jsonObject, boolean INCLUDE_BOOKINGS) {
    if (this.jsonObject != null) {
      JSONArray jsonGuests = (JSONArray) jsonObject.get("guests");
      JSONObject jsonGuest;
      Guest guest;
      for (int i = 0; i < jsonGuests.size(); i++) {
        jsonGuest = (JSONObject) jsonGuests.get(i);
        if (this.guests == null) this.guests = new ArrayList<Guest>();
        guest = new Guest();
        guest.setId(jsonGuest.get("id").toString());
        guest.setName(jsonGuest.get("name").toString());
        guest.setEmail(jsonGuest.get("email").toString());
        guest.setCineplexName(jsonGuest.get("cineplexname").toString());
        guest.setMobileNo(Integer.parseInt(jsonGuest.get("mobileno").toString()));

        if (INCLUDE_BOOKINGS) guest.setBookings(new BookingDAO().getBookingsByGuest(guest));

        this.guests.add(guest);
      }
    }
  }
示例#4
0
文件: PersonDAO.java 项目: pkkann/his
  public ArrayList<Person> getAllPersons() throws SQLException {
    conn = DBTool.getInstance();

    System.out.println("Getting all persons...");
    if (conn.isValid(10000)) {
      Statement s = conn.createStatement();
      ArrayList<Person> persons = new ArrayList<>();

      ResultSet rs = s.executeQuery("SELECT * FROM person");
      while (rs.next()) {
        int idperson = rs.getInt("idperson");
        String firstname = rs.getString("firstname");
        String middlename = rs.getString("middlename");
        String lastname = rs.getString("lastname");
        String address = rs.getString("address");
        ADate birthday = new ADate(rs.getString("birthday"));
        ADate expirationDate = new ADate(rs.getString("expirationdate"));
        File picturePath = new File(rs.getString("picturepath"));
        ADate quarantineExpirationDate = null;
        if (!rs.getString("quarantineexpirationdate").isEmpty()) {
          quarantineExpirationDate = new ADate(rs.getString("quarantineexpirationdate"));
        }
        ADate creationDate = new ADate(rs.getString("creationdate"));
        boolean oneOne = false;
        if (rs.getInt("oneone") == 1) {
          oneOne = true;
        }
        boolean quarantine = false;
        if (rs.getInt("quarantine") == 1) {
          quarantine = true;
        }
        boolean enrolled = false;
        if (rs.getInt("enrolled") == 1) {
          enrolled = true;
        }
        boolean hone = false;
        if (rs.getInt("hone") == 1) {
          hone = true;
        }
        Statement s2 = conn.createStatement();
        ArrayList<Guest> guests = new ArrayList<>();
        ResultSet rsGuest =
            s2.executeQuery("SELECT * FROM guest WHERE idperson = " + idperson + ";");
        while (rsGuest.next()) {
          Guest g =
              new Guest(
                  rsGuest.getString("firstname"),
                  rsGuest.getString("middlename"),
                  rsGuest.getString("lastname"),
                  new ADate(rsGuest.getString("birthday")),
                  new ADate(rsGuest.getString("creationdate")));
          g.setId(rsGuest.getInt("idguest"));
          guests.add(g);
        }

        Person p =
            new Person(
                firstname,
                middlename,
                lastname,
                address,
                birthday,
                expirationDate,
                picturePath,
                creationDate,
                oneOne);
        p.setId(idperson);
        p.setQuarantine(quarantine);
        p.setQuarantineExpirationDate(quarantineExpirationDate);
        p.setEnrolled(enrolled);
        p.setHone(hone);
        p.setGuests(guests);
        persons.add(p);

        rsGuest.close();
        s2.close();
      }
      System.out.println("Get complete!");
      rs.close();
      s.close();
      conn.close();
      return persons;
    } else {
      System.out.println("Connection invalid");
      conn.close();
      return null;
    }
  }