diff --git a/.gitignore b/.gitignore index 9f9615c998ecd8b8055613ea52ce5e61027dfa16..b21a14b0534df92abd3b1e5fe8e10c120fa989c4 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,4 @@ Dokumentation/Thumbs.db Dokumentation/Klassendiagramm/Thumbs.db Dokumentation/Uebung 1/Thumbs.db ======= ->>>>>>> 47d7bfd324c39b8339db585da515957e5ac54bd3 +>>>>>>> 47d7bfd324c39b8339db585da515957e5ac54bd3 \ No newline at end of file diff --git a/src/main/java/org/s4s/dao/ShopDAO.java b/src/main/java/org/s4s/dao/ShopDAO.java index ea5d10b659dabdf95c5dc1c934d16cf2e2ed5905..ff7bdd88d26fe1250c383390e4b9ef7e57b3261d 100644 --- a/src/main/java/org/s4s/dao/ShopDAO.java +++ b/src/main/java/org/s4s/dao/ShopDAO.java @@ -11,4 +11,6 @@ public interface ShopDAO { boolean viewShop(User user); boolean addShop(User user, String shopName); + + int getShopIdByUserId(int userId); } diff --git a/src/main/java/org/s4s/gui/views/ArtikelerstellungsView.java b/src/main/java/org/s4s/gui/views/ArtikelerstellungsView.java index 7b6f25b9d68ba90b0b0a4ce3f9abcf21007f61b5..c07d6cd9c0899d051388dc71d2154406745fab47 100644 --- a/src/main/java/org/s4s/gui/views/ArtikelerstellungsView.java +++ b/src/main/java/org/s4s/gui/views/ArtikelerstellungsView.java @@ -5,6 +5,7 @@ */ package org.s4s.gui.views; +import com.vaadin.navigator.View; import com.vaadin.navigator.ViewChangeListener; import com.vaadin.server.FileResource; import com.vaadin.server.FontAwesome; @@ -31,13 +32,14 @@ import com.vaadin.ui.VerticalLayout; import java.io.File; import java.io.FileOutputStream; import java.io.OutputStream; -import org.s4s.dao.impl.ArtikelerstellungsControl; +import org.s4s.process.control.ArtikelerstellungsControl; +import org.s4s.process.control.ShopControl; /** * * @author synot */ -public class ArtikelerstellungsView extends TemplateView { +public class ArtikelerstellungsView extends TemplateView implements View { @Override public void enter(ViewChangeListener.ViewChangeEvent event) { @@ -134,27 +136,54 @@ public class ArtikelerstellungsView extends TemplateView { nsModul.setNullSelectionAllowed(false); ArtikelerstellungsControl aCont = new ArtikelerstellungsControl(); + ShopControl sCont = new ShopControl(); try { nsModul.addItems(aCont.getModul()); } catch (Exception e) { } nsModul.setNullSelectionAllowed(false); - - bErstellen.addClickListener((Button.ClickEvent event) -> { - if (tfName.isEmpty()) { - Notification.show("Bitte einen Namen eingeben!", Notification.Type.ERROR_MESSAGE); - } else if(taBeschreibung.isEmpty()) { - Notification.show("Bitte eine Beschreibung eingeben!", Notification.Type.ERROR_MESSAGE); - } else if(tfPreis.isEmpty()) { - Notification.show("Bitte einen Preis eingeben!", Notification.Type.ERROR_MESSAGE); - } else if(nsKategorie.isEmpty()) { - Notification.show("Bitte wählen Sie eine Kategorie aus!", Notification.Type.ERROR_MESSAGE); - } else { - boolean result = aCont.addProduct(tfName.getValue(), taBeschreibung.getValue(), dfVon.getValue(), dfBis.getValue(), tfPreis.getValue(), Byte image, int aId, int sId, true, 3, 2); - } - }); +// bErstellen.addClickListener((Button.ClickEvent event) -> { +// +// if (tfName.isEmpty()) { +// Notification.show("Bitte einen Namen eingeben!", Notification.Type.ERROR_MESSAGE); +// } else if(taBeschreibung.isEmpty()) { +// Notification.show("Bitte eine Beschreibung eingeben!", Notification.Type.ERROR_MESSAGE); +// } else if(tfPreis.isEmpty()) { +// Notification.show("Bitte einen Preis eingeben!", Notification.Type.ERROR_MESSAGE); +// } else if(nsKategorie.isEmpty()) { +// Notification.show("Bitte wählen Sie eine Kategorie aus!", Notification.Type.ERROR_MESSAGE); +// } else { +// try { +// User u = (User) UI.getCurrent().getSession().getAttribute(Roles.CURRENTUSER); +// int sId = sCont.getShopIdByUserId(u.getUserId()); +// int mId = aCont.getModulByName(nsModul.getValue().toString()); +// int cId = 0; +// if (nsKategorie.getValue().equals("Multimedia")) { +// cId = 1; +// } else { +// cId = 2; +// } +// +// String name = tfName.getValue(); +// String beschreibung = taBeschreibung.getValue(); +// Date dVon = dfVon.getValue(); +// Date dBis = dfBis.getValue(); +// double preis = Double.parseDouble(tfPreis.getValue()); +// +// boolean result = aCont.addProduct(name, beschreibung, dVon, dBis, preis, image, sId, mId, cId); +// +// if (result) { +// Notification.show("Artikel wurde erfolgreich gespeichert.", Notification.Type.ASSISTIVE_NOTIFICATION); +// } else { +// Notification.show("Artikel konnte nicht gespeichert werden!", Notification.Type.ERROR_MESSAGE); +// } +// } catch (DAOException ex) { +// Logger.getLogger(ArtikelerstellungsView.class.getName()).log(Level.SEVERE, null, ex); +// } +// } +// }); HorizontalLayout hKommand = new HorizontalLayout(bAbbrechen, bErstellen); HorizontalLayout hVerfuegbarkeit = new HorizontalLayout(dfVon, dfBis); diff --git a/src/main/java/org/s4s/process/control/ArtikelerstellungsControl.java b/src/main/java/org/s4s/process/control/ArtikelerstellungsControl.java index 42a47af6195aba6493be6481a470ad42432cc029..803c2f3db47591a6dbae015f09a65bd1b1350426 100644 --- a/src/main/java/org/s4s/process/control/ArtikelerstellungsControl.java +++ b/src/main/java/org/s4s/process/control/ArtikelerstellungsControl.java @@ -3,8 +3,10 @@ * To change this template file, choose Tools | Templates * and open the template in the editor. */ -package org.s4s.dao.impl; +package org.s4s.process.control; +import com.vaadin.ui.Image; +import com.vaadin.ui.UI; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; @@ -12,10 +14,13 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; import org.s4s.dao.ProductDAO; +import org.s4s.dao.impl.AbstractDatabaseClass; import org.s4s.exceptions.DAOException; import org.s4s.modell.dto.Product; import org.s4s.modell.dto.Shop; +import org.s4s.modell.dto.User; import org.s4s.services.db.JDBCConnection; +import org.s4s.services.util.Roles; /** * @@ -23,6 +28,9 @@ import org.s4s.services.db.JDBCConnection; */ public class ArtikelerstellungsControl extends AbstractDatabaseClass implements ProductDAO { + private static final User user = (User) UI.getCurrent().getSession().getAttribute(Roles.CURRENTUSER); + private final Statement statement = JDBCConnection.getInstance().getStatement(); + //DB-Block Statement st; String sql_select; @@ -33,7 +41,7 @@ public class ArtikelerstellungsControl extends AbstractDatabaseClass implements ResultSet result; try { - sql_select = "SELECT * FROM \"ERR\".\"Modul\""; + sql_select = "SELECT * FROM \"ERR\".\"modul\""; result = JDBCConnection.getInstance().getStatement().executeQuery(sql_select); while (result.next()) { @@ -46,10 +54,25 @@ public class ArtikelerstellungsControl extends AbstractDatabaseClass implements return moduls; } + + public int getModulByName(String modul) throws DAOException { + int mId = 0; + ResultSet result; - @Override - public List<Product> getProductByTyp(String typ) throws DAOException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + try { + sql_select = "SELECT * FROM \"ERR\".\"modul\"" + + "WHERE name = \'" + modul + "\'"; + result = JDBCConnection.getInstance().getStatement().executeQuery(sql_select); + + while (result.next()) { + mId = result.getInt("modulid"); + } + + } catch (SQLException e) { + throw new DAOException(e); + } + + return mId; } @Override @@ -57,13 +80,12 @@ public class ArtikelerstellungsControl extends AbstractDatabaseClass implements throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } - @Override - public boolean addProduct(String name, String beschreibung, Date dVon, Date dBis, double preis, Byte pic, int artikelID, int shopID, boolean gekauft, int modulID, int cat) throws DAOException { + public boolean addProduct(String name, String beschreibung, Date dVon, Date dBis, double preis, Image pic, int shopID, int modulID, int cat) throws DAOException { boolean done = false; try { - sql_update = "INSERT INTO \"ERR\".\"artikel\" " - + "VALUES(\'" + name + "\', \'" + beschreibung + "\', \'" + dVon + "\', \'" + preis + "\', \'" + dBis + "\', \'" + pic + "\', \'" + artikelID + "\', \'" + shopID + "\', \'" + gekauft + "\', \'" + modulID + "\', \'" + cat + "\')"; + sql_update = "INSERT INTO \"ERR\".\"artikel\"(name, beschreibung, datum_von, preis, datum_bis, foto, shopid, gekauft, modulid, kategorie) " + + "VALUES(\'" + name + "\', \'" + beschreibung + "\', \'" + dVon + "\', \'" + preis + "\', \'" + dBis + "\', \'" + pic + "\', \'" + modulID + "\', \'" + cat + "\')"; int exe = JDBCConnection.getInstance().getStatement().executeUpdate(sql_select); diff --git a/src/main/java/org/s4s/process/control/ContactControl.java b/src/main/java/org/s4s/process/control/ContactControl.java index a00198f01822a7c09c73644abe867bea3a185b88..b0fc00ad673fd6fa9bed14e2adab699d3883df7d 100644 --- a/src/main/java/org/s4s/process/control/ContactControl.java +++ b/src/main/java/org/s4s/process/control/ContactControl.java @@ -1,9 +1,12 @@ -package org.s4s.process.control; - -/** - * - * @author synot - */ -public class ContactControl { - -} +//package org.s4s.process.control; +// +//import com.vaadin.navigator.View; +//import org.s4s.gui.views.TemplateView; +// +///** +// * +// * @author synot +// */ +//public class ContactControl extends TemplateView implements View { +// +//} diff --git a/src/main/java/org/s4s/process/control/ShopControl.java b/src/main/java/org/s4s/process/control/ShopControl.java index 25df8f4e4619f1dc6916a47841f23585ffb48953..798e2a2ce29b49571a30e2241fb404f8814b5499 100644 --- a/src/main/java/org/s4s/process/control/ShopControl.java +++ b/src/main/java/org/s4s/process/control/ShopControl.java @@ -1,6 +1,5 @@ package org.s4s.process.control; -import com.vaadin.server.VaadinSession; import com.vaadin.ui.UI; import java.sql.ResultSet; import java.sql.SQLException; @@ -94,6 +93,23 @@ public class ShopControl extends AbstractDatabaseClass implements ShopDAO { } } + + @Override + public int getShopIdByUserId(int userId) { + int result = 0; + try { + ResultSet set = executeQuery("SELECT *" + + "FROM \"ERR\".\"shop\" " + + "WHERE besitzer = " + user.getUserId() + ";"); + + if (set.next()) { + result = set.getInt("shopid"); + } + } catch (SQLException ex) { + Logger.getLogger(ShopDAO.class.getName()).log(Level.SEVERE, null, ex); + } + return result; + } }