public int createEmployee(Employee employee, List<Skill> selectedSkills) {
   open();
   employee.setId((int) createBasicEmployee(employee));
   for (Skill skill : selectedSkills) {
     addEmployeeSkill(employee, skill);
   }
   close();
   return employee.getId();
 }
 public void removeEmployeeMaterial(Employee employee, Material material) {
   open();
   ContentValues cv = new ContentValues();
   cv.put(EMPLOYEE_ID, employee.getId());
   cv.put(MATERIAL_ID, material.getId());
   myDatabase.delete(
       EMPLOYEE_MATERIAL_TABLE,
       EMPLOYEE_ID + " =? AND " + MATERIAL_ID + " =?",
       new String[] {Integer.toString(employee.getId()), Integer.toString(material.getId())});
   close();
 }
 public void removeEmployeeContext(Employee employee, SkillContext context) {
   open();
   ContentValues cv = new ContentValues();
   cv.put(EMPLOYEE_ID, employee.getId());
   cv.put(CONTEXT_ID, context.getId());
   myDatabase.delete(
       EMPLOYEE_CONTEXT_TABLE,
       EMPLOYEE_ID + " =? AND " + CONTEXT_ID + " =?",
       new String[] {Integer.toString(employee.getId()), Integer.toString(context.getId())});
   close();
 }
 public void removeEmployeeSkill(Employee employee, Skill skill) {
   open();
   ContentValues cv = new ContentValues();
   cv.put(EMPLOYEE_ID, employee.getId());
   cv.put(SKILL_ID, skill.getId());
   myDatabase.delete(
       EMPLOYEE_SKILL_TABLE,
       EMPLOYEE_ID + " =? AND " + SKILL_ID + " =?",
       new String[] {Integer.toString(employee.getId()), Integer.toString(skill.getId())});
   close();
 }
 public void addEmployeeContext(Employee employee, SkillContext context) {
   open();
   ContentValues cv = new ContentValues();
   cv.put(EMPLOYEE_ID, employee.getId());
   cv.put(CONTEXT_ID, context.getId());
   myDatabase.insert(EMPLOYEE_CONTEXT_TABLE, null, cv);
   close();
 }
 public void addEmployeeMaterial(Employee employee, Material material) {
   open();
   ContentValues cv = new ContentValues();
   cv.put(EMPLOYEE_ID, employee.getId());
   cv.put(MATERIAL_ID, material.getId());
   myDatabase.insert(EMPLOYEE_MATERIAL_TABLE, null, cv);
   close();
 }
 public void addEmployeeSkill(Employee employee, Skill skill) {
   open();
   ContentValues cv = new ContentValues();
   cv.put(EMPLOYEE_ID, employee.getId());
   cv.put(SKILL_ID, skill.getId());
   myDatabase.insert(EMPLOYEE_SKILL_TABLE, null, cv);
   close();
 }
 public List<Employee> getEmployeeList() {
   open();
   String[] columns = new String[] {EMPLOYEE_NAME, EMPLOYEE_ID};
   Cursor c = myDatabase.query(EMPLOYEE_TABLE, columns, null, null, null, null, null);
   List<Employee> employees = new ArrayList<Employee>();
   int iTableID = c.getColumnIndex(EMPLOYEE_ID);
   int iId = c.getColumnIndex(EMPLOYEE_NAME);
   if (c != null) {
     for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
       Employee e = new Employee();
       e.setId(c.getInt(iTableID));
       e.setName(c.getString(iId));
       employees.add(e);
     }
   }
   close();
   return employees;
 }
 public Employee getEmployee(int id) {
   open();
   Employee e = new Employee();
   Cursor c =
       myDatabase.rawQuery(
           "SELECT * FROM "
               + EMPLOYEE_TABLE
               + " WHERE "
               + EMPLOYEE_ID
               + " = ? ORDER BY "
               + EMPLOYEE_NAME
               + " ASC",
           new String[] {Integer.toString(id)});
   int iTableId = c.getColumnIndex(EMPLOYEE_ID);
   int iId = c.getColumnIndex(EMPLOYEE_NAME);
   if (c != null) {
     c.moveToFirst();
     e.setId(c.getInt(iTableId));
     e.setName(c.getString(iId));
   }
   close();
   return e;
 }
 /**
  * Update the employee with a new list of selected items
  *
  * @param employee
  * @param selectedItems
  */
 public void updateEmployee(Employee employee, List<? extends DatabaseObject> selectedItems) {
   open();
   updateEmployeeName(employee);
   int employeeId = employee.getId();
   if (selectedItems.get(0) instanceof Skill) {
     List<Skill> employeeSkills = getEmployeeSkills(employeeId);
     for (Skill skill : employeeSkills) {
       if (!alreadyInList(skill, selectedItems)) {
         removeEmployeeSkill(employee, skill);
       }
     }
     for (Object skill : selectedItems) {
       if (!alreadyInList(skill, employeeSkills)) {
         addEmployeeSkill(employee, (Skill) skill);
       }
     }
   } else if (selectedItems.get(0) instanceof Material) {
     List<Material> employeeMaterials = getEmployeeMaterials(employeeId);
     for (Material material : employeeMaterials) {
       if (!alreadyInList(material, selectedItems)) {
         removeEmployeeMaterial(employee, material);
       }
     }
     for (Object material : selectedItems) {
       if (!alreadyInList(material, employeeMaterials)) {
         addEmployeeMaterial(employee, (Material) material);
       }
     }
   } else if (selectedItems.get(0) instanceof SkillContext) {
     List<SkillContext> employeeContexts = getEmployeeContexts(employeeId);
     for (SkillContext context : employeeContexts) {
       if (!alreadyInList(context, selectedItems)) {
         removeEmployeeContext(employee, context);
       }
     }
     for (Object context : selectedItems) {
       if (!alreadyInList(context, employeeContexts)) {
         addEmployeeContext(employee, (SkillContext) context);
       }
     }
   }
   close();
 }
 private void updateEmployeeName(Employee e) {
   ContentValues cv = new ContentValues();
   cv.put(EMPLOYEE_NAME, e.getName());
   myDatabase.update(
       EMPLOYEE_TABLE, cv, EMPLOYEE_ID + "= ?", new String[] {String.valueOf(e.getId())});
 }
 private long createBasicEmployee(Employee e) {
   ContentValues cv = new ContentValues();
   cv.put(EMPLOYEE_NAME, e.getName());
   return myDatabase.insert(EMPLOYEE_TABLE, null, cv);
 }