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

Lib Manage

Uploaded by

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

Lib Manage

Uploaded by

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

Source code(In Python):-

# Checking mysql connectivity:-

import mysql.connector as c
con=c.connect(host='localhost',user='root',passwd='pagalhaitu',
database='library')
if con.is_connected():
print('Successfully connected to the database......')

# Creating a function to add books:-

def addbook():
c=int(input("Enter Book Code:"))
bn=input("Enter Book Name: ")
ba=input("Enter Author's Name: ")
t=int(input("Total Books:"))
data=(c,bn,ba,t,)
sql='insert into book values(%s,%s,%s,%s);'
c=con.cursor()
c.execute(sql,data)
con.commit()
print("\n\n\n\nBook Added Successfully..........\n\n\n\n")
wait = input('\n\n\nPress enter to continue.....\n\n\n\n\n\n')
main()
# Creating a function for issued books:-

def issueb():
co=int(input('Enter Book Code:'))
n=input('Enter Name:')
r=int(input("Enter Regno.:"))
d=input('Enter Date:')
a="insert into issue values(%s,%s,%s,%s);"
data=(co,n,r,d)
cursor=con.cursor()
cursor.execute(a,data)
con.commit()
print('Book issued successfully')
wait=input('Press enter to continue')
bookup(co,-1)
main()

# Creating a function for returned books:-

def returnb():
co=int(input('Enter Book Code:'))
n=input('Enter Name:')
r=int(input("Enter Regno.:"))
d=input('Enter Date:')
a="insert into returned values(%s,%s,%s,%s);"
data=(co,n,r,d)
cursor=con.cursor()
cursor.execute(a,data)
con.commit()
print('Book returned by:',n)
wait=input('Press enter to continue')
bookup(co,1)
main()

# Creating a function for the book quantity:-

def bookup(co,u):
a='select quantity from book where bcode=%s;'
data=(co,)
c=con.cursor()
c.execute(a,data)
myresult=c.fetchone()
t=myresult[0]+u
sql="update book set quantity=%s where bcode=%s;"
d=(t,co)
c.execute(sql,d)
con.commit()
wait = input('\n\n\nPress enter to continue.....\n\n\n\n\n\n')
main()

# Creating a function for the deletion of a book:-

def dbook():
ac=int(input("Enter Book Code: "))
a= "delete from book where bcode=%s;"
data=(ac,)
c=con.cursor()
c.execute(a,data)
con.commit()
print("Book deleted successfully")
wait = input('\n\n\nPress enter to
continue.....\n\n\n\n\n\n\n\n\n\n\n\n')
main()

# Creating a function to display book details:-

def dispbook():
a="select * from book;"
c=con.cursor()
c.execute(a)
myresult=c.fetchall()
for i in myresult:
print("Book code:",i[0])
print("Author:",i[1])
print("Book name:",i[2])
print("Quantity:",i[3])
print('\n\n')
wait = input('\n\n\nPress enter to
continue.....\n\n\n\n\n\n\n\n\n\n\n\n')
main()

# Creating a function to give report on isssued books:-

def report_issued_books():
a="select * from issue;"
c=con.cursor()
c.execute(a)
myresult=c.fetchall()
for i in myresult:
print(myresult)

wait = input('\n\n\nPress enter to


continue.....\n\n\n\n\n\n\n\n\n\n\n\n')
main()

# Creating a function to give report on returned books:-


def report_return_books():
a= 'select* from returned;'
c=con.cursor()
c.execute(a)
myresult=c.fetchall()
for i in myresult:
print(myresult)

wait = input('\n\n\nPress enter to


continue.....\n\n\n\n\n\n\n\n\n\n\n\n')
main()

# Library management system:-

def main():
print("""
1. ADD BOOK
2. ISSUE OF BOOK
3. RETURN OF BOOK
4. DELETE BOOK
5. DISPLAY BOOKS
6. REPORT MENU
7. EXIT PROGRAM""")
choice=input("Enter Task No:......")
print('\n\n\n\n\n\n\n')
if(choice=='1'):
addbook()
elif(choice=='2'):
issueb()
elif(choice=='3'):
returnb()
elif(choice=='4'):
dbook()
elif(choice=='5'):
dispbook()
elif(choice=='6'):
print('''
REPORT MENU:
1. ISSUED BOOKS
2. RETURNED BOOKS
3. GO BACK TO MAIN MENU \n\n\n''')
choice=input("Enter Task No:......")
print('\n\n\n\n\n\n\n')
if choice=='1':
report_issued_books()
elif choice=='2':
report_return_books()
elif choice=='3':
main()
else:
print("PIease try again........\n\n\n\n\n\n\n\n\n")
main()
elif(choice=='7'):
print('Thank you and have a great day ahead
ahead...............\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n')
else:
print("Please try again........\n\n\n\n\n\n\n\n\n\n\n\n")
main()

main()
Output in python:-
Output in mysql:-

You might also like