-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNewManager.java
More file actions
103 lines (81 loc) · 3.34 KB
/
NewManager.java
File metadata and controls
103 lines (81 loc) · 3.34 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
98
99
100
101
102
103
package controller;
import javafx.event.ActionEvent;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import model.Branch;
import model.BranchManager;
import services.BranchDAO;
import services.BranchManagerDAO;
public class NewManager {
private final BranchManagerDAO branchManagerDAO = new BranchManagerDAO();
private final BranchManager branchManager = new BranchManager();
private final BranchDAO branchDAO = new BranchDAO();
public Button addManagerButton;
public TextField salaryField;
public TextField branchCodeField;
public PasswordField passwordField;
public TextField nameField;
public TextField usernameField;
public TextField emailField;
public void addManagerAction(ActionEvent event) {
if (isAnyFieldEmpty()) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Missing Information");
alert.setHeaderText(null);
alert.setContentText("Please fill in all the fields before proceeding.");
alert.showAndWait();
return;
}
branchManager.setBranchCode(branchCodeField.getText());
branchManager.setEmail(emailField.getText());
branchManager.setName(nameField.getText());
branchManager.setUsername(usernameField.getText());
branchManager.setPassword(passwordField.getText());
branchManager.setRole("Manager");
branchManager.setSalary(Double.parseDouble(salaryField.getText()));
Branch branch = branchDAO.getBranchByCode(branchCodeField.getText());
if (branch == null) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Branch Not Found");
alert.setHeaderText(null);
alert.setContentText("The branch with the given code does not exist. Please create the branch first.");
alert.showAndWait();
return;
}
branchManager.setEmployeeCount(branch.getEmployeeCount());
boolean success = branchManagerDAO.addBranchManager(branchManager);
if (success) {
// Display a success message
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Success");
alert.setHeaderText(null);
alert.setContentText("Branch Manager has been added successfully!");
alert.showAndWait();
clearFields();
} else {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error");
alert.setHeaderText(null);
alert.setContentText("An error occurred while adding the Branch Manager. Please try again.");
alert.showAndWait();
}
}
private void clearFields() {
usernameField.clear();
nameField.clear();
emailField.clear();
passwordField.clear();
branchCodeField.clear();
salaryField.clear();
}
private boolean isAnyFieldEmpty() {
return usernameField.getText().isEmpty()
|| nameField.getText().isEmpty()
|| emailField.getText().isEmpty()
|| passwordField.getText().isEmpty()
|| branchCodeField.getText().isEmpty()
|| salaryField.getText().isEmpty();
}
}