|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
import os,re
|
|
|
|
|
import os
|
|
|
|
|
import re
|
|
|
|
|
from datetime import date
|
|
|
|
|
from bll.student_bll import StudentBLL
|
|
|
|
|
from dal.student_dal_json import StudentDAL
|
|
|
|
@ -15,6 +16,7 @@ class StudentUI:
|
|
|
|
|
self.file_path = file_path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def display_menu(self):
|
|
|
|
|
"""显示主菜单"""
|
|
|
|
|
os.system('cls' if os.name == 'nt' else 'clear')
|
|
|
|
@ -87,8 +89,6 @@ class StudentUI:
|
|
|
|
|
print("*" * 50)
|
|
|
|
|
|
|
|
|
|
name = self.get_input("请输入姓名: ")
|
|
|
|
|
id_number = self.get_input("请输入身份证号: ")
|
|
|
|
|
# 验证学号格式(新增)
|
|
|
|
|
id_number = self.get_input("请输入身份证号: ")
|
|
|
|
|
while not re.match(r'^\d{17}[\dXx]$', id_number):
|
|
|
|
|
print("身份证号格式不正确,请输入 18 位身份证号。")
|
|
|
|
@ -96,9 +96,9 @@ class StudentUI:
|
|
|
|
|
|
|
|
|
|
while True:
|
|
|
|
|
student_id = self.get_input("请输入学号: ")
|
|
|
|
|
if re.match(r'^\d{10,15}$', student_id): # 假设学号是8-12位数字
|
|
|
|
|
if re.match(r'^\d{10,15}$', student_id): # 假设学号是10 - 15位数字
|
|
|
|
|
break
|
|
|
|
|
print("学号格式不正确,请输入8-12位数字")
|
|
|
|
|
print("学号格式不正确,请输入10到15位数字")
|
|
|
|
|
|
|
|
|
|
gender = self.get_input("请输入性别(男/女): ")
|
|
|
|
|
|
|
|
|
@ -120,11 +120,15 @@ class StudentUI:
|
|
|
|
|
except ValueError:
|
|
|
|
|
print("体重必须为0到500之间的有效数值,请重新输入")
|
|
|
|
|
|
|
|
|
|
# 从身份证号中提取出生日期
|
|
|
|
|
birth_date_str = id_number[6:14]
|
|
|
|
|
birth_date = date(int(birth_date_str[:4]), int(birth_date_str[4:6]), int(birth_date_str[6:]))
|
|
|
|
|
|
|
|
|
|
# 修改后的日期输入验证
|
|
|
|
|
while True:
|
|
|
|
|
enrollment_date = self.get_input("请输入入学日期(YYYY-MM-DD): ")
|
|
|
|
|
try:
|
|
|
|
|
date_obj = date.fromisoformat(enrollment_date)
|
|
|
|
|
enrollment_date_obj = date.fromisoformat(enrollment_date)
|
|
|
|
|
break
|
|
|
|
|
except ValueError:
|
|
|
|
|
print("日期格式错误,请使用 YYYY-MM-DD 格式(例如:2023-09-01)")
|
|
|
|
@ -138,8 +142,8 @@ class StudentUI:
|
|
|
|
|
sid=student_id,
|
|
|
|
|
name=name,
|
|
|
|
|
height=height,
|
|
|
|
|
birth_date=date_obj, # 使用验证后的日期对象
|
|
|
|
|
enrollment_date=date_obj, # 使用验证后的日期对象
|
|
|
|
|
birth_date=birth_date, # 使用从身份证提取的出生日期
|
|
|
|
|
enrollment_date=enrollment_date_obj,
|
|
|
|
|
class_name=class_name
|
|
|
|
|
)
|
|
|
|
|
if self.bll.add_student(student):
|
|
|
|
|