Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

import time

import datetime as dt
import mysql.connector as sql
import Tables_EMS
from tabulate import tabulate

conn=sql.connect(host='localhost',user='root',password='abc123',database='EMS')
mycursor=conn.cursor()

def menu():
print()
print("EMPLOYEES MANAGEMENT SYSTEM".center(100,'*'))

while True:
print("\n\n")
print("EMPLOYEES MENU".center(100,'*'))
print("1. Employee registeration")
print("2. Employee List")
print("3. Update salary")
print("4. Details of an Employee")
print("5. Number of employees in each department")
print("6. Edit Employee Details")
print("7. Delete Employee Details")
print("8. Logout")

choice=int(input("Enter the choice: "))

if choice==1:
register()
elif choice==2:
emp_list()
elif choice==3:
update_salary()
elif choice==4:
emp_details()
elif choice==5:
em_count()
elif choice==6:
emp_edit()
elif choice==7:
emp_delete()()
elif choice==8:
break
else :
print("\n\n\t Invalid Choice. Try Again")

def register():
print("Employee Registration".center(100,'*'))
v_em_no=int(input("enter your employee ID: "))
v_em_name=input ("enter your name: ")
v_em_dept=input( "enter department you want to join: ")
v_em_salary=input ("enter your salary: ")
v_em_age=int(input("enter your age: "))

v_sql_insert="insert into office values("+str(v_em_no)+",'"


+v_em_name+"','"+v_em_dept+"',"+str(v_em_salary)+","+str(v_em_age)+")"
mycursor.execute(v_sql_insert)
conn.commit()

print("congrats you have joined suuceessfully")


print(" registerd suyccessfully ")

def emp_list():
print("List of Employee".center(100,'*'))
mycursor.execute("select * from office")
result=mycursor.fetchall()
print()
print(tabulate(result, headers=['E_Number', 'E_Name','Department','E_Salary', 'Age']))
print("\n\n")

def update_salary():
print("Update Employee Salary".center(100,'*'))
nam=input("Enter the employee name: ")
mycursor.execute("select em_name from office where em_name='{}'".format(nam))
data=mycursor.fetchall()

if data:
ch=input("Do you want to update the salary(Y/N): ")
if ch.upper()=='Y':
sal=int(input("Enter the new salary: "))
mycursor.execute("update office set em_salary = {} where
(em_name='{}')".format(sal,nam))
conn.commit()
print("\n\nSalary updated successfully ")
else:
print("Sorry, Employee Name NOT Found")

def emp_details():
print()
print("Employee Details".center(100,'*'))
eid=int(input("Enter the employee ID: "))

mycursor.execute("select * from office where em_no={}".format(eid))


data=mycursor.fetchall()
if data:
print(tabulate(data, headers=['E_Number', 'E_Name','Department','E_Salary', 'Age']))
else:
print("\nInvalid Employee ID.")

def em_count():
print()
print("Employee In Each Department".center(100,'*'))
mycursor.execute("select em_dept, count(*) from office group by em_dept")
data=mycursor.fetchall()
if data:
print(tabulate(data, headers=['Department', 'No. of Employee']))
else:
print("\n\nRecord NOT Found")

def emp_edit():
eid=int(input("Enter Employee ID: "))

mycursor.execute("select * from office where em_no={}".format(eid))


data=mycursor.fetchall()

if data:
name=data[0][0]
dept=data[0][1]
age=int(data[0][3])
print(tabulate(data, headers=['E_Number', 'E_Name','Department','E_Salary', 'Age']))
ch=input("\n\nDo you want edit Name(Y/N): ")
if ch.upper()=='Y':
name=input("Enter New Employee Name: ")

ch=input("Do you want edit Department(Y/N): ")


if ch.upper()=='Y':
dept=input("Enter New Employee Department: ")
ch=input("Do you want edit Age(Y/N): ")
if ch.upper()=='Y':
age=int(input("Enter New Employee Age: "))

mycursor.execute("update office set em_name='{}', em_dept='{}',em_age={} where


(em_no={})".format(name,dept,age,eid))
conn.commit()
print("\n\nEmployee Details Updated Successfully ")
else:
print("\n\nInvalid Employee ID")

def emp_delete():
eid=int(input("Enter Employee ID: "))

mycursor.execute("select * from office where em_no={}".format(eid))


data=mycursor.fetchall()

if data:
print("\nEmployee Details")
print(tabulate(data, headers=['E_Number', 'E_Name','Department','E_Salary', 'Age']))
ch=input("\n\nDo you want delete employee details(Y/N): ")
if ch.upper()=='Y':
mycursor.execute("delete from office where (em_no={})".format(eid))
conn.commit()
print("\n\nEmployee Details Deleted Successfully ")
else:
print("\n\nInvalid Employee ID")

########### MAIN METHID#############

while True:
print("\n\n")
print('WELCOME TO START EMPLOYEE MANAGEMENT SYSTEM'.center(100,'*'))
print("\t\t\t\t\t\t\t\t\t",dt.datetime.now())
print()

print("MAIN MENU".center(100,'*'))
print()
print('1. REGISTER \n')
print('2. LOGIN \n')
print('3. Exit\n')

n=int(input('Enter your choice(1-3): '))

if n== 1:
name=input('Enter User Name: ')
passwd=input('Enter a 4 DIGIT Password: ')
print()
sql="INSERT INTO log_id (user_id, password) values ('" + name + "',' " + passwd + " ') "
mycursor.execute(sql)
conn.commit()

print('\n\nUser Created Succesfully\n\n')


menu

elif n==2 :
name=input('Enter your Username: ')
passwd=input('Enter your 4 DIGIT Password=')

mycursor.execute("select * from log_id where user_id=" + name + " and password=" +


passwd )
data=mycursor.fetchall()

if not data:
print('\n\nInvalid Username or Password')
c=input("\n\tPress any key to continue....")
else:
menu()

elif n==3:
break

else:
print("\n\n\t Invalid Choice. Try Again")

mycursor.close()
conn.close()

You might also like