Library Management System
Library Management System
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
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())
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)
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')
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')
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()
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.')
# 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)
RB_frame = Frame(root)
RB_frame.place(relx=0.3, rely=0.24, relheight=0.785, relwidth=0.7)
# 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)