main.py
import pymysql
from Course import Course
from Admin import Admin
from Fees import Fees
from Instructor import Instructor
from Student import Student
# database connection
connection = pymysql.connect(host="localhost", user="root", passwd="", database="schoolmanagement")
cursor = connection.cursor()
courseSql = """CREATE TABLE Course(
ID INT(20) PRIMARY KEY AUTO_INCREMENT,
Course_name VARCHAR(256) NOT NULL,
Course_code VARCHAR(256))"""
cursor.execute(courseSql)
print("Course Table created")
studentSql = """CREATE TABLE Student(
ID INT(20) PRIMARY KEY AUTO_INCREMENT,
student_name VARCHAR (256) NOT NULL,
student_roll_no VARCHAR (256) NOT NULL,
student_gpa VARCHAR (256))"""
cursor.execute(studentSql)
print("Student Table Created")
instructorSql = """CREATE TABLE Instructor(
ID INT(20) PRIMARY KEY AUTO_INCREMENT,
instructor_name VARCHAR (256) NOT NULL,
expertise VARCHAR (256) NOT NULL)"""
cursor.execute(instructorSql)
print("Instructor Table created")
adminSql = """CREATE TABLE Admin(
ID INT(20) PRIMARY KEY AUTO_INCREMENT,
username VARCHAR (256) NOT NULL,
password VARCHAR (256) NOT NULL)"""
cursor.execute(adminSql)
print("Admin Table Created")
feeSql = """CREATE TABLE Fee(
ID INT(20) PRIMARY KEY AUTO_INCREMENT,
student_name VARCHAR (256) NOT NULL,
fee VARCHAR (256) NOT NULL,
due_date VARCHAR (256) NOT NULL)"""
cursor.execute(feeSql)
print("Fee Table created")
course = Course()
course.courseID = 101
course.courseName = "DSA"
admin = Admin()
admin.userName = "admin"
admin.password = "admin"
fees = Fees()
fees.fee = 75000
fees.studentID = 1
fees.dueDate = "27/3/2021"
instructor = Instructor()
instructor.InstructorName = "Askri"
instructor.InstructorID = "102"
instructor.expertise = "Data Science"
student = Student()
student.iD = 1
student.name = "Nabeel"
student.gpa = 3.0
cursor.execute("INSERT INTO admin(username,password) VALUES(%s,%s)",(admin.userName,admin.password))
cursor.execute("INSERT INTO course(Course_name,Course_code) VALUES(%s,%s)", (course.courseName,course.courseID))
cursor.execute("INSERT INTO fee(student_name,fee,due_date) VALUES (%s,%s,%s)", (fees.studentID,fees.fee,fees.dueDate))
cursor.execute("INSERT INTO instructor(instructor_name,expertise)VALUES (%s,%s)",(instructor.InstructorName,
instructor.expertise))
cursor.execute("INSERT INTO student(student_name,student_roll_no,student_gpa) VALUES (%s,%s,%s)",(student.name, student.iD, student.gpa))
print("Data inserted")
print("Retrieve")
print("Admin")
retriveAdmin = "SELECT * FROM admin"
cursor.execute(retriveAdmin)
rows = cursor.fetchall()
for row in rows:
print(row)
print("Course")
retriveCourse = "SELECT * FROM course"
cursor.execute(retriveCourse)
rows = cursor.fetchall()
for row in rows:
print(row)
print("Fees")
retriveFee = "SELECT * FROM fee"
cursor.execute(retriveFee)
rows = cursor.fetchall()
for row in rows:
print(row)
print("Instructor")
retriveInstructor = "SELECT * FROM instructor"
cursor.execute(retriveInstructor)
rows = cursor.fetchall()
for row in rows:
print(row)
print("Student")
retriveStudent = "SELECT * FROM student"
cursor.execute(retriveStudent)
rows = cursor.fetchall()
for row in rows:
print(row)
connection.commit()
connection.close()
Admin.py code:
class Admin:
def __init__(self, userName = None, password = 0):
super().__init__()
self.__name = userName
self.__pass = password
@property
def userName(self) -> str:
return self.__name
@userName.setter
def userName(self, name) -> None:
self.__name = name
@property
def password(self) -> str:
return self.__pass
@password.setter
def password(self, password) -> None:
self.__pass = password
Instructor.py code:
class Instructor:
def __init__(self, name = None, iD = 0, expertise = None):
super().__init__()
self.__name = name
self.__id = iD
self.__expertIn = expertise
@property
def InstructorName(self) -> str:
return self.__name
@InstructorName.setter
def InstructorName(self, name) -> None:
self.__name = name
@property
def InstructorID(self) -> int:
return self.__id
@InstructorID.setter
def InstructorID(self, iD) -> None:
self.__id = iD
@property
def expertise(self) -> str:
return self.__expertIn
@expertise.setter
def expertise(self, expertise) -> None:
self.__expertIn = expertise
Student.py code:
class Student:
def __init__(self, name = None, iD = 0, gpa = 0.0):
super().__init__()
self.__name = name
self.__id = iD
self.__gpa = gpa
@property
def name(self) -> str:
return self.__name
@name.setter
def name(self, name) -> None:
self.__name = name
@property
def iD(self) -> int:
return self.__id
@iD.setter
def iD(self, iD) -> None:
self.__id = iD
@property
def gpa(self) -> float:
return self.__gpa
@gpa.setter
def gpa(self, gpa) -> None:
self.__gpa = gpa
Course.py
class Course:
def __init__(self, course_name = None, course_id = 0):
super().__init__()
self.__name = course_name
self.__cID = course_id
@property
def courseName(self) -> str:
return self.__name
@courseName.setter
def courseName(self, name) -> None:
self.__name = name
@property
def courseID(self) -> str:
return self.__cID
@courseID.setter
def courseID(self, iD) -> None:
self.__cID = iD
Fees.py
class Fees:
def __init__(self, studentID = 0, fee = 0, dueDate = None):
super().__init__()
self.__id = studentID
self.__fee = fee
self.__duedate = dueDate
@property
def studentID(self) -> int:
return self.__id
@studentID.setter
def studentID(self, iD) -> None:
self.__id = iD
@property
def fee(self) -> int:
return self.__fee
@fee.setter
def fee(self, fee) -> None:
self.__fee = fee
@property
def dueDate(self) -> int:
return self.__duedate
@dueDate.setter
def dueDate(self, dueDate) -> None:
self.__duedate = dueDate
No comments:
Post a Comment