import file_funcs
from employers import Employers
import human_resource_sys
file_employer = 'employers'
# employee = 'employees'
name = 'name'
password = 'password'
# 登錄注冊界面
def list_login():
print('''
+++++++++++++++++++++++++++++++++++++++++++++++++
+ welcome to human resource system +
+ +
+ 1.register +
+ +
+ 2.login +
+ +
+ 0.exit +
+++++++++++++++++++++++++++++++++++++++++++++++++
''')
cmd = input('>>>>>>>')
if '0' <= cmd <= '2':
return cmd
else:
print('輸入內(nèi)存錯誤宠默!')
return False
def register():
user_name = input('請輸入用戶名:')
# 取出說有的用戶信息阳藻,列表
all_info = file_funcs.get_content(file_employer)
for info in all_info:
# 用戶個人信息辆憔,對象
user = Employers.set_employer(info)
if user_name == user.name:
print('該用戶名已經(jīng)存在蒋失!')
return False
else:
print('用戶名可用!')
pass_word = input('請輸入密碼:')
pass_word2 = input('請再次輸入密碼:')
if pass_word == pass_word2:
new_user = {name: user_name, password: pass_word}
new_employer = Employers.set_employer(new_user)
file_funcs.set_content(file_employer, new_employer.__dict__)
print('注冊成功钻洒!')
return user_name
else:
print('兩次密碼不一致酗昼!')
return False
def login():
user_name = input('請輸入用戶名:')
all_info = file_funcs.get_content(file_employer)
print(all_info)
for info in all_info:
user = Employers.set_employer(info)
if user_name == user.name:
pass_word = input('請輸入密碼:')
if pass_word == user.password:
print('登錄成功!')
return True
else:
print('密碼錯誤闺骚!')
return False
print('用戶名不存在彩扔!')
# 用戶登錄
def main():
while True:
cmd = list_login()
if not cmd:
continue
if cmd == '1':
result = register()
if result:
human_resource_sys.main(result)
if cmd == '2':
login()
if cmd == '0':
exit(0)
if __name__ == '__main__':
main()
employee
class Employees:
"""員工類"""
def __init__(self):
self.name = ''
self._age = 0
self.id = ''
self._salary = 0
self.position = ''
self.department = ''
@property
def age(self):
return self._age
@age.setter
def age(self, age):
if not age.isdigit():
print('輸入數(shù)據(jù)類型錯誤!')
elif 16 < age < 70:
print('不在法定工作年齡內(nèi)!')
else:
self._age = int(age)
@property
def salary(self):
return self._salary
@salary.setter
def salary(self, salary):
if not salary.isdigit():
print('輸入數(shù)據(jù)類型錯誤僻爽!')
else:
self._salary = int(salary)
@classmethod
def set_employee(cls, employee):
new_employee = cls()
for key in employee:
if key == 'age':
new_employee.age = employee[key]
if key == 'salary':
new_employee.salary = employee[key]
new_employee.__setattr__(key, employee[key])
return new_employee
if __name__ == '__main__':
pass
employer
class Employers:
"""雇主類"""
def __init__(self):
self.name = ''
self.password = ''
self.employees = []
@classmethod
def set_employer(cls, employer):
new_employer = cls()
for key in employer:
new_employer.__setattr__(key, employer[key])
return new_employer
if __name__ == '__main__':
pass
文件操作
import json
def get_content(file_name):
try:
with open('./files/' + file_name + '.json', 'r', encoding='utf-8') as f:
content = json.load(f)
except FileNotFoundError:
content = []
return content
def set_content(file_name, new_content):
content = get_content(file_name)
with open('./files/' + file_name + '.json', 'w', encoding='utf-8') as f:
content.append(new_content)
json.dump(content, f)
return True
def reset_content(file_name, new_content):
with open('./files/' + file_name + '.json', 'w', encoding='utf-8') as f:
json.dump(new_content, f)
return True
if __name__ == '__main__':
pass
human resource
import dao
file_employer = 'employers'
def list_human_resource():
print('''
+++++++++++++++++++++++++++++++++++++++++++++++++
+ welcome to human resource system +
+ 1.add new employee +
+ 2.View employee's information by id +
+ 3.del employee by id +
+ 4.view all employees' information +
+ 5.view employees' average age +
+ 6.view the most high salary +
+ 0.exit +
+++++++++++++++++++++++++++++++++++++++++++++++++
''')
user_cmd = input('>>>>>')
if '0' <= user_cmd <= '6':
return user_cmd
else:
print('輸入內(nèi)存錯誤虫碉!')
return False
def human_resource(user_cmd):
while True:
if not user_cmd:
continue
# 添加員工
if user_cmd == '1':
while True:
new_employee = dao.employee_input()
dao.add_employee(file_employer, new_employee, employer_name)
# 判斷是否繼續(xù)或者退出
print('''
1.繼續(xù)添加
2.返回上一層
''')
user_cmd = input('>>>>>')
if user_cmd == '1':
continue
elif user_cmd == '2':
return
else:
print('輸入有誤!')
return
# 查看員工個人信息
if user_cmd == '2':
pass
# 刪除員工
if user_cmd == '3':
pass
# 查看所有員工
if user_cmd == '4':
dao.find_all(employer_name)
# 查看平均年齡
if user_cmd == '5':
pass
# 查看最高工資
if user_cmd == '6':
pass
# 退出程序
if user_cmd == '0':
exit(0)
def main(employer):
global employer_name
employer_name = employer
while True:
human_resource(list_human_resource())
if __name__ == '__main__':
pass