public static ArrayList<Customer> getAllCustomers() { ArrayList<Customer> list = new ArrayList<Customer>(); DBHelper db = new DBHelper(); try { String queryString = "SELECT * FROM customer"; ResultSet rs = db.executeQuery(queryString); while (rs.next()) { Customer customer = new Customer(); customer.setId(rs.getInt("id")); customer.setFirstName(rs.getString("first_name")); customer.setLastName(rs.getString("last_name")); customer.setPhone(rs.getString("phone")); customer.setAddress(rs.getString("address")); customer.setZipCode(rs.getInt("zipcode")); customer.setCity(rs.getString("city")); customer.setEmail(rs.getString("email")); customer.setPassword(rs.getString("password")); list.add(customer); } } catch (Exception e) { e.printStackTrace(); } db.close(); return list; }
/** * Returns the customer data. * * @param alias the customer alias * @param passwordHash the customer password-hash * @return the customer * @throws IllegalStateException if the login data is invalid * @throws SQLException if there is a problem with the underlying JDBC connection */ public Customer queryCustomer(final String alias, final byte[] passwordHash) throws SQLException { final Customer customer = new Customer(); synchronized (this.connection) { try (PreparedStatement statement = this.connection.prepareStatement(SQL_SELECT_CUSTOMER)) { statement.setString(1, alias); statement.setBytes(2, passwordHash); try (ResultSet resultSet = statement.executeQuery()) { if (!resultSet.next()) throw new IllegalStateException("customer doesn't exist."); customer.setIdentity(resultSet.getLong("identity")); customer.setAlias(resultSet.getString("alias")); customer.setGivenName(resultSet.getString("givenName")); customer.setFamilyName(resultSet.getString("familyName")); customer.setStreet(resultSet.getString("street")); customer.setPostcode(resultSet.getString("postcode")); customer.setCity(resultSet.getString("city")); customer.setEmail(resultSet.getString("email")); customer.setPhone(resultSet.getString("phone")); } } } return customer; }
public void register(ActionEvent actionEvent) { CustomerDAO cdao = HibernateDAOFactory.instance().getCustomerDAO(); RequestContext context = RequestContext.getCurrentInstance(); FacesMessage msg = null; boolean loggedIn = false; FacesContext fc = FacesContext.getCurrentInstance(); ExternalContext ec = fc.getExternalContext(); if (cdao.checklemail(email)) { Customer cs = new Customer(); cs.setEmail(email); cs.setPass(pass); cs.setFullName(fullName); cs.setAddress(address); cs.setPhone(phone); cs.setVip(vip); cdao.add(cs); loggedIn = true; msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Registe succes! Welcome", email); String url = "index.xhtml"; try { ec.redirect(url); } catch (IOException ex) { } } else { loggedIn = false; msg = new FacesMessage(FacesMessage.SEVERITY_WARN, "Registe Error", "Invalid credentials"); } FacesContext.getCurrentInstance().addMessage(null, msg); context.addCallbackParam("loggedIn", loggedIn); }
public static Customer getCustomer(int id) { Customer customer = new Customer(); DBHelper db = new DBHelper(); try { String queryString = "SELECT * FROM customer WHERE id = " + id; ResultSet rs = db.executeQuery(queryString); if (rs != null && rs.next()) { customer.setId(rs.getInt("id")); customer.setFirstName(rs.getString("first_name")); customer.setLastName(rs.getString("last_name")); customer.setPhone(rs.getString("phone")); customer.setAddress(rs.getString("address")); customer.setZipCode(rs.getInt("zipcode")); customer.setCity(rs.getString("city")); customer.setEmail(rs.getString("email")); customer.setPassword(rs.getString("password")); } db.close(); } catch (Exception e) { e.printStackTrace(); } return customer; }
/** * Get a customer to put in the database * * @param id for the customer * @param warehouse for the customer * @param station for the customer * @return customer */ public Customer getCustomer(int id, Warehouse warehouse, Station station) { Customer customer = new Customer(); customer.setCustomerID(id); customer.setWarehouseID(warehouse.getWarehouseID()); customer.setStationID(station.getStationID()); customer.setFirstName(fnames.get(randInt(0, fnames.size()))); customer.setMiddleInitial(letters[randInt(0, letters.length)]); customer.setLastName(lnames.get(randInt(0, lnames.size()))); customer.setAddress(randAddress()); customer.setCity(cities.get(randInt(0, cities.size()))); customer.setState(states.get(randInt(0, states.size()))); customer.setZip(zips.get(randInt(0, zips.size()))); customer.setPhone(randInt(100, 1000) + "-" + randInt(100, 1000) + "-" + randInt(1000, 10000)); customer.setDateAdded(randDate()); customer.setDiscount(new BigDecimal(randDouble(minDiscount, maxDiscount))); customer.setBalance(new BigDecimal(0)); customer.setTotalPaid(new BigDecimal(0)); customer.setNumPayments(0); customer.setDeliveriesReceived(0); return customer; }