コード例 #1
0
 public void apply() throws IOException {
   try {
     if (addLoginUser) {
       if (!password.equals(passwordConfirm)) {
         sessionManager.addGlobalMessageFatal("Password is not equal to Confirm Password.", null);
         throw new ValidatorException(
             new FacesMessage(
                 FacesMessage.SEVERITY_FATAL,
                 "Password and Confirm Password are not equal.",
                 null));
       }
     }
     if (hasPhoto) {
       String photoName = editWorkInfo.getId() + FileUtil.getSuffix(tmpName);
       FileUtil.renameFile(sessionManager.getPhotoPath(), tmpName, photoName);
       editWorkInfo.setPhotoName(photoName);
     }
     editWorkInfo.setName(firstName + " " + lastName);
     workInfoService.add(editWorkInfo);
     if (addLoginUser) {
       editUser.setPassword(PasswordHash.makePasswordHash(password));
       editUser.getEmployee().setId(editWorkInfo.getId());
       userService.add(editUser);
     }
     clear();
   } catch (IOException e) {
     logger.error("Employee Date update error.", e);
     sessionManager.addGlobalMessageFatal("Employee Data update error.", null);
     throw e;
   }
 }
コード例 #2
0
 public void delete() throws IOException {
   try {
     for (WorkInfoDto employee : selecteds) {
       workInfoService.delete(employee.getId());
     }
     clear();
   } catch (IOException e) {
     logger.error("Employee Date delete error.", e);
     sessionManager.addGlobalMessageFatal("Employee Data delete error.", null);
     throw e;
   }
 }
コード例 #3
0
  public void nameValidate(FacesContext context, UIComponent component, Object value) {
    boolean find = false;
    String name = (String) value;

    for (WorkInfoDto dto : getAllList()) {
      if (dto.getName().equals(name)) {
        find = true;
      }
    }
    if (!find) {
      throw new ValidatorException(
          new FacesMessage(FacesMessage.SEVERITY_FATAL, "Employee Name doesn't exist.", null));
    }
  }
コード例 #4
0
 public List<String> completeEmployeeName(String query) {
   ArrayList<String> filterList = new ArrayList<String>();
   if (baseList == null) {
     try {
       baseList = workInfoService.getAllList(condition.genQuery());
       listModel = new WorkInfoListModel(baseList);
     } catch (IOException e) {
       throw new RuntimeException(e);
     }
   }
   for (WorkInfoDto dto : baseList) {
     if (dto.getName().toLowerCase().contains(query.toLowerCase())) filterList.add(dto.getName());
   }
   return filterList;
 }
コード例 #5
0
 private void setEmployeeValue(String lable, String content, WorkInfoDto e) throws IOException {
   lable = lable.toLowerCase();
   if (lable.equals("id")) {
     e.setId(content);
   } else if (lable.equals("name")) {
     e.setName(content);
   } else if (lable.equals("phone")) {
     e.setPhone(content);
   } else if (lable.equals("email")) {
     e.setEmail(content);
   } else if (lable.equals("job title")) {
     e.setJobTitle(jobTitleService.findByName(content));
   } else if (lable.equals("sub unit")) {
     e.setDepartment(departmentService.findByName(content));
   } else if (lable.equals("employment status")) {
     e.setStatus(statusService.findByName(content));
   } else if (lable.equals("job category")) {
     e.setJobCategory(jobCategoryService.findByName(content));
   }
 }
コード例 #6
0
 private boolean exist(String id) {
   for (WorkInfoDto dto : getAllList()) {
     if (dto.getId().equals(id)) return true;
   }
   return false;
 }
コード例 #7
0
  private ArrayList<WorkInfoDto> readExcelFromInputstream(InputStream inputstream) {

    //		// HSSFWorkbook wb = new HSSFWorkbook(new
    //		// FileInputStream("e:\\workbook.xls"));
    //		// HSSFSheet sheet = wb.getSheetAt(0);
    //		//
    //		// for (Iterator<Row> iter = (Iterator<Row>) sheet.rowIterator();
    //		// iter.hasNext();) {
    //		// Row row = iter.next();
    //		// for (Iterator<Cell> iter2 = (Iterator<Cell>) row.cellIterator();
    //		// iter2.hasNext();) {
    //		// Cell cell = iter2.next();
    //		// String content = cell.getStringCellValue();// 除非是sring类型,否则这样迭代读取会有错误
    //		// System.out.println(content);
    //		HSSFWorkbook rwb = null;
    //		try {
    //
    //			rwb = new HSSFWorkbook(inputstream);
    //			HSSFSheet st = rwb.getSheetAt(0);
    //			if (st != null) {
    //				ArrayList<WorkInfoDto> list = new ArrayList<WorkInfoDto>();
    //				ArrayList<String> lables = new ArrayList<String>();
    //				boolean first = true;
    //				for (Iterator<Row> iter = st.rowIterator(); iter.hasNext();) {
    //					Row row = iter.next();
    //					if (first) {
    //						for (Iterator<Cell> iter2 = row.cellIterator(); iter2
    //								.hasNext();) {
    //							Cell cell = iter2.next();
    //							lables.add(cell.getStringCellValue());
    //						}
    //						first = false;
    //					}
    //
    //					else {
    //						int j = 0;
    //						WorkInfoDto e = new WorkInfoDto();
    //						for (Iterator<Cell> iter2 = row.cellIterator(); iter2
    //								.hasNext();) {
    //							Cell cell = iter2.next();
    //							String val = "";
    //							if (cell.getCellType() == HSSFCell.CELL_TYPE_BOOLEAN)
    //								val = String
    //										.valueOf(cell.getBooleanCellValue());
    //							else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC)
    //								val = String.valueOf((int) cell
    //										.getNumericCellValue());
    //							else if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING)
    //								val = cell.getStringCellValue();
    //							setEmployeeValue(lables.get(j++), val, e);
    //						}
    //						list.add(e);
    //					}
    //				}
    //				return list;
    //			}
    //		} catch (Exception ex) {
    //			ex.printStackTrace();
    //		} finally {
    //			try {
    //				inputstream.close();
    //			} catch (IOException e) {
    //				e.printStackTrace();
    //			}
    //		}
    //		return null;

    boolean success = true;
    HSSFWorkbook rwb = null;
    try {

      rwb = new HSSFWorkbook(inputstream);
      HSSFSheet st = rwb.getSheetAt(0);
      if (st != null) {
        ArrayList<WorkInfoDto> list = new ArrayList<WorkInfoDto>();
        ArrayList<String> lables = new ArrayList<String>();
        boolean first = true;
        for (Iterator<Row> iter = st.rowIterator(); iter.hasNext(); ) {
          Row row = iter.next();
          if (first) {
            for (Iterator<Cell> iter2 = row.cellIterator(); iter2.hasNext(); ) {
              Cell cell = iter2.next();
              lables.add(cell.getStringCellValue());
            }
            first = false;
          } else {
            int j = 0;
            WorkInfoDto e = new WorkInfoDto();
            boolean complete = true;
            for (Iterator<Cell> iter2 = row.cellIterator(); iter2.hasNext(); ) {
              Cell cell = iter2.next();
              String val = "";
              if (cell.getCellType() == HSSFCell.CELL_TYPE_BOOLEAN)
                val = String.valueOf(cell.getBooleanCellValue());
              else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC)
                val = String.valueOf((int) cell.getNumericCellValue());
              else if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING)
                val = cell.getStringCellValue();
              if (lables.get(j).toLowerCase().equals("id") && exist(val)) {
                System.out.println(lables.get(j) + " : " + val);
                complete = false;
                success = false;
              }
              setEmployeeValue(lables.get(j++), val, e);
            }
            if (complete) list.add(e);
            else {
              sessionManager.addGlobalMessageWarn(
                  "ID: " + e.getId() + " has existed. This employee is not added into system.",
                  null);
              // FacesMessage message = new FacesMessage("ID: " +
              // e.getId() +
              // " has existed. This employee is not added into system.",null);
            }
          }
        }
        if (success)
          sessionManager.addGlobalMessageInfo("The data file is successfully uploaded.", null);
        else
          sessionManager.addGlobalMessageWarn(
              "There are employees that not be added to the system.", null);
        return list;
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    } finally {
      try {
        inputstream.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    return null;
  }