-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathBook.py
137 lines (127 loc) · 5.43 KB
/
Book.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#PYTHON MODULE: BOOK
import mysql.connector
from mysql.connector import errorcode
from datetime import date, datetime, timedelta
from mysql.connector import(connection)
import os
import platform
def clrscreen():
if platform.system() == "Windows":
print(os.system("cls"))
def insertData():
try:
cnx = mysql.connector.connect(user='root', password='123', host='localhost', database='Library')
Cursor = cnx.cursor()
bno = input("Enter Book Code : ")
bname = input("Enter Book Name : ")
Auth = input("Enter Book Author's Name : ")
price = int(input("Enter Book Price : "))
publ = input("Enter Publisher of Book : ")
qty = int(input("Enter Quantity purchased : "))
print("Enter Date of Purchase (Date/Month and Year seperately) : ")
DD = int(input("Enter Date : "))
MM = int(input("Enter Month : "))
YY = int(input("Enter Year : "))
Qry = ("INSERT INTO BookRecord VALUES (%s, %s, %s, %s, %s, %s, %s)")
data = (bno, bname, Auth, price, publ, qty, date(YY,MM,DD))
Cursor.execute(Qry,data)
cnx.commit()
Cursor.close()
cnx.close()
print("Record Inserted.")
except mysql.connector.ERROR as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("Something is wrong with your user name or password")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("Database does not exist")
else:
print(err)
cnx.close()
def deleteBook():
try:
cnx = mysql.connector.connect(user='root', password='123', host='localhost', database='Library')
Cursor = cnx.cursor()
bno = input("Enter Book Code of Book to be deleted from the Library : ")
Qry = ("""DELETE FROM BookRecord WHERE BNO = %s""")
del_rec = (bno,)
Cursor .execute(Qry, del_rec)
cnx.commit()
Cursor.close()
cnx.close()
print(Cursor.rowcount, "Record(s) Deleted Successfully.")
except mysql.connector.ERROR as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("Something is wrong with your user name or password")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("Database does not exist")
else:
print(err)
cnx.close()
def SearchBookRec():
try:
cnx = mysql.connector.connect(user='root', password='123', host='localhost', database='Library')
Cursor = cnx.cursor()
bno = input("Enter Book No to be Searched from the Library : ")
query = ("SELECT * FROM BookRecord WHERE BNo = %s ")
rec_srch = (bno,)
Cursor.execute(query, rec_srch)
Rec_count = 0
for(Bno, Bname, Author, price, publ, qty, Date_of_Purchase) in Cursor:
Rec_count += 1
print("=============================================================")
print("Book Code : ", Bno)
print("Book Name : ", Bname)
print("Author of Book : ", Author)
print("Price of Book : ", price)
print("Publisher : ", publ)
print("Total Quantity in Hand : ", qty)
print("Purchased On : ", Date_of_Purchase)
print("=============================================================")
if Rec_count%2 == 0:
input("Press any key continue")
clrscreen()
print(Rec_count, "Record(s) found")
cnx.commit()
Cursor.close()
cnx.close()
except mysql.connector.ERROR as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("Something is wrong with your user name or password")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("Database does not exist")
else:
print(err)
cnx.close()
def UpdateBook():
try:
cnx = mysql.connector.connect(user='root', password='123', host='localhost', database='Library')
Cursor = cnx.cursor()
bno = input("Enter Book Code of Book to be Updated from the Library : ")
query = ("SELECT * FROM BookRecord WHERE BNo = %s ")
rec_srch = (bno,)
print("Enter new data")
bname = input("Enter Book Name : ")
Auth = input("Enter Book Author's Name : ")
price = int(input("Enter Book Price : "))
publ = input("Enter Publisher of Book : ")
qty = int(input("Enter Quantity purchased : "))
print("Enter Date of Purchase (Date/Month and Year seperately) : ")
DD = int(input("Enter Date : "))
MM = int(input("Enter Month : "))
YY = int(input("Enter Year : "))
Date_of_Purchase = date(YY,MM,DD)
Qry = ("UPDATE BookRecord SET bname=%s, Auth=%s, price=%s, publ=%s, qty=%s, Date_of_Purchase=%s WHERE Bno=%s")
data = (bname, Auth, price, publ, qty, Date_of_Purchase, bno)
Cursor.execute(Qry,data)
cnx.commit()
Cursor.close()
cnx.close()
print(Cursor.rowcount, "Record(s) Updated Successfully.")
except mysql.connector.ERROR as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("Something is wrong with your user name or password")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("Database does not exist")
else:
print(err)
cnx.close()