-
Notifications
You must be signed in to change notification settings - Fork 0
/
updateConstants.py
244 lines (166 loc) · 7.53 KB
/
updateConstants.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
#-------------------------------------------------------------------------------
# Name: Update Constants
# Purpose: access the database and pull the constants data
#
#
# Author: DBMS
#
# Created: 01/08/2014
# Copyright: (c) DBMS 2014
# Licence: <your licence>
#-------------------------------------------------------------------------------
import extractData as data
import UI
import dateTimeOutput
import sqlite3
def checkError(funcOutput): #returns false is there is an error, returns true if no error exists
'''Checks the output of the function to see if an error message was returned
'''
if 'Error' in funcOutput: #sees if the output returns an error
return False
else: #output does not return an error
return True
def checkBack(funcOutput):
'''Checks if the BACK button was selected
'''
if 'BACK' in funcOutput: #Checks if the output shows "QUIT"
return True #this will mean
else:
return False
def inputCredits(c, inputStage):
'''Implements the creditsInputScrolling tk app and will update the database
'''
c.execute("SELECT course_code, term FROM courses;") #grabs names of all the courses
allCourses = c.fetchall()
courseDisplayName = []
for i in range(len(allCourses)):
#first element [i][0] is the course code, the second [i][1] is the term that the course is in
courseDisplayName.append(allCourses[i][0] + " - Term: " + str(allCourses[i][1]))
creditsList = UI.creditsInputScrolling.runApp(courseDisplayName) #initializes the entry widget to input credits data
while not checkError(creditsList): #do while loop that repeats until there is no more error
UI.errorMessageBox.runApp(creditsList)
creditsList = UI.creditsInputScrolling.runApp(courseDisplayName)
if checkBack(creditsList):
return inputStage - 1
for credit in creditsList:
c.execute('''UPDATE courses SET credits = ?;''',(credit,)) #adds to each course record the number of credits
return inputStage + 1
def inputUnitFees(c, inputStage):
''' Uses the feeUnitsInput tk app and will update the database
'''
c.execute("SELECT DISTINCT program FROM students;")
programList = c.fetchall()
unitFeesList = UI.feeUnitsInput.runApp(programList)
while not checkError(unitFeesList) and not len(programList) == len(unitFeesList):
UI.errorMessageBox.runApp(unitFeesList)
unitFeesList = UI.feeUnitsInput.runApp(programList)
if checkBack(unitFeesList):
return inputStage - 1
if len(programList) == len(unitFeesList):
for i in range(len(unitFeesList)):
c.execute("UPDATE program_info SET unit_fees = ? WHERE program_name = ?;",(unitFeesList[i], programList[i][0],))
return inputStage + 1
def inputBIU(c, inputStage):
''' Uses the BIUInput tk app and will update the database
'''
BIUList = UI.BIUInput.runApp()
while not checkError(BIUList) and not len(BIUList) == 1:
UI.errorMessageBox.runApp(BIUList)
BIUList = UI.BIUInput.runApp()
if checkBack(BIUList):
return inputStage - 1
if len(BIUList) == 1:
c.execute("SELECT COUNT (*) FROM constants WHERE id = 1")
checkExists = c.fetchone()
if checkExists == (1,): #if a BIU value exists in the database
c.execute("UPDATE constants SET value = ? WHERE id = 1;", (BIUList)) #update that existing value
elif checkExists == (0,): #if no BIU value exists
c.execute("INSERT INTO constants (name,value) VALUES (?,?);",("BIU Value", BIUList[0])) #insert a new record
return inputStage + 1
def inputFormulaFees(c, inputStage):
''' Uses the formulaFeesInput tk app and will update the database
'''
c.execute("SELECT DISTINCT program FROM students;")
programList = c.fetchall()
formulaFeeList = UI.formulaFeesInput.runApp(programList)
while not checkError(formulaFeeList) and not len(programList) == len(formulaFeeList):
UI.errorMessageBox.runApp(formulaFeeList)
formulaFeeList = UI.formulaFeesInput.runApp(programList)
if checkBack(formulaFeeList):
return inputStage - 1
if len(programList) == len(formulaFeeList):
for i in range(len(formulaFeeList)):
c.execute("UPDATE program_info SET formula_fees = ? WHERE program_name = ?;",(formulaFeeList[i],programList[i][0]))
return inputStage + 1
def inputNormalUnits(c, inputStage):
c.execute("SELECT DISTINCT program FROM students;")
programList = c.fetchall()
normalUnitsList = UI.normalUnitsInput.runApp(programList)
while not checkError(normalUnitsList) and not len(programList) == len(normalUnitsList):
UI.errorMessageBox.runApp(normalUnitsList)
normalUnitsList = UI.normalUnitsInput.runApp(programList)
if checkBack(normalUnitsList):
return inputStage - 1
if len(programList) == len(normalUnitsList):
for i in range(len(normalUnitsList)):
c.execute("UPDATE program_info SET normal_units = ? WHERE program_name = ?;", (normalUnitsList[i],programList[i][0],))
return inputStage + 1
def inputProgWeights(c, inputStage):
c.execute("SELECT DISTINCT program FROM students;")
programList = c.fetchall()
programList.append("1st Year Arts")
programList.append("1st Year Science")
progWeightsList = UI.programWeightsInput.runApp(programList)
while not checkError(progWeightsList) and not len(programList) == len(progWeightsList):
UI.errorMessageBox.runApp(progWeightsList)
progWeightsList = UI.programWeightsInput.runApp(programList)
if checkBack(progWeightsList):
return inputStage - 1
if len(programList) == len(progWeightsList):
for i in range(len(progWeightsList[:-2])): #SQL updates for all programs "BSCH", "BAH" but NOT 1st year arts and science
c.execute("UPDATE program_info SET program_weight = ? WHERE program_name = ?;",(progWeightsList[i],programList[i][0]))
for i in range(len(progWeightsList)-2,len(progWeightsList)):
c.execute("SELECT COUNT (*) FROM program_info WHERE program_name = ?", (programList[i],))
checkExists = c.fetchone()
if checkExists == (0,): #happens when 1st year Arts and Science records DO NOT exist
c.execute("INSERT INTO program_info(program_name, program_weight) VALUES (?,?);",(programList[i],progWeightsList[i]))
elif checkExists == (1,): #happens when 1st year Arts and Science records DO exist
c.execute("UPDATE program_info SET program_weight = ? WHERE program_name = ?;", (progWeightsList[i],programList[i]))
return inputStage + 1
def runApp():
''' Runs all the functions in a loop
If the submit button is pressed for each app, the next app will shows
If the back button is pressed, the previous app will show up (data will be reentered entirely)
'''
conn = data.connectDB()
c = conn.cursor()
numOfFrames = 6
inputStage = 0 #initialize
while inputStage != numOfFrames:
if inputStage == 0:
inputStage = inputCredits(c,inputStage)
elif inputStage == 1:
inputStage = inputUnitFees(c,inputStage)
elif inputStage == 2:
inputStage = inputBIU(c,inputStage)
elif inputStage == 3:
inputStage = inputFormulaFees(c,inputStage)
elif inputStage == 4:
inputStage = inputNormalUnits(c,inputStage)
elif inputStage == 5:
inputStage = inputProgWeights(c,inputStage)
elif inputStage == -1: #when it is equal to -1 (go back on inputCredits)
inputStage = 0 #makes them input credits again
else:
break
try:
c.execute('''INSERT INTO timeRecord(time_id,timeStam)
VALUES (2,?);''',(dateTimeOutput.pythonTime(),))
except sqlite3.IntegrityError:
c.execute('''UPDATE timeRecord
SET timeStam = ?
WHERE time_id = 2;''',(dateTimeOutput.pythonTime(),))
conn.commit()
conn.close()
if __name__ == '__main__':
runApp()