Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Ip Docs

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 36

St.

Joseph’s Co-Ed School

Session: 2023-24
Subject: Informatics Practices
Topic: Library Management System

Submitted to: Submitted by:


Mrs. Khushboo Hemnani Atharva Sharma
Board Roll No. _______
Index

Sr. No. Description

1 Acknowledgment

2 Certificate

3 Introduction to our project

4 Benefits

5 MySQL Tables

6 Source Code

7 Output

8 Bibliography
CERTIFICATE

This is to certify that Atharva Sharma, a student of


class 12th D has successfully completed his project
Library Management System under the guidance of
Mrs. Khushboo Hemnani.

Signature of Signature of
Internal Examiner External Examiner
ACKNOWLEDGEMENT

I would like to express my special thanks to my


Information Practices teacher Mrs. Khushboo Hemnani
for her able guidance and support in completing my
Project.

I would also like to extend my gratitude to the Principal


Fr. Ronald M. Vaughan who has given me the
opportunity to make this Project.

Lastly, I would like to thank my parents sister and


friends for their my fellow helpful feedback and
guidance throughout.
Introduction to our project
In the dynamic and ever-evolving landscape of educational
institutions and community libraries, efficient management of
resources is paramount. The Library Management System (LMS)
is an innovative solution designed to streamline and enhance the
operations of libraries, providing an organized and user-friendly
platform for both librarians and library patrons.
The primary goal of the Library Management System is to
automate the traditional manual processes involved in library
management. By leveraging modern technology, the system aims
to improve the accessibility, efficiency, and overall experience of
library services.
Benefits
 Efficiency: Automation of routine tasks reduces manual effort,
enabling librarians to focus on providing improved services.
 Accessibility: Patrons can access the library's collection
remotely, check availability, and reserve books online,
fostering a more convenient and inclusive library experience.
Resource
 Optimization: The LMS helps optimize the utilization of library
resources, ensuring that books are available when needed and
reducing instances of misplaced items.

In Conclusion:
The Library Management System stands as a technological
cornerstone in the realm of library administration. By blending
efficiency with accessibility, it aims to elevate the standard of
library services, fostering a culture of knowledge acquisition and
community engagement.

MySQL tables
Tables used:
1) Books
2) Members

3) IssuedBookList

Source Code
import pandas as pd
import mysql.connector
from tabulate import tabulate
from datetime import date

mycon=mysql.connector.connect(host="localhost",user = "root",passwd="ttggamer",database = "12ip")


cursor = mycon.cursor()
#----------------------------------------------------------Books--------------------------------------------------------------------
class BookOperations:
def ShowBookDetails(self):
AllBookEntries=pd.read_sql("select * from Books;",mycon)
print(tabulate(AllBookEntries, headers='keys', tablefmt = 'psql', showindex=False))
FuncOverExitOrNo()

#-------------------------------------------------------------------------------------------------------------------------------------
def AddBookDetails(self):
print("Preparing for new Entry..")
EnteredBookIDs = pd.read_sql("select BookId from Books;", mycon)

print("Previously entered entries:")


AllBookEntries=pd.read_sql("select * from Books;",mycon)
print(tabulate(AllBookEntries, headers='keys', tablefmt = 'psql', showindex=False))

BookId = int(input("Enter Book ID: "))


if BookId in EnteredBookIDs.values:
print("\nBookID already exists...\n\n")
self.AddBookDetails() #
return
BookName = input("Enter Book Name: ")
Author = input("Enter Authors Name: ")
Price = float(input("Enter Price: "))
Copies = int(input("Enter No. of Copies available: "))

insert_query = "INSERT INTO Books values({},'{}','{}',{},{})".format(BookId, BookName, Author,


Price, Copies)
cursor.execute(insert_query)
mycon.commit()
print("Entry added successfully!")
FuncOverExitOrNo()

#-------------------------------------------------------------------------------------------------------------------------------------

def DeleteBookDetails(self):
AllBookEntries=pd.read_sql("select * from Books;",mycon)
print(tabulate(AllBookEntries, headers='keys', tablefmt = 'psql', showindex=False))

EnteredBookIDs = pd.read_sql("select BookId from Books;", mycon)


