def mark_operation(grade):
    '''
    the function is used to let faculty to operate the student's mark, such as add mark, modify
    the mark(will be achieved in future)
    :param grade:
    :return:
    '''
    while True:
        user_exit_choice = input(
            'input q to quit or input any other value to continue to manage your student>>>'
        )
        if user_exit_choice == 'q':
            print('successfully quit')
            return 0
        data_handler.load_data(grade.grade_name)
        for i, item in enumerate(grade.grade_student):
            print(i + 1, item.name)

        user_choice = input('please choose a student to operate>>>')
        if user_choice.isdigit() and int(user_choice) > 0 and int(
                user_choice) <= len(grade.grade_student):
            mark = input('please input the mark you want to add>>>')
            student = grade.grade_student[int(user_choice) - 1]
            student.mark_add(mark)
            grade.grade_student[int(user_choice) - 1] = student
            for faculty in grade.grade_faculty:
                for i, grade_obj in enumerate(faculty.grade):
                    if grade_obj.grade_name == grade.grade_name:
                        faculty.grade[i] = grade
                        data_handler.dump_info(faculty.name, faculty)
            data_handler.dump_info(grade.grade_name, grade)
            print('Add mark successfully!')
        else:
            continue
def look_over_student_list(grade):
    '''
    the function is used to exhibit the student list of a grade
    :param grade:
    :return:
    '''
    data_handler.load_data(grade.grade_name)
    for i, item in enumerate(grade.grade_student):
        print(i + 1, item.name)
    time.sleep(2)
def manage_port():
    '''
    the function is the port for user to create object
    :return:
    '''
    while True:
        user_exit_choice = input('input q to quit or input any other value to continue to manage>>>')
        if user_exit_choice == 'q':
            exit('successfully quit')
        print('----School list----')
        print('1 Beijing_school')
        print('2 Shanghai_school')
        user_choice = input('please choose school>>>')
        if user_choice in school_dict:

            while True:
                user_exit_choice2 = input('input q to quit or input any other value to continue>>>')
                if user_exit_choice2 == 'q':
                    break
                print('----Server list----')
                print('1 Create course')
                print('2 Create grade')
                print('3 Create faculty')
                user_choice2 = input('please choose a server>>>')
                if user_choice2 in server_dict:
                    user_school = data_handler.load_data(school_dict[user_choice])
                    server_dict[user_choice2](user_school)
                else:
                    print('invalid input!')
                    break
def faculty_port():
    '''
    the function is used to provide a port for faculty to manage his grade
    and students
    :return:
    '''
    while True:
        user_exit_choice = input(
            'input q to quit or input any other value to continue to manage>>>'
        )
        if user_exit_choice == 'q':
            print('successfully quit')
            break
        user_name = input('please input your name>>>')
        if os.path.isfile(BASE_DIR + "\\data\\%s" % user_name) == False:
            print('invalid name,please check your input!')
            continue
        faculty = data_handler.load_data(user_name)
        grade = choose_grade(faculty)
        if grade == False:
            continue
        while True:
            user_exit_choice2 = input(
                'input q to quit or input any other value to continue to manage your grade>>>'
            )
            if user_exit_choice2 == 'q':
                break
            print('----Sever list----')
            print('1 look over student list')
            print('2 mark operation')
            user_choice = input('please choose a sever>>>')
            if user_choice in faculty_sever_dict:
                faculty_sever_dict[user_choice](grade)
            else:
                print('invalid input!')
def query_mark():
    '''
    the function is used to query a student's mark through his grade and his name
    :return:
    '''
    while True:
        user_exit_choice = input(
            'input q to quit or input any other value to continue to choose your grade>>>'
        )
        if user_exit_choice == 'q':
            print('successfully quit')
            break
        print('----School list----')
        print('1 %s' % student_school_dict['1'])
        print('2 %s' % student_school_dict['2'])
        user_choice = input('please choose school>>>')
        if user_choice in student_school_dict:
            student_school = data_handler.load_data(
                student_school_dict[user_choice])
        else:
            print('invalid input!')
            continue
        for i, item in enumerate(student_school.grade):
            print(i + 1, item.grade_name)
        user_choice2 = input('please choose a grade>>>')
        if user_choice2.isdigit() and int(user_choice2) > 0 and int(
                user_choice2) <= len(student_school.grade):
            student_grade = data_handler.load_data(
                student_school.grade[int(user_choice2) - 1].grade_name)
            while True:
                user_exit_choice = input(
                    'input q to quit or input any other value to continue to Query>>>'
                )
                if user_exit_choice == 'q':
                    print('successfully quit')
                    break
                student_name = input('please input your name>>>')
                state = False
                for i in student_grade.grade_student:
                    if i.name == student_name:
                        state = True
                        student_obj = i
                        print(student_obj.mark)
                        break
                if state == False:
                    print('you are not in the grade,please check your input')
def student_port():
    '''
    the function is used to provide a port for student to query his mark and
    enroll in.
    :return:
    '''
    while True:
        user_exit_choice0 = input(
            'input q to quit or input any other value to continue to join our course!>>>'
        )
        if user_exit_choice0 == 'q':
            print('successfully quit')
            break
        sever_dict = {'1': 'query your mark', '2': 'enroll in!'}
        print('----Sever list----')
        print('1 query your mark')
        print('2 enroll in!')

        student_choice = input('please choose a sever>>>')
        if student_choice in sever_dict:
            if student_choice == '1':
                query_mark()
            else:
                while True:
                    user_exit_choice = input(
                        'input q to quit or input any other value to continue to join our course!>>>'
                    )
                    if user_exit_choice == 'q':
                        print('successfully quit')
                        break

                    print('----School list----')
                    print('1 %s' % student_school_dict['1'])
                    print('2 %s' % student_school_dict['2'])
                    user_choice = input('please choose school>>>')
                    if user_choice in student_school_dict:
                        student_school = data_handler.load_data(
                            student_school_dict[user_choice])
                    else:
                        print('invalid input!')
                        continue
                    course_obj = select_course(student_school)
                    grade_obj, user_grade_choice = select_grade(student_school)
                    name = input('please input your name>>>')
                    age = input('please input your age>>>')
                    sex = input('please input your sex>>>')
                    mobile_phone = input(
                        'please input your mobile phone number>>>')
                    state = pay_tuition(course_obj)
                    if state == False:
                        continue
                    student = Student(name, age, sex, mobile_phone,
                                      student_school)
                    student.change_state(state)
                    grade_obj.bind_student(student)
                    student.bind_grade(grade_obj)
                    student_school.grade[user_grade_choice - 1] = grade_obj
                    data_handler.dump_info(grade_obj.grade_name, grade_obj)
                    data_handler.dump_info(student_school.name, student_school)
                    for faculty in grade_obj.grade_faculty:
                        for i, grade in enumerate(faculty.grade):
                            if grade.grade_name == grade_obj.grade_name:
                                faculty.grade[i] = grade_obj
                                data_handler.dump_info(faculty.name, faculty)
                    print('Successfully enroll in!')
        else:
            print('invalid input!')
            continue