0% found this document useful (0 votes)
36 views13 pages

EMPLOYEE MANAGEMENT SYSTEM Eding (Repaired) Sorce Code

The document contains the source code for an employee management system program written in Python. The program uses dictionaries and the pickle module to store employee data in a binary file. It features menus for registering new employees, displaying all employee details, searching employees, modifying employee details, and deleting employees. The menus utilize functions to handle each task and call the main menu after completing an action.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views13 pages

EMPLOYEE MANAGEMENT SYSTEM Eding (Repaired) Sorce Code

The document contains the source code for an employee management system program written in Python. The program uses dictionaries and the pickle module to store employee data in a binary file. It features menus for registering new employees, displaying all employee details, searching employees, modifying employee details, and deleting employees. The menus utilize functions to handle each task and call the main menu after completing an action.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

SOURCE CODE

import pickle
import os import
datetime
from prettytable import PrettyTable
Emp={ } # Creating Empty Dictionary
print("*"*68)
print("* *")
print("* Welcome to Employee Management System *")
print("* *")
print("*"*68)
now=datetime.datetime.now()
print("Date:",now.strftime("%d-%m-%y"),end="\t\t\t\t\t")
print("Time:",now.strftime("%H:%M:%S"))
count=0

User=input("Enter User Name:")


Pass=input("Enter Password:")

#Main Menu
def MainMenu(): global
count
if User=="admin" and Pass=="admin@123":
print("1.Employee Registration")
print("2.Display all Employees")
print("3.Search Particular Employee Details")
print("4.Modify Employee Detail")
print("5.Delete Employees Details")
opt=int(input("Enter your choice:"))
if opt==1:
Registration()
elif opt==2:
Display()

elif opt==3:
Search()
elif opt==4:
Modify()
elif opt==5:
Delete()
else:
print("Invalid Option")
exit()
else:

if count<2:
print("Try again!!! Invalid Username/Password") count+=1
MainMenu()
else:
print("Too Many Try, Sorry Access is Blocked!!!")

# Employee Registration Module


def Registration():
f=open("emp.dat",'ab') opt='y'
global Emp
print("-"*68)
print("| |")
print("| Welcome to Employee Registration Menu |")
print("| |")
print("-"*68)
while opt=='y':
Emp['Id']=int(input("Enter the Employee Id number:"))
Check=Search_Id()
if Emp['Id']==Check or Check==None:

Emp['Name']=input("Enter the Name of the Employee:")


Emp['Dob']=input("Enter the Employee's Date of birth:")
Emp['Gen']=input("Enter the Employee's Gender:")
Emp['Dept']=input("Enter the Employee's Department:")
Emp['Des']=input("Enter the Employee's Designation:")
Emp['Sal']=int(input("Enter the Employee's salary:"))
Emp['Doj']=input("Enter the Employee's Date of join:")
Emp['BG']=input("Enter the Employee's Blood group:")
Emp['Mobno']=int(input("Enter the Employee's Mobile number:"))
Emp['Adh']=int(input("Enter the Employee's Aadhar number:"))
Emp['Mail']=input("Enter the Employee's E-mail:")
Emp['Ms']=input("Enter the Employee's marital status:")
Emp['Country']=input("Enter the Employee's country name:")
pickle.dump(Emp,f)
opt=input("Do you want to add another Employee Details(y/n)?:") else:
print("Employee ID already exists") if
opt=='n':
print("Thank You, You're details are saved") f.close()
MainMenu()

#Employee Details Display Module


def Display():
f=open("emp.dat",'rb')
print("-"*68)

print("| |")
print("| Welcome to Employee Details Menu |")
print("| |")
print("-"*68)
x=PrettyTable()
try:
while True:
S=pickle.load(f)
x.field_names=list(S.keys())
x.add_row(list(S.values()))
except:

print(x)
f.close()
MainMenu()
# Employee Search Module
def Search():
print("1.Search using Employee Id")

print("2.Serach using Employee Aadhar number")

print("3.Search using Employee Department")

opt=int(input("Enter YourChoice:"))
if opt==1:

no=int(input("Enter the Employee Id:")) Search_Choice('Id',no)


elif opt==2:

Aadh=int(input("Enter the Employee's Aadhar Number:")) Search_Choice('Adh',Aadh)


elif opt==3:
Dep=input("Enter the Employee's Dept Name:")
Search_Choice('Dept',Dep)
MainMenu()

def Search_Id():
F=open("emp.dat",'rb')
try:
while True:
S=pickle.load(F)
return(S['Id'])
except:
F.close()

def Search_Choice(p,q):
F=open("emp.dat",'rb')
found=0 x=PrettyTable()
try:

