-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_book.py
More file actions
127 lines (113 loc) · 3.88 KB
/
update_book.py
File metadata and controls
127 lines (113 loc) · 3.88 KB
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
from tkinter import *
from black import out
from connect_db import connect
from tkinter import messagebox
import pymysql
def update_books(home, update_book):
update_book.configure(background="black")
Label(
update_book, text="Update Book", bg="black", fg="white", font=("Courier", 35)
).pack(pady=15)
Label(
update_book, text="Enter Book Id", bg="black", fg="white", font=("Courier", 25)
).pack(pady=5)
id = Text(update_book, height=1, width=30, font=("Courier", 25))
id.pack(pady=5)
update_book.pack(expand=1, fill=X)
Button(
update_book,
text="Submit",
command=lambda: queryby_id(id, update_book),
bg="black",
fg="white",
font=("Courier", 25),
).pack(pady=12)
home.pack_forget()
def detailed_update(update_book, output):
Label(update_book, text="Name", bg="black", fg="white", font=("Courier", 25)).pack(
pady=5
)
name = Text(update_book, height=1, width=30, font=("Courier", 25))
name.pack(pady=5)
Label(
update_book, text="Author", bg="black", fg="white", font=("Courier", 25)
).pack(pady=5)
author = Text(update_book, height=1, width=30, font=("Courier", 25))
author.pack(pady=5)
Label(
update_book, text="Category", bg="black", fg="white", font=("Courier", 25)
).pack(pady=5)
category = Text(update_book, height=1, width=30, font=("Courier", 25))
category.pack(pady=5)
Label(
update_book, text="Total Count", bg="black", fg="white", font=("Courier", 25)
).pack(pady=5)
t_count = Text(update_book, height=1, width=30, font=("Courier", 25))
t_count.pack()
display_details(name, author, category, t_count, output)
Button(
update_book,
text="update",
command=lambda: update_submit(name, author, category, t_count, output),
bg="black",
fg="white",
font=("Courier", 25),
).pack(pady=12)
def queryby_id(id, update_book):
book_id = id.get(1.0, "end-1c")
query = "select * from Books where book_id=" + book_id
try:
result = connect(query)
if len(result) > 0:
output = fetch_detail(result)
detailed_update(update_book, output)
else:
messagebox.showinfo("Error", "Enter valid book_id")
except (pymysql.Error, pymysql.Warning) as e:
err = str(e)
messagebox.showinfo("Error", "Can't add data into Database " + err)
def display_details(name, author, category, t_count, output):
name.insert(INSERT, output[1])
author.insert(INSERT, output[2])
category.insert(INSERT, output[3])
t_count.insert(INSERT, output[4])
def fetch_detail(result):
for row in result:
id = row[0]
name = row[1]
author = row[2]
cat_id = row[3]
t_count = row[4]
avail_count = row[5]
return [id, name, author, cat_id, t_count, avail_count]
def update_submit(name, author, category, t_count, output):
name = name.get(1.0, "end-1c")
author = author.get(1.0, "end-1c")
category = category.get(1.0, "end-1c")
t_count = t_count.get(1.0, "end-1c")
d = int(t_count) - output[4]
avail_count = output[5]
avail_count += d
if d < 0:
messagebox.showinfo("Error", "New count is less than available ")
else:
query = (
"update Books set name='"
+ name
+ "',aut_name='"
+ author
+ "',cat_id="
+ category
+ ",t_count="
+ t_count
+ ",avail_count="
+ str(avail_count)
+ " where book_id="
+ str(output[0])
)
try:
connect(query)
messagebox.showinfo("Success", "Details updated successfully")
except (pymysql.Error, pymysql.Warning) as e:
err = str(e)
messagebox.showinfo("Error", "Can't update the details of book " + err)