-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmager.py
More file actions
233 lines (220 loc) · 7.39 KB
/
Copy pathmager.py
File metadata and controls
233 lines (220 loc) · 7.39 KB
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
import mysql
from A1 import display_menu, Verfication, login
#make action for the stu menu
def stuRole(user_id):
while True:
display_menu("stu")
choice = input("Enter your choice: ")
if choice == "1":
student_classes(user_id)
elif choice == "2":
drop_class(user_id)
elif choice == "3":
break
else:
print("Please enter a valid choice")
#check student classes
def student_classes(user_id):
conn = Verfication()
if conn:
try:
cursor = conn.cursor()
query = """
SELECT r.class,r.code
FROM roster r
JOIN rosterclass rc ON r.ID = rc.rosterid
WHERE rc.userid = %s
"""
cursor.execute(query, (user_id,))
classes = cursor.fetchall()
cursor.close()
if classes:
print("\nYour Classes:")
for c in classes:
print(f"{c[0]} - {c[1]}")
else:
print("\nYou have no classes yet")
except mysql.connector.Error as err:
print(f"Something went wrong trying to view classes: {err}")
finally:
conn.close()
#drop the student classes
def drop_class(user_id):
conn = Verfication()
if conn:
try:
cursor = conn.cursor()
student_classes(user_id)
class_id = int(input("Enter class ID: "))
query = """
DELETE FROM rosterclass WHERE userid = %s
AND rosterid = %s
"""
cursor.execute(query, (user_id,class_id))
conn.commit()
cursor.close()
print("\nClass Deleted")
except mysql.connector.Error as err:
print(f"Something went wrong trying to delete class: {err}")
except ValueError:
print("\nClass ID is not valid")
finally:
conn.close()
#set the actions to the manager menu
def mangerRole(user_id):
while True:
display_menu("mgr")
choice = input("Enter your choice: ")
if choice == "1":
view_student_classes()
elif choice == "2":
view_rosters()
elif choice == "3":
add_student_to_rosters()
elif choice == "4":
drop_student_from_rosters()
elif choice == "5":
add_student()
elif choice == "6":
break
else:
print("Please enter a valid choice")
#allow the sudent to view their classes
def view_student_classes():
conn = Verfication()
if conn:
try:
cursor = conn.cursor()
student_id = int(input("Enter student ID: "))
query = """
SELECT r.class,r.code
FROM roster r
JOIN rosterclass rc ON r.ID = rc.rosterid
WHERE rc.userid = %s
"""
cursor.execute(query, (student_id,))
schedule = cursor.fetchall()
cursor.close()
if schedule:
print("\nStudent Class Viewed")
for c in schedule:
print(f"{c[0]} - {c[1]}")
else:
print("\nStudent have no classes yet")
except mysql.connector.Error as err:
print(f"Something went wrong trying to view classes: {err}")
except ValueError:
print("\nID is not valid")
finally:
conn.close()
#alllow to check roster of particular class
def view_rosters():
conn = Verfication()
if conn:
try:
cursor = conn.cursor()
print("For USER ID enter 2 its the available class")
classid = int(input("Enter User ID: "))
query = """
SELECT u.fname, u.lname
FROM USERS u
JOIN rosterclass rc ON u.id = rc.userid
WHERE rc.userid = %s
"""
cursor.execute(query, (classid,))
rosters = cursor.fetchall()
cursor.close()
if rosters:
print("\nRoster Viewed")
for r in rosters:
print(f"{r[0]} - {r[1]}")
else:
print("\nStudents not enrolled in this class")
except mysql.connector.Error as err:
print(f"Something went wrong trying to view rosters: {err}")
except ValueError:
print("\nID is not valid")
finally:
conn.close()
#let us be able to add students to rosters
def add_student_to_rosters():
conn = Verfication()
if conn:
try:
cursor = conn.cursor()
student_id = int(input("Enter student ID: "))
print("For class ID enter 1 its the available class")
class_id = int(input("Enter class ID: "))
query = """
INSERT INTO rosterclass (userid, rosterid) VALUES (%s, %s)
"""
cursor.execute(query, (student_id, class_id))
conn.commit()
cursor.close()
print("Student Added to Roster")
except mysql.connector.Error as err:
print(f"Something went wrong trying to add student to roster: {err}")
except ValueError:
print("\nID is not valid")
finally:
conn.close()
#manger can drop student from roster
def drop_student_from_rosters():
conn = Verfication()
if conn:
try:
cursor = conn.cursor()
student_id = int(input("Enter student ID: "))
class_id = int(input("Enter class ID: "))
query= """
DELETE FROM rosterclass WHERE userid = %s
AND rosterid = %s
"""
cursor.execute(query, (student_id, class_id))
conn.commit()
cursor.close()
print("\nStudent Removed from Roster Successfully")
except mysql.connector.Error as err:
print(f"Something went wrong trying to remove student from roster: {err}")
except ValueError:
print("\nID is not valid")
finally:
conn.close()
#add student to database
def add_student():
conn = Verfication()
if conn:
try:
cursor = conn.cursor()
username = input("Enter username: ")
userpassword = input("Enter password: ")
roleID = "stu"
fname = input("Enter first name: ")
lname = input("Enter last name: ")
majorID = input("Enter major ID: ")
query = """
INSERT INTO Users (username, userpassword, roleID, fname, lname, majorID) VALUES (%s, %s, %s, %s, %s, %s)
"""
cursor.execute(query, (username, userpassword, roleID, fname, lname, majorID))
conn.commit()
cursor.close()
print("Student Added to Successfully")
except mysql.connector.Error as err:
print(f"Something went wrong trying to add student to roster: {err}")
except ValueError:
print("\nmajor is not valid")
finally:
conn.close()
def main():
#main method
user = login(input("Username: "), input("Password: "))
if user:
print(f"\nWelcome, {user[1]}! (Role: {user[2]})")
if user[2] == "stu":
stuRole(user[0])
elif user[2] == "mgr":
mangerRole(user[0])
else:
print("\nLogin failed. Exiting.")
if __name__ == "__main__":
main()