Example #1
0
  public User getUserDetails(String userId) {

    PreparedStatement ps = null;
    ResultSet rs = null;
    User user = null;

    RegisterService registerService = new RegisterService();

    try {

      ps = connection.prepareStatement("SELECT * FROM user WHERE username=? LIMIT 1");
      ps.setString(1, username);
      rs = ps.executeQuery();

      if (rs != null && rs.next()) {
        user = new User(userId);
        user.setFirstName(rs.getString("firstname"));
        user.setLastName(rs.getString("lastname"));
        user.setEmail(rs.getString("email"));
        user.setPhoneNumber(rs.getString("primaryPhone"));
        user.setCellphone(rs.getString("secondaryPhone"));

        user.setAddress(registerService.createAddressFromID(rs.getInt("addressID")));
        user.setCard(registerService.createCardFromID(rs.getInt("creditCardID")));
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }

    return user;
  }
Example #2
0
 public User[] getAllUser() {
   Vector<User> v = new Vector<User>();
   Cursor cursor = null;
   try {
     cursor = db.find("select * from " + TABLENAME, null);
     while (cursor.moveToNext()) {
       User temp = new User();
       temp.setId_DB(cursor.getInt(cursor.getColumnIndex("id_DB")));
       temp.setAddress(cursor.getString(cursor.getColumnIndex(User.ADDRESS)));
       temp.setQq(cursor.getString(cursor.getColumnIndex(User.QQ)));
       temp.setDanwei(cursor.getString(cursor.getColumnIndex(User.DANWEI)));
       temp.setName(cursor.getString(cursor.getColumnIndex(User.NAME)));
       temp.setMobile(cursor.getString(cursor.getColumnIndex(User.MOBILE)));
       v.add(temp);
     }
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     if (cursor != null) cursor.close();
     db.closeConnection();
   }
   if (v.size() > 0) {
     return v.toArray(new User[] {});
   } else {
     User[] users = new User[1];
     User user = new User();
     user.setName("无结果111");
     users[0] = user;
     return users;
   }
 }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {

    int id = item.getItemId();
    switch (id) {
      case 1: // 保存
        if (!nameET.getText().toString().equals("")) {
          User user = new User();
          user.setName(nameET.getText().toString());
          user.setDanwei(danweiET.getText().toString());
          user.setMobile(mobileET.getText().toString());
          user.setQq(qqET.getText().toString());
          user.setAddress(addressET.getText().toString());
          ContactsTable ct = new ContactsTable(this);
          if (ct.addData(user)) {
            Toast.makeText(this, "添加成功!", Toast.LENGTH_LONG).show();
          } else {
            Toast.makeText(this, "添加失败!", Toast.LENGTH_LONG).show();
          }
        } else {
          Toast.makeText(this, "请先输入姓名!", Toast.LENGTH_LONG).show();
        }
        break;
      case 2: // 返回
        finish();
        break;
      default:
        break;
    }

    return super.onOptionsItemSelected(item);
  }
  /**
   * Import users
   *
   * @param nodes list of users nodes (wrapper node, thus only one)
   * @return
   */
  private Boolean processUsers(NodeList nodes) {
    NodeList users = nodes.item(0).getChildNodes();

    for (int i = 0; i < users.getLength(); i++) {
      if (users.item(i).getNodeType() == Node.ELEMENT_NODE) {
        Element userNode = (Element) users.item(i);

        User user = new User();

        user.setIduser(Integer.parseInt(getTagValue("iduser", userNode)));
        user.setForename(getTagValue("forename", userNode));
        user.setSurname(getTagValue("surname", userNode));
        user.setPermitNumber(getTagValue("permitNumber", userNode));
        user.setAddress(getTagValue("address", userNode));
        user.setEmail(getTagValue("email", userNode));
        user.setRegistered(
            DatatypeConverter.parseDateTime(getTagValue("registered", userNode)).getTime());
        user.setExpire(DatatypeConverter.parseDateTime(getTagValue("expire", userNode)).getTime());
        user.setPassword(getTagValue("password", userNode));
        user.setLevel(getTagValue("level", userNode));

        try {
          userMgr.Save(user);
        } catch (EJBException ex) {
          ex.printStackTrace(System.out);
        }
      }
    }
    return true;
  }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
      case 1: // 保存
        if (!nameET.getText().toString().equals("")) {
          user.setName(nameET.getText().toString());
          user.setMobile(mobileET.getText().toString());
          user.setDanwei(danweiET.getText().toString());
          user.setQq(qqET.getText().toString());
          user.setAddress(addressET.getText().toString());
          ContactsTable ct = new ContactsTable(UpdateContactsActivity.this);

          // 修改数据库联系人信息
          if (ct.updateUser(user)) {
            Toast.makeText(UpdateContactsActivity.this, "修改成功!", Toast.LENGTH_SHORT).show();
          } else {
            Toast.makeText(UpdateContactsActivity.this, "修改失败!", Toast.LENGTH_SHORT).show();
          }
        } else {
          Toast.makeText(UpdateContactsActivity.this, "数据不能为空!", Toast.LENGTH_SHORT).show();
        }
        break;
      case 2: // 返回
        finish();
        break;
      default:
        break;
    }
    return super.onOptionsItemSelected(item);
  }
