def view_classroom(self, class_id): sc_table = DatabasesCls("student_classroom") classroom_table = DatabasesCls("classroom") course_table = DatabasesCls("courses") school_table = DatabasesCls("schools") school_data = school_table.open() sc_data = sc_table.open() classroom_data = classroom_table.open() course_data = course_table.open() if class_id in sc_data: while True: print("_" * 100) print("班级ID\t\t学生ID\t\t\t讲师ID\t\t\t班级名称\t\t\t\t课程名称\t\t学校") print("-" * 100) student_list = sc_data[class_id] for student in student_list: teacher_id = classroom_data[class_id]["teacher_id"] class_name = classroom_data[class_id]["class_name"] course_id = classroom_data[class_id]["course_id"] course_name = course_data[course_id]["name"] school_id = classroom_data[class_id]["school_id"] school_name = school_data[school_id]["name"] print("%s\t\t%s\t\t\t%s\t\t\t%s\t\t\t%s\t\t%s" % \ (class_id,student,teacher_id,class_name,course_name,school_name)) print("-" * 100) choice = input("[B|b返回]: ") if choice == "B" or choice == "b": break else: print("该班级还没有学员!!") time.sleep(1)
def student_list(self): print("学员列表--") student_pc_table = DatabasesCls("student_purchase_course") course_table = DatabasesCls("courses") data = student_pc_table.open() course_data = course_table.open() print(data) while True: print("_" * 100) print("学员ID\t\t\t购买的课程\t\t\t课程名称\t\t\t购买时间\t\t\t\t\t班级关联状态") print("-" * 100) for k, v in data.items(): for i, j in v.items(): student_id = k course_id = i course_name = course_data[course_id]["name"] purchase_time = j["purchase_time"] status = j["status"] status_com = "" if status == 0: status_com = "未关联" elif status == 1: status_com = "已关联" print("%s\t\t\t%s\t\t\t\t\t%s\t\t\t%s\t\t\t%s" % (student_id, course_id, course_name, purchase_time, status_com)) print("-" * 100) choice = input("请输入选项[A关联班级|B|b返回]: ").strip() if choice == "B" or choice == "b": break elif choice == "A" or choice == "a": Admin.join_student(self)
def classroom_list(self): classroom_data = ClassroomStaticCls.classroom_table.open() course_data = CourseStaticCls.course_table.open() teacher_data = TeacherStaticCls.teacher_table.open() school_data = SchoolStaticCls.school_table.open() sc_table = DatabasesCls("student_classroom") sc_data = sc_table.open() print(sc_data) while True: print("_" * 130) print("-" * 130) for k, v in classroom_data.items(): class_id, class_name, course_id, school_id, teacher_id = \ k, v["class_name"], v["course_id"], v["school_id"], v["teacher_id"] course_name = course_data[course_id]["name"] school_name = school_data[school_id]["name"] teacher_name = teacher_data[teacher_id]["name"] count = len(sc_data[class_id]) print("班级ID: %s\t\t班级名字: %s\t\t课程ID: %s\t\t课程名字: %s\t\t所在学校: %s\t\t授课讲师: %s\t\t学生人数: %s" % \ (class_id, class_name, course_id, course_name, school_name, teacher_name,count)) print("-" * 130) choice = input("输入班级ID查看班级学员(B返回): ") if choice == "B" or choice == "b": break School.view_classroom(self, choice)
def update(self): school_table = DatabasesCls("schools") school_list = school_table.open() data = self.teacher_table.open() if self.id in data and self.id.isalnum(): if self.password != "" and self.name != "" and self.phone != "" and self.teacher_title \ != "" and self.teacher_salary != "": if self.teacher_school in school_list: try: self.teacher_obj["password"] = self.password self.teacher_obj["name"] = self.name self.teacher_obj["phone"] = self.phone self.teacher_obj["school_id"] = self.teacher_school self.teacher_obj["title"] = self.teacher_title self.teacher_obj["salary"] = self.teacher_salary self.teacher_obj["email"] = self.teacher_email data[self.id] = self.teacher_obj self.teacher_table.save(data) return 0 #保存成功 except BaseException: return 3 #保存失败 else: return 3 #学校代码不存在 else: return 2 #账号密码、名字、手机、职务、薪资不能为空 else: return 1 #讲师账号已存在或输入错误
def my_course(self): print("我的课程--") user_name = user_data["user_id"] sc_table = DatabasesCls("student_classroom") cr_table = DatabasesCls("classroom") courses_table = DatabasesCls("courses") spc_table = DatabasesCls("student_purchase_course") spc_data = spc_table.open() courses_data = courses_table.open() sc_data = sc_table.open() cr_data = cr_table.open() print(sc_data) print(cr_data) print(courses_data) print(spc_data) while True: print("_" * 50) print("课程ID\t\t\t课程名称\t\t\t课程大纲") print("-" * 50) course_dict = spc_data[user_name] for id, value in course_dict.items(): course_id = id course_name = courses_data[course_id]["name"] course_outline = courses_data[course_id]["outline"] print("%s\t\t\t\t%s\t\t\t%s" % (course_id, course_name, course_outline)) print("-" * 50) choice = input("选择课程ID进入学习[B返回]: ") print(course_dict) if choice == "B" or choice == "b": break try: choice = int(choice) except: pass if choice in course_dict: course = courses_data[choice]["name"] try: course_dict[choice]["count"] += 1 except: course_dict[choice]["count"] = 0 finally: spc_data[user_name] = course_dict spc_table.save(spc_data) print("正在学习课程%s, 已学习%s次..." % (course, course_dict[choice]["count"])) time.sleep(1)
def join_student(self): student_table = DatabasesCls("students") classroom_table = DatabasesCls("classroom") student_classroom = DatabasesCls("student_classroom") student_pc_table = DatabasesCls("student_purchase_course") student_data = student_table.open() classroom_data = classroom_table.open() sc_data = student_classroom.open() pc_data = student_pc_table.open() print("关联班级--") print("/" * 15 + "学员关联班级 (*选项为必填)" + "/" * 15) student_id = input("*请输入学员的ID: ").strip() student_class_id = input("*请输入该学员关联的班级ID: ").strip() print(sc_data) if student_id in student_data: if student_id in pc_data: if student_class_id in classroom_data: try: s_list = sc_data[student_class_id] except: s_list = [] if student_id not in s_list: s_list.append(student_id) print(s_list) sc_data[student_class_id] = s_list student_classroom.save(sc_data) course_id = classroom_data[student_class_id][ "course_id"] pc_data[student_id][course_id]["status"] = 1 student_pc_table.save(pc_data) print("关联成功!") time.sleep(1) else: print("学员%s已经关联到该班级." % student_id) print(sc_data) else: print("班级ID不存在!!") else: print("该学员未购买该课程!!") else: print("学员ID不存在!!")
def update(self): school_table = DatabasesCls("schools") course_table = DatabasesCls("courses") teacher_table = DatabasesCls("teachers") class_data = self.classroom_table.open() course_data = course_table.open() school_data = school_table.open() teacher_data = teacher_table.open() if self.class_id in class_data: if self.class_name != "": if self.course_id in course_data: if self.school_id in school_data: if self.teacher_id in teacher_data: try: enroll_date = time.strftime( "%Y-%m-%d %H:%M:%S", time.localtime()) self.classroom_obj[ "class_name"] = self.class_name self.classroom_obj[ "course_id"] = self.course_id self.classroom_obj[ "teacher_id"] = self.teacher_id self.classroom_obj[ "school_id"] = self.school_id self.classroom_obj["enroll_date"] = str( enroll_date) class_data[self.class_id] = self.classroom_obj self.classroom_table.save(class_data) return 0 # 保存成功 except BaseException: return 1 # 保存失败 else: return 2 # 讲师ID不存在 else: return 6 # 学校不存在 else: return 3 # 课程ID不存在 else: return 4 # 班级名字为空 else: return 5 # 班级ID不存在
def view_grade(self): print("查询成绩--") user_name = user_data["user_id"] spc_table = DatabasesCls("student_purchase_course") courses_table = DatabasesCls("courses") spc_data = spc_table.open() course_data = courses_table.open() while True: print("_" * 50) print("课程ID\t\t\t课程名称\t\t\t学习成绩") print("-" * 50) course_dict = spc_data[user_name] for course_id, value in course_dict.items(): course_name = course_data[course_id]["name"] study_grade = value["grade"] print("%s\t\t\t\t%s\t\t\t%s分" % (course_id, course_name, study_grade)) print("-" * 50) choice = input("[B|b返回]: ") if choice == "B" or choice == "b": break
def my_classroom(self): print("我的班级--") user_name = user_data["user_id"] sc_table = DatabasesCls("student_classroom") cr_table = DatabasesCls("classroom") sc_data = sc_table.open() cr_data = cr_table.open() while True: print("_" * 50) print("班级ID\t\t\t班级名称\t\t\t\t讲师") print("-" * 50) print(sc_data) for class_id, student_list in sc_data.items(): if user_name in student_list: class_name = cr_data[class_id]["class_name"] teacher = cr_data[class_id]["teacher_id"] print("%s\t\t\t%s\t\t\t%s" % (class_id, class_name, teacher)) print("-" * 50) choice = input("[B|b返回]: ") if choice == "B" or choice == "b": break
def study_record(self): print("上课记录--") user_name = user_data["user_id"] spc_table = DatabasesCls("student_purchase_course") courses_table = DatabasesCls("courses") spc_data = spc_table.open() course_data = courses_table.open() while True: print("_" * 50) print("课程ID\t\t\t课程名称\t\t\t学习次数") print("-" * 50) course_dict = spc_data[user_name] for course_id, value in course_dict.items(): course_name = course_data[course_id]["name"] try: study_count = value["count"] except: study_count = 0 print("%s\t\t\t\t%s\t\t\t%s" % (course_id, course_name, study_count)) print("-" * 50) choice = input("[B|b返回]: ") if choice == "B" or choice == "b": break
class SchoolStaticCls(object): school_table = DatabasesCls("schools") def __init__(self, school_code, school_name, school_city): super(SchoolStaticCls, self).__init__() self.school_code = school_code self.school_name = school_name self.school_city = school_city self.school_obj = {} def create(self): data = self.school_table.open() if self.school_code not in data and self.school_code.isdigit(): if self.school_name != "" or self.school_city != "": try: self.school_obj["name"] = self.school_name self.school_obj["city"] = self.school_city data[self.school_code] = self.school_obj self.school_table.save(data) return 0 except (KeyError, ValueError) as e: return 1 else: return 2 else: return 3 def update(self): data = self.school_table.open() if self.school_code in data: if self.school_name != "" or self.school_city != "": try: self.school_obj["name"] = self.school_name self.school_obj["city"] = self.school_city data[self.school_code] = self.school_obj self.school_table.save(data) return 0 except (KeyError, ValueError) as e: return 1 else: return 2 else: return 3
def create_classroom(self): print("/" * 15 + "创建班级 (*选项为必填)" + "/" * 15) class_id = input("*输入要创建的班级ID(如:1801): ").strip() class_name = input("*输入要创建的班级名字: ").strip() course_id = input("*输入该班级开设(关联)的课程ID: ").strip() school_id = input("*输入该班级所在的学校ID: ").strip() teacher_id = input("*输入该班级的授课(关联)讲师的ID帐号: ").strip() try: course_id = int(course_id) except ValueError: pass classroom = ClassroomStaticCls(class_id, class_name, course_id, school_id, teacher_id) # 初始化 对象中的数据 new_classroom = classroom.create() # 在初始化数据后 调用 create方法 #============================================== # 增加一个为空的班级对应学生的信息的存放着 sc_table = DatabasesCls("student_classroom") sc_data = sc_table.open() #读取学生班级信息 sc_data[class_id] = [] sc_table.save(sc_data) if new_classroom == 0: print("创建成功!") elif new_classroom == 1: print("创建失败! 无法保存.") elif new_classroom == 2: print("讲师不存在或讲师ID错误!") elif new_classroom == 3: print("课程不存在或课程ID错误!") elif new_classroom == 4: print("班级名字不能为空!") elif new_classroom == 5: print("班级ID已存在!") elif new_classroom == 6: print("学校不存在!") else: print("创建失败!") print(classroom.classroom_obj)
class TeacherStaticCls(TeacherAccountBase): teacher_table = DatabasesCls("teachers") def __init__(self, id, password, name, phone, teacher_school, teacher_title, teacher_salary, teacher_email): super(TeacherStaticCls, self).__init__(id, password, name, phone) self.teacher_school = teacher_school self.teacher_title = teacher_title self.teacher_salary = teacher_salary self.teacher_email = teacher_email self.teacher_obj = {} def create(self): school_table = DatabasesCls("schools") school_list = school_table.open() data = self.teacher_table.open() if self.id not in data and self.id.isalnum(): if self.password != "" and self.name != "" and self.phone != "" and self.teacher_title \ != "" and self.teacher_salary != "": if self.teacher_school in school_list: try: self.teacher_obj["password"] = self.password self.teacher_obj["name"] = self.name self.teacher_obj["phone"] = self.phone self.teacher_obj["school_id"] = self.teacher_school self.teacher_obj["title"] = self.teacher_title self.teacher_obj["salary"] = self.teacher_salary self.teacher_obj["email"] = self.teacher_email data[self.id] = self.teacher_obj self.teacher_table.save(data) return 0 #保存成功 except BaseException: return 4 #保存失败 else: return 3 #学校代码不存在 else: return 2 #账号密码、名字、手机、职务、薪资不能为空 else: return 1 #讲师账号已存在或输入错误 def update(self): school_table = DatabasesCls("schools") school_list = school_table.open() data = self.teacher_table.open() if self.id in data and self.id.isalnum(): if self.password != "" and self.name != "" and self.phone != "" and self.teacher_title \ != "" and self.teacher_salary != "": if self.teacher_school in school_list: try: self.teacher_obj["password"] = self.password self.teacher_obj["name"] = self.name self.teacher_obj["phone"] = self.phone self.teacher_obj["school_id"] = self.teacher_school self.teacher_obj["title"] = self.teacher_title self.teacher_obj["salary"] = self.teacher_salary self.teacher_obj["email"] = self.teacher_email data[self.id] = self.teacher_obj self.teacher_table.save(data) return 0 #保存成功 except BaseException: return 3 #保存失败 else: return 3 #学校代码不存在 else: return 2 #账号密码、名字、手机、职务、薪资不能为空 else: return 1 #讲师账号已存在或输入错误 @classmethod #修饰符对应的函数不需要实例化,不需要 self 参数,但第一个参数需要是表示自身类的 cls 参数,可以来调用类的属性,类的方法,实例化对象等。 def delete(cls, account): data = cls.teacher_table.open() if account in data: try: del data[account] cls.teacher_table.save(data) return 0 except KeyError: pass else: return 1
class ClassroomStaticCls(object): classroom_table = DatabasesCls("classroom") def __init__(self, class_id, class_name, course_id, school_id, teacher_id): super(ClassroomStaticCls, self).__init__() self.class_id = class_id self.class_name = class_name self.course_id = course_id self.school_id = school_id self.teacher_id = teacher_id self.classroom_obj = {} def create(self): school_table = DatabasesCls("schools") course_table = DatabasesCls("courses") teacher_table = DatabasesCls("teachers") class_data = self.classroom_table.open() course_data = course_table.open() school_data = school_table.open() teacher_data = teacher_table.open() if self.class_id not in class_data and self.class_id.isdigit(): if self.class_name != "": if self.course_id in course_data: if self.school_id in school_data: if self.teacher_id in teacher_data: try: enroll_date = time.strftime( "%Y-%m-%d %H:%M:%S", time.localtime()) self.classroom_obj[ "class_name"] = self.class_name self.classroom_obj[ "course_id"] = self.course_id self.classroom_obj[ "teacher_id"] = self.teacher_id self.classroom_obj[ "school_id"] = self.school_id self.classroom_obj["enroll_date"] = str( enroll_date) class_data[self.class_id] = self.classroom_obj self.classroom_table.save(class_data) return 0 #保存成功 except BaseException: return 1 #保存失败 else: return 2 #讲师ID不存在 else: return 6 #学校不存在 else: return 3 #课程ID不存在 else: return 4 #班级名字为空 else: return 5 #班级ID已存在或为空 def update(self): school_table = DatabasesCls("schools") course_table = DatabasesCls("courses") teacher_table = DatabasesCls("teachers") class_data = self.classroom_table.open() course_data = course_table.open() school_data = school_table.open() teacher_data = teacher_table.open() if self.class_id in class_data: if self.class_name != "": if self.course_id in course_data: if self.school_id in school_data: if self.teacher_id in teacher_data: try: enroll_date = time.strftime( "%Y-%m-%d %H:%M:%S", time.localtime()) self.classroom_obj[ "class_name"] = self.class_name self.classroom_obj[ "course_id"] = self.course_id self.classroom_obj[ "teacher_id"] = self.teacher_id self.classroom_obj[ "school_id"] = self.school_id self.classroom_obj["enroll_date"] = str( enroll_date) class_data[self.class_id] = self.classroom_obj self.classroom_table.save(class_data) return 0 # 保存成功 except BaseException: return 1 # 保存失败 else: return 2 # 讲师ID不存在 else: return 6 # 学校不存在 else: return 3 # 课程ID不存在 else: return 4 # 班级名字为空 else: return 5 # 班级ID不存在 @classmethod #修饰符对应的函数不需要实例化,不需要 self 参数,但第一个参数需要是表示自身类的 cls 参数,可以来调用类的属性,类的方法,实例化对象等。 def delete(cls, class_id): data = cls.classroom_table.open() if class_id in data: try: del data[class_id] cls.classroom_table.save(data) return 0 except KeyError: pass else: return 1
def __init__(self, name): super(Student, self).__init__() self.name = name self.student_purchase_course = DatabasesCls("student_purchase_course")
def __init__(self, cookie): super(StudentsAccountCls, self).__init__() self.cookie = cookie self.user_table = DatabasesCls("students")
def view_classroom(self, teacher_id): print("查看班级学员--") cr_table = DatabasesCls("classroom") sc_table = DatabasesCls("student_classroom") course_table = DatabasesCls("courses") spc_table = DatabasesCls("student_purchase_course") cr_data = cr_table.open() sc_data = sc_table.open() course_data = course_table.open() spc_data = spc_table.open() classes = [] while True: print("_" * 120) print( "班级ID\t\t班级名称\t\t\t\t讲师ID\t\t\t课程ID\t\t课程名称\t\t\t学校ID\t\t班级人数\t\t\t创建时间" ) print("-" * 120) for class_id, class_value in cr_data.items(): teacher = class_value["teacher_id"] if teacher == teacher_id: classes.append(class_id) class_name = class_value["class_name"] course_id = class_value["course_id"] course_name = course_data[course_id]["name"] school_id = class_value["school_id"] count = len(sc_data[class_id]) enroll_date = class_value["enroll_date"] print("%s\t\t%s\t\t\t%s\t\t\t%s\t\t\t%s\t\t\t%s\t\t\t\t%s\t\t\t%s" % \ (class_id,class_name,teacher,course_id,course_name,school_id,count,enroll_date)) print("-" * 120) choice = input("输入选项: \n" "1 查看学员\n" "2 开始上课\n" "3 返回\n" "Enter your choice: ") if choice == "3": break if choice == "1": print("查看班级学员--") class_id2 = input("请输入班级ID: ") if class_id2 in classes: while True: print("_" * 80) print("班级ID\t\t学生ID\t\t\t课程名称\t\t\t学习次数\t\t\t成绩") print("-" * 80) student_list = sc_data[class_id2] if class_id2 in cr_data: course_id = cr_data[class_id2]["course_id"] course_name = course_data[course_id]["name"] for student_id in student_list: if student_id in spc_data: study_count = spc_data[student_id][ course_id]["count"] study_grade = spc_data[student_id][ course_id]["grade"] print( "%s\t\t%s\t\t\t%s\t\t\t%s\t\t\t\t%s" % (class_id2, student_id, course_name, study_count, study_grade)) print("-" * 80) choice = input("输入选项: \n" "1 修改学员成绩\n" "2 返回\n" "Enter your choice: ") if choice == "2": return if choice == "1": print("修改学员成绩--") student = input("输入学员ID: ") grade = input("输入学员成绩: ") if student in student_list: if grade.isdigit(): spc_data[student][course_id][ "grade"] = grade spc_table.save(spc_data) print(spc_data) print("修改成功!") time.sleep(1) else: print("成绩格式错误!") else: print("学员不存在!") else: print("班级ID不存在!") if choice == "2": print("选择班级上课--") class_id3 = input("请输入班级ID: ") if class_id3 in classes: print("开始上课----") time.sleep(1) else: print("班级ID不存在!")
class CourseStaticCls(object): course_table = DatabasesCls("courses") def __init__(self, course_name, course_price, course_period, course_outline, course_id=None): super(CourseStaticCls, self).__init__() self.course_id = course_id self.course_name = course_name self.course_price = course_price self.course_period = course_period self.course_outline = course_outline self.course_obj = {} def create(self): data = self.course_table.open() self.course_id = len(data) + 1 if self.course_name == "": return 1 #课程名称不能为空 elif not myisnum(self.course_price): return 2 #课程价格非数字 else: try: self.course_obj["name"] = self.course_name self.course_obj["price"] = self.course_price self.course_obj["period"] = self.course_period self.course_obj["outline"] = self.course_outline data[self.course_id] = self.course_obj self.course_table.save(data) # 存储 return 0 except (KeyError, ValueError) as e: return 3 #保存失败 def update(self, course_id): data = self.course_table.open() if course_id in data: if self.course_name == "": return 2 #课程名称不能为空 elif not myisnum(self.course_price): return 3 #课程价格非数字 else: try: self.course_obj["name"] = self.course_name self.course_obj["price"] = self.course_price self.course_obj["period"] = self.course_period self.course_obj["outline"] = self.course_outline data[course_id] = self.course_obj self.course_table.save(data) return 0 except (KeyError, ValueError) as e: return 4 #保存失败 else: return 1 #课程ID不存在 @classmethod #修饰符对应的函数不需要实例化,不需要 self 参数,但第一个参数需要是表示自身类的 cls 参数,可以来调用类的属性,类的方法,实例化对象等。 def delete(cls, course_id): data = cls.course_table.open() if course_id in data: try: del data[course_id] cls.course_table.save(data) return 0 except KeyError: pass else: return 1