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 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 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 show_grade_info(self): """ 展示自己所教班级 :return: """ print(magenta("您所教的班级如下:")) for _ in self.grade_list: print(blue(_))
def show_info(self): """展示个人信息""" msg = """ ----- 亲爱的同学 {name} 你好,你详细信息如下----- 姓 名: {name} 性 别: {sex} 年 龄: {age} 所在学校: {school} 所在班级: {grade} """.format(name=self.name, sex=self.sex, age=self.age, school=self.school_name, grade=self.class_name) print(blue(msg))
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 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_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 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 show_school(self): school_all = self.readSchoolDb() print(magenta("当前开放的学校地址:".center(40, "-"))) for _ in school_all: print(blue(_)) time.sleep(1)
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