-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddNewVendor.java
More file actions
83 lines (63 loc) · 2.11 KB
/
AddNewVendor.java
File metadata and controls
83 lines (63 loc) · 2.11 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
package controller;
import javafx.fxml.FXML;
import javafx.scene.control.TextField;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.stage.Stage;
import model.Vendor;
import services.VendorDAO;
public class AddNewVendor {
@FXML
private TextField vendorIdField;
@FXML
private TextField nameField;
@FXML
private TextField contactInfoField;
public VendorDAO vendorDAO=new VendorDAO();
@FXML
private void handleAddVendor() {
// Validate input fields
if (validateInputs()) {
String vendorId = vendorIdField.getText().trim();
String name = nameField.getText().trim();
String contactInfo = contactInfoField.getText().trim();
// Here you would typically call a service or repository to save the vendor
saveVendor(vendorId, name, contactInfo);
// Show success message
showAlert("Vendor Added", "New vendor has been successfully added to the system.");
// Close the window
closeWindow();
}
}
@FXML
private void handleCancel() {
closeWindow();
}
private boolean validateInputs() {
if (vendorIdField.getText().trim().isEmpty()) {
showAlert("Validation Error", "Vendor ID cannot be empty.");
return false;
}
if (nameField.getText().trim().isEmpty()) {
showAlert("Validation Error", "Vendor Name cannot be empty.");
return false;
}
return true;
}
private void saveVendor(String vendorId, String name, String contactInfo)
{
Vendor vendor=new Vendor(vendorId,name,contactInfo);
vendorDAO.addVendor(vendor);
}
private void showAlert(String title, String content) {
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle(title);
alert.setHeaderText(null);
alert.setContentText(content);
alert.showAndWait();
}
private void closeWindow() {
Stage stage = (Stage) vendorIdField.getScene().getWindow();
stage.close();
}
}