コード例 #1
0
 def __init__(self):
     if not os.path.exists(school_db_file):
         self.init_school()
         self.school_db = file_oper(school_db_file, 'rb')
         self.manage_run()
     else:
         self.school_db = file_oper(school_db_file, 'rb')
         self.manage_run()
コード例 #2
0
    def add_grade(self):
        grade_name = input('\033[34;1m输入班级名:\033[0m')
        course_name = input('\033[34;1m输入班级要上的课程名:\033[0m')
        if course_name in self.school_obj.school_course:
            course_obj = self.school_obj.school_course[course_name]
            if grade_name not in self.school_obj.school_grade:
                self.school_obj.create_grade(grade_name, course_obj)
                self.school_db[self.choice_school] = self.school_obj
                file_oper(school_db_file, 'wb', self.school_db)

            else:
                print('\033[31;1m班级信息已存在.\033[0m')
        else:
            print('\033[31;1m课程信息不存在.\033[0m')
コード例 #3
0
 def add_course(self):
     course_name = input('\033[34;1m输入课程名:\033[0m')
     course_price = input('\033[34;1m输入课程价格:\033[0m')
     course_time = input('\033[34;1m输入课程周期:\033[0m')
     if course_name not in self.school_obj.school_course:
         self.school_obj.create_course(course_name, course_price,
                                       course_time)
         self.school_db[self.choice_school] = self.school_obj
         file_oper(school_db_file, 'wb', self.school_db)
         print('\033[32;1m课程新增成功。\033[0m')
     else:
         print('\033[31;1m课程信息已存在.\033[0m')
         self.school_obj.create_course(course_name, course_price,
                                       course_time)
         print('\033[32;1m课程更新成功。\033[0m')
コード例 #4
0
 def __init__(self):
     if os.path.exists(school_db_file):
         self.school_db = file_oper(school_db_file, 'rb')
         self.manage_run()
     else:
         print('\033[31;1m数据库不存在,请初始化数据库.')
         exit(1)
コード例 #5
0
 def add_teacher(self):
     teacher_name = input('\033[34;1m输入讲师名:\033[0m')
     teacher_salary = input('\033[34;1m输入讲师薪资:\033[0m')
     grade_name = input('\033[34;1m输入讲师关联的班级:\033[0m')
     if grade_name in self.school_obj.school_grade:
         grade_obj = self.school_obj.school_grade[grade_name]
         if teacher_name not in self.school_obj.school_teacher:
             self.school_obj.create_teacher(teacher_name, teacher_salary,
                                            grade_name, grade_obj)
             print('\033[32;1m讲师新增成功.\033[0m')
         else:
             print('\033[31;1m讲师信息已存在.\033[0m')
             self.school_obj.create_teacher(teacher_name, teacher_salary,
                                            grade_name, grade_obj)
             print('\033[32;1m讲师更新成功.\033[0m')
         self.school_db[self.choice_school] = self.school_obj
         file_oper(school_db_file, 'wb', self.school_db)
     else:
         print('\033[31;1m班级信息不存在,请先创建班级.\033[0m')
コード例 #6
0
ファイル: student_center.py プロジェクト: hukeyy/learn_python
    def manage_run(self):
        for key in self.school_db:
            print('学校名:', key)
        choice_school = input('>>>').strip()
        if choice_school in self.school_db:
            self.choice_school = choice_school
            self.school_obj = self.school_db[choice_school]
            student_name = input('\033[34;1m输入学生名:\033[0m').strip()
            student_age = input('\033[34;1m输入学生年龄:\033[0m').strip()
            self.school_obj.show_grade_course()
            grade_name = input('\033[34;1m输入要选择的班级名:\033[0m')
            if grade_name in self.school_obj.school_grade:
                self.school_obj.create_student(student_name, student_age,
                                               grade_name)
                self.school_db[self.choice_school] = self.school_obj
                file_oper(school_db_file, 'wb', self.school_db)
                print('\033[32;1m选课成功.\033[0m')

            else:
                print('\033[31;1m班级信息不存在.\033[0m')
コード例 #7
0
 def init_teacher(self):
     data = {}
     file_oper(teacher_db_file, 'wb', data)
コード例 #8
0
ファイル: student_center.py プロジェクト: hukeyy/learn_python
 def __init__(self):
     if os.path.exists(school_db_file):
         self.school_db = file_oper(school_db_file, 'rb')
         self.manage_run()
     else:
         print('\033[31;1m数据库文件不存在,请先初始化.\033[0m')
コード例 #9
0
 def init_school(self):
     sh = School('上海', '上海市')
     bj = School('北京', '北京市')
     data = {'上海': sh, '北京': bj}
     file_oper(school_db_file, 'wb', data)