import sys
import os
informationDict = {}
UserName = ""
staff_table = "information.txt"
#登录
def login():
print(loadData(staff_table))
count =3
judgeDict = {}
with open("user_information.txt","r",encoding="utf-8") as f:
for i in f.readlines():
data = i.strip().split(",")
judgeDict.setdefault(data[0],data[1])
while not count is None:
global UserName
print("欢迎进入个人信息修改系统".center(50,"*"))
UserName = input("请输入用户名字:").strip().title()
PassWord = input("请输入用户密码:").strip()
if count >1:
if UserName in judgeDict.keys() and PassWord == judgeDict[UserName]:
return print("恭喜你,登录成功。。。")
else:
count-=1
print("sorry,你输入的用户名和密码有误,请重新输入!")
continue
else:
print("连续登录三次错误,系统将自动退出!")
sys.exit()
#解析文件parse
def loadData(file_name):
with open(file_name,"r",encoding="utf-8") as f:
for i in f.readlines():
data = i.strip().split(",")
informationDict.setdefault(data[1],data[2:])
return informationDict
#查询
def findFun(para1,para2,para3):
temp = ["name","age","phonenumber","dept","hiredate"]
logicSymbol = [">","<","=",">=","<=","like"]
if para3[0] in temp and para3[1] in logicSymbol:
if para3[1] == ">":
judgeCondition = "".join(para3[1:])
for i in informationDict.keys():
temp.append(informationDict[i][0])
print(temp)
result = {k:v for k,v in informationDict.items() if int(v[0]) >26 }
elif para3[1] == ">":
print()
else:
print()
else:
print("表中不包含你过滤项目或条件语法有误")
#打印信息
def printInfoFun():
global UserName
print("""
***************************
Name:{0}
Age:{1[0]}
PhoneNumber:{1[1]}
Dept:{1[2]}
HireDate:{1[3]}
***************************
""".format(UserName,informationDict[UserName]))
# 创建
def createFun():
print()
#删除
def deleteFun(para1,para2):
print()
#修改
def modifyFun():
print()
login()
print("欢迎进入个人信息查询系统,请输入合法语法指令".center(50,"*"))
while 1:
command = input(">>>>>>>").strip()
splitResult = command.split()
para2 = splitResult[splitResult.index("from"):splitResult.index("where")+1]
para3 = splitResult[(splitResult.index("where")+1):]
if command.startswith("find"):
# print("{0}的个人信息如下:
{1}".format(UserName,informationDict[UserName]))
findFun(splitResult[1],para2,para3)
continue
elif command.startswith("add"):
createFun()
continue
elif command.startswith("del"):
deleteFun()
continue
elif command.startswith("update"):
print("{0}的个人信息如下:
{1}".format(UserName,informationDict[UserName]))
modifyFun()
continue
else:
print("输入指定有误,请重新输入!")
continue
1,Alex Li,22,13651054608,IT,2013-04-01
2,Jack Wang,28,13451024608,HR,2015-01-07
3,Rain Wang,21,13451054608,IT,2017-04-01
4,Mack Qiao,44,15653354208,Sales,2016-02-01
5,Rachel Chen,23,13351024606,IT,2013-03-16
6,Eric Liu,19,18531054602,Marketing,2012-12-01
7,Chao Zhang,21,13235324334,Administration,2011-08-08
8,Kevin Chen,22,13151054603,Sales,2013-04-01
9,Shit Wen,20,13351024602,IT,2017-07-03
10,Shanshan Du,26,13698424612,Operation,2017-07-02
Alex Li,123
Jack Wang,1234
Rain Wang,1235
Mack Qiao,1236
Rachel Chen,1237
Eric Liu,1238
Chao Zhang,1239
Kevin Chen,1230
Shit Wen,12355
Shanshan Du,123598