while True:
BookIdToBeRemoved = int(input("Enter the Book Id which is to be removed: "))
if BookIdToBeRemoved in EnteredBookIDs.values:
Confirmation = input("Are you sure you want to delete this Entry(Y/N): ")
if Confirmation=='y'or Confirmation=='Y':
insert_query = "delete from Books where BookId={}".format(BookIdToBeRemoved)
cursor.execute(insert_query)
mycon.commit()
break
elif Confirmation == 'n'or Confirmation == 'N':
print("Aborting..")
return
else:
print("Book ID not found..")
continue
print("Entry deleted successfully!")

#-------------------------------------------------------------------------------------------------------------------------------------
def SearchBook(self):
SearchField=int(input("\nBy which field do you want to search the book\n1. ID\n2. Book Name\n3.
Author\n4. Price range\n>>"))
if SearchField==1:
EnteredBookIDs = pd.read_sql("select BookId from Books;", mycon)
while True:
BookId=int(input("Enter Book Id: "))
if BookId not in EnteredBookIDs.values:
print("ID not found in the list.. \nTry again? (Y/N): ")
LeaveChoiceFunc()
else:
SearchBookByID = pd.read_sql("select * from Books where BookId={}".format(BookId),mycon)
print(tabulate(SearchBookByID,headers='keys',tablefmt = 'psql', showindex=False))
break

elif SearchField==2:
BookName = input("Enter the Book Name: ")
SearchBookByName = pd.read_sql("select * from Books where
BookName='{}'".format(BookName),mycon)
print(tabulate(SearchBookByName,headers='keys',tablefmt = 'psql', showindex=False))
elif SearchField==3:
Author = input("Enter the Author's Name: ")
SearchBookByAuthor = pd.read_sql("select * from Books where Author='{}'".format(Author),mycon)
print(tabulate(SearchBookByAuthor,headers='keys',tablefmt = 'psql', showindex=False))
elif SearchField==4:
MinBookPrice = int(input("Enter the min Price of Book: "))
MaxBookPrice = int(input("Enter max Price of Book: "))
SearchBookByPrice = pd.read_sql("select * from Books where Price>{} and
Price<{}".format(MinBookPrice,MaxBookPrice),mycon)
if SearchBookByPrice.empty==True:
print("No Books found under the given range..")
return
print(tabulate(SearchBookByPrice,headers='keys',tablefmt = 'psql', showindex=False))
else:
print("\nInvalid Field...\n\n")
self.SearchBook()
FuncOverExitOrNo()

#-------------------------------------------------------------------------------------------------------------------------------------
def EditBookEntry(self):
EnteredBookIDs = pd.read_sql("select BookId from Books;", mycon)

AllBookEntries=pd.read_sql("select * from Books;",mycon)


print(tabulate(AllBookEntries, headers='keys', tablefmt = 'psql', showindex=False))

EntryToBeEdited = int(input("Enter the Book ID of the entry you want to edit: "))
if EntryToBeEdited not in EnteredBookIDs.values:
print("\nEntry not found\n\n")
self.EditBookEntry()
return
else:
EntryBackup = pd.read_sql("select * from Books where BookId={}".format(EntryToBeEdited),mycon)

NewBookId = input("Enter new Book ID (Enter '-' to use old value): ")
if NewBookId != '-':
if int(NewBookId) in EnteredBookIDs.values:
print("\nBookID already exists...\n\n")
self.EditBookEntry()
return
else:
NewBookName = input("Enter new Book Name (Enter '-' to use old value): ")
NewAuthor = input("Enter new Authors Name (Enter '-' to use old value): ")
NewPrice = input("Enter new Price (Enter '-' to use old value): ")
NewCopies = input("Enter new No. of Copies available (Enter '-' to use old value): ")
Data = [NewBookId,NewBookName,NewAuthor,NewPrice,NewCopies]
DataToBeEntered=[]
for i in range (len(Data)):
if Data[i]=='-':
DataToBeEntered.append(EntryBackup.iat[0,i])
else:
DataToBeEntered.append(Data[i])
DataToBeEntered[-1]=intfloat(DataToBeEntered[-1])
DataToBeEntered[-2]=float(DataToBeEntered[-2])

UpdateQuery = "update Books set BookId = {}, BookName ='{}', Author = '{}', Price = {}, CopiesAvailable = {} where
BookId={}".format(DataToBeEntered[0],DataToBeEntered[1],
DataToBeEntered[2],DataToBeEntered[3],
DataToBeEntered[4],DataToBeEntered[0])
cursor.execute(UpdateQuery)
mycon.commit()
print("Entry Updated successfully!")
FuncOverExitOrNo()

#-------------------------------------------------------------------------------------------------------------------------------------
BookOptions = {1 : ShowBookDetails,
2 : SearchBook,
3 : AddBookDetails,
4 : EditBookEntry,
5 : DeleteBookDetails}

#-------------------------------------------------------------------------------------------------------------------------------------
def BookOperationsNavigator(self):
B_Obj=BookOperations()
Navi = int(input("\n1. Show Book List \n2. Search Book List \n3. Add Book Details \n4. Edit Book Entry \
n5. Delete Book Entry \n6. Main Menu \n>>"))
if Navi == 6:
MainMenu()
else:
B_Obj.BookOptions[Navi](self)

#-------------------------------------------------------------Members------------------------------------------------------------
class MemberOperations:
def ShowMemberDetails(self):
AllMemberEntries=pd.read_sql("select * from Members;",mycon)
print(tabulate(AllMemberEntries, headers='keys', tablefmt = 'psql', showindex=False))
FuncOverExitOrNo()
def AddMemberDetails(self):
print("Preparing for new Entry..")
EnteredMemberIDs = pd.read_sql("select MemberId from Members;", mycon)

print("Previously entered entries:")


AllMemberEntries=pd.read_sql("select * from Members;",mycon)
print(tabulate(AllMemberEntries, headers='keys', tablefmt = 'psql', showindex=False))

EnteredMemberIDs = pd.read_sql("select MemberId from Members;", mycon)


MemberId = int(input("Enter Member ID: "))
if MemberId in EnteredMemberIDs.values:
print("\nMember ID already exists...\n\n")
AddMemberDetails()
return
MemberName = input("Enter Member Name: ")
Phone = int(input("Enter Phone No. of Member(10 digit): "))

insert_query = "INSERT INTO Members values({},'{}',{})".format(MemberId, MemberName, Phone)


cursor.execute(insert_query)
mycon.commit()
print("data successfully entered!")
FuncOverExitOrNo()

#-------------------------------------------------------------------------------------------------------------------------------------
def EditMemberEntry(self):
EnteredMemberIDs = pd.read_sql("select MemberId from Members;", mycon)

AllMemberEntries=pd.read_sql("select * from Members;",mycon)


print(tabulate(AllMemberEntries, headers='keys', tablefmt = 'psql', showindex=False))

while True:
EntryToBeEdited = int(input("Enter the Member ID of the entry you want to edit: "))
if EntryToBeEdited not in EnteredMemberIDs.values:
print("\nEntry not found \nTry again? (Y/N): ")
LeaveChoiceFunc()
else:
EntryBackup = pd.read_sql("select * from Members where
MemberId={}".format(EntryToBeEdited),mycon)

NewMemberId = input("Enter new Member ID (Enter '-' to use old value): ")
if NewMemberId != '-':
if int(NewMemberId) in EnteredMemberIDs.values:
print("\nMember ID already exists... \n")
self.EditMemberEntry()
return
else:
NewMemberName = input("Enter new Member's Name (Enter '-' to use old value): ")
NewPhone = input("Enter new Phone No.[10 digits] (Enter '-' to use old value): ")
Data = [NewMemberId,NewMemberName,NewPhone]
DataToBeEntered=[]
for i in range (len(Data)):
if Data[i]=='-':
DataToBeEntered.append(EntryBackup.iat[0,i])
else:
DataToBeEntered.append(Data[i])
DataToBeEntered[-1]=int(DataToBeEntered[-1])
UpdateQuery = "update Members set MemberId = {}, MemberName ='{}', Phone = {} where
MemberId={}".format(DataToBeEntered[0],DataToBeEntered[1],

DataToBeEntered[2],DataToBeEntered[0])
cursor.execute(UpdateQuery)
mycon.commit()
print("Entry Updated successfully!")
FuncOverExitOrNo()
#-------------------------------------------------------------------------------------------------------------------------------------
def SearchMember(self):
SearchField=int(input("\nBy which field do you want to search \n1. ID\n2. Member Name\n3. Phone\
n>>"))
if SearchField==1:
EnteredMemberIDs = pd.read_sql("select MemberId from Members;", mycon)
while True:
MemberId=int(input("Enter Member Id: "))
if MemberId not in EnteredMemberIDs.values:
print("ID not found..\n")
LeaveChoice = input("Leave? (Y/N): ")
if LeaveChoice == 'Y'or LeaveChoice == 'y':
FuncOverExitOrNo()
else: continue
else:
SearchMemberByID = pd.read_sql("select * from Members where
MemberId={}".format(MemberId),mycon)
print(tabulate(SearchMemberByID,headers='keys',tablefmt = 'psql', showindex=False))
break
elif SearchField==2:
MemberName = input("Enter the Member's Name: ")
SearchMemberByName = pd.read_sql("select * from Members where
MemberName='{}'".format(MemberName),mycon)
print(tabulate(SearchMemberByName,headers='keys',tablefmt = 'psql', showindex=False))
elif SearchField==3:
Phone=int(input("Enter the Phone No.: "))
SearchMemberByPhone = pd.read_sql("select * from Members where
Phone={}".format(Phone),mycon)
print(tabulate(SearchMemberByPhone,headers='keys',tablefmt = 'psql', showindex=False))
else:
print("\nInvalid Field...\n\n")
self.SearchMember()
FuncOverExitOrNo()

#-------------------------------------------------------------------------------------------------------------------------------------
def DeleteMemberDetails(self):
AllMemberEntries=pd.read_sql("select * from Members;",mycon)
print(tabulate(AllMemberEntries, headers='keys', tablefmt = 'psql', showindex=False))

EnteredMemberIDs = pd.read_sql("select MemberId from Members;", mycon)

while True:
MemberIdToBeRemoved = int(input("Enter the Member Id which is to be removed: "))
if MemberIdToBeRemoved in EnteredMemberIDs.values:
Confirmation = input("Are you sure you want to delete this Entry(Y/N): ")
if Confirmation=='y'or Confirmation=='Y':
insert_query = "delete from Members where MemberId={}".format(MemberIdToBeRemoved)
cursor.execute(insert_query)
mycon.commit()
break
elif Confirmation == 'n'or Confirmation == 'N':
print("Aborting..")
return
else:
print("Member ID not found..")
continue
print("Entry deleted successfully!")
FuncOverExitOrNo()
MemberOptions = {1 : ShowMemberDetails,
2 : SearchMember,
3 : AddMemberDetails,
4 : EditMemberEntry,
5 : DeleteMemberDetails}

#-------------------------------------------------------------------------------------------------------------------------------------
def MemberOperationsNavigator(self):
M_Obj=MemberOperations()
Navi = int(input("\n1. Show Member List \n2. Search Member List \n3. Add Member Details \n4. Edit
Member Entry \n5. Delete Member Entry \n6. Main Menu \n>>"))
if Navi == 6:
MainMenu()
else:
M_Obj.MemberOptions[Navi](self)

#------------------------------------------------------------Issue-------------------------------------------------------------------
class IssueOperations:
#-------------------------------------------------------------------------------------------------------------------------------------
def IssueABook(self):

GetLastIssueId = pd.read_sql("select max(issueId) from issuedbooklist;", mycon)


GetLastIssueId = GetLastIssueId.at[0,'max(issueId)']

EnteredBookIDs = pd.read_sql("select BookId from Books;", mycon)


EnteredMemberIDs = pd.read_sql("select MemberId from Members;", mycon)

while True:
MemberId = int(input("Enter Member Id: "))
if MemberId not in EnteredMemberIDs.values:
print("Member Id not found..\n\nTry again? (Y/N) \n>>")
LeaveChoiceFunc()
else:
IssueChoice = int(input("Enter the Id of the book you want to issue: "))
if IssueChoice in EnteredBookIDs.values:
IssueCount = int(input("Enter the no. of copies to be issued: "))
AvailableBookCopies = pd.read_sql("select CopiesAvailable from Books where BookId =
{};".format(IssueChoice), mycon)
AvailableBookCopies = AvailableBookCopies.at[-0,'CopiesAvailable']
if AvailableBookCopies >= IssueCount:
IssueId = GetLastIssueId+1
IssueDate = str(date.today())
IssueDate = IssueDate.replace('-','')
ReturnPeriod = int(input("Enter the No. of days for which you want to issue (Min: 1 week, Max
1 month): "))
if ReturnPeriod <7 or ReturnPeriod >31:
print("Invalid issue period..\n\n Try again? (Y/N) \n>>")
ChoiceFunc()
else:
DateToReturn = int(IssueDate)+ReturnPeriod
IssueDate,DateToReturn = str(IssueDate), str(DateToReturn)

IssueQuery = "insert into IssuedBookList values({},'{}', '{}', {}, {}, {});".format(IssueId,


IssueDate, DateToReturn,
IssueChoice, MemberId, IssueCount)
cursor.execute(IssueQuery)
mycon.commit()
AdjustedCount = AvailableBookCopies - IssueCount
UpdateQuery = "update Books set CopiesAvailable = {} where BookId =
{}".format(AdjustedCount,IssueChoice)
cursor.execute(UpdateQuery)
mycon.commit()
print("Book Issued Successfully!")
FuncOverExitOrNo()
else:
print("The requested amount of copies is higher than available number of copies..\n\nTry again? (Y/N) \n>>")
LeaveChoiceFunc()
else:
print("Book Id not found..\n\nTry again? (Y/N) \n>>")
LeaveChoiceFunc()
FuncOverExitOrNo() #if n pressed in the leave choice func, returns here and goes to main menu
#-------------------------------------------------------------------------------------------------------------------------------------
def ReturnQueryExecution(self,IssuedBookEntry,BookEntryOfIssuedBook,IssueId):
IssuedCount = IssuedBookEntry.at[0,"CopiesIssued"]
ReturnQuery = "update Books set CopiesAvailable = {} where BookId =
{};".format((BookEntryOfIssuedBook.at[0,'CopiesAvailable'] + IssuedCount),
IssuedBookEntry.at[0,'BookId'])
cursor.execute(ReturnQuery)
mycon.commit()
Del_IssuedBook_Query = "delete from IssuedBookList where IssueId = {};".format(IssueId)
cursor.execute(Del_IssuedBook_Query)
mycon.commit()
print("Book returned Successfully!")
FuncOverExitOrNo()
#-------------------------------------------------------------------------------------------------------------------------------------
def ReturnABook(self):
AllIssueIDs = pd.read_sql("select IssueId from IssuedBookList;",mycon)
while True:
IssueId = int(input("Enter your Issue ID given at the time of Issue: "))

if IssueId not in AllIssueIDs.values:


print("Invalid Issue ID.. \nTry again? (Y/N)")
LeaveChoiceFunc()
else: break

IssuedBookEntry = pd.read_sql("select * from IssuedBookList where IssueId = {};".format(IssueId),mycon) #


Issue Entry inn IssueBookList table
BookEntryOfIssuedBook = pd.read_sql("select CopiesAvailable from Books where BookId =
{};".format(IssuedBookEntry.at[0,'BookId']),mycon) # Entry of Book in Books Table

PendingCheck = pd.read_sql("""select IssueId, case when DateToReturn>curdate() then 'Not Pending' else
'Pending' end as ReturnStatus
from IssuedBookList
where IssueId = {};""".format(IssueId),mycon)

LateFeePerDay = 1.5
CurDate, DateToReturn = date.today(), IssuedBookEntry.at[0,'DateToReturn']

if PendingCheck.at[0,'ReturnStatus'] == 'Pending':
DaysLateCount = (CurDate-DateToReturn).days
LateFeePayable = DaysLateCount * LateFeePerDay
print(f"You are {DaysLateCount} days late. \nLate Fees will be charged accordingly, calculating amount...\n")

print(f"₹{LateFeePayable}/- payable to the Library..")


self.ReturnQueryExecution(IssuedBookEntry,BookEntryOfIssuedBook,IssueId)
else:
DaysLeft = (DateToReturn-CurDate).days
print(f"You still have {DaysLeft} left to return the book, are you sure you want to return the book?")
Confirmation = input("(Y/N) \n>>")
if Confirmation.upper() == 'Y':
self.ReturnQueryExecution(IssuedBookEntry,BookEntryOfIssuedBook,IssueId)
else:
FuncOverExitOrNo()
#-------------------------------------------------------------------------------------------------------------------------------------
def IssuedBooksDetails(self):

IssuedBooksDetail=pd.read_sql("""select IssuedBookList.IssueId, IssuedBookList.IssueDate,


IssuedBookList.DateToReturn, Books.BookId, IssuedBookList.CopiesIssued, Members.MemberId,
Members.MemberName, Members.Phone,
case when DateToReturn>curdate() then 'Not Pending' else 'Pending' end as ReturnStatus
from Books, Members, IssuedBookList
where IssuedBookList.BookId=Books.BookId and
IssuedBookList.MemberId=Members.MemberId;""",mycon)

print(tabulate(IssuedBooksDetail, headers='keys', tablefmt = 'psql', showindex=False))


FuncOverExitOrNo()

#-------------------------------------------------------------------------------------------------------------------------------------
IssueClassOptions = {1 : IssuedBooksDetails,
2 : IssueABook,
3 : ReturnABook}

#-------------------------------------------------------------------------------------------------------------------------------------
def IssueOperationsNavigator(self):
I_Obj=IssueOperations()
Navi = int(input("\n1. Details of Issued Books \n2. Issue a Book \n3. Return a Book \n4. Main Menu \
n>>"))
if Navi == 4:
MainMenu()
else:
I_Obj.IssueClassOptions[Navi](self)
#-------------------------------------------------------------------------------------------------------------------------------------

#----------------------------------------------------------Main Menu-------------------------------------------------------------
def LeaveChoiceFunc():
LeaveChoice = input()
if LeaveChoice == 'Y'or LeaveChoice == 'y':
return # CONTINUE
else:
FuncOverExitOrNo()
return False # BREAK
#-------------------------------------------------------------------------------------------------------------------------------------
def FuncOverExitOrNo():
ContinueOrNo = int(input("\n1. Return to Main Menu \n2. Close program \n>>"))
if ContinueOrNo == 1:
MainMenu()
else:
mycon.close()
quit()
#-------------------------------------------------------------------------------------------------------------------------------------
def MainMenu():
print("Enter your choice")
MainMenuChoice = int(input("\n1. Book List operations \n2. Member List operations \n3. Issued Book
details \n4. Quit \n>>"))
if MainMenuChoice == 1:
BO.BookOperationsNavigator()
elif MainMenuChoice == 2:
MO.MemberOperationsNavigator()
elif MainMenuChoice == 3:
IO.IssueOperationsNavigator()
elif MainMenuChoice == 4:
mycon.close()
quit()
#-------------------------------------------------------------------------------------------------------------------------------------
BO = BookOperations()
MO = MemberOperations()
IO = IssueOperations()
#-------------------------------------------------------------------------------------------------------------------------------------
MainMenu()

Output
1. Book List Operations:
I. Showing Book List
II. Searching Book List
a) By ID:

b) By Book Name:
c) By Author:

d) By Price range:
III. Adding Book Details

In SQL:
IV. Editing Book entry

In MySQL:
V. Deleting an entry

In MySQL:

2. Member List Operations:

I. Showing Member List


II. Searching Member List
a) By ID
b) By Name

c) By Phone
III. Adding Member Details
In MySQL:

IV. Editing Member Entry


In MySQL:
V. Deleting Member Entry

In MySQL:
3. Issued Book Details
I. Details of Issued Books
II. Issuing a Book

In MySQL:

IssueBookList Table after issuing


Entry of the issued book in Books Table before issuing:

Entry of the issued book in Books Table after issuing:

The CopiesAvailable value of the issued book in the Books Table


gets reduced by the amount of copies issued
III. Returning a Book

Rs. 1.5 is charged for each extra pending day.

In MySQL:
Entry of the book in IssuedBookList table before returning:

Entry of the book in Books table before returning:


Entry of the book in IssuedBookList table after returning:

Entry of the book in Books table after returning:

The CopiesAvailable value of the returned book in the Books Table


gets increased by the amount of copies returned.
Bibliography

1. stackoverflow.com
2. geeksforgeeks.org
3. wikipedia.org
4. docs.python.org

You might also like