Computer Science Library Management Project
Computer Science Library Management Project
Swarnalatha J
(PRINCIPAL)
ACKNOWLEDGEMENT
I express my deep gratitude and appreciation to
those who agreed in this project, for their time
expended and courage in sharing their insights
with a fledging student . It is to them that I am
most indebted, and I can only hope that the
product of our collaboration benefits each one
as much as I benefited from the process.
I had been immeasurably enriched by working
under the guidance of Mr. T. Manoj Kumar the
subject teacher ,who has a great level of
knowledge and who has an art of encouraging ,
correcting and directing me in every situation
possible, which has enabled me to complete the
project.
I acknowledge to all the people who have
involved and supported me in making this
project.
With thanks…
Madhan Sai Raghavendra B V
Grade 12 science group
THANKS
SOURCE CODE
# Connecting to Database
connector = sqlite3.connect('library.db')
cursor = connector.cursor()
connector.execute(
'CREATE TABLE IF NOT EXISTS Library (BK_NAME
TEXT, BK_ID TEXT PRIMARY KEY NOT NULL,
AUTHOR_NAME TEXT, BK_STATUS TEXT,
CARD_ID TEXT)'
)
# Functions
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, cursor
global tree
tree.delete(*tree.get_children())
def clear_fields():
global bk_status, bk_id, bk_name, author_name,
card_id
bk_status.set('Available')
for i in ['bk_id', 'bk_name', 'author_name', 'card_id']:
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 add_record():
global connector
global bk_name, bk_id, author_name, bk_status
if bk_status.get() == 'Issued':
card_id.set(issuer_card())
else:
card_id.set('N/A')
clear_and_display()
if not tree.focus():
mb.showerror('Select a row!', 'To view a record,
you must select it in the table. Please do so before
continuing.')
return
current_item_selected = tree.focus()
values_in_selected_item =
tree.item(current_item_selected)
selection = values_in_selected_item['values']
bk_name.set(selection[0]) ;
bk_id.set(selection[1]) ; bk_status.set(selection[3])
author_name.set(selection[2])
try:
card_id.set(selection[4])
except:
card_id.set('')
def update_record():
def update():
global bk_status, bk_name, bk_id, author_name,
card_id
global connector, tree
if bk_status.get() == 'Issued':
card_id.set(issuer_card())
else:
card_id.set('N/A')
clear_and_display()
edit.destroy()
bk_id_entry.config(state='normal')
clear.config(state='normal')
view_record()
bk_id_entry.config(state='disable')
clear.config(state='disable')
edit = Button(left_frame, text='Update Record',
font=btn_font, bg=btn_hlb_bg, width=20,
command=update)
edit.place(x=50, y=375)
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"]
tree.delete(current_item)
clear_and_display()
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())
def change_availability():
global card_id, tree, connector
if not tree.selection():
mb.showerror('Error!', 'Please select a book from
the database')
return
current_item = tree.focus()
values = tree.item(current_item)
BK_id = values['values'][1]
BK_status = values["values"][3]
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()
clear_and_display()
# Variables
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
# StringVars
bk_status = StringVar()
bk_name = StringVar()
bk_id = StringVar()
author_name = StringVar()
card_id = 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 Name', bg=lf_bg,
font=lbl_font).place(x=98, y=25)
Entry(left_frame, width=25, font=entry_font,
text=bk_name).place(x=45, y=55)
tree.config(xscrollcommand=XScrollbar.set,
yscrollcommand=YScrollbar.set)
clear_and_display()