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

CS Project MYSQL

This document contains the code for a library management system project in Python. The code includes functions for menu display, book management (add, delete, modify, display books), member management (add, delete, modify, display members), and issuing and returning books. The project uses MySQL to connect to a database and execute SQL queries to add, modify and retrieve data from tables to manage book and member records.

Uploaded by

Samir Parmar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
135 views

CS Project MYSQL

This document contains the code for a library management system project in Python. The code includes functions for menu display, book management (add, delete, modify, display books), member management (add, delete, modify, display members), and issuing and returning books. The project uses MySQL to connect to a database and execute SQL queries to add, modify and retrieve data from tables to manage book and member records.

Uploaded by

Samir Parmar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Computer Science

PROJECT
ON
LIBRARY
MANAGEMENT

NAME:
CLASS:
ROLL NO. :
CERTIFICATE
This is to certify that ____________ of class ______,
_______________________ School, has successfully
completed her Investigatory Project as prescribed by CBSE in
the year ____________.

Date :

Roll No. :

Signature of Subject Signature of External


Teacher Examiner

__________________ __________________
ACKNOWLEDGEMENT

It would be my utmost pleasure to thank my


Computer Science teacher ____________ for giving
me this knowledgeable topic "LIBRARY
MANAGEMENT" and supporting me during the
course of this project. I would also like to thank my
parents and God for encouraging me and giving me
strength to complete this project on time.
Secondly, I also like to thank my partner for being
co-operative and pally with me throughout the
process and for helping me to make this a full proof
success.
PROGRAM CODE
LIBRARY.py

import math

import os

def DispMenu():

print("\n\n\n\t\t############ LIBRARY MANAGEMENT ###############")

print("\n\t\t\t 1. BOOK MANAGEMENT ")

print("\n\t\t\t 2. MEMBER MANAGEMENT ")

print("\n\t\t\t 3. ISSUE BOOK")

print("\n\t\t\t 4. RETURN BOOK")

print("\n\t\t\t 5. EXIT ")

print("\t\t######################################################")

def BookMenu():

print("\n\n\n\t\t############ BOOK MANAGEMENT ###############")

print("\n\t\t\t 1. ADD BOOK ")

print("\n\t\t\t 2. DELETE BOOK ")

print("\n\t\t\t 3. MODIFY BOOK")

print("\n\t\t\t 4. DISPLAY BOOKS")


print("\n\t\t\t 5. EXIT ")

print("\t\t##################################################")

def MemberMenu():

print("\n\n\n\t\t############ MEMBER MANAGEMENT ###############")

print("\n\t\t\t 1. ADD MEMBER ")

print("\n\t\t\t 2. DELETE MEMBER ")

print("\n\t\t\t 3. MODIFY MEMBER")

print("\n\t\t\t 4. DISPLAY MEMBERS")

print("\n\t\t\t 5. EXIT ")

print("\t\t##################################################")

def bookadd():

import mysql.connector # Import MySQL connector

con1 = mysql.connector.connect(host='localhost', database='world', user='root', password='tiger')


# Open a connection to a database

cursor1 = con1.cursor() #Create a cursor object

#Execute SQL query to insert records in the table newitems

print("Enter the following information")


bno=input("Enter the book number:")

bname=input("Enter book name:")

bauthor=input("Enter author name:")

bprice=float(input("Enter book price:"))

bstat="N"

