员工信息表(还未完成)

*****

#!/usr/bin/env python
# _*_coding:utf-8_*_
# Author:believepd


def matching():
    dic = {"id": 0, "name": 1, "age": 2, "phone": 3, "job": 4}
    return dic


def show(select_list, sec_front_cond):
    for select_item in select_list:
        for front_cond in sec_front_cond:
            print(select_item[matching()[front_cond]], end=" ")
        print()


def front_cond_filter(f_cond):
    if "*" == f_cond:
        return matching().keys()
    elif f_cond:
        f_cond = f_cond.split(",")
        return [each_cond.strip() for each_cond in f_cond]
    else:
        print(f_cond)


def sec_back_cond_filter(cond_sign, back_cond):
    select_list = []
    sign, val = back_cond.split(cond_sign)
    sign = sign.strip()
    val = val.strip()
    judge = "int(line_list[matching()[sign]]) %s int(val)" % cond_sign if cond_sign == "<" or cond_sign == ">" else "line_list[matching()[sign]]"
    with open("staff_info", encoding="utf-8") as f:
        for line in f:
            line_list = line.strip().split(",")
            if eval(judge):
                select_list.append(line_list)
        return select_list


def back_cond_filter(b_cond):
    if ">" in b_cond:
        select_list = sec_back_cond_filter(">", b_cond)
    elif "<" in b_cond:
        select_list = sec_back_cond_filter("<", b_cond)
    elif "=" in b_cond:
        select_list = sec_back_cond_filter("==", b_cond.replace("=", "=="))
    elif "like" in b_cond:
        select_list = sec_back_cond_filter("in", b_cond)
    return select_list


def input_adjust():
    input_str = input("\033[39;1m请输入:\033[0m")
    front_cond, back_cond = input_str.split("where")
    front_cond = front_cond.replace("select", "").strip()
    sec_front_cond = front_cond_filter(front_cond)
    back_cond = back_cond.strip()
    select_list = back_cond_filter(back_cond)
    show(select_list, sec_front_cond)


def file_search():
    print("=" * 40)
    print("\033[34;1m操作说明\033[0m".center(45))
    print("=" * 40)
    print("请输入类似以下语法进行查找:")
    print("select name,age,job where age>22")
    print("select * where job=IT")
    print("select * where phone like '111'")
    print("=" * 40)
    input_adjust()


def main():
    print("=" * 40)
    print("\033[34;1m欢迎使用员工管理系统\033[0m".center(40))
    while True:
        print("="*40)
        print("1  查询员工信息")
        print("2  修改员工信息")
        print("3  删除员工信息")
        print("4  添加新员工信息")
        print("5  退出系统")
        print("="*40)
        user_choice = input("\033[39;1m请选择您要进行的操作:\033[0m").strip()
        if user_choice.isdigit():
            user_choice = int(user_choice)
            if user_choice == 1:
                file_search()
            # elif user_choice == 2:
            #     file_update()
            # elif user_choice == 3:
            #     file_delete()
            # elif user_choice == 4:
            #     file_add()
            elif user_choice == 5:
                exit("\033[39;1m欢迎下次继续使用\033[0m")
            else:
                print("\033[31;1m请正确输入信息!\033[0m")
        else:
            print("\033[31;1m请正确输入信息!\033[0m")
            continue


if __name__ == '__main__':
    main()
View Code

猜你喜欢

转载自www.cnblogs.com/believepd/p/9633860.html
今日推荐