-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathElection2020_GUI_Admin.py
290 lines (254 loc) · 7.8 KB
/
Election2020_GUI_Admin.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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
import random
from hashlib import md5
from tkinter import *
from PIL import ImageTk, Image
import tkinter.messagebox
import cx_Oracle
F=open('./.resources/connection.txt','r')
global connection_string
connection_string = F.read()
F.close()
def Query_DB(query):
connection = None
res = None
flag = False
try:
#create connection
connection = cx_Oracle.connect(connection_string)
cur = connection.cursor()
cur.execute(query)
res = cur.fetchall()
flag = True
except cx_Oracle.Error as error:
print(error)
flag = error
finally:
# release the connection
if connection:
connection.close()
return res,flag
def Inser_DB(stm):
connection = None
flag = False
try:
#create connection
connection = cx_Oracle.connect(connection_string)
cur = connection.cursor()
cur.execute(stm)
flag = True
except cx_Oracle.Error as error:
print(error)
flag = error
finally:
# release the connection
if connection:
connection.commit()
cur.close()
connection.close()
return flag
def Add_Elected():
def Inscription_(Lname,Fname):
Lname=Lname.upper()
Fname=Fname.upper()
result,flag = Query_DB("SELECT * FROM candidats")
if flag == True:
for line in result:
if (line[2]==Lname) and (line[1]==Fname):
return False
return True
else:
pass
#tkinter.messagebox.showinfo("ERROR!!",str(flag))
def click():
Lname=textentry1.get().upper()
Fname=textentry2.get().upper()
if(Inscription_(Lname,Fname)==False) :
tkinter.messagebox.showinfo("ALERT!!","Ce candidat est déjà enregistré!")
window2.destroy()
else:
num,flag = Query_DB("SELECT COUNT(*) FROM candidats")
if flag == True:
i = int(num[0][0])+1
stm = f"INSERT INTO candidats VALUES('C{str(i)}','{Fname}','{Lname}')"
flag = Inser_DB(stm)
if flag == True:
tkinter.messagebox.showinfo("INFO!!","ajouté avec succès")
clear_()
else:
tkinter.messagebox.showinfo("ERROR!!",str(flag))
else:
tkinter.messagebox.showinfo("ERROR!!",str(flag))
window2.destroy()
window2 =Toplevel()
window2.title("Ajouter un candidat")
window2.configure(background="#ebd034")
window2.geometry("270x180")
window2.resizable(0, 0)
window2.iconbitmap('./.resources/gear.ico')
Label(window2,text="Nom:",bg=background_color).place(x=10,y=10)
textentry1= Entry(window2,bg="white",width=38)
textentry1.place(x=10,y=30)
Label(window2,text="Prenom:",bg=background_color).place(x=10,y=60)
textentry2= Entry(window2,bg="white",width=38)
textentry2.place(x=10,y=80)
Button(window2,font="none 9 italic",fg="white",bg="black",text="Add",command=click).place(x=190,y=120)
window2.mainloop()
def Liste_Candidat():
F,flag=Query_DB("SELECT * FROM candidats")
if flag == True:
i=1
R=""
for line in F:
R+=line[0]+" --> "+line[1]+" "+line[2]+'\n'
i+=1
tkinter.messagebox.showinfo("Liste des candidats",R)
return i
else:
tkinter.messagebox.showinfo("ERROR!!",str(flag))
def Delete_cand():
def click():
i = 0
j = 0
for e in D:
if D[e].get() == 1:
j += 1
stm = f"DELETE FROM candidats WHERE code = '{e}' "
flag = Inser_DB(stm)
if flag != True:
i +=1
tkinter.messagebox.showinfo("ERROR!!",str(flag))
j = j - i
tkinter.messagebox.showinfo("ALERT!!",str(j)+" candidats supprimer avec succès")
clear_()
window5.destroy()
def sel_all():
for a in A:
a.select()
def dsel_all():
for a in A:
a.deselect()
n=Liste_Candidat()
window5 = Toplevel()
window5.resizable(0, 0)
window5.title("Candidats")
window5.iconbitmap('./.resources/gear.ico')
window5.configure(background=background_color)
Label(window5,text="veuillez selectionnez les candidats a supprimer",bg=background_color).pack()
D = {}
A = []
text,flag = Query_DB("SELECT code FROM candidats")
if flag == True:
i = 0
for a in text:
t = a[0]
D[t] = IntVar()
A.append(Checkbutton(window5,bg=background_color, text = t,variable = D[t],onvalue = 1,offvalue = 0 ))
A[i].pack(side = TOP, ipady = 5)
i+=1
else:
tkinter.messagebox.showinfo("ERROR!!",str(flag))
Button(window5,font="none 9 italic",fg="white",bg="black",text="SELECT ALL",command=sel_all).pack(side = 'left',padx = 10)
Button(window5,font="none 9 italic",fg="white",bg="black",text="DESELECT ALL",command=dsel_all).pack(side = 'right',padx = 10)
Button(window5,font="none 9 italic",fg="white",bg="black",text="DELETE",command=click).pack(padx=15,pady=15)
window5.mainloop()
def Delete_users():
def click():
i = 0
j = 0
for e in D:
if D[e].get() == 1:
j += 1
stm = f"DELETE FROM personnes WHERE login = '{e}' "
flag = Inser_DB(stm)
if flag != True:
i +=1
tkinter.messagebox.showinfo("ERROR!!",str(flag))
j = j - i
tkinter.messagebox.showinfo("ALERT!!",str(j)+" utilisateurs supprimer avec succès")
window5.destroy()
def sel_all():
for a in A:
a.select()
def dsel_all():
for a in A:
a.deselect()
window5 = Toplevel()
window5.resizable(0, 0)
window5.title("Utilisateurs")
window5.iconbitmap('./.resources/gear.ico')
window5.configure(background=background_color)
Label(window5,text="veuillez selectionnez les utilisateurs a supprimer",bg=background_color).pack()
D = {}
A = []
text,flag = Query_DB("SELECT login FROM personnes")
if flag == True:
i = 0
for a in text:
t = a[0]
D[t] = IntVar()
A.append(Checkbutton(window5,bg=background_color, text = t,variable = D[t],onvalue = 1,offvalue = 0 ))
A[i].pack(side = TOP, ipady = 5)
i+=1
else:
tkinter.messagebox.showinfo("ERROR!!",str(flag))
Button(window5,font="none 9 italic",fg="white",bg="black",text="SELECT ALL",command=sel_all).pack(side = 'left',padx = 10)
Button(window5,font="none 9 italic",fg="white",bg="black",text="DESELECT ALL",command=dsel_all).pack(side = 'right',padx = 10)
Button(window5,font="none 9 italic",fg="white",bg="black",text="DELETE",command=click).pack(padx=15,pady=15)
window5.mainloop()
def Dic_candidat():
c=[]
C,flag=Query_DB("SELECT * FROM candidats")
if flag == True:
i=1
for line in C:
i+=1
c.append(line[0])
D={}
for e in c:
D[e]=0
return D
return False
def Dic_candidat_DB(D = Dic_candidat()):
if D == False:
return False
Inser_DB("DELETE FROM stats")
for e in D:
stm = f"INSERT INTO stats VALUES('{e}','{D[e]}','NO')"
Inser_DB(stm)
def DB_Dic():
A = Query_DB("SELECT CODE,POINTS FROM stats")
D={}
for a in A:
D[a[0]] = a[1]
return D
def clear_():
D=Dic_candidat()
flag = Dic_candidat_DB(D)
if flag == False:
tkinter.messagebox.showinfo("ERROR!!","Error!!")
return False
Inser_DB("UPDATE personnes SET STATUS='OK'")
tkinter.messagebox.showinfo("ALERT!!","Les résultats sont mis à zéro.\ntous les membres puissent voter à nouveau!!")
def prcp_gui(background_color):
window.resizable(0, 0)
state = DISABLED
#state = None
Button(window,font=button_font,fg="white",bg=button_color,width=20,text="Ajouter un candidat",command=Add_Elected).place(x=20,y=170)
Button(window,font=button_font,fg="white",bg=button_color,width=20,text="Liste: code --> candidat",command=Liste_Candidat).place(x=420,y=170)
Button(window,font=button_font,fg="white",bg=button_color,width=20,text="Supprimer les candidats",command=Delete_cand).place(x=20,y=220)
Button(window,font=button_font,fg="white",bg=button_color,width=20,text="Supprimer les utilisateurs",command=Delete_users).place(x=420,y=225)
Button(window,font=button_font,fg="white",bg=button_color,width=20,text="Clear Result",command=clear_).place(x=220,y=280)
background_color="#ebd034"
button_color="#f80000"
button_font="none 12 bold"
window = Tk()
window.geometry("653x350")
window.title("Election 2020 Admin Dashboard by ZKARA(©)")
window.configure(background=background_color)
window.iconbitmap('./.resources/gear.ico')
imge=Image.open("./.resources/admin.png")
photo=ImageTk.PhotoImage(imge)
lab=Label(image=photo,bg=background_color)
lab.place(x=272,y=20)
prcp_gui(background_color)
window.mainloop()