0% found this document useful (0 votes)
11 views19 pages

Library Management System

Uploaded by

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

Library Management System

Uploaded by

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

USTP Virtual Library

Submitted to:
SIR KENNETH CODILLA AMPOLITOD

Submitted by:
BAUTISTA, Vladimir Cromwell G
DADES, ARIELLE V
ESCOBIA, HARVEY R
LAQUINA, MELVIN Jhon T
PONGASI, DV FOWLER D
SAMBLACENIO, John Roland A
YAMIS, Ralp Lorenz N
Table of contents

Teams
Introduction of the system
Flowcharts system
Screenshot of the output of the system
About the Team

Together with the team, which was led by Arielle V. Dades the assigned leader
of the group and her members constructed a library management system. Vladimir
Cromwell G. Bautista and Ralp Lorenz N. Yamis as the lead programmers, and
are assisted by Harvey R. Escobia, Melvin Jhon T. Laquina, Dv Fowler D.
Pongasi and John Roland A. Samblacenio. And Arielle V. Dades as the
designer. As each one was given their assigned parts the library
management system was successfully constructed due to the team’s
hardwork and cooperation.
Introduction of the system

The library management system is constructed for users to improve the way
the library's resources are managed by providing a user-friendly and effective
means of managing the library. As it helps users to maintain the database of new
books and the books that are borrowed, returned, or updated. Our system provides
the key features or tools needed to maintain an organized and accessible library.
The key features are:
 Add books – This feature allows the user to add new books to the library, the
user will be able to add the details of the books which are the title, the
author, and its genre.
 Update book – This feature allows the user to edit the details of the book. To
change the name of the author, the title, or its genre.
 Delete book – This feature allows the user to delete books that are
unimportant or the ones that they don’t need anymore.
 Search book – This feature allows the user to search for a specific book in the
library. Whether by its Title, author, or genre. The system will search if it also
exists in the library.
 Borrow book – This feature allows the user to borrow a book in the library.
 Return book - This feature allows the user to return the borrowed book.
 Book list – this feature allows the user to access the list of the books existing
in the library.
 Clear fields – This feature allows the user to clear the text entered in the
Author, Title, and genre.
 Delete full inventory – This allows the user to delete all the books listed in the
library.
 Change availability – This allows the user to change the availability of the
book. If the book is currently issued or available.
 Popular book report – This allows the user to see which book is popular in the
library.
The library management system focuses on exploring the features and
capabilities of the system and discover how it can transform the way to manage the
library.
Flowcharts system
Source code
# Importing all necessary modules
import sqlite3
from tkinter import *
import tkinter.ttk as ttk
import tkinter.messagebox as mb
import tkinter.simpledialog as sd

# Global variable for the connector


connector = sqlite3.connect('your_database.db')

# Create a cursor object to execute SQL commands


cursor = connector.cursor()

# Define the CREATE TABLE query with the Genre field


create_table_query = '''
CREATE TABLE IF NOT EXISTS Library (
BK_NAME TEXT,
BK_ID TEXT PRIMARY KEY,
AUTHOR_NAME TEXT,
GENRE TEXT,
BK_STATUS TEXT,
CARD_ID TEXT
)
'''

# Execute the CREATE TABLE query to update the schema


cursor.execute(create_table_query)
connector.commit()
cursor.close()

# System color and fonts


lf_bg = 'LightSkyBlue' # Left Frame Background Color
rtf_bg = 'DeepSkyBlue' # Right Top Frame Background Color
rbf_bg = 'DodgerBlue' # Right Bottom Frame Background Color
btn_hlb_bg = 'SteelBlue' # Background color for Head Labels and Buttons

lbl_font = ('Georgia', 13) # Font for all labels


entry_font = ('Times New Roman', 12) # Font for all Entry widgets
btn_font = ('Gill Sans MT', 13)

