员工信息表
a = True def out(): def wapper(f): def inner(): global a if a: flag3=True while flag3: a = input("用户名:") b = input("密码:") if a=="王镇" and b=="大脸": a=False f() break else: print("用户名或,密码错误") else:f() return inner return wapper # # # 增 @out() def func(): l = [] with open ("员工信息","r",encoding="utf-8")as f: for i in f: i=i.strip().split(",") l.append(i[0]) a1=max(l) # print(i) flag=True while flag: a = input("输入id,或Q\q推出") if a.upper()=="Q":break if a.isdigit()==False: print("输入数字") continue if eval(a)-eval(a1)==1: b=input("输入name") c = input("输入age") d = input("输入phone") e = input("输入job") with open ("员工信息" ,"a",encoding="utf-8")as f: f.write("%s %s" % (a +"," + b +","+ c+"," + d+"," + e, "\n")) break else:print("序号有误,重新输入") # 删 @out() def func1(): l = [] l1 = [] flag1 = True while flag1: with open("员工信息","r",encoding="utf-8")as f: for i in f: i=i.strip().split(",") l1.append(i[0]) a=input("输入想删除信息的序号,或Q\q退出 ") if a.upper()=="Q": flag1=False break elif a in l1: with open("员工信息", "r", encoding="utf-8")as f: for i in f: i = i.strip().split(",") if a==i[0]: i=",".join(i) print("是否删除",i) choice=input("Y\\N") if choice.upper()=="Y": continue else: i = i.strip().split(",") l.append(i) else:l.append(i) with open("员工信息","w",encoding="utf-8")as f: for i in l: i=",".join(i) f.write("%s%s"%(i,"\n")) # flag1=False break else:print("输入有误,重新输入") # # # 查 @out() def func2(): l2=[] l1=[] flag3 = True while flag3: with open("员工信息", "r", encoding="utf-8")as f: for i in f: l2.append(i) i=i.strip().split(",") l1.append(i[0]) a=input("输入想查询信息的序号,或Q\q退出 ") if a.upper()=="Q":break for l in l1: if a==l: k=(l2[eval(l)-1]).strip() print(k) break else: print("输入有误") #改 @out() def func3(): l=[] a=input("要修改的序号") with open("员工信息", "r", encoding="utf-8")as f: for i in f: i = i.strip().split(",") if a != i[0]: l.append(i) else: i=",".join(i) print(i) b=input("要修改的name") c = input("要修改的age") d = input("要修改的phone") e = input("要修改的work") a=a+","+b+","+c+","+d+","+e a = a.strip().split(",") l.append(a) # print(l) with open("员工信息", "w", encoding="utf-8")as f: for i in l: i = ",".join(i) f.write("%s%s" % (i, "\n")) # func3() l=["增","删","改","查"] print(list(zip(range(1,5),l))) while 1: c =input("输入要进行的操作的序号 Q或q退出") if c.upper()=="Q":break # c=eval(c) if c=="1": func() elif c=="2": func1() elif c=="3": func3() elif c=="4": func2() else:pass
# select name, age where age>22 # select * where job = IT # select * where phone like 133 def open1(a,b): global a2 dic = {"name": 1, "age": 2, "phone": 3, "job": 4} a1 = a.split("where")[1] if b in a1: a2 = a1.split(b) with open("员工信息", encoding="utf-8")as f: for i in f: i = i.strip().split(",") if b=="=": if i[dic[a2[0].strip()]] ==a2[1].strip(): l1 = ",".join(i) print(l1) elif b == "like": if a2[1].strip() in i[dic[a2[0].strip()]]: l1 = ",".join(i) print(l1) elif b == ">": if i[dic[a2[0].strip()]] > a2[1].strip(): l1 = ",".join(i) print(l1) elif b == "<": if i[dic[a2[0].strip()]] < a2[1].strip(): l1 = ",".join(i) print(l1) def open2(a,b): l = [] dic = {"name": 1, "age": 2, "phone": 3, "job": 4} a1 = a.split("where")[0:1] a2 = a.split("where")[1] # print(type(a1),"\n",type(a2)) a1 = a1[0].strip().split(",") # a1.remove("select") l1 = a1[1:] for p in l1: l.append(p) a3 = a1[0].split(" ") a3.remove("select") l = (l + a3) l.reverse() print(l) # print(a1, "\n", a2,l) if b in a2: a2 = a2.split(b) with open("员工信息", "r", encoding="utf-8")as f: for i in f: i = i.strip().split(",") if b == ">": if i[dic[a2[0].strip()]] > a2[1].strip(): l1=[i[dic[k.strip()]] for k in l] print(l1) elif b =="<": if i[dic[a2[0].strip()]] < a2[1].strip(): l1 = [i[dic[k.strip()]] for k in l] print(l1) elif b == "=": if i[dic[a2[0].strip()]] == a2[1].strip(): l1 = [i[dic[k.strip()]] for k in l] print(l1) elif b == "like": if a2[1].strip() in i[dic[a2[0].strip()]]: l1 = [i[dic[k.strip()]] for k in l] print(l1) def f(): while 1 : a = input(">>>>或Q\\q退出") if a.upper()=="Q":break if "*" in a: if "=" in a: open1(a,"=") elif ">"in a: open1(a,"=") elif "<" in a: open1(a,"<") elif "like" in a: open1(a, "like") elif "*" not in a: if ">" in a: open2(a,">") elif "<" in a: open2(a, "<") elif "=" in a: open2(a, "=") elif "like" in a: open2(a, "like") f()