From a16f979d2c8bfe5362ad42169b202202793e5f6b Mon Sep 17 00:00:00 2001 From: barblade Date: Thu, 12 Jun 2014 19:52:39 +0200 Subject: [PATCH] Dodana klasa RetrieveData --- .../java/ksiazka/kucharska/RetrieveData.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/main/java/ksiazka/kucharska/RetrieveData.java diff --git a/src/main/java/ksiazka/kucharska/RetrieveData.java b/src/main/java/ksiazka/kucharska/RetrieveData.java new file mode 100644 index 0000000..5cd1818 --- /dev/null +++ b/src/main/java/ksiazka/kucharska/RetrieveData.java @@ -0,0 +1,60 @@ +package ksiazka.kucharska; + +import java.util.List; + +import javax.swing.DefaultListModel; + +import db.Cookbook; +import db.Recipe; +import ksiazka.kucharska.FrmMain; + +public class RetrieveData extends FrmMain{ + /** + * + */ + private static final long serialVersionUID = 1L; + public static void insertSampleData(){ + Cookbook myCb = new Cookbook(); + myCb.insertRecipe("Kanapka", + "Chleb, margaryna, szynka", + "Posmarować kanapke margaryną i położyć na niej plaster szynki", + "kanapka, szynka, chleb"); + myCb.insertRecipe("Kanapka z sererm", + "Chleb, margaryna, ser", + "Posmarować kanapke margaryną i położyć na niej plaster sera", + "kanapka, ser, chleb"); + myCb.closeConnection(); + } + public static void fillList(){ + Cookbook myCb = new Cookbook(); + List names = myCb.selectNames(); + + DefaultListModel recipesList; + recipesList = getRecipesList(); + + for (String r : names) + { + recipesList.addElement(r); + } + myCb.closeConnection(); + } + public static void fillComponents(String name){ + Cookbook myCb = new Cookbook(); + Recipe myRecipe = myCb.selectRecipe(name); + lblRecipeTitle.setText(name); + txtIngredients.setText(myRecipe.getIngredients()); + txtDescription.setText(myRecipe.getDescription()); + txtTags.setText(myRecipe.getTags()); + myCb.closeConnection(); + } + public static void addNewRecipe(){ + Cookbook myCb = new Cookbook(); + myCb.insertRecipe(txtEdTitle.getText(), txtIngredients.getText(), txtDescription.getText(), txtTags.getText()); + myCb.closeConnection(); + } + public static void removeRecipe(String name){ + Cookbook myCb = new Cookbook(); + myCb.deleteRecipe(name); + myCb.closeConnection(); + } +}