Ejemplo n.º 1
0
  /** ButtonMethod for add ingredients from the ingredientList into the tableview */
  public void addIngredientButton() {

    String selectedIngredient = recipeIngredients.getSelectionModel().getSelectedItems().toString();
    selectedIngredient = selectedIngredient.replaceAll("\\[", "").replaceAll("\\]", "");

    items.add(
        new Ingredient(
            selectedIngredient,
            ingredientAmount.getText(),
            ingredientUnit.getSelectionModel().getSelectedItem().toString())); // Creates new
    addedIngredientTable.setItems(
        items); // Object of the type Ingredient and adds it to the tableView.
  }
Ejemplo n.º 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);
  }
Ejemplo n.º 3
0
  /** Searchfield for searching ingredients in the ingredientList */
  public void updateIngredientSearch() {
    ArrayList<ArrayList<String>> dataSet;
    ObservableList<String> itemList = FXCollections.observableArrayList();
    String condition = "Name LIKE '" + "%" + ingredientSearch.getText() + "%'";
    System.out.println("Condition " + condition);

    try {

      dataSet = fetchData("Ingredients", "Name", condition);

      for (ArrayList<String> element : dataSet) {
        itemList.add(element.get(0));
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }
    recipeIngredients.setItems(
        itemList); // Sets the listview to show the ingredients that matches the search
  } // Criteria