0% found this document useful (0 votes)
2 views

source code

The document is a Python script that connects to a MySQL database to create and manage employee records. It allows users to create a database and a table, add employee records, display all records or specific records, delete records, and modify existing records. The script includes a menu-driven interface for user interaction and uses the tabulate library for formatted output.

Uploaded by

KING KUNAL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

source code

The document is a Python script that connects to a MySQL database to create and manage employee records. It allows users to create a database and a table, add employee records, display all records or specific records, delete records, and modify existing records. The script includes a menu-driven interface for user interaction and uses the tabulate library for formatted output.

Uploaded by

KING KUNAL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

import mysql.

connector

import datetime

from tabulate import tabulate

db=input("enter name of your database:")

mydb=mysql.connector.connect(host="localhost",user="root",passwd="1166")

mycursor=mydb.cursor()

sql="CREATE DATABASE if not exists %s" % (db,)

mycursor.execute(sql)

print("Database created Successfully")

mycursor=mydb.cursor()

mycursor.execute("Use "+db)

TableName=input("name of the table to be created:")

query="Create table if not exists "+TableName+" \

(empno int primary key,\

name varchar(20) not null,\

job varchar(20),\

BasicSalary int,\

DA float,\

HRA float,\

GrossSalary float,\

Tax float,\

NetSalary float)"

print("Table "+TableName+" created successfully.....")

mycursor.execute(query)

while True:

print('\n\n\n')
print("."*100)

print('MAIN MENU'.center(100))

print("*"*100)

print('\t\t\t\t 1.Adding Employee records')

print('\t\t\t\t 2.FOR DISPLAYING RECORD OF ALL THE EMPLOYEE')

print('\t\t\t\t 3.FOR DISPLAYING RECORD OF A PARTICULAR EPLOYEE')

print('\t\t\t\t 4.FOR DELETING RECORDS OF ALL THE EMPLOYEE')

print('\t\t\t\t 5.FOR DELETING RECORD OF A PARTICULAR MEMBER')

print('\t\t\t\t 6.FOR MODIFYNIG IN A RECORD')

print('\t\t\t\t 7.FOR FOR DISPLAYING PAYROLL')

print('\t\t\t\t 8.FOR FOR DISPLAYING SALARY SLIP FOR ALL THE EMPLOYEE')

print('\t\t\t\t 9.FOR FOR DISPLAYING SALARY SLIP FOR A PARTICULAR EMPLOYEE')

print('\t\t\t\t 10.FOR EXIT')

print('enter choice...',end=' ')

choice=int(input())

if choice==1:

try:

print('Enter employee information...')

mempno=int(input('Enter employee no.'))

mname=input('enter employee name:')

mjob=input('enter employee job')

mbasic=float(input('enter basic salary:'))

if mjob.upper()=='OFFICER':

mda=mbasic*0.5

mhra=mbasic*0.35

mtax=mbasic*0.2

elif mjob.upper()=='MANAGER':

mda=mbasic*0.45
mhra=mbasic*0.30

mtax=mbasic*0.15

else:

mda=mbasic*0.40

mhra=mbasic*.25

mtax=mbasic*0.1

mgross=mbasic+mda+mhra

mnet=mgross-mtax

rec=(mempno,mname,mjob,mbasic,mda,mhra,mgross,mtax,mnet)

query="insert into "+TableName+" values (%s,%s,%s,%s,%s,%s,%s,%s,%s)"

mycursor.execute(query,rec)

mydb.commit()

print('Record added successfully....')

except Exception as e:

print("5",e)

elif choice==2:

try:

print(2)

query='select * from '+TableName

mycursor.execute(query)

q=input("enter table format plain, simple, github, grid ,fancy_grid, pipe, orgtbl, jira, presto,
pretty, psql, rst, rst, mediawiki, moinmoni, youtrack, html, latex, latex_raw, latex_booktab, textile =")

print("LOADING.",end="")

for i in range(10000000):

if i%100000==0:
print(".",end="")

print("loaded")

print(tabulate(mycursor, headers=['EmpNo','Name','Job','BasicSalary','DA','HRA','Gross
Salary','Tax','Net Salary'],tablefmt=q))

'''myrecords=mycursor.fetchall()

for rec in myrecords:

print(rec)'''

except :

print('Something went wrong')

elif choice==3:

try:

en=input('Enter employee no. of the record to be displayed...')

query="select * from "+TableName+" where empno="+en

print(query)

mycursor.execute(query)

myrecord=mycursor.fetchone()

print("LOADING.",end="")

for i in range(10000000):

if i%1000125==0:

print(".",end="")

print("loaded")

print("\n\nRecord of Employee No.:"+en)

print(myrecord)

c=mycursor.rowcount

if c==-1:
print("nothing to display")

except:

print("nothing")

elif choice==4:

try:

ch=input('Do not want to delete all the record (y/n)')

if ch.upper()=='Y':

mycursor.execute('delete from '+TableName)

mydb.commit()

print("LOADING.",end="")

for i in range(10000000):

if i%100125==0:

print(".",end="")

print("loaded")

print('all the records are deleted...')

except:

print('Something went wrong')

elif choice==5:

try:

en=input('Enter employee no. of the record to be deleted...')

print("LOADING.",end="")

for i in range(10000000):

if i%100125==0:

print(".",end="")

print("loaded")

query='delete from '+TableName+' where empno='+en


mycursor.execute(query)

mydb.commit()

c=mycursor.rowcount

if c>0:

print('employee no ',en,' not found')

except:

print('Something went wrong')

You might also like