python 学生考勤管理系统
时间: 2023-09-16 18:06:41 浏览: 175
一个简单的学生考勤管理系统可以包含以下功能:
1. 学生信息管理:包括学生的基本信息、班级信息等。
2. 考勤信息管理:包括学生的签到、请假、旷课等考勤信息的管理。
3. 数据统计功能:可以对学生的考勤情况进行统计分析,生成报表等。
4. 用户权限管理:管理员可以设置不同用户的权限,保证安全性和数据的完整性。
5. 界面友好:设计一个简洁、易用的图形界面,方便用户进行操作。
下面是一个简单的 Python 学生考勤管理系统的示例代码:
```python
import csv
class Student:
def __init__(self, name, id, gender, class_name):
self.name = name
self.id = id
self.gender = gender
self.class_name = class_name
self.attendence = []
def __str__(self):
return f"{self.name}({self.id})"
def add_attendence(self, attendence):
self.attendence.append(attendence)
class Attendence:
def __init__(self, student_id, date, status):
self.student_id = student_id
self.date = date
self.status = status
def __str__(self):
return f"{self.student_id} {self.date} {self.status}"
class StudentManager:
def __init__(self):
self.students = []
def add_student(self, student):
self.students.append(student)
def get_student_by_id(self, id):
for student in self.students:
if student.id == id:
return student
return None
def get_all_students(self):
return self.students
def save_to_file(self, filename):
with open(filename, mode='w', newline='') as file:
writer = csv.writer(file)
writer.writerow(["Name", "ID", "Gender", "Class"])
for student in self.students:
writer.writerow([student.name, student.id, student.gender, student.class_name])
def load_from_file(self, filename):
with open(filename, mode='r') as file:
reader = csv.DictReader(file)
for row in reader:
student = Student(row["Name"], row["ID"], row["Gender"], row["Class"])
self.add_student(student)
class AttendenceManager:
def __init__(self):
self.attendences = []
def add_attendence(self, attendence):
self.attendences.append(attendence)
def get_attendences_by_id(self, id):
return [attendence for attendence in self.attendences if attendence.student_id == id]
def get_all_attendences(self):
return self.attendences
def save_to_file(self, filename):
with open(filename, mode='w', newline='') as file:
writer = csv.writer(file)
writer.writerow(["Student ID", "Date", "Status"])
for attendence in self.attendences:
writer.writerow([attendence.student_id, attendence.date, attendence.status])
def load_from_file(self, filename):
with open(filename, mode='r') as file:
reader = csv.DictReader(file)
for row in reader:
attendence = Attendence(row["Student ID"], row["Date"], row["Status"])
self.add_attendence(attendence)
class App:
def __init__(self):
self.student_manager = StudentManager()
self.attendence_manager = AttendenceManager()
def add_student(self, name, id, gender, class_name):
student = Student(name, id, gender, class_name)
self.student_manager.add_student(student)
def add_attendence(self, student_id, date, status):
attendence = Attendence(student_id, date, status)
self.attendence_manager.add_attendence(attendence)
student = self.student_manager.get_student_by_id(student_id)
student.add_attendence(attendence)
def save_to_file(self, student_filename, attendence_filename):
self.student_manager.save_to_file(student_filename)
self.attendence_manager.save_to_file(attendence_filename)
def load_from_file(self, student_filename, attendence_filename):
self.student_manager.load_from_file(student_filename)
self.attendence_manager.load_from_file(attendence_filename)
if __name__ == "__main__":
app = App()
app.add_student("张三", "001", "男", "一班")
app.add_student("李四", "002", "女", "一班")
app.add_attendence("001", "2021-01-01", "出勤")
app.add_attendence("001", "2021-01-02", "请假")
app.add_attendence("002", "2021-01-01", "出勤")
app.add_attendence("002", "2021-01-02", "旷课")
app.save_to_file("students.csv", "attendences.csv")
app2 = App()
app2.load_from_file("students.csv", "attendences.csv")
students = app2.student_manager.get_all_students()
for student in students:
print(student)
attendences = app2.attendence_manager.get_attendences_by_id(student.id)
for attendence in attendences:
print(attendence)
```
阅读全文