Employee Management Project

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 4

import mysql.

connector

con = mysql.connector.connect(
host="localhost", user="root", password="", database="emp")

def Add_Employee():
Id = input("Enter Employee Id : ")
if(check_employee(Id) == True):
print("Employee aready exists\nTry Again\n")
menu()
else:
Name = input("Enter Employee Name : ")
Post = input("Enter Employee Post : ")
Salary = input("Enter Employee Salary : ")
data = (Id, Name, Post, Salary)
sql = 'insert into empd values(%s,%s,%s,%s)'
c = con.cursor()
c.execute(sql, data)
con.commit()
print("Employee Added Successfully ")
menu()
def Promote_Employee():
Id = int(input("Enter Employ's Id"))

if(check_employee(Id) == False):
print("Employee does not exists\nTry Again\n")
menu()
else:
Post = input("Enter change in post")

sql = 'select post from empd where id=%s'


data = (Id,)
c = con.cursor()

c.execute(sql, data)

r = c.fetchone()
t = Post

sql = 'update empd set Post=%s where id=%s'


d = (t, Id)

c.execute(sql, d)

con.commit()
print("Employee Promoted")
menu()

def Bonus_Employee():
Id = int(input("Enter Employ's Id"))
if(check_employee(Id) == False):
print("Employee does not exists\nTry Again\n")
menu()
else:
bn = int(input("Enter Bonus:"))

sql = 'select salary from empd where id=%s'


data = (Id,)
c = con.cursor()

c.execute(sql, data)

r = c.fetchone()
t = r[0]+bn

sql = 'update empd set salary=%s where id=%s'


d = (t, Id)

c.execute(sql, d)

con.commit()
print("Bonus Added")
menu()

def leave_Employee():
Id=input("Enter employee Id")
day=int(input("Enter the number of leave days"))
if (day<=3):
print("LEAVE GRANTED")
print("EMPLOYEE ID:",Id,",",day,"DAYS LEAVE GRANTED")
else:
print("PLEASE SEEK PERMISSION FROM THE HR MANAGER")
menu()

def Remove_Employee():
Id = input("Enter Employee Id : ")

if(check_employee(Id) == False):
print("Employee does not exists\nTry Again\n")
menu()
else:

sql = 'delete from empd where id=%s'


data = (Id,)
c = con.cursor()

c.execute(sql, data)
con.commit()
print("Employee Removed")
menu()

def check_employee(employee_id):

sql = 'select * from empd where id=%s'

c = con.cursor(buffered=True)
data = (employee_id,)

c.execute(sql, data)

r = c.rowcount
if r == 1:
return True
else:
return False

def Display_Employees():

sql = 'select * from empd'


c = con.cursor()

c.execute(sql)

r = c.fetchall()
for i in r:
print("Employee Id : ", i[0])
print("Employee Name : ", i[1])
print("Employee Post : ", i[2])
print("Employee Salary : ", i[3])
print("---------------------\
-----------------------------\
------------------------------\
---------------------")

menu()

def menu():
print(" Employee Management System")
print("Press: ")
print("1 to Add Employee")
print("2 to Remove Employee ")
print("3 to Display Employee")
print("4 to Bonus Employees")
print("5 to promote Employee")
print("6 to Grant leave")
print("7 tO Exit")

ch = int(input("Enter your Choice "))


if ch == 1:
Add_Employee()
elif ch == 2:
Remove_Employee()
elif ch == 4:
Bonus_Employee()
elif ch == 3:
Display_Employees()
elif ch == 7:
Exit(0)
elif ch== 5:
Promote_Employee()
elif ch==6:
leave_Employee()
else:
print("Invalid Choice")
menu()

menu()

You might also like