mirror of
https://github.com/BalrajSinghGidda/Smart-College-Management-System.git
synced 2026-04-07 09:37:22 +00:00
First draft of the app
This commit is contained in:
@@ -1 +1 @@
|
||||
flake-profile-1-link
|
||||
flake-profile-3-link
|
||||
@@ -1 +0,0 @@
|
||||
/nix/store/yh4rk74mwj495vjphknnjmk8mbz87yaz-java-devshell-env
|
||||
1
.direnv/flake-profile-3-link
Symbolic link
1
.direnv/flake-profile-3-link
Symbolic link
@@ -0,0 +1 @@
|
||||
/nix/store/pv7anfrpq0yks95kdn0wig9s7pi04scz-java-devshell-env
|
||||
BIN
college.db
Normal file
BIN
college.db
Normal file
Binary file not shown.
33
flake.nix
33
flake.nix
@@ -19,11 +19,42 @@
|
||||
maven
|
||||
gradle
|
||||
jdt-language-server
|
||||
# JavaFX Dependencies
|
||||
gtk3
|
||||
libGL
|
||||
glib
|
||||
pango
|
||||
cairo
|
||||
atk
|
||||
gdk-pixbuf
|
||||
fontconfig
|
||||
freetype
|
||||
xorg.libX11
|
||||
xorg.libXext
|
||||
xorg.libXxf86vm
|
||||
xorg.libXi
|
||||
xorg.libXtst
|
||||
];
|
||||
|
||||
shellHook = ''
|
||||
export JAVA_HOME=${pkgs.jdk21}
|
||||
echo "☕ Java devshell ready — JDK 21, Maven, Gradle"
|
||||
export LD_LIBRARY_PATH="${pkgs.lib.makeLibraryPath (with pkgs; [
|
||||
gtk3
|
||||
glib
|
||||
pango
|
||||
cairo
|
||||
atk
|
||||
gdk-pixbuf
|
||||
fontconfig
|
||||
freetype
|
||||
libGL
|
||||
xorg.libX11
|
||||
xorg.libXext
|
||||
xorg.libXxf86vm
|
||||
xorg.libXi
|
||||
xorg.libXtst
|
||||
])}:$LD_LIBRARY_PATH"
|
||||
echo "☕ Java devshell ready (with JavaFX support) — JDK 21, Maven, Gradle"
|
||||
'';
|
||||
};
|
||||
});
|
||||
|
||||
67
pom.xml
Normal file
67
pom.xml
Normal file
@@ -0,0 +1,67 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.college</groupId>
|
||||
<artifactId>management-system</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
<javafx.version>21.0.1</javafx.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.openjfx</groupId>
|
||||
<artifactId>javafx-controls</artifactId>
|
||||
<version>${javafx.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjfx</groupId>
|
||||
<artifactId>javafx-fxml</artifactId>
|
||||
<version>${javafx.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.xerial</groupId>
|
||||
<artifactId>sqlite-jdbc</artifactId>
|
||||
<version>3.45.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.itextpdf</groupId>
|
||||
<artifactId>itext7-core</artifactId>
|
||||
<version>8.0.2</version>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-csv</artifactId>
|
||||
<version>1.10.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.11.0</version>
|
||||
<configuration>
|
||||
<release>21</release>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.openjfx</groupId>
|
||||
<artifactId>javafx-maven-plugin</artifactId>
|
||||
<version>0.0.8</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<!-- Default configuration for running -->
|
||||
<id>default-cli</id>
|
||||
<configuration>
|
||||
<mainClass>com.college.management.App</mainClass>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
321
src/main/java/com/college/management/AdminDashboard.java
Normal file
321
src/main/java/com/college/management/AdminDashboard.java
Normal file
@@ -0,0 +1,321 @@
|
||||
package com.college.management;
|
||||
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.*;
|
||||
import javafx.stage.Stage;
|
||||
import java.sql.*;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.scene.control.cell.PropertyValueFactory;
|
||||
|
||||
public class AdminDashboard {
|
||||
private Stage stage;
|
||||
private int userId;
|
||||
private String username;
|
||||
|
||||
public AdminDashboard(Stage stage, int userId, String username) {
|
||||
this.stage = stage;
|
||||
this.userId = userId;
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public void show() {
|
||||
BorderPane root = new BorderPane();
|
||||
|
||||
// Sidebar
|
||||
VBox sidebar = new VBox(10);
|
||||
sidebar.setPadding(new Insets(20));
|
||||
sidebar.setStyle("-fx-background-color: #2c3e50;");
|
||||
sidebar.setPrefWidth(200);
|
||||
|
||||
Label brand = new Label("Admin Panel");
|
||||
brand.setStyle("-fx-text-fill: white; -fx-font-size: 18px; -fx-font-weight: bold;");
|
||||
|
||||
Button btnUsers = createSidebarButton("Manage Users");
|
||||
Button btnNotices = createSidebarButton("Post Notice");
|
||||
Button btnTimetable = createSidebarButton("Timetable");
|
||||
Button btnEvents = createSidebarButton("Events");
|
||||
Button btnChat = createSidebarButton("Global Chat");
|
||||
Button btnPrivateChat = createSidebarButton("Private Chat");
|
||||
Button btnReports = createSidebarButton("Reports");
|
||||
Button btnLogout = createSidebarButton("Logout");
|
||||
|
||||
sidebar.getChildren().addAll(brand, new Separator(), btnUsers, btnNotices, btnTimetable, btnEvents, btnChat, btnPrivateChat, btnReports, btnLogout);
|
||||
|
||||
root.setLeft(sidebar);
|
||||
|
||||
// Default Content
|
||||
showUserManagement(root);
|
||||
|
||||
btnUsers.setOnAction(e -> showUserManagement(root));
|
||||
btnNotices.setOnAction(e -> showNoticeManagement(root));
|
||||
btnTimetable.setOnAction(e -> showTimetableManagement(root));
|
||||
btnEvents.setOnAction(e -> showEventManagement(root));
|
||||
btnChat.setOnAction(e -> showChat(root, "Admin"));
|
||||
btnPrivateChat.setOnAction(e -> root.setCenter(new PrivateChatUI(userId).getView()));
|
||||
btnReports.setOnAction(e -> showReports(root));
|
||||
btnLogout.setOnAction(e -> new App().start(stage));
|
||||
|
||||
Scene scene = new Scene(root, 900, 600);
|
||||
stage.setTitle("Admin Dashboard");
|
||||
stage.setScene(scene);
|
||||
}
|
||||
|
||||
private void showTimetableManagement(BorderPane root) {
|
||||
VBox content = new VBox(15);
|
||||
content.setPadding(new Insets(20));
|
||||
Label title = new Label("Manage Timetable");
|
||||
title.setStyle("-fx-font-size: 24px; -fx-font-weight: bold;");
|
||||
|
||||
GridPane form = new GridPane();
|
||||
form.setHgap(10); form.setVgap(10);
|
||||
|
||||
ComboBox<String> cbDay = new ComboBox<>(FXCollections.observableArrayList("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"));
|
||||
cbDay.setPromptText("Day");
|
||||
TextField txtTime = new TextField(); txtTime.setPromptText("Time (e.g. 09:00-10:00)");
|
||||
TextField txtSubject = new TextField(); txtSubject.setPromptText("Subject");
|
||||
TextField txtFaculty = new TextField(); txtFaculty.setPromptText("Faculty Name");
|
||||
Button btnAdd = new Button("Add Entry");
|
||||
|
||||
form.add(new Label("Day:"), 0, 0); form.add(cbDay, 1, 0);
|
||||
form.add(new Label("Time:"), 0, 1); form.add(txtTime, 1, 1);
|
||||
form.add(new Label("Subject:"), 0, 2); form.add(txtSubject, 1, 2);
|
||||
form.add(new Label("Faculty:"), 0, 3); form.add(txtFaculty, 1, 3);
|
||||
form.add(btnAdd, 1, 4);
|
||||
|
||||
btnAdd.setOnAction(e -> {
|
||||
try (Connection conn = DatabaseManager.getConnection();
|
||||
PreparedStatement pstmt = conn.prepareStatement("INSERT INTO timetable (day, time_slot, subject, faculty_name) VALUES (?, ?, ?, ?)")) {
|
||||
pstmt.setString(1, cbDay.getValue());
|
||||
pstmt.setString(2, txtTime.getText());
|
||||
pstmt.setString(3, txtSubject.getText());
|
||||
pstmt.setString(4, txtFaculty.getText());
|
||||
pstmt.executeUpdate();
|
||||
new Alert(Alert.AlertType.INFORMATION, "Timetable entry added!").show();
|
||||
} catch (SQLException ex) { ex.printStackTrace(); }
|
||||
});
|
||||
|
||||
content.getChildren().addAll(title, form);
|
||||
root.setCenter(content);
|
||||
}
|
||||
|
||||
private void showEventManagement(BorderPane root) {
|
||||
VBox content = new VBox(15);
|
||||
content.setPadding(new Insets(20));
|
||||
Label title = new Label("Manage Events");
|
||||
title.setStyle("-fx-font-size: 24px; -fx-font-weight: bold;");
|
||||
|
||||
TextField txtTitle = new TextField(); txtTitle.setPromptText("Event Title");
|
||||
DatePicker datePicker = new DatePicker();
|
||||
TextArea txtDesc = new TextArea(); txtDesc.setPromptText("Event Description");
|
||||
Button btnAdd = new Button("Add Event");
|
||||
|
||||
btnAdd.setOnAction(e -> {
|
||||
try (Connection conn = DatabaseManager.getConnection();
|
||||
PreparedStatement pstmt = conn.prepareStatement("INSERT INTO events (title, description, event_date) VALUES (?, ?, ?)")) {
|
||||
pstmt.setString(1, txtTitle.getText());
|
||||
pstmt.setString(2, txtDesc.getText());
|
||||
pstmt.setString(3, datePicker.getValue().toString());
|
||||
pstmt.executeUpdate();
|
||||
new Alert(Alert.AlertType.INFORMATION, "Event added!").show();
|
||||
} catch (SQLException ex) { ex.printStackTrace(); }
|
||||
});
|
||||
|
||||
content.getChildren().addAll(title, txtTitle, datePicker, txtDesc, btnAdd);
|
||||
root.setCenter(content);
|
||||
}
|
||||
|
||||
public static void showChat(BorderPane root, String senderName) {
|
||||
VBox content = new VBox(10);
|
||||
content.setPadding(new Insets(20));
|
||||
Label title = new Label("Global Chat / Announcements");
|
||||
title.setStyle("-fx-font-size: 24px; -fx-font-weight: bold;");
|
||||
|
||||
TextArea chatArea = new TextArea();
|
||||
chatArea.setEditable(false);
|
||||
chatArea.setPrefHeight(400);
|
||||
|
||||
HBox inputArea = new HBox(10);
|
||||
TextField txtMsg = new TextField();
|
||||
txtMsg.setPrefWidth(500);
|
||||
Button btnSend = new Button("Send");
|
||||
|
||||
Runnable refreshChat = () -> {
|
||||
try (Connection conn = DatabaseManager.getConnection();
|
||||
Statement stmt = conn.createStatement();
|
||||
ResultSet rs = stmt.executeQuery("SELECT sender, content, timestamp FROM messages ORDER BY id ASC")) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
while (rs.next()) {
|
||||
sb.append("[").append(rs.getString("timestamp")).append("] ")
|
||||
.append(rs.getString("sender")).append(": ")
|
||||
.append(rs.getString("content")).append("\n");
|
||||
}
|
||||
chatArea.setText(sb.toString());
|
||||
chatArea.setScrollTop(Double.MAX_VALUE);
|
||||
} catch (SQLException ex) { ex.printStackTrace(); }
|
||||
};
|
||||
|
||||
btnSend.setOnAction(e -> {
|
||||
if (txtMsg.getText().isEmpty()) return;
|
||||
try (Connection conn = DatabaseManager.getConnection();
|
||||
PreparedStatement pstmt = conn.prepareStatement("INSERT INTO messages (sender, content) VALUES (?, ?)")) {
|
||||
pstmt.setString(1, senderName);
|
||||
pstmt.setString(2, txtMsg.getText());
|
||||
pstmt.executeUpdate();
|
||||
txtMsg.clear();
|
||||
refreshChat.run();
|
||||
} catch (SQLException ex) { ex.printStackTrace(); }
|
||||
});
|
||||
|
||||
refreshChat.run();
|
||||
inputArea.getChildren().addAll(txtMsg, btnSend);
|
||||
content.getChildren().addAll(title, chatArea, inputArea);
|
||||
root.setCenter(content);
|
||||
}
|
||||
|
||||
private void showReports(BorderPane root) {
|
||||
VBox content = new VBox(20);
|
||||
content.setPadding(new Insets(20));
|
||||
|
||||
Label title = new Label("System Reports");
|
||||
title.setStyle("-fx-font-size: 24px; -fx-font-weight: bold;");
|
||||
|
||||
Button btnCSV = new Button("Export Students to CSV");
|
||||
Button btnPDF = new Button("Export Students to PDF");
|
||||
|
||||
btnCSV.setOnAction(e -> {
|
||||
try {
|
||||
ReportGenerator.exportStudentsCSV("students_report.csv");
|
||||
new Alert(Alert.AlertType.INFORMATION, "Exported to students_report.csv").show();
|
||||
} catch (Exception ex) { ex.printStackTrace(); }
|
||||
});
|
||||
|
||||
btnPDF.setOnAction(e -> {
|
||||
try {
|
||||
ReportGenerator.exportStudentsPDF("students_report.pdf");
|
||||
new Alert(Alert.AlertType.INFORMATION, "Exported to students_report.pdf").show();
|
||||
} catch (Exception ex) { ex.printStackTrace(); }
|
||||
});
|
||||
|
||||
content.getChildren().addAll(title, btnCSV, btnPDF);
|
||||
root.setCenter(content);
|
||||
}
|
||||
|
||||
private void showNoticeManagement(BorderPane root) {
|
||||
VBox content = new VBox(15);
|
||||
content.setPadding(new Insets(20));
|
||||
|
||||
Label title = new Label("Post New Notice");
|
||||
title.setStyle("-fx-font-size: 24px; -fx-font-weight: bold;");
|
||||
|
||||
TextField txtTitle = new TextField();
|
||||
txtTitle.setPromptText("Notice Title");
|
||||
TextArea txtContent = new TextArea();
|
||||
txtContent.setPromptText("Notice Content...");
|
||||
Button btnPost = new Button("Post Notice");
|
||||
|
||||
btnPost.setOnAction(e -> {
|
||||
if (txtTitle.getText().isEmpty() || txtContent.getText().isEmpty()) return;
|
||||
try (Connection conn = DatabaseManager.getConnection();
|
||||
PreparedStatement pstmt = conn.prepareStatement("INSERT INTO notices (title, content, date) VALUES (?, ?, ?)")) {
|
||||
pstmt.setString(1, txtTitle.getText());
|
||||
pstmt.setString(2, txtContent.getText());
|
||||
pstmt.setString(3, java.time.LocalDate.now().toString());
|
||||
pstmt.executeUpdate();
|
||||
txtTitle.clear();
|
||||
txtContent.clear();
|
||||
new Alert(Alert.AlertType.INFORMATION, "Notice Posted!").show();
|
||||
} catch (SQLException ex) { ex.printStackTrace(); }
|
||||
});
|
||||
|
||||
content.getChildren().addAll(title, txtTitle, txtContent, btnPost);
|
||||
root.setCenter(content);
|
||||
}
|
||||
|
||||
private Button createSidebarButton(String text) {
|
||||
Button btn = new Button(text);
|
||||
btn.setMaxWidth(Double.MAX_VALUE);
|
||||
btn.setStyle("-fx-background-color: transparent; -fx-text-fill: white; -fx-alignment: CENTER_LEFT;");
|
||||
return btn;
|
||||
}
|
||||
|
||||
private void showUserManagement(BorderPane root) {
|
||||
VBox content = new VBox(20);
|
||||
content.setPadding(new Insets(20));
|
||||
|
||||
Label title = new Label("User Management");
|
||||
title.setStyle("-fx-font-size: 24px; -fx-font-weight: bold;");
|
||||
|
||||
// Form to add user
|
||||
HBox form = new HBox(10);
|
||||
TextField txtUsername = new TextField();
|
||||
txtUsername.setPromptText("Username");
|
||||
PasswordField txtPassword = new PasswordField();
|
||||
txtPassword.setPromptText("Password");
|
||||
ComboBox<String> cbRole = new ComboBox<>(FXCollections.observableArrayList("STUDENT", "FACULTY", "ADMIN"));
|
||||
cbRole.setPromptText("Role");
|
||||
Button btnAdd = new Button("Add User");
|
||||
|
||||
form.getChildren().addAll(txtUsername, txtPassword, cbRole, btnAdd);
|
||||
|
||||
// Table to show users
|
||||
TableView<User> table = new TableValue();
|
||||
setupUserTable(table);
|
||||
refreshUserTable(table);
|
||||
|
||||
btnAdd.setOnAction(e -> {
|
||||
addUser(txtUsername.getText(), txtPassword.getText(), cbRole.getValue(), table);
|
||||
txtUsername.clear();
|
||||
txtPassword.clear();
|
||||
});
|
||||
|
||||
content.getChildren().addAll(title, form, table);
|
||||
root.setCenter(content);
|
||||
}
|
||||
|
||||
private void setupUserTable(TableView<User> table) {
|
||||
TableColumn<User, Integer> colId = new TableColumn<>("ID");
|
||||
colId.setCellValueFactory(new PropertyValueFactory<>("id"));
|
||||
|
||||
TableColumn<User, String> colUser = new TableColumn<>("Username");
|
||||
colUser.setCellValueFactory(new PropertyValueFactory<>("username"));
|
||||
|
||||
TableColumn<User, String> colRole = new TableColumn<>("Role");
|
||||
colRole.setCellValueFactory(new PropertyValueFactory<>("role"));
|
||||
|
||||
table.getColumns().addAll(colId, colUser, colRole);
|
||||
}
|
||||
|
||||
private void refreshUserTable(TableView<User> table) {
|
||||
ObservableList<User> users = FXCollections.observableArrayList();
|
||||
try (Connection conn = DatabaseManager.getConnection();
|
||||
Statement stmt = conn.createStatement();
|
||||
ResultSet rs = stmt.executeQuery("SELECT id, username, role FROM users")) {
|
||||
while (rs.next()) {
|
||||
users.add(new User(rs.getInt("id"), rs.getString("username"), rs.getString("role"), ""));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
table.setItems(users);
|
||||
}
|
||||
|
||||
private void addUser(String user, String pass, String role, TableView<User> table) {
|
||||
if (user.isEmpty() || pass.isEmpty() || role == null) return;
|
||||
try (Connection conn = DatabaseManager.getConnection();
|
||||
PreparedStatement pstmt = conn.prepareStatement("INSERT INTO users (username, password, role) VALUES (?, ?, ?)")) {
|
||||
pstmt.setString(1, user);
|
||||
pstmt.setString(2, pass);
|
||||
pstmt.setString(3, role);
|
||||
pstmt.executeUpdate();
|
||||
refreshUserTable(table);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// Inner class fix for TableView
|
||||
private static class TableValue extends TableView<User> {}
|
||||
}
|
||||
96
src/main/java/com/college/management/App.java
Normal file
96
src/main/java/com/college/management/App.java
Normal file
@@ -0,0 +1,96 @@
|
||||
package com.college.management;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class App extends Application {
|
||||
|
||||
@Override
|
||||
public void start(Stage stage) {
|
||||
DatabaseManager.initializeDatabase();
|
||||
showLoginScreen(stage);
|
||||
}
|
||||
|
||||
private void showLoginScreen(Stage stage) {
|
||||
VBox layout = new VBox(10);
|
||||
layout.setPadding(new Insets(20));
|
||||
layout.setAlignment(Pos.CENTER);
|
||||
|
||||
Label titleLabel = new Label("College Management System - Login");
|
||||
titleLabel.setStyle("-fx-font-size: 20px; -fx-font-weight: bold;");
|
||||
|
||||
TextField usernameField = new TextField();
|
||||
usernameField.setPromptText("Username");
|
||||
usernameField.setMaxWidth(250);
|
||||
|
||||
PasswordField passwordField = new PasswordField();
|
||||
passwordField.setPromptText("Password");
|
||||
passwordField.setMaxWidth(250);
|
||||
|
||||
Button loginButton = new Button("Login");
|
||||
loginButton.setMinWidth(100);
|
||||
|
||||
Label statusLabel = new Label();
|
||||
|
||||
loginButton.setOnAction(e -> {
|
||||
String user = usernameField.getText();
|
||||
String pass = passwordField.getText();
|
||||
handleLogin(user, pass, stage, statusLabel);
|
||||
});
|
||||
|
||||
layout.getChildren().addAll(titleLabel, usernameField, passwordField, loginButton, statusLabel);
|
||||
|
||||
Scene scene = new Scene(layout, 400, 300);
|
||||
stage.setTitle("Login");
|
||||
stage.setScene(scene);
|
||||
stage.show();
|
||||
}
|
||||
|
||||
private void handleLogin(String username, String password, Stage stage, Label statusLabel) {
|
||||
try (Connection conn = DatabaseManager.getConnection();
|
||||
PreparedStatement pstmt = conn.prepareStatement("SELECT role FROM users WHERE username = ? AND password = ?")) {
|
||||
|
||||
pstmt.setString(1, username);
|
||||
pstmt.setString(2, password);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
|
||||
if (rs.next()) {
|
||||
String role = rs.getString("role");
|
||||
int userId = -1;
|
||||
try (PreparedStatement idStmt = conn.prepareStatement("SELECT id FROM users WHERE username = ?")) {
|
||||
idStmt.setString(1, username);
|
||||
ResultSet rsId = idStmt.executeQuery();
|
||||
if (rsId.next()) userId = rsId.getInt("id");
|
||||
}
|
||||
|
||||
if ("ADMIN".equals(role)) {
|
||||
new AdminDashboard(stage, userId, username).show();
|
||||
} else if ("FACULTY".equals(role)) {
|
||||
new FacultyDashboard(stage, userId, username).show();
|
||||
} else if ("STUDENT".equals(role)) {
|
||||
new StudentDashboard(stage, userId, username).show();
|
||||
}
|
||||
} else {
|
||||
statusLabel.setText("Invalid username or password.");
|
||||
statusLabel.setStyle("-fx-text-fill: red;");
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
statusLabel.setText("Database error.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch();
|
||||
}
|
||||
}
|
||||
58
src/main/java/com/college/management/ChatService.java
Normal file
58
src/main/java/com/college/management/ChatService.java
Normal file
@@ -0,0 +1,58 @@
|
||||
package com.college.management;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ChatService {
|
||||
|
||||
public static void sendPrivateMessage(int senderId, int receiverId, String content) {
|
||||
String sql = "INSERT INTO private_messages (sender_id, receiver_id, content) VALUES (?, ?, ?)";
|
||||
try (Connection conn = DatabaseManager.getConnection();
|
||||
PreparedStatement pstmt = conn.prepareStatement(sql)) {
|
||||
pstmt.setInt(1, senderId);
|
||||
pstmt.setInt(2, receiverId);
|
||||
pstmt.setString(3, content);
|
||||
pstmt.executeUpdate();
|
||||
} catch (SQLException e) { e.printStackTrace(); }
|
||||
}
|
||||
|
||||
public static List<String> getPrivateConversation(int user1, int user2) {
|
||||
List<String> messages = new ArrayList<>();
|
||||
String sql = "SELECT u.username as sender_name, pm.content, pm.timestamp " +
|
||||
"FROM private_messages pm " +
|
||||
"JOIN users u ON pm.sender_id = u.id " +
|
||||
"WHERE (pm.sender_id = ? AND pm.receiver_id = ?) " +
|
||||
"OR (pm.sender_id = ? AND pm.receiver_id = ?) " +
|
||||
"ORDER BY pm.timestamp ASC";
|
||||
try (Connection conn = DatabaseManager.getConnection();
|
||||
PreparedStatement pstmt = conn.prepareStatement(sql)) {
|
||||
pstmt.setInt(1, user1);
|
||||
pstmt.setInt(2, user2);
|
||||
pstmt.setInt(3, user2);
|
||||
pstmt.setInt(4, user1);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
messages.add("[" + rs.getString("timestamp") + "] " +
|
||||
rs.getString("sender_name") + ": " + rs.getString("content"));
|
||||
}
|
||||
} catch (SQLException e) { e.printStackTrace(); }
|
||||
return messages;
|
||||
}
|
||||
|
||||
public static List<User> getChatableUsers(int currentUserId, String roleToFilter) {
|
||||
List<User> users = new ArrayList<>();
|
||||
String sql = "SELECT id, username, role FROM users WHERE id != ?";
|
||||
if (roleToFilter != null) sql += " AND role = '" + roleToFilter + "'";
|
||||
|
||||
try (Connection conn = DatabaseManager.getConnection();
|
||||
PreparedStatement pstmt = conn.prepareStatement(sql)) {
|
||||
pstmt.setInt(1, currentUserId);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
users.add(new User(rs.getInt("id"), rs.getString("username"), rs.getString("role"), ""));
|
||||
}
|
||||
} catch (SQLException e) { e.printStackTrace(); }
|
||||
return users;
|
||||
}
|
||||
}
|
||||
109
src/main/java/com/college/management/DatabaseManager.java
Normal file
109
src/main/java/com/college/management/DatabaseManager.java
Normal file
@@ -0,0 +1,109 @@
|
||||
package com.college.management;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
public class DatabaseManager {
|
||||
private static final String URL = "jdbc:sqlite:college.db";
|
||||
|
||||
public static Connection getConnection() throws SQLException {
|
||||
return DriverManager.getConnection(URL);
|
||||
}
|
||||
|
||||
public static void initializeDatabase() {
|
||||
try (Connection conn = getConnection();
|
||||
Statement stmt = conn.createStatement()) {
|
||||
|
||||
// Users table
|
||||
stmt.execute("CREATE TABLE IF NOT EXISTS users (" +
|
||||
"id INTEGER PRIMARY KEY AUTOINCREMENT," +
|
||||
"username TEXT UNIQUE NOT NULL," +
|
||||
"password TEXT NOT NULL," +
|
||||
"role TEXT NOT NULL" + // ADMIN, FACULTY, STUDENT
|
||||
")");
|
||||
|
||||
// Profiles table
|
||||
stmt.execute("CREATE TABLE IF NOT EXISTS profiles (" +
|
||||
"user_id INTEGER PRIMARY KEY," +
|
||||
"full_name TEXT," +
|
||||
"email TEXT," +
|
||||
"department TEXT," +
|
||||
"FOREIGN KEY(user_id) REFERENCES users(id)" +
|
||||
")");
|
||||
|
||||
// Attendance
|
||||
stmt.execute("CREATE TABLE IF NOT EXISTS attendance (" +
|
||||
"id INTEGER PRIMARY KEY AUTOINCREMENT," +
|
||||
"student_id INTEGER," +
|
||||
"date TEXT," +
|
||||
"status TEXT," + // PRESENT, ABSENT
|
||||
"FOREIGN KEY(student_id) REFERENCES users(id)" +
|
||||
")");
|
||||
|
||||
// Marks
|
||||
stmt.execute("CREATE TABLE IF NOT EXISTS marks (" +
|
||||
"id INTEGER PRIMARY KEY AUTOINCREMENT," +
|
||||
"student_id INTEGER," +
|
||||
"subject TEXT," +
|
||||
"score REAL," +
|
||||
"FOREIGN KEY(student_id) REFERENCES users(id)" +
|
||||
")");
|
||||
|
||||
// Notices
|
||||
stmt.execute("CREATE TABLE IF NOT EXISTS notices (" +
|
||||
"id INTEGER PRIMARY KEY AUTOINCREMENT," +
|
||||
"title TEXT," +
|
||||
"content TEXT," +
|
||||
"date TEXT," +
|
||||
"posted_by INTEGER," +
|
||||
"FOREIGN KEY(posted_by) REFERENCES users(id)" +
|
||||
")");
|
||||
|
||||
// Timetable
|
||||
stmt.execute("CREATE TABLE IF NOT EXISTS timetable (" +
|
||||
"id INTEGER PRIMARY KEY AUTOINCREMENT," +
|
||||
"day TEXT," + // Monday, Tuesday, etc.
|
||||
"time_slot TEXT," + // e.g., 09:00 - 10:00
|
||||
"subject TEXT," +
|
||||
"faculty_name TEXT," +
|
||||
"target_role TEXT" + // ALL, STUDENT, FACULTY
|
||||
")");
|
||||
|
||||
// Events
|
||||
stmt.execute("CREATE TABLE IF NOT EXISTS events (" +
|
||||
"id INTEGER PRIMARY KEY AUTOINCREMENT," +
|
||||
"title TEXT," +
|
||||
"description TEXT," +
|
||||
"event_date TEXT" +
|
||||
")");
|
||||
|
||||
// Messages (Simple Chat)
|
||||
stmt.execute("CREATE TABLE IF NOT EXISTS messages (" +
|
||||
"id INTEGER PRIMARY KEY AUTOINCREMENT," +
|
||||
"sender TEXT," +
|
||||
"content TEXT," +
|
||||
"timestamp DATETIME DEFAULT CURRENT_TIMESTAMP" +
|
||||
")");
|
||||
|
||||
// Private Messages (One-to-One)
|
||||
stmt.execute("CREATE TABLE IF NOT EXISTS private_messages (" +
|
||||
"id INTEGER PRIMARY KEY AUTOINCREMENT," +
|
||||
"sender_id INTEGER," +
|
||||
"receiver_id INTEGER," +
|
||||
"content TEXT," +
|
||||
"timestamp DATETIME DEFAULT CURRENT_TIMESTAMP," +
|
||||
"FOREIGN KEY(sender_id) REFERENCES users(id)," +
|
||||
"FOREIGN KEY(receiver_id) REFERENCES users(id)" +
|
||||
")");
|
||||
|
||||
// Insert default admin if not exists
|
||||
stmt.execute("INSERT OR IGNORE INTO users (username, password, role) VALUES ('admin', 'admin123', 'ADMIN')");
|
||||
|
||||
System.out.println("Database initialized successfully.");
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
240
src/main/java/com/college/management/FacultyDashboard.java
Normal file
240
src/main/java/com/college/management/FacultyDashboard.java
Normal file
@@ -0,0 +1,240 @@
|
||||
package com.college.management;
|
||||
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.*;
|
||||
import javafx.stage.Stage;
|
||||
import java.sql.*;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.scene.control.cell.PropertyValueFactory;
|
||||
import java.time.LocalDate;
|
||||
|
||||
public class FacultyDashboard {
|
||||
private Stage stage;
|
||||
private int userId;
|
||||
private String username;
|
||||
|
||||
public FacultyDashboard(Stage stage, int userId, String username) {
|
||||
this.stage = stage;
|
||||
this.userId = userId;
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public void show() {
|
||||
BorderPane root = new BorderPane();
|
||||
|
||||
VBox sidebar = new VBox(10);
|
||||
sidebar.setPadding(new Insets(20));
|
||||
sidebar.setStyle("-fx-background-color: #34495e;");
|
||||
sidebar.setPrefWidth(200);
|
||||
|
||||
Label brand = new Label("Faculty Panel");
|
||||
brand.setStyle("-fx-text-fill: white; -fx-font-size: 18px; -fx-font-weight: bold;");
|
||||
|
||||
Button btnAttendance = createSidebarButton("Attendance");
|
||||
Button btnMarks = createSidebarButton("Marks Entry");
|
||||
Button btnTimetable = createSidebarButton("My Timetable");
|
||||
Button btnEvents = createSidebarButton("Events");
|
||||
Button btnChat = createSidebarButton("Global Chat");
|
||||
Button btnPrivateChat = createSidebarButton("Private Chat");
|
||||
Button btnLogout = createSidebarButton("Logout");
|
||||
|
||||
sidebar.getChildren().addAll(brand, new Separator(), btnAttendance, btnMarks, btnTimetable, btnEvents, btnChat, btnPrivateChat, btnLogout);
|
||||
root.setLeft(sidebar);
|
||||
|
||||
showAttendanceManagement(root);
|
||||
|
||||
btnAttendance.setOnAction(e -> showAttendanceManagement(root));
|
||||
btnMarks.setOnAction(e -> showMarksEntry(root));
|
||||
btnTimetable.setOnAction(e -> showTimetable(root));
|
||||
btnEvents.setOnAction(e -> showEvents(root));
|
||||
btnChat.setOnAction(e -> AdminDashboard.showChat(root, username));
|
||||
btnPrivateChat.setOnAction(e -> root.setCenter(new PrivateChatUI(userId).getView()));
|
||||
btnLogout.setOnAction(e -> new App().start(stage));
|
||||
|
||||
Scene scene = new Scene(root, 900, 600);
|
||||
stage.setTitle("Faculty Dashboard");
|
||||
stage.setScene(scene);
|
||||
}
|
||||
|
||||
private void showTimetable(BorderPane root) {
|
||||
VBox content = new VBox(15);
|
||||
content.setPadding(new Insets(20));
|
||||
Label title = new Label("College Timetable");
|
||||
title.setStyle("-fx-font-size: 22px; -fx-font-weight: bold;");
|
||||
|
||||
TableView<TimetableEntry> table = new TableView<>();
|
||||
setupTimetableTable(table);
|
||||
loadTimetable(table);
|
||||
|
||||
content.getChildren().addAll(title, table);
|
||||
root.setCenter(content);
|
||||
}
|
||||
|
||||
private void showEvents(BorderPane root) {
|
||||
VBox content = new VBox(15);
|
||||
content.setPadding(new Insets(20));
|
||||
Label title = new Label("Upcoming Events");
|
||||
title.setStyle("-fx-font-size: 22px; -fx-font-weight: bold;");
|
||||
|
||||
ListView<String> listView = new ListView<>();
|
||||
try (Connection conn = DatabaseManager.getConnection();
|
||||
Statement stmt = conn.createStatement();
|
||||
ResultSet rs = stmt.executeQuery("SELECT title, description, event_date FROM events ORDER BY event_date ASC")) {
|
||||
while (rs.next()) {
|
||||
listView.getItems().add(rs.getString("event_date") + " - " + rs.getString("title") + "\n" + rs.getString("description"));
|
||||
}
|
||||
} catch (SQLException e) { e.printStackTrace(); }
|
||||
|
||||
content.getChildren().addAll(title, listView);
|
||||
root.setCenter(content);
|
||||
}
|
||||
|
||||
private void setupTimetableTable(TableView<TimetableEntry> table) {
|
||||
TableColumn<TimetableEntry, String> colDay = new TableColumn<>("Day");
|
||||
colDay.setCellValueFactory(new PropertyValueFactory<>("day"));
|
||||
TableColumn<TimetableEntry, String> colTime = new TableColumn<>("Time");
|
||||
colTime.setCellValueFactory(new PropertyValueFactory<>("timeSlot"));
|
||||
TableColumn<TimetableEntry, String> colSub = new TableColumn<>("Subject");
|
||||
colSub.setCellValueFactory(new PropertyValueFactory<>("subject"));
|
||||
TableColumn<TimetableEntry, String> colFac = new TableColumn<>("Faculty");
|
||||
colFac.setCellValueFactory(new PropertyValueFactory<>("facultyName"));
|
||||
table.getColumns().addAll(colDay, colTime, colSub, colFac);
|
||||
}
|
||||
|
||||
private void loadTimetable(TableView<TimetableEntry> table) {
|
||||
ObservableList<TimetableEntry> data = FXCollections.observableArrayList();
|
||||
try (Connection conn = DatabaseManager.getConnection();
|
||||
Statement stmt = conn.createStatement();
|
||||
ResultSet rs = stmt.executeQuery("SELECT day, time_slot, subject, faculty_name FROM timetable")) {
|
||||
while (rs.next()) {
|
||||
data.add(new TimetableEntry(rs.getString("day"), rs.getString("time_slot"), rs.getString("subject"), rs.getString("faculty_name")));
|
||||
}
|
||||
} catch (SQLException e) { e.printStackTrace(); }
|
||||
table.setItems(data);
|
||||
}
|
||||
|
||||
public static class TimetableEntry {
|
||||
private String day, timeSlot, subject, facultyName;
|
||||
public TimetableEntry(String d, String t, String s, String f) { day = d; timeSlot = t; subject = s; facultyName = f; }
|
||||
public String getDay() { return day; }
|
||||
public String getTimeSlot() { return timeSlot; }
|
||||
public String getSubject() { return subject; }
|
||||
public String getFacultyName() { return facultyName; }
|
||||
}
|
||||
|
||||
private Button createSidebarButton(String text) {
|
||||
Button btn = new Button(text);
|
||||
btn.setMaxWidth(Double.MAX_VALUE);
|
||||
btn.setStyle("-fx-background-color: transparent; -fx-text-fill: white; -fx-alignment: CENTER_LEFT;");
|
||||
return btn;
|
||||
}
|
||||
|
||||
private void showAttendanceManagement(BorderPane root) {
|
||||
VBox content = new VBox(15);
|
||||
content.setPadding(new Insets(20));
|
||||
|
||||
Label title = new Label("Mark Attendance");
|
||||
title.setStyle("-fx-font-size: 22px; -fx-font-weight: bold;");
|
||||
|
||||
DatePicker datePicker = new DatePicker(LocalDate.now());
|
||||
TableView<User> table = new TableView<>();
|
||||
setupStudentTable(table);
|
||||
loadStudents(table);
|
||||
|
||||
HBox controls = new HBox(10);
|
||||
Button btnPresent = new Button("Mark Present");
|
||||
Button btnAbsent = new Button("Mark Absent");
|
||||
controls.getChildren().addAll(new Label("Date:"), datePicker, btnPresent, btnAbsent);
|
||||
|
||||
btnPresent.setOnAction(e -> markAttendance(table, datePicker.getValue(), "PRESENT"));
|
||||
btnAbsent.setOnAction(e -> markAttendance(table, datePicker.getValue(), "ABSENT"));
|
||||
|
||||
content.getChildren().addAll(title, controls, table);
|
||||
root.setCenter(content);
|
||||
}
|
||||
|
||||
private void showMarksEntry(BorderPane root) {
|
||||
VBox content = new VBox(15);
|
||||
content.setPadding(new Insets(20));
|
||||
|
||||
Label title = new Label("Enter Marks");
|
||||
title.setStyle("-fx-font-size: 22px; -fx-font-weight: bold;");
|
||||
|
||||
TableView<User> table = new TableView<>();
|
||||
setupStudentTable(table);
|
||||
loadStudents(table);
|
||||
|
||||
HBox controls = new HBox(10);
|
||||
TextField txtSubject = new TextField();
|
||||
txtSubject.setPromptText("Subject");
|
||||
TextField txtScore = new TextField();
|
||||
txtScore.setPromptText("Score");
|
||||
Button btnSave = new Button("Save Mark");
|
||||
|
||||
controls.getChildren().addAll(txtSubject, txtScore, btnSave);
|
||||
|
||||
btnSave.setOnAction(e -> saveMark(table, txtSubject.getText(), txtScore.getText()));
|
||||
|
||||
content.getChildren().addAll(title, controls, table);
|
||||
root.setCenter(content);
|
||||
}
|
||||
|
||||
private void setupStudentTable(TableView<User> table) {
|
||||
TableColumn<User, Integer> colId = new TableColumn<>("ID");
|
||||
colId.setCellValueFactory(new PropertyValueFactory<>("id"));
|
||||
TableColumn<User, String> colUser = new TableColumn<>("Student Name");
|
||||
colUser.setCellValueFactory(new PropertyValueFactory<>("username"));
|
||||
table.getColumns().addAll(colId, colUser);
|
||||
}
|
||||
|
||||
private void loadStudents(TableView<User> table) {
|
||||
ObservableList<User> students = FXCollections.observableArrayList();
|
||||
try (Connection conn = DatabaseManager.getConnection();
|
||||
PreparedStatement pstmt = conn.prepareStatement("SELECT id, username FROM users WHERE role = 'STUDENT'")) {
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
students.add(new User(rs.getInt("id"), rs.getString("username"), "STUDENT", ""));
|
||||
}
|
||||
} catch (SQLException e) { e.printStackTrace(); }
|
||||
table.setItems(students);
|
||||
}
|
||||
|
||||
private void markAttendance(TableView<User> table, LocalDate date, String status) {
|
||||
User selected = table.getSelectionModel().getSelectedItem();
|
||||
if (selected == null || date == null) return;
|
||||
|
||||
try (Connection conn = DatabaseManager.getConnection();
|
||||
PreparedStatement pstmt = conn.prepareStatement("INSERT INTO attendance (student_id, date, status) VALUES (?, ?, ?)")) {
|
||||
pstmt.setInt(1, selected.getId());
|
||||
pstmt.setString(2, date.toString());
|
||||
pstmt.setString(3, status);
|
||||
pstmt.executeUpdate();
|
||||
showAlert("Success", "Attendance marked as " + status);
|
||||
} catch (SQLException e) { e.printStackTrace(); }
|
||||
}
|
||||
|
||||
private void saveMark(TableView<User> table, String subject, String scoreStr) {
|
||||
User selected = table.getSelectionModel().getSelectedItem();
|
||||
if (selected == null || subject.isEmpty() || scoreStr.isEmpty()) return;
|
||||
|
||||
try (Connection conn = DatabaseManager.getConnection();
|
||||
PreparedStatement pstmt = conn.prepareStatement("INSERT INTO marks (student_id, subject, score) VALUES (?, ?, ?)")) {
|
||||
pstmt.setInt(1, selected.getId());
|
||||
pstmt.setString(2, subject);
|
||||
pstmt.setDouble(3, Double.parseDouble(scoreStr));
|
||||
pstmt.executeUpdate();
|
||||
showAlert("Success", "Marks saved for " + subject);
|
||||
} catch (Exception e) { e.printStackTrace(); }
|
||||
}
|
||||
|
||||
private void showAlert(String title, String content) {
|
||||
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
||||
alert.setTitle(title);
|
||||
alert.setHeaderText(null);
|
||||
alert.setContentText(content);
|
||||
alert.showAndWait();
|
||||
}
|
||||
}
|
||||
96
src/main/java/com/college/management/PrivateChatUI.java
Normal file
96
src/main/java/com/college/management/PrivateChatUI.java
Normal file
@@ -0,0 +1,96 @@
|
||||
package com.college.management;
|
||||
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.*;
|
||||
import java.util.List;
|
||||
|
||||
public class PrivateChatUI {
|
||||
private int currentUserId;
|
||||
private User selectedUser;
|
||||
private TextArea chatArea;
|
||||
private ListView<User> userList;
|
||||
|
||||
public PrivateChatUI(int currentUserId) {
|
||||
this.currentUserId = currentUserId;
|
||||
}
|
||||
|
||||
public Pane getView() {
|
||||
BorderPane layout = new BorderPane();
|
||||
|
||||
// Left side: User List
|
||||
VBox leftPane = new VBox(10);
|
||||
leftPane.setPadding(new Insets(10));
|
||||
leftPane.setPrefWidth(200);
|
||||
Label userLbl = new Label("Contacts");
|
||||
userLbl.setStyle("-fx-font-weight: bold;");
|
||||
|
||||
userList = new ListView<>();
|
||||
refreshUserList();
|
||||
|
||||
userList.setCellFactory(param -> new ListCell<User>() {
|
||||
@Override
|
||||
protected void updateItem(User item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
if (empty || item == null) setText(null);
|
||||
else setText(item.getUsername() + " (" + item.getRole() + ")");
|
||||
}
|
||||
});
|
||||
|
||||
leftPane.getChildren().addAll(userLbl, userList);
|
||||
layout.setLeft(leftPane);
|
||||
|
||||
// Center: Chat Area
|
||||
VBox chatPane = new VBox(10);
|
||||
chatPane.setPadding(new Insets(10));
|
||||
|
||||
chatArea = new TextArea();
|
||||
chatArea.setEditable(false);
|
||||
chatArea.setPrefHeight(400);
|
||||
chatArea.setWrapText(true);
|
||||
|
||||
HBox inputPane = new HBox(10);
|
||||
TextField txtMsg = new TextField();
|
||||
txtMsg.setPrefWidth(400);
|
||||
Button btnSend = new Button("Send");
|
||||
inputPane.getChildren().addAll(txtMsg, btnSend);
|
||||
|
||||
chatPane.getChildren().addAll(new Label("Chat Window"), chatArea, inputPane);
|
||||
layout.setCenter(chatPane);
|
||||
|
||||
// Logic
|
||||
userList.getSelectionModel().selectedItemProperty().addListener((obs, oldVal, newVal) -> {
|
||||
selectedUser = newVal;
|
||||
refreshMessages();
|
||||
});
|
||||
|
||||
btnSend.setOnAction(e -> {
|
||||
if (selectedUser != null && !txtMsg.getText().isEmpty()) {
|
||||
ChatService.sendPrivateMessage(currentUserId, selectedUser.getId(), txtMsg.getText());
|
||||
txtMsg.clear();
|
||||
refreshMessages();
|
||||
}
|
||||
});
|
||||
|
||||
return layout;
|
||||
}
|
||||
|
||||
private void refreshUserList() {
|
||||
List<User> users = ChatService.getChatableUsers(currentUserId, null);
|
||||
userList.getItems().setAll(users);
|
||||
}
|
||||
|
||||
private void refreshMessages() {
|
||||
if (selectedUser == null) {
|
||||
chatArea.setText("Select a contact to start chatting.");
|
||||
return;
|
||||
}
|
||||
List<String> history = ChatService.getPrivateConversation(currentUserId, selectedUser.getId());
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String msg : history) {
|
||||
sb.append(msg).append("\n");
|
||||
}
|
||||
chatArea.setText(sb.toString());
|
||||
chatArea.setScrollTop(Double.MAX_VALUE);
|
||||
}
|
||||
}
|
||||
57
src/main/java/com/college/management/ReportGenerator.java
Normal file
57
src/main/java/com/college/management/ReportGenerator.java
Normal file
@@ -0,0 +1,57 @@
|
||||
package com.college.management;
|
||||
|
||||
import com.itextpdf.kernel.pdf.PdfDocument;
|
||||
import com.itextpdf.kernel.pdf.PdfWriter;
|
||||
import com.itextpdf.layout.Document;
|
||||
import com.itextpdf.layout.element.Paragraph;
|
||||
import com.itextpdf.layout.element.Table;
|
||||
import org.apache.commons.csv.CSVFormat;
|
||||
import org.apache.commons.csv.CSVPrinter;
|
||||
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
|
||||
public class ReportGenerator {
|
||||
|
||||
public static void exportStudentsCSV(String filePath) throws Exception {
|
||||
try (Connection conn = DatabaseManager.getConnection();
|
||||
Statement stmt = conn.createStatement();
|
||||
ResultSet rs = stmt.executeQuery("SELECT id, username, role FROM users WHERE role = 'STUDENT'");
|
||||
CSVPrinter printer = new CSVPrinter(new FileWriter(filePath), CSVFormat.DEFAULT.withHeader("ID", "Username", "Role"))) {
|
||||
while (rs.next()) {
|
||||
printer.printRecord(rs.getInt("id"), rs.getString("username"), rs.getString("role"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void exportStudentsPDF(String filePath) throws Exception {
|
||||
PdfWriter writer = new PdfWriter(filePath);
|
||||
PdfDocument pdf = new PdfDocument(writer);
|
||||
Document document = new Document(pdf);
|
||||
|
||||
document.add(new Paragraph("Student Report").setFontSize(20).setBold());
|
||||
|
||||
float[] columnWidths = {50f, 200f, 100f};
|
||||
Table table = new Table(columnWidths);
|
||||
|
||||
table.addCell("ID");
|
||||
table.addCell("Username");
|
||||
table.addCell("Role");
|
||||
|
||||
try (Connection conn = DatabaseManager.getConnection();
|
||||
Statement stmt = conn.createStatement();
|
||||
ResultSet rs = stmt.executeQuery("SELECT id, username, role FROM users WHERE role = 'STUDENT'")) {
|
||||
while (rs.next()) {
|
||||
table.addCell(String.valueOf(rs.getInt("id")));
|
||||
table.addCell(rs.getString("username"));
|
||||
table.addCell(rs.getString("role"));
|
||||
}
|
||||
}
|
||||
|
||||
document.add(table);
|
||||
document.close();
|
||||
}
|
||||
}
|
||||
208
src/main/java/com/college/management/StudentDashboard.java
Normal file
208
src/main/java/com/college/management/StudentDashboard.java
Normal file
@@ -0,0 +1,208 @@
|
||||
package com.college.management;
|
||||
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.*;
|
||||
import javafx.stage.Stage;
|
||||
import java.sql.*;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.scene.control.cell.PropertyValueFactory;
|
||||
|
||||
public class StudentDashboard {
|
||||
private Stage stage;
|
||||
private int studentId;
|
||||
private String studentName;
|
||||
|
||||
public StudentDashboard(Stage stage, int studentId, String studentName) {
|
||||
this.stage = stage;
|
||||
this.studentId = studentId;
|
||||
this.studentName = studentName;
|
||||
}
|
||||
|
||||
public void show() {
|
||||
BorderPane root = new BorderPane();
|
||||
|
||||
VBox sidebar = new VBox(10);
|
||||
sidebar.setPadding(new Insets(20));
|
||||
sidebar.setStyle("-fx-background-color: #16a085;");
|
||||
sidebar.setPrefWidth(200);
|
||||
|
||||
Label brand = new Label("Student Panel");
|
||||
brand.setStyle("-fx-text-fill: white; -fx-font-size: 18px; -fx-font-weight: bold;");
|
||||
Label nameLbl = new Label("Welcome, " + studentName);
|
||||
nameLbl.setStyle("-fx-text-fill: #ecf0f1; -fx-font-size: 12px;");
|
||||
|
||||
Button btnMarks = createSidebarButton("My Marks");
|
||||
Button btnAttendance = createSidebarButton("My Attendance");
|
||||
Button btnTimetable = createSidebarButton("Time Table");
|
||||
Button btnEvents = createSidebarButton("Upcoming Events");
|
||||
Button btnChat = createSidebarButton("Global Chat");
|
||||
Button btnPrivateChat = createSidebarButton("Private Chat");
|
||||
Button btnNotices = createSidebarButton("Notices");
|
||||
Button btnLogout = createSidebarButton("Logout");
|
||||
|
||||
sidebar.getChildren().addAll(brand, nameLbl, new Separator(), btnMarks, btnAttendance, btnTimetable, btnEvents, btnChat, btnPrivateChat, btnNotices, btnLogout);
|
||||
root.setLeft(sidebar);
|
||||
|
||||
showMarks(root);
|
||||
|
||||
btnMarks.setOnAction(e -> showMarks(root));
|
||||
btnAttendance.setOnAction(e -> showAttendance(root));
|
||||
btnTimetable.setOnAction(e -> showTimetable(root));
|
||||
btnEvents.setOnAction(e -> showEvents(root));
|
||||
btnChat.setOnAction(e -> AdminDashboard.showChat(root, studentName));
|
||||
btnPrivateChat.setOnAction(e -> root.setCenter(new PrivateChatUI(studentId).getView()));
|
||||
btnNotices.setOnAction(e -> showNotices(root));
|
||||
btnLogout.setOnAction(e -> new App().start(stage));
|
||||
|
||||
Scene scene = new Scene(root, 900, 600);
|
||||
stage.setTitle("Student Dashboard - " + studentName);
|
||||
stage.setScene(scene);
|
||||
}
|
||||
|
||||
private void showTimetable(BorderPane root) {
|
||||
VBox content = new VBox(15);
|
||||
content.setPadding(new Insets(20));
|
||||
Label title = new Label("Class Schedule");
|
||||
title.setStyle("-fx-font-size: 22px; -fx-font-weight: bold;");
|
||||
|
||||
TableView<FacultyDashboard.TimetableEntry> table = new TableView<>();
|
||||
setupTimetableTable(table);
|
||||
loadTimetable(table);
|
||||
|
||||
content.getChildren().addAll(title, table);
|
||||
root.setCenter(content);
|
||||
}
|
||||
|
||||
private void setupTimetableTable(TableView<FacultyDashboard.TimetableEntry> table) {
|
||||
TableColumn<FacultyDashboard.TimetableEntry, String> colDay = new TableColumn<>("Day");
|
||||
colDay.setCellValueFactory(new PropertyValueFactory<>("day"));
|
||||
TableColumn<FacultyDashboard.TimetableEntry, String> colTime = new TableColumn<>("Time");
|
||||
colTime.setCellValueFactory(new PropertyValueFactory<>("timeSlot"));
|
||||
TableColumn<FacultyDashboard.TimetableEntry, String> colSub = new TableColumn<>("Subject");
|
||||
colSub.setCellValueFactory(new PropertyValueFactory<>("subject"));
|
||||
TableColumn<FacultyDashboard.TimetableEntry, String> colFac = new TableColumn<>("Faculty");
|
||||
colFac.setCellValueFactory(new PropertyValueFactory<>("facultyName"));
|
||||
table.getColumns().addAll(colDay, colTime, colSub, colFac);
|
||||
}
|
||||
|
||||
private void loadTimetable(TableView<FacultyDashboard.TimetableEntry> table) {
|
||||
ObservableList<FacultyDashboard.TimetableEntry> data = FXCollections.observableArrayList();
|
||||
try (Connection conn = DatabaseManager.getConnection();
|
||||
Statement stmt = conn.createStatement();
|
||||
ResultSet rs = stmt.executeQuery("SELECT day, time_slot, subject, faculty_name FROM timetable")) {
|
||||
while (rs.next()) {
|
||||
data.add(new FacultyDashboard.TimetableEntry(rs.getString("day"), rs.getString("time_slot"), rs.getString("subject"), rs.getString("faculty_name")));
|
||||
}
|
||||
} catch (SQLException e) { e.printStackTrace(); }
|
||||
table.setItems(data);
|
||||
}
|
||||
|
||||
private void showEvents(BorderPane root) {
|
||||
VBox content = new VBox(15);
|
||||
content.setPadding(new Insets(20));
|
||||
Label title = new Label("Upcoming Events");
|
||||
title.setStyle("-fx-font-size: 22px; -fx-font-weight: bold;");
|
||||
|
||||
ListView<String> listView = new ListView<>();
|
||||
try (Connection conn = DatabaseManager.getConnection();
|
||||
Statement stmt = conn.createStatement();
|
||||
ResultSet rs = stmt.executeQuery("SELECT title, description, event_date FROM events ORDER BY event_date ASC")) {
|
||||
while (rs.next()) {
|
||||
listView.getItems().add(rs.getString("event_date") + " - " + rs.getString("title") + "\n" + rs.getString("description"));
|
||||
}
|
||||
} catch (SQLException e) { e.printStackTrace(); }
|
||||
|
||||
content.getChildren().addAll(title, listView);
|
||||
root.setCenter(content);
|
||||
}
|
||||
|
||||
private Button createSidebarButton(String text) {
|
||||
Button btn = new Button(text);
|
||||
btn.setMaxWidth(Double.MAX_VALUE);
|
||||
btn.setStyle("-fx-background-color: transparent; -fx-text-fill: white; -fx-alignment: CENTER_LEFT;");
|
||||
return btn;
|
||||
}
|
||||
|
||||
private void showMarks(BorderPane root) {
|
||||
VBox content = new VBox(15);
|
||||
content.setPadding(new Insets(20));
|
||||
Label title = new Label("Academic Results");
|
||||
title.setStyle("-fx-font-size: 22px; -fx-font-weight: bold;");
|
||||
|
||||
TableView<MarkRecord> table = new TableView<>();
|
||||
TableColumn<MarkRecord, String> colSub = new TableColumn<>("Subject");
|
||||
colSub.setCellValueFactory(new PropertyValueFactory<>("subject"));
|
||||
TableColumn<MarkRecord, Double> colScore = new TableColumn<>("Score");
|
||||
colScore.setCellValueFactory(new PropertyValueFactory<>("score"));
|
||||
table.getColumns().addAll(colSub, colScore);
|
||||
|
||||
ObservableList<MarkRecord> data = FXCollections.observableArrayList();
|
||||
try (Connection conn = DatabaseManager.getConnection();
|
||||
PreparedStatement pstmt = conn.prepareStatement("SELECT subject, score FROM marks WHERE student_id = ?")) {
|
||||
pstmt.setInt(1, studentId);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
data.add(new MarkRecord(rs.getString("subject"), rs.getDouble("score")));
|
||||
}
|
||||
} catch (SQLException e) { e.printStackTrace(); }
|
||||
table.setItems(data);
|
||||
|
||||
content.getChildren().addAll(title, table);
|
||||
root.setCenter(content);
|
||||
}
|
||||
|
||||
private void showAttendance(BorderPane root) {
|
||||
VBox content = new VBox(15);
|
||||
content.setPadding(new Insets(20));
|
||||
Label title = new Label("Attendance Records");
|
||||
title.setStyle("-fx-font-size: 22px; -fx-font-weight: bold;");
|
||||
|
||||
int present = 0, total = 0;
|
||||
try (Connection conn = DatabaseManager.getConnection();
|
||||
PreparedStatement pstmt = conn.prepareStatement("SELECT status FROM attendance WHERE student_id = ?")) {
|
||||
pstmt.setInt(1, studentId);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
total++;
|
||||
if ("PRESENT".equals(rs.getString("status"))) present++;
|
||||
}
|
||||
} catch (SQLException e) { e.printStackTrace(); }
|
||||
|
||||
double percent = total == 0 ? 0 : (double) present / total * 100;
|
||||
Label stats = new Label(String.format("Attendance: %d/%d (%.2f%%)", present, total, percent));
|
||||
stats.setStyle("-fx-font-size: 18px;");
|
||||
|
||||
content.getChildren().addAll(title, stats);
|
||||
root.setCenter(content);
|
||||
}
|
||||
|
||||
private void showNotices(BorderPane root) {
|
||||
VBox content = new VBox(15);
|
||||
content.setPadding(new Insets(20));
|
||||
Label title = new Label("College Notices");
|
||||
title.setStyle("-fx-font-size: 22px; -fx-font-weight: bold;");
|
||||
|
||||
ListView<String> listView = new ListView<>();
|
||||
try (Connection conn = DatabaseManager.getConnection();
|
||||
Statement stmt = conn.createStatement();
|
||||
ResultSet rs = stmt.executeQuery("SELECT title, content, date FROM notices ORDER BY id DESC")) {
|
||||
while (rs.next()) {
|
||||
listView.getItems().add(rs.getString("date") + " - " + rs.getString("title") + "\n" + rs.getString("content"));
|
||||
}
|
||||
} catch (SQLException e) { e.printStackTrace(); }
|
||||
|
||||
content.getChildren().addAll(title, listView);
|
||||
root.setCenter(content);
|
||||
}
|
||||
|
||||
public static class MarkRecord {
|
||||
private String subject;
|
||||
private double score;
|
||||
public MarkRecord(String subject, double score) { this.subject = subject; this.score = score; }
|
||||
public String getSubject() { return subject; }
|
||||
public double getScore() { return score; }
|
||||
}
|
||||
}
|
||||
20
src/main/java/com/college/management/User.java
Normal file
20
src/main/java/com/college/management/User.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package com.college.management;
|
||||
|
||||
public class User {
|
||||
private int id;
|
||||
private String username;
|
||||
private String role;
|
||||
private String fullName;
|
||||
|
||||
public User(int id, String username, String role, String fullName) {
|
||||
this.id = id;
|
||||
this.username = username;
|
||||
this.role = role;
|
||||
this.fullName = fullName;
|
||||
}
|
||||
|
||||
public int getId() { return id; }
|
||||
public String getUsername() { return username; }
|
||||
public String getRole() { return role; }
|
||||
public String getFullName() { return fullName; }
|
||||
}
|
||||
Binary file not shown.
BIN
target/classes/com/college/management/AdminDashboard.class
Normal file
BIN
target/classes/com/college/management/AdminDashboard.class
Normal file
Binary file not shown.
BIN
target/classes/com/college/management/App.class
Normal file
BIN
target/classes/com/college/management/App.class
Normal file
Binary file not shown.
BIN
target/classes/com/college/management/ChatService.class
Normal file
BIN
target/classes/com/college/management/ChatService.class
Normal file
Binary file not shown.
BIN
target/classes/com/college/management/DatabaseManager.class
Normal file
BIN
target/classes/com/college/management/DatabaseManager.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
target/classes/com/college/management/FacultyDashboard.class
Normal file
BIN
target/classes/com/college/management/FacultyDashboard.class
Normal file
Binary file not shown.
BIN
target/classes/com/college/management/PrivateChatUI$1.class
Normal file
BIN
target/classes/com/college/management/PrivateChatUI$1.class
Normal file
Binary file not shown.
BIN
target/classes/com/college/management/PrivateChatUI.class
Normal file
BIN
target/classes/com/college/management/PrivateChatUI.class
Normal file
Binary file not shown.
BIN
target/classes/com/college/management/ReportGenerator.class
Normal file
BIN
target/classes/com/college/management/ReportGenerator.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
target/classes/com/college/management/StudentDashboard.class
Normal file
BIN
target/classes/com/college/management/StudentDashboard.class
Normal file
Binary file not shown.
BIN
target/classes/com/college/management/User.class
Normal file
BIN
target/classes/com/college/management/User.class
Normal file
Binary file not shown.
@@ -0,0 +1,13 @@
|
||||
com/college/management/StudentDashboard.class
|
||||
com/college/management/FacultyDashboard.class
|
||||
com/college/management/ReportGenerator.class
|
||||
com/college/management/PrivateChatUI.class
|
||||
com/college/management/DatabaseManager.class
|
||||
com/college/management/AdminDashboard$TableValue.class
|
||||
com/college/management/App.class
|
||||
com/college/management/PrivateChatUI$1.class
|
||||
com/college/management/ChatService.class
|
||||
com/college/management/User.class
|
||||
com/college/management/FacultyDashboard$TimetableEntry.class
|
||||
com/college/management/StudentDashboard$MarkRecord.class
|
||||
com/college/management/AdminDashboard.class
|
||||
@@ -0,0 +1,9 @@
|
||||
/home/balraj/Work/Smart College Management System/src/main/java/com/college/management/DatabaseManager.java
|
||||
/home/balraj/Work/Smart College Management System/src/main/java/com/college/management/App.java
|
||||
/home/balraj/Work/Smart College Management System/src/main/java/com/college/management/ChatService.java
|
||||
/home/balraj/Work/Smart College Management System/src/main/java/com/college/management/ReportGenerator.java
|
||||
/home/balraj/Work/Smart College Management System/src/main/java/com/college/management/PrivateChatUI.java
|
||||
/home/balraj/Work/Smart College Management System/src/main/java/com/college/management/AdminDashboard.java
|
||||
/home/balraj/Work/Smart College Management System/src/main/java/com/college/management/FacultyDashboard.java
|
||||
/home/balraj/Work/Smart College Management System/src/main/java/com/college/management/StudentDashboard.java
|
||||
/home/balraj/Work/Smart College Management System/src/main/java/com/college/management/User.java
|
||||
Reference in New Issue
Block a user