while True:
S=pickle.load(F) if
S[p]==q:
x.field_names=list(S.keys())
x.add_row(list(S.values()))
found=1
except EOFError:
print(x) F.close()

if found==0:
print("Searching Record is not found") MainMenu()

#Employee Details Modification Module


def Modify():
F1=open("emp.dat",'rb')
F2=open("temp.dat","wb") f=0
print("-"*68)
print("| |")
print("| Welcome to Employee Modification Menu|")
print("| |")
print("-"*68)
x=PrettyTable()
no=int(input("\nEnter the employee id of which you want to modify:"))
try:
while True:
S=pickle.load(F1) if
S['Id']==no:

x.field_names=list(S.keys())
x.add_row(list(S.values()))
print("Before Modify")
print(x)
f=1

print("Choose one option from below")


print("1.Id","2.Name","3.Dob","4.Gender","5.Department","6.Designation","7.Salary","8
.Doj","9.Blood Group",sep=" ")

print("10.MobileNumber","11.AadharNumber","12.E-Mail Address","13.Martiual
Status","14.Country",sep=" ")
h=int(input("Enter which detail of the Emp you want to modify""\t"":")) if h==1:

ID=int(input(“Enter the new id of the Employee""\t"":"))

S['Id']=ID

elif h==2:
NAME=input("Enter the Name of the Employee""\t"":")
S['Name']=NAME
elif h==3:
Dob=input("Enter the new Dob of the Employee""\t"":")
S['Dob']=Dob
elif h==4:

Gender=input("\nEnter the Gender of the Employee""\t"":")


S['Gen']=Gender
elif h==5:
Dep=input("Enter the new Department of the Employee""\t"":")
S['Dept']=Dep

elif h==6:
Des=input("Enter the new Designation of the Employee""\t"":")
S['Des']=Des
elif h==7:
Sal=int(input(”Enter the new Salary of the Employee""\t"":"))
S['Sal']=Sal

elif h==8:
Doj=input("Enter the new DOJ of the Employee""\t"":")
S['Doj']=Doj
elif h==9:
BG=input("Enter the new Blood Group of the Employee""\t"":")
S['BG']=BG
elif h==10:
Mob=int(input("Enter the new Mobile Number ""\t"":"))
S['Mobno']=Mob
elif h==11:
Aadhar=int(input("Enter the new Aadhar Number ""\t"":"))
S['Adh']=Aadhar
elif h==12:
Email=input("Enter the new Email Address of the Employee""\t"":")
S['Mail']=Email
elif h==13:
MS=input("Enter the Present Martial Status of the Employee""\t"":")
S['Ms']=MS
elif h==14:
Country=input("Enter the new Country of the Employee""\t"":")
S['Country']=Country else:
print("Invalid option")
break
pickle.dump(S,F2)
else:
pickle.dump(S,F2)

except:
F1.close()
F2.close()
if f==0:
print("Employee ID not found") else:
print("Record Modified Successfully")
os.remove("emp.dat") os.rename("temp.dat","emp.dat")
Search_Choice('Id',no)
MainMenu()

# Employ ee Details Delete Module


def Delete():
F1=open("emp.dat",'rb')
F2=open("temp.dat","wb") f=0
print("-"*68)

print("| |")
print("| Welcome to Employee Deletion Menu |")
print("| |")
print("-"*68)
no=int(input("Enter the employee id of which you want to Delete?")) x=PrettyTable()

try:
while True:
S=pickle.load(F1) if
S['Id']==no:
x.field_names=list(S.keys())
x.add_row(list(S.values()))
print(x)
f=1

opt=input("Do you want to Delete the above Employee(y/n)?")

if opt=='y':
print("The above Employee Details are Deleted Successfully") else:
pickle.dump(S,F2)
else:
pickle.dump(S,F2)
except:
F1.close()
F2.close()
if f==0:

print("Employee ID not found") else:


os.remove("emp.dat") os.rename("temp.dat","emp.dat")
MainMenu()

# Main Program
MainMenu()
SCREEN SHOTS

1. Main Menu:

2. Employee Registration Menu:


3. Employee Details Display Menu:

4. Employee Search Menu:

5. Employee Modification Menu:


6. Employee Delete Menu:
BIBLIOGRAPHY

BOOKS:
❖ COMPUTER SCIENCE WITH PYTHON -BY SUMITA ARORA
❖ COMPUTER SCIENCE WITH PYTHON -BY PREETI ARORA
❖ PYTHON COOKBOOK

WEBSITES:

❖ www.geeksforgeeks.org
❖ https://docs.python.org/3/
❖ https://www.w3schools.com/python/

*************************************************************************************

You might also like