├── .gitattributes
├── .gitignore
├── LICENSE
├── README.md
├── main.py
├── requirements.txt
└── src
├── __init__.py
├── assets.py
├── classes.py
├── mysql_database.py
├── student.py
└── teacher.py
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | __pycache__
2 | .env
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |

2 | SCHOOL MANAGEMENT SYSTEM
3 |
4 |
5 |
6 | # Requirements
7 | * [MySQL Database](https://www.mysql.com/downloads/)
8 | * Install the packages in requirements.txt
9 | ```
10 | [+] Open Terminal on the root directory and run the following
11 | [-] pip install -r requirements.txt
12 | ```
13 |
14 | # Enviroment Variables
15 | ```
16 | [+] Create a .env file in the root directory for the MySQL parameters
17 | [-] MYSQL_HOST = ''
18 | [-] MYSQL_PORT = ''
19 | [-] MYSQL_USER = ''
20 | [-] MYSQL_PASSWORD = ''
21 | [-] MYSQL_DATABASE = ''
22 | ```
23 |
24 | # Procedure
25 | * Fork the Repository [click here](https://github.com/akkupy/School-Management-System/fork)
26 | * Clone the repository
27 | * Create a .env file with Environment Variables listed above in the root directory of the cloned folder.
28 | * Run the main.py file.
29 |
30 | # Screenshots
31 |
32 | 
33 |
34 |
35 | # Listen A Sec
36 | * Feel free to report any bugs!
37 | * Star if you like it:)
38 | * Can be used as school project,etc.
39 |
40 |
--------------------------------------------------------------------------------
/main.py:
--------------------------------------------------------------------------------
1 | # SCHOOL MANAGEMENT SYSTEM...
2 |
3 | # Importing
4 | from typing import Final
5 | from time import sleep
6 | from sys import exit
7 | import mysql.connector as msc
8 | import src
9 | from dotenv import load_dotenv,find_dotenv
10 | from os import getenv
11 | from getpass import getpass
12 | from rich.console import Console
13 | from rich import print as rprint
14 | from rich.table import Table
15 |
16 | load_dotenv(find_dotenv())
17 | console = Console()
18 |
19 | # Declaring ENV Variables
20 |
21 | MYSQL_HOST: Final = getenv('MYSQL_HOST')
22 | MYSQL_PORT: Final = getenv('MYSQL_PORT')
23 | MYSQL_USER: Final = getenv('MYSQL_USER')
24 | MYSQL_PASSWORD: Final = getenv('MYSQL_PASSWORD')
25 | MYSQL_DATABASE: str = getenv('MYSQL_DATABASE')
26 |
27 | rprint(r'''
28 | [green]
29 | ____ _ _ __ __ _ ____ _
30 | / ___| ___| |__ ___ ___ | | | \/ | __ _ _ __ __ _ __ _ ___ _ __ ___ ___ _ __ | |_ / ___| _ _ ___| |_ ___ _ __ ___
31 | \___ \ / __| '_ \ / _ \ / _ \| | | |\/| |/ _` | '_ \ / _` |/ _` |/ _ | '_ ` _ \ / _ | '_ \| __| \___ \| | | / __| __/ _ | '_ ` _ \
32 | ___) | (__| | | | (_) | (_) | | | | | | (_| | | | | (_| | (_| | __| | | | | | __| | | | |_ ___) | |_| \__ | || __| | | | | |
33 | |____/ \___|_| |_|\___/ \___/|_| |_| |_|\__,_|_| |_|\__,_|\__, |\___|_| |_| |_|\___|_| |_|\__| |____/ \__, |___/\__\___|_| |_| |_|
34 | |___/ |___/
35 | [/green][bold blue]
36 | CREDITS : akkupy.me
37 | [/ bold blue]
38 | ''')
39 |
40 |
41 |
42 |
43 |
44 | def main():
45 |
46 | rprint("Enter the password")
47 | inputPassword: str = getpass(':')
48 |
49 | src.Enter()
50 |
51 | with console.status("[bold green]Verifying Password..") as status:
52 | sleep(3)
53 | if inputPassword != MYSQL_PASSWORD:
54 | console.log("[bold red]ACCESS DENIED![/bold red]")
55 | exit()
56 | else:
57 | console.log("[green]Password Verified![/green]")
58 |
59 | with console.status("[bold green]Checking for MYSQL Connection..") as status:
60 | sleep(3)
61 | try:
62 | connection = msc.connect(host = MYSQL_HOST , port = MYSQL_PORT , user = MYSQL_USER , passwd = MYSQL_PASSWORD)
63 | cursor = connection.cursor()
64 | if connection.is_connected():
65 | console.log(f"[green]Connection Established ![/green]")
66 | except:
67 | console.log(f'[bold][red]Unable to Connect to MYSQL Server ')
68 | exit()
69 |
70 |
71 | with console.status("[bold green]Checking for Database..") as status:
72 | sleep(2)
73 | if MYSQL_DATABASE == '':
74 | console.log(f'[bold][red]Database Not Defined. ')
75 | database = False
76 | else:
77 | database = MYSQL_DATABASE
78 | console.log(f'[bold][green]Database Found. ')
79 |
80 | if not database:
81 | database = src.create_database(cursor,console)
82 | connection = msc.connect(host = MYSQL_HOST , port = MYSQL_PORT , user = MYSQL_USER , passwd = MYSQL_PASSWORD , database = database)
83 | cursor = connection.cursor()
84 | src.create_table(cursor,console)
85 |
86 | while True:
87 | src.Enter()
88 | table = Table(title="Akkupy School")
89 | table.add_column("S. No.", style="cyan", no_wrap=True)
90 | table.add_column("Section", style="magenta")
91 | table.add_row("1","Students")
92 | table.add_row("2","Teachers")
93 | table.add_row("3","Classes")
94 | table.add_row("4","Exit")
95 | console.print(table)
96 | sectionValue = src.Choice("Enter a Choice(1,2,3,4)", [1, 2, 3, 4])
97 |
98 | match sectionValue:
99 | case 1:
100 | src.Student(cursor,connection,console)
101 | case 2:
102 | src.Teachers(cursor,connection,console)
103 | case 3:
104 | src.Class(cursor,connection,console)
105 | case 4:
106 | with console.status("[red bold]Quitting Program....[/red bold]") as status:
107 | sleep(3)
108 | connection.close()
109 | console.log("[bold red] Bye.[/bold red]")
110 | exit()
111 |
112 |
113 |
114 | if __name__=="__main__":
115 | main()
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | markdown-it-py==3.0.0
2 | mdurl==0.1.2
3 | mysql-connector==2.2.9
4 | mysql-connector-python==8.0.22
5 | protobuf==4.24.3
6 | Pygments==2.16.1
7 | python-dotenv==1.0.0
8 | rich==13.5.2
9 |
--------------------------------------------------------------------------------
/src/__init__.py:
--------------------------------------------------------------------------------
1 | from .teacher import Teachers,Addteachers,Displayteachers,EditTeacher,EditTeacher2,RemoveTeacher
2 | from .mysql_database import create_database,create_table
3 | from .assets import Enter,Star,Lag,Checker,Choice
4 | from .student import Addstudent,EditStudent,Removestudent,Displaystudent,Student,EditStudent2
5 | from .classes import AddClass,RemoveClass,EditClass,EditClass2,DisplayClass,Class
6 |
--------------------------------------------------------------------------------
/src/assets.py:
--------------------------------------------------------------------------------
1 | from rich import print as rprint
2 |
3 | # Def1:SPACE
4 | def Enter():
5 | print()
6 |
7 |
8 | # Def2:HORIZONTAL LINE
9 | def Star():
10 | print('=' * 121)
11 |
12 |
13 | # Def21:ENTER KEY FUNCTION
14 | def Lag():
15 | rprint("Press ENTER KEY to Continue")
16 | input("")
17 |
18 |
19 | # Def22:INTEGER RETREIVAL CHECKING
20 | def Checker(inputString: str, type: str = 'foo'):
21 | if type == "int":
22 | try:
23 | Enter()
24 | rprint(inputString)
25 | userInput = int(input(':'))
26 | return userInput
27 | except:
28 | Enter()
29 | rprint("[bold red]ERROR : Enter As per Instruction")
30 | return Checker(inputString, type)
31 |
32 |
33 | # Choice Picker
34 | def Choice(inputString: str, inputRange: list):
35 | try:
36 | Enter()
37 | rprint(inputString)
38 | inputChoice = int(input(':'))
39 | if inputChoice in inputRange:
40 | return inputChoice
41 | else:
42 | Enter()
43 | rprint(f"[bold red]ERROR : Enter the choice from {inputRange}")
44 | return Choice(inputString, inputRange)
45 | except:
46 | Enter()
47 | rprint(f"[bold red]ERROR : Enter the choice from {inputRange}")
48 | return Choice(inputString, inputRange)
--------------------------------------------------------------------------------
/src/classes.py:
--------------------------------------------------------------------------------
1 | from .assets import *
2 | from rich import print as rprint
3 | from rich.table import Table
4 | from time import sleep
5 |
6 | # Def5:CLASS MAIN MENU
7 | def Class(cursor,connection,console):
8 | while True:
9 |
10 | Enter()
11 | table = Table(title="Class")
12 | table.add_column("S. No.", style="cyan", no_wrap=True)
13 | table.add_column("Section", style="magenta")
14 | table.add_row("1","Add a Class")
15 | table.add_row("2","Display all classes")
16 | table.add_row("3","Edit the Class")
17 | table.add_row("4","Remove a Class")
18 | table.add_row("5","Go Back (Main Menu)")
19 | console.print(table)
20 | sectionValue = Choice("Enter a Choice(1,2,3,4,5)", [1, 2, 3, 4, 5])
21 |
22 | if sectionValue == 1:
23 | AddClass(cursor,connection,console)
24 | elif sectionValue == 2:
25 | DisplayClass(cursor,console)
26 | elif sectionValue == 3:
27 | EditClass(cursor,connection,console)
28 | elif sectionValue == 4:
29 | RemoveClass(cursor,connection,console)
30 | else:
31 | break
32 |
33 | def AddClass(cursor,connection,console):
34 |
35 | numberOfClasses = Checker("Enter the Number of Classes to Add:", "int")
36 |
37 | for i in range(numberOfClasses):
38 |
39 | rprint("\n[bold violet]ENTER THE DETAILS OF THE CLASS\n")
40 |
41 | cursor.execute("select * from Class")
42 | allClasses = cursor.fetchall()
43 | defaultCLassID = len(allClasses) + 1
44 |
45 |
46 | rprint("\nDefault Class ID:", defaultCLassID)
47 |
48 | classNum = Checker("Enter the Class(Max 2 Digits):", "int")
49 |
50 | rprint("\nEnter the Division(Max 3 Characters)")
51 | classDiv = input(":")
52 | rprint("\nEnter the Class Teacher(Max 20 Characters)")
53 | classTeacher = input(":")
54 | classNumStudents = Checker("Enter the Number Of Students(Max 3 Digits):", "int")
55 | rprint("\nEnter Subject 1(Max 20 Characters)")
56 | classSubject1 = input(":")
57 | rprint("\nEnter Subject 2(Max 20 Characters)")
58 | classSubject2 = input(":")
59 | rprint("\nEnter Subject 3(Max 20 Characters)")
60 | classSubject3 = input(":")
61 | rprint("\nEnter Subject 4(Max 20 Characters)")
62 | classSubject4 = input(":")
63 | rprint("\nEnter Subject 5(Max 20 Characters)")
64 | classSubject5 = input(":")
65 |
66 | try:
67 | cursor.execute(
68 | "insert into Class values({},{},'{}','{}',{},'{}','{}','{}','{}','{}')".format(defaultCLassID, classNum, classDiv, classTeacher, classNumStudents, classSubject1, classSubject2, classSubject3, classSubject4, classSubject5))
69 | connection.commit()
70 |
71 | Enter()
72 | with console.status("[bold green]Adding Details to Database...") as status:
73 | sleep(2)
74 | console.log(f'[bold][green]Class Created Successfully.. ')
75 | Enter()
76 | Lag()
77 | Enter()
78 |
79 | except:
80 |
81 | Enter()
82 | rprint("[bold red]ERROR : Invalid Details Entered.")
83 | Enter()
84 |
85 | wish = Choice("Do You Wish To Retry Or Go Back(Main Menu) (1/2):", [1, 2])
86 | if wish == 1:
87 | AddClass(cursor,connection,console)
88 | if wish == 2:
89 | return 0
90 |
91 | def DisplayClass(cursor,console):
92 | def allClasses():
93 |
94 | Enter()
95 | cursor.execute("select * from Class")
96 |
97 | table = Table(title="Display All Classes")
98 | table.add_column("Class ID", style="cyan", no_wrap=True)
99 | table.add_column("Class", style="magenta")
100 | table.add_column("Division", style="magenta")
101 | table.add_column("Class Teacher", style="magenta")
102 | table.add_column("No: Of Students", style="magenta")
103 | table.add_column("Subject 1", style="magenta")
104 | table.add_column("Subject 2", style="magenta")
105 | table.add_column("Subject 3", style="magenta")
106 | table.add_column("Subject 4", style="magenta")
107 | table.add_column("Subject 5", style="magenta")
108 | for i in cursor:
109 | if i[0] == 0:
110 | continue
111 | table.add_row(str(i[0]),str(i[1]),i[2],i[3],str(i[4]),i[5],i[6],i[7],i[8],i[9])
112 | console.print(table)
113 |
114 | Enter()
115 | Lag()
116 |
117 | def classWithTeacher():
118 |
119 | Enter()
120 | cursor.execute("select class,division,class_teacher,class_id from Class")
121 |
122 | table = Table(title="Display Class With Class Teacher")
123 | table.add_column("Class ID", style="cyan", no_wrap=True)
124 | table.add_column("Class", style="magenta")
125 | table.add_column("Division", style="magenta")
126 | table.add_column("Class Teacher", style="magenta")
127 | for i in cursor:
128 | if i[3] == 0:
129 | continue
130 | table.add_row(str(i[3]),str(i[0]),i[1],i[2])
131 | console.print(table)
132 |
133 | Enter()
134 | Lag()
135 |
136 |
137 | def classWithStudent():
138 |
139 | Enter()
140 | cursor.execute("select class,division,no_of_students,class_id from Class")
141 |
142 | table = Table(title="Display Class With Number OF Students")
143 | table.add_column("Class ID", style="cyan", no_wrap=True)
144 | table.add_column("Class", style="magenta")
145 | table.add_column("Division", style="magenta")
146 | table.add_column("Number OF Students", style="magenta")
147 | for i in cursor:
148 | if i[3] == 0:
149 | continue
150 | table.add_row(str(i[3]),str(i[0]),i[1],str(i[2]))
151 | console.print(table)
152 |
153 | Enter()
154 | Lag()
155 |
156 |
157 | while True:
158 |
159 | Enter()
160 | table = Table(title="Display Classes")
161 | table.add_column("S. No.", style="cyan", no_wrap=True)
162 | table.add_column("Section", style="magenta")
163 | table.add_row("1","Display All Classes")
164 | table.add_row("2","Display Class With Class Teacher")
165 | table.add_row("3","Display Class With Number of Students")
166 | table.add_row("4","Back")
167 | console.print(table)
168 | sectionValue = Choice("Enter a Choice(1,2,3,4)", [1, 2, 3, 4])
169 |
170 | if sectionValue == 1:
171 | allClasses()
172 | elif sectionValue == 2:
173 | classWithTeacher()
174 | elif sectionValue == 3:
175 | classWithStudent()
176 | else:
177 | break
178 |
179 |
180 | def EditClass(cursor,connection,console):
181 |
182 | Enter()
183 | cursor.execute("select * from Class")
184 |
185 | table = Table(title="Display All Classes")
186 | table.add_column("Class ID", style="cyan", no_wrap=True)
187 | table.add_column("Class", style="magenta")
188 | table.add_column("Division", style="magenta")
189 | for i in cursor:
190 | if i[0] == 0:
191 | continue
192 | table.add_row(str(i[0]),str(i[1]),i[2])
193 | console.print(table)
194 |
195 | classID = Checker("Enter the Class ID:", "int")
196 | Enter()
197 | classes = []
198 | cursor.execute("select * from Class")
199 | for i in cursor:
200 | if i[0] == 0:
201 | continue
202 | classes.append(i[0])
203 | if classID in classes:
204 | EditClass2(classID,cursor,connection,console)
205 | else:
206 | rprint("[bold red]ERROR : Enter A Valid Class ID")
207 | Lag()
208 | return 0
209 |
210 |
211 |
212 | def EditClass2(classID,cursor,connection,console):
213 |
214 | Enter()
215 | table = Table(title="Choose What to Edit")
216 | table.add_column("S. No.", style="cyan", no_wrap=True)
217 | table.add_column("Section", style="magenta")
218 | table.add_row("1","Class")
219 | table.add_row("2","Division")
220 | table.add_row("3","Class Teacher")
221 | table.add_row("4","Number Of Students")
222 | table.add_row("5","Subject 1")
223 | table.add_row("6","Subject 2")
224 | table.add_row("7","Subject 3")
225 | table.add_row("8","Subject 4")
226 | table.add_row("9","Subject 5")
227 | table.add_row("10","Exit")
228 | console.print(table)
229 | sectionValue = Choice("Enter Your Choice(1,2,3,4,5,6,7,8,9,10)", [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
230 |
231 | match sectionValue:
232 | case 1:
233 | value = Checker("Enter the Class (Max 2 Digits)", "int")
234 | sqlCol = 'class'
235 | case 2:
236 | rprint("\nEnter the Division(Max 3 Characters)")
237 | value = input(":")
238 | sqlCol = 'division'
239 | case 3:
240 | rprint("\nEnter the Class Teacher(Max 20 Characters)")
241 | value = input(":")
242 | sqlCol = 'class_teacher'
243 | case 4:
244 | value = Checker("Enter the No: of Students(Max 3 Digits)", "int")
245 | sqlCol = 'no_of_students'
246 | case 5:
247 | rprint("\nEnter the Subject 1(Max 20 Characters)")
248 | value = input(":")
249 | sqlCol = 'subject1'
250 | case 6:
251 | rprint("\nEnter the Subject 2(Max 20 Characters)")
252 | value = input(":")
253 | sqlCol = 'subject2'
254 | case 7:
255 | rprint("\nEnter the Subject 3(Max 20 Characters)")
256 | value = input(":")
257 | sqlCol = 'subject3'
258 | case 8:
259 | rprint("\nEnter the Subject 4(Max 20 Characters)")
260 | value = input(":")
261 | sqlCol = 'subject4'
262 | case 9:
263 | rprint("\nEnter the Subject 5(Max 20 Characters)")
264 | value = input(":")
265 | sqlCol = 'subject5'
266 | case 10:
267 | return 0
268 |
269 | try:
270 | if type(value) is int:
271 | query = f"update Class set {sqlCol}={value} where class_id={classID}"
272 | cursor.execute(query)
273 | else:
274 | query = f"update Class set {sqlCol}='{value}' where class_id={classID}"
275 | cursor.execute(query)
276 | connection.commit()
277 |
278 | Enter()
279 | with console.status("[bold green]Updating Details in Database...") as status:
280 | sleep(2)
281 | console.log(f'[bold][green]Class Updated Successfully.. ')
282 | Enter()
283 | Lag()
284 | Enter()
285 |
286 | except:
287 |
288 | Enter()
289 | rprint("[bold red]ERROR : Invalid Value Entered.")
290 | Enter()
291 | Lag()
292 | return 0
293 |
294 | def RemoveClass(cursor,connection,console):
295 |
296 | Enter()
297 | cursor.execute("select * from Class")
298 |
299 | table = Table(title="Display All Classes")
300 | table.add_column("Class ID", style="cyan", no_wrap=True)
301 | table.add_column("Class", style="magenta")
302 | table.add_column("Division", style="magenta")
303 | for i in cursor:
304 | if i[0] == 0:
305 | continue
306 | table.add_row(str(i[0]),str(i[1]),i[2])
307 | console.print(table)
308 |
309 | Enter()
310 | classID = Checker("Enter the Class ID", "int")
311 | classIDList = []
312 | cursor.execute("select class_id from Class")
313 | for i in cursor:
314 | if i[0] == 0:
315 | continue
316 | classIDList.append(i[0])
317 | if classID in classIDList:
318 | try:
319 | cursor.execute("delete from Class where class_id={}".format(classID))
320 | connection.commit()
321 |
322 | Enter()
323 | with console.status("[bold green]Deleting from Database...") as status:
324 | sleep(2)
325 | console.log(f'[bold][green]Class with ID {classID} is Deleted Successfully.. ')
326 | Enter()
327 | Lag()
328 | Enter()
329 |
330 | except:
331 | Enter()
332 | rprint("[bold red]ERROR : Cannot Delete The Class As It Is Used In Other Tables.")
333 | Enter()
334 | rprint(f"[bold green]HINT : Delete All The Records Which Use {classID} As Class ID From Other Tables")
335 | Enter()
336 | Lag()
337 | return 0
338 | else:
339 | Enter()
340 | rprint("[bold red]ERROR : Enter A Valid Class ID")
341 | Enter()
342 | Lag()
343 | return 0
--------------------------------------------------------------------------------
/src/mysql_database.py:
--------------------------------------------------------------------------------
1 | from .assets import *
2 | from time import sleep
3 | # TABLE CREATION
4 | def create_table(cursor,console):
5 |
6 | with console.status("[bold green]Checking/Creating Class Table..") as status:
7 | sleep(2)
8 | query = "CREATE TABLE if not exists Class(class_id int(5) PRIMARY KEY,class int(2),division varchar(10),class_teacher varchar(50),no_of_students int(3),subject1 varchar(20),subject2 varchar(20),subject3 varchar(20),subject4 varchar(20),subject5 varchar(20));"
9 | cursor.execute(query)
10 | cursor.execute("select * from Class")
11 | flag = False
12 | for i in cursor:
13 | if i[0] == 0:
14 | flag = True
15 | if not flag:
16 | query = "insert into Class values({},{},'{}','{}',{},'{}','{}','{}','{}','{}')".format(0, 0, 'Class 0', 'For Non Class Teacher', 0, 'Nil', 'Nil', 'Nil', 'Nil', 'Nil')
17 | cursor.execute(query)
18 | console.log(f"[green]Done.[/green]")
19 |
20 | with console.status("[bold green]Checking/Creating Students Table..") as status:
21 | sleep(2)
22 | query = "CREATE TABLE if not exists Students(Admission_No int(10) PRIMARY KEY,student_name varchar(30) NOT NULL, date_of_birth date,date_of_joining date, gender varchar(2),address varchar(50),ph_no varchar(11),class_id int(5));"
23 | cursor.execute(query)
24 | query = "ALTER TABLE Students Add FOREIGN KEY(class_id) references Class(class_id);"
25 | cursor.execute(query)
26 | console.log(f"[green]Done.[/green]")
27 |
28 | with console.status("[bold green]Checking/Creating Teachers Table..") as status:
29 | sleep(2)
30 | query = "CREATE TABLE if not exists Teachers(teachers_id int(5)PRIMARY KEY,teachers_name varchar(30) NOT NULL,department varchar(20),date_of_joining date,gender varchar(2),address varchar(50), ph_no varchar(11),class_id int(5) DEFAULT 0);"
31 | cursor.execute(query)
32 | query = "ALTER TABLE Teachers Add FOREIGN KEY(class_id) references Class(class_id);"
33 | cursor.execute(query)
34 | console.log(f"[green]Done.[/green]")
35 |
36 |
37 | # CREATE NEW DATABASE
38 | def create_database(cursor,console):
39 | with console.status("[bold green]Creating New Database..") as status:
40 | sleep(3)
41 | query = "CREATE DATABASE IF NOT EXISTS school;"
42 | cursor.execute(query)
43 | console.log("[green]Database Created![/green]")
44 | return 'school'
45 |
--------------------------------------------------------------------------------
/src/student.py:
--------------------------------------------------------------------------------
1 | from .assets import *
2 | from rich import print as rprint
3 | from rich.table import Table
4 | from time import sleep
5 |
6 | # STUDENT MAIN MENU
7 | def Student(cursor,connection,console):
8 | while True:
9 |
10 | Enter()
11 | table = Table(title="Students")
12 | table.add_column("S. No.", style="cyan", no_wrap=True)
13 | table.add_column("Section", style="magenta")
14 | table.add_row("1","Add a Student")
15 | table.add_row("2","Display Students")
16 | table.add_row("3","Edit the Details")
17 | table.add_row("4","Remove a Student")
18 | table.add_row("5","Go Back (Main Menu)")
19 | console.print(table)
20 | sectionValue = Choice("Enter a Choice(1,2,3,4,5)", [1, 2, 3, 4, 5])
21 |
22 | match sectionValue:
23 | case 1:
24 | r = Addstudent(cursor,connection,console)
25 | if r == 1:
26 | break
27 | case 2:
28 | Displaystudent(cursor,console)
29 | case 3:
30 | EditStudent(cursor,connection,console)
31 | case 4:
32 | Removestudent(cursor,connection,console)
33 | case 5:
34 | break
35 |
36 |
37 | def Addstudent(cursor,connection,console):
38 |
39 | classes = []
40 |
41 | cursor.execute("select class_id from Class")
42 | for i in cursor:
43 | if i[0] == 0:
44 | continue
45 | classes.append(i[0])
46 |
47 | numberOfStudents = Checker("Enter the Number of Students to Add:", "int")
48 |
49 | for i in range(numberOfStudents):
50 |
51 | rprint("\n[bold violet]ENTER THE DETAILS OF STUDENTS\n")
52 |
53 | cursor.execute("select * from Students")
54 | allStudents = cursor.fetchall()
55 |
56 | defaultAdm = len(allStudents) + 101
57 |
58 | rprint("\nDefault Admission No:", defaultAdm)
59 | rprint("\nEnter the Student name(Max 30 Characters)")
60 | studentName = input(":")
61 | rprint("\nEnter the Date Of Birth(yyyy/mm/dd)")
62 | studentDOB = input(":")
63 | rprint("\nEnter the Date of Joining(yyyy/mm/dd)")
64 | studentDOJ = input(":")
65 | rprint("\nEnter the gender(M/F/O)")
66 | studentGender = input(":")
67 | rprint("\nEnter the Address(Max 50 Characters)")
68 | studentAddress = input(":")
69 | studentPh = Checker("Enter the Phone Number(10 Digits):", "int")
70 |
71 | cursor.execute("select class,division,class_id from Class")
72 |
73 | Enter()
74 | table = Table(title="Class")
75 | table.add_column("Class", style="cyan", no_wrap=True)
76 | table.add_column("Division", style="magenta")
77 | table.add_column("Class ID", style="violet")
78 | for i in cursor:
79 | if i[2] == 0:
80 | continue
81 | table.add_row(str(i[0]),i[1],str(i[2]))
82 |
83 | console.print(table)
84 |
85 | classID = Checker("Enter the Class ID(As Per Class):", "int")
86 | if classID not in classes:
87 | Enter()
88 | rprint("[bold red]ERROR : Class Corresponding To The Class ID Is Not Found")
89 | rprint("[bold green]HINT : Create The Class Table First!")
90 | Enter()
91 | Lag()
92 | return 1
93 | try:
94 |
95 | cursor.execute(
96 | "insert into Students values({},'{}','{}','{}','{}','{}',{},{})".format(defaultAdm, studentName, studentDOB, studentDOJ, studentGender, studentAddress, studentPh, classID))
97 | connection.commit()
98 |
99 | Enter()
100 | with console.status("[bold green]Adding Details to Database...") as status:
101 | sleep(2)
102 | console.log(f'[bold][green]Student Details Added Successfully.. ')
103 | Enter()
104 | Lag()
105 | Enter()
106 |
107 | except:
108 | Enter()
109 | rprint("[bold red]ERROR : Invalid Details Entered.")
110 | Enter()
111 |
112 | wish = Choice("Do You Wish To Retry Or Go Back(Main Menu) (1/2):", [1, 2])
113 | if wish == 1:
114 | Addstudent(cursor,connection,console)
115 | if wish == 2:
116 | return 0
117 |
118 |
119 | # Def7:DISPLAY STUDENT MENU
120 | def Displaystudent(cursor,console):
121 | def allStudents():
122 |
123 | Enter()
124 | cursor.execute("select * from Students")
125 |
126 | table = Table(title="Display All Details Of The Student")
127 | table.add_column("Admission No", style="cyan", no_wrap=True)
128 | table.add_column("Student Name", style="magenta")
129 | table.add_column("Date Of Birth", style="magenta")
130 | table.add_column("Date Of Joining", style="magenta")
131 | table.add_column("Gender", style="magenta")
132 | table.add_column("Address", style="magenta")
133 | table.add_column("Phone Number", style="magenta")
134 | table.add_column("Class ID", style="magenta")
135 | for i in cursor:
136 | table.add_row(str(i[0]),i[1],str(i[2]),str(i[3]),i[4],i[5],str(i[6]),str(i[7]))
137 | console.print(table)
138 |
139 | Enter()
140 | Lag()
141 |
142 | def studentClass():
143 |
144 | Enter()
145 | cursor.execute("select s.student_name,c.class,c.division from Students s,Class c where s.class_id=c.class_id")
146 |
147 | table = Table(title="Display Student With Class And Division")
148 | table.add_column("Student Name", style="cyan", no_wrap=True)
149 | table.add_column("Class", style="magenta")
150 | table.add_column("Division", style="magenta")
151 | for i in cursor:
152 | table.add_row(i[0],str(i[1]),i[2])
153 | console.print(table)
154 |
155 | Enter()
156 | Lag()
157 |
158 | def studentClassTeacher():
159 |
160 | Enter()
161 | cursor.execute("select s.student_name,c.class_teacher from Students s,Class c where s.class_id=c.class_id")
162 |
163 | table = Table(title="Display Student With Class Teacher")
164 | table.add_column("Student Name", style="cyan", no_wrap=True)
165 | table.add_column("Class Teacher", style="magenta")
166 | for i in cursor:
167 | table.add_row(i[0],i[1])
168 | console.print(table)
169 |
170 | Enter()
171 | Lag()
172 |
173 | def studentSubject():
174 |
175 | Enter()
176 | cursor.execute("select s.student_name,c.subject1,c.subject2,c.subject3,c.subject4,c.subject5 from Students s,Class c where s.class_id=c.class_id")
177 |
178 | table = Table(title="Display Student With Subjects")
179 | table.add_column("Student Name", style="cyan", no_wrap=True)
180 | table.add_column("Subject 1", style="magenta")
181 | table.add_column("Subject 2", style="magenta")
182 | table.add_column("Subject 3", style="magenta")
183 | table.add_column("Subject 4", style="magenta")
184 | table.add_column("Subject 5", style="magenta")
185 | for i in cursor:
186 | table.add_row(i[0],i[1],i[2],i[3],i[4],i[5])
187 | console.print(table)
188 |
189 | Enter()
190 | Lag()
191 |
192 | while True:
193 |
194 | Enter()
195 | table = Table(title="Display Students")
196 | table.add_column("S. No.", style="cyan", no_wrap=True)
197 | table.add_column("Section", style="magenta")
198 | table.add_row("1","Display All The Details Of The Student")
199 | table.add_row("2","Display The Students With Class and Division")
200 | table.add_row("3","Display Student With Class Teacher")
201 | table.add_row("4","Display Student With Subjects")
202 | table.add_row("5","Back")
203 | console.print(table)
204 | sectionValue = Choice("Enter a Choice(1,2,3,4,5)", [1, 2, 3, 4,5])
205 |
206 | if sectionValue == 1:
207 | allStudents()
208 | elif sectionValue == 2:
209 | studentClass()
210 | elif sectionValue == 3:
211 | studentClassTeacher()
212 | elif sectionValue == 4:
213 | studentSubject()
214 | else:
215 | break
216 |
217 |
218 |
219 | def EditStudent(cursor,connection,console):
220 |
221 | Enter()
222 | cursor.execute("select * from Students")
223 |
224 | table = Table(title="Display All Students")
225 | table.add_column("Admission No:", style="cyan", no_wrap=True)
226 | table.add_column("Student Name", style="magenta")
227 | for i in cursor:
228 | table.add_row(str(i[0]),i[1])
229 | console.print(table)
230 |
231 | studentAdm = Checker("Enter the Admission No:", "int")
232 | Enter()
233 | students = []
234 | cursor.execute("select * from Students")
235 | for i in cursor:
236 | students.append(i[0])
237 | if studentAdm in students:
238 | EditStudent2(studentAdm,cursor,connection,console)
239 | else:
240 | rprint("[bold red]ERROR : Enter A Valid Admission No:")
241 | Lag()
242 | return 0
243 |
244 |
245 | def EditStudent2(studentAdm,cursor,connection,console):
246 |
247 | Enter()
248 | table = Table(title="Choose What to Edit")
249 | table.add_column("S. No.", style="cyan", no_wrap=True)
250 | table.add_column("Section", style="magenta")
251 | table.add_row("1","Student Name")
252 | table.add_row("2","Date Of Birth")
253 | table.add_row("3","Date Of Joining")
254 | table.add_row("4","Gender")
255 | table.add_row("5","Address")
256 | table.add_row("6","Phone Number")
257 | table.add_row("7","Class ID")
258 | table.add_row("8","Exit")
259 | console.print(table)
260 | sectionValue = Choice("Enter Your Choice(1,2,3,4,5,6,7,8)", [1, 2, 3, 4, 5, 6, 7, 8])
261 |
262 | match sectionValue:
263 | case 1:
264 | rprint("\nEnter the Student Name(Max 30 Characters)")
265 | value = input(":")
266 | sqlCol = 'student_name'
267 | case 2:
268 | rprint("\nEnter the Date Of Birth(yyyy/mm/dd)")
269 | value = input(":")
270 | sqlCol = 'date_of_birth'
271 | case 3:
272 | rprint("\nEnter the Date of Joining(yyyy/mm/dd)")
273 | value = input(":")
274 | sqlCol = 'date_of_joining'
275 | case 4:
276 | rprint("\nEnter the Gender(M/F/O)")
277 | value = input(":")
278 | sqlCol = 'gender'
279 | case 5:
280 | rprint("\nEnter the Address(Max 50 Characters)")
281 | value = input(":")
282 | sqlCol = 'address'
283 | case 6:
284 | value = Checker("Enter the Phone Number(10 Digits)", "int")
285 | sqlCol = 'ph_no'
286 | case 7:
287 | Enter()
288 | cursor.execute("select * from Class")
289 |
290 | table = Table(title="Display All Classes")
291 | table.add_column("Class ID", style="cyan", no_wrap=True)
292 | table.add_column("Class", style="magenta")
293 | table.add_column("Division", style="magenta")
294 | for i in cursor:
295 | if i[0] == 0:
296 | continue
297 | table.add_row(str(i[0]),str(i[1]),i[2])
298 | console.print(table)
299 |
300 | value = Checker("Enter the Class ID:", "int")
301 | Enter()
302 | classes = []
303 | cursor.execute("select * from Class")
304 | for i in cursor:
305 | if i[0] == 0:
306 | continue
307 | classes.append(i[0])
308 | sqlCol = 'class_id'
309 | if value not in classes:
310 | rprint("[bold red]ERROR : Enter A Valid Class ID")
311 | Lag()
312 | return 0
313 |
314 | case 8:
315 | return 0
316 |
317 | try:
318 | if type(value) is int:
319 | query = f"update Students set {sqlCol}={value} where Admission_No={studentAdm}"
320 | cursor.execute(query)
321 | else:
322 | query = f"update Students set {sqlCol}='{value}' where Admission_No={studentAdm}"
323 | cursor.execute(query)
324 | connection.commit()
325 |
326 | Enter()
327 | with console.status("[bold green]Updating Details in Database...") as status:
328 | sleep(2)
329 | console.log(f'[bold][green]Student Updated Successfully.. ')
330 | Enter()
331 | Lag()
332 | Enter()
333 |
334 | except:
335 |
336 | Enter()
337 | rprint("[bold red]ERROR : Invalid Value Entered.")
338 | Enter()
339 | Lag()
340 | return 0
341 |
342 | def Removestudent(cursor,connection,console):
343 |
344 | Enter()
345 | cursor.execute("select * from Students")
346 |
347 | table = Table(title="Display All Details Of The Student")
348 | table.add_column("Admission No", style="cyan", no_wrap=True)
349 | table.add_column("Student Name", style="magenta")
350 | table.add_column("Date Of Birth", style="magenta")
351 | table.add_column("Date Of Joining", style="magenta")
352 | table.add_column("Gender", style="magenta")
353 | table.add_column("Address", style="magenta")
354 | table.add_column("Phone Number", style="magenta")
355 | table.add_column("Class ID", style="magenta")
356 | for i in cursor:
357 | table.add_row(str(i[0]),i[1],str(i[2]),str(i[3]),i[4],i[5],str(i[6]),str(i[7]))
358 | console.print(table)
359 |
360 | Enter()
361 | studentAdm = Checker("Enter the Admission No:", "int")
362 | Enter()
363 | students = []
364 | cursor.execute("select * from Students")
365 | for i in cursor:
366 | students.append(i[0])
367 | if studentAdm in students:
368 | try:
369 | cursor.execute("delete from Students where Admission_No={}".format(studentAdm))
370 | connection.commit()
371 |
372 | Enter()
373 | with console.status("[bold green]Deleting from Database...") as status:
374 | sleep(2)
375 | console.log(f'[bold][green]Record With Admission No: {studentAdm} is Deleted Successfully.. ')
376 | Enter()
377 | Lag()
378 | Enter()
379 |
380 | except:
381 | Enter()
382 | rprint(f"[bold red]HINT : Enter A Valid Admission No!")
383 | Enter()
384 | Lag()
385 | return 0
386 | else:
387 | Enter()
388 | rprint("[bold red]ERROR : Enter A Valid Class ID")
389 | Enter()
390 | Lag()
391 | return 0
392 |
--------------------------------------------------------------------------------
/src/teacher.py:
--------------------------------------------------------------------------------
1 | from .assets import *
2 | from rich import print as rprint
3 | from rich.table import Table
4 | from time import sleep
5 |
6 | def Teachers(cursor,connection,console):
7 | while True:
8 |
9 | Enter()
10 | table = Table(title="Teachers")
11 | table.add_column("S. No.", style="cyan", no_wrap=True)
12 | table.add_column("Section", style="magenta")
13 | table.add_row("1","Add a Teacher")
14 | table.add_row("2","Display Information Of Teachers")
15 | table.add_row("3","Edit the Details")
16 | table.add_row("4","Remove a Teacher")
17 | table.add_row("5","Go Back (Main Menu)")
18 | console.print(table)
19 | sectionValue = Choice("Enter a Choice(1,2,3,4,5)", [1, 2, 3, 4, 5])
20 |
21 | match sectionValue:
22 | case 1:
23 | r = Addteachers(cursor,connection,console)
24 | if r == 1:
25 | break
26 | case 2:
27 | Displayteachers(cursor,console)
28 | case 3:
29 | EditTeacher(cursor,connection,console)
30 | case 4:
31 | RemoveTeacher(cursor,connection,console)
32 | case 5:
33 | break
34 |
35 |
36 | def Addteachers(cursor,connection,console):
37 |
38 | classes = []
39 |
40 | cursor.execute("select class_id from Class")
41 | for i in cursor:
42 | if i[0] == 0:
43 | continue
44 | classes.append(i[0])
45 |
46 | numberOfTeachers = Checker("Enter the Number of Teachers to Add:", "int")
47 |
48 | for i in range(numberOfTeachers):
49 |
50 | rprint("\n[bold violet]ENTER THE DETAILS OF TEACHERS\n")
51 |
52 | cursor.execute("select * from Teachers")
53 | allTeachers = cursor.fetchall()
54 |
55 | defaultID = len(allTeachers) + 101
56 |
57 | rprint("\nDefault Teacher's ID:", defaultID)
58 | rprint("\nEnter the Teacher name(Max 30 Characters)")
59 | teacherName = input(":")
60 | rprint("\nEnter the Department(Max 20 Characters)")
61 | teacherDept = input(":")
62 | rprint("\nEnter the Date of Joining(yyyy/mm/dd)")
63 | teacherDOJ = input(":")
64 | rprint("\nEnter the gender(M/F/O)")
65 | teacherGender = input(":")
66 | rprint("\nEnter the Address(Max 50 Characters)")
67 | teacherAddress = input(":")
68 | teacherPh = Checker("Enter the Phone Number(10 Digits):", "int")
69 |
70 | cursor.execute("select class,division,class_id from Class")
71 |
72 | Enter()
73 | table = Table(title="Class")
74 | table.add_column("Class", style="cyan", no_wrap=True)
75 | table.add_column("Division", style="magenta")
76 | table.add_column("Class ID", style="violet")
77 | for i in cursor:
78 | if i[2] == 0:
79 | continue
80 | table.add_row(str(i[0]),i[1],str(i[2]))
81 |
82 | console.print(table)
83 |
84 | classID = Checker("Enter the Class ID(For Class Teacher, if not enter 0):", "int")
85 | if classID not in classes and classID!= 0:
86 | Enter()
87 | rprint("[bold red]ERROR : Class Corresponding To The Class ID Is Not Found")
88 | rprint("[bold green]HINT : Create The Class Table First!")
89 | Enter()
90 | Lag()
91 | return 1
92 | try:
93 | cursor.execute("insert into Teachers values({},'{}','{}','{}','{}','{}','{}',{})".format(defaultID, teacherName, teacherDept, teacherDOJ, teacherGender, teacherAddress, teacherPh, classID))
94 | connection.commit()
95 |
96 | Enter()
97 | with console.status("[bold green]Adding Details to Database...") as status:
98 | sleep(2)
99 | console.log(f'[bold][green]Teacher\'s Details Added Successfully.. ')
100 | Enter()
101 | Lag()
102 | Enter()
103 |
104 | except:
105 | Enter()
106 | rprint("[bold red]ERROR : Invalid Details Entered.")
107 | Enter()
108 |
109 | wish = Choice("Do You Wish To Retry Or Go Back(Main Menu) (1/2):", [1, 2])
110 | if wish == 1:
111 | Addteachers(cursor,connection,console)
112 | if wish == 2:
113 | return 0
114 |
115 | def Displayteachers(cursor,console):
116 | def allTeachers():
117 |
118 | Enter()
119 | cursor.execute("select * from Teachers")
120 |
121 | table = Table(title="Display All Details Of The Teachers")
122 | table.add_column("Teacher's ID", style="cyan", no_wrap=True)
123 | table.add_column("Teacher Name", style="magenta")
124 | table.add_column("Department", style="magenta")
125 | table.add_column("Date Of Joining", style="magenta")
126 | table.add_column("Gender", style="magenta")
127 | table.add_column("Address", style="magenta")
128 | table.add_column("Phone Number", style="magenta")
129 | table.add_column("Class ID", style="magenta")
130 | for i in cursor:
131 | table.add_row(str(i[0]),i[1],i[2],str(i[3]),i[4],i[5],str(i[6]),str(i[7]))
132 | console.print(table)
133 |
134 | Enter()
135 | Lag()
136 |
137 | def teachersClass():
138 |
139 | Enter()
140 | cursor.execute("select t.teachers_id,t.teachers_name,c.class,c.division from Teachers t,Class c where t.class_id=c.class_id")
141 |
142 | table = Table(title="Display Teachers With Class Teacher Post")
143 | table.add_column("Teacher's ID", style="cyan", no_wrap=True)
144 | table.add_column("Teacher Name", style="magenta")
145 | table.add_column("Class", style="magenta")
146 | table.add_column("Division", style="magenta")
147 | for i in cursor:
148 | if i[2] == 0:
149 | continue
150 | table.add_row(str(i[0]),i[1],str(i[2]),i[3])
151 | console.print(table)
152 |
153 | Enter()
154 | Lag()
155 |
156 |
157 | while True:
158 |
159 | Enter()
160 | table = Table(title="Display Teachers")
161 | table.add_column("S. No.", style="cyan", no_wrap=True)
162 | table.add_column("Section", style="magenta")
163 | table.add_row("1","Display All The Details Of The Teachers")
164 | table.add_row("2","Display Teacher With Class Teacher Post")
165 | table.add_row("3","Back")
166 | console.print(table)
167 | sectionValue = Choice("Enter a Choice(1,2,3)", [1, 2, 3])
168 |
169 | if sectionValue == 1:
170 | allTeachers()
171 | elif sectionValue == 2:
172 | teachersClass()
173 | else:
174 | break
175 |
176 |
177 | def EditTeacher(cursor,connection,console):
178 |
179 | Enter()
180 | cursor.execute("select * from Teachers")
181 |
182 | table = Table(title="Display All Teachers")
183 | table.add_column("Teacher's ID:", style="cyan", no_wrap=True)
184 | table.add_column("Teacher Name", style="magenta")
185 | for i in cursor:
186 | table.add_row(str(i[0]),i[1])
187 | console.print(table)
188 |
189 | teachersID = Checker("Enter the Teacher's ID:", "int")
190 | Enter()
191 | teachers = []
192 | cursor.execute("select * from Teachers")
193 | for i in cursor:
194 | teachers.append(i[0])
195 | if teachersID in teachers:
196 | EditTeacher2(teachersID,cursor,connection,console)
197 | else:
198 | rprint("[bold red]ERROR : Enter A Valid Teacher's ID")
199 | Lag()
200 | return 0
201 |
202 |
203 |
204 | def EditTeacher2(teachersID,cursor,connection,console):
205 |
206 |
207 | Enter()
208 | table = Table(title="Choose What to Edit")
209 | table.add_column("S. No.", style="cyan", no_wrap=True)
210 | table.add_column("Section", style="magenta")
211 | table.add_row("1","Teacher Name")
212 | table.add_row("2","Department")
213 | table.add_row("3","Date Of Joining")
214 | table.add_row("4","Gender")
215 | table.add_row("5","Address")
216 | table.add_row("6","Phone Number")
217 | table.add_row("7","Class ID")
218 | table.add_row("8","Exit")
219 | console.print(table)
220 | sectionValue = Choice("Enter Your Choice(1,2,3,4,5,6,7,8)", [1, 2, 3, 4, 5, 6, 7, 8])
221 |
222 | match sectionValue:
223 | case 1:
224 | rprint("\nEnter the Teacher's Name(Max 30 Characters)")
225 | value = input(":")
226 | sqlCol = 'teachers_name'
227 | case 2:
228 | rprint("\nEnter the Department(Max 20 Characters)")
229 | value = input(":")
230 | sqlCol = 'department'
231 | case 3:
232 | rprint("\nEnter the Date of Joining(yyyy/mm/dd)")
233 | value = input(":")
234 | sqlCol = 'date_of_joining'
235 | case 4:
236 | rprint("\nEnter the Gender(M/F/O)")
237 | value = input(":")
238 | sqlCol = 'gender'
239 | case 5:
240 | rprint("\nEnter the Address(Max 50 Characters)")
241 | value = input(":")
242 | sqlCol = 'address'
243 | case 6:
244 | value = Checker("Enter the Phone Number(10 Digits)", "int")
245 | sqlCol = 'ph_no'
246 | case 7:
247 | Enter()
248 | cursor.execute("select * from Class")
249 |
250 | table = Table(title="Display All Classes")
251 | table.add_column("Class ID", style="cyan", no_wrap=True)
252 | table.add_column("Class", style="magenta")
253 | table.add_column("Division", style="magenta")
254 | for i in cursor:
255 | if i[0] == 0:
256 | continue
257 | table.add_row(str(i[0]),str(i[1]),i[2])
258 | console.print(table)
259 |
260 | value = Checker("Enter the Class ID:", "int")
261 | Enter()
262 | classes = []
263 | cursor.execute("select * from Class")
264 | for i in cursor:
265 | if i[0] == 0:
266 | continue
267 | classes.append(i[0])
268 | sqlCol = 'class_id'
269 | if value not in classes:
270 | rprint("[bold red]ERROR : Enter A Valid Class ID")
271 | Lag()
272 | return 0
273 |
274 | case 8:
275 | return 0
276 |
277 | try:
278 | if type(value) is int:
279 | query = f"update Teachers set {sqlCol}={value} where teachers_id={teachersID}"
280 | cursor.execute(query)
281 | else:
282 | query = f"update Teachers set {sqlCol}='{value}' where teachers_id={teachersID}"
283 | cursor.execute(query)
284 | connection.commit()
285 |
286 | Enter()
287 | with console.status("[bold green]Updating Details in Database...") as status:
288 | sleep(2)
289 | console.log(f'[bold][green]Teacher Updated Successfully.. ')
290 | Enter()
291 | Lag()
292 | Enter()
293 |
294 | except:
295 |
296 | Enter()
297 | rprint("[bold red]ERROR : Invalid Value Entered.")
298 | Enter()
299 | Lag()
300 | return 0
301 |
302 |
303 |
304 | def RemoveTeacher(cursor,connection,console):
305 |
306 | Enter()
307 | cursor.execute("select * from Teachers")
308 |
309 | table = Table(title="Display All Details Of The Teachers")
310 | table.add_column("Teacher's ID", style="cyan", no_wrap=True)
311 | table.add_column("Teacher Name", style="magenta")
312 | table.add_column("Department", style="magenta")
313 | table.add_column("Date Of Joining", style="magenta")
314 | table.add_column("Gender", style="magenta")
315 | table.add_column("Address", style="magenta")
316 | table.add_column("Phone Number", style="magenta")
317 | table.add_column("Class ID", style="magenta")
318 | for i in cursor:
319 | table.add_row(str(i[0]),i[1],i[2],str(i[3]),i[4],i[5],str(i[6]),str(i[7]))
320 | console.print(table)
321 |
322 | Enter()
323 | teachersID = Checker("Enter the Teacher's ID:", "int")
324 | Enter()
325 | teachers = []
326 | cursor.execute("select * from Teachers")
327 | for i in cursor:
328 | teachers.append(i[0])
329 | if teachersID in teachers:
330 | try:
331 | cursor.execute("delete from Teachers where teachers_id={}".format(teachersID))
332 | connection.commit()
333 |
334 | Enter()
335 | with console.status("[bold green]Deleting from Database...") as status:
336 | sleep(2)
337 | console.log(f'[bold][green]Record With Teacher ID: {teachersID} is Deleted Successfully.. ')
338 | Enter()
339 | Lag()
340 | Enter()
341 |
342 | except:
343 | Enter()
344 | rprint(f"[bold red]HINT : Enter A Valid Teacher's ID!")
345 | Enter()
346 | Lag()
347 | return 0
348 | else:
349 | Enter()
350 | rprint("[bold red]ERROR : Enter A Valid Class ID")
351 | Enter()
352 | Lag()
353 | return 0
354 |
355 |
--------------------------------------------------------------------------------