Skip to content
Snippets Groups Projects
Commit c54c42ca authored by Timo Jeremy Pinzauti's avatar Timo Jeremy Pinzauti
Browse files

Last Push. Produkte können jetzt auch gelöscht werden.

parent 461e5284
Branches Anforderungen
No related tags found
No related merge requests found
......@@ -30,4 +30,6 @@ public interface ProductDAO {
// Product - Attribute: Dienstleistung -> Timespan required
public boolean addProduct(String name, String beschreibung, Date dVon, Date dBis, double preis, Image pic, int shopID, int modulID, int cat) throws DAOException;
public void deleteProductById(int pId) throws DAOException;
}
......@@ -224,4 +224,17 @@ public class ProductDAOimpl extends AbstractDatabaseClass implements ProductDAO
return done;
}
@Override
public void deleteProductById(int pId) throws DAOException {
try {
sql_update = "DELETE FROM \"ERR\".\"artikel\" "
+ "WHERE \"artikelid\" = \'" + pId + "\';";
JDBCConnection.getInstance().getStatement().execute(sql_update);
} catch (Exception e) {
e.printStackTrace();
System.out.println("Exception occur: " + e);
}
}
}
package org.s4s.gui.views;
import com.sun.jmx.snmp.SnmpDefinitions;
import com.vaadin.data.util.BeanContainer;
import com.vaadin.data.util.BeanItem;
import com.vaadin.event.ItemClickEvent;
import com.vaadin.navigator.ViewChangeListener;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.ui.*;
......@@ -9,6 +12,7 @@ import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.s4s.dao.impl.ProductDAOimpl;
import org.s4s.exceptions.DAOException;
import org.s4s.modell.dto.*;
import org.s4s.process.control.ProductControl;
......@@ -28,6 +32,8 @@ public class ShopView extends TemplateView {
private final BeanContainer<Integer, Product> dataProducts = new BeanContainer<>(Product.class);
private final Table tableProducts = new Table("Products", dataProducts);
private Product selectedProduct = null;
@Override
public void enter(ViewChangeListener.ViewChangeEvent event) {
if (session.getAttribute(Roles.CURRENTUSER) == null) {
......@@ -81,6 +87,7 @@ public class ShopView extends TemplateView {
table.setVisibleColumns(new Object[]{"name", "price"});
table.setColumnHeader("name", "Name");
table.setColumnHeader("price", "Preis in €");
table.setSelectable(true);
verticalLayout.addComponent(table);
table.setSizeFull();
}
......@@ -102,7 +109,7 @@ public class ShopView extends TemplateView {
verticalLayout.addComponent(label_ShopDetails);
verticalLayout.setComponentAlignment(label_ShopDetails, Alignment.MIDDLE_CENTER);
Panel panel_ProductQuantity = new Panel("Anzahl Produkte: ");
Panel panel_ProductQuantity = new Panel("Anzahl Produkte: " + table.size());
Panel panel_Rating = new Panel("Bewertung: " + shop.getBewertung());
Panel panel_RatingNumber = new Panel("Bewertungsanzahl: " + shop.getBewertungsanzahl());
Panel panel_ShopName = new Panel("Anbieter: " + shop.getName());
......@@ -121,6 +128,32 @@ public class ShopView extends TemplateView {
setUpFooterAndHeader(verticalLayout);
button_deleteProduct.addClickListener((Button.ClickEvent event) -> {
if (!(selectedProduct == null)) {
try {
ProductDAOimpl.getInstance().deleteProductById(selectedProduct.getId());
if (ProductDAOimpl.getInstance().getProductById(selectedProduct.getId()).getName() != null) {
Notification.show("Das Produkt\n" + selectedProduct.getName() + "\nkonnte nicht gelöscht werden!", Notification.Type.ERROR_MESSAGE);
}
UI.getCurrent().getNavigator().navigateTo(Views.SHOPVIEW + "/" + shop.getShopId());
} catch (DAOException ex) {
Logger.getLogger(ShopView.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
Notification.show("Das Produkt\n" + selectedProduct.getName() + "\nkonnte nicht geladen werden!", Notification.Type.ERROR_MESSAGE);
}
});
table.addItemClickListener((ItemClickEvent event) -> {
BeanItem<Product> productBean = dataProducts.getItem(event.getItemId());
selectedProduct = productBean.getBean();
System.err.println(selectedProduct.getId() + "; " + selectedProduct.getName());
if (event.isDoubleClick()) {
UI.getCurrent().getNavigator().navigateTo(Views.ARTIKELDETAILS + "/" + selectedProduct.getId());
}
});
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment