-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dynamic DEVs - Student Registration System.py
271 lines (208 loc) · 7.72 KB
/
Dynamic DEVs - Student Registration System.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
import sqlite3
from os import system, name # os for clear function
from time import sleep
import getpass
# Connect to db
conn = sqlite3.connect('StudentInformation.db')
# Create cursor
c = conn.cursor()
# Create table
# Try except
try:
c.execute("""CREATE TABLE user (
username text,
fullname text,
email text,
passwd text
)
""")
except:
pass
try:
c.execute("""CREATE TABLE students (
studentId text,
name text,
reg_status text,
uId text
)
""")
except:
pass
# Create another table for courses and section
try:
c.execute("""CREATE TABLE courses (
reg_id text,
courses text,
section text
)
""")
except:
pass
# define our clear function
def clear():
# for windows
if name == 'nt':
_ = system('cls')
# for mac and linux(here, os.name is 'posix')
else:
_ = system('clear')
def reg_status_fn():
reg_input = int(input('\nRegistration Status: \n\t1. Completed 2. Partially Completed 3. Pending\nEnter 1, 2 or 3: '))
if reg_input == 1:
n = 'Completed'
elif reg_input == 2:
n = 'Partially Completed'
else:
n = 'Pending'
return n
def search_print(id_input,uId):
if id_input == 0:
clear()
print('\n\t-----------Searching (by Student ID)-----------\n\n')
id_input = input('ID Number: ')
print('Searching ',flush=True,end="")
sleep(0.5)
print('.',flush=True,end="")
sleep(0.5)
print('.',flush=True,end="")
sleep(0.3)
print('.',flush=True,end="")
c.execute("SELECT rowid, * FROM students WHERE studentId = ? AND uId = ?",(id_input,uId))
#c.execute("SELECT rowid, * FROM students WHERE uId = ?",(uId))
infos = c.fetchall()
#print(infos)
if len(infos)>=1:
c.execute("SELECT * FROM courses WHERE reg_id = ?",(str(infos[0][0]),))
infos_course = c.fetchall()
conn.commit()
print('\nHere is the Student Information:\n')
print(f'\tStudent ID: {id_input}')
print(f'\tName: {infos[0][2]}\n')
print('\t Courses Section')
for info in infos_course:
print('\t',info[1],'\t',info[2])
print(f'\n\tRegistration Status: {infos[0][3]}')
else:
print('\n\nNot found!!!')
input('\nPress any key to continue...')
def update_student(uId):
clear()
print('\n\t-----------Update Student Information-----------\n')
id_input = input("ID Number: ")
c.execute("SELECT rowid, * FROM students WHERE studentId = ? AND uId = ?",(id_input,uId))
infos = c.fetchall()
if len(infos)>=1:
print(f'\n\t-----------Update Information of ID: {id_input}------------\n\n')
print('\t\t1. Update Name\n\t\t2. Update Courses\n\t\t3. Update Registration Status\n\t\t4. Show Updated Information\n\n')
while True:
n = input("Enter 1, 2, 3 or 4: ")
if n =='1':
name = input("Enter Updated Name: ")
c.execute("UPDATE students SET name = ? WHERE studentId = ?",(name,id_input))
conn.commit()
elif n == '2':
reg_id = str(infos[0][0])
c.executemany("DELETE FROM courses WHERE reg_id = ?",reg_id)
course_sec = [tuple(x.split(':')) for x in input('Courses and Section: Input Style "CSE231:C" \nEnter all courses: \n').split()]
id_course_sec = [(reg_id,) + item for item in course_sec]
c.executemany("INSERT INTO courses VALUES (?,?,?)",id_course_sec)
conn.commit()
elif n == '3':
reg = reg_status_fn()
c.execute("UPDATE students SET reg_status = ? WHERE studentId = ?",(reg,id_input))
conn.commit()
elif n == '4':
search_print(id_input,uId)
return
else:
print("\nNot Found!!!")
input('\nPress any key to continue...')
def delete_student(uId):
clear()
print('\n\t-----------Deleting (by Student ID)-----------\n')
id_input = input('ID Number: ')
c.execute("SELECT rowid, * FROM students WHERE studentId = ? AND uId = ?",(id_input,uId))
infos = c.fetchall()
if len(infos)>=1:
c.execute("DELETE FROM students WHERE studentId = ?",(id_input,))
c.executemany("DELETE FROM courses WHERE reg_id = ?",(str(infos[0][0]),))
conn.commit()
print('Deleting ',flush=True,end="")
sleep(0.3)
print('.',flush=True,end="")
sleep(0.3)
print('.',flush=True,end="")
sleep(0.2)
print('.',flush=True,end="")
print('\nDeleted!!!')
#print('\nRegistration Deleted successfully of ID',id_input)
else:
print("Not Found!!!")
input('\nPress any key to continue...')
def add_student(uId):
clear()
# Inputing data
print('\n\t-----------Add Student (Enter these information Properly)-----------\n')
id_input = input('ID number: ')
name = input('\nName: ')
#print('Courses and Section: Input Style "CSE231:C" \nEnter all courses: ')
print()
course_sec = [tuple(x.split(':')) for x in input('Courses and Section: Input Style "CSE231:C" \nEnter all courses: \n\n').split()]
reg = reg_status_fn()
c.execute("INSERT INTO students VALUES (?,?,?,?)",(id_input,name,reg,uId))
reg_id = c.lastrowid
id_course_sec = [(reg_id,) + item for item in course_sec]
c.executemany("INSERT INTO courses VALUES (?,?,?)",id_course_sec)
conn.commit()
print('Registration Recorded of ID',id_input)
search_print(id_input,uId)
def menu(uId):
while True:
clear()
print('\n\t----------------Semester Registration System----------------\n\t\t\t By The Dynamic DEVs\n\n')
print('\t\t\t1. Add a New Student\n\t\t\t2. Search by Student ID\n\t\t\t3. Update Student Information\n\t\t\t4. Delete Registration Record\n\n')
n = input("Enter 1, 2, 3, 4 and 'e' for exit: ")
if n =='1': add_student(uId)
elif n == '2': search_print(0,uId)
elif n == '3': update_student(uId)
elif n == '4': delete_student(uId)
elif n == 'e': exit()
def login():
print('\n\n\t\t--------------Login--------------\n\n')
login_uname = input('\tUsername: ')
login_pass = getpass.getpass('\tPassword: ')
c.execute("SELECT rowid, * FROM user WHERE username = ? AND passwd = ?",(login_uname,login_pass))
info = c.fetchall()
if len(info)>=1:
menu(str(info[0][0]))
else:
print('\n\nYour Username or Password are incorrect! Please Try again!')
n = input("Press 1. Register or 2. Login: ")
if n=='1':
register()
else:
login()
def register():
print('\n\n\t\t--------------Create an Account--------------\n\n')
reg_uname = input('\tUsername: ')
reg_name = input('\tFull Name: ')
reg_email = input('\tEmail: ')
reg_pass = input('\tPassword: ')
reg_conf_pass = input('\tConfirm Password: ')
if reg_pass == reg_conf_pass:
c.execute("INSERT INTO user VALUES (?,?,?,?)",(reg_uname,reg_name,reg_email,reg_pass))
conn.commit()
print("Successfully Registered!!! Now Login!\n\n")
login()
else:
print("Password does not match! Try again!")
input("Press any key for try again! ")
register()
# Login Screen
clear()
print('\n\t----------------Semester Registration System----------------\n\t\t\t By The Dynamic DEVs\n\n')
print('\t\t\t1. Login 2. Register\n\n')
choose = input('Enter 1 or 2: ')
if choose == '1': login()
elif choose == '2': register()
else: exit()