# Source Code
import [Link] as scon
con=[Link](host='localhost',user='root',password='saurabh',database=
'emp')
if con.is_connected:
print ("Connected")
#ALL THE FUCTIONS USED
def getlog():
cur=[Link]()
[Link]('select * from log;')
log=[Link]()
return (log)
def getsal():
cur=[Link]()
[Link]('select * from sal;')
sal=[Link]()
return (sal)
#Get id
def getid():
while True:
i=int(input("\nEnter your id :"))
if i>1100 and i<10000:
return (i)
break;
else :
print ("Enter appropriate id")
#Get password
def getpass():
while True:
p=int(input("Enter your 4-digit Password :"))
if p>999 and p<10000:
return (p)
break;
else :
print ("Password must contain 4 digits")
#ENROLL AND GET ID FOR NEW EMPLOYEES
def enroll():
name=input("Enter your name ")
name=[Link]()
while True:
gnd=input("Enter your gender ")
gnd=[Link]()
if gnd=="M" or gnd=="F":
break;
post=input("Enter your post ")
post=[Link]()
mob=int(input("Enter your mobile no "))
while True:
pas=int(input("Choose your password [4-digit] "))
if pas>999 and pas<10000:
break;
cur=[Link]()
qr="INSERT INTO log (pass, name, post, gender, mobile_no) VALUES
(%s, %s, %s, %s, %s)"
val=(pas,name,post,gnd,mob)
[Link](qr,val)
[Link]()
print ("\nYour record is inserted")
emp_id=[Link]
[Link]()
return (emp_id)
#FETCH RECORD FOR GIVEN ID AND PASSWORD
def data(i,p):
cur=[Link]()
qr="Select * from log where id = %s"
val=(i,)
[Link](qr,val)
tup=[Link]()
[Link]()
cur=[Link]()
qr="Select * from sal where id = %s"
val=(i,)
[Link](qr,val)
tp=[Link]()
eid=0
pas=0
for rec in tup:
eid=int(rec[0])
pas=int(rec[1])
if i==eid and p==pas:
print ("Details: ",tup)
print ("Salary: ",tp)
else :
print ("\nWrong id or password\n")
#TO VALIDATE ID AND PASSWORD
def cnf(i):
while True:
p=int(input("Enter your 4-digit Password :"))
if p>999 and p<10000:
break;
else :
print ("Password must contain 4 digits")
cur=[Link]()
qr="Select * from log where id = %s"
val=(i,)
[Link](qr,val)
tup=[Link]()
[Link]()
eid=0
pas=0
for rec in tup:
eid=int(rec[0])
pas=int(rec[1])
if i==eid and p==pas:
perm=1
print ("Access Given")
return (perm)
else :
print ("\nWrong id or password")
#CACULATION AND ENTERY OF SALARY INTO DATABASE
def ipsal(i):
whr=int(input("\nEnter your working hours :"))
lvs=int(input("Enter numbers of leaves taken this month :"))
pnt=lvs*200
sal=(whr*400)-pnt
cur=[Link]()
qr="insert into sal values (%s, %s, %s, %s, %s)"
val=(i,whr,lvs,pnt,sal)
[Link](qr,val)
[Link]()
[Link]()
print ("Your salary is: $",sal)
#PROGRAMS
while True:
print ("\nWelcome to Employee Management System\n")
print ("Enter 0 to view database ")
print ("Enter 1 to enroll new employee ")
print ("Enter 2 to view employee data ")
print ("Enter 3 to calculate salary ")
print ("Enter 4 to modify Password")
print ("Enter 9 to exit program ")
choice=int(input("\nEnter your choice "))
if choice==0:
print ("\nEmployees")
for i in getlog():
print (i)
print ("\nSalary ")
for i in getsal():
print (i)
elif choice==1:
ids=enroll()
print ("\nYour employee id is: ",ids)
elif choice==2:
i=getid()
p=getpass()
data(i,p)
elif choice==3:
i=getid()
perm=cnf(i)
if perm==1:
ipsal(i)
elif choice==4:
i=getid()
print ("Enter your previous password")
perm=cnf(i)
if perm==1:
print ("\nEnter New Password\n")
np=getpass()
cur=[Link]()
qr="update log set pass =%s where id =%s"
val=(np,i)
[Link](qr,val)
[Link]()
[Link]()
print ("Your password has been modified")
elif choice==9:
print ("\nThanks for using this program\n")
break;
else:
print ("Enter appropriate choice")
else:
print ("Connection Error")