代码供参考:链接:https://pan.baidu.com/s/1kO0XgXM98rorw-i1dJFL9Q 密码:g4go
运行逻辑如下:
运行create_manager_user创建一个管理员账号
运行main程序,通过校验账号名密码来确定用户的权限,账号密码权限等信息均存储在user_info这张表中;
运行main程序,通过校验账号名密码来确定用户的权限,账号密码权限等信息均存储在user_info这张表中;
管理员验证通过后,进入managersystem(),可以进行如下操作:
menu_manager = ['Create School','Create Class','Create Teacher','Create Student','Create Course']
同理老师/学生可以有如下操作:
menu_teacher = ['Show Your School infomation','Show Your Classes infomation'] menu_stu = ['Select School','Select Class','Pay Tuition ']
使用eval()来实现对应的函数功能,但是不能传入参数,导致后续用户重复输入用户名,待解决!
简单记录几个函数
1. createSchool():
让用户以input的方式输入对象的属性信息,新建一个对象,并保存所有属性信息,在保存的时候曾遇到障碍:
因为设置了school={},所以每次写入时都会清空原有字典信息,重新写入,而不是增加,解决办法如下:
先判断下该文件是否为空,如果为空就正常写入school={},如果不为空就读出文件信息,更新信息并重新写入,不知道是否有更好的办法!
def save_info(self): school_info_exist = file_open_ifnone('school_info') if school_info_exist: with open('school_info', 'rb') as f_schoolinfo_r: while True: try: school_info = pickle.load(f_schoolinfo_r) except: school_info[self.name] = {} school_info[self.name]['address'] = self.address school_info[self.name]['headmaster'] = self.headmaster school_info[self.name]['tel'] = self.tel school_info[self.name]['classeslist'] = self.classeslist school_info[self.name]['teacherlist'] = self.teacherlist school_info[self.name]['studentlist'] = self.studentlist print(school_info) # 以二进制的方式写入文件中 with open("school_info", 'ab') as f_schoolinfo: pickle.dump(school_info, f_schoolinfo) break else: school[self.name] = {} school[self.name]['address'] = self.address school[self.name]['headmaster'] = self.headmaster school[self.name]['tel'] = self.tel school[self.name]['classeslist'] = self.classeslist school[self.name]['teacherlist'] = self.teacherlist school[self.name]['studentlist'] = self.studentlist print(school) # 以二进制的方式写入文件中 with open("school_info", 'ab') as f_schoolinfo: pickle.dump(school, f_schoolinfo)
2. chooseSchool():
学生视图下的选择学校函数,逻辑为先展示所有学校的信息,然后让学生输入想选择的学校,如果输入的学校名称在列表中,再输入学生姓名,并查询此学校目前的学生信息,如果该学生没在此学校注册过,则更新学校-studentlist的信息,即学生完成注册