You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/main/java/sealey/javafxinventorysystem/AddPart.java
+53-2Lines changed: 53 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -22,6 +22,15 @@
22
22
importjava.util.Objects;
23
23
importjava.util.ResourceBundle;
24
24
25
+
/*
26
+
* @author Max Sealey
27
+
*
28
+
* The AddPart controller controls the components for the AddPart scene, and displays radio buttons to indicate whether the created item is In-House or Outsourced,
29
+
* a disabled TextField containing an auto-generated unique ID #, and TextFields for the item's name, inventory amount, price, max items possible, min items possible,
30
+
* and either the machine ID (when In-House radio button is selected) or company name (when Outsourced radio button is selected). Below that is the save button and the
31
+
* cancel button, both of which navigate back to the MainWindow, though only the save button adds the entered data into the table (upon input validation).
32
+
* */
33
+
25
34
publicclassAddPartimplementsInitializable {
26
35
Stagestage;
27
36
Parentscene;
@@ -64,8 +73,13 @@ public class AddPart implements Initializable {
64
73
@FXML
65
74
privateButtonsaveButton;
66
75
67
-
// Helper Functions
68
-
@FXML
76
+
/*
77
+
* The search() method is a helper function that returns a boolean indicating whether an integer is already being used as an ID number for an existing part.
78
+
* This is only called in the generateID() method to ensure that the auto-generated ID is unique.
79
+
*
80
+
* @param id Integer to be checked for ID uniqueness
81
+
* @return boolean True if ID belongs to existing part, False otherwise
82
+
* */
69
83
booleansearch(intid){
70
84
for(Partp : Inventory.getAllParts())
71
85
{
@@ -75,6 +89,12 @@ boolean search(int id){
75
89
}
76
90
returnfalse;
77
91
}
92
+
93
+
/*
94
+
* The generateID() method is a helper function that generates an ID number for created part. Always returns the next unique integer in sequential order
95
+
*
96
+
* @return id Integer that is either 1 (if List is empty), or the next unique integer
97
+
* */
78
98
intgenerateID() {
79
99
intid = 1;
80
100
for(Parta : Inventory.getAllParts()) {
@@ -87,13 +107,26 @@ int generateID() {
87
107
returnid;
88
108
}
89
109
110
+
/*
111
+
* The onActionCancel() event handler navigates back to the MainWindow without adding any data to Inventory When the Cancel button is clicked.
112
+
*
113
+
* @param event ActionEvent object for the Cancel button
114
+
* @throws IOException Throws error message if there is an issue with the event
scene = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("MainWindow.fxml")));
94
120
stage.setScene(newScene(scene));
95
121
stage.show();
96
122
}
123
+
124
+
/*
125
+
* The onActionSave() event handler checks for valid input when the Save button is clicked, and if valid, adds Part to Inventory and navigates back to the MainWindow.
126
+
*
127
+
* @param event ActionEvent object for the Save button
128
+
* @throws IOException Throws error message if there is an issue with the event
0 commit comments