-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConstructFeedBackController.java
More file actions
99 lines (75 loc) · 3.28 KB
/
ConstructFeedBackController.java
File metadata and controls
99 lines (75 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package jobinterviewpreparationsystem;
import java.sql.Connection;
import java.sql.PreparedStatement;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import jobinterviewpreparationsystem.DB.DatabaseConnection;
public class ConstructFeedBackController {
@FXML
private TextField userName; // User ID input field
@FXML
private TextField feedback; // Feedback input field
@FXML
private TextField rating; // Rating input field
@FXML
private Label submit; // Label to display submit status
// GoBack button
private DatabaseConnection dbConnection; // Database connection utility
public ConstructFeedBackController() throws SQLException {
dbConnection = DatabaseConnection.getInstance(); // Get the database connection instance
}
// Handler for submitting feedback
@FXML
private void handleSubmitButton(ActionEvent event) {
// Retrieve user input from text fields
String userId = userName.getText().trim();
String feedbackText = feedback.getText().trim();
String ratingText = rating.getText().trim();
// Validate input
if (userId.isEmpty() || feedbackText.isEmpty() || ratingText.isEmpty()) {
showAlert("Error", "Please fill in all fields.");
return;
}
try {
// Save feedback to the database
boolean success = saveFeedbackToDatabase(userId, feedbackText, ratingText);
if (success) {
showAlert("Success", "Feedback submitted successfully.");
} else {
showAlert("Error", "Failed to submit feedback.");
}
} catch (SQLException e) {
e.printStackTrace();
showAlert("Error", "Database error occurred. Please try again.");
}
}
// Save feedback to the database
private boolean saveFeedbackToDatabase(String userId, String feedbackText, String ratingText) throws SQLException {
String query = "INSERT INTO feedback_table (user_id, feedback, rating) VALUES (?, ?, ?)";
try (Connection connection = DatabaseConnection.getInstance().getConnection();
PreparedStatement stmt = connection.prepareStatement(query);) {
stmt.setInt(1, Integer.parseInt(userId)); // Set userId (assumed to be an integer)
stmt.setString(2, feedbackText); // Set feedback text
stmt.setInt(3, Integer.parseInt(ratingText)); // Set rating (assumed to be an integer)
int rowsInserted = stmt.executeUpdate();
return rowsInserted > 0; // Return true if at least one row is inserted
}
}
private void showAlert(String title, String message) {
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle(title);
alert.setHeaderText(null);
alert.setContentText(message);
alert.showAndWait();
}
// Go back to the previous screen (navigate to the previous page)
@FXML
private void handleGoBackButton(ActionEvent event) {
JobInterviewPreparationSystem.showMentorScreen(); // Implement your method to navigate back
}
}