def add_del_school(self): while 1: school_list = self.readSchoolDb() if len(school_list): print(magenta("目前开放的学校如下".center(50, '-'))) for _ in school_list: print(blue(_)) school_name = input("请输入创建的学校名称 <【d】删除|【b】返回>: ").strip() if school_name == 'b': break elif school_name == 'd': #【d】删除 if os.path.getsize(settings.SCHOOL_PATH) > 0: with open(settings.SCHOOL_PATH, 'rb+') as f: user_dict = pickle.load(f) choice = input("删除相应的地址:") if choice in user_dict: user_dict.pop(choice) #指定删除 else: print(red("输入有误")) dict = pickle.dumps(user_dict) f.seek(0) f.truncate(0) f.write(dict) else: print(red("当前文件是空")) # break elif school_name in school_list: print(red("抱歉,当前 【{}】 校区已经存在,请勿重复创建.".format(school_name))) # break else: School(school_name) print(blue("【{}】 校区创建成功".format(school_name)))
def manage_sys(): print(magenta("管理员登录".center(30, "-"))) _username = input("请输入管理员姓名: ").strip() _password = input("请输入管理员密码: ").strip() if _username == settings.ROOT_NAME and _password == settings.ROOT_PASSWD: while 1: print(green(settings.msg_master)) choice = input("请输入系统序列号<【b】返回 | 【q】退出>: ") if choice.lower() == 'b': break elif choice.lower() == 'q': exit("goodbye".center(50, "-")) else: eval(settings.master_dict[choice])( ) if choice in settings.master_dict else print( red("抱歉输入编号不存在")) else: print(red('用户名或者密码错误'))
def create_class_record(self): """ 创建上课记录 :return: """ while 1: print(magenta("您所教的班级如下".center(50, '-'))) for _ in self.grade_list: print(blue(_)) grade_name = input("请选择上课的班级<【b】返回>: ") if grade_name == 'b': break if grade_name in self.grade_list: break else: print(red("您输入班级有问题,请重新输入")) continue result_str = grade_name + time.strftime("%Y-%m-%d %X") + "上课记录" self.class_record.append(result_str) #添加到班级记录列表中 print(green("上课成功")) #读取班级数据 teacher_list = self.readTeacherDb() teacher_list[self.name] = self #存储班级数据 self.writeTeacherDb(teacher_list)
def login(): """ 教师登录验证 :return: """ print(magenta("教师登录".center(40, '-'))) teacher_all = Baseclass.readTeacherDb() #读取所有教师信息 username = input("请输入您的姓名: ").strip() if username in teacher_all: teacher_info = teacher_all[username] password = input("请输入您的密码: ").strip() if password in teacher_info.password: print(yellow("认证成功".center(40, '*'))) return teacher_info else: print(red("您输入的密码有误,请重新输入!")) else: print(red("抱歉 老师 {} 不在本系统中".format(username)))
def create_grades(self): """创建班级""" teacher_info = self.readTeacherDb() #读取教师数据 grade_name = input("请输入班级名称: ").strip() #选择教师 while 1: print(magenta("请选择本校老师: ".center(40, '-'))) for _ in self.school_teacher_list: print(yellow(_)) teacher_name = input("请输入你要选择的老师姓名: ").strip() if teacher_name not in self.school_teacher_list: print(red("输入的有误")) else: break #选择课程 while 1: print(magenta("请选择本校课程:".center(40, '-'))) for _ in self.school_course_list: print(yellow(_)) grade_course = input("请输入你要选择的课程名称: ").strip() if grade_course not in self.school_course_list: print(red("输入的有误")) else: break # 创建班级对象 grade_obj = Grades(grade_name, grade_course, teacher_name) #写入学校班级数据库 self.school_grades_list[grade_name] = grade_name #先读取学校数据 school_list = self.readSchoolDb() #再存储学校数据 school_list[self.school_name] = self self.writeSchoolDb(school_list) #写入教师数据库 teacher_info[teacher_name].grade_list[grade_name] = grade_name self.writeTeacherDb(teacher_info) # 写入班级数据库 grade_info = self.readGradeDb() grade_info[grade_name] = grade_obj self.writeGradeDb(grade_info)
def add_del_teacher(self): while 1: school_all = self.readSchoolDb() if not len(school_all): print(red("暂时没有开放学校地址,请联系管理员【henson】")) break print(magenta('请选择您的学校地址: '.center(40, "-"))) for _ in school_all: print(blue(_)) choice_name = input("请输入上面选择的学校地址<【b】返回>: ").strip() if choice_name == 'b': break elif choice_name in school_all: school_obj = school_all[choice_name] school_obj.create_teacher( ) #重点,触发了School类下的create_teacher()函数方法的Teacher() print(yellow("创建讲师成功")) break else: print(red("输入有误"))
def student_sys(): #学生菜单入口 while 1: print(green(settings.msg_student_main)) choice = input("请选择要进入的系统序号<【b】返回|【q】退出>: ").strip() if choice.lower() == 'b': break #跳出循环 elif choice.lower() == 'q': exit("goodbye".center(40, '-')) else: eval(settings.student_main_dict[choice])( ) if choice in settings.student_main_dict else print( red("Error,输入编号不存在!"))
def student_register(self): school_all = self.readSchoolDb() while 1: if not len(school_all): print(red("暂时没开放学校,请联系管理员")) break #跳出循环 print(magenta("当前开放的学校".center(40, '-'))) for _ in school_all: print(blue(_)) choice = input("请输入选择的学校名称<【b】返回>: ").strip() if choice.lower() == 'b': break elif choice in school_all: school_obj = school_all[choice] #更新继承School类 # print(school_obj.__dict__) school_obj.create_student() #马上跳到School类下创建学生函数方法 # self.create_student() #等于School.create_student() break else: print(red("输入有误"))
def run(): while 1: # print(magenta("欢迎进入选课系统".center(50, '-'))) print(green(settings.msg_main)) choice = input("请输入系统序列号<【b】返回 | 【q】退出>: ") if choice.lower() == 'b': break elif choice.lower() == 'q': exit("goodbye".center(50, "-")) else: # 使用eval函数妙用 eval(settings.main_dict[choice])( ) if choice in settings.main_dict else print(red("抱歉输入编号不存在"))
def student_login(self): student_obj = Student.login() if student_obj: while 1: print(green(settings.msg_student)) choice = input("请选择要进入的系统序号< 【b】返回|【q】退出>: ").strip() if choice.lower() == 'b': break #退出循环 elif choice.lower() == 'q': exit("goodbye".center(40, '-')) else: eval(settings.student_dict[choice])( student_obj ) if choice in settings.student_dict else print( red("抱歉输入编号不存在"))
def login(): print(magenta("学生登录".center(40, "-"))) student_all = Baseclass.readStudentDb() name = input("请输入您的姓名: ").strip() if name in student_all: student_info = student_all[name] password = input("请输入您的密码: ").strip() if password == student_info.password: print(yellow("登录成功")) return student_info else: print("您输入的密码有误") else: print(red("抱歉 学生 %s 在本系统中不存在" % name))
def add_class(self): school_all = self.readSchoolDb() while 1: print(magenta("请选择您的学校:".center(40, "-"))) for _ in school_all: print(_) choice = input("请输入选择的学校名称<【b】返回>: ").strip() if choice == 'b': break if choice in school_all: school_obj = school_all[choice] school_obj.create_grades() # print(yellow("创建班级成功")) break else: print(red("输入有误"))
def create_teacher(self): school_all = self.readSchoolDb() while 1: teacher_name = input("请输入教师姓名: ").strip() if teacher_name in school_all[ self.school_name].school_teacher_list: print( red("抱歉该 【{}】 校区的【{}】 老师已经存在,请勿重复创建".format( self.school_name, teacher_name))) else: break teacher_password = input("请输入教师登录密码: ").strip() teacher_age = input("请输入教师年龄: ").strip() teacher_sex = input("请输入教师性别: ").strip() school_name = self.school_name #更新 #创建教师对象 teacher_obj = Teacher(teacher_name, teacher_password, teacher_age, teacher_sex, school_name) #读取教师数据 teacher_info = self.readTeacherDb() teacher_info[ teacher_name] = teacher_obj #重点,main.py交互逻辑文件中的Admin类需要要调用下面的School类的Techer()方法 #存储教师数据 self.writeTeacherDb(teacher_info) self.school_teacher_list[teacher_name] = teacher_name #读取学校数据 school_list = self.readSchoolDb() school_list[self.school_name] = self #存储学校数据 self.writeSchoolDb(school_list) print( blue("""----- 恭喜注册成功 【 {name} 】 老师注册详细信息如下----- 姓 名:{name} 密 码:{pwd} 年 龄:{age} 性 别:{sex} 所在学校:{school} 请妥善保存好您的信息 """.format(name=teacher_name, pwd=teacher_password, age=teacher_age, sex=teacher_sex, school=school_name)))
def teacher_sys(): teacher_obj = Teacher.login() #先登录再执行下面的操作 # print(teacher_obj) if teacher_obj: while 1: print(green(settings.msg_teacher)) choice = input("请输入系统序列号<【b】返回 | 【q】退出>: ") if choice.lower() == 'b': break elif choice.lower() == 'q': exit("goodbye".center(50, "-")) else: eval(settings.teacher_dict[choice])( teacher_obj ) if choice in settings.teacher_dict else print( red("抱歉输入编号不存在"))
def add_course(self): while 1: school_all = self.readSchoolDb() print(magenta("请选择您的学校".center(40, "-"))) for _ in school_all: print(_) choice = input("请输入选择的学校地址<【b】返回>: ").strip() if choice == 'b': break print(magenta("欢迎进入{} 校区".center(40, '-').format(choice))) if choice in school_all: school_obj = school_all[choice] school_obj.create_course() # print(yellow("创建课程成功")) break else: print(red("输入有误"))
def create_course(self): """创建课程""" while 1: school_all = self.readSchoolDb() print(magenta("当前校区,开放的课程如下".center(40, '-'))) for _ in school_all[self.school_name].school_course_list: print(blue("开放的课程 >> {}".format(_))) course_name = input("请输入课程名称: ").strip() course_cycle = input("请输入课程周期: ").strip() course_price = input("请输入课程价格: ").strip() # 创建课程对象 course_obj = Course(course_name, course_cycle, course_price, self.school_name) # 读取课程数据 course_info = self.readCourseDb() course_info[course_name] = course_obj # 存储课程信息 # self.writeCourseDb(course_info) self.school_course_list[ course_name] = course_name #更新到school_course_list字典里面保存先 # 读取学校数据先做判断是否存在 school_list = self.readSchoolDb() if course_name in school_all[self.school_name].school_course_list: print(red("抱歉,你的课程【{}】已经存在,创建失败".format(course_name))) break # 存储学校数据 school_list[self.school_name] = self self.writeCourseDb(course_info) self.writeSchoolDb(school_list) print( blue("""----- 恭喜注册成功 【 {name} 】 课程注册详细信息如下----- 课程名字:{name} 课程周期:{cycle} 课程价格:{price} 所在学校:{school} 请妥善保存好您的信息 """.format(name=course_name, cycle=course_cycle, price=course_price, school=self.school_name))) break
def pay_tuition(self): """支付学费""" if self.pay == 1: print(green("学费已交,无需再交")) else: print("您当前需要付学费: ", self.tuition, '元') while True: tuition_name = input("请输入您要交的学费: ").strip() if tuition_name.isdigit() and ( int(tuition_name) - int(self.tuition) >= 0): print(blue("学费已交,谢谢")) self.pay = 1 #写入学生数据 student_info = self.readSchoolDb() #先读数据 student_info[self.name] = self #再更新数据 self.writeStudentDb(student_info) #保存数据 return True else: print(red("您输入学费不够支付"))
def create_student(self): """创建学生""" while 1: print(magenta("创建学生".center(40, '-'))) name = input("请输入您的姓名: ").strip() password = input("请输入您的密码: ").strip() while 1: print(blue(" --> 年龄必须是大于0整数")) age = input("请输入您的年龄: ").strip() if age.isdigit(): if not int(age) >= 0: print(red("--> 年龄必须是大于0")) else: break else: print(red(" --> 年龄必须是整数")) while 1: print(blue("--> 性别你只能输入以下可选选项")) for _ in settings.GENDER: print(_, end=" | ") print("") sex = input("请输入您的性别: ").strip() if sex in settings.GENDER: break #如果sex存在就跳过 #读班级数据 grade_list = self.readGradeDb() #读学校数据 school_list = self.readSchoolDb() print(magenta("该校区目前可选择班级信息如下: ".center(40, '-'))) for _ in school_list[self.school_name].school_grades_list: print(_) grade_name = input("请输入要注册班级名称: ").strip() if grade_name in grade_list: if name in grade_list[grade_name].student_list: print(red("抱歉该班级学生 {} 已经存在,新增学生失败".format(name))) break else: print(red("您输入的班级名称有问题")) break grade_obj = grade_list[grade_name] #更新 grade_obj.student_list[name] = name #更新 grade_list[grade_name] = grade_obj #再更新 #写入班级学生列表 self.writeGradeDb(grade_list) #读班级课程数据 course_all = self.readCourseDb() # course_price = course_all[grade_obj.course_name].price course_price = course_all[grade_obj.course_name].course_price #创建学生对象 student_obj = Student(name, password, age, sex, grade_name, grade_obj.course_name, self.school_name, course_price) #写入数据 student_all = self.readStudentDb() #先读出数据 student_all[name] = student_obj #更新 self.writeStudentDb(student_all) #写入数据 msg = """----- 恭喜注册成功 【 {name} 】 同学注册详细信息如下---- 姓 名: {name} 密 码: {pwd} 年 龄: {age} 性 别: {sex} 学 校: {school} 班 级: {grade} 请妥善保存好您的信息 """.format(name=name, pwd=password, age=age, sex=sex, school=self.school_name, grade=grade_name) print(blue(msg)) break