File tree Expand file tree Collapse file tree
src/main/java/sealey/javafxinventorysystem Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -64,6 +64,29 @@ public class AddPart implements Initializable {
6464 @ FXML
6565 private Button saveButton ;
6666
67+ // Helper Functions
68+ @ FXML
69+ boolean search (int id ){
70+ for (Part p : Inventory .getAllParts ())
71+ {
72+ if (p .getId () == id ){
73+ return true ;
74+ }
75+ }
76+ return false ;
77+ }
78+ int generateID () {
79+ int id = 1 ;
80+ for (Part a : Inventory .getAllParts ()) {
81+ if (search (id )){
82+ id ++;
83+ } else {
84+ return id ;
85+ }
86+ }
87+ return id ;
88+ }
89+
6790 @ FXML
6891 void onActionCancel (ActionEvent event ) throws IOException {
6992 stage = (Stage )((Button )event .getSource ()).getScene ().getWindow ();
@@ -73,7 +96,7 @@ void onActionCancel(ActionEvent event) throws IOException {
7396 }
7497 @ FXML
7598 void onActionSave (ActionEvent event ) throws IOException {
76- int id = Integer .parseInt (partIDText .getText ());
99+ int id = Integer .parseInt (partIDText .getPromptText ());
77100 String name = partNameText .getText ();
78101 int inv = Integer .parseInt (inventoryText .getText ());
79102 double price = Double .parseDouble (priceText .getText ());
@@ -108,6 +131,6 @@ public void onActionMachineLabel(ActionEvent actionEvent) {
108131
109132 @ Override
110133 public void initialize (URL url , ResourceBundle resourceBundle ) {
111- System . out . println ( "initialized" );
134+ partIDText . setPromptText ( String . valueOf ( generateID ()) );
112135 }
113136}
You can’t perform that action at this time.
0 commit comments