-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIssueBook.py
77 lines (69 loc) · 3.5 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
from datetime import date, datetime
from tkinter import *
from tkinter import messagebox
import mysql.connector
from mysql.connector import Error
import os
import sys
py = sys.executable
# creating window
class issue(Tk):
def __init__(self):
super().__init__()
self.iconbitmap(r"import your favicon.ico path")
self.title('Library Admisintration')
self.maxsize(440, 300)
self.canvas = Canvas(width=1366, height=768, bg='gray')
self.canvas.pack()
c = StringVar()
d = StringVar()
# verifying input
def isb():
if (len(c.get())) == 0:
messagebox.showinfo('Error', 'Empty field!')
elif (len(d.get())) == 0:
messagebox.showinfo('Error', 'Empty field!')
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 availability from book where availability = 'YES' and book_id = %s",
[c.get()])
self.pc = self.mycursor.fetchall()
try:
if self.pc:
print("success")
book = c.get()
stud = d.get()
now = datetime.now()
idate = now.strftime('%Y-%m-%d %H:%M:%S')
self.mycursor.execute(
"Insert into issue_book(book_id,stud_id,issue_date,return_date) values (%s,%s,%s,%s)",
[book, stud, idate, ''])
self.conn.commit()
self.mycursor.execute("Update book set availability = 'NO' where book_id = %s", [book])
self.conn.commit()
messagebox.showinfo("Success", "Successfully Issue!")
ask = messagebox.askyesno("Confirm", "Do you want to add another?")
if ask:
self.destroy()
os.system('%s %s' % (py, 'IssueBook.py'))
else:
self.destroy()
else:
messagebox.showinfo("Oop's", "Book id " + c.get() + " is not available")
except Error:
messagebox.showerror("Error", "Check The Details")
except Error:
messagebox.showerror("Error", "Something goes wrong")
# label and input box
Label(self, text='Book Issuing', bg='gray', font=('Courier new', 24)).place(x=135, y=40)
Label(self, text='Book ID:', bg='gray', font=('Courier new', 15), fg='black').place(x=55, y=100)
Entry(self, textvariable=c, width=40).place(x=160, y=106)
Label(self, text='Student ID:', bg='gray', font=('Courier new', 15), fg='black').place(x=20, y=150)
Entry(self, textvariable=d, width=40).place(x=160, y=158)
Button(self, text="ISSUE", width=20, command=isb).place(x=200, y=200)
issue().mainloop()