0% found this document useful (0 votes)
25 views8 pages

Museum Management

The document defines functions to manage a museum database using MySQL. It includes functions to create tables, add/update/remove employee and item records, and view records. Menu options allow navigating between the different data management functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views8 pages

Museum Management

The document defines functions to manage a museum database using MySQL. It includes functions to create tables, add/update/remove employee and item records, and view records. Menu options allow navigating between the different data management functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 8

from os import sys

import mysql.connector as a
from tabulate import tabulate
Password = ' '

def login ( ):
global Password
print ('=' *15+ 'Welcome To Login '+'='*15)
Password = input('Enter password:')

login()

try:
x = a.connect (host='localhost' , user='root',passwd = Password)
cur = x.cursor()
x.commit()
except:
print('='*15+'invalid password'+'='*15,'\n')
login()
x = a.connect(host = 'localhost',user = 'root',passwd = Password)
cur = x.cursor()
x.commit()

def Create():
cur.execute("CREATE DATABASE IF NOT EXISTS Museum_Managment")
cur.execute("USE Museum_Managment")
cur.execute("CREATE table IF NOT EXISTS Employee\
(ID int PRIMARY KEY UNIQUE ,\
Name varchar(40) NOT NULL ,\
Gender varchar(10),\
Designation varchar(40),\
Salary int,\
Address varchar(100), \
Mobile varchar(15) UNIQUE)")
cur.execute("CREATE table IF NOT EXISTS Item\
(Item_id int PRIMARY KEY UNIQUE ,\
Archo_item varchar(50),\
Total_Item int NOT NULL,\
Dynasty varchar(60) ,\
Era varchar(20) )")
cur.execute ("CREATE table IF NOT EXISTS Ticket\
(Bill_No int ,\
Date date ,\
Day varchar(15),\
Visitor varchar(40),\
Cost_Prize int ,\
Total_Ticket int ,\
T_Prize int )")
x.commit()

def Menu() :
print ("_"*15+"Main Menu"+"_"*15)
print("1. Employee Details")
print("2.Archeological item Detail")
print("3.Ticket Detail")
print("4.Exit")

m = int(input("Enter your choice:"))


if m == 1:
Employee()
elif m == 2:
Arch_Item()
elif m == 3:
Ticket()
elif m == 4:
exit()
else:
print("Please Enter Valid Choice!!!")
Menu()

def Employee():
print("^"*15 + "Employee Menu"+"^"*15)
print("1. Add Employee Detail ")
print("2. Update Employee Detail ")
print("3. Remove Employee Detail ")
print("4. Show Employee Detail")
print("5. Back to Menu")

e = int (input("Enter your choice :"))


if e == 1:
Add_Employee()
elif e == 2:
Update_Employee()
elif e == 3:
Remove_Employee()
elif e == 4:
Show_Employee()
else:
Menu()

def Add_Employee():
lst = ['n','N','no','NO','No']
j =' '
while j not in lst :
print ("<"*15 + "Enter Employee Details"+">"*15)
e_id = int(input("Enter Employee ID:"))
e_name = input("Enter Employee name:")
e_g = input("Enter Employee Gender:")
e_desig= input("Enter Employee Designation:")
e_sal =int( input("Enter Employee salary:"))
e_add=input("Enter Employee Address:")
e_phone= int(input("Enter Employee contact number:"))
cur.execute("INSERT INTO Employee VALUES ({},'{}','{}','{}',{},'{}',
{})" .format(e_id, e_name, e_g, e_desig , e_sal , e_add , e_phone))
j = input("Do you want to enter more data?(y/n)")
x.commit()
Employee()

