用python写一个管理系统
时间: 2023-06-25 19:05:03 浏览: 98
用python写的学生管理系统
好的,管理系统有很多种类型,我来给你写一个简单的员工信息管理系统。
首先,我们需要定义一个员工类 Employee,包含员工的姓名、工号、职位、入职时间等基本信息。代码如下:
```python
class Employee:
def __init__(self, name, employee_id, position, hire_date):
self.name = name
self.employee_id = employee_id
self.position = position
self.hire_date = hire_date
```
接下来,我们需要一个员工信息管理系统类,包含添加员工、删除员工、修改员工信息、查询员工信息等功能。代码如下:
```python
class EmployeeSystem:
def __init__(self):
self.employees = []
# 添加员工
def add_employee(self, employee):
self.employees.append(employee)
# 删除员工
def remove_employee(self, employee_id):
for employee in self.employees:
if employee.employee_id == employee_id:
self.employees.remove(employee)
return True
return False
# 修改员工信息
def update_employee(self, employee_id, new_employee):
for i, employee in enumerate(self.employees):
if employee.employee_id == employee_id:
self.employees[i] = new_employee
return True
return False
# 查询员工信息
def get_employee(self, employee_id):
for employee in self.employees:
if employee.employee_id == employee_id:
return employee
return None
```
最后,我们可以写一个简单的测试程序来验证上述代码的正确性。代码如下:
```python
if __name__ == '__main__':
system = EmployeeSystem()
# 添加员工
employee1 = Employee('张三', '001', '经理', '2021-01-01')
system.add_employee(employee1)
# 查询员工信息
employee = system.get_employee('001')
print(employee.name, employee.employee_id, employee.position, employee.hire_date)
# 修改员工信息
employee2 = Employee('李四', '001', '副经理', '2021-02-01')
system.update_employee('001', employee2)
employee = system.get_employee('001')
print(employee.name, employee.employee_id, employee.position, employee.hire_date)
# 删除员工
system.remove_employee('001')
employee = system.get_employee('001')
if employee is None:
print('员工已删除')
```
以上代码实现了一个简单的员工信息管理系统,你可以根据需要进行修改和扩展。
阅读全文