SOURCE Code
#Employee Management System.
#CBSE Class 12th.
#By Muhammad Najm.
import pickle
line="-"*90
#Adding Employee details to file.
def add_emp():
emp={}
emp['id']=input("Enter Employee ID: ")
emp['fst']=input("Enter First Name: ")
emp['lst'] =input("Enter Last Name: ")
emp['dsg'] =input("Enter Designation: ")
emp['adds'] =input("Enter Address: ")
emp['phn'] =input("Enter Phone Number: ")
emp['sly']=input("Enter Salary:")
f=open("[Link]","ab")
[Link](emp,f)
[Link]()
print("Employee added successfully!")
#Display Employee details.
def dsp_all():
try:
f=open("[Link]","rb")
print("--------------------Employee Details--------------------")
while True:
try:
emp = [Link](f)
print("ID: ",emp['id'])
print("Name: ",emp['fst'],emp['lst'])
print("Designation: ",emp['dsg'])
print("Address: ",emp['adds'])
print("Phone: ",emp['phn'])
print("Salary: ",emp['sly'])
print("-"*45)
exceptEOFError:
print("File END!")
break
[Link]()
except FileNotFoundError:
print("No Employee record found.")
#Search Employee by ID.
def srch_emp():
e_id=input("Enter Employee ID to search for: ")
found=False
try:
f=open("[Link]","rb")
while True:
try:
emp=[Link](f)
if emp['id']==e_id:
print("Employee Found:")
print(emp)
found=True
break
exceptEOFError:
break
[Link]()
if not found:
print("Employee not found.")
except FileNotFoundError:
print("No Employee record found.")
#Update an Employee record.
def updt_emp():
e_id=input("Enter Employee ID to update: ")
updated=False
try:
f = open("[Link]","rb")
data=[]
while True:
try:
emp=[Link](f)
[Link](emp)
exceptEOFError:
break
[Link]()
#Updating Employee Record.
for emp in data:
If emp['id']==e_id:
print("Current Record: ",emp)
print("Enter new details (press ENTER to skip):")
fn=input("Enter new First Name: ")
ln=input("Enter new Last Name: ")
ds=input("Enter new Designation: ")
ad=input("Enter new Address: ")
ph=input("Enter new Phone: ")
sl=input("Enter new Salary: ")
if fn != "":
emp['fst'] = fn
if ln != "":
emp['lst'] = ln
if ds != "":
emp['dsg'] = ds
if ad != "":
emp['ads'] = ad
if ph != "":
emp['phn'] = ph
if sl != "":
emp['sly'] = sl
updated = True
if updated:
f=open("[Link]","wb")
for emp in data:
[Link](emp,f)
[Link]()
print("Record updated successfully")
else:
print("Employee ID not found")
except FileNotFoundError:
print("No employee record found")
#Deleting Employee Record.
def del_emp():
e_id=input("Enter Employee ID to delete: ")
deleted = False
try:
f=open("[Link]","rb")
data=[]
while True:
try:
emp=[Link](f)
[Link](emp)
except EOFError:
break
[Link]()
new_data=[]
for emp in data:
if emp['id'] != e_id:
new_data.append(emp)
else:
deleted = True
if deleted:
f = open("[Link]","wb")
for emp in new_data:
[Link](emp,f)
[Link]()
print("Employee deleted successfully!")
else:
print("Employee ID not found.")
except FileNotFoundError:
print("No Employee record found.")
#Menu Driven Function.
def menu():
print("="*91)
print(" *EMPLOYEE MANAGEMENT SYSTEM*")
print("="*91)
print("1. Add Employee.")
print("2. Display All Employee.")
print("3. Search Employee.")
print("4. Update Employee.")
print("5. Delete Employee.")
print("6. Exit.")
print("="*91)
while True:
ch=input("Enter your choice(1–6): ")
if ch=='1':
add_emp()
print(line)
elif ch=='2':
dsp_all()
print(line)
elif ch=='3':
srch_emp()
print(line)
elif ch=='4':
updt_emp()
print(line)
elif ch=='5':
del_emp()
print(line)
elif ch=='6':
print("Exiting program…")
print('\n')
print("Thank you for using the program.")
print("Program by: Muhammad Najm.")
print(line)
print(line)
print(line)
break
else:
print("Invalid choice! Try again.")
#Running Program.
A=input("Do you want to use the program? (Y / N) ")
if 'Y' in A or 'y' in A:
menu()
else:
print("Thank You.")