职工信息管理系统python
时间: 2023-09-11 09:04:54 浏览: 112
职工信息管理系统是一个比较常见的企业内部管理系统,使用Python语言进行开发也是可行的。
以下是一个简单的职工信息管理系统的Python代码示例:
```python
# 员工信息类
class Employee:
def __init__(self, id, name, department, salary):
self.id = id
self.name = name
self.department = department
self.salary = salary
def __str__(self):
return f"{self.id}\t{self.name}\t{self.department}\t{self.salary}"
# 员工信息管理系统类
class EmployeeManagementSystem:
def __init__(self):
self.employees = []
# 添加员工信息
def add_employee(self, employee):
self.employees.append(employee)
# 删除员工信息
def delete_employee(self, id):
for employee in self.employees:
if employee.id == id:
self.employees.remove(employee)
return True
return False
# 修改员工信息
def modify_employee(self, id, new_name, new_department, new_salary):
for employee in self.employees:
if employee.id == id:
employee.name = new_name
employee.department = new_department
employee.salary = new_salary
return True
return False
# 查询员工信息
def search_employee(self, id):
for employee in self.employees:
if employee.id == id:
return employee
return None
# 显示所有员工信息
def display_all_employees(self):
print("ID\tName\tDepartment\tSalary")
for employee in self.employees:
print(employee)
# 测试代码
ems = EmployeeManagementSystem()
ems.add_employee(Employee(1, "Alice", "Technology", 10000))
ems.add_employee(Employee(2, "Bob", "Finance", 8000))
ems.add_employee(Employee(3, "Charlie", "Marketing", 12000))
ems.display_all_employees()
employee = ems.search_employee(2)
if employee:
print("Employee found:", employee)
else:
print("Employee not found.")
if ems.modify_employee(3, "David", "Sales", 15000):
print("Employee information modified.")
else:
print("Failed to modify employee information.")
if ems.delete_employee(2):
print("Employee deleted.")
else:
print("Failed to delete employee.")
```
这个示例代码实现了一个简单的员工信息管理系统,包括添加、删除、修改、查询和显示所有员工信息等功能。当然,这只是一个简单的示例,实际上可以根据需求进行更加复杂的开发。
阅读全文