写一个Python编码 企业员工信息管理系统 建立一个企业信息管理系统实现以下功能 1、企业有:业务部10人,技术部5人,人事部3人,行政部2人,信息部2人(人名自拟) 2、模仿课件第8章,学生信息管理系统,实现企业员工信息的增删改查,增删改查要具体到相应部门。
时间: 2023-05-14 18:06:07 浏览: 113
以下是 Python 代码实现企业员工信息管理系统:
```python
class Employee:
def __init__(self, name, department):
self.name = name
self.department = department
class BusinessDepartment:
def __init__(self):
self.employees = []
def add_employee(self, name):
employee = Employee(name, "业务部")
self.employees.append(employee)
def remove_employee(self, name):
for employee in self.employees:
if employee.name == name:
self.employees.remove(employee)
return True
return False
def update_employee(self, old_name, new_name):
for employee in self.employees:
if employee.name == old_name:
employee.name = new_name
return True
return False
def search_employee(self, name):
for employee in self.employees:
if employee.name == name:
return employee
return None
class TechnologyDepartment:
def __init__(self):
self.employees = []
def add_employee(self, name):
employee = Employee(name, "技术部")
self.employees.append(employee)
def remove_employee(self, name):
for employee in self.employees:
if employee.name == name:
self.employees.remove(employee)
return True
return False
def update_employee(self, old_name, new_name):
for employee in self.employees:
if employee.name == old_name:
employee.name = new_name
return True
return False
def search_employee(self, name):
for employee in self.employees:
if employee.name == name:
return employee
return None
class PersonnelDepartment:
def __init__(self):
self.employees = []
def add_employee(self, name):
employee = Employee(name, "人事部")
self.employees.append(employee)
def remove_employee(self, name):
for employee in self.employees:
if employee.name == name:
self.employees.remove(employee)
return True
return False
def update_employee(self, old_name, new_name):
for employee in self.employees:
if employee.name == old_name:
employee.name = new_name
return True
return False
def search_employee(self, name):
for employee in self.employees:
if employee.name == name:
return employee
return None
class AdministrationDepartment:
def __init__(self):
self.employees = []
def add_employee(self, name):
employee = Employee(name, "行政部")
self.employees.append(employee)
def remove_employee(self, name):
for employee in self.employees:
if employee.name == name:
self.employees.remove(employee)
return True
return False
def update_employee(self, old_name, new_name):
for employee in self.employees:
if employee.name == old_name:
employee.name = new_name
return True
return False
def search_employee(self, name):
for employee in self.employees:
if employee.name == name:
return employee
return None
class InformationDepartment:
def __init__(self):
self.employees = []
def add_employee(self, name):
employee = Employee(name, "信息部")
self.employees.append(employee)
def remove_employee(self, name):
for employee in self.employees:
if employee.name == name:
self.employees.remove(employee)
return True
return False
def update_employee(self, old_name, new_name):
for employee in self.employees:
if employee.name == old_name:
employee.name = new_name
return True
return False
def search_employee(self, name):
for employee in self.employees:
if employee.name == name:
return employee
return None
class Company:
def __init__(self):
self.business_department = BusinessDepartment()
self.technology_department = TechnologyDepartment()
self.personnel_department = PersonnelDepartment()
self.administration_department = AdministrationDepartment()
self.information_department = InformationDepartment()
def add_employee(self, name, department):
if department == "业务部":
self.business_department.add_employee(name)
elif department == "技术部":
self.technology_department.add_employee(name)
elif department == "人事部":
self.personnel_department.add_employee(name)
elif department == "行政部":
self.administration_department.add_employee(name)
elif department == "信息部":
self.information_department.add_employee(name)
def remove_employee(self, name, department):
if department == "业务部":
return self.business_department.remove_employee(name)
elif department == "技术部":
return self.technology_department.remove_employee(name)
elif department == "人事部":
return self.personnel_department.remove_employee(name)
elif department == "行政部":
return self.administration_department.remove_employee(name)
elif department == "信息部":
return self.information_department.remove_employee(name)
def update_employee(self, old_name, new_name, department):
if department == "业务部":
return self.business_department.update_employee(old_name, new_name)
elif department == "技术部":
return self.technology_department.update_employee(old_name, new_name)
elif department == "人事部":
return self.personnel_department.update_employee(old_name, new_name)
elif department == "行政部":
return self.administration_department.update_employee(old_name, new_name)
elif department == "信息部":
return self.information_department.update_employee(old_name, new_name)
def search_employee(self, name, department):
if department == "业务部":
return self.business_department.search_employee(name)
elif department == "技术部":
return self.technology_department.search_employee(name)
elif department == "人事部":
return self.personnel_department.search_employee(name)
elif department == "行政部":
return self.administration_department.search_employee(name)
elif department == "信息部":
return self.information_department.search_employee(name)
company = Company()
company.add_employee("张三", "业务部")
company.add_employee("李四", "技术部")
company.add_employee("王五", "人事部")
company.add_employee("赵六", "行政部")
company.add_employee("钱七", "信息部")
print(company.search_employee("张三", "业务部").name)
print(company.search_employee("李四", "技术部").name)
print(company.search_employee("王五", "人事部").name)
print(company.search_employee("赵六", "行政部").name)
print(company.search_employee("钱七", "信息部").name)
company.update_employee("张三", "张三丰", "业务部")
print(company.search_employee("张三丰", "业务部").name)
company.remove_employee("张三丰", "业务部")
print(company.search_employee("张三丰", "业务部"))
```
这个企业员工信息管理系统可以实现增删改查功能,并且可以具体到相应部门。
阅读全文