· 6 years ago · May 06, 2019, 07:52 AM
1from tkinter import *
2from tkinter import ttk
3from tkinter import messagebox
4import sqlite3
5
6#----Register as a Teacher----
7
8class Register_Teacher:
9
10 #Initialise Register_Teacher
11 def __init__(self):
12 #Create the widget
13 sheet=Tk()
14 self.sheet=sheet
15 self.sheet.title('Register as a Teacher')
16
17 #Draw a frame in the widget
18 frame=LabelFrame(sheet, text='Complete the register with your data')
19 frame.grid(row=0, column=0)
20
21 #The following text will ask for details using labels and let the user answer in the entry next to each specified detail
22 Name=Label(frame, text='Enter your name:').grid(row=1, column=0)
23 self.name=Entry(frame)
24 self.name.grid(row=1, column=1)
25
26 Surname=Label(frame, text='Enter your surname:').grid(row=2, column=0)
27 self.surname=Entry(frame)
28 self.surname.grid(row=2, column=1)
29
30 Password=Label(frame, text='Password:').grid(row=3, column=0)
31 self.password=Entry(frame, show="*")
32 self.password.grid(row=3, column=1)
33
34 RepeatPassword=Label(frame, text='Repeat Password:').grid(row=4, column=0)
35 self.repeatpassword=Entry(frame, show="*")
36 self.repeatpassword.grid(row=4, column=1)
37
38 #The following buttons are used to go back to the main menu or to enter the information written by the user
39 Back = Button(frame, text="Go back", command=lambda:[self.GoBack(sheet)]).grid(row=5, column=1)
40 Submit = Button(frame, text="Submit", command=lambda:[self.Enter(self.name, self.surname, self.password, self.repeatpassword)]).grid(row=5, column=0)
41 #"lambda" is used to call more than one command at the same time, although it is not the case in the above buttons
42
43 # Return to main menu function
44 def GoBack(self,sheet):
45 sheet.destroy()
46 window.deiconify()
47
48 # Enter function validates that the password and repeatpassword match and then it enters the teacher details
49 def Enter(self, name, surname, password, repeatpassword):
50 conn = sqlite3.connect("Project.db")
51 cur = conn.cursor()
52
53 # Get methods used to take what the user wrote
54 name1=name.get()
55 surname1=surname.get()
56 password1=password.get()
57 repeatpassword1=repeatpassword.get()
58
59 # Validating password using nested if
60 if password1==repeatpassword1:
61 # If the passwords are repeated, the program will then check if the teacher´s name and surname are allready in the database
62 # as we are supposing only a few teachers will participate in work experience.
63 cur.execute("SELECT * FROM Teacher WHERE Name = ? AND Surname = ?",(name1, surname1))
64 rel=cur.fetchall()
65 print(rel)
66 if rel == []:
67 # Insert name surname and password into the table Teacher
68 cur.execute("INSERT INTO Teacher VALUES (:Name, :Surname, :Password)", {'Name': name1, 'Surname': surname1, 'Password': password1})
69
70 else:
71 #Show an error message
72 messagebox.showinfo("Invalid", "Teacher with the same details already exists")
73 else:
74 #Show error message and delete the content of the password
75 messagebox.showinfo("Error", "Password missmatch")
76 self.password.delete(0, END)
77 self.repeatpassword.delete(0, END)
78
79 conn.commit()
80 conn.close()
81
82#----- Login as a Teacher -----
83
84class Login_Teacher:
85
86 def __init__(self):
87 # Create the widget
88 root=Tk()
89 self.root = root
90 self.root.title('Teacher Login')
91
92 # Create a frame in the widget
93 widget = LabelFrame(root, text = 'Add your username and password!')
94 widget.grid(row=0, column=0)
95
96 # Create labels and entries to input name and password
97 Name = Label(widget, text = 'Teacher Name:').grid(row=1, column=0)
98 self.name = Entry(widget)
99 self.name.grid(row=1, column=1)
100
101 Password = Label(widget, text='Teacher Password:').grid(row=2, column=0)
102 self.password = Entry(widget, show="*")
103 self.password.grid(row=2, column=1)
104
105 # Submit and return buttons
106 Return = Button(widget, text='Return', command=lambda:[self.GoBack(root)]).grid(row=3, column=1)
107 Submit = Button(widget, text = 'Submit', command=lambda:[self.Validation(self.name, self.password)]).grid(row=3, column=0)
108
109 # Register as a Teacher button
110 Register = Button(widget, text='Register as a Teacher', command=lambda:[Register_Teacher()]).grid(row=3, column=2)
111
112 # Go Back to main menu function
113 def GoBack(self,root):
114 root.destroy()
115 #Deiconify is used to show the
116 window.deiconify()
117
118 # Validation function
119 def Validation(self, name, password):
120 nameT=name.get()
121 passwordT=password.get()
122
123 connection = sqlite3.connect("Project.db")
124 cursor = connection.cursor()
125
126 # Sql statement that selects
127 cursor.execute("SELECT * FROM Teacher WHERE Name = ? AND Password = ?",(nameT, passwordT))
128 details=cursor.fetchall()
129
130 # python if else statement
131 if details ==[]:
132 messagebox.showinfo("Error", "Name or Password missmatch")
133
134 else:
135 self.TeacherInterface()
136
137 connection.commit()
138 connection.close()
139
140 #
141 def TeacherInterface(self):
142 widget1= Tk()
143 self.widget1=widget1
144 self.widget1.title('Teacher Interface')
145
146 QuestionnaireNumber=Label(widget1, text='What questionnaire do you want to know information about?').grid(row=0, column= 0)
147 self.questionnairenumber=Entry(widget1)
148 self.questionnairenumber.grid(row=0, column=1)
149
150 Percentages=Button(widget1, text='Show current percentages in treeview', command=lambda:[self.CalculateCurrentPercentages(self.questionnairenumber, self.tree)]).grid(row=1, column=0)
151 #----------
152 FindStudentID=Label(widget1, text='Write the id of the student:').grid(row=2, column=0)
153 self.findstudentid=Entry(widget1)
154 self.findstudentid.grid(row=2, column=1)
155
156 SubmitB=Button(widget1, text='Find the student with the id above', command=lambda:[self.Find_Student(widget1, self.findstudentid, self.tree)]).grid(row=3, column=0)
157 #----------
158 Placement=Button(widget1, text='Click here to create a new placement or organisation record.', command=lambda:[self.EnterPlacement()]).grid(row=5, column=0)
159
160
161 AddQuestion=Label(widget1, text='Add a question:').grid(row=6, column=0)
162 self.addquestion=Entry(widget1)
163 self.addquestion.grid(row=6, column=1)
164
165 QuestionnaireFor=Label(widget1, text='What questionnaire is the question going to be for?').grid(row=7, column=0)
166 self.questionnairefor=Entry(widget1)
167 self.questionnairefor.grid(row=7, column=1)
168
169 AddEnter=Button(widget1, text='Enter the question', command=lambda:[self.Insert_Question(self.addquestion,self.questionnairefor)]).grid(row=8, column=0)
170
171 #--This should be used in a new upgrade
172 #ModQuestionID=Label(widget1, text='To modify a question insert the question id: E.g QID2').grid(row=6, column=2)
173 #self.modquestionid=Entry(widget1)
174 #self.modquestionid.grid(row=6, column=3)
175
176 #--This should be used in a new upgrade
177 #ModQuestion=Label(widget1, text='Write the new question').grid(row=7, column=2)
178 #self.modquestion=Entry(widget1)
179 #self.modquestion.grid(row=7, column=3)
180
181 #ModifyEnter=Button(widget1, text='Enter the question id', command=lambda:[self.Modify_Question(self.modquestionid, self.modquestion)]).grid(row=9, column=2)
182
183 # Create a tree view
184 self.tree= ttk.Treeview(self.widget1, height=5)
185 self.tree.grid(row=10, column=0)
186
187 # Insert_Question is a procedure which adds a question to the Question table
188 def Insert_Question(self, addquestion, questionnairefor):
189 conn = sqlite3.connect("Project.db")
190 cur = conn.cursor()
191 addquestion1=addquestion.get()
192 questionnairefor1=questionnairefor.get()
193 # sql select command
194 cur.execute("SELECT * FROM Questions")
195 current=cur.fetchall()
196 count=1
197 #for loop
198 for record in current:
199 count+=1
200 Qid="QID"+str(count)
201 # Insert question using sql
202 cur.execute("INSERT INTO Questions VALUES (:Q_ID, :Question)",{'Q_ID':Qid, 'Question':addquestion1})
203
204 # Search for the number of records in the table to create a new link id
205 cur.execute("SELECT Link_ID FROM LinkQuestionnairesToQuestions")
206 linknumber=cur.fetchall()
207 linkcount=1
208 # For loop
209 for row in linknumber:
210 linkcount += 1
211
212 questionnaireid="QrID"+str(questionnairefor1)
213 Linkid1="LinkID" + str(linkcount)
214
215 # Insert record into LinkQuestionnairesToQuestions
216 cur.execute("INSERT INTO LinkQuestionnairesToQuestions VALUES(:Link_ID, :Qr_ID,:Q_ID)",{'Link_ID':str(Linkid1),'Qr_ID':str(questionnaireid),'Q_ID':str(Qid)})
217 conn.commit()
218 conn.close()
219
220 # Modify_Question is not in use because it was decided that it was unnecessary
221 def Modify_Question(self, modquestionid, modquestion):
222 conn = sqlite3.connect("Project.db")
223 cur = conn.cursor()
224 modquestionid1=modquestionid.get()
225 modquestion1=modquestion.get()
226 cur.execute("SELECT Question FROM Questions WHERE Q_ID=?",(str(modquestionid1),))
227 line=cur.fetchone()
228 print(line)
229 if line[0]==" ":
230 message.showinfo('Error', 'Question id does not match any record in the table')
231 else:
232 cur.execute("INSERT INTO Questions Values (:Q_ID, :Question)",{'Q_ID':str(modquestionid1), 'Question':str(modquestion1)})
233
234
235 conn.commit()
236 conn.close()
237
238 # CalculateCurrentPercentages is a function which counts the answers
239 # and retreives them to the tree where they are displayed.
240 def CalculateCurrentPercentages(self,questionnairenumber, tree):
241 conn= sqlite3.connect('Project.db')
242 cur=conn.cursor()
243 QN=questionnairenumber.get()
244 Qr="QrID"+str(QN)
245 # Selects the Link_ID and the Q_ID
246 cur.execute("SELECT Link_ID,Q_ID FROM LinkQuestionnairesToQuestions WHERE Qr_ID=?", (Qr,))
247 records=cur.fetchall()
248 # For loop
249 for record in records:
250 # Sql command to select the answer
251 cur.execute("SELECT Answer FROM Results WHERE Link_ID=?", (record[0],))
252 possibilities=cur.fetchall()
253 print(possibilities)
254 YesC=0
255 NoC=0
256 LongC=0
257 ShortC=0
258 SufficientC=0
259 # For loop and if and elif statements
260 for possibility in possibilities:
261 if possibility[0]=="Yes":
262 YesC = YesC + 1
263
264 elif possibility[0]=="No":
265 NoC += 1
266
267 elif possibility[0]=="Long":
268 LongC +=1
269
270 elif possibility[0]=="Short":
271 ShortC += 1
272
273 elif possibility[0]=="Sufficient":
274 SufficientC +=1
275 #Insert items into a tree view
276 self.tree.insert("", 1, text=record[1] + "Yes =" + str(YesC))
277 self.tree.insert("", 2, text=record[1] + "No =" + str(NoC))
278 self.tree.insert("", 3, text=record[1] + "Long =" + str(LongC))
279 self.tree.insert("", 4, text=record[1] + "Short =" + str(ShortC))
280 self.tree.insert("", 5, text=record[1] + "Sufficient =" + str(SufficientC))
281 #print(record[1])
282 #print("counts",YesC, NoC, LongC, ShortC, SufficientC)
283
284 conn.commit()
285 conn.close()
286
287 #
288 def Find_Student(self, widget1, findstudentid, tree):
289 conn= sqlite3.connect('Project.db')
290 cur= conn.cursor()
291
292 findstudentid1=findstudentid.get()
293 cur.execute("SELECT * FROM Student WHERE St_ID=?",(findstudentid1,))
294 found=cur.fetchall()
295 print(found)
296 if found==[]:
297 messagebox.showinfo('Error','Student id does not exist')
298
299 else:
300 for item in found:
301 self.tree.insert("",0, text=item,values=(item))
302 print(item)
303 print("hey")
304
305 conn.commit()
306 conn.close()
307 def EnterPlacement(self):
308 #self.widget1=widget1
309 top = Toplevel()
310 top.title('Placements and Companies')
311 StudentID=Label(top, text='Student ID').grid(row=1, column=0)
312 self.studentid=Entry(top)
313 self.studentid.grid(row=1, column=1)
314
315 OrganisationID=Label(top, text='Organisation ID (AriAr : CompanyName´s first three letter and company´s email first 2 letter)').grid(row=2, column=0)
316 self.organisationid=Entry(top)
317 self.organisationid.grid(row=2, column=1)
318
319 CompanyStartDate=Label(top, text='Tell me the on what day you started work experience: (YearMonthDay)').grid(row=3, column=0)
320 self.companystartdate=Entry(top)
321 self.companystartdate.grid(row=3, column=1)
322
323 CompanyEndDate=Label(top, text='Tell me the on what day did you finished work experience: (YearMonthDay)').grid(row=4, column=0)
324 self.companyenddate=Entry(top)
325 self.companyenddate.grid(row=4, column=1)
326
327 SubmitB=Button(top, text='Enter data to create a placement id', command=lambda:[self.NewPlacementEntry(self.organisationid, self.studentid, self.companystartdate, self.companyenddate)]).grid(row=5, column=0)
328 #----------------
329 Or=Label(top, text='Or').grid(row=6, column=0)
330 NewOrganisationName=Label(top, text='Write the organisation name').grid(row=7, column=0)
331 self.neworganisationname=Entry(top)
332 self.neworganisationname.grid(row=7, column=1)
333
334 NewOrganisationEmail=Label(top, text='Write the organisations contact email').grid(row=8, column=0)
335 self.neworganisationemail=Entry(top)
336 self.neworganisationemail.grid(row=8, column=1)
337
338 SubmitOrganisationDetails=Button(top, text='Click here to enter the organisation details', command=lambda:[self.NewOrganisationEntry(self.neworganisationname, self.neworganisationemail)]).grid(row=9, column=0)
339
340
341 def NewPlacementEntry(self, organisationid, studentid, companystartdate, companyenddate):
342 organisationid1=organisationid.get()
343 studentid1=studentid.get()
344 companystartdate1=companystartdate.get()
345 companyenddate1=companyenddate.get()
346 studentid2=str(studentid1)
347 PlacementID= str(organisationid1) + studentid2[0:2]
348 conn= sqlite3.connect('Project.db')
349 cur= conn.cursor()
350
351 cur.execute("INSERT INTO Placement VALUES(:Pl_ID, :St_ID, :Org_ID, :Com_StartDate, :Com_EndDate)",{'Pl_ID':PlacementID, 'St_ID':str(studentid1), 'Org_ID':str(organisationid1), 'Com_StartDate':str(companystartdate1), 'Com_EndDate':str(companyenddate1)})
352
353 conn.commit()
354 conn.close()
355
356 def NewOrganisationEntry(self, neworganisationname, neworganisationemail):
357 neworganisationname1=neworganisationname.get()
358 neworganisationemail1=neworganisationemail.get()
359 neworganisationname2=str(neworganisationname1)
360 neworganisationemail2=str(neworganisationemail1)
361 print(neworganisationname1)
362 print(neworganisationemail1)
363 organisationid= neworganisationname2[0:2] + neworganisationemail2[0:3]
364 conn=sqlite3.connect('Project.db')
365 cur=conn.cursor()
366
367 cur.execute("INSERT INTO Organisation VALUES (:Or_ID, :Com_Name, :Com_Email)",{'Or_ID':str(organisationid), 'Com_Name':str(neworganisationname1), 'Com_Email':str(neworganisationemail1)})
368
369 conn.commit()
370 conn.close()
371
372class Register_Student:
373 def __init__(self):
374 paper=Tk()
375 self.paper = paper
376 self.paper.title('Register for students')
377
378 conn=sqlite3.connect('Project.db')
379 c=conn.cursor()
380
381 frame=LabelFrame(paper, text='Complete the requirements')
382 frame.grid(row=0,column=0)
383
384 StudentName=Label(frame, text="Tell me your full name:").grid(row=0, column=0)
385 self.studentname=Entry(frame)
386 self.studentname.grid(row=0, column=1)
387
388 StudentSurname=Label(frame, text="Tell me your surnames:").grid(row=1, column=0)
389 self.studentsurname=Entry(frame)
390 self.studentsurname.grid(row=1, column=1)
391
392 StudentPassword=Label(frame, text="Tell me your password:").grid(row=2, column=0)
393 self.studentpassword=Entry(frame, show="*")
394 self.studentpassword.grid(row=2, column=1)
395
396 StudentRepeatPassword=Label(frame, text="Repeat your password:").grid(row=3, column=0)
397 self.studentrepeatpassword=Entry(frame, show="*")
398 self.studentrepeatpassword.grid(row=3, column=1)
399
400 StudentBirthDate=Label(frame, text="Tell me your birth date(YearMonthDay E.g. 20010214)").grid(row=4, column=0)
401 self.studentbirthdate=Entry(frame)
402 self.studentbirthdate.grid(row=4, column=1)
403
404 Submit = Button(frame, text = 'Submit', command=lambda:[self.ValidatingSubmit(paper, self.studentname, self.studentsurname, self.studentpassword, self.studentrepeatpassword, self.studentbirthdate)]).grid(row=5, column=0)
405 Return = Button(frame, text='Go back', command=lambda:[self.Close(paper)]).grid(row=5, column=1)
406
407 def ValidatingSubmit(self, paper, studentname, studentsurname, studentpassword, studentrepeatpassword, studentbirthdate):
408 conn = sqlite3.connect("Project.db")
409 cur = conn.cursor()
410
411 studentname2=studentname.get()
412 studentsurname2=studentsurname.get()
413 studentpassword2=studentpassword.get()
414 studentrepeatpassword2=studentrepeatpassword.get()
415 studentbirthdate2=studentbirthdate.get()
416
417 if studentpassword2==studentrepeatpassword2:
418 self.Add_Student(studentname2, studentsurname2, studentbirthdate2, studentpassword2)
419 else:
420 messagebox.showinfo("Error", "Password missmatch")
421 self.password.delete(0, END)
422 self.repeatpassword.delete(0, END)
423
424 conn.commit()
425 conn.close()
426
427 def Add_Student(self, studentname2, studentsurname2, studentbirthdate2, studentpassword2):
428 conn=sqlite3.connect('Project.db')
429 c=conn.cursor()
430
431 FormationPreID = studentname2[0:3] + studentsurname2[0:4] + "_"
432
433 c.execute("SELECT St_ID FROM Student WHERE St_Name = ? AND St_Surname=?",(studentname2,studentsurname2))
434 t=c.fetchall()
435 v=0
436 for item in t:
437 print(item)
438 number=item[0].split("_")
439 print(number)
440 if int(number[1]) > v:
441 v=int(number[1])
442 v +=1
443
444 StudentID = FormationPreID + str(v)
445
446 c.execute("INSERT INTO Student VALUES (:St_ID, :St_Name, :St_Password, :St_Date_of_Birth, :St_Surname)",{'St_ID': StudentID, 'St_Name':studentname2, 'St_Password':studentpassword2, 'St_Date_of_Birth':studentbirthdate2, 'St_Surname':studentsurname2})
447
448 conn.commit()
449 conn.close()
450
451
452 def Close(self, paper):
453 paper.destroy()
454 window.deiconify()
455
456
457
458
459class Login_Student:
460 #self.db_name = 'project.db'
461 #self.conn = sqlite3.connect('Student.db')
462 # self.cur = self.conn.cursor()
463 def __init__(self):
464 db_name= 'Project.db'
465 self.db_name = db_name
466 trebol=Tk()
467 self.trebol = trebol
468 self.trebol.title('Student Login')
469 frame = LabelFrame(trebol, text = 'Write your username and password!')
470 frame.grid(row = 0, column = 0)
471
472 Username=Label(frame, text ='Student Username:').grid(row = 1, column = 0)
473 self.username = Entry(frame)
474 self.username.grid(row = 1, column = 1)
475
476
477 Password=Label(frame, text ='Password:').grid(row=2, column=0)
478 self.password = Entry(frame, show="*")
479 self.password.grid(row=2, column=1)
480
481
482 Register = Button(frame, text='Register as a Student', command=lambda:[Register_Student()]).grid(row=3, column=2)
483
484 Submit = Button(frame, text = 'Submit', command=lambda:[self.ValidatingSubmit(trebol, self.username, self.password)]).grid(row=3, column=0)
485 Return = Button(frame, text='Go back', command=lambda:[self.Close(trebol)]).grid(row=3, column=1)
486
487 def ValidatingSubmit(self, trebol, username, password):
488 usernameS = username.get()
489 passwordS = password.get()
490
491 conn = sqlite3.connect("Project.db")
492 cur = conn.cursor()
493 cur.execute("SELECT * FROM Student WHERE St_ID=? AND St_Password=?",(usernameS,passwordS))
494 detailsS=cur.fetchall()
495 if detailsS ==[]:
496 messagebox.showinfo("Error", "Username or Password missmatch")
497
498 else:
499 self.StudentInterface(trebol, self.db_name, usernameS, passwordS)
500 conn.commit()
501 conn.close()
502
503 def Close(self, trebol):
504 trebol.destroy()
505 window.deiconify()
506
507 def RegisterasStudent(self):
508 Register_Student()
509
510 def StudentInterface(self, trebol, db_name, usernameS, passwordS):
511 u=usernameS
512 p=passwordS
513 self.u=u
514 self.p=p
515 print(u,p)
516 self.trebol = trebol
517 top = Toplevel()
518 top.title("Student Interface")
519 OPTIONS = [
520 "YEAR",
521 "YEAR 11",
522 "YEAR 12"
523 ]
524 SUBJECT = ["Engineer","Biology", "Chemistry", "Physics"]
525 #variable=StringVar(top)
526 #variable.set(OPTIONS[0])
527
528 #YearButton = OptionMenu(top, variable, *OPTIONS).grid(row=0,column=1)
529 print(db_name)
530 TableButton = Button(top, text="Create tables", command=lambda:[self.Create_Table(self, db_name)]).grid(row=6, column=0)
531
532 #var1=StringVar(top)
533 #var1.set(SUBJECT[0])
534
535 #SubjectButton = OptionMenu(top, var1, *SUBJECT).grid(row=0, column=0)
536
537 Choice=Label(top, text="Choose a questionnaire:").grid(row=1, column=0)
538 self.Choice1=Entry(top)
539 self.Choice1.grid(row=1, column=1)
540
541 Organisation=Label(top, text="Tell me the company name you went to:").grid(row=2, column=0)
542 self.organisation=Entry(top)
543 self.organisation.grid(row=2,column=1)
544
545 StartQuestionnaire = Button(top, text="Click here to start the questionnaire", command=lambda:[SelectingQuestions(self,self.Choice1,self.u, self.p, self.organisation),Clear_Button(self, self.Choice1, self.organisation)]).grid(row=3)
546
547 def SelectingQuestions(self,Choice1,u,p, organisation):
548 conn = sqlite3.connect("Project.db")
549 cur = conn.cursor()
550 print("u and p =",u,p)
551
552 org=organisation.get()
553 QuestionnaireChosen=Choice1.get()
554 QuestionnaireChosen1="QrID" + QuestionnaireChosen
555 cur.execute("""SELECT LinkQuestionnairesToQuestions.Link_ID, Questions.Question
556 FROM LinkQuestionnairesToQuestions
557 INNER JOIN Questions USING (Q_ID)
558 WHERE Qr_ID=?""", (QuestionnaireChosen1,))
559
560 records=cur.fetchall()
561 for record in records:
562 print(record)
563 link=record[0]
564 q=record[1]
565 Questionnaire(link, QuestionnaireChosen, q, u, p, org)
566
567
568
569 def Clear_Button(self, Choice1, organisation ):
570 self.Choice1.delete(0, END)
571 self.organisation.delete(0, END)
572
573 def Create_Table(self):
574 conn = sqlite3.connect("Project.db")
575 cur = conn.cursor()
576 #self.Create_Connection(self, db_name)
577
578 cur.execute("""CREATE TABLE IF NOT EXISTS Questionnaires(Qr_ID TEXT PRIMARY KEY, Questionnaire INTEGER)""")
579
580
581 cur.execute("""CREATE TABLE IF NOT EXISTS Questions(Q_ID TEXT PRIMARY KEY, Question TEXT)""")
582
583
584 cur.execute("""CREATE TABLE IF NOT EXISTS LinkQuestionnairesToQuestions(
585 Link_ID TEXT , Qr_ID TEXT NOT NULL, Q_ID TEXT NOT NULL,
586 FOREIGN KEY (Qr_ID) REFERENCES Questionnaires(Qr_ID),
587 FOREIGN KEY (Q_ID) REFERENCES Questions(Q_ID),
588 PRIMARY KEY (Qr_ID, Q_ID)
589 )""")
590
591
592 cur.execute("""CREATE TABLE IF NOT EXISTS Student(St_ID TEXT PRIMARY KEY, St_Name TEXT,
593 St_Password TEXT, St_Date_of_Birth DATE, St_Surname TEXT)""")
594
595 cur.execute("""CREATE TABLE IF NOT EXISTS Organisation(Or_ID TEXT PRIMARY KEY, Com_Name TEXT, Com_Email TEXT)""")
596
597 cur.execute("""CREATE TABLE IF NOT EXISTS Placement(Pl_ID TEXT PRIMARY KEY, St_ID TEXT, Org_ID TEXT, Com_StartDate DATE, Com_EndDate DATE,
598 FOREIGN KEY (St_ID) REFERENCES Student(St_ID),
599 FOREIGN KEY (Org_ID) REFERENCES Organisation(Or_ID)
600 )""")
601
602 cur.execute("""CREATE TABLE IF NOT EXISTS Results(Re_ID TEXT PRIMARY KEY, Link_ID TEXT , Pl_ID TEXT, Answer TEXT,
603 FOREIGN KEY (Pl_ID) REFERENCES Placement(Pl_ID),
604 FOREIGN KEY (Link_ID) REFERENCES LinkQuestionnairesToQuestions(Link_ID)
605 )""")
606
607 cur.execute("""CREATE TABLE IF NOT EXISTS Teacher(Name TEXT, Surname TEXT, Password TEXT)""")
608
609 conn.commit()
610 conn.close()
611
612
613class Questionnaire:
614 def __init__(self,link, QuestionnaireChosen, q, u, p, org):
615 conn = sqlite3.connect("Project.db")
616 cur = conn.cursor()
617 Org=org
618 usernameS=u
619 passwordS=p
620 self.usernameS=usernameS
621 self.passwordS=passwordS
622 self.Org=Org
623 l=link
624 a=q+l
625 pen=Tk()
626 self.pen=pen
627 pen.title("Questionnaire " + QuestionnaireChosen)
628 Question = Label(pen, text = a)
629 Question.grid(row=0, column=0)
630 Linkid = Label(pen, text = "Enter the link id from the question:").grid(row=1, column=0)
631 self.link=Entry(pen)
632 self.link.grid(row=1, column=1)
633 Ans = Label(pen, text='Answer the question:').grid(row=2, column=0)
634 self.ans=Entry(pen)
635 self.ans.grid(row=2 ,column=1)
636 SubmitButton = Button(pen, text='Enter answer', command=lambda:[self.InsertAnswer(pen, self.ans, self.link, self.usernameS, self.Org), self.Clear(pen)])
637 SubmitButton.grid(row=3, column=0)
638
639 def InsertAnswer(self, pen, ans, link, usernameS, Org):
640 conn = sqlite3.connect("Project.db")
641 cur = conn.cursor()
642 o=Org
643 A1=ans.get()
644 Linkid1=link.get()
645 cur.execute("SELECT * FROM Organisation WHERE Com_Name = ?",(o,))
646 OrgID=cur.fetchall()
647 OrID= OrgID[0][0]
648 ResultsID=str(Linkid1) + str(usernameS) + str(OrID)
649 cur.execute("INSERT INTO Results VALUES (:Re_ID, :Link_ID, :Pl_ID, :Answer )",{'Re_ID':str(ResultsID), 'Link_ID': str(Linkid1), 'Pl_ID': str(OrID), 'Answer':str(A1)})
650 conn.commit()
651 conn.close()
652 def Clear(self, pen):
653 pen.destroy()
654
655
656
657
658
659class Main_Menu:
660 #self.connection = sqlite3.connect('Student.db')
661
662 def __init__(self, window):
663 self.window = window
664 self.window.title('Main Menu')
665
666 frame=LabelFrame(self.window, text='Select an option')
667 frame.grid(row=0, column=0)
668 self.frame=frame
669
670 self.Welcome_Message = Label(self.frame, text="Welcome to our program\nPlease register or enrol as a teacher or student").grid(row=0, column=0)
671 self.Login_Teacher_Button = Button(self.frame, text="Login as a teacher", command=lambda:[self.hide(window),Login_Teacher()]).grid(row=1, column=0)
672 self.Login_Student_Button = Button(self.frame, text="Login as a student", command=lambda:[self.hide(window),Login_Student()]).grid(row=2, column=0)
673 self.Register_Student_Button = Button(self.frame, text="Register as a student", command=lambda:[self.hide(window),Register_Student()]).grid(row=3, column=0)
674 self.Register_Teacher_Button = Button(self.frame, text="Register as a teacher", command=lambda:[self.hide(window),Register_Teacher()]).grid(row=4, column=0)
675 self.Close_Button = Button(self.frame, text="Quit", command=lambda:[self.Close(window)]).grid(row=5, column=0)
676
677 def hide(self, window):
678 self.window.withdraw()
679
680 def Close(self, window):
681 self.window.destroy()
682
683if __name__ == '__main__':
684 window=Tk()
685 application = Main_Menu(window)
686 window.mainloop()