Example #6
0
 private void addManager() throws UserNameExistsException {
   User manager = new User();
   manager.setUserName("root");
   manager.setPassword(Hash.hashString("root"));
   manager.setPhoneNumber("0123456789");
   manager.setEmail("*****@*****.**");
   manager.setAddress("Root street 42.");
   userDAO.insertUser(manager);
 }
Example #7
0
 @Test
 public void testUpdateUser() {
   IUserOperation userOperation = session.getMapper(IUserOperation.class);
   User user = userOperation.selectUserById(7);
   user.setUsername("liangzhuo2");
   user.setAge(25);
   user.setAddress("湖北天门黄潭");
   userOperation.updateUser(user);
 }
Example #8
0
 @Test
 public void testAddUser() {
   User user = new User();
   user.setUsername("liangzhuo");
   user.setAge(26);
   user.setAddress("湖北天门");
   IUserOperation userOperation = session.getMapper(IUserOperation.class);
   userOperation.addUser(user);
 }
Example #9
0
  public void testAddAndRemoveUser() throws Exception {
    User user = new User("testuser");
    user.setPassword("testpass");
    user.setFirstName("Test");
    user.setLastName("Last");
    Address address = new Address();
    address.setCity("Denver");
    address.setProvince("CO");
    address.setCountry("USA");
    address.setPostalCode("80210");
    user.setAddress(address);
    user.setEmail("*****@*****.**");
    user.setWebsite("http://tek42.com");
    user.setTimeZone("US/Central");

    // Here we are creating an org that should already be in the database...
    // Ideally, we somehow have an org object... from the other dao or whatever...
    /*
     * Account org = new Account(); org.setName("Tek42"); org.setId(1L);
     */
    Account org = adao.get(2L);
    System.out.println("Have org: " + org);
    user.setAccount(org);

    Role role = rdao.getRoleByName(Constants.USER_ROLE);
    assertNotNull(role.getId());
    user.addRole(role);

    user = dao.saveUser(user);

    assertNotNull(user.getId());

    user = dao.get(user.getId());

    assertEquals("Vigilant", user.getAccount().getName());
    assertEquals("testpass", user.getPassword());
    assertEquals("US/Central", user.getTimeZone());

    dao.remove(user.getId());

    try {
      dao.get(user.getId());
      fail("getUser didn't throw DataAccessException");
    } catch (DataAccessException d) {
      assertNotNull(d);
    }
  }
