parent
36813aaa18
commit
4d4bd8e2e2
@ -1,10 +1 @@
|
|||||||
[
|
[]
|
||||||
{
|
|
||||||
"sid": "110309230907041",
|
|
||||||
"name": "cgt",
|
|
||||||
"height": 180,
|
|
||||||
"birth_date": "2002-01-25",
|
|
||||||
"enrollment_date": "2023-09-01",
|
|
||||||
"class_name": "cs"
|
|
||||||
}
|
|
||||||
]
|
|
@ -1,129 +1,9 @@
|
|||||||
from datetime import date
|
|
||||||
|
|
||||||
from ui.studentui import StudentUI
|
from ui.studentui import StudentUI
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
"""主函数"""
|
||||||
ui = StudentUI()
|
ui = StudentUI()
|
||||||
while True:
|
ui.run()
|
||||||
ui.display_menu()
|
|
||||||
choice = ui.get_input("请输入你的选择: ")
|
|
||||||
if choice == '1':
|
|
||||||
ui.add_student()
|
|
||||||
elif choice == '2':
|
|
||||||
sid = ui.get_input("请输入要删除的学生学号: ")
|
|
||||||
try:
|
|
||||||
if ui.bll.delete_student(sid):
|
|
||||||
print("学生信息删除成功!")
|
|
||||||
else:
|
|
||||||
print("学生信息删除失败。")
|
|
||||||
except ValueError as e:
|
|
||||||
print(e)
|
|
||||||
elif choice == '3':
|
|
||||||
sid = ui.get_input("请输入要更新的学生学号: ")
|
|
||||||
student = ui.bll.get_student_by_id(sid)
|
|
||||||
if student:
|
|
||||||
# 获取更新信息
|
|
||||||
name = ui.get_input(f"请输入新的姓名(当前:{student.name}),不修改请直接回车: ")
|
|
||||||
height = ui.get_input(f"请输入新的身高(当前:{student.height}),不修改请直接回车: ")
|
|
||||||
birth_date = ui.get_input(f"请输入新的出生日期(当前:{student.birth_date}),不修改请直接回车: ")
|
|
||||||
enrollment_date = ui.get_input(f"请输入新的入学日期(当前:{student.enrollment_date}),不修改请直接回车: ")
|
|
||||||
class_name = ui.get_input(f"请输入新的班级(当前:{student.class_name}),不修改请直接回车: ")
|
|
||||||
|
|
||||||
if name:
|
|
||||||
student.name = name
|
|
||||||
if height:
|
|
||||||
student.height = int(height)
|
|
||||||
if birth_date:
|
|
||||||
student.birth_date = date.fromisoformat(birth_date)
|
|
||||||
if enrollment_date:
|
|
||||||
student.enrollment_date = date.fromisoformat(enrollment_date)
|
|
||||||
if class_name:
|
|
||||||
student.class_name = class_name
|
|
||||||
|
|
||||||
try:
|
|
||||||
if ui.bll.update_student(sid, student):
|
|
||||||
print("学生信息更新成功!")
|
|
||||||
else:
|
|
||||||
print("学生信息更新失败。")
|
|
||||||
except ValueError as e:
|
|
||||||
print(e)
|
|
||||||
else:
|
|
||||||
print(f"学生 ID {sid} 不存在。")
|
|
||||||
elif choice == '4':
|
|
||||||
ui.display_query_menu()
|
|
||||||
query_choice = ui.get_input("请输入你的查询选择: ")
|
|
||||||
if query_choice == '1':
|
|
||||||
students = ui.bll.get_all_students()
|
|
||||||
for student in students:
|
|
||||||
print(student)
|
|
||||||
elif query_choice == '2':
|
|
||||||
sid = ui.get_input("请输入要查询的学生学号: ")
|
|
||||||
student = ui.bll.get_student_by_id(sid)
|
|
||||||
if student:
|
|
||||||
print(student)
|
|
||||||
else:
|
|
||||||
print(f"学生 ID {sid} 不存在。")
|
|
||||||
elif query_choice == '3':
|
|
||||||
# 这里和按学号查询逻辑一样
|
|
||||||
sid = ui.get_input("请输入要查询的学生学号: ")
|
|
||||||
student = ui.bll.get_student_by_id(sid)
|
|
||||||
if student:
|
|
||||||
print(student)
|
|
||||||
else:
|
|
||||||
print(f"学生 ID {sid} 不存在。")
|
|
||||||
elif query_choice == '4':
|
|
||||||
name = ui.get_input("请输入要查询的学生姓名: ")
|
|
||||||
students = ui.bll.get_students_by_name(name)
|
|
||||||
for student in students:
|
|
||||||
print(student)
|
|
||||||
elif query_choice == '5':
|
|
||||||
class_name = ui.get_input("请输入要查询的班级: ")
|
|
||||||
students = ui.bll.get_students_by_class(class_name)
|
|
||||||
for student in students:
|
|
||||||
print(student)
|
|
||||||
elif query_choice == '0':
|
|
||||||
continue
|
|
||||||
elif choice == '5':
|
|
||||||
ui.display_stats_menu()
|
|
||||||
stats_choice = ui.get_input("请输入你的统计选择: ")
|
|
||||||
if stats_choice == '1':
|
|
||||||
count = ui.bll.dal.get_student_count()
|
|
||||||
print(f"学生总数为: {count}")
|
|
||||||
elif stats_choice == '2':
|
|
||||||
average_height = ui.bll.dal.get_average_height()
|
|
||||||
print(f"学生平均身高为: {average_height:.2f} cm")
|
|
||||||
elif stats_choice == '3':
|
|
||||||
min_height = int(ui.get_input("请输入最小身高: "))
|
|
||||||
max_height = int(ui.get_input("请输入最大身高: "))
|
|
||||||
count = ui.bll.dal.count_students_by_height_range(min_height, max_height)
|
|
||||||
print(f"身高在 {min_height} - {max_height} cm 之间的学生数量为: {count}")
|
|
||||||
elif stats_choice == '4':
|
|
||||||
year = int(ui.get_input("请输入入学年份: "))
|
|
||||||
count = ui.bll.dal.count_students_by_enrollment_year(year)
|
|
||||||
print(f"{year} 年入学的学生数量为: {count}")
|
|
||||||
elif stats_choice == '5':
|
|
||||||
min_age = int(ui.get_input("请输入最小年龄: "))
|
|
||||||
max_age = int(ui.get_input("请输入最大年龄: "))
|
|
||||||
count = ui.bll.dal.count_students_by_age_range(min_age, max_age)
|
|
||||||
print(f"年龄在 {min_age} - {max_age} 岁之间的学生数量为: {count}")
|
|
||||||
elif stats_choice == '0':
|
|
||||||
continue
|
|
||||||
elif choice == '6':
|
|
||||||
ui.display_import_export_menu()
|
|
||||||
import_export_choice = ui.get_input("请输入你的导入导出选择: ")
|
|
||||||
if import_export_choice != '0':
|
|
||||||
ui.handle_import_export(import_export_choice)
|
|
||||||
else:
|
|
||||||
continue
|
|
||||||
|
|
||||||
elif choice == '7':
|
|
||||||
try:
|
|
||||||
ui.bll.dal.clear_all_students()
|
|
||||||
print("所有学生信息已清空!")
|
|
||||||
except Exception as e:
|
|
||||||
print(f"清空学生信息失败: {e}")
|
|
||||||
elif choice == '0':
|
|
||||||
break
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
Loading…
Reference in new issue