یک برنامه کامل برای مدیر با امکان حذف و ویرایش کارمندان
import os
import dill
import sys
admin_login_info={"admin":"12345"}
if os.path.exists("Employees_Info.pkl"):
with open("Employees_info.pkl","rb") as f:
Employees_list=dill.load(f)
else:
Employees_list=[]
class Employees:
def __init__(self,username,password):
self.__username=username
self.__password=password
@property
def username(self):
return self.__username
@username.setter
def username(self,newusername):
self.__username=newusername
@property
def password(self):
return self.__password
@password.setter
def password(self,newpass):
self.__password=newpass
def __str__(self):
return f"{self.__username}_{self.__password}"
print("wellcome")
while 1:
username=input("Plz enter admin username:\n")
password=input("Plz enter admin password\n")
if username in admin_login_info and admin_login_info[username]==password:
print("login succesful")
while 1:
print("--------------")
user_choice=input("1.create a new employee\n2.edit a employee\n\
3.delete a employee\n4.enter 4 to save and end\n--------------\n")
if user_choice=="1":
while 1:
print("enter 0 to go back")
Ename=input("plz enter employee username:\n")
if Ename=="0":break
Epass=input("plz enter employee password:\n")
if Ename=="0":break
emp=Employees(Ename,Epass)
Employees_list.append(emp)
print("created")
elif user_choice=="2":
if not Employees_list:print("there is no user,plz create user first")
else:
for i,item in enumerate(Employees_list,start=1):
print(i,".",item)
try:
choice=int(input("choose wich employee you want to edit\
(enter 0 to go back):\n"))
if choice==0:continue
elif choice<1 or choice>len(Employees_list):
print("plz enter a valid choice")
else:
choice=Employees_list[choice-1]
Ename=input("plz enter new username to change:\n")
Epass=input("plz enter new password to change:\n")
choice.username=Ename
choice.password=Epass
print("changed")
except:print("enter a valid choice")
elif user_choice=="3":
if not Employees_list:print("there is no user,plz create user first")
else:
for i,item in enumerate(Employees_list,start=1):
print(i,".",item)
try:
choice=int(input("choose wich employee you want to edit:\n"))
if choice<1 or choice>len(Employees_list):
print("plz enter a valid choice")
else:
Employees_list.pop(choice-1)
print("deleted")
except:print("enter a valid choice")
elif user_choice=="4":
with open("Employees_Info.pkl","wb") as f:
dill.dump(Employees_list,f)
print("ended and saved")
sys.exit()
else:
print("enter a valid choice")
else:
print("username or password is wrong")
یک برنامه ساده برای کارمندان
import os
import dill
import datetime
print("wellcome")
if os.path.exists("Employees_Info.pkl"):
with open("Employees_Info.pkl", "rb") as f:
E_INFO=dill.load(f)
while True:
e_username=input("plz enter username(enter 0 to end):\n")
if e_username=="0":break
e_password=input("plz enter password(enter 0 to end):\n")
if e_password=="0":break
for item in E_INFO:
if f"{e_username}_{e_password}"==str(item):
print("login succesfull")
joindate = str(datetime.datetime.now())
print(f"you joined in:{joindate}")
with open("Employees_joindate", "a") as f:
f.write(f"{e_username} joined in:{joindate}\n")
print("program end")
break
else:#حلقه ی فور الس
print("user name or paswword is wrong")
else:
print("admin doesnt created the file")