Professional Documents
Culture Documents
COMPUTER SCIENCE
(2021-2022)
PROJECT TITLE
LIBRARY MANAGEMENT SYSTEM
ACKNOWLEDGEMENT
I, Your Beautiful Name, of class 12 Science B, firstly take the privilege to thank my
parents for giving me the opportunity to undergo my Higher Secondary. This satisfaction that
accompanies the successful completion of any task would have been incomplete without
mentioning the people who made it possible.
I have the pleasure in successful completion of this project based on Library, Interface
with Python and MySQL queries on the assigned topic: “Library Management Project.”
I would like to appreciate the motivation and understanding extended towards the
completion of this project by my teachers, Mrs. S. Mishra and Mrs. B. Kharnaior, for their
encouragement and guidance for this project work, even amidst the pandemic.
And last but not the least, I would like to thank The Almighty God for showering His
blessings.
- Your Beautiful
Name
Library
Management
System
A software designed to provide an experience
shared by the User and the Administrator of
visiting an e-library.
Fig 1.1 Library Structure
1
# membership.py module
import mysql.connector
from pandas import *
from tabulate import tabulate
current_user = []
userexists = False
mycon = mysql.connector.connect(
host="localhost", user="root", password="1234", database="library")
if not mycon:
print("Error in connecting")
mycursor = mycon.cursor()
global mycursor
global current_user
Initial_issue = 0
credentials = [name, password, address, phoneNo, Initial_issue]
if phoneNo.isdigit() and len(phoneNo) == 10 and len(password) > 5:
mycursor.execute("insert into
usersdata(Name,Password,PhoneNo,Address,BooksIssued)
values('{}','{}','{}','{}',{})".format(
name, password, phoneNo, address, Initial_issue))
mycon.commit()
current_user.extend(credentials)
current_user.append(0)
return True
else:
if not phoneNo.isdigit():
return "Invalid phoneNo"
else:
return "Password too short"
return False
if userexists == True:
return True
else:
return False
else:
return "Wrong userId"
except:
return False
# function returns the userID of the current user after taking in the name
def current_user_id(Name):
mycursor.execute("select * from usersdata")
data = mycursor.fetchall()
for i in data:
list(i)
if Name == str(i[0]):
return str(i[2])
break
5
# books.py module
import mysql.connector
import pandas as pd
from tabulate import tabulate
mycon = mysql.connector.connect(
host="localhost", user="root", password="1234", database="library")
if not mycon:
print("Error in connecting")
mycursor = mycon.cursor()
# transaction.py module
7
import datetime
import mysql.connector as sqlt
from numpy import bitwise_or
con = sqlt.connect(host="localhost", user="root",
password="1234", database="library")
cursor = con.cursor()
def no(id):
qry = "select * from usersdata where userId='{}';".format(id)
cursor.execute(qry)
r = cursor.fetchone()
if r:
nom = r[5]
if nom < 4:
nom2 = nom+1
if r:
q2 = "select bookId, NoOfCopiesLeft from bookstable where
bookId={};".format(bookID)
cursor.execute(q2)
r1 = cursor.fetchall()
if r1:
out2 = [item for t in r1 for item in t]
if int(out2[1]) > 0:
dt_str = str(datetime.datetime.now())
NoOfCopiesLeft = out2[1]-1
q3 = "insert into issuetable(bookId,userId,DateIssued)
8
values('{}','{}','{}');".format(bookID, memID,
dt_str)
cursor.execute(q3)
q4 = "update bookstable set NoOfCopiesLeft={} where
bookId='{}';".format(NoOfCopiesLeft, bookID)
cursor.execute(q4)
q5 = "update usersdata set booksissued={} where
userid='{}';".format(nom2, memID)
cursor.execute(q5)
q6 = "update issuetable set no_of_copies={} where
bookid='{}';".format(total_issued, bookID)
cursor.execute(q6)
con.commit()
else:
return "Wrong UserId"
else:
return "Maximun limit exceed"
except:
return "Wrong Entry"
if nom > 0:
nom2 = nom-1
if r:
q2 = "select bookId, NoOfCopiesLeft from bookstable where
bookId={};".format(bookID)
cursor.execute(q2)
r1 = cursor.fetchall()
if r1:
out1 = [item for t in r1 for item in t]
dt_str = str(datetime.datetime.now())
9
NoOfCopiesLeft = out1[1]+1
q3 = "insert into returntable(bookId,userId,datereturned)
values('{}','{}','{}');".format(bookID, memID,
dt_str)
cursor.execute(q3)
q4 = "update bookstable set NoOfCopiesLeft={} where
bookId='{}';".format(NoOfCopiesLeft, bookID)
cursor.execute(q4)
q5 = "update usersdata set booksissued={} where
userid='{}';".format(nom2, memID)
cursor.execute(q5)
con.commit()
else:
return "Wrong Book ID"
else:
return "Wrong UserId"
else:
return "You dont have any books issued"
except:
return "Wrong Entry"
# report.py module
def col_chart():
q = "select bookId,count(no_of_copies) as totalcopies from issuetable
group by bookId;"
df = pd.read_sql(q, con)
# print(df)
plt.bar(df.bookId, df.totalcopies)
plt.xlabel("Book ID")
plt.ylabel("Copies Issued")
plt.title("Best Reading Book")
plt.xticks(df.bookId)
plt.show()
# importing tkinter
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
import mysql.connector
# variable to store the current userID (user who is using the application )
userID = ''
def clearFrame():
for widget in frame.winfo_children():
widget.destroy()
12
try:
if bookid.get == "":
messagebox.showinfo("Error", "Please complete the required
field!")
elif book_issue(str(userID), str(bookid.get())) == "Book Issued":
messagebox.showinfo(
"Issued", "Book issued, return it before 14 days to exempt any
fine")
after_login_signup()
else:
messagebox.showinfo("Error", book_issue(
str(userID), str(bookid.get())))
except:
messagebox.showinfo("Error", "Can't verify issue")
# book_search(int(bookid2.get()))
tv = ttk.Treeview(frame, columns=(1, 2, 3, 4),
show="headings", height="15")
tv.place(x=20, y=20)
13
tv.heading(1, text="BookID")
tv.heading(2, text="Title")
tv.heading(3, text="Author")
tv.heading(4, text="Availability")
i = 0
for row in mycursor:
if row[6] > 0:
tv.insert('', i, text='', values=(
row[0], row[1], row[2], "Available"))
else:
tv.insert('', i, text='', values=(
row[0], row[1], row[2], " Not Available"))
i = i+1
# function that decides what happen what happens when the user clicks the
issue option after logging in
def after_issuebtn():
clearFrame()
lblfrstrow = Label(frame, text="Book ID *")
lblfrstrow.place(x=150, y=150)
global bookid
bookid = Entry(frame, width=35, borderwidth=5)
bookid.place(x=150, y=170, width=350)
# function that decides what happen what happens when the user clicks the
return option after logging in
def after_returnbtn():
clearFrame()
lblfrstrow = Label(frame, text="Book ID *")
lblfrstrow.place(x=150, y=150)
global bookid6
bookid6 = Entry(frame, width=35, borderwidth=5)
bookid6.place(x=150, y=170, width=350)
14
verifyissuebtn = Button(frame, text="RETURN",
bg='yellow', command=verifyreturn)
verifyissuebtn.place(x=230, y=220, width=155)
# this function changes the password by calling the pwd_edit function from the
library
def change_passworde():
a = paw.get()
if paw.get == "":
messagebox.showinfo("Error", "Please complete the required field")
elif len(paw.get()) < 6:
messagebox.showinfo("Error", "Password too short ")
elif pwd_edit(a, paw.get()):
pwd_edit(int(userID), a)
messagebox.showinfo("Success", "Password Changed")
account()
else:
messagebox.showinfo("Success", "Error")
# this function changes the phone number by calling the phno_edit function
from the library
def change_phone():
a = phone2.get()
if phone2.get == "":
messagebox.showinfo("Error", "Please complete the required field")
elif len(phone2.get()) != 10:
messagebox.showinfo("Error", "Invalid Phone No")
elif phno_edit(int(userID), phone2.get()):
phno_edit(int(userID), a)
messagebox.showinfo("Success", "PhoneNO Changed")
account()
else:
messagebox.showinfo("Success", phno_edit(int(userID), a))
# this function changes the address by calling the ad_edit function from the
library
def change_address():
global address
if address.get == "":
15
messagebox.showinfo("Error", "Please complete the required field")
a = address.get()
if ad_edit(int(userID), address.get()):
ad_edit(int(userID), a)
messagebox.showinfo("Success", "Address Changed")
account()
else:
messagebox.showinfo("Success", ad_edit(int(userID), a))
# this function deletes the user account by calling the member_delete function
from the library
def delete_account():
member_delete(int(userID))
messagebox.showinfo("GoodBye", "We are sad to see you GO!!!")
mainpro()
# this function defines what happens after the user click the accountsettings
from the right hand top corner dropdown menu
def account():
clearFrame()
changephone = Button(
frame, text="Change PhoneNo", width=35, borderwidth=5, command=phone)
changephone.place(x=180, y=120)
def warning1():
ans = messagebox.askyesno(
"Delete", "Are you sure you want to change your password?")
if ans:
passwor()
changepassword = Button(frame, text="Change Password",
width=35, borderwidth=5, command=warning1)
changepassword.place(x=180, y=160)
17
def warning():
ans = messagebox.askyesno(
"Delete", "Are you sure you want to delete your account?")
if ans:
delete_account()
delete = Button(
frame, text="Delete Account", width=35, borderwidth=5, bg="red",
comman=warning)
delete.place(x=180, y=200)
def selected(event):
if clicked.get() == "logout":
clearFrame()
mainpro()
elif clicked.get() == "accountsettings":
clearFrame()
account()
clicked = StringVar()
clicked.set(name)
elif error:
messagebox.showinfo(
"Success", "User Created Succesfully. Use Your Phone number as
your username.")
mainpro()
else:
messagebox.messagebox.showinfo("Error", "User cant be created")
# this function takes all the needed data for new user
def signup():
clearFrame()
global password2
password2 = Entry(frame, width=35, borderwidth=5)
password2.place(x=150, y=130, width=200)
global contact2
19
contact2 = Entry(frame, width=35, borderwidth=5)
contact2.place(x=150, y=180, width=200)
global address2
address2 = Entry(frame, width=35, borderwidth=5)
address2.place(x=150, y=230, width=200)
global signinbtn2
signinbtn2 = Button(frame, text="Create Account",
command=signup_click, width=35, borderwidth=5,
bg="yellow")
signinbtn2.place(x=160, y=300, width=155)
else:
messagebox.showinfo("Error", "Invalid username or password.")
Username.delete(0, END)
password.delete(0, END)
# book_search(int(bookid2.get()))
tv = ttk.Treeview(frame, columns=(1, 2, 3, 4),
show="headings", height="15")
tv.place(x=20, y=20)
tv.heading(1, text="UserID")
tv.heading(2, text="Name")
tv.heading(3, text="Phone No")
tv.heading(4, text="Current Books Issued")
i = 0
for row in mycursor:
tv.insert('', i, text='', values=(
row[2], row[0], row[3], row[5]))
i = i+1
def warning1():
ans = messagebox.askyesno(
"Delete", "Are you sure you want to delete this book?")
if ans:
deletebooksbutton()
delbtn = Button(frame, text="DELETE",
width=35, borderwidth=5, command=warning1, fg="red")
delbtn.place(x=180, y=220)
delbtn = Button(frame, text="Back", width=35,
borderwidth=5, command=afteradlog, bg="cyan")
delbtn.place(x=180, y=280)
def warning1():
ans = messagebox.askyesno("Delete", "Are you sure you want to
logout?")
if ans:
mainpro()
logout = Button(frame, text="LOGOUT", command=warning1, bg="red",
width=35, borderwidth=5)
logout.place(x=180, y=290)
return
return
def selected(event):
if clicked.get() == "memberlogin":
clearFrame()
mainpro()
elif clicked.get() == "adminlogin":
clearFrame()
admin()
clicked = StringVar()
clicked.set("memberlogin")
drop = OptionMenu(frame, clicked, "memberlogin",
"adminlogin", command=selected)
drop.place(x=0, y=0)
lblfrstrow = Label(frame, text="Administrative Username *")
lblfrstrow.place(x=150, y=90)
global Username4
Username4 = Entry(frame, width=35, borderwidth=5)
Username4.place(x=150, y=110, width=200)
global password4
password4 = Entry(frame, width=35, borderwidth=5)
password4.place(x=150, y=170, width=200)
# flow of control starts form here(it defines what shows up when the
users/admin starts the application)
def mainpro():
clearFrame()
global Username
global password
def selected(event):
if clicked.get() == "memberlogin":
clearFrame()
mainpro()
elif clicked.get() == "adminlogin":
clearFrame()
admin()
clicked = StringVar()
clicked.set("memberlogin")
drop = OptionMenu(frame, clicked, "adminlogin",
"memberlogin", command=selected)
drop.place(x=0, y=0)
login_btn = PhotoImage(
file='FRONTEND/iconAndImages/login.png')
submitbtn = Button(frame, image=login_btn,
command=login, borderwidth=0)
submitbtn.place(x=160, y=220, width=155)
registerbtn = PhotoImage(file='FRONTEND/iconAndImages/reg.png')
register = Button(frame, image=registerbtn,
command=signup, borderwidth=0)
25
register.place(x=160, y=300, width=155)
root.mainloop()
# main(flow starts )
mainpro()
Output
26
Fig 2.1 Member Login Page
27
Fig 2.3 Issue Books
28
Fig 2.5 Best Reading Book Chart
30
Fig 3.3 Add Books
31
Fig 3.5 Member Details
32
Fig 4.2 Account Settings
33
MySQL
34
Fig 5.4 Returntable
35
Prerequisites
Software
1) Python 3.8.5
2) MySQL 5.5
3) Visual Studio Code
Hardware
1) Intel(R) Core (TM) i5-10210U CPU @ 1.60GHz 2.11 GHz
2) 8.00 GB RAM
3) Windows 11
4) 10 GB of available hard disk for software installation
5) Internet connection required for software installation
36
Bibliography
Books
“Computer Science with Python”- Arora, Sumita.
“Python Programming: Using Problem Solving Approach”-
Thareja, Seema.
“The Definituve Guide to MySQL”- Kofler, Michael
Websites
www.W3School.com
www.sololearn.com
www.freecodecamp.com
www.python.org
37