-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReceivebook.py
More file actions
249 lines (226 loc) · 11.2 KB
/
Copy pathReceivebook.py
File metadata and controls
249 lines (226 loc) · 11.2 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
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
import tkinter as tk
from tkinter import *
from tkinter import messagebox as mBox
import pymysql
import Dbcon as Db
from datetime import datetime, date
class RetnApp(tk.Tk):
def __init__(self):
super().__init__()
self.title("RECEIVE BOOK.")
self.geometry("420x360+10+60")
self.configure(bg="gray")
self.resizable(0, 0)
# ====================Variables========================#
isbnno = tk.StringVar
admno = tk.StringVar
dated = tk.StringVar
dated1 = tk.IntVar
fine = tk.StringVar
fineamnt = tk.IntVar
d = datetime(1, 1, 1).now()
# ============================================================Frames=====================================================================
self.MFrame = LabelFrame(self, width=390, height=300, font=('arial', 15, 'bold'), \
bg='lightblue', bd=15, relief='ridge')
self.MFrame.grid(row=0, column=0, padx=10, pady=20)
self.CFrame = LabelFrame(self.MFrame, width=300, height=300, font=('arial', 12, 'bold'), \
relief='ridge', bd=10, bg='lightblue', text='RECEIVE')
self.CFrame.grid(row=1, column=0, padx=10)
self.EFrame = LabelFrame(self,width=200, height=100, font=('arial', 10, 'bold'), \
bg='lightblue', relief='ridge', bd=13)
self.EFrame.grid(row=2, column=0, pady=10)
# ========================================================Labels of CFrame========================================================
self.Lisbnno = Label(self.CFrame, text='ISBN Number:', font=('arial', 10, 'bold'), bg='lightblue')
self.Lisbnno.grid(row=0, column=0, sticky=W, padx=20, pady=10)
self.Ladmno = Label(self.CFrame, text='STUDENT Number:', font=('arial', 10, 'bold'), bg='lightblue')
self.Ladmno.grid(row=1, column=0, sticky=W, padx=20)
self.Ldatedb = Label(self.CFrame, text='DATE BORROWED:', font=('arial', 10, 'bold'), bg='lightblue')
self.Ldatedb.grid(row=2, column=0, sticky=W, padx=20)
self.Ldated = Label(self.CFrame, text='DATE:', font=('arial', 10, 'bold'), bg='lightblue')
self.Ldated.grid(row=3, column=0, sticky=W, padx=20)
self.Lfine = Label(self.CFrame, text='FINE:', font=('arial', 10, 'bold'), bg='lightblue')
self.Lfine.grid(row=4, column=0, sticky=W, padx=20)
# ========================================================Entries of CFrame========================================================
self.Txtisbnno = Entry(self.CFrame, font=('arial', 10, 'bold'), textvariable=isbnno)
self.Txtisbnno.grid(row=0, column=1, padx=10, pady=5)
self.Txtadmno = Entry(self.CFrame, font=('arial', 10, 'bold'), textvariable=admno)
self.Txtadmno.grid(row=1, column=1, padx=10, pady=5)
self.Txtdatedb = Entry(self.CFrame, font=('arial', 10, 'bold'), textvariable=dated1)
self.Txtdatedb.grid(row=2, column=1, padx=10, pady=5)
self.Txtdated = Entry(self.CFrame, font=('arial', 10, 'bold'), textvariable=dated)
self.Txtdated.insert(tk.INSERT, d.strftime('%Y-%m-%d'))
self.Txtdated.grid(row=3, column=1, padx=10, pady=5)
self.Txtfine = Entry(self.CFrame, font=('arial', 10, 'bold'), textvariable=fine)
self.Txtfine.grid(row=4, column=1, padx=10, pady=5)
# ========================================================Buttons of self.EFrame=========================================================
self.btnReturn = Button(self.EFrame, text='RECEIVE', font=('arial', 10, 'bold'), width=8, command=self.retnbks)
self.btnReturn.grid(row=0, column=0, padx=10, pady=10)
self.btnInfo = Button(self.EFrame, text='BOOK INFO', font=('arial', 10, 'bold'), width=9, command=self.searchst)
self.btnInfo.grid(row=0, column=1, padx=10, pady=10)
self.btnGetfine = Button(self.EFrame, text='FINE', font=('arial', 10, 'bold'), width=8, command=self.getfine)
self.btnGetfine.grid(row=0, column=2, padx=10, pady=10)
self.btnExit = Button(self.EFrame, text='EXIT', font=('arial', 10, 'bold'), width=8, command=self.exitt)
self.btnExit.grid(row=0, column=3, padx=10, pady=10)
# ==========Exit Function==========
def exitt(self):
result = mBox.askquestion(self, 'Are you sure you want to exit?', icon="warning")
if result == 'yes':
self.destroy()
# ==========Clear Function==========
def allclear(self):
self.Txtisbnno.delete(0, END)
self.Txtadmno.delete(0, END)
self.Txtdatedb.delete(0, END)
self.Txtfine.delete(0, END)
# ==============Function To Check if borrowed Book with given ISBN Exist or Not==================
def isbnbkck(self, isbnno):
try:
conn = pymysql.connect(**Db.dbConfig)
cursor = conn.cursor()
cursor.execute("select * from borrowbook where isbnno=%s", isbnno)
rowcount = cursor.rowcount
if cursor.rowcount == 1:
return True
else:
return False
cursor.close()
conn.close()
except Exception as es:
print('Error', f"due to :{str(es)}")
# ====================Function To Check if Admission number Exist or Not====================
def admbkck(self, admno):
try:
conn = pymysql.connect(**Db.dbConfig)
cursor = conn.cursor()
cursor.execute("select * from borrowbook where admno=%s", admno)
rowcount = cursor.rowcount
if cursor.rowcount == 1:
return True
else:
return False
cursor.close()
conn.close()
except Exception as es:
print('Error', f"due to :{str(es)}")
# ======Function To Check if borrowed Book ISBN and Admission number match====================
def admretnck(self, admno, isbnno):
try:
conn = pymysql.connect(**Db.dbConfig)
cursor = conn.cursor()
cursor.execute("select * from borrowbook where admno=%s and isbnno=%s", (admno, isbnno))
rowcount = cursor.rowcount
if cursor.rowcount == 1:
return True
else:
return False
cursor.close()
conn.close()
except Exception as es:
print('Error', f"due to :{str(es)}")
# ======Function To Delete ISBN from borrowbook Table After being Returned============
def admretdel(self, isbnno):
try:
conn = pymysql.connect(**Db.dbConfig)
cursor = conn.cursor()
cursor.execute("delete from borrowbook where isbnno=%s", isbnno)
conn.commit()
rowcount = cursor.rowcount
if cursor.rowcount == 1:
return rowcount
cursor.close()
conn.close()
except Exception as es:
print('Error', f"due to :{str(es)}")
# ======Function To Get fine============
def getfine(self):
isbnno = self.Txtisbnno.get()
admno = self.Txtadmno.get()
dated = self.Txtdated.get()
dated1 = self.Txtdatedb.get()
if isbnno == "" or admno == "" or dated == "" or dated1 == "":
mBox.showerror(self, 'Error, Enter ISBN then Click on BOOK INFO')
else:
try:
conn = pymysql.connect(**Db.dbConfig)
cursor = conn.cursor()
cursor.execute("select dated from borrowbook where admno=%s and isbnno=%s", (admno, isbnno))
rowcount = cursor.fetchone()
for row in rowcount:
todayy = datetime.now()
bday = datetime.strptime(self.Txtdatedb.get(), '%Y-%m-%d')
days = (todayy - bday).days
fineamnt = 0,
if days < 5:
self.Txtfine.insert(tk.INSERT, fineamnt)
mBox.showinfo("fine is:", fineamnt)
else:
fineamnt = 5 * days
self.Txtfine.insert(tk.INSERT, fineamnt)
mBox.showinfo("fine is:", fineamnt)
cursor.close()
conn.close()
except Exception as es:
print('Error', f"due to :{str(es)}")
# ======Function To Get book Information============
def searchst(self):
isbnno = self.Txtisbnno.get()
if isbnno == "":
mBox.showerror(self, 'Error Enter ISBN number', )
else:
try:
conn = pymysql.connect(**Db.dbConfig)
cursor = conn.cursor()
cursor.execute("select * from borrowbook where isbnno=%s", isbnno)
rowcount = cursor.fetchall()
for row in rowcount:
self.Txtadmno.insert(tk.INSERT, str(row[1]))
self.Txtdatedb.insert(tk.INSERT, (row[2]))
if cursor.rowcount == 1:
mBox.showinfo("Information", "record found")
else:
mBox.showinfo("Error", "Unable to Search")
self.clear()
cursor.close()
conn.close()
except Exception as es:
print('Error', f"due to :{str(es)}")
# ======Function To Receive Book============
def retnbks(self):
isbnno = self.Txtisbnno.get()
admno = self.Txtadmno.get()
dated = self.Txtdated.get()
dated1 = self.Txtdatedb.get()
fine = self.Txtfine.get()
if isbnno == "" or admno == "" or dated == "" or dated1 == "" or fine == "":
mBox.showerror(self, 'Error Enter ISBN NO,Then click on BOOK INFO ')
else:
try:
conn = pymysql.connect(**Db.dbConfig)
cursor = conn.cursor()
if not RetnApp.isbnbkck(self, isbnno):
mBox.showinfo('Information', "Wrong ISBN Number.")
self.allclear()
else:
if not RetnApp.admretnck(self, admno, isbnno):
mBox.showinfo('Information', "Student No and ISBN No dont match.")
self.allclear()
else:
cursor.execute("Insert into receive( isbnno,admno,dated,dated1,fine)""values(%s,%s,%s,%s,%s)",(isbnno, admno, dated, dated1, fine))
conn.commit()
RetnApp.admretdel(self, isbnno)
if cursor:
mBox.showinfo("Done", "received sucessfully")
ask = mBox.askyesno("Confirm", "Do you want to receive another book?")
if ask:
self.allclear()
else:
self.allclear()
else:
mBox.showerror("Error", "Unable to Receive book")
cursor.close()
conn.close()
except Exception as es:
print('Error', f"due to :{str(es)}")
if __name__ == "__main__":
rtnapp = RetnApp()
rtnapp.mainloop()