-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIssueBook.py
205 lines (157 loc) · 6.15 KB
/
IssueBook.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
from tkinter import *
from PIL import ImageTk,Image
from tkinter import messagebox
import pymysql
# Add your own database name and password here to reflect in the code
mypass = "12345"
mydatabase="library"
con = pymysql.connect(host="localhost",user="root",password=mypass,database=mydatabase)
cur = con.cursor()
# Enter Table Names here
issueTable = "issuedetail" #Issue Table
bookTable = "books" #Book Table
stuTable = "studetail" #Student Table
empTable = "empdetail" #Employee Table
allRoll = [] #List To store all Roll Numbers
allEmpId = [] #List To store all Employee IDs
allBid = [] #List To store all Book IDs
def issue():
global issueBtn,labelFrame,lb1,en1,en2,en3,quitBtn,root,Canvas1,status
bid = en1.get()
issueto = en2.get()
issueby = en3.get()
issueBtn.destroy()
quitBtn.destroy()
labelFrame.destroy()
lb1.destroy()
en1.destroy()
en2.destroy()
en3.destroy()
extractBid = "select bid from "+bookTable
try:
cur.execute(extractBid)
con.commit()
for i in cur:
allBid.append(i[0])
if bid in allBid:
checkAvail = "select status from "+bookTable+" where bid = '"+bid+"'"
cur.execute(checkAvail)
con.commit()
for i in cur:
check = i[0]
if check == 'available':
status = True
else:
status = False
else:
messagebox.showinfo("Error","Book ID not present")
except:
messagebox.showinfo("Error","Can't fetch Book IDs")
extractRollno = "select rollno from "+stuTable
try:
cur.execute(extractRollno)
con.commit()
for i in cur:
allRoll.append(i[0])
if issueto in allRoll:
pass
else:
messagebox.showinfo("Error","Roll No not present")
except:
messagebox.showinfo("Error","Can't fetch Roll No")
extractEmpID = "select empid from "+empTable
try:
cur.execute(extractEmpID)
con.commit()
for i in cur:
allEmpId.append(i[0])
if issueby in allEmpId:
pass
else:
messagebox.showinfo("Error","Emp ID not present")
except:
messagebox.showinfo("Error","Can't fetch Emp IDs")
labelFrame = Frame(root,bg='black')
labelFrame.place(relx=0.1,rely=0.3,relwidth=0.8,relheight=0.5)
y = 0.25
Label(labelFrame, text="%-20s%-30s%-30s"%('BID','Issued To','Issued By'),bg='black',fg='white').place(relx=0.27,rely=0.1)
Label(labelFrame, text="---------------------------------------------------------",bg='black',fg='white').place(relx=0.2,rely=0.2)
issueSql = "insert into "+issueTable+" values ('"+bid+"','"+issueto+"','"+issueby+"')"
show = "select * from "+issueTable
updateStatus = "update "+bookTable+" set status = 'issued' where bid = '"+bid+"'"
try:
if bid in allBid and issueto in allRoll and issueby in allEmpId and status == True:
cur.execute(issueSql)
con.commit()
cur.execute(updateStatus)
con.commit()
else:
allBid.clear()
allEmpId.clear()
allRoll.clear()
return
con.commit()
cur.execute(show)
con.commit()
for i in cur:
Label(labelFrame, text="%-20s%-30s%-30s"%(i[0],i[1],i[2]),bg='black',fg='white').place(relx=0.27,rely=y)
y += 0.1
print(i)
except:
messagebox.showinfo("Search Error","The value entered is wrong, Try again")
print(bid)
print(issueto)
print(issueby)
allBid.clear()
allEmpId.clear()
allRoll.clear()
backBtn = Button(root,text="< Back",bg='#455A64', fg='white', command=issueBook)
backBtn.place(relx=0.53,rely=0.85, relwidth=0.18,relheight=0.08)
def issueBook():
global en1,en2,en3,issueBtn,lb1,labelFrame,quitBtn,Canvas1,root,status
root = Tk()
root.title("Library")
root.minsize(width=400,height=400)
root.geometry("600x500")
same=True
n=0.3
# Adding a background image
background_image =Image.open("library.jpg")
[imageSizeWidth, imageSizeHeight] = background_image.size
newImageSizeWidth = int(imageSizeWidth*n)
if same:
newImageSizeHeight = int(imageSizeHeight*n)
else:
newImageSizeHeight = int(imageSizeHeight/n)
Canvas1 = Canvas(root)
Canvas1.config(bg="#706fd3",width = newImageSizeWidth, height = newImageSizeHeight)
Canvas1.pack(expand=True,fill=BOTH)
labelFrame = Frame(root,bg='black')
labelFrame.place(relx=0.1,rely=0.3,relwidth=0.8,relheight=0.3)
headingFrame1 = Frame(root,bg="#333945",bd=5)
headingFrame1.place(relx=0.25,rely=0.1,relwidth=0.5,relheight=0.13)
headingFrame2 = Frame(headingFrame1,bg="#EAF0F1")
headingFrame2.place(relx=0.01,rely=0.05,relwidth=0.98,relheight=0.9)
headingLabel = Label(headingFrame2, text="ISSUE BOOK", fg='black')
headingLabel.place(relx=0.25,rely=0.15, relwidth=0.5, relheight=0.5)
# Book ID
lb1 = Label(labelFrame,text="Book ID : ", bg='black', fg='white')
lb1.place(relx=0.05,rely=0.2)
en1 = Entry(labelFrame)
en1.place(relx=0.3,rely=0.2, relwidth=0.62)
# Issued To Roll Number
lb2 = Label(labelFrame,text="Issued To(rollno) : ", bg='black', fg='white')
lb2.place(relx=0.05,rely=0.4)
en2 = Entry(labelFrame)
en2.place(relx=0.3,rely=0.4, relwidth=0.62)
# Issued By Employee Number
lb3 = Label(labelFrame,text="Issued By(empid) : ", bg='black', fg='white')
lb3.place(relx=0.05,rely=0.6)
en3 = Entry(labelFrame)
en3.place(relx=0.3,rely=0.6, relwidth=0.62)
#Issue Button
issueBtn = Button(root,text="Issue",bg='#d1ccc0', fg='black',command=issue)
issueBtn.place(relx=0.28,rely=0.75, relwidth=0.18,relheight=0.08)
quitBtn = Button(root,text="Quit",bg='#aaa69d', fg='black', command=root.quit)
quitBtn.place(relx=0.53,rely=0.75, relwidth=0.18,relheight=0.08)
root.mainloop()