sql_query=("insert into book (bookno, bookname, bookauthor, bookprice, status) values


(%s,%s,%s,%s,%s);")

insert_data=(bno,bname,bauthor,bprice,bstat)

cursor1.execute(sql_query,insert_data)

con1.commit() # Stores the data permanently in the table

con1.close() #Close connection object

cursor1.close() #Close cursor object

print("book added")

def bookdelete():

bno=input("Enter book Number to be deleted")

flag=0

import mysql.connector # Import MySQL connector

con1 = mysql.connector.connect(host='localhost', database='world', user='root', password='tiger')

# Open a connection to a database


cursor1 = con1.cursor() #Create a cursor object

#Execute SQL query to update the table

cursor1.execute("delete from book where bookno = %s",(bno,))

con1.commit() # Stores the data permanently in the table

con1.close() #Close connection object

cursor1.close()

def bookmodify():

import mysql.connector # Import MySQL connector

con1 = mysql.connector.connect(host='localhost', database='world', user='root', password='tiger')

# Open a connection to a database

cursor1 = con1.cursor() #Create a cursor object

#Execute SQL query to insert records in the table newitems

bno=input("Enter the book number you want to modify")

print("Enter the following information")

bname=input("Enter book name:")

bauthor=input("Enter author name:")

bprice=input("Enter book price:")


bstat="N"

cursor1.execute("update book set bookname=%s, bookauthor=%s, bookprice=%s, status=%s where


bookno=%s",(bname,bauthor,bprice,bstat,bno))

con1.commit() # Stores the data permanently in the table

con1.close() #Close connection object

cursor1.close() #Close cursor object

print("book modified")

def bookdisp():

import mysql.connector # Import MySQL connector

con1 = mysql.connector.connect(host='localhost', database='world', user='root', password='tiger')

# Open a connection to a database

cursor1 = con1.cursor() #Create a cursor object

cursor1.execute ("select * from book;") #Execute SQL query to create a table

# fetch all rows of a result set and store in rs as a list of tuples

rs = cursor1.fetchall()

print("\n\n\n########################## BOOK DETAILS #############################")

print("%10s"%"BOOK NO.","%20s"%"TITLE","%20s"%"AUTHOR","%15s"%"PRICE",
"%15s"%"STATUS")
for row in rs: # for loop to display all records

print("%10s"%row[0],"%20s"%row[1],"%20s"%row[2],"%15s"%row[3],"%15s"%row[4])

print("\n########################## BOOK DETAILS #############################")

K=input("\n\nPress any key to continue")

con1.close() #Close connection object

cursor1.close() #Close cursor object

def memberadd():

import mysql.connector # Import MySQL connector

con1 = mysql.connector.connect(host='localhost', database='world', user='root', password='tiger')

# Open a connection to a database

cursor1 = con1.cursor() #Create a cursor object

#Execute SQL query to insert records in the table newitems

print("Enter the following information")

mno=input("Enter the member number:")

mname=input("Enter member name:")

mbno=" "
bstat="N"

sql_query=("insert into member1 (memberno, membername, booknum, memstatus) values


(%s,%s,%s,%s);")

insert_data=(mno,mname,mbno,bstat)

cursor1.execute(sql_query,insert_data)

con1.commit() # Stores the data permanently in the table

con1.close() #Close connection object

cursor1.close() #Close cursor object

print("Member added")

def memberdelete():

mno=input("Enter member number to be deleted")

flag=0

import mysql.connector # Import MySQL connector

con1 = mysql.connector.connect(host='localhost', database='world', user='root', password='tiger')

# Open a connection to a database


cursor1 = con1.cursor() #Create a cursor object

#Execute SQL query to update the table

cursor1.execute("delete from member1 where memberno = %s",(mno,))

con1.commit() # Stores the data permanently in the table

con1.close() #Close connection object

cursor1.close()

print("book deleted")

def membermodify():

import mysql.connector # Import MySQL connector

con1 = mysql.connector.connect(host='localhost', database='world', user='root', password='tiger')

# Open a connection to a database

cursor1 = con1.cursor() #Create a cursor object

#Execute SQL query to insert records in the table newitems

mno=input("Enter the member number you want to modify")

print("Enter the following information")

mname=input("Enter member name:")

mbno=" "

mstat="N"
cursor1.execute("update member1 set membername=%s, booknum=%s, memstatus=%s where
memberno=%s",(mname,mbno,mstat,mno))

con1.commit() # Stores the data permanently in the table

con1.close() #Close connection object

cursor1.close() #Close cursor object

print("book modified")

def memberdisp():

import mysql.connector # Import MySQL connector

con1 = mysql.connector.connect(host='localhost', database='world', user='root', password='tiger')

# Open a connection to a database

cursor1 = con1.cursor() #Create a cursor object

cursor1.execute ("select * from member1;") #Execute SQL query to create a table

# fetch all rows of a result set and store in rs as a list of tuples

rs = cursor1.fetchall()

print("\n\n\n########################## BOOK DETAILS #############################")

print("%10s"%"MEMBER NO.","%20s"%"NAME","%20s"%"BOOK NUMBER","%15s"%"STATUS")

for row in rs: # for loop to display all records

print("%10s"%row[0],"%20s"%row[1],"%20s"%row[2],"%15s"%row[3])
print("\n########################## BOOK DETAILS #############################")

K=input("\n\nPress any key to continue")

con1.close() #Close connection object

cursor1.close() #Close cursor object

def IssueBook():

mno=input("Enter Member Number")

flag=0

import mysql.connector # Import MySQL connector

con1 = mysql.connector.connect(host='localhost', database='world', user='root', password='tiger')

# Open a connection to a database

con2 = mysql.connector.connect(host='localhost', database='world', user='root', password='tiger')

# Open a connection to a database

cursor1 = con1.cursor() #Create a cursor object

cursor2 = con2.cursor()

cursor1.execute("select * from member1 where memberno=%s",(mno,))


mrec=cursor1.fetchone()

print(mrec)

print(mrec[0])

if mrec[0]==mno:

print("Member Details:")

print(mrec)

if mrec[3]== "N":

bno=input("Enter Book Number")

cursor2.execute("select * from book where bookno=%s",(bno,))

brec=cursor2.fetchone()

if brec[0]== bno:

flag=1

if brec[4]=="N":

print("Book Details:")

print(brec)

cursor1.execute("update member1 set booknum= %s, memstatus= %s where


memberno=%s",(bno,"Y",mno))

cursor2.execute("update book set status=%s where bookno=%s",("Y",bno))

print("Book Successfully Issued")

print("Return the book within 10 days of issue date")


con1.commit() # Stores the data permanently in the table

con2.commit()

else:

print("Book already issued")

if (flag==0):

print("Book already issued")

else:

print("Return the previous book")

con1.close()

cursor1.close()

con2.close()

cursor2.close()

def ReturnBook():

mno=input("Enter Member Number")

flag=0

import mysql.connector # Import MySQL connector

con1 = mysql.connector.connect(host='localhost', database='world', user='root', password='tiger')

# Open a connection to a database


con2 = mysql.connector.connect(host='localhost', database='world', user='root', password='tiger')

# Open a connection to a database

cursor1 = con1.cursor() #Create a cursor object

cursor2 = con2.cursor()

cursor1.execute("select * from member1 where memberno=%s",(mno,))

mrec=cursor1.fetchone()

if mrec[0]==mno:

print("Member Details:")

print(mrec)

bno=mrec[2]

cursor2.execute("select * from book where bookno=%s",(bno,))

brec=cursor2.fetchone()

if mrec[2]== brec[0]:

print("Book details:")

print(brec)

flag=1

cursor1.execute("update member1 set booknum= %s, memstatus= %s where memberno=%s",("


","N",mno))

cursor2.execute("update book set status=%s where bookno=%s",("N",bno))

days=int(input("Book returned in no. of days: "))


fine=0

if (days>10):

fine=(days-10)*2

print("Deposit the fine amount:",fine)

print("Book Successfully Returned")

con1.commit() # Stores the data permanently in the table

con2.commit()

if (flag==0):

print("Book not found")

choice=0

while choice!=5:

DispMenu()

choice = int(input('\t\t\t ENTER YOUR CHOICE :'))

if choice==1:

ch=0
while ch!=5:

BookMenu()

ch = int(input('\t\t\t ENTER YOUR CHOICE :'))

if ch==1:

bookadd()

elif ch==2:

bookdelete()

elif ch==3:

bookmodify()

elif ch==4:

bookdisp()

elif ch==5:

break

else:

print('\n\t\t\t == INVALID CHOICE == ')

elif choice==2:
ch=0

while ch!=5:

MemberMenu()

ch = int(input('\t\t\t ENTER YOUR CHOICE :'))

if ch==1:

memberadd()

elif ch==2:

memberdelete()

elif ch==3:

membermodify()

elif ch==4:

memberdisp()

elif ch==5:

break

else:

print('\n\t\t\t == INVALID CHOICE == ')


elif choice==3:

IssueBook()

elif choice==4:

ReturnBook()

elif choice==5:

break

else:

print('\n\t\t\t == INVALID CHOICE == ')


OUTPUT SCREENSHOTS

You might also like