def Update_Employee():
print("UPDATE IN EMPLOYEEE TABLE ")
lst=['y','Y','Yes','YES','yes']
ans = 'y'
while ans in lst:
ch=int( input ("Enter what do you want to update :\
\n 1. Employee Id \n2. Employee Name \n3.Employee Gender \
n4.Employee Designation \n5. Employee Salary \n6. Employee addresss\
\n 7. Employee Contact Nummber "))
if ch == 1:
old_id = int(input("Enter existing Id of employee:"))
new_id = int(input("Enter new employee id:"))
cur.execute("UPDATE Employee SET ID ={} WHERE ID = {}" .format(new_id ,
old_id ))
x.commit()
print(" Data Updated successfully!!")
elif ch == 2:
new = input("Enter employee name to be updated: ")
Id = int(input("Enter employee id whose name to be updated:"))
cur.execute("UPDATE Employee SET Name = '{}' WHERE ID
={}" .format(new,Id))
x.commit()
print("Data updated successfully!!")
elif ch == 3:
g = input ("Enter updated gender:")
Id = int(input("Enter employee id whose gender to be updated:"))
cur.execute("UPDATE Employee SET Gender = '{}' WHERE ID
={}" .format(g,Id))
x.commit()
print("Data updated successfully!!")
elif ch == 4:
new = input("Enter updated designation:")
Id = int(input("Enter employee id whose designation to be updated:"))
cur.execute("UPDATE Employee SET Designation = '{}' WHERE ID
={}" .format(new,Id))
x.commit()
print("Data updated successfully!!")
elif ch == 5:
new =int (input("Enter updated salary:"))
Id = int(input("Enter employee id whose salary to be updated:"))
cur.execute("UPDATE Employee SET Salary = {} WHERE Id
={}" .format(new,Id))
x.commit()
print("Data updated successfully!!")
elif ch == 6:
new =input("Enter updated address:")
Id = int(input("Enter employee id whose address to be updated:"))
cur.execute("UPDATE Employee SET address = '{}' WHERE Id
={}" .format(new,Id))
x.commit()
print("Data updated successfully!!")
elif ch == 7:
new =int (input("Enter updated Contact number:"))
Id = int(input("Enter employee id whose contact number to be
updated:"))
cur.execute("UPDATE Employee SET Mobile = {} WHERE Id
={}" .format(new,Id))
x.commit()
print("Data updated successfully!!")
else:
print("Invalid choice!!")
ans=input ("Do you want to update more data? (y/n)")
Employee()

def Remove_Employee():
print("REMOVING EMPLOYEE'S DETAIL")
lst=['y','Y','Yes','YES','yes']
ans = 'y'
while ans in lst:
d = input ("Select whether you want to delete \nA. Delete entire data \
nB.Delete selected data")
if d == 'A' or d =='a':
cur.execute("DELETE FROM Employee")
x.commit()
print("Entire data deleted successfully !!")
if d == 'B' or d == 'b':
Id = int(input("Enter employee Id whose record to be removed:"))
cur.execute("DELETE FROM Employee WHERE ID = {}".format(Id))
x.commit()
print("Selected record deleted successfully!!")
ans = input("Do you want to remove more records?(y\n)")
Employee()

def Show_Employee():
print("EMPLOYEE DETAILS")
cur.execute("SELECT * FROM Employee")
data = cur.fetchall()
h= ['ID' , 'Name' , 'Gender', 'Designation' , 'Salary', 'Address','Mobile']
print(tabulate(data , headers =h, tablefmt ='psql'))
Employee()

def Arch_Item():
print("^"*15 + "Archeological Item Menu"+"^"*15)
print("1. Add Item Detail ")
print("2. Update Item Detail ")
print("3. Remove Item Detail ")
print("4. Show Item Detail")
print("5. Back to Menu")

e = int (input("Enter your choice :"))


if e == 1:
Add_Item()
elif e == 2:
Update_Item()
elif e == 3:
Remove_Item()
elif e == 4:
Show_Item()
else:
Menu()

def Add_Item():
lst = ['n','N','no','NO','No']
ans =' '
while ans not in lst :
Id = int(input("Enter Archeological item id:"))
Item = input("Enter which type of item it is:")
n = int(input("Enter total number of item present:"))
d= input("Enter to which dynasty the item belongs:")
e = (input("Enter the era in which it was used:"))
cur.execute("INSERT INTO Item VALUES ({},'{}',
{},'{}','{}')".format(Id,Item,n,d,e))
ans = input ("Do you want to enter more data?(y/n)")
x.commit()
ans = input("Do you want to enter more data?(y/n)")
Arch_Item()
def Update_Item():
print("UPDATE IN EMPLOYEEE TABLE ")
lst=['n','N','No','NO','no']
ans = ' '
while ans not in lst:
ch = int(input("Enter whether you want to update\
\n1.Archeological Item ID \n2.Item name \n3.Number of
Items \n4.Dynasty \n5.Era"))
if ch == 1:
old = int(input("Enter existing Id :"))
new = int(input("Enter new Id:"))
cur.execute("UPDATE Item SET Item_id = {} WHERE Item_id =
{}".format(new,old))
x.commit()
print("Data Updated successful!!")
elif ch == 2:
old = int(input("Enter Id whose name has to be updated :"))
new = int(input("Enter updated name:"))
cur.execute("UPDATE Item SET Archo_item = '{}' WHERE Item_id =
{}".format(new,old))
x.commit()
print("Data Updated successful!!")
elif ch == 3:
old = int(input("Enter Id whose number of item has to be updated :"))
new = int(input("Enter updated number of item:"))
cur.execute("UPDATE Item SET Total_Item = {} WHERE Item_id =
{}".format(new,old))
x.commit()
print("Data Updated successful!!")
elif ch == 4:
old = int(input("Enter Id whose dynasty has to be updated :"))
new = int(input("Enter updated dynasty of item:"))
cur.execute("UPDATE Item SET Dynasty = '{}' WHERE Item_id =
{}".format(new,old))
x.commit()
print("Data Updated successful!!")
elif ch == 5:
old = int(input("Enter Id whose era has to be updated :"))
new = int(input("Enter updated Era of item:"))
cur.execute("UPDATE Item SET Era = '{}' WHERE Item_id =
{}".format(new,old))
x.commit()
print("Data Updated successful!!")
ans = input("Do you want to enter more data? (y/n)")
Arch_Item()

def Remove_Item():
print("REMOVING ARCHEOLOGICAL ITEM'S DETAIL")
lst=['n','N','NO','No','no']
ans = ' '
while ans not in lst:
d = input ("Select whether you want to delete \nA. Delete entire data \
nB.Delete selected data")
if d == 'A' or d =='a':
cur.execute("DELETE FROM Item")
x.commit()
print("Entire data deleted successfully !!")
elif d == 'B' or d == 'b':
Id = int(input("Enter Archeological Item Id whose record to be
removed:"))
cur.execute("DELETE FROM Item WHERE Item_id = {}".format(Id))
x.commit()
print("Selected record deleted successfully!!")
ans = input("Do you want to remove more records?(y\n)")
Arch_Item()

def Show_Item():
print("ARCHEOLOGIC ITEM DETAILS")
cur.execute("SELECT * FROM Item")
data = cur.fetchall()
h= ['Item_id' , 'Archo_item' , 'Total_Item', 'Dynasty' , 'Era']
print(tabulate(data , headers =h, tablefmt ='psql'))
Arch_Item()

def Ticket():
print("^"*15 + "TICKET MENU" +"^"*15)
print("1. Add Ticket Detail ")
print("2. Update Ticket Detail ")
print("3. Remove Ticket Detail ")
print("4. Show Ticket Detail")
print("5. Back to Menu")

e = int (input("Enter your choice :"))


if e == 1:
Add_Ticket()
elif e == 2:
Update_Ticket()
elif e == 3:
Remove_Ticket()
elif e == 4:
Show_Ticket()
else:
Menu()

def Add_Ticket():
lst = ['n','N','no','NO','No']
ans =' '
while ans not in lst :
Sn = int (input("Enter the bill number:"))
date = int(input ("Enter the date in YYYY/MM/DD:"))
day = input ("Enter the day:")
v = input("Enter visitors name:")
cp = int (input("Enter selling prize of 1 ticket:"))
tt =int(input("Enter total ticket bought:"))
tp = int(input("Enter total prize:"))
cur.execute("INSERT INTO Ticket VALUES({},{},'{}','{}',{},{},
{})".format(Sn,date,day,v,cp,tt,tp))
x.commit()
ans = input("Do you want to enter more data ?(y/n)")
Ticket()

def Update_Ticket():
print("UPDATE IN TICKET TABLE ")
lst=['n','N','No','NO','no']
ans = ' '
while ans not in lst:
ch=int( input ("Enter what do you want to update :\
\n 1.Bill Number \n2.Date \n3.Day \n4.Visitor's Name \n5.Cost Prize
of a Ticket \n6.Total number of Tickets sold\
\n7.Total Prize "))
if ch == 1:
old_id = int(input("Enter existing Bill Number:"))
new_id = int(input("Enter updayed Bill Number:"))
cur.execute("UPDATE Ticket SET Bill_No ={} WHERE Bill_No =
{}" .format(new_id , old_id ))
x.commit()
print(" Data Updated successfully!!")
elif ch == 2:
new = int(input("Enter updated Date : "))
Id = int(input("Enter Bill Number whose Date to be updated:"))
cur.execute("UPDATE Ticket SET Date = {} WHERE Bill_No
={}" .format(new,Id))
x.commit()
print("Data updated successfully!!")
elif ch == 3:
g = input ("Enter updated Day:")
Id = int(input("Enter Bill Number whose Day to be updated:"))
cur.execute("UPDATE Ticket SET Day = '{}' WHERE Bill_No
={}" .format(g,Id))
x.commit()
print("Data updated successfully!!")
elif ch == 4:
new = input("Enter updated Visitor's Name:")
Id = int(input("Enter Bill Number whose Visitor Name to be updated:"))
cur.execute("UPDATE Ticket SET Visitor = '{}' WHERE Bill_No
={}" .format(new,Id))
x.commit()
print("Data updated successfully!!")
elif ch == 5:
new =int (input("Enter updated Prize of 1 Ticket:"))
Id = int(input("Enter Bill Number whose Prize of 1 to be updated:"))
cur.execute("UPDATE Ticket SET Cost_Prize = {} WHERE Bill_No
={}" .format(new,Id))
x.commit()
print("Data updated successfully!!")
elif ch == 6:
new =int (input("Enter updated Total Number of tickets bought:"))
Id = int(input("Enter Bill Number whose Tickets Bought to be
updated:"))
cur.execute("UPDATE Ticket SET Total_Ticket = {} WHERE Bill_No
={}" .format(new,Id))
x.commit()
print("Data updated successfully!!")
elif ch == 7:
new =int (input("Enter updated Total Prize:"))
Id = int(input("Enter Bill Number whose Total Prize to be updated:"))
cur.execute("UPDATE Ticket SET T_Prize = {} WHERE Bill_No
={}" .format(new,Id))
x.commit()
print("Data updated successfully!!")
else:
print("Invalid choice!!")
ans=input ("Do you want to update more data? (y/n)")
Ticket()

def Remove_Ticket():
print("REMOVING TICKET DETAIL")
lst=['n','N','NO','No','no']
ans = ' '
while ans not in lst:
d = input ("Select whether you want to delete \nA. Delete entire data \
nB.Delete selected data")
if d == 'A' or d =='a':
cur.execute("DELETE FROM Item")
x.commit()
print("Entire data deleted successfully !!")
elif d == 'B' or d == 'b':
Id = int(input("Enter Bill Number whose record to be removed:"))
cur.execute("DELETE FROM Ticket WHERE Item_id = {}".format(Id))
x.commit()
print("Selected record deleted successfully!!")
ans = input("Do you want to remove more records?(y\n)")
Ticket()

def Show_Ticket():
print("TICKET DETAILS")
cur.execute("SELECT * FROM Ticket")
data = cur.fetchall()
h= ['Bill_No' , 'Date' , 'Day', 'Visitor' , 'Cost_Prize' , 'Total_Prize' ,
'T_Prize']
print(tabulate(data , headers =h, tablefmt ='psql'))
Ticket()

Create()
Menu()

print("-"*15+"END"+"-"*15)

You might also like