CS project file
CS project file
Deoli
PROJECT TOPIC:
Management System
Principal
2
1 | Page
ACKNOWLEDGMENT
3
2 | Page
HARDWARES AND SOFTWARES
REQUIRED
HARDWARES
1. Desktop Computer / Laptop
2. Mobile Phone
SOFTWARES
1. python (Latest Version)
2. MySQL
3. MySQL-Connector-Python,Requests,
4
3 | Page
TABLE OF CONTENTS
5
4 | Page
INTRODUCTION
The project Automated Enrollment and Data Management System
includes the enrollment of users and managing data within an
educational environment. The software provides functionalities for
creating and managing database tables, inserting and updating
records, and viewing data securely.
It includes an authentication feature, allowing admins and users to
log in to their respective panels. Users can view data related to them,
such as assigned classes or accessible tables, while administrators
have the privilege to add, delete, and update information within the
database.
The system supports secure login using user IDs and passwords,
ensuring role-based access. Only the admin has the authority to make
structural changes, such as modifying the schema or managing user
data. The data can be retrieved efficiently and presented in a user-
friendly format, including export options for creating detailed reports.
The interface is highly intuitive, ensuring smooth operation, while
robust security measures protect personal and sensitive data. Fast
data processing and structured design make this system both efficient
and cost-effective.
The purpose of this project, titled “Automated Enrollment and Data
Management System,” is to computerize the enrollment process and
enhance database management for educational institutions. This
software aims to be user-friendly, simple, fast, and efficient,
addressing the needs of modern data management. 6
5 | Page
Python Source
Code
7
10 | Page
import mysql.connector
import pandas as pd
import os
HOST = "localhost"
USER = "amit"
PASSWORD = "password"
DATABASE = "enrollmentfile"
data_types = {
"int": "INT",
"varchar": "VARCHAR",
"text": "TEXT",
"date": "DATE",
def connect_db():
return mysql.connector.connect(
host=HOST,
user=USER,
password=PASSWORD,
database=DATABASE
try:
conn = connect_db()
cursor = conn.cursor()
rows = cursor.fetchall()
if headers[0].strip() == '':
headers[0] = "ID"
df = pd.DataFrame(rows, columns=headers)
if os.path.exists(file_name):
os.remove(file_name)
wb = load_workbook(file_name)
ws = wb.active
heading_cell.value = heading
thick_border = Border(
left=Side(style='thick'),
right=Side(style='thick'),
top=Side(style='thick'),
bottom=Side(style='thick')
column_letter = get_column_letter(col_num)
ws.column_dimensions[column_letter].width = max_length + 2
cell.font = header_font
cell.alignment = center_alignment
cell.border = thick_border
cell.value = value
cell.alignment = center_alignment
cell.border = thick_border
summary_start_row = len(rows) + 4
summary_start_col = 2
total_count = len(df[header])
similar_counts = df[header].value_counts()
similar_counts.font = Font(bold=True)
count_cell.font = Font(bold=True)
summary_row = summary_start_row + 1
summary_row += 1
summary_start_row = summary_row + 0
wb.save(file_name)
print(f"Error: {err}")
finally:
cursor.close()
conn.close()
def create_database():
try:
cursor = conn.cursor()
if not database_name.isalnum():
return
print(f"Error: {err}")
finally:
if conn.is_connected():
cursor.close()
conn.close()
def create_table():
try:
conn = connect_db()
cursor = conn.cursor()
primary_key_column = None
for i in range(num_columns):
mysql_type = data_types.get(column_type.lower())
if mysql_type is None:
return
if mysql_type == "VARCHAR":
if is_primary_key == 'yes':
return
primary_key_column = column_name
else:
columns.append(f"{column_name} {mysql_type}")
conn.commit()
print(f"Table '{table_name}' created successfully.")
print(f"Error: {err}")
finally:
if conn.is_connected():
cursor.close()
conn.close()
def insert_data(table_name):
try:
conn = connect_db()
cursor = conn.cursor()
cursor.execute(f"DESCRIBE {table_name}")
values = [input(f"Enter the value for '{col}': ") for col in columns]
cursor.execute(insert_query, tuple(values))
conn.commit()
print(f"Error: {err}")
finally:
if conn.is_connected():
cursor.close()
conn.close()
def update_data(table_name):
try:
conn = connect_db()
cursor = conn.cursor()
try:
identifier_value = int(identifier_input)
except ValueError:
identifier_value = identifier_input
conn.commit()
print(f"Error: {err}")
finally:
if conn.is_connected():
cursor.close()
conn.close()
def show_tables():
try:
conn = connect_db()
cursor = conn.cursor()
cursor.execute("SHOW TABLES")
tables = cursor.fetchall()
if tables:
print(table[0])
else:
print(f"Error: {err}")
finally:
if conn.is_connected():
cursor.close()
conn.close()
def show_data(table_name):
try:
conn = connect_db()
cursor = conn.cursor()
result = cursor.fetchall()
df = pd.DataFrame(result, columns=columns)
print(f"Error: {err}")
finally:
if conn.is_connected():
cursor.close()
conn.close()
def add_column(table_name):
try:
conn = connect_db()
cursor = conn.cursor()
column_type = input("Enter the data type for the new column: ")
conn.commit()
print(f"Error: {err}")
finally:
if conn.is_connected():
cursor.close()
conn.close()
def delete_column(table_name):
try:
conn = connect_db()
cursor = conn.cursor()
conn.commit()
print(f"Error: {err}")
finally:
if conn.is_connected():
cursor.close()
conn.close()
def delete_row(table_name):
try:
conn = connect_db()
cursor = conn.cursor()
condition_column = input("Enter the column to use for the deletion condition: ")
condition_value = input(f"Enter the value for '{condition_column}' to identify the row(s) to delete:
")
conn.commit()
deleted_rows = cursor.rowcount
print(f"Error: {err}")
finally:
if conn.is_connected():
cursor.close()
conn.close()
def delete_value(table_name):
conn = connect_db()
if conn is None:
try:
cursor = conn.cursor()
else:
# Prompt for the column name for updating rows if condition is needed
condition_column = input("Enter the column to use for the condition (leave blank if no condition
is needed): ")
else:
conn.commit()
else:
try:
conn.rollback()
finally:
if conn.is_connected():
cursor.close()
conn.close()
import mysql.connector
def connect_db():
return mysql.connector.connect(
try:
conn = connect_db()
cursor = conn.cursor()
rows = cursor.fetchall()
headers[0] = "ID"
df = pd.DataFrame(rows, columns=headers)
if os.path.exists(file_name):
os.remove(file_name)
wb = load_workbook(file_name)
ws = wb.active
heading_cell.value = heading
thick_border = Border(bottom=Side(style='thick'))
thick_border = Border(
left=Side(style='thick'),
right=Side(style='thick'),
top=Side(style='thick'),
bottom=Side(style='thick')
column_letter = get_column_letter(col_num)
ws.column_dimensions[column_letter].width = max_length + 2
cell.font = header_font
cell.alignment = center_alignment
cell.border = thick_border
cell.value = value
cell.alignment = center_alignment
cell.border = thick_border
summary_start_row = len(rows) + 4
summary_start_col = 2
total_count = len(df[header])
similar_counts = df[header].value_counts()
similar_counts.font = Font(bold=True)
count_cell.font = Font(bold=True)
summary_row += 1
summary_start_row = summary_row + 0
wb.save(file_name)
print(f"Error: {err}")
finally:
cursor.close()
conn.close()
db = connect_db()
cursor = db.cursor()
table_name = "granted"
check_table_query = f"""
SELECT COUNT(*)
FROM information_schema.tables
"""
cursor.execute(check_table_query)
table_exists = cursor.fetchone()[0]
if not table_exists:
create_table_query = f"""
admin VARCHAR(222),
class VARCHAR(223)
);
"""
cursor.execute(create_table_query)
db.commit()
else:
cursor.execute(query, (admin_name,))
result = cursor.fetchall()
if result:
granted_classes = [row[0] for row in result] # Fetch all granted classes for this admin
cursor.execute("SHOW TABLES;")
# Filter the tables that match the granted classes (e.g., class_2, class_3, amit1)
if not accessible_tables:
else:
print(f"- {table}")
print(f"{', '.join(accessible_tables)}")
return
if cursor.fetchone() is None:
return
else:
while True:
print("\nDatabase Operations:")
print("q. Quit")
if command == "1":
print("Creating a database...")
create_database()
print("Creating a table...")
show_tables()
create_table()
show_data(table_name)
insert_data(table_name)
1. Add column
2. Delete row
3. Delete column
4. Delete value
5. Update data
""")
if what_todo == "1":
add_column(table_name)
show_data(table_name)
delete_row(table_name)
show_data(table_name)
delete_column(table_name)
show_data(table_name)
delete_value(table_name)
show_data(table_name)
update_data(table_name)
show_data(table_name)
show_data(table_name)
elif command == "6":
show_tables()
save_table_with_counts_per_column(table_name, file_name)
os.startfile(file_name)
break
else:
save_table_with_counts_per_column(table_name, file_name)
os.startfile(file_name)
else:
db.commit()
cursor.close()
db.close()
def view_only_access():
try:
conn = connect_db()
cursor = conn.cursor()
cursor.execute("SHOW TABLES")
print(f"{i}. {table}")
table_index = int(input("\nEnter the number corresponding to the table you want to view: ")) - 1
return
selected_table = tables[table_index]
show_data(selected_table)
print("\nYou have view-only access. No modifications allowed.")
print(f"Error: {err}")
finally:
if conn.is_connected():
cursor.close()
conn.close()
def por():
try:
r = int(input("Enter 1 for table 'granted' and 2 for 'user1': ")) - 1 # Convert input to 0-based
index
raise ValueError
table_name = table_name1[r]
while True:
print("\nDatabase Operations:")
print("q. Quit")
if command == "1":
print("Creating a database...")
create_database()
print("Creating a table...")
show_tables()
create_table()
show_data(table_name)
insert_data(table_name)
what_todo = input("""
1. Add column
2. Delete row
3. Delete column
4. Delete value
5. Update data
""")
if what_todo == "1":
add_column(table_name)
show_data(table_name)
delete_row(table_name)
show_data(table_name)
delete_column(table_name)
show_data(table_name)
delete_value(table_name)
show_data(table_name)
update_data(table_name)
show_data(table_name)
show_data(table_name)
show_tables()
break
else:
print("Invalid command. Please try again.")
def check10():
db = connect_db()
cursor = db.cursor()
table_name = "user1"
check_table_query = f"""
SELECT COUNT(*)
FROM information_schema.tables
"""
cursor.execute(check_table_query)
table_exists = cursor.fetchone()[0]
if not table_exists:
create_table_query = f"""
admin VARCHAR(222),
adminpass VARCHAR(223)
);
"""
cursor.execute(create_table_query)
db.commit()
else:
table_name = "granted"
check_table_query = f"""
SELECT COUNT(*)
FROM information_schema.tables
"""
cursor.execute(check_table_query)
table_exists = cursor.fetchone()[0]
if not table_exists:
create_table_query = f"""
CREATE TABLE {table_name} (
admin VARCHAR(222),
class VARCHAR(223)
);
"""
cursor.execute(create_table_query)
db.commit()
por()
else:
por()
return
cursor.close()
def login():
if aaab =="teacher":
ask= input ("your want to change or only see the the data\n")
if ask =="yes":
import mysql.connector
# Establish connection to MySQL
db = mysql.connector.connect(
host="localhost",
user="amit",
password="password",
database="enrollmentfile"
db = connect_db()
cursor = db.cursor()
table_name = "user1"
check_table_query = f"""
SELECT COUNT(*)
FROM information_schema.tables
"""
cursor.execute(check_table_query)
table_exists = cursor.fetchone()[0]
if not table_exists:
create_table_query = f"""
admin VARCHAR(222),
adminpass VARCHAR(223)
);
"""
cursor.execute(create_table_query)
db.commit()
else:
cursor = db.cursor()
global admin_name
cursor.execute(query)
# Fetch all results
results = cursor.fetchall()
admin_found = False
if admin_name == admin:
admin_found = True
if admin_password == admipass:
manage_class_data(admin_name)
return
else:
print("Incorrect password.")
break
if not admin_found:
db.commit()
cursor.close()
db.close()
else:
view_only_access()
if passcode == "admin123":
check10()
else:
return
login()