-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEntry_Management.py
243 lines (202 loc) · 9.12 KB
/
Entry_Management.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
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
from twilio.rest import Client
import mysql.connector
import tkinter as tk
import smtplib
import tkinter.messagebox
from PIL import ImageTk, Image
import os
from config import GmailID, password, acc_ID, aut_token, number, username, sqlpass
BASE_DIR = os.getcwd()
##Popup message when user's information has been stored during check-in time!!
def popup1():
tk.messagebox.showinfo("SAVED", "Your information has been stored!")
##Popup Message when user has been sucessfully checked out
def popup2():
tk.messagebox.showinfo("Checked-Out", "You have been successfully checked out!")
##Popup Message when user enter invalid details!!
def popup3():
tk.messagebox.showerror("Error","Please enter valid details!")
##Popup Message when the same user check's in again without check-out
def popup4():
tk.messagebox.showerror("Error","You haven't checked out yet!")
#Function To store user data in Mysql database
def save_query(name1, mail1, phone1, name2, mail2, phone2):
cursor1 = mydb.cursor()
sql = "INSERT INTO INFORMATION (Vis_Name, Vis_mail, Vis_phone, Host_name, Host_phone,Host_email) VALUES(%s, %s, " \
"%s, %s, %s, %s) "
Val = (name1, mail1, phone1, name2, phone2, mail2)
cursor1.execute(sql, Val)
mydb.commit()
#Function to send Emails using smtp
def send_email(mail1, name, mail2, number):
server = smtplib.SMTP('smtp.gmail.com:587')
server.ehlo()
server.starttls()
server.login(GmailID, password)
msg = name + " is coming to meet you and visitor's Contact Number is " + number
server.sendmail(mail1, mail2, msg)
#Function to Send Mail to visitor after check out
def send_email_checkout(mail1):
server = smtplib.SMTP('smtp.gmail.com:587')
server.ehlo()
server.starttls()
server.login(GmailID, password)
msg = "Here are the details of your meeting.\n"
cursor3 = mydb.cursor()
sql = "SELECT Vis_Name FROM INFORMATION WHERE Vis_mail=%s"
cursor3.execute(sql, (mail1,))
name = ""
for i in cursor3:
name = str(i[0])
sql = "SELECT Vis_phone FROM INFORMATION WHERE Vis_mail=%s"
cursor3.execute(sql, (mail1,))
phone = ""
for i in cursor3:
phone = str(i[0])
sql = "SELECT Check_in FROM INFORMATION WHERE Vis_mail=%s"
cursor3.execute(sql, (mail1,))
cintime = ""
for i in cursor3:
cintime = str(i[0])
sql = "SELECT Check_out FROM INFORMATION WHERE Vis_mail=%s"
cursor3.execute(sql, (mail1,))
couttime = ""
for i in cursor3:
#print(i[0])
couttime = str(i[0])
sql = "SELECT Host_Name FROM INFORMATION WHERE Vis_mail=%s"
cursor3.execute(sql, (mail1,))
hname = ""
for i in cursor3:
hname = str(i[0])
sql = "SELECT Host_email FROM INFORMATION WHERE Vis_mail=%s"
cursor3.execute(sql, (mail1,))
mail2 = ""
for i in cursor3:
mail2 = str(i[0])
details = "Name: " + name + "\nPhone No.: " + phone + "\nCheck-In Time: " + cintime + "\nCheck-Out Time: " + couttime + "\nHost Name: " + hname + "\nAdress: Innovaccer Office"
#print(details)
msg += details
#print(msg)
server.sendmail(mail2 ,mail1, msg)
##Function to take in user data and check wether entered data is valid or not
def get_data(a, b, c, d, e, f):
Name_vis = a.get()
Mail_vis = b.get()
Phone_vis = c.get()
Name_host = d.get()
Mail_host = e.get()
Phone_host = f.get()
try:
#send_sms(Phone_host, Name_vis, Phone_vis)
send_email(Mail_vis, Name_vis, Mail_host, Phone_vis)
save_query(Name_vis, Mail_vis, Phone_vis, Name_host, Mail_host, Phone_host)
popup1()
except:
popup3()
##Function to sand SMS using Twilio
def send_sms(number2, name, number1):
# Your Account SID from twilio.com/console
account_sid = str(acc_ID)
# Your Auth Token from twilio.com/console
auth_token = str(aut_token)
client = Client(account_sid, auth_token)
message = client.messages.create(
to="+91" + str(number2),
from_=str(number),
body=name + " is coming to meet you and visitor's Contact Number is " + number1)
##Function to gather the visitor that haven't checked out yet and update his checkout time
def check_out(mk):
cursor2 = mydb.cursor()
val = mk.get()
sql = "UPDATE INFORMATION SET Check_out=NOW() WHERE Vis_mail=%s and Check_out is NULL"
cursor2.execute(sql, (val,))
mydb.commit()
try:
send_email_checkout(val)
popup2()
except:
popup3()
mydb = mysql.connector.connect(host="localhost", user=str(username), passwd=str(sqlpass))
cursor = mydb.cursor()
try:
cursor.execute("CREATE DATABASE entry_info")
cursor.execute("USE entry_info")
cursor.execute("CREATE TABLE INFORMATION (Vis_Name varchar(255),Vis_mail varchar(255),Vis_phone varchar(255),"
"Check_in TIMESTAMP DEFAULT CURRENT_TIMESTAMP, Check_out TIMESTAMP, Host_name varchar(255),"
"Host_phone varchar(255),Host_email "
"varchar(255))")
except:
cursor.execute("USE entry_info")
###GUI BEGINS!!
class EntryManger(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
self.geometry('500x500')
#self.iconphoto(tk.PhotoImage(False, file = os.path.join(BASE_DIR,"icon.ico")))
#self.iconbitmap(os.path.join(BASE_DIR,"icon.ico"))
self.resizable(0,0) #Disable Maximize Button
self.config(bg='white')
self.title("Entry Management Application")
self._frame = None
self.switch_frame(PageOne)
def switch_frame(self, frame_class):
if self._frame is not None:
self._frame.destroy()
new_frame = frame_class(self)
new_frame.config(bg='white')
new_frame.pack(expand=1, fill='both')
self._frame = new_frame
##Start Screen
class PageOne(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
label = tk.Label(self, text=" Visitor Information", fg='orange', font=('Candara 15 bold'),bg='white').grid(row=0)
l1 = tk.Label(self, text="Visitor's Name: ", font=('Candara 12 bold'),bg='white').grid(row=1)
# l1.config(font=('Arial', 10, 'Bold'))
e1 = tk.Entry(self, width=50, selectforeground='white',bd=3)
e1.grid(row=1, column=2)
tk.Label(self, text="Visitor's Email:", font=('Candara 12 bold'),bg='white').grid(row=2)
e2 = tk.Entry(self, width=50, selectforeground='white',bd=3)
e2.grid(row=2, column=2);
tk.Label(self, text="Visitor's Phone:", font=('Candara 12 bold'),bg='white').grid(row=3)
e3 = tk.Entry(self, width=50, selectforeground='white',bd=3)
e3.grid(row=3, column=2)
label = tk.Label(self, text="Host Information", fg='orange', font=('Candara 15 bold'),bg='white').grid(row=4)
tk.Label(self, text="Host's Name:", font=('Candara 12 bold'),bg='white').grid(row=5)
e4 = tk.Entry(self, width=50, selectforeground='white',bd=3)
e4.grid(row=5, column=2)
tk.Label(self, text="Host's Email:", font=('Candara 12 bold'),bg='white').grid(row=6)
e5 = tk.Entry(self, width=50, selectforeground='white',bd=3)
e5.grid(row=6, column=2)
tk.Label(self, text="Host's Phone:", font=('Candara 12 bold'),bg='white').grid(row=7)
e6 = tk.Entry(self, width=50, selectforeground='white',bd=3)
e6.grid(row=7, column=2)
tk.Button(self, text="Check-In", command=lambda: get_data(e1, e2, e3, e4, e5, e6), activebackground='orange', bd=3, width=10, height=2).place(x=180, y=230)
tk.Button(self, text="Go to Check-Out", command=lambda: master.switch_frame(PageTwo), activebackground='orange', bd=3, width=14, height=2, ).place(x=300, y=230)
load = Image.open(os.path.join(BASE_DIR,"background.png"))
render = ImageTk.PhotoImage(load)
img = tk.Label(self, image=render)
img.image = render
img.place(x=0, y=300)
##Second Screen
class PageTwo(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
#tk.Frame(self,width=100, height=100)
l1 = tk.Label(self, text="Welcome for Check-Out ", fg='orange', font=('Candara 16 bold'), bg='white').place(x=10, y=0)
tk.Label(self, text="Visitor's Mail ID:", font=('Candara 12 bold'), bg='white').place(x=40, y=45)
ek = tk.Entry(self, width=52, selectforeground='black',bd=3)
ek.place(x=160, y=50)
b1 = tk.Button(self, text="Check-Out", command=lambda: check_out(ek), activebackground='orange', bd=4,width=8, height=2)
b1.place(x=300, y=80)
b2 = tk.Button(self, text="Go Back", command=lambda: master.switch_frame(PageOne), activebackground='orange', bd=3,width=8, height=2)
b2.place(x=200, y=82)
load = Image.open(os.path.join(BASE_DIR,"background.png"))
render = ImageTk.PhotoImage(load)
img = tk.Label(self, image=render)
img.image = render
img.place(x=0, y=300)
if __name__ == '__main__':
app = EntryManger()
app.mainloop()