Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 54

1

CERTIFICATE

TO WHOMSOEVER IT MAY CONCERN

This is to certify that Miss.ADITI BISHT studying in


Class XII SCI has successfully completed project on
“BOOKSTORE” for the A.I.S.S.C.E Informatics
Practices(265_ Practical Examination 2020-2021) under my
supervision and guidance, and has taken interest and shown
utmost sincerity in the completion of this project.
I certify that the programs are up to my expectations and as
per the guidelines issued by CBSE.

Gurpreet Singh Aditi Bisht


(PGT-COMPUTERS) (XII-SCI)

2
DECLARATION

I hereby declare that the project work entitled


“BOOKSTORE”, submitted to Mr.Gurpreet
Singh, PGT- Computer, Pinegrove School,
Subathu, is prepared by me.

ADITI BISHT
XII Science

3
ACKNOWLEDGEMENT

I would like to express a deep sense of gratitude to


my IP teacher Mr.Gurpreet Singh for guiding me
in making the project. His constructive advice and
constant motivation have played a huge role in the
successful completion of this project.I also thank
my classmates for their timely help & support for
completion of the practical file.

ADITI BISHT
XII Science

CONTENTS
4
S.No. Synopsis Component Page No.
01 INTRODUCTION & PROJECT CATEGORY 6

02 MODULE SPECIFICATIONS 7-20

3 SYSTEM SPECIFICATION 21

4 TEXT FILES USED 22-24


4.1 Error.txt 22-23
4.2 About.txt 24

5 WORKING DESCRIPTION 25

6 DATA STRUCTURES 26-28

7 SOURCE CODE 29--41

8 OUTPUT 42-52

9 BIBLIOGRAPHY 53

5
INTRODUCTION & PROJECT LAYOUT
Bookstore Management System is a program
developed, for managing the work of a bookstore,
using Python (Spyder) as frontend and MySQL as
Backend. This program emphasis on storing and
selling books and updating information related to
them. It has a simple and easy user friendly interface
designed for people with minimum computer
knowledge. Python is selected as the language for
development due to its object oriented and open
source nature. Similarly MySQL also attracts lots of
developer because of its simple, friendly and open
source nature. Both MySQL and Python can be
downloaded free of cost from their respective
websites.

6
MODULE FUNCTIONS

#Function 1(Menu)
def MenuSet():
print("Enter 1 : Add Books")
print("Enter 2 : Available Books")
print("Enter 3 : Orders")
print("Enter 4 : Customer Details ")
print("Enter 5 : Database Setup")
try:
userInput = int(input("Please Select An Option : "))
except ValueError:
exit("\n Incorrect input!")
else:
print("\n")
if(userInput == 1):
AddBook()
elif(userInput == 2):
AvailableBooks()
elif(userInput == 3):
Order_Mgmt()
elif(userInput == 4):
CustomerView()
elif(userInput == 5):
db_mgmt()
else:
print("Enter correct choice. . . ")
print("#"*74)
7
print("* * * * * * * * * * WELCOME TO THE PROJECT ON BOOKSTORE * * * * * *
* * * ")
print("* * * * * * * * * * * * * DEVELOPED BY : ADITI BISHT * * * * * * * * * * * ")
print("#"*74)
print("")
MenuSet()
def runAgain():
runAgn = input("\n Do you want to continue Y/n: ")
while(runAgn.lower() == 'y'):
MenuSet()
runAgn = input("\n Do you want to continue Y/n:")
runAgain()

#Function 2(Adding Books)


def AddBook():
sql="Insert into
books(book_id,title,author,publication,genre,price,stock,ISBN,author_id,pub_id)
values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);"
sql1="Insert into author(author,author_id) values(%s,%s); "
sql2="Insert into publication(publication,pub_id) values(%s,%s);"
L=[]
book_id=int(input("Enter Book ID : "))
L.append(book_id)
search="select count(*) from books where book_id=%s;"
val=(book_id,)
mycur.execute(search,val)
for x in mycur:
cnt=x[0]
if cnt==0:
title=str(input("Enter Book Name:"))
L.append(title)
author=str(input("Enter Author Name:"))