def issuer_card():
Cid = sd.askstring('Issuer Card ID', 'What is the Issuer\'s Card ID?\
t\t\t')
if not Cid:
mb.showerror('Issuer ID cannot be zero!', 'Can\'t keep Issuer ID
empty, it must have a value')
else:
return Cid

def display_records():
global connector, tree
tree.delete(*tree.get_children())

curr = connector.execute('SELECT * FROM Library')


data = curr.fetchall()

for record in data:


tree.insert('', END, values=record)

def clear_fields():
global bk_status, bk_id, bk_name, author_name, card_id, genre

bk_status.set('Available')
for i in ['bk_id', 'bk_name', 'author_name', 'card_id', 'genre']:
exec(f"{i}.set('')")
bk_id_entry.config(state='normal')
try:
tree.selection_remove(tree.selection()[0])
except:
pass

def clear_and_display():
clear_fields()
display_records()

def search_records():
search_query = search_var.get().strip()
if not search_query:
mb.showerror('Empty Search Query', 'Please enter a search
query.')
return

cursor = connector.cursor()
# cursor.execute("SELECT * FROM Library WHERE BK_NAME LIKE ?", ('%' +
search_query + '%',))
cursor.execute("SELECT * FROM Library WHERE BK_NAME LIKE ? OR
AUTHOR_NAME LIKE ? OR GENRE LIKE ?",
('%' + search_query + '%', '%' + search_query + '%',
'%' + search_query + '%',))
search_result = cursor.fetchall()
cursor.close()

