Fee Management Project Details Without Using PANDA
Fee Management Project Details Without Using PANDA
mysql.connector for database operations and csv for file handling. The project is structured
to include functionalities like managing student details, handling fee payments, generating
reports, and exporting/importing data using CSV files.
Requirements
1. Python Libraries
o mysql.connector: To interact with the MySQL database.
o csv: For file handling (import/export CSV).
2. MySQL Database
o A database named fee_management with a table students to store student
data.
Project Features
1. Add Student
Adds a new student record with name, roll number, class, and pending fees.
2. Update Fee Payment
Updates the pending fees when a payment is made.
3. View All Students
Displays all students with their details.
4. Search Student
Searches for a student by roll number or name.
5. Export to CSV
Exports the student records to a CSV file.
6. Import from CSV
Imports student data from a CSV file into the database.
7. Delete Student
Deletes a student record based on their roll number.
Project Structure
plaintext
Copy code
fee_management/
├── fee_management.py # Main script
└── requirements.txt # File to install dependencies
Database Setup
Create the fee_management database and students table using the following SQL script:
sql
Copy code
CREATE DATABASE fee_management;
USE fee_management;
Python Code
python
Copy code
import mysql.connector
import csv
# Database Connection
def connect_to_database():
return mysql.connector.connect(
host="localhost",
user="root", # Replace with your username
password="password", # Replace with your password
database="fee_management"
)
# Add Student
def add_student(roll_no, name, student_class, pending_fees):
conn = connect_to_database()
cursor = conn.cursor()
query = "INSERT INTO students (roll_no, name, class, pending_fees)
VALUES (%s, %s, %s, %s)"
cursor.execute(query, (roll_no, name, student_class, pending_fees))
conn.commit()
conn.close()
print("Student added successfully!")
# Search Student
def search_student(roll_no=None, name=None):
conn = connect_to_database()
cursor = conn.cursor()
if roll_no:
query = "SELECT * FROM students WHERE roll_no = %s"
cursor.execute(query, (roll_no,))
elif name:
query = "SELECT * FROM students WHERE name LIKE %s"
cursor.execute(query, (f"%{name}%",))
results = cursor.fetchall()
conn.close()
return results
# Export to CSV
def export_to_csv(filename):
students = view_students()
with open(filename, "w", newline="") as file:
writer = csv.writer(file)
writer.writerow(["Roll No", "Name", "Class", "Pending Fees"])
writer.writerows(students)
print(f"Data exported to {filename} successfully!")
# Delete Student
def delete_student(roll_no):
conn = connect_to_database()
cursor = conn.cursor()
query = "DELETE FROM students WHERE roll_no = %s"
cursor.execute(query, (roll_no,))
conn.commit()
conn.close()
print("Student deleted successfully!")
# Main Menu
def main():
while True:
print("\n--- Fee Management System ---")
print("1. Add Student")
print("2. Update Fee Payment")
print("3. View All Students")
print("4. Search Student")
print("5. Export to CSV")
print("6. Import from CSV")
print("7. Delete Student")
print("8. Exit")
if choice == 1:
roll_no = int(input("Enter Roll No: "))
name = input("Enter Name: ")
student_class = input("Enter Class: ")
pending_fees = float(input("Enter Pending Fees: "))
add_student(roll_no, name, student_class, pending_fees)
elif choice == 2:
roll_no = int(input("Enter Roll No: "))
amount = float(input("Enter Fee Payment Amount: "))
update_fee_payment(roll_no, amount)
elif choice == 3:
view_students()
elif choice == 4:
roll_no = int(input("Enter Roll No (or 0 to skip): "))
name = input("Enter Name (or press Enter to skip): ")
results = search_student(roll_no if roll_no != 0 else None,
name if name else None)
print(results)
elif choice == 5:
filename = input("Enter filename (with .csv extension): ")
export_to_csv(filename)
elif choice == 6:
filename = input("Enter filename (with .csv extension): ")
import_from_csv(filename)
elif choice == 7:
roll_no = int(input("Enter Roll No to Delete: "))
delete_student(roll_no)
elif choice == 8:
print("Exiting...")
break
else:
print("Invalid choice! Try again.")
if __name__ == "__main__":
main()
Sample Output
1. Main Menu
plaintext
Copy code
--- Fee Management System ---
1. Add Student
2. Update Fee Payment
3. View All Students
4. Search Student
5. Export to CSV
6. Import from CSV
7. Delete Student
8. Exit
2. Add Student
plaintext
Copy code
Enter Roll No: 1
Enter Name: John Doe
Enter Class: 10A
Enter Pending Fees: 1500
Student added successfully!
plaintext
Copy code
Roll No | Name | Class | Pending Fees
---------------------------------------------
1 | John Doe | 10A | 1500.00
How to Run
bash
Copy code
pip install mysql-connector-python
bash
Copy code
python fee_management.py