CMD版HR人力資源管理理系統
阿新 • • 發佈:2019-01-12
1 print("歡迎來到HR人力資源管理理系統") 2 menu = ("1:檢視員工資訊", "2:新增員工資訊", "3:修改員工資訊", "4:刪除員工資訊", "Q:退出") 3 def menu_op(): #定義選單函式,選擇操作 4 print(menu) 5 msg = input("請做出你的選擇或退出:") 6 if msg=="1": 7 look() 8 elif msg=="2": 9 add()10 elif msg=="3": 11 amend() 12 elif msg=="4": 13 re() 14 elif msg.upper()=="Q": 15 exit() 16 else: 17 print("請重新輸入!!") 18 menu_op() 19 def look(): 20 with open("emp.db", "r+", encoding="utf-8") as f: 21 people = f.readlines() #每行以列表形式,讀取檔案所有內容 22 #print(people) 23 msg = input("請輸入你要檢視的員工ID(Q進入選單):") 24 if msg.isdigit(): 25 for i in people: # 26 if i[0] == msg: #根據ID選擇列表內員工 27 print(i) 28look() 29 elif msg.upper()=="Q": 30 menu_op() 31 else: 32 print("請正確輸入!!") 33 def add(): 34 while True: 35 with open("emp.db","r+",encoding="utf-8") as f: 36 people = f.readlines() 37 f.seek(0) 38 print(people) 39 msg = input("請輸入您的ID,姓名,薪水(用逗號分隔):") 40 #print(msg.split(",")[0]) 41 if msg.upper()=="Q": 42 menu_op() 43 elif len(msg.split(",")) !=3: 44 print("你的輸入有誤,請重新輸入!!") 45 else: 46 for i in people: 47 if i.strip()==msg: 48 print("你輸入的員工已存在!!") 49 add() 50 if len(people) < 1 or i.strip()!=msg: 51 f.seek(0,2) 52 f.write(msg + "\n") 53 f.flush() 54 f.close() 55 add() 56 def amend(): 57 with open("emp.db", "r+", encoding="utf-8") as f: 58 people = f.readlines() 59 print(people) 60 msg = input("請輸入你要修改的員工ID(Q退出):") 61 if msg.isdigit(): 62 for i in people: 63 if i.split(",")[0] == msg: 64 print(i) 65 msg1 = input("請重新輸入您的ID,姓名,薪水(用逗號分隔,Q退出):") 66 if msg1.upper() == "Q": 67 amend() 68 elif len(msg1.split(",")) != 3: 69 print("你的輸入有誤,請重新輸入!!") 70 else: 71 for i in people: 72 if msg==i[0]: 73 people.remove(i) 74 people.append(msg1+"\n") 75 f.seek(0) 76 f.write("".join(people)) 77 f.flush() 78 f.close() 79 amend() 80 elif msg.upper() == "Q": 81 menu_op() 82 def re(): 83 with open("emp.db", "r+", encoding="utf-8") as f: 84 people = f.readlines() 85 print(people) 86 msg = input("請輸入你要刪除的員工ID(Q退出):") 87 if msg.isdigit(): 88 for i in people: 89 if msg == i[0]: 90 people.remove(i) 91 #people[int(msg)-1] = msg1 92 f.seek(0) 93 f.truncate() 94 f.write("".join(people)) 95 f.flush() 96 f.close() 97 re() 98 elif msg.upper()=="Q": 99 menu_op() 100 else: 101 print("請重新輸入!!") 102 menu_op()