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

CS_Project_z

Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

DURGAPUR PUBLIC SCHOOL

COMPUTER SCIENCE
PROJECT
LIBRARY MANAGEMENT SYSTEM

Abstract
This project presents the development of a Library Management System to streamline library
operations and provide a user-friendly solution for managing books, members, and
borrowing processes.

Md. Zunaid Khan


XII(B) ROLL: 18
Subject: Computer Science (083)
CERTIFICATE

This is to certify that the project entitled ‘Library Management System’ is


authentic work carried out under my supervision as part of the CBSE
curriculum of Class XII Computer Science and that it is as per the
guidelines issued by CBSE. To the best of my knowledge, the project is
original and a bonafide work undertaken by Md. Zunaid Khan.

_____________________ ______________________
Signature of Principal Signature of External Examiner

_____________________
Signature of Subject Teacher

1|P a g e
DECLARATION

I, Md. Zunaid Khan, a student of class XII, hereby declare that I have
completed my project to the best of mine ability and knowledge. I have
taken a lot of effort to complete this task successfully.

______________________
Signature of the Student

2|P a g e
ACKNOWLEDGEMENT

First and above all, I praise God, the almighty for providing me this
opportunity and granting me the capability to proceed successfully. This
piece of work will never be accomplished without His blessings. Then I
would like to express my greatest appreciation to everyone who have
helped and supported me throughout the project. I am thankful to my
Computer Science Teacher, Mrs. Debosree Bhattacharjee for her ongoing
support during the project. Her advice and encouragement had a huge
role to finalize this project report. I wish to thank my parents as well for
their support and encouragement without which I could not have
completed this project in the limited timeframe. In the end, I want to thank
my friends who displayed appreciation for our work and motivated me to
continue my work.

3|P a g e
INDEX

PAGE
SL NO. TOPIC
NO.
1. INTRODUCTION 5

2. OPERATIONS 5-6

3. SYSTEM DESIGN 7

4. PYTHON SOURCE CODE 8 – 16

5. SQL QUERIES 16 - 17

6. DEMONSTRATIONS 17 – 20

7. CONCLUSION 20

8. BIBLIOGRAPHY 21

4|P a g e
1 INTRODUCTION

Aim of the project:


This project has been prepared as a requirement for AISSCE-2024-25.
Its main aim is to develop a python program which manages the working
of a library.

Purpose:
The purpose of this project is to ease the management of a Library. It
uses Python programming with SQL connectivity concepts to make the
work easier and support the smooth functioning of a Library. This is
Python Projects on Library Management system, which provided a lot of
facility to their member to manage their activity easily. The objective and
scope of my Project Library Management system is to record the details
various activities of member. It will simplify the task and reduce the
paper work.

2 OPERATIONS

1. Edit books database - Register a book by entering following details


and assigning a Book ID to the book:
a. Book Name
b. Author
c. Publisher

5|P a g e
d. Price
e. Quantity

2. Edit members database - Register a Member by entering following


details and assigning a Member ID to the member:
a. Member ID
b. Member Name
c. Telefone
d. E-mail
e. Address

3. Edit issuedbooks database - Issue a book by entering the following


details:
a. Member ID
b. Member Name
c. Book ID
d. Book Name
e. Quantity

4. View all books - We can know all the details of an issued book
using Issue ID.

5. View all members - We can view list of all the books present in the
library.

6. View all issued books - We can view list of all the members
registered with the library.

7. Exit - Exits the application.

6|P a g e
3 SYSTEM DESIGN


LIBRARY MANAGEMENT
SYSTEM

PYTHON CODES SQL QUERIES

`QuantumLeap.py` library (database)

edit_books() books

members
edit_members()

issuedbooks
issbk()

view_books()

view_members()

view_issbk()

menu()

7|P a g e
4 PYTHON SOURCE CODE

Module named `QuantumLeap.py`

import mysql.connector as sqlc


import string
import random

# Books Dataset

def edit_books():
flag = True
c = sqlc.connect(user='root', host='localhost',
password='zunaid1234', database='library')
mc = c.cursor()

while flag:
bname = input("Enter the book name: ")
ath = input("Enter the author: ")
pb = input("Enter the publisher: ")
prc = float(input("Enter the price: "))
qty = int(input("Enter the quantity: "))

mc.execute("SELECT `Book Name`, `Author`, `Publisher` FROM


books")
records = mc.fetchall()
cr = (bname, ath, pb)

if cr in records:
mc.execute(
"UPDATE books SET `Price` = %s, `Quantity` = %s
WHERE `Book Name` = %s AND `Author` = %s AND `Publisher` = %s",
(prc, qty, bname, ath, pb)
)
else:
mc.execute("SELECT `Book ID` FROM books")
records = [r[0] for r in mc.fetchall()]

while True:
fc = random.choice(string.ascii_uppercase)
digits = ''.join(random.choices(string.digits, k=3))
bid = fc + digits

8|P a g e
if bid not in records:
break

mc.execute(
"INSERT INTO books (`Book ID`, `Book Name`,
`Author`, `Publisher`, `Price`, `Quantity`) VALUES (%s, %s, %s, %s,
%s, %s)",
(bid, bname, ath, pb, prc, qty)
)
print(f"Book ID assigned: {bid}")

c.commit() # Make sure to commit changes to the database

choice = input("Want to enter more data (Y/N)? ")


if choice.lower() == 'n':
flag = False

c.close()

# Members Dataset

def edit_members():
flag = True
c = sqlc.connect(user='root', host='localhost',
password='zunaid1234', database='library')
mc = c.cursor()

while flag:
mc.execute("SELECT `Member ID`, `Member Name`, `Telefone`,
`E-mail`, `Address` FROM members")
members = mc.fetchall()
act = input("What do you want to do - Edit(E)/Add(A) or
Remove(R)? ")
if act.lower() == 'e' or act.lower() == 'a':
try:
mid = int(input("Enter the member ID: "))
except ValueError:
mnm = input("Enter the member name: ")
tel = input("Enter the telephone number: ")
em = input("Enter the email ID: ")
ads = input("Enter the address: ")

9|P a g e
if any(mnm == record[1] and (tel == record[2] or em
== record[3] or ads == record[4]) for record in members):
mc.execute(
"UPDATE members SET `Telefone` = %s, `E-
mail` = %s, `Address` = %s WHERE `Member Name` = %s",
(tel, em, ads, mnm)
)
else:
while True:
digits =
''.join(random.choices(string.digits, k=3))
if digits not in [record[0] for record in
members]:
break
mc.execute("INSERT INTO members (`Member ID`,
`Member Name`, `Telefone`, `E-mail`, `Address`) VALUES (%s, %s, %s,
%s, %s)", (digits, mnm, tel, em, ads))
print(f"Member ID assigned: {digits}")
else:
mnm2 = input("Enter the member name: ")
tel2 = input("Enter the telephone number: ")
em2 = input("Enter the email ID: ")
ads2 = input("Enter the address: ")

if mid in [record[0] for record in members]:


if mnm2 in [record[1] for record in members]:
mc.execute(
"UPDATE members SET `Telefone` = %s, `E-
mail` = %s, `Address` = %s WHERE `Member ID` = %s",
(tel2, em2, ads2, mid)
)
else:
print("The Member Name is incorrect...")
else:
print("No such Member ID exists...")
elif act.lower() == 'r':
idv = input("Enter the Member ID: ")
nmv = input("Enter the name of the member: ")
telv = input("Enter the telefone of the member (if you
know): ").strip()
emv = input("Enter the email ID of the member (if you
know): ").strip()

10 | P a g e
if telv or emv:
if (idv == record[0] and nmv == record[1] and (telv
== record[2] or emv == record[3]) for record in members):
mc.execute("DELETE FROM members WHERE `Member
ID` = %s", (idv, ))
print(f"Removed member with ID: {idv}")
else:
print("Invalid data... No member with such
dataset exists.")
else:
print("Error! Either the telephone or email ID is
required for removal of a member.")
else:
print('Invalid Input...')

c.commit() # Make sure to commit changes to the database

choice = input("Want to make more change (Y/N)? ").strip()


if choice.lower() == 'n':
flag = False

c.close()

# Issued Books dataset

def issbk():
flag = True
c = sqlc.connect(user='root', host='localhost',
password='zunaid1234', database='library')
mc = c.cursor()

while flag:
act = input("Do you want to return or issue? (r/i)
").strip().lower()

if act == 'i':
mid = int(input("Enter the Member ID: "))
mnm = input("Enter the name of the member: ")
mc.execute("SELECT `Member ID`, `Member Name` FROM
members")
record = mc.fetchall()
cr = (mid, mnm)

11 | P a g e
if cr in record:
bid = input("Enter the book ID: ")
bnm = input("Enter the book name: ")
mc.execute("SELECT `Book ID`, `Book Name` FROM
books")
rec = mc.fetchall()
crr = (bid, bnm)

if crr in rec:
mc.execute("SELECT `Member ID`, `Member Name`,
`Book ID`, `Book Name` FROM issuedbooks")
ccc = mc.fetchall()

if (mid, mnm, bid, bnm) in ccc:


print("Same book cannot be issued twice by
the same member...")
else:
qty = int(input("Enter the quantity: "))
mc.execute("SELECT CURDATE()")
date = mc.fetchone()[0]

mc.execute("SELECT `Member ID`, `Member


Name`, `Book ID`, `Book Name`, `Issue Date` FROM issuedbooks")
cii = mc.fetchall()

if (mid, mnm, bid, bnm, date) in cii:


mc.execute("SELECT `Quantity Issued`
FROM issuedbooks WHERE `Member ID` = %s AND `Book ID` = %s AND
`Issue Date` = %s", (mid, bid, date))
qi = mc.fetchone()[0]
mc.execute("UPDATE issuedbooks SET
`Quantity Issued` = %s WHERE `Member ID` = %s AND `Book ID` = %s AND
`Issue Date` = %s", (qi + qty, mid, bid, date))
else:
mc.execute("INSERT INTO issuedbooks
(`Member ID`, `Member Name`, `Book ID`, `Book Name`, `Quantity
Issued`, `Issue Date`) VALUES (%s, %s, %s, %s, %s, %s)", (mid, mnm,
bid, bnm, qty, date))
else:
print("No such book exists in the database...")
else:

12 | P a g e
print("Invalid credentials...")

elif act == 'r':


mid = int(input("Enter the Member ID: "))
mnm = input("Enter the name of the member: ")
mc.execute("SELECT `Member ID`, `Member Name` FROM
members")
record = mc.fetchall()
cr = (mid, mnm)

if cr in record:
bid = input("Enter the book ID: ")
bnm = input("Enter the book name: ")
mc.execute("SELECT `Book ID`, `Book Name` FROM
books")
rec = mc.fetchall()
crr = (bid, bnm)

if crr in rec:
qty = int(input("Enter the quantity of returned
books: "))
mc.execute("SELECT `Member ID`, `Member Name`,
`Book ID`, `Book Name` FROM issuedbooks")
cii = mc.fetchall()

if (mid, mnm, bid, bnm) in cii:


mc.execute("SELECT `Quantity Issued` FROM
issuedbooks WHERE `Member ID` = %s AND `Book ID` = %s", (mid, bid))
qi = mc.fetchone()[0]

if (qi - qty) < 0:


print(f"THIS MEMBER HAVE ISSUED ONLY
{qi} books...")
elif (qi - qty) == 0:
mc.execute("DELETE FROM issuedbooks
WHERE `Member ID` = %s AND `Book ID` = %s", (mid, bid))
else:
mc.execute("UPDATE issuedbooks SET
`Quantity Issued` = %s WHERE `Member ID` = %s AND `Book ID` = %s",
(qi - qty, mid, bid))
else:

13 | P a g e
print("THIS MEMBER HAVE NO SUCH ISSUED
BOOKS...")
else:
print("NO SUCH BOOK EXISTS...")
else:
print("NO SUCH MEMBER EXISTS...")

else:
print("PLEASE ENTER A VALID INPUT...")

c.commit() # Ensure all changes are committed to the


database
choice = input("Want to make more change (Y/N)?
").strip().lower()

if choice == 'n':
flag = False

c.close()

# View books dataset

def viewbooks():
c = sqlc.connect(user='root', host='localhost',
password='zunaid1234', database='library')
mc = c.cursor()
mc.execute("SELECT * FROM books")
records = mc.fetchall()
for record in records:
print(record)
c.close()

# View members dataset

def viewmembers():
c = sqlc.connect(user='root', host='localhost',
password='zunaid1234', database='library')
mc = c.cursor()
mc.execute("SELECT * FROM members")
recs = mc.fetchall()
for rec in recs:
print(rec)

14 | P a g e
c.close()

# View issuedbooks dataset

from datetime import datetime

def viewissbk():
c = sqlc.connect(user='root', host='localhost',
password='zunaid1234', database='library')
mc = c.cursor()
mc.execute("SELECT issuedbooks.`Member ID`, issuedbooks.`Member
Name`, members.`Telefone`, members.`E-mail`, members.`Address`,
issuedbooks.`Book ID`, issuedbooks.`Book Name`, books.`Publisher`,
issuedbooks.`Quantity Issued`, issuedbooks.`Issue Date` FROM
issuedbooks, members, books WHERE (issuedbooks.`Member ID` =
members.`Member ID`) AND (issuedbooks.`Book ID` = books.`Book ID`)")
recs = mc.fetchall()
for rec in recs:
mid, mnm, tel, email, addr, bid, bnm, pub, qty, issue_date =
rec
formatted_date = issue_date.strftime('%d-%b-%Y') if
isinstance(issue_date, datetime) else issue_date
print(f"Member ID: {mid}, Member Name: {mnm}, Telefone:
{tel}, E-mail: {email}, Address: {addr}, Book ID: {bid}, Book Name:
{bnm}, Publisher: {pub}, Quantity Issued: {qty}, Issue Date:
{formatted_date}")

c.close()

def menu():
while True:
print('''Which of the following tasks do you want to do?
1. Edit books database
2. Edit members database
3. Edit issuedbooks database
4. View all books
5. View all members
6. View all issuedbooks
7. Exit''')
choice = int(input("Enter an integer based on the above
numbering: "))

15 | P a g e
if choice == 1:
edit_books()
elif choice == 2:
edit_members()
elif choice == 3:
issbk()
elif choice == 4:
viewbooks()
elif choice == 5:
viewmembers()
elif choice == 6:
viewissbk()
elif choice == 7:
break
else:
print("Invalid choice! Please enter a valid input...")

menu()

5 SQL QUERIES

mysql> CREATE DATABASE library;


mysql> USE library;
mysql> CREATE TABLE books (`Book ID` PRIMARY KEY VARCHAR(4),
-> `Book Name` NOT NULL VARCHAR(50),
-> `Author` NOT NULL VARCHAR(50),
-> `Price` NOT NULL INTEGER,
-> `Quantity` INTEGER);
mysql> CREATE TABLE members (`Member ID` INTEGER PRIMARY KEY,
-> `Member Name` VARCHAR(50) NOT NULL,
-> `Telefone` INTEGER NOT NULL,
-> `E-mail` VARCHAR(30) NOT NULL,
-> `Address` VARCHAR(100) NOT NULL);
mysql> CREATE TABLE issuedbooks (`Member ID` INTEGER NOT NULL,
-> `Book ID` VARCHAR(4) NOT NULL,
-> `Book Name` VARCHAR(50) NOT NULL,

16 | P a g e
-> `Quantity Issued` INTEGER NOT NULL,
-> PRIMARY KEY (`Member ID`, `Book ID`));

6 DEMONSTRATION

First prompt after running the program:

1. Editing the books table (Adding a new book):

2. Editing the books table (Updating the details of an existing book):

17 | P a g e
3. Editing the members table (Adding a new member):

4. Editing the members table (Updating the credentials of an existing member):

18 | P a g e
5. Issuing a book:

6. Viewing all the books:

7. Viewing all the active members:

8. Viewing all the currently issued books:

19 | P a g e
9. Exiting the program:

7 CONCLUSION

In conclusion, the development of a Python program with MySQL


connectivity for a Library Management System represents a significant
advancement in the efficient management of library resources. This
project has demonstrated the versatility and power of Python as a
programming language, coupled with the robustness of MySQL
databases. The system provides a user-friendly interface for librarians
and patrons, streamlines the book checkout process, and offers
comprehensive data analysis tools. Overall, this project not only
enhances the operational capabilities of libraries but also enriches the
user experience, ensuring that libraries remain vital resources in the
digital age.

20 | P a g e
BIBLIOGRAPHY

 “Computer Science with Python”, Sumita Arora


 “Python Crash Course, 3rd Edition”, Eric Matthes
 “Python Datetime”, w3schools.com
 “Python and MySQL Database: A Practical Introduction”,
realpython.com
 “Python Random Module”, geeksforgeeks.org

21 | P a g e

You might also like