Example #10
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    switch (id) {
      case 1:
        if (!nameET.getText().toString().equals("")) {
          User user = new User();
          user.setName(nameET.getText().toString());
          user.setMobile(mobileET.getText().toString());
          user.setDanwei(danweiET.getText().toString());
          user.setQq(qqET.getText().toString());
          user.setAddress(addressET.getText().toString());
          ContactsTable ct = new ContactsTable(this);
          if (ct.addData(user)) {
            Toast.makeText(this, "添加成功", Toast.LENGTH_LONG).show();
          } else {
            Toast.makeText(this, "添加失败", Toast.LENGTH_LONG).show();
          }

        } else {
          Toast.makeText(this, "请先输入姓名", Toast.LENGTH_LONG).show();
        }
        break;
      case 2:
        finish();
        break;
      default:
        break;
    }

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
      return true;
    }

    return super.onOptionsItemSelected(item);
  }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    switch (id) {
      case 1: // 保存
        if (!nameET.getText().toString().equals("")) {
          user.setName(nameET.getText().toString());
          user.setDanwei(danweiET.getText().toString());
          user.setMobile(mobileET.getText().toString());
          user.setQq(qqET.getText().toString());
          user.setAddress(addressET.getText().toString());
          ContactsTable ct = new ContactsTable(UpdateContactsActivity.this);

          // 修改数据库联系人信息
          if (ct.updateUser(user)) {
            Toast.makeText(UpdateContactsActivity.this, "修改成功!", Toast.LENGTH_LONG).show();
          } else {
            Toast.makeText(UpdateContactsActivity.this, "修改失败!", Toast.LENGTH_LONG).show();
          }
        } else {
          Toast.makeText(UpdateContactsActivity.this, "数据不能为空!", Toast.LENGTH_LONG).show();
        }
        break;
      case 2: // 返回
        finish();
        break;
      default:
        break;
    }
    /*//noinspection SimplifiableIfStatement
            if (id == R.id.action_settings) {
                return true;
            }
    */
    return super.onOptionsItemSelected(item);
  }
  public User getUser(MySqlHelper helper, String userName, String password) {
    User user = new User();
    String query =
        "select * "
            + "from login u inner join address a on u.UserId = a.UserId "
            + "inner join personalinfo p on a.AddressId = p.AddressId "
            + "where Email=? and Password= ?";
    System.out.println(query);
    System.out.println("u=" + userName + " p=" + password);
    try {
      java.sql.PreparedStatement loginPreparedStatement =
          helper.conn.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
      loginPreparedStatement.setString(1, userName);
      loginPreparedStatement.setString(2, password);
      ResultSet rs = loginPreparedStatement.executeQuery();
      while (rs.next()) {
        user.setFirstName(rs.getString("FirstName"));
        user.setLastName(rs.getString("LastName"));
        user.setUserType(Integer.toString(rs.getInt("UserTypeId")));
        user.setEmail(rs.getString("Email"));

        Address address = new Address();
        address.setAddressLine1(rs.getString("AddressLine1"));
        address.setAddressLine2(rs.getString("AddressLine2"));
        address.setCity(rs.getString("City"));
        address.setState(rs.getString("State"));
        address.setZipCode(rs.getString("ZipCode"));
        address.setLattitude(rs.getString("Lattitude"));
        address.setLongitude(rs.getString("Longitude"));

        user.setAddress(address);

        user.setPhoneNumber(rs.getString("PhoneNumber"));
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    return user;
  }
Example #13
0
 public User getUserByID(int id) {
   Cursor cursor = null;
   try {
     cursor = db.find("select * from " + TABLENAME + " where id_DB=?", new String[] {id + ""});
     User temp = new User();
     cursor.moveToNext();
     temp.setId_DB(cursor.getInt(cursor.getColumnIndex("id_DB")));
     temp.setAddress(cursor.getString(cursor.getColumnIndex(User.ADDRESS)));
     temp.setQq(cursor.getString(cursor.getColumnIndex(User.QQ)));
     temp.setDanwei(cursor.getString(cursor.getColumnIndex(User.DANWEI)));
     temp.setMobile(cursor.getString(cursor.getColumnIndex(User.MOBILE)));
     temp.setName(cursor.getString(cursor.getColumnIndex(User.NAME)));
     return temp;
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     if (cursor != null) {
       cursor.close();
     }
     db.closeConnection();
   }
   return null;
 }
Example #14
0
  @Test
  public void testSaveSingleObjectWithNoTypeAndOneContainment() {
    JsonNode expected =
        mapper
            .createObjectNode()
            .put("userId", "1")
            .put("name", "Paul")
            .set("address", mapper.createObjectNode().put("addId", "a1").put("city", "Prague"));

    User u1 = ModelFactory.eINSTANCE.createUser();
    u1.setUserId("1");
    u1.setName("Paul");

    Address add = ModelFactory.eINSTANCE.createAddress();
    add.setAddId("a1");
    add.setCity("Prague");

    u1.setAddress(add);

    JsonNode result = mapper.valueToTree(u1);

    assertEquals(expected, result);
  }
Example #15
0
 private void addUsers() throws IOException {
   RandomAccessFile f = new RandomAccessFile("randomUser.csv", "r");
   String dataString = null;
   ResourceType type = null;
   try {
     type = resourceTypeDAO.getResourceTypeByResourceTypeName("human");
   } catch (Exception e) {
     System.err.println(e);
   }
   ArrayList<Group> groups = null;
   Random random = new Random(1l);
   try {
     groups = groupDAO.getAllGroups();
   } catch (DAOException e1) {
     e1.printStackTrace();
   }
   while ((dataString = f.readLine()) != null) {
     String[] data = dataString.split(";");
     User insert = new User();
     if (data[0].length() < 45) {
       insert.setUserName(data[0]);
     } else {
       insert.setUserName(data[0].substring(0, 44));
     }
     insert.setPassword(Hash.hashString(data[1]));
     if (data[2].length() < 15) {
       insert.setPhoneNumber(data[2]);
     } else {
       insert.setPhoneNumber(data[2].substring(0, 14));
     }
     if (data[3].length() < 45) {
       insert.setEmail(data[3]);
     } else {
       insert.setEmail(data[3].substring(0, 44));
     }
     if (data[4].length() < 45) {
       insert.setAddress(data[4]);
     } else {
       insert.setAddress(data[4].substring(0, 44));
     }
     Resource pair = new Resource();
     pair.setActive(true);
     pair.setDescription("");
     pair.setResourceTypeID(type.getResourceTypeID());
     pair.setResourceName(data[5]);
     System.out.println(insert);
     try {
       userDAO.insertUser(insert);
       resourceDAO.insertResource(pair);
       resourceDAO.linkResourceToUser(pair, insert);
     } catch (Exception e) {
       e.printStackTrace();
     }
     for (int i = 0; i < 3; ++i) {
       try {
         resourceDAO.addResourceToGroup(pair, groups.get(random.nextInt(groups.size())));
       } catch (DAOException e) {
         System.out.println(
             "Resource already added to group, but don't worry, there are plenty to choose from");
       }
     }
   }
   f.close();
 }
Example #16
0
 public void updateUsrById(User u) {
   int id = u.getId();
   User u2 = findById(id);
   u2.setAddress(u.getAddress());
   u2.setCode(u.getCode());
 }