-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReturnBook.py
58 lines (54 loc) · 2.74 KB
/
ReturnBook.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
from tkinter import *
from tkinter import messagebox
import os,sys
import mysql.connector
from mysql.connector import Error
from datetime import datetime,date
py = sys.executable
class ret(Tk):
def __init__(self):
super().__init__()
self.iconbitmap(r"import your favicon.ico path")
self.title("Return")
self.maxsize(420,280)
self.canvas = Canvas(width=500, height=417, bg='gray')
l1 = Label(self, text="Return Book", bg='gray', font=("Courier new", 20, 'bold')).place(x=100, y=20)
self.canvas.pack()
self.cal = 0
a = StringVar()
def qui():
if len(a.get()) == '0':
messagebox.showerror("Error","Please Enter The Book Id")
else:
try:
self.conn = mysql.connector.connect(host='localhost',
database='database_name',
user='username',
password='user password')
self.mycursor = self.conn.cursor()
self.mycursor.execute("Select book_id from issue_book where return_date = '' and book_id = %s",[a.get()])
temp = self.mycursor.fetchone()
if temp:
self.mycursor.execute("update book set availability ='YES' where book_id = %s", [a.get()])
self.conn.commit()
now = datetime.now()
idate = now.strftime('%Y-%m-%d %H:%M:%S')
self.mycursor.execute("update issue_book set return_date = %s where book_id = %s", [idate,a.get()])
self.conn.commit()
self.conn.close()
messagebox.showinfo('Info', 'Succesfully Returned')
d = messagebox.askyesno("Confirm", "Return more books?")
if d:
self.destroy()
os.system('%s %s' % (py, 'ReturnBook.py'))
else:
self.destroy()
else:
messagebox.showinfo("Oop's", "Book not yet issued")
except Error:
messagebox.showerror("Error","Something Goes Wrong")
Label(self, text='Return Book', fg='red',font=('arial', 35, 'bold')).pack()
Label(self, text='Enter Book ID', font=('Comic Scan Ms', 15, 'bold')).place(x=20, y=120)
Entry(self, textvariable=a, width=40).place(x=165, y=124)
Button(self, text="Return", width=25, command=qui).place(x=180, y=180)
ret().mainloop()