-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbmsEnrollCalc.py
202 lines (143 loc) · 6.31 KB
/
dbmsEnrollCalc.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
#-------------------------------------------------------------------------------
# Name: main, imports all the modules and runs them
# Purpose: shows the main menu
# main loop contains the sequence of events and workflow
#
#
# Author: DBMS
#
# Created: 05/08/2014
# Copyright: (c) DBMS 2014
# Licence: <your licence>
#-------------------------------------------------------------------------------
import os
import sys
import sqlite3
import preprocess
import writeToExcel
import updateConstants
import excelPreprocess
import UI
import extractData as data
import dateTimeOutput
class Instance:
def __init__(self):
self.menu = True
self.dataDirectory = False
self.dataLocation = False
self.MainLoop()
def MainLoop(self):
''' Main loop of program. The menu tk app returns strings based on the button pressed.
'''
#self.DatabaseSetup()
while self.menu != "QUIT APPLICATION":
self.DatabaseSetup()
self.Instructions()
self.menu = UI.mainMenu.runApp(self.instructionList)
if self.menu == "Import Student and Course Data":
self.dataLocation = False
while self.dataLocation is False:
self.SetDataLocation() #keeps on asking for the data location
if self.dataLocation != False : #as long as the dataLocation is valid, the database will be updated
self.UpdateData(self.dataLocation)
UI.messageOutputBox.runApp(["Student and course data have been succesfully imported."])
elif self.menu == "Update Program Data":
if self.noStudData: #cannot update the program data if no courses have been imported
UI.errorMessageBox.runApp("Please Import student and course data first.")
elif not self.noStudData:
self.UpdateConstants()
UI.messageOutputBox.runApp(["Program and BIU data have been successfully imported."])
elif self.menu == "View Data":
if self.noStudData and self.noBIUData: #cannot process excel spreadsheets if no data is present
UI.errorMessageBox.runApp("Please Import student and course data and Update program data.")
else:
self.OutputExcel()
#UI.messageOutputBox.runApp(["Sheet was saved successfully."]) #for some reason this will kill the tkinter root window of the main menu too
elif self.menu == "DELETE DATABASE":
''' This option is shown under the menu bar
'''
self.DeleteDatabase()
sys.exit()
def SetDataLocation(self):
'''See if the directory with spreadsheets exists
Then check the contents of the sheets. If they cannot be processed (does not have appropriate headings),
TypeError is returned and the dataLocation is False
'''
userApproved = False
while not userApproved:
self.dataLocation = UI.askDataDirectory.runApp() #asks user for the data location
self.excelExtension = "xls"
self.dirExist = preprocess.checkDirectory(self.dataLocation, self.excelExtension) #checks if the data is valid (True or False)
if self.dirExist:
self.filesList = excelPreprocess.findFiles(self.dataLocation, self.excelExtension)
self.sheetAddressList = excelPreprocess.findSheetAddresses(self.dataLocation)
try:
self.courseCodes = excelPreprocess.checkCourseCode(self.filesList, self.sheetAddressList)
userApproved = UI.gridBoxScrolling.runApp(self.courseCodes) #user can submit (userApproved = True) or go back (userApproved = False)
except TypeError:
UI.errorMessageBox.runApp("The spreadsheets in the directory are not valid.")
self.dataLocation = False
else:
self.dataLocation = False
UI.errorMessageBox.runApp("The directory does not have spreadsheets.")
def Instructions(self):
''' This method generates the instructions used to direct the user.
Checks the database for timestamp records to see if data exists.
If all the data is present, it will ask the user to just 'View Data'
'''
self.instructionList = []
''' Checks for a time stamp on the students and courses tables (imported from Excel)
'''
self.noStudData = False
try:
self.timeStamStud = data.grabTimeStamp(self.c,"Student Data")
except TypeError: #if there is no time stamp value, it means no data has been imported
self.noStudData = True
except sqlite3.OperationalError: #if there is no db available
self.noStudData = True
if self.noStudData: #IF THERE IS NO STUDENT DATA
self.instructionList.append("No student or course data has been imported.\n Please 'Import Student and Course Data' first.")
elif not self.noStudData: #IF THERE IS STUDENT DATA
self.instructionList.append("Student and course data was imported at " + str(self.timeStamStud) + "\n You do not need to import student and course data.")
''' Checks for a time stamp on the program data tables (inputted by user)
'''
self.noBIUData = False
try:
self.timeStamBIU = data.grabTimeStamp(self.c,"BIU Data")
except TypeError:
self.noBIUData = True
except sqlite3.OperationalError:
self.noBIUData = True
if self.noBIUData: #IF THERE IS NO BIU DATA
self.instructionList.append("No program or BIU data has been imported. \n Please 'Update Program Data.'")
elif not self.noBIUData: #IF THERE IS BIU DATA
self.instructionList.append("Program and BIU data was imported at " + str(self.timeStamBIU) + "\n You do not need to update program data, unless the student \n and course data was updated after the program data.")
self.instructionList.append("Please select 'View Data' to access the data. A spreadsheet\n will be output with the requested data.")
def DatabaseSetup(self):
''' Used every loop in the main menu loop
'''
self.conn = data.connectDB()
self.c = self.conn.cursor()
def OutputExcel(self):
writeToExcel.runApp()
def UpdateData(self,dataLocation):
preprocess.main(dataLocation)
def UpdateConstants(self):
updateConstants.runApp()
def DeleteDatabase(self):
''' Needs to close the DB. Then it will delete the DB
'''
self.conn.close()
cdLocation = os.getcwd()
dbName = "\\enrolldata.db"
dbLocation = cdLocation + dbName
try:
os.remove(dbLocation)
except WindowsError: #WindowsError appreas when there is no database file
pass
def main():
program = Instance()
del program #kill the object
if __name__ == '__main__':
main()
#make sure all excel files are closed