diff --git a/GUI/GUI_student.py b/GUI/GUI_student.py new file mode 100644 index 0000000..7bc47cc --- /dev/null +++ b/GUI/GUI_student.py @@ -0,0 +1,77 @@ +from PyQt5.QtWidgets import * +from PyQt5 import uic +import student +import file_operations +import os # Import os for file operations + + +class Mygui(QMainWindow): + + def __init__(self): + super(Mygui, self).__init__() + uic.loadUi("first_gui.ui", self) + + self.show() + + # Connect buttons to their respective methods + self.pushButton.clicked.connect(self.add_record) # Record Button + self.pushButton_2.clicked.connect(self.display_records) # Display Records Button + self.pushButton_3.clicked.connect(self.delete_file) # Delete All Records Button + + def add_record(self): + # Retrieve input values from the GUI + roll = self.lineEdit.text() + name = self.lineEdit_2.text() + percentage = self.lineEdit_3.text() + + # Ensure the inputs are valid (check if fields are not empty and percentage is numeric) + if roll.isdigit() and percentage.replace('.', '', 1).isdigit(): + # Create a Student object + student_obj = student.Student() + student_obj.add_record(int(roll), name, float(percentage)) + + # Write the student record to the file using file_operations + result = file_operations.write_record(student_obj) + self.statusBar().showMessage(result) # Display result message in the status bar + + # Clear the input fields after adding the record + self.lineEdit.clear() + self.lineEdit_2.clear() + self.lineEdit_3.clear() + else: + self.statusBar().showMessage("Invalid input. Please check the fields.") + + def display_records(self): + # Fetch all records from the file using file_operations + records = file_operations.display_all_records() + + # Clear the textEdit area before displaying new records + self.textEdit.clear() + + # Display all records in the textEdit widget + if records: + for record in records: + self.textEdit.append(record + "\n") # Display each record and add a new line + else: + self.textEdit.append("No records found.") + + def delete_file(self): + try: + if os.path.exists("stud.dat"): + os.remove("stud.dat") # Delete the file + self.statusBar().showMessage("All records deleted successfully!") + self.textEdit.clear() # Clear the text area if needed + else: + self.statusBar().showMessage("File not found!") + except Exception as e: + self.statusBar().showMessage(f"Error: {str(e)}") + + +def main(): + app = QApplication([]) + window = Mygui() + app.exec_() + + +if __name__ == '__main__': + main() diff --git a/GUI/file_operations.py b/GUI/file_operations.py index 9f7c752..fb2435d 100644 --- a/GUI/file_operations.py +++ b/GUI/file_operations.py @@ -1,11 +1,12 @@ # file_operations.py import pickle - +import os +import student def write_record(student): try: with open("stud.dat", "ab") as file: - pickle.dump(student, file) + pickle.dump(student, file) # Ensure student is a Student instance return "Record added in file!" except Exception as e: return f"Error: {str(e)}" @@ -16,10 +17,26 @@ def display_all_records(): try: with open("stud.dat", "rb") as file: while True: - student = pickle.load(file) - records.append(student.display_record()) - return records - except EOFError: - return records + try: + student = pickle.load(file) # Load the Student object + records.append(student.display_record()) # Append the student's record + except EOFError: + break + return records if records else ["No records found."] + except FileNotFoundError: + return ["File not found! Please add a record first."] + except pickle.UnpicklingError: + return ["Error in unpickling data! The file might be corrupted."] except IOError: return ["File could not be opened!"] + +def delete_file(self): + try: + if os.path.exists("stud.dat"): + os.remove("stud.dat") # Delete the file + self.statusBar().showMessage("All records deleted successfully!") + self.textEdit.clear() # Clear the text area if needed + else: + self.statusBar().showMessage("File not found!") + except Exception as e: + self.statusBar().showMessage(f"Error: {str(e)}") \ No newline at end of file diff --git a/GUI/first_gui.ui b/GUI/first_gui.ui new file mode 100644 index 0000000..6b8425d --- /dev/null +++ b/GUI/first_gui.ui @@ -0,0 +1,163 @@ + + + MainWindow + + + + 0 + 0 + 462 + 593 + + + + MainWindow + + + + + + 10 + 20 + 121 + 21 + + + + Roll Number: + + + + + + 10 + 50 + 121 + 16 + + + + Name + + + + + + 10 + 80 + 121 + 16 + + + + Percentage: + + + + + + 210 + 20 + 201 + 22 + + + + + + + 210 + 50 + 201 + 22 + + + + + + + 210 + 80 + 201 + 22 + + + + + + + 70 + 120 + 281 + 31 + + + + Add Record + + + + + + 20 + 180 + 421 + 261 + + + + + + + 20 + 450 + 421 + 41 + + + + Display all Records + + + + + + 10 + 150 + 55 + 16 + + + + Records: + + + + + + 20 + 500 + 421 + 31 + + + + Delete the Data + + + + + + + 0 + 0 + 462 + 26 + + + + + + + + diff --git a/GUI/readme.md b/GUI/readme.md new file mode 100644 index 0000000..c65613f --- /dev/null +++ b/GUI/readme.md @@ -0,0 +1,19 @@ +# Student Management System GUI + +A simple Student Management System built using PyQt5 and Python for managing student records. The application allows users to add, display, and delete student records. + +## Features + +- **Add Student Record**: Enter roll number, name, and percentage to add a new student record. +- **Display Records**: View all student records stored in a file. +- **Delete Records**: Delete all records and reset the database by removing the `stud.dat` file. + +## Technologies Used + +- **Python**: Programming language used for development. +- **PyQt5**: GUI toolkit for creating the application interface. +- **Pickle**: Used for serializing and deserializing Python objects. + +## To run the GUI: + +> python GUI_student.py diff --git a/GUI/stud.dat b/GUI/stud.dat deleted file mode 100644 index 1d97c76..0000000 Binary files a/GUI/stud.dat and /dev/null differ