def do_add_employee(self, line):
        """
        Syntax: add_employee [employee id]
        Starts the process to add a new employee to the current datasource
        parameters:
            employee id:
                the four digit id of the employee to update. may not exist in
                the datasource yet, must be 1 letter and three numbers, e.g.
                "A123"
        output:
            after the process is finished, all information about the new
            employee is displayed
        """
        if not IV.validate_input_employee_id(line):
            self.do_help("add_employee")
            return False

        new_emp_id = line

        if dataHandler.employee_exists(new_emp_id, self._datasource):
            print("An employee with this id already exists.")
            return False

        inputs = {
            "gender": "gender",
            "sales": "sales performance (0-999)",
            "bmi": "bmi (normal, overweight, obesity, underweight)",
            "salary": "salary (0-999)",
            "birthday": "birthday (dd-mm-yyyy)",
            "age": "age (0-99)"
        }

        prompt = "Please enter the new employee's {}: "

        for k in inputs.keys():
            val = input(prompt.format(inputs[k]))
            while not IV.validate_input(val, k):
                print("There was an error. Please check your input.")
                val = input(prompt.format(inputs[k]))
            inputs[k] = IC.convert_input(val, k)

        inputs["empid"] = new_emp_id

        new_emp = employee.create_employee(inputs)

        dataHandler.save_employee(new_emp, self._datasource)
    def do_update_employee(self, line):
        """
        Syntax: update_employee [employee id]
        Starts the update process for the employee with the selected id
        parameters:
            employee id:
                the four digit id of the employee to update
        output:
            after the process is finished, all old and new information about the
            employee is displayed
        """
        if not IV.validate_input_employee_id(line):
            print("invalid employee id.")
            self.do_help("update_employee")
            return False
        if not dataHandler.employee_exists(line, self._datasource):
            print("employee does not exist.")
            return False
        to_change = dataHandler.get_employee(line, self._datasource)
        print("The employee to change:")
        print(to_change)
        print("If you want to change an attribute, please enter the new value")
        print("To leave an attribute unchanged, leave prompt empty")
        attributes = ["gender", "sales", "bmi", "salary", "birthday", "age"]

        prompt = "Attribute: {} Current: {} Enter new value:\n"
        for a in attributes:
            uin = "XXXXX"
            skip = False
            while not IV.validate_input(uin, a):
                if len(uin) == 0:
                    skip = True
                    break
                uin = input(prompt.format(a, getattr(to_change, a)))
            if not skip:
                uin = IC.convert_input(uin, a)
                setattr(to_change, a, uin)

        print("Updated employee:")
        print(to_change)
        uin = "X"
        while not uin.lower() in ["y", "n"]:
            uin = input("Do you want to accept these changes (y/n)")
        if uin == "y":
            dataHandler.update_employee(to_change, self._datasource)
 def get_all_employees(self):
     """
     reads the file this object was initiated with and returns all contained
     employees as Employee objects in a list
     @params: -
     @return: list of Employee objects, may be empty
     """
     employees = []
     errors = []
     # using file as a resource so I dont forget to close it
     with open(self._file) as source:
         skipped_first = False
         for line in source:
             if not skipped_first:
                 skipped_first = True
                 continue
             if line.startswith(CSV_COMMENT):
                 #print("Encountered comment: " + line)
                 continue
             try:
                 #print("reading line: " + line)
                 split = line.split(",")
                 # TODO: HIGH: validate data
                 emp_id = IC.convert_input(split[0], "empid")
                 gender = IC.convert_input(split[1], "gender")
                 sales = IC.convert_input(split[2], "sales")
                 bmi = IC.convert_input(split[3], "bmi")
                 salary = IC.convert_input(split[4], "salary")
                 bday = IC.convert_input(split[5], "birthday")
                 age = IC.convert_input(split[6], "age")
                 attributes = {
                     "empid": emp_id,
                     "gender": gender,
                     "sales": sales,
                     "bmi": bmi,
                     "salary": salary,
                     "birthday": bday,
                     "age": age
                 }
                 # TODO: high: catch ValueError from employee creation
                 employees.append(employee.create_employee(attributes))
             except Exception as err:
                 errors.append("Error when reading line: {}".format(line))
     [IO.stdErr(e) for e in errors]
     return employees
    def get_all_employees(self):
        command = "SELECT * FROM employees"
        lines = self._execute_command(command)

        employees = []

        for l in lines:
            try:
                parameters = {}
                parameters["empid"] = IC.convert_input(l[0], "empid")
                parameters["gender"] = IC.convert_input(l[1], "gender")
                parameters["age"] = IC.convert_input(l[2], "age")
                parameters["sales"] = IC.convert_input(l[3], "sales")
                parameters["bmi"] = IC.convert_input(l[4], "bmi")
                parameters["salary"] = IC.convert_input(l[5], "salary")
                parameters["birthday"] = IC.convert_input(l[6], "birthday")
                employees.append(employee.create_employee(parameters))
            except Exception as err:
                IO.stdErr("Error in translating database row: " + str(l))
                IO.stdErr(str(err))
                print(parameters)
        return employees