You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.1 KiB
70 lines
2.1 KiB
import sys
|
|
from datetime import date
|
|
from typing import Optional
|
|
from src.models.student import Student
|
|
from src.bll.student_service import StudentService
|
|
|
|
|
|
class ConsoleUI:
|
|
def __init__(self, service: StudentService):
|
|
self.service = service
|
|
|
|
def run(self):
|
|
while True:
|
|
self._show_main_menu()
|
|
choice = input("请选择操作: ").strip()
|
|
|
|
if choice == "1":
|
|
self._add_student()
|
|
elif choice == "2":
|
|
self._delete_student()
|
|
elif choice == "3":
|
|
self._update_student()
|
|
elif choice == "4":
|
|
self._query_students()
|
|
elif choice == "5":
|
|
self._show_statistics()
|
|
elif choice == "6":
|
|
self._data_import_export()
|
|
elif choice == "7":
|
|
self._clear_all_data()
|
|
elif choice == "0":
|
|
print("感谢使用学生信息管理系统,再见!")
|
|
sys.exit(0)
|
|
else:
|
|
print("无效选择,请重新输入!")
|
|
|
|
def _show_main_menu(self):
|
|
print("\n" + "=" * 30)
|
|
print("学生信息管理系统".center(26))
|
|
print("=" * 30)
|
|
print("1. 添加学生信息")
|
|
print("2. 删除学生信息")
|
|
print("3. 更新学生信息")
|
|
print("4. 查询学生信息")
|
|
print("5. 统计分析")
|
|
print("6. 数据导入导出")
|
|
print("7. 清空所有学生信息")
|
|
print("0. 退出系统")
|
|
print("=" * 30)
|
|
|
|
def _add_student(self):
|
|
print("\n" + "=" * 30)
|
|
print("添加学生信息".center(26))
|
|
print("=" * 30)
|
|
|
|
student_data = {}
|
|
student_data["name"] = input("姓名: ").strip()
|
|
student_data["id_card"] = input("身份证号: ").strip()
|
|
student_data["stu_id"] = input("学号: ").strip()
|
|
|
|
# 其他可选字段输入...
|
|
|
|
try:
|
|
student = Student(**student_data)
|
|
success, msg = self.service.add_student(student)
|
|
print(msg)
|
|
except Exception as e:
|
|
print(f"添加失败: {str(e)}")
|
|
|
|
# 其他UI方法... |