def search_all(self): # Execute the search self.curs.execute("SELECT * FROM employees") # Get the list of all resulting rows results_list = self.curs.fetchall() # A list to hold our matched employees employees = [] # While there are employees in the row list while results_list: # Remove the row from the list employee = results_list.pop() # Build an employee from the row emp = Employee() emp.ein = employee[0] emp.ssn = employee[1] emp.first_name = employee[2] emp.last_name = employee[3] emp.payrate = employee[4] # Add employee to list employees.append(emp) # Reverse ordering of employees since it's backwards employees.reverse() # Returns list of matching employees return employees
def search(self, column, query): # Execute the search # Using different placeholders for columns and data due to sqlite3 qwerks self.curs.execute("SELECT * FROM employees WHERE {}=?".format(column), (query,)) # Get the list of all resulting rows results_list = self.curs.fetchall() # A list to hold our matched employees employees = [] # While there are employees in the row list while results_list: # Remove the row from the list employee = results_list.pop() # Build an employee from the row emp = Employee() emp.ein = employee[0] emp.ssn = employee[1] emp.first_name = employee[2] emp.last_name = employee[3] emp.payrate = employee[4] # Add employee to list employees.append(emp) # Reverse ordering of employees since it's backwards employees.reverse() # Returns list of matching employees return employees
def add_screen(self): # Clear Screen os.system('cls' if os.name == 'nt' else 'clear') print print "HEMS -> Add" print # Create new Employee object employee = Employee() # Get info from user + sanitize employee.ein = self.sanitize_digits(raw_input("Employee Identification Number (EIN): ")) # Check if EIN is already in the system employee_list = self.search('ein', employee.ein) # While there are employees whom match that EIN while employee_list: # Try again print "Input Error! Employee already exists!" employee.ein = self.sanitize_digits(raw_input("Employee Identification Number (EIN): ")) # And re-check employee_list = self.search('ein', employee.ein) employee.ssn = self.sanitize_ssn(raw_input("SSN: ")) employee.first_name = self.sanitize_letters(raw_input("First Name: ")) employee.last_name = self.sanitize_letters(raw_input("Last Name: ")) employee.payrate = self.sanitize_digits(raw_input("Payrate: ")) # Add employee to database self.add(employee) print print "Employee Added" print raw_input("Back (Enter): ")
def remove_screen(self): # Clear Screen os.system('cls' if os.name == 'nt' else 'clear') print print "HEMS -> Remove" print # Create new Employee object employee = Employee() # Get info from user + sanitize employee.ein = self.sanitize_digits(raw_input("Employee Identification Number (EIN): ")) print "ARE YOU SURE YOU WISH TO REMOVE THIS USER?" print "YES - Remove User" print "NO - Do Nothing" print choice = raw_input('Selection (YES[Remove]/NO[Do Nothing]): ') # Input Sanitation good_choices = {"YES", "NO", "N", "no", "n", "0"} while choice not in good_choices: print "Input Error!" choice = raw_input("Selection (YES[Remove]/NO[Do Nothing]): ") # Remove if choice == "YES": # Remove employee from database self.remove(employee.ein) print print "Employee Removed" print else: print raw_input("Back (Enter): ")