8
L.append(author)
publication=str(input("Enter Publication House:"))
L.append(publication)
genre=str(input("Genre:"))
L.append(genre)
price=int(input("Enter the price:"))
L.append(price)
stock=int(input("Enter Quantity:"))
L.append(stock)
ISBN=str(input("Enter ISBN : "))
L.append(ISBN)
author_id=float(input("Enter Author ID:"))
L.append(author_id)
pub_id=float(input("Enter Publisher ID:"))
L.append(pub_id)
cust=(L)
rl=(author,author_id)
r2=(publication,pub_id)
mycur.execute(sql,cust)
mycur.execute(sql1,rl)
mycur.execute(sql2,r2)
mydb.commit()
print("SUCCESSFULLY ADDED!")
else:
stock=int(input("Enter Quantity:"))
L.append(stock)
sql3= "update books set stock=stock+%s where book_id=%s;"
val2=(stock,book_id)
mycur.execute(sql3,val2)
mydb.commit()
print("STOCK SUCCESSFULLY UPDATED!")

9
#Function 3(Available Books)
def AvailableBooks():
print("Select the search criteria:")
print("1.Book ID")
print("2.Title")
print("3.Author")
print("4.Publisher")
print("5.Genre")
print("6.View All")
print("7. Back (Main Menu)")
ch=int(input("Enter the choice:"))
if ch==1:
s=input("Enter Book ID : ")
rl=(s,)
sql="select * from books where book_id=%s"
mycur.execute(sql,rl)
elif ch==2:
s=input("Enter title:")
rl=(s,)
sql="select * from books where title=%s"
mycur.execute(sql,rl)
elif ch==3:
s=input("Enter author:")
rl=(s,)
sql="select * from books where author=%s"
mycur.execute(sql,rl)
elif ch==4:
s=input("Enter Publication:")
rl=(s,)
sql="select * from books where publication=%s"