if not search_result:
mb.showinfo('No Results', 'No records found matching your search
query.')
else:
tree.delete(*tree.get_children())
for record in search_result:
tree.insert('', END, values=record)

search_var.set('')

def borrow_book():
if not tree.selection():
mb.showerror('Error!', 'Please select a book from the database.')
return
current_item = tree.focus()
values = tree.item(current_item)['values']
BK_status = values[4]

if BK_status == 'Issued':
mb.showinfo('Book Already Issued', 'This book is already
issued.')
else:
cursor = connector.cursor()
cursor.execute('UPDATE Library SET BK_STATUS=?, CARD_ID=? WHERE
BK_ID=?',
('Issued', issuer_card(), values[1]))
connector.commit()
cursor.close()
clear_and_display()
mb.showinfo('Book Issued', 'The book has been successfully
issued.')

def return_book():
if not tree.selection():
mb.showerror('Error!', 'Please select a book from the database.')
return

current_item = tree.focus()
values = tree.item(current_item)['values']
BK_status = values[4]

if BK_status == 'Available':
mb.showinfo('Book Already Returned', 'This book is already
returned.')
else:
cursor = connector.cursor()
cursor.execute('UPDATE Library SET BK_STATUS=?, CARD_ID=? WHERE
BK_ID=?',
('Available', 'N/A', values[1]))
connector.commit()
cursor.close()
clear_and_display()
mb.showinfo('Book Returned', 'The book has been successfully
returned.')

def remove_record():
if not tree.selection():
mb.showerror('Error!', 'Please select an item from the database')
return

current_item = tree.focus()
values = tree.item(current_item)
selection = values["values"]

cursor = connector.cursor()
cursor.execute('DELETE FROM Library WHERE BK_ID=?', (selection[1],))
connector.commit()
cursor.close()
tree.delete(current_item)

mb.showinfo('Done', 'The record you wanted deleted was successfully


deleted.')

def delete_inventory():
if mb.askyesno('Are you sure?',
'Are you sure you want to delete the entire
inventory?\n\nThis command cannot be reversed'):
tree.delete(*tree.get_children())

cursor = connector.cursor()
cursor.execute('DELETE FROM Library')
connector.commit()
cursor.close()
else:
return

def update_record():
def update():
global bk_status, bk_name, bk_id, author_name, card_id, genre
global connector, tree

current_item = tree.focus()
values = tree.item(current_item)
selection = values["values"]

bk_name_val = bk_name.get()
bk_status_val = bk_status.get()
author_name_val = author_name.get()
bk_id_val = bk_id.get()
genre_val = genre.get()

cursor = connector.cursor()
cursor.execute('UPDATE Library SET BK_NAME=?, BK_STATUS=?,
AUTHOR_NAME=?, GENRE=? WHERE BK_ID=?',
(bk_name_val, bk_status_val, author_name_val,
genre_val, bk_id_val))
connector.commit()
cursor.close()

clear_and_display()

edit.destroy()
bk_id_entry.config(state='normal')
clear.config(state='normal')

if tree.selection():
current_item = tree.focus()
values = tree.item(current_item)["values"]
bk_name.set(values[0])
bk_id.set(values[1])
author_name.set(values[2])
genre.set(values[3])
bk_status.set(values[4])

bk_id_entry.config(state='disabled')
clear.config(state='disabled')

edit = Button(left_frame, text='Update Record', font=btn_font,


bg=btn_hlb_bg, width=20, command=update)
edit.place(x=50, y=425)

def add_record():
global connector
global bk_name, bk_id, author_name, bk_status, genre, card_id

if bk_status.get() == 'Issued':
card_id.set(issuer_card())
else:
card_id.set('N/A')

surety = mb.askyesno('Are you sure?',


'Are you sure this is the data you want to
enter?\nPlease note that Book ID cannot be changed in the future')

if surety:
try:
connector.execute(
'INSERT INTO Library (BK_NAME, BK_ID, AUTHOR_NAME, GENRE,
BK_STATUS, CARD_ID) VALUES (?, ?, ?, ?, ?, ?)',
(bk_name.get(), bk_id.get(), author_name.get(),
genre.get(), bk_status.get(), card_id.get()))
connector.commit()

clear_and_display()

mb.showinfo('Record added', 'The new record was successfully


added to your database')
except sqlite3.IntegrityError:
mb.showerror('Book ID already in use!',
'The Book ID you are trying to enter is already
in the database, please alter that book\'s record or check any
discrepancies on your side')

def change_availability():
if not tree.selection():
mb.showerror('Error!', 'Please select a book from the database')
return

current_item = tree.focus()
values = tree.item(current_item)['values']
BK_id = values[1]
BK_status = values[4]

cursor = connector.cursor()

if BK_status == 'Issued':
surety = mb.askyesno('Is return confirmed?', 'Has the book been
returned to you?')
if surety:
cursor.execute('UPDATE Library SET BK_STATUS=?, CARD_ID=?
WHERE BK_ID=?', ('Available', 'N/A', BK_id))
connector.commit()
else:
mb.showinfo('Cannot be returned', 'The book status cannot be
set to Available unless it has been returned')
else:
cursor.execute('UPDATE Library SET BK_STATUS=?, CARD_ID=? WHERE
BK_ID=?', ('Issued', issuer_card(), BK_id))
connector.commit()

cursor.close()
clear_and_display()

def generate_popular_book_report():
cursor = connector.cursor()
cursor.execute(
'SELECT BK_NAME, COUNT(*) as total FROM Library WHERE BK_STATUS=?
GROUP BY BK_NAME ORDER BY total DESC LIMIT 1',
('Issued',))
result = cursor.fetchone()
cursor.close()

if result:
popular_book = result[0]
mb.showinfo('Popular Book Report', f'The most popular book at the
moment is: {popular_book}')
else:
mb.showinfo('Popular Book Report', 'No books have been issued
yet.')

# Adding search entry and button


root = Tk()
root.title('USTP Library Management System')
root.geometry('1300x720')
root.resizable(0, 0)

# StringVars
bk_status = StringVar()
bk_name = StringVar()
bk_id = StringVar()
author_name = StringVar()
card_id = StringVar()
genre = StringVar()

search_var = StringVar()

# Frames
left_frame = Frame(root, bg=lf_bg)
left_frame.place(x=0, y=30, relwidth=0.3, relheight=0.96)

RT_frame = Frame(root, bg="#79BAEC")


RT_frame.place(relx=0.3, y=30, relheight=0.2, relwidth=0.7)

RB_frame = Frame(root)
RB_frame.place(relx=0.3, rely=0.24, relheight=0.785, relwidth=0.7)

Label(root, text='USTP VIRTUAL LIBRARY', font=("Noto Sans CJK TC", 15,


'bold'), bg=btn_hlb_bg, fg='#000000').pack(side=TOP, fill=X)

# Adding Borrow button


borrow_button = Button(left_frame, text='Borrow Book', font=btn_font,
bg=btn_hlb_bg, width=20, command=borrow_book)
borrow_button.place(x=50, y=545)

# Adding return button


return_button = Button(left_frame, text='Return Book', font=btn_font,
bg=btn_hlb_bg, width=20, command=return_book)
return_button.place(x=50, y=610)

# Left Frame
Label(left_frame, text='Book Title', bg=lf_bg, font=lbl_font).place(x=99,
y=25)
Entry(left_frame, width=25, font=entry_font,
textvariable=bk_name).place(x=45, y=55)

Label(left_frame, text='Book ID', bg=lf_bg, font=lbl_font).place(x=110,


y=105)
bk_id_entry = Entry(left_frame, width=25, font=entry_font,
textvariable=bk_id)
bk_id_entry.place(x=45, y=135)

Label(left_frame, text='Author Name', bg=lf_bg,


font=lbl_font).place(x=90, y=185)
Entry(left_frame, width=25, font=entry_font,
textvariable=author_name).place(x=45, y=215)

Label(left_frame, text='Genre', bg=lf_bg, font=lbl_font).place(x=108,


y=267) # Add label for Genre
Entry(left_frame, width=25, font=entry_font,
textvariable=genre).place(x=45, y=295) # Add entry for Genre

Label(left_frame, text='Status of the Book', bg=lf_bg,


font=lbl_font).place(x=75, y=345)
dd = OptionMenu(left_frame, bk_status, *['Available', 'Issued'])
dd.configure(font=entry_font, width=12)
dd.place(x=75, y=380)

submit = Button(left_frame, text='Add Book', font=btn_font,


bg=btn_hlb_bg, width=20, command=add_record)
submit.place(x=50, y=425)

clear = Button(left_frame, text='Clear Fields', font=btn_font,


bg=btn_hlb_bg, width=20, command=clear_fields)
clear.place(x=50, y=485)

# Right Top Frame


Button(RT_frame, text='Delete Book', font=btn_font, bg=btn_hlb_bg,
width=17, command=remove_record).place(x=8, y=30)
Button(RT_frame, text='Delete full inventory', font=btn_font,
bg=btn_hlb_bg, width=17, command=delete_inventory).place(x=178, y=30)
Button(RT_frame, text='Edit Book', font=btn_font, bg=btn_hlb_bg,
width=17, command=update_record).place(x=348, y=30)
Button(RT_frame, text='Change Availability', font=btn_font,
bg=btn_hlb_bg, width=19, command=change_availability).place(x=518, y=30)
Button(RT_frame, text='Popular Book Report', font=btn_font,
bg=btn_hlb_bg, width=19,
command=generate_popular_book_report).place(x=705, y=30)

# Search Bar in Right Top Frame


Label(RT_frame, text='Search Book', bg="#79BAEC",
font=lbl_font).place(x=9, y=90)
search_entry = Entry(RT_frame, width=25, font=entry_font,
textvariable=search_var)
search_entry.place(x=110, y=90)

search_button = Button(RT_frame, text='Search', font=btn_font,


bg=btn_hlb_bg, width=15, command=search_records)
search_button.place(x=320, y=80)

# Right Bottom Frame


Label(RB_frame, text='BOOK INVENTORY', bg=btn_hlb_bg, font=("Noto Sans
CJK TC", 15, 'bold')).pack(side=TOP, fill=X)

tree = ttk.Treeview(RB_frame, selectmode=BROWSE,


columns=('Book Name', 'Book ID', 'Author', 'Genre',
'Status', 'Issuer Card ID'))

XScrollbar = Scrollbar(tree, orient=HORIZONTAL, command=tree.xview)


YScrollbar = Scrollbar(tree, orient=VERTICAL, command=tree.yview)
XScrollbar.pack(side=BOTTOM, fill=X)
YScrollbar.pack(side=RIGHT, fill=Y)
tree.config(xscrollcommand=XScrollbar.set, yscrollcommand=YScrollbar.set)

tree.heading('Book Name', text='Book Name', anchor=CENTER)


tree.heading('Book ID', text='Book ID', anchor=CENTER)
tree.heading('Author', text='Author', anchor=CENTER)
tree.heading('Genre', text='Genre', anchor=CENTER) # Add heading for
Genre
tree.heading('Status', text='Status of the Book', anchor=CENTER)
tree.heading('Issuer Card ID', text='Card ID of the Issuer',
anchor=CENTER)

tree.column('#0', width=0, stretch=NO)


tree.column('#1', width=225, stretch=NO)
tree.column('#2', width=70, stretch=NO)
tree.column('#3', width=150, stretch=NO)
tree.column('#4', width=100, stretch=NO) # Adjust column width for Genre
tree.column('#5', width=105, stretch=NO)
tree.column('#6', width=132, stretch=NO)

tree.place(y=30, x=0, relheight=0.9, relwidth=1)


clear_and_display()

# Finalizing the window


root.update()
root.mainloop()
Screenshot of the output of the system

You might also like