0% found this document useful (0 votes)
3 views26 pages

Library Management

Project

Uploaded by

rohit792403
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)
3 views26 pages

Library Management

Project

Uploaded by

rohit792403
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/ 26

*************************************************************************************

LIBRARY MANAGEMENT
CREATING LIBRARY DATABASE
mysql> create database library;
Query OK, 1 row affected (0.02 sec)

mysql> use library;


Database changed

TABLES IN LIBRARY DATABASE


CREATING BOOK TABLE:
mysql> create table book(
->bno integer(6) primary key,
->bname char(30) not null,
->auth char(30),
->pub char(10),
->price integer(5),
->avail integer(1));
Query OK, 0 rows affected (0.13 sec)
RECORDS IN BOOK TABLE:
mysql> insert into book values(101,'Programming Python','mks','kvs',250,1);
Query OK, 1 row affected (0.03 sec)
mysql> insert into book values(102,'CS with C++','mks','kvs',350,1);
Query OK, 1 row affected (0.03 sec)
mysql> insert into book values(103,'Programming with C','mks','kvs',450,1);
Query OK, 1 row affected (0.03 sec)
mysql> insert into book values(104,'Skill with People','Del carnegi','Manjul',180,1);
Query OK, 1 row affected (0.03 sec)
mysql> insert into book values(105,'Nutrition Science','Ray D Strend','Manjul',280,1);
Query OK, 1 row affected (0.03 sec)

=====================================================================================
*************************************************************************************

CREATING STUDENT TABLE:


mysql> Create table Student(

->adno integer(6) primary key,

->name char(30) not null,

->class char(10),

->nob integer(1),

->fine integer(4));

Query OK, 0 rows affected (0.06 sec)

RECORDS IN BOOK TABLE:


mysql> insert into student values(1001,'Manoj Chaudhary','xiib',0,0);

Query OK, 1 row affected (0.03 sec)

mysql> insert into student values(1002,'Anuj Chaudhary','xiib',0,0);

Query OK, 1 row affected (0.03 sec)

mysql> insert into student values(1003,'Anubhav Pandey','xiib',0,0);

Query OK, 1 row affected (0.05 sec)

mysql> insert into student values(1004,'Abhinav Pandey','xiia',0,0);

Query OK, 1 row affected (0.03 sec)

mysql> insert into student values(1005,'Prashant Kumar','xiia',0,0);

Query OK, 1 row affected (0.03 sec)

=====================================================================================
*************************************************************************************

CREATING ISSUE TABLE:


mysql> create table issue(
mysql> create table issue(

->adno integer(6) references student(adno),

->bno integer(6) references book(bno),

->doi date,

->dor date,

->retr integer(1));

Query OK, 0 rows affected (0.06 sec)

RECORDS IN ISSUE TABLE:

=====================================================================================
*************************************************************************************

PROGRAM

'''=========== Our School Library========='''


importdatetime as dt

importmysql.connector as sqltor

FUNCTION DEFINITIONS:
defbook_issue(): # FOR BOOK ISSUE

print("=====Book Issue=====")

adn=int(input("Admission Number:"))

bn=int(input("Book Number:"))

st1="select * from student where adno={}".format(adn)

cursor.execute(st1)

data=cursor.fetchone()

if not data:

print("invalid Admission number")

else:

if data[3]>=2:

print("No more books can be issued!!")

else:

st2="select * from book where bno={}".format(bn)

cursor.execute(st2)

data1=cursor.fetchone()

if not data1:

print("Invalid Book Number!!!")

else:

if data1[5]==0:

print("Book can Not be issued!!")

=====================================================================================
*************************************************************************************

else:

date1=dt.date.today()

st3="insert into issue(adno,bno,doi,retr) values({},{},'{}',{})".format(adn,bn,date1,0)

cursor.execute(st3)

st4="update student set nob=1 where adno={}".format(adn)

cursor.execute(st4)

st5="update book set avail=0 where bno={}".format(bn)

cursor.execute(st5)

mycon.commit()

print("Book No:{} is issued to admission no:{}".format(adn,bn))

defbook_return(): #FOR BOOK RETURN

print("=====Book Return=====")

adn=int(input("Admission Number:"))

bn=int(input("Book Number:"))

st="select * from issue where adno={} and bno={}".format(adn,bn)

cursor.execute(st)

data=cursor.fetchone()

if data[4]==0:

date1=dt.date.today()

st1="update issue set dor='{}',retr=1 where adno={} and bno={} and retr={}".format(date1,adn,bn,0)

cursor.execute(st1)

st2="update student set nob=nob-1 where adno={}".format(adn)

cursor.execute(st2)

st3="update book set avail=1 where bno={}".format(bn)

cursor.execute(st3)

mycon.commit()

=====================================================================================
*************************************************************************************

print("Book is returned successfully!!")

else:

print("Book can not be returned!!!")

def defaulter(): #TO DISPLAY LIST OF DEFAULTERS

print("============LIST OF DEFAULTER=============")

st="select * from issue where retr=0"

cursor.execute(st)

data=cursor.fetchall()

date1=dt.date.today()

print("===========================================")

print("adno name claqssbooknobnameno_of_book")

print("===========================================")

for row in data:

date2=row[2]

ddiff=date1-date2

ifddiff.days>10:

st1="select * from student where adno={}".format(row[0])

cursor.execute(st1)

row1=cursor.fetchone()

st2="select * from book where bno={}".format(row[1])

cursor.execute(st2)

row2=cursor.fetchone()

print(row[0],row1[1],row1[2],row[1],row2[1],row1[3])

print("===========================================")

=====================================================================================
*************************************************************************************

defissue_list(): # TO DISPLAY CONTENT ISSUED TABLE

st="select * from issue where retr=0"

cursor.execute(st)

data=cursor.fetchall()

print("List of Issue Books")

print("-----------------------------")

print("Adnobnodt_issuedt_return")

print("==============================")

for row in data:

print(row)

print("==============================")

defclear_issue(): # TO REMOVE THE CONTENT OF ISSUE TABLE AFTER RETURNING BOOKS

st="delete from issue where retr=1"

cursor.execute(st)

mycon.commit()

defstudent_entry(): # TO ADD NEW STUDENTS DATA

print("Enter New Student Details:")

print("----------------------")

admno=int(input("Admission Number:"))

name=input("Student Name:")

clas=input("Class&Section[in Roman]:")

st="insert into student values({},'{}','{}',{},{})".format(admno,name,clas,0,0)

cursor.execute(st)

mycon.commit()

=====================================================================================
*************************************************************************************

defstudent_tc(): #TO REMOVE STUDENT DATA IF NO DUES

print("Enter the details of student got TC")

admno=int(input("Admission Number:"))

st1="select * from issue where adno={} and retr={}".format(admno,0)

cursor.execute(st1)

data=cursor.fetchall()

if data:

print("TC cant be issued!!")

print("Please return the book issued to you!!")

else:

st2="delete from student where adno={}".format(admno)

cursor.execute(st2)

st3="delete from issue where adno={}".format(admno)

mycon.commit()

defstudent_search(): # TO SEARCH STUDENT DATA WHETHER BOOK CAN BE ISSUED

print("Enter admn no. to check number of issue books")

admno=int(input("Admission Number:"))

st="select * from student where adno={}".format(admno)

cursor.execute(st)

data=cursor.fetchone()

if data:

print("adno name class no_books fine")

print(data)

if data[3]<2:

print("Books can be issued!!")

else:

print("No more Book can be issued!!")

else:

=====================================================================================
*************************************************************************************

print("Invalid Admission Number!")

defstudent_update(): # TO MODIFY STUDENT DATA

print("Enter admn no. to Modify Student Data")

admno=int(input("Admission Number:"))

st="select * from student where adno={}".format(admno)

cursor.execute(st)

data=cursor.fetchone()

print("adno name class no_books fine")

print(data)

print("Enter new Details!!")

name=input("Student Name:")

clas=input("Class&Section[in Roman]:")

nob=int(input("Number of Books Issued:"))

fine=int(input("Fine imposed:"))

st="update student set name='{}',class='{}',nob={},fine={} where


adno={}".format(name,clas,nob,fine,admno)

cursor.execute(st)

print("Student data Updated Successfully!!")

mycon.commit()

defbook_entry(): # TO ADD NEW BOOK DATA

print("Enter New Book Details:")

print("----------------------")

bn=int(input("Book Number:"))

name=input("book Name:")

auth=input("Author:")

=====================================================================================
*************************************************************************************

pub=input("publication:")

price=int(input("Price:"))

avail=1

st="insert into book values({},'{}','{}','{}',{},{})".format(bn,name,auth,pub,price,1)

cursor.execute(st)

mycon.commit()

defbook_delete(): # TO REMOVE BO0K DATA

print("Enter the details of student got TC")

bn=int(input("Book Number to delete:"))

st1="select * from issue where bno={} and retr={}".format(bn,1)

cursor.execute(st1)

data=cursor.fetchall()

if data==():

print("Book is Not Available!!")

else:

st2="delete from book where bno={}".format(bn)

cursor.execute(st2)

mycon.commit()

print("Book is removed Successfully!!")

defbook_search(): # TO SEARCH BOOK DETAILS WHETHER IT CAN BE ISSUED

print("Enter Book no. to Search")

bn=int(input("Book Number:"))

st="select * from book where bno={}".format(bn)

cursor.execute(st)

data=cursor.fetchone()

print("bnobname author Publisher Price Available")

print("---------------------------------------------")

=====================================================================================
*************************************************************************************

print(data)

print("---------------------------------------------")

defbook_update(): # TO MODIFY BOOK DETAILS EXCEPT BOOK NUMBER

print("Enter Book no. to Modify Book Details")

bn=int(input("Book Number:"))

st="select * from book where bno={}".format(bn)

cursor.execute(st)

data=cursor.fetchone()

print("bnobname author Publisher Price Available")

print(data)

print("Enter new Details!!")

name=input("Book Name:")

auth=input("Author:")

pub=input("Publication:")

price=int(input("Price of Book:"))

avail=int(input("Available[1:Available,0:Not Available]:"))

st="update book set bname='{}',auth='{}',pub='{}',price={},avail={} where


bno={}".format(name,auth,pub,price,avail,bn)

cursor.execute(st)

print("Book data Updated Successfully!!")

mycon.commit()

defavailable_book(): # TO DISPLAY LIST OF AVAILABLE BOOKS WHICH CAN BE ISSUED

St="select * from book where avail={}".format(1)

cursor.execute(st)

data=cursor.fetchall()

print("bnobname author Publisher Price Available")

print("---------------------------------------------")

=====================================================================================
*************************************************************************************

for row in data:

print(row)

print("---------------------------------------------")

def menu(): #MAIN MENU

print("=========MAIN MENU=========")

print("1:ISSUE BOOK")

print("2:RETURN BOOK")

print("3:DEFAULTER LIST")

print("4:LIST OF ISSUED BOOKS")

print("5:CLEAR BOOK ISSUE")

print("6:STUDENT MENU")

print("7:BOOK MENU")

print("OTHER : EXIT")

=====================================================================================
*************************************************************************************

# ==========================MAIN PROGRAM=======================
mycon=sqltor.connect(host="localhost",user="root",password="admin",database="library")

ifmycon.is_connected()==False:

print("Error connecting to mysqldatabse")

cursor=mycon.cursor()

while(True):

menu()

opt=int(input("Choose Option:"))

if opt==1:

book_issue()

elif opt==2:

book_return()

elif opt==3:

defaulter()

elif opt==4:

issue_list()

elif opt==5:

clear_issue()

elif opt==6:

print("1: New Student Entry")

print("2: Student TC")

print("3: Search Student")

print("4: Update Student Details")

op=int(input("Enter Your Choice"))

if op==1:

student_entry()

elif op==2:

student_tc()

=====================================================================================
*************************************************************************************

elif op==3:

student_search()

elif op==4:

student_update()

elif opt==7:

print("1: New Book Entry")

print("2: Remove Book")

print("3: Search Book")

print("4: Update Book Details")

op=int(input("Enter Your Choice"))

if op==1:

book_entry()

elif op==2:

book_delete()

elif op==3:

book_search()

elif op==4:

book_update()

elif op==5:

available_book()

else:

print("Good Bye!!!")

break

=====================================================================================
*************************************************************************************

PROGRAM EXECUTION
=========MAIN MENU=========
1:ISSUE BOOK
2:RETURN BOOK
3:DEFAULTER LIST
4:LIST OF ISSUED BOOKS
5:CLEAR BOOK ISSUE
6:STUDENT MENU
7:BOOK MENU
OTHER : EXIT
Choose Option:1
=====Book Issue=====
Admission Number:1001
Book Number:101
Book No:1001 is issued to admission no:101
CONTENT OF ISSUE, STUDENT AND BOO AFTER ISSUE

=====================================================================================
*************************************************************************************

=========MAIN MENU=========
1:ISSUE BOOK
2:RETURN BOOK
3:DEFAULTER LIST
4:LIST OF ISSUED BOOKS
5:CLEAR BOOK ISSUE
6:STUDENT MENU
7:BOOK MENU
OTHER : EXIT
Choose Option:4
List of Issue Books
-----------------------------
Adnobnodt_issuedt_return
==============================
(1001, 101, datetime.date(2020, 1, 28), None, 0)
==============================
CONTENT OF ISSUE, STUDENT AND BOO AFTER RETURNING BOOK

=====================================================================================
*************************************************************************************

=========MAIN MENU=========

1:ISSUE BOOK

2:RETURN BOOK

3:DEFAULTER LIST

4:LIST OF ISSUED BOOKS

5:CLEAR BOOK ISSUE

6:STUDENT MENU

7:BOOK MENU

OTHER : EXIT

Choose Option:3

============LIST OF DEFAULTER=============

===========================================

adno name claqssbooknobnameno_of_book

===========================================

===========================================

=========MAIN MENU=========

1:ISSUE BOOK

2:RETURN BOOK

3:DEFAULTER LIST

4:LIST OF ISSUED BOOKS

5:CLEAR BOOK ISSUE

6:STUDENT MENU

7:BOOK MENU

OTHER : EXIT

Choose Option:5

=====================================================================================
*************************************************************************************

=========MAIN MENU=========

1:ISSUE BOOK #NEW STUDENT ENTRY

2:RETURN BOOK

3:DEFAULTER LIST

4:LIST OF ISSUED BOOKS

5:CLEAR BOOK ISSUE

6:STUDENT MENU

7:BOOK MENU

OTHER : EXIT

Choose Option:6

1: New Student Entry

2: Student TC

3: Search Student

4: Update Student Details

Enter Your Choice1

Enter New Student Details:

----------------------

Admission Number:1006

Student Name:Mohit

Class&Section[in Roman]:xiia

=====================================================================================
*************************************************************************************

=========MAIN MENU========= #REMOVE STUDENT DATA

1:ISSUE BOOK

2:RETURN BOOK

3:DEFAULTER LIST

4:LIST OF ISSUED BOOKS

5:CLEAR BOOK ISSUE

6:STUDENT MENU

7:BOOK MENU

OTHER : EXIT

Choose Option:6

1: New Student Entry

2: Student TC

3: Search Student

4: Update Student Details

Enter Your Choice2

Enter the details of student got TC

Admission Number:105

=====================================================================================
*************************************************************************************

=========MAIN MENU========= #SEARCH STUDENT TO CHECK FOR ISSUE

1:ISSUE BOOK

2:RETURN BOOK

3:DEFAULTER LIST

4:LIST OF ISSUED BOOKS

5:CLEAR BOOK ISSUE

6:STUDENT MENU

7:BOOK MENU

OTHER : EXIT

Choose Option:6

1: New Student Entry

2: Student TC

3: Search Student

4: Update Student Details

Enter Your Choice3

Enter admn no. to check number of issue books

Admission Number:1002

adno name class no_books fine

(1002, 'Anuj Chaudhary', 'xiib', 0, 0)

Books can be issued!!

=====================================================================================
*************************************************************************************

=========MAIN MENU========= #UPDATE STUDENT DETAILS

1:ISSUE BOOK

2:RETURN BOOK

3:DEFAULTER LIST

4:LIST OF ISSUED BOOKS

5:CLEAR BOOK ISSUE

6:STUDENT MENU

7:BOOK MENU

OTHER : EXIT

Choose Option:6

1: New Student Entry

2: Student TC

3: Search Student

4: Update Student Details

Enter Your Choice4

Enter admn no. to Modify Student Data

Admission Number:1004

adno name class no_books fine

(1004, 'Abhinav Pandey', 'xiia', 0, 0)

Enter new Details!!

Student Name:Abhinav

Class&Section[in Roman]:xiib

Number of Books Issued:0

Fine imposed:0

Student data Updated Successfully!!

=====================================================================================
*************************************************************************************

=========MAIN MENU=========#ADD NEW BOOK

1:ISSUE BOOK

2:RETURN BOOK

3:DEFAULTER LIST

4:LIST OF ISSUED BOOKS

5:CLEAR BOOK ISSUE

6:STUDENT MENU

7:BOOK MENU

OTHER : EXIT

Choose Option:7

1: New Book Entry

2: Remove Book

3: Search Book

4: Update Book Details

Enter Your Choice1

Enter New Book Details:

----------------------

Book Number:106

bookName:Skill with Python

Author:mks

publication:kvs

Price:210

=====================================================================================
*************************************************************************************

=========MAIN MENU=========#REMOVE BOOK

1:ISSUE BOOK

2:RETURN BOOK

3:DEFAULTER LIST

4:LIST OF ISSUED BOOKS

5:CLEAR BOOK ISSUE

6:STUDENT MENU

7:BOOK MENU

OTHER : EXIT

Choose Option:7

1: New Book Entry

2: Remove Book

3: Search Book

4: Update Book Details

Enter Your Choice2

Enter the details of student got TC

Book Number to delete:103

Book is removed Successfully!!

=====================================================================================
*************************************************************************************

=========MAIN MENU=========# SEARCH A BOOK FOR AVAILABILITY

1:ISSUE BOOK

2:RETURN BOOK

3:DEFAULTER LIST

4:LIST OF ISSUED BOOKS

5:CLEAR BOOK ISSUE

6:STUDENT MENU

7:BOOK MENU

OTHER : EXIT

Choose Option:7

1: New Book Entry

2: Remove Book

3: Search Book

4: Update Book Details

Enter Your Choice3

Enter Book no. to Search

Book Number:102

bnobname author Publisher Price Available

---------------------------------------------

(102, 'CS with C++', 'mks', 'kvs', 350, 1)

---------------------------------------------

=====================================================================================
*************************************************************************************

=========MAIN MENU========= #UPDATE BOOK DETAILS

1:ISSUE BOOK

2:RETURN BOOK

3:DEFAULTER LIST

4:LIST OF ISSUED BOOKS

5:CLEAR BOOK ISSUE

6:STUDENT MENU

7:BOOK MENU

OTHER : EXIT

Choose Option:7

1: New Book Entry

2: Remove Book

3: Search Book

4: Update Book Details

Enter Your Choice4

Enter Book no. to Modify Book Details

Book Number:102

bnobname author Publisher Price Available

(102, 'CS with C++', 'mks', 'kvs', 350, 1)

Enter new Details!!

Book Name:C++

Author:mks

Publication:kvs

Price of Book:100

Available[1:Available,0:Not Available]:1

Book data Updated Successfully!!

=====================================================================================
*************************************************************************************

FINALLY THE CONTENT OF ALL TABLES

********************

=====================================================================================

You might also like