-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudent_management.py
315 lines (228 loc) · 9.94 KB
/
student_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
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# -*- coding: utf-8 -*-
from tkinter import *
import tkinter.ttk
import tkinter.font as font
import tkinter.messagebox
import MySQLdb
import face_dataset
import face_training
import face_recognition
import os
from pathlib import Path
from datetime import datetime
db = MySQLdb.connect(host="localhost",user="pi",password="raspberry",db="project",charset='utf8')
cur = db.cursor(MySQLdb.cursors.DictCursor)
def student_management(root):
sm = Toplevel(root)
sm.title("학생관리")
sm.geometry("1000x800+150+150")
sm.resizable(False,False)
la1 = Label(sm,text='학번')
myFont = font.Font(family='Helvetica', size=20, weight='bold')
la1.place(height=100,width=150,x=250,y=5)
la1['font']=myFont
data1=Entry(sm)
data1.place(height=40,width=200,x=400,y=35)
data1['font']=myFont
data1.insert(0,"전체")
def search_student():
if(data1.get()=="전체"):
sql = "select * from student"
cur.execute(sql)
while(True):
student = cur.fetchone()
if not student: break
treeview.insert('', 'end', text=student['major'], values=(student['student_number'],student['grade'],student['name']))
else:
sql = "select * from student where student_number = %s"
cur.execute(sql,(int(data1.get()),))
student = cur.fetchone()
if(student == None):
tkinter.messagebox.showwarning("알림","정보를 찾을 수 없습니다.",parent=sm)
else:
treeview.insert('', 'end', text=student['major'], values=(student['student_number'],student['grade'],student['name']))
bu=Button(sm,text="검색",bg="steelblue",command=search_student)
bu['font']=font.Font(family='Helvetica',size=15)
bu.place(height=40,width=100,x=630,y=35)
treeview = tkinter.ttk.Treeview(sm,columns=["one","two","three","four"],displaycolumns=["one","two","three","four"])
style = tkinter.ttk.Style()
style.configure("Treeview.Heading", font=('Helvetica', 15 ,'bold'))
treeview.column("#0",width=200)
treeview.heading("#0",text="학과")
treeview.column("#1",width=200,anchor="center")
treeview.heading("#1",text="학번",anchor="center")
treeview.column("#2",width=200,anchor="center")
treeview.heading("#2",text="학년",anchor="center")
treeview.column("#3",width=200,anchor="center")
treeview.heading("#3",text="이름",anchor="center")
scrollbar = Scrollbar(treeview)
scrollbar.pack(side = RIGHT, fill=Y )
scrollbar.config(command = treeview.yview )
treeview.place(height=600,width=802,x=70,y=100)
#데이터삽입
bottom_b1 =Button(sm,text="추가",bg="steelblue",command=lambda:insert_student(root))
bottom_b1['font']=font.Font(family='Helvetica',size=15)
bottom_b1.place(height=40,width=100,x=90,y=745)
bottom_b2 =Button(sm,text="수정",bg="steelblue",command=lambda:update_student(root))
bottom_b2['font']=font.Font(family='Helvetica',size=15)
bottom_b2.place(height=40,width=100,x=420,y=745)
bottom_b3 =Button(sm,text="삭제",bg="steelblue",command=lambda:delete_student(root))
bottom_b3['font']=font.Font(family='Helvetica',size=15)
bottom_b3.place(height=40,width=100,x=720,y=745)
def insert_student(root):
sm = Toplevel(root)
sm.title("학생등록")
sm.geometry("300x350+150+150")
la1 = Label(sm,text='학번')
myFont = font.Font(family='Helvetica', size=15, weight='bold')
la1.place(height=30,width=40,x=30,y=5)
la1['font']=myFont
data1=Entry(sm)
data1.place(height=30,width=120,x=90,y=5)
data1['font']=myFont
la2 = Label(sm,text='학과')
myFont = font.Font(family='Helvetica', size=15, weight='bold')
la2.place(height=30,width=40,x=30,y=85)
la2['font']=myFont
data2=Entry(sm)
data2.place(height=30,width=120,x=90,y=85)
data2['font']=myFont
la3 = Label(sm,text='학년')
myFont = font.Font(family='Helvetica', size=15, weight='bold')
la3.place(height=30,width=40,x=30,y=165)
la3['font']=myFont
data3=Entry(sm)
data3.place(height=30,width=120,x=90,y=165)
data3['font']=myFont
la4 = Label(sm,text='이름')
myFont = font.Font(family='Helvetica', size=15, weight='bold')
la4.place(height=30,width=40,x=30,y=245)
la4['font']=myFont
data4=Entry(sm)
data4.place(height=30,width=120,x=90,y=245)
data4['font']=myFont
def err_c():
sql = "insert into student values(%s,%s,%s,%s)"
cur.execute(sql,(int(data1.get()),data2.get(),int(data3.get()),data4.get()))
db.commit()
sql = "select picture_count from picture where student_number = %s"
cur.execute(sql,(int(data1.get()),))
student = cur.fetchone()
face_dataset.face_dataset(data1.get(),0)
sql = "insert into picture values(%s,%s)"
cur.execute(sql,(30,int(data1.get())))
db.commit()
tkinter.messagebox.showinfo("알림","학생 등록되었습니다",parent=sm)
bu=Button(sm,text="사진등록",bg="steelblue",command=lambda: err_c())
bu['font']=font.Font(family='Helvetica',size=15)
bu.place(height=30,width=120,x=90,y=295)
def update_student(root):
sm = Toplevel(root)
sm.title("학생수정")
sm.geometry("300x350+150+150")
la1 = Label(sm,text='학번')
myFont = font.Font(family='Helvetica', size=15, weight='bold')
la1.place(height=30,width=40,x=30,y=5)
la1['font']=myFont
data1=Entry(sm)
data1.place(height=30,width=120,x=90,y=5)
data1['font']=myFont
la2 = Label(sm,text='학과')
myFont = font.Font(family='Helvetica', size=15, weight='bold')
la2.place(height=30,width=40,x=30,y=85)
la2['font']=myFont
data2=Entry(sm)
data2.place(height=30,width=120,x=90,y=85)
data2['font']=myFont
la3 = Label(sm,text='학년')
myFont = font.Font(family='Helvetica', size=15, weight='bold')
la3.place(height=30,width=40,x=30,y=165)
la3['font']=myFont
data3=Entry(sm)
data3.place(height=30,width=120,x=90,y=165)
data3['font']=myFont
la4 = Label(sm,text='이름')
myFont = font.Font(family='Helvetica', size=15, weight='bold')
la4.place(height=30,width=40,x=30,y=245)
la4['font']=myFont
data4=Entry(sm)
data4.place(height=30,width=120,x=90,y=245)
data4['font']=myFont
def process_update():
sql = "update student set major=%s,grade=%s,name=%s where student_number = %s"
cur.execute(sql,(data2.get(),int(data3.get()),data4.get(),int(data1.get())))
tkinter.messagebox.showinfo("알림","저장되었습니다",parent=sm)
db.commit()
def process_search():
sql = "select * from student where student_number = %s"
cur.execute(sql,(int(data1.get()),))
student = cur.fetchone()
if(student==None):
tkinter.messagebox.showwarning("알림","정보를 찾을 수 없습니다",parent=sm)
else:
data2.insert(0,"%s"%student['major'])
data3.insert(0,"%s"%student['grade'])
data4.insert(0,"%s"%student['name'])
bu=Button(sm,text="저장하기",bg="steelblue",command=process_update)
bu['font']=font.Font(family='Helvetica',size=15)
bu.place(height=30,width=120,x=90,y=295)
bu=Button(sm,text="검색",bg="steelblue",command=process_search)
bu['font']=font.Font(family='Helvetica',size=15)
bu.place(height=30,width=70,x=220,y=5)
def delete_student(root):
sm = Toplevel(root)
sm.title("학생삭제")
sm.geometry("300x350+150+150")
la1 = Label(sm,text='학번')
myFont = font.Font(family='Helvetica', size=15, weight='bold')
la1.place(height=30,width=40,x=30,y=5)
la1['font']=myFont
data1=Entry(sm)
data1.place(height=30,width=120,x=90,y=5)
data1['font']=myFont
la2 = Label(sm,text='학과')
myFont = font.Font(family='Helvetica', size=15, weight='bold')
la2.place(height=30,width=40,x=30,y=85)
la2['font']=myFont
data2=Entry(sm)
data2.place(height=30,width=120,x=90,y=85)
data2['font']=myFont
la3 = Label(sm,text='학년')
myFont = font.Font(family='Helvetica', size=15, weight='bold')
la3.place(height=30,width=40,x=30,y=165)
la3['font']=myFont
data3=Entry(sm)
data3.place(height=30,width=120,x=90,y=165)
data3['font']=myFont
la4 = Label(sm,text='이름')
myFont = font.Font(family='Helvetica', size=15, weight='bold')
la4.place(height=30,width=40,x=30,y=245)
la4['font']=myFont
data4=Entry(sm)
data4.place(height=30,width=120,x=90,y=245)
data4['font']=myFont
def process_delete():
sql = "delete from student where student_number =%s"
cur.execute(sql,(int(data1.get()),))
for p in Path("/home/pi/fdCam/dataset").glob("User."+data1.get()+".*.jpg"):
p.unlink()
db.commit()
Path("/home/pi/fdCam/trainer/").glob("trainer.yml")
tkinter.messagebox.showinfo("알림","삭제되었습니다",parent=sm)
face_training.face_training()
def process_search():
sql = "select * from student where student_number = %s"
cur.execute(sql,(int(data1.get()),))
student = cur.fetchone()
if(student==None):
tkinter.messagebox.showwarning("알림","정보를 찾을 수 없습니다",parent=sm)
else:
data2.insert(0,"%s"%student['major'])
data3.insert(0,"%s"%student['grade'])
data4.insert(0,"%s"%student['name'])
bu=Button(sm,text="삭제하기",bg="steelblue",command=process_delete)
bu['font']=font.Font(family='Helvetica',size=15)
bu.place(height=30,width=120,x=90,y=295)
bu=Button(sm,text="검색",bg="steelblue",command=process_search)
bu['font']=font.Font(family='Helvetica',size=15)
bu.place(height=30,width=70,x=220,y=5)