10
mycur.execute(sql,rl)
elif ch==5:
s=input("Enter genre:")
rl=(s,)
sql="select * from books where genre=%s"
mycur.execute(sql,rl)
elif ch==6:
sql="select * from books"
mycur.execute(sql)
print("The details of the available books are : ")
print("-"*160)
print("Book_Id Title Author Publication Genre
Price Stock ISBN Author_Id Pub_Id")
print("-"*160)
for i in mycur:
print(i[0],"\t",i[1],"\t",i[2],"\t",i[3],"\t",i[4],"\t ",i[5],"\t ",i[6],"\t ",i[7],"\
t",i[8],"\t ",i[9],"\t")
print("-"*160)

#Function 4 (Adding & Listing Orders)


def Order_Mgmt( ):
while True:
print("1. Add Order")
print("2. List Order")
print("3. Back (Main Menu)")
o=int (input("Enter Your Choice :"))
if o==1 :
sql="Insert into
orders(order_id,book_id,cust_id,price,order_date,qty,total) values(%s,%s,%s,%s,
%s,%s,%s)"

11
sql1="Insert into
customers(cust_id,cust_name,address,email_id,ph_no) values(%s,%s,%s,%s,%s)"
L=[]
cust_id=int(input("Enter Customer ID:" ))
L.append(cust_id)
sql3="select count(*) from customers where cust_id=%s;"
val=(cust_id,)
mycur.execute(sql3,val)
for x in mycur:
cnt=x[0]
if cnt !=0 :
now=datetime.datetime.now()
L.append(now)

order_id=now.year+now.month+now.day+now.hour+now.minute+now.second
L.append(order_id)
sql4="select distinct
cust_id,cust_name,address,email_id,ph_no from customers where cust_id= %s;"
val2=(cust_id,)
mycur.execute(sql4,val2)
res=mycur.fetchall()
for x in res:
cust_id=x[0]
L.append(cust_id)
cust_name=x[1]
L.append(cust_name)
print("Name:",x[1])
address=x[2]
L.append(address)
print("Address:",x[2])
email_id=x[3]
L.append(email_id)
print("Email ID:",x[3])

12
ph_no=x[4]
L.append(ph_no)
print("Mobile No.:",x[4])
book_id=int(input("Enter Book ID : "))
L.append(book_id)
sql5="select title,price,stock from books where book_id=%s;"
rl=(book_id,)
mycur.execute(sql5,rl)
res=mycur.fetchall()
for x in res:
title=x[0]
L.append(title)
print("Title:",x[0])
price=x[1]
L.append(price)
print("Price:",x[1])
stock=x[2]
L.append(stock)
print("Stock:",x[2])
qty=int(input("Enter Quantity:"))
if qty <= stock:
L.append(qty)
total=qty*price
L.append(total)
print("TOTAL:",total)
cust=(cust_id,cust_name,address,email_id,ph_no)
r1=(order_id,book_id,cust_id,price,now,qty,total)
sql6="update books set stock=stock-%s where book_id=%s;"
val3=(qty,book_id)
mycur.execute(sql6,val3)
mycur.execute(sql,r1)
mycur.execute(sql1,cust)
mydb.commit()
13
print("ORDER SUCCESSFUL!")
else:
print("Quantity not Available")

else:
now=datetime.datetime.now()
L.append(now)

order_id=now.year+now.month+now.day+now.hour+now.minute+now.second
L.append(order_id)
cust_name=str(input("Enter Customer Name : "))
L.append(cust_name)
address=str(input("Enter Address:"))
L.append(address)
email_id=input("Enter Email ID : ")
L.append(email_id)
ph_no=(input("Enter mobile number : "))
L.append(ph_no)
book_id=int(input("Enter Book ID : "))
L.append(book_id)
sql4="select title,price,stock from books where book_id=%s;"
rl=(book_id,)
mycur.execute(sql4,rl)
res=mycur.fetchall()
for x in res:
title=x[0]
L.append(title)
print("Title:",x[0])
price=x[1]
L.append(price)
print("Price:",x[1])
stock=x[2]
L.append(stock)

14
print("Stock:",x[2])
qty=int(input("Enter Quantity:"))
if qty<=stock:
L.append(qty)
total=qty*price
L.append(total)
print("TOTAL:",total)
cust=(cust_id,cust_name,address,email_id,ph_no)
r1=(order_id,book_id,cust_id,price,now,qty,total)
sql5="update books set stock=stock-%s where book_id=%s;"
val3=(qty,book_id)
mycur.execute(sql,r1)
mycur.execute(sql1,cust)
mycur.execute(sql5,val3)
mydb.commit()
print("ORDER SUCCESSFUL!")
else:
print("Quantity not Available")
elif o==2 :
print("1.Specific Order")
print("2.All Orders")
print("3.Back (Main Menu)")
try:
a=int (input("Enter Your Choice :"))
except ValueError:
exit("\n Incorrect input!")
else:
print("\n")
if a== 1:
s=input("Enter Order_Id:")
rl=(s,)
sql3="select * from orders where order_id=%s"
mycur.execute(sql3,rl)
15
print("The details of the available books are : ")
print("-"*75)
print("Order_Id Book_Id Cust_Id Price Order_Date Qty
Total ")
print("-"*75)
for i in mycur:
print(i[0],"\t ",i[1],"\t ",i[2],"\t ",i[3],"\t",i[4],"\t",i[5],"\t",i[6])
print("-"*75)
elif a==2:
sql4="select * from orders;"
mycur.execute(sql4)
print("The details of the available books are : ")
print("-"*75)
print("Order_Id Book_Id Cust_Id Price Order_Date Qty
Total ")
print("-"*75)
for i in mycur:
print(i[0],"\t ",i[1],"\t ",i[2],"\t ",i[3],"\t",i[4],"\t",i[5],"\t",i[6])
print("-"*75)
elif o== 3 :
break
#Function 5 (Viewing Customers)

def CustomerView():
while True:
print("1.Specific Customer")
print("2.All Customers")
print("3.Back (Main Menu)")
a=int (input("Enter Your Choice :"))
if a== 1:
s=input("Enter Customer ID : ")
rl=(s,)

16
sql="select * from customers where cust_id=%s"
mycur.execute(sql,rl)
print("The details of the customer are : ")
print("-"*155)
print("Cust_Id Cust_Name Ph_No Address
Email_Id Order_Id Month Order_Date ")
print("-"*155)
for i in mycur:
print(i[0],"\t",i[1],"\t",i[5],"\t",i[6],"\t",i[7],"\t",i[8],"\t
",i[10],"\t",i[11],"\t")
elif a==2:
sql1="select * from customers;"
mycur.execute(sql1)
print("The details of the customer are : ")
print("-"*140)
print(" Cust_Id Cust_Name Ph_No Address
Email_Id Order_Id Month Order_Date ")
print("-"*140)
for i in mycur:
print(i[0],"\t",i[1],"\t",i[5],"\t",i[6],"\t",i[7],"\t",i[8],"\t
",i[10],"\t",i[11],"\t")
print("-"*140)
elif a==3:
break

#Function 6 (Database Creation)


def db_mgmt( ):
while True :
print("1.Database creation")
print("2.List Database")
print("3.Back (Main Menu)")
p=int (input("Enter Your Choice :"))
17
if p==1 :
print(" Creating BOOKS table ")
sql = "CREATE TABLE if not exists books (\
Book_Id decimal(10) PRIMARY KEY,\
Title varchar(30) ,\
Author varchar(20) ,\
Publication varchar(20) ,\
Genre varchar(20) ,\
Price double(10,3) ,\
Stock int(10) ,\
ISBN varchar(20) ,\
Author_Id decimal(10) ,\
Pub_Id decimal(10));"
mycur.execute(sql)
print("BOOKS table created")
print("Creating AUTHOR table")
sql="CREATE TABLE if not exists author (\
Author varchar(20) ,\
Author_Id decimal(10) ,\
Stock int(10) ,\
Title varchar(30) ,\
Book_Id decimal(10));"
mycur.execute(sql)
print("AUTHOR table created")
print("Creating PUBLICATION table")
sql="CREATE TABLE if not exists publication (\
Publication varchar(20) ,\
Pub_Id decimal(10) ,\
Stock int(10) ,\
Title varchar(30) ,\
Book_Id decimal(10));"
mycur.execute(sql)
print("PUBLICATION table created")
18
print(" Creating ORDER table")
sql = "CREATE TABLE if not exists orders (\
Order_Id int(4) ,\
Book_Id int(10) ,\
Title varchar(30) ,\
Cust_Id decimal(10) ,\
Price double(10,3) ,\
Order_Date date ,\
Qty int(10) ,\
Total double(10,3) ,\
Cust_Name varchar(30) ,\
Address varchar(30) ,\
Email_Id varchar(30) ,\
Ph_No decimal(10) ,\
Sales_Id int(4) ,\
Month varchar(10));"
mycur.execute(sql)
print("ORDER table created")
print("Creating CUSTOMER table")
sql = "CREATE TABLE if not exists customers (\
Cust_Id decimal(10) ,\
Cust_Name varchar(30) ,\
Book_Id int(10) ,\
Title varchar(30) ,\
Qty int(8) ,\
Ph_No decimal(10) ,\
Address varchar(30) ,\
Email_Id varchar(30) ,\
Order_Id int(4) ,\
Total double(10,3) ,\
Month varchar(10) ,\
Order_Date date ,\
Price double(10,3) ,\
19
Sales_Id int(4));"
mycur.execute(sql)
print("CUSTOMER table created")
if p==2 :
sql="show tables;"
mycur.execute(sql)
for i in mycur:
print(i)
if p== 3 :
break

20
SYSTEM SPECIFICATIONS
HARDWARE
 Windows 10
 RAM 4GB
 Intel Core i3 @3.50GHz
SOFTWARE
 Spyder(Python 3.7)
 MySQL 5.7

21
TEXT FILES USED
1. ERROR.txt
_____________________ExceptionHandling________________

Error handling in Python is done through the use of exceptions that are
caught in try blocks and handled in except blocks. Syntax:
try:
# statement that may raise error
except:
# handle exception here
finally:
# statement that will always run

####Try and Except :


If an error is encountered, a try block code execution is stopped and
transferred
down to the except block. In addition to using an except block after the
try block, you can also use the finally block. The code in the finally block
will be executed regardless of whether an exception occurs.
##Raising an Exception:
You can raise an exception in your own program by using the raise
exception
[,value] statement. Raising an exception breaks current code execution
and returns the exception back until it is handled.
Example:A try block looks like the one below:
try:
print "Hello World"
except:
print "This is an error message!"
22
____________________Some Exceptions______________________

EXCEPTION DESCRIPTION
NAME
Raised when a calculation exceeds maximum
OverflowError()
limit for a numeric type.

Raised when division or modulo by zero takes


ZeroDivisonError()
place for all numeric types.
Raised when there is no input from either the raw
EOFError() input() or input()function and the end of file is
reached.
ImportError() Raised when an import statement fails.

IndexError() Raised when an index is not found in a sequence.

Raised when an identifier is not found in the local


NameError()
or global namespace.
Raised when an input/ output operation fails, such
IOError() as the print statement or the open() function when
trying to open a file that does not exist.
Raised when an operation or function is attempted
TypeError()
that is invalid for the specified data type.
Raised when the built-in function for a data type
ValueError() has the valid type of arguments, but the arguments
have invalid values specified

23
2. ABOUT.txt
This project has been created by Aditi Bisht of class XII
Science under the guidance of Mr. Gurpreet Singh to fulfill
the requirement of the CBSE Senior Secondary
Examination Class XII for Informatics Practices. This
project demonstrates the working of a “Bookstore” with
Python – MySQL connectivity.

24
WORKING DESCRIPTION

The project is aimed to:


 Reduce paper wastage and digitalize a bookstore.

 Reduce time taking adding and ordering processes through


automated query statements.

 Provide user-friendly response to the customer.

 Act as a bill generator by printing orders.

 Offer various queries or transactions through a single portal.

25
Database Structure
The Bookstore database consists of 6 tables. Each and every table is
setup with the required integrity constraints to work properly. The
structure of the database tables is given below:
1.BOOKS

2.AUTHORS
26
3.PUBLICATION

4.ORDERS

5.CUSTOMERS

27
SOURCE CODE
28
import os
import platform
import mysql.connector
import datetime
now=datetime.datetime.now()
from sys import exit
mydb=mysql.connector.connect(host="localhost",user="root",password="compute
r",database="bookstore")
mycur=mydb.cursor()
def AddBook():
sql="Insert into
books(book_id,title,author,publication,genre,price,stock,ISBN,author_id,pub_id)
values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);"
sql1="Insert into author(author,author_id) values(%s,%s); "
sql2="Insert into publication(publication,pub_id) values(%s,%s);"
L=[]
book_id=int(input("Enter Book ID : "))
L.append(book_id)
search="select count(*) from books where book_id=%s;"
val=(book_id,)
mycur.execute(search,val)
for x in mycur:
cnt=x[0]
if cnt==0:
title=str(input("Enter Book Name:"))
L.append(title)
author=str(input("Enter Author Name:"))
L.append(author)
publication=str(input("Enter Publication House:"))
L.append(publication)
genre=str(input("Genre:"))
L.append(genre)
price=int(input("Enter the price:"))
L.append(price)
stock=int(input("Enter Quantity:"))
29
L.append(stock)
ISBN=str(input("Enter ISBN : "))
L.append(ISBN)
author_id=float(input("Enter Author ID:"))
L.append(author_id)
pub_id=float(input("Enter Publisher ID:"))
L.append(pub_id)
cust=(L)
rl=(author,author_id)
r2=(publication,pub_id)
mycur.execute(sql,cust)
mycur.execute(sql1,rl)
mycur.execute(sql2,r2)
mydb.commit()
print("SUCCESSFULLY ADDED!")
else:
stock=int(input("Enter Quantity:"))
L.append(stock)
sql3= "update books set stock=stock+%s where book_id=%s;"
val2=(stock,book_id)
mycur.execute(sql3,val2)
mydb.commit()
print("STOCK SUCCESSFULLY UPDATED!")
def AvailableBooks():
print("Select the search criteria:")
print("1.Book ID")
print("2.Title")
print("3.Author")
print("4.Publisher")
print("5.Genre")
print("6.View All")
print("7. Back (Main Menu)")
ch=int(input("Enter the choice:"))
if ch==1:

30
s=input("Enter Book ID : ")
rl=(s,)
sql="select * from books where book_id=%s"
mycur.execute(sql,rl)
elif ch==2:
s=input("Enter title:")
rl=(s,)
sql="select * from books where title=%s"
mycur.execute(sql,rl)
elif ch==3:
s=input("Enter author:")
rl=(s,)
sql="select * from books where author=%s"
mycur.execute(sql,rl)
elif ch==4:
s=input("Enter Publication:")
rl=(s,)
sql="select * from books where publication=%s"
mycur.execute(sql,rl)
elif ch==5:
s=input("Enter genre:")
rl=(s,)
sql="select * from books where genre=%s"
mycur.execute(sql,rl)
elif ch==6:
sql="select * from books"
mycur.execute(sql)
print("The details of the available books are : ")
print("-"*160)
print("Book_Id Title Author Publication Genre
Price Stock ISBN Author_Id Pub_Id")
print("-"*160)
for i in mycur:
print(i[0],"\t",i[1],"\t",i[2],"\t",i[3],"\t",i[4],"\t ",i[5],"\t ",i[6],"\t ",i[7],"\
t",i[8],"\t ",i[9],"\t")
31
print("-"*160)

def Order_Mgmt( ):
while True:
print("1. Add Order")
print("2. List Order")
print("3. Back (Main Menu)")
o=int (input("Enter Your Choice :"))
if o==1 :
sql="Insert into
orders(order_id,book_id,cust_id,price,order_date,qty,total) values(%s,%s,%s,%s,
%s,%s,%s)"
sql1="Insert into
customers(cust_id,cust_name,address,email_id,ph_no) values(%s,%s,%s,%s,%s)"
L=[]
cust_id=int(input("Enter Customer ID:" ))
L.append(cust_id)
sql3="select count(*) from customers where cust_id=%s;"
val=(cust_id,)
mycur.execute(sql3,val)
for x in mycur:
cnt=x[0]
if cnt !=0 :
now=datetime.datetime.now()
L.append(now)
order_id=now.year+now.month+now.day+now.hour+now.minute+now.second
L.append(order_id)
sql4="select distinct
cust_id,cust_name,address,email_id,ph_no from customers where cust_id= %s;"
val2=(cust_id,)
mycur.execute(sql4,val2)
res=mycur.fetchall()
for x in res:

32
cust_id=x[0]
L.append(cust_id)
cust_name=x[1]
L.append(cust_name)
print("Name:",x[1])
address=x[2]
L.append(address)
print("Address:",x[2])
email_id=x[3]
L.append(email_id)
print("Email ID:",x[3])
ph_no=x[4]
L.append(ph_no)
print("Mobile No.:",x[4])
book_id=int(input("Enter Book ID : "))
L.append(book_id)
sql5="select title,price,stock from books where book_id=%s;"
rl=(book_id,)
mycur.execute(sql5,rl)
res=mycur.fetchall()
for x in res:
title=x[0]
L.append(title)
print("Title:",x[0])
price=x[1]
L.append(price)
print("Price:",x[1])
stock=x[2]
L.append(stock)
print("Stock:",x[2])
qty=int(input("Enter Quantity:"))
if qty <= stock:
L.append(qty)
total=qty*price
L.append(total)
33
print("TOTAL:",total)
cust=(cust_id,cust_name,address,email_id,ph_no)
r1=(order_id,book_id,cust_id,price,now,qty,total)
sql6="update books set stock=stock-%s where book_id=
%s;"
val3=(qty,book_id)
mycur.execute(sql6,val3)
mycur.execute(sql,r1)
mycur.execute(sql1,cust)
mydb.commit()
print("ORDER SUCCESSFUL!")
else:
print("Quantity not Available")
else:
now=datetime.datetime.now()
L.append(now)
order_id=now.year+now.month+now.day+now.hour+now.minute+now.second
L.append(order_id)
cust_name=str(input("Enter Customer Name : "))
L.append(cust_name)
address=str(input("Enter Address:"))
L.append(address)
email_id=input("Enter Email ID : ")
L.append(email_id)
ph_no=(input("Enter mobile number : "))
L.append(ph_no)
book_id=int(input("Enter Book ID : "))
L.append(book_id)
sql4="select title,price,stock from books where book_id=%s;"
rl=(book_id,)
mycur.execute(sql4,rl)
res=mycur.fetchall()
for x in res:

34
title=x[0]
L.append(title)
print("Title:",x[0])
price=x[1]
L.append(price)
print("Price:",x[1])
stock=x[2]
L.append(stock)
print("Stock:",x[2])
qty=int(input("Enter Quantity:"))
if qty<=stock:
L.append(qty)
total=qty*price
L.append(total)
print("TOTAL:",total)
cust=(cust_id,cust_name,address,email_id,ph_no)
r1=(order_id,book_id,cust_id,price,now,qty,total)
sql5="update books set stock=stock-%s where book_id=%s;"
val3=(qty,book_id)
mycur.execute(sql,r1)
mycur.execute(sql1,cust)
mycur.execute(sql5,val3)
mydb.commit()
print("ORDER SUCCESSFUL!")
else:
print("Quantity not Available")
elif o==2 :
print("1.Specific Order")
print("2.All Orders")
print("3.Back (Main Menu)")
try:
a=int (input("Enter Your Choice :"))
except ValueError:
exit("\n Incorrect input!")
else:
35
print("\n")
if a== 1:
s=input("Enter Order_Id:")
rl=(s,)
sql3="select * from orders where order_id=%s"
mycur.execute(sql3,rl)
print("The details of the order are : ")
print("-"*70)
print("Order_Id Book_Id Cust_Id Price Order_Date Qty
Total ")
print("-"*70)
for i in mycur:
print(i[0],"\t ",i[1],"\t ",i[2]," ",i[3]," ",i[4]," ",i[5],"\
t",i[6])
print("-"*70)
elif a==2:
sql4="select * from orders;"
mycur.execute(sql4)
print("The details of the orders are : ")
print("-"*70)
print("Order_Id Book_Id Cust_Id Price Order_Date Qty
Total ")
print("-"*70)
for i in mycur:
print(i[0],"\t ",i[1],"\t ",i[2]," ",i[3]," ",i[4]," ",i[5],"\
t",i[6])
print("-"*70)
elif o== 3 :
break

def CustomerView():
while True:
print("1.Specific Customer")
print("2.All Customers")
print("3.Back (Main Menu)")
36
a=int (input("Enter Your Choice :"))
if a== 1:
s=input("Enter Customer ID : ")
rl=(s,)
sql="select * from customers where cust_id=%s"
mycur.execute(sql,rl)
print("The details of the customer are : ")
print("-"*85)
print("Cust_Id Cust_Name Address Email_Id
Ph_No ")
print("-"*85)
for i in mycur:
print(i[0],"\t",i[1]," ",i[2]," ",i[3]," ",i[4])
print("-"*85)
elif a==2:
sql1="select * from customers;"
mycur.execute(sql1)
print("The details of the customers are : ")
print("-"*85)
print("Cust_Id Cust_Name Address
Email_Id Ph_No ")
print("-"*85)
for i in mycur:
print(i[0],"\t",i[1]," ",i[2]," ",i[3]," ",i[4])
print("-"*85)
elif a==3:
break
def db_mgmt( ):
while True :
print("1.Database creation")
print("2.List Database")
print("3.Back (Main Menu)")
p=int (input("Enter Your Choice :"))
if p==1 :
print(" Creating BOOKS table ")
37
sql = "CREATE TABLE if not exists books (\
Book_Id decimal(10) PRIMARY KEY,\
Title varchar(30) ,\
Author varchar(20) ,\
Publication varchar(20) ,\
Genre varchar(20) ,\
Price double(10,3) ,\
Stock int(10) ,\
ISBN varchar(20) ,\
Author_Id decimal(10) ,\
Pub_Id decimal(10));"
mycur.execute(sql)
print("BOOKS table created")
print("Creating AUTHOR table")
sql="CREATE TABLE if not exists author (\
Author varchar(20) ,\
Author_Id decimal(10) ,\
Stock int(10) ,\
Title varchar(30) ,\
Book_Id decimal(10));"
mycur.execute(sql)
print("AUTHOR table created")
print("Creating PUBLICATION table")
sql="CREATE TABLE if not exists publication (\
Publication varchar(20) ,\
Pub_Id decimal(10) ,\
Stock int(10) ,\
Title varchar(30) ,\
Book_Id decimal(10));"
mycur.execute(sql)
print("PUBLICATION table created")
print(" Creating ORDER table")
sql = "CREATE TABLE if not exists orders (\
Order_Id int(4) ,\
Book_Id int(10) ,\
38
Title varchar(30) ,\
Cust_Id decimal(10) ,\
Price double(10,3) ,\
Order_Date date ,\
Qty int(10) ,\
Total double(10,3) ,\
Cust_Name varchar(30) ,\
Address varchar(30) ,\
Email_Id varchar(30) ,\
Ph_No decimal(10) ,\
Sales_Id int(4) ,\
Month varchar(10));"
mycur.execute(sql)
print("ORDER table created")
print("Creating CUSTOMER table")
sql = "CREATE TABLE if not exists customers (\
Cust_Id decimal(10) ,\
Cust_Name varchar(30) ,\
Book_Id int(10) ,\
Title varchar(30) ,\
Qty int(8) ,\
Ph_No decimal(10) ,\
Address varchar(30) ,\
Email_Id varchar(30) ,\
Order_Id int(4) ,\
Total double(10,3) ,\
Month varchar(10) ,\
Order_Date date ,\
Price double(10,3) ,\
Sales_Id int(4));"
mycur.execute(sql)
print("CUSTOMER table created")
if p==2 :
sql="show tables;"
mycur.execute(sql)
39
for i in mycur:
print(i)
if p== 3 :
break
def MenuSet():
print("Enter 1 : Add Books")
print("Enter 2 : Available Books")
print("Enter 3 : Orders")
print("Enter 4 : Customer Details ")
print("Enter 5 : Database Setup")
try:
userInput = int(input("Please Select An Option : "))
except ValueError:
exit("\n Incorrect input!")
else:
print("\n")
if(userInput == 1):
AddBook()
elif(userInput == 2):
AvailableBooks()
elif(userInput == 3):
Order_Mgmt()
elif(userInput == 4):
CustomerView()
elif(userInput == 5):
db_mgmt()
else:
print("Enter correct choice. . . ")
print("#"*74)
print("* * * * * * * * * * WELCOME TO THE PROJECT ON BOOKSTORE * *
* * * * * * * ")
print("* * * * * * * * * * * * * DEVELOPED BY : ADITI BISHT * * * * * * * *
* * * ")
print("#"*74)

40
print("")
MenuSet()
def runAgain():
runAgn = input("\n Do you want to continue Y/n: ")
while(runAgn.lower() == 'y'):
MenuSet()
runAgn = input("\n Do you want to continue Y/n:")
runAgain()

OUTPUT
1.ADDING BOOKS

41
42
2.UPDATING STOCK

43
3.AVAILABLE BOOKS

44
45
4.ADDING ORDERS

46
5.LISTING ORDERS

47
48
6.CUSTOMER DETAILS

7.DATABASE CREATION
49
1.BOOKS TABLE

50
2.AUTHOR TABLE

3. PUBLICATION TABLE

4.ORDERS TABLE

51
5.CUSTOMERS TABLE

52
BIBLIOGRAPHY
1.Informatics Practices by Sumita Arora
2.www.python.com

53
THANK
YOU

54

You might also like