コード例 #1
0
 /**
  * Updates updateEditRecipeList and UpdateIngredients when loading vista. Sets cellValueFactory
  * with the column names for the tableview.
  */
 @Override
 public void initialize(URL location, ResourceBundle resources) {
   System.out.println("Initialize EditRecipesController");
   mainController = VistaNavigator.getMainController();
   updateIngredients();
   Name.setCellValueFactory(new PropertyValueFactory<Ingredient, String>("name"));
   Amount.setCellValueFactory(new PropertyValueFactory<Ingredient, String>("amount"));
   Unit.setCellValueFactory(new PropertyValueFactory<Ingredient, String>("unit"));
   System.out.println("- End of Initialize EditRecipesController");
 }
コード例 #2
0
  /** ButtonMethod for updating data into the recipes */
  public void SubmitButtonAction() {
    String values = "";
    String columns = "Name, Type, Cuisine, Difficulty, Diet, Time, Description";
    String[] fields = {
      recipeName.getText(),
      recipeType.getText(),
      recipeCuisine.getText(),
      recipeDifficulty.getText(),
      recipeDiet.getText(),
      recipeTime.getText(),
      recipeDescription.getText()
    }; // Array with Values

    for (String value : fields) values += "'" + value + "',";
    values = values.substring(0, values.length() - 1);

    try {
      System.out.println("- SubmitButtonAction");
      insertInto("Recipes", columns, values); // Update data in columns with values
      System.out.println("- End of SubmitButtonAction");

      recipeID = fetchData("recipes", "ID", "Name='" + recipeName.getText() + "'").get(0).get(0);

      for (Object o : addedIngredientTable.getItems()) { // Foreach object in the list, getItems
        String iName = Name.getCellData(o).toString(); // iName = ingredientName
        String iAmount = Amount.getCellData(o).toString(); // iAmount = ingredientAmount
        String iUnit = Unit.getCellData(o).toString(); // iUnit = ingredientUnit

        System.out.println("TESTING" + iName);

        String currentId =
            fetchData("Ingredients", "ID", "Name='" + iName + "'")
                .toString(); // Fetches id where name
        currentId = currentId.replaceAll("\\[", "").replaceAll("\\]", ""); // is column-name

        System.out.println("RECIPE ID" + recipeID);
        System.out.println("Current ID" + currentId);

        insertInto(
            "RUI",
            "RID, IID, Quantity, Unit",
            "'" + recipeID + "','" + currentId + "','" + iAmount + "','" + iUnit + "'");

        // Inserts recipe id, current id,
      } // amount, and unit
    } catch (SQLException e) {
      e.printStackTrace();
    }

    Recipe.setSelectedByID(recipeID);
    VistaNavigator.loadVista(VistaNavigator.RECIPE);
  }