diff --git a/WebContent/addProduct.jsp b/WebContent/addProduct.jsp index 6caf5f34..b88d2edf 100644 --- a/WebContent/addProduct.jsp +++ b/WebContent/addProduct.jsp @@ -99,6 +99,13 @@ placeholder="Select Image" name="image" class="form-control" id="last_name" required> +
+ +
+
diff --git a/WebContent/header.jsp b/WebContent/header.jsp index aba1304c..7c03f8f8 100644 --- a/WebContent/header.jsp +++ b/WebContent/header.jsp @@ -72,6 +72,9 @@
  • Camera
  • Speakers
  • Tablets
  • +
  • most selling
  • +
  • least selling
  • +
  • Used
  • @@ -109,6 +112,10 @@
  • Camera
  • Speakers
  • Tablets
  • +
  • most selling
  • +
  • least selling
  • +
  • Used
  • + <% if (notf == 0) { @@ -163,6 +170,10 @@
  • Camera
  • Speakers
  • Tablets
  • +
  • most selling
  • +
  • least selling
  • +
  • Used
  • +
  • Stock
  • Shipped
  • diff --git a/WebContent/userHome.jsp b/WebContent/userHome.jsp index 255f4937..30e326c1 100644 --- a/WebContent/userHome.jsp +++ b/WebContent/userHome.jsp @@ -38,8 +38,22 @@ products = prodDao.searchAllProducts(search); message = "Showing Results for '" + search + "'"; } else if (type != null) { - products = prodDao.getAllProductsByType(type); - message = "Showing Results for '" + type + "'"; + if ("mostSelling".equals(type)) { + products = prodDao.getMostSelling(); + + } else if ("leastSelling".equals(type) ) { + products = prodDao.getMostSelling(); + Collections.reverse(products); + }else if("used".equals(type)) { + products = prodDao.getAllUsed(); + } + + else + + { + products = prodDao.getAllProductsByType(type); + } + message = "Showing Results for '" + type + "'"; } else { products = prodDao.getAllProducts(); } diff --git a/src/com/shashi/beans/ProductBean.java b/src/com/shashi/beans/ProductBean.java index c67c754e..b198a1f4 100644 --- a/src/com/shashi/beans/ProductBean.java +++ b/src/com/shashi/beans/ProductBean.java @@ -16,6 +16,9 @@ public ProductBean() { private double prodPrice; private int prodQuantity; private InputStream prodImage; + private int soldQ; + private boolean used; + public ProductBean(String prodId, String prodName, String prodType, String prodInfo, double prodPrice, int prodQuantity, InputStream prodImage) { @@ -27,6 +30,7 @@ public ProductBean(String prodId, String prodName, String prodType, String prodI this.prodPrice = prodPrice; this.prodQuantity = prodQuantity; this.prodImage = prodImage; + this.setUsed(used); } public String getProdId() { @@ -85,4 +89,26 @@ public void setProdImage(InputStream prodImage) { this.prodImage = prodImage; } + + public void setSoldQ(int soldQ){ + this.soldQ = soldQ; + } + + public int getSoldQ(){ + return this.soldQ; + } + + public void setUsed(int x) { + if(x==0) { + this.used=false; + + } + this.used = true; + } + + public boolean getUsed() { + return this.used; + } + + } diff --git a/src/com/shashi/service/ProductService.java b/src/com/shashi/service/ProductService.java index 0611f972..a68709c1 100644 --- a/src/com/shashi/service/ProductService.java +++ b/src/com/shashi/service/ProductService.java @@ -8,7 +8,7 @@ public interface ProductService { public String addProduct(String prodName, String prodType, String prodInfo, double prodPrice, int prodQuantity, - InputStream prodImage); + InputStream prodImage,int used); public String addProduct(ProductBean product); @@ -35,4 +35,11 @@ public String addProduct(String prodName, String prodType, String prodInfo, doub public boolean sellNProduct(String prodId, int n); public int getProductQuantity(String prodId); + + + public List getMostSelling(); + + public boolean increaseSoldQ(String prodId,int n); + + public List getAllUsed(); } diff --git a/src/com/shashi/service/impl/OrderServiceImpl.java b/src/com/shashi/service/impl/OrderServiceImpl.java index a82cd4d0..1f515937 100644 --- a/src/com/shashi/service/impl/OrderServiceImpl.java +++ b/src/com/shashi/service/impl/OrderServiceImpl.java @@ -53,6 +53,7 @@ public String paymentSuccess(String userName, double paidAmount) { break; else ordered = new ProductServiceImpl().sellNProduct(item.getProdId(), item.getQuantity()); + new ProductServiceImpl().increaseSoldQ(item.getProdId(), item.getQuantity()); if (!ordered) break; diff --git a/src/com/shashi/service/impl/ProductServiceImpl.java b/src/com/shashi/service/impl/ProductServiceImpl.java index 7c85a5de..a6fa98f1 100644 --- a/src/com/shashi/service/impl/ProductServiceImpl.java +++ b/src/com/shashi/service/impl/ProductServiceImpl.java @@ -7,7 +7,7 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; - +import java.util.Collections; import com.shashi.beans.DemandBean; import com.shashi.beans.ProductBean; import com.shashi.service.ProductService; @@ -224,6 +224,93 @@ public List getAllProducts() { return products; } + + @Override + public List getMostSelling(){ + List products = new ArrayList(); + + Connection con = DBUtil.provideConnection(); + PreparedStatement ps = null; + ResultSet rs = null; + + try { + ps = con.prepareStatement("select * from product ORDER BY soldQ"); + + rs = ps.executeQuery(); + + while (rs.next()) { + + ProductBean product = new ProductBean(); + + product.setProdId(rs.getString(1)); + product.setProdName(rs.getString(2)); + product.setProdType(rs.getString(3)); + product.setProdInfo(rs.getString(4)); + product.setProdPrice(rs.getDouble(5)); + product.setProdQuantity(rs.getInt(6)); + product.setProdImage(rs.getAsciiStream(7)); + product.setSoldQ(rs.getInt(8)); + product.setUsed(rs.getInt(9)); + + products.add(product); + + } + + } catch (SQLException e) { + e.printStackTrace(); + } + + DBUtil.closeConnection(con); + DBUtil.closeConnection(ps); + DBUtil.closeConnection(rs); + Collections.reverse(products); + + return products; + } + + @Override + public List getAllUsed(){ + List products = new ArrayList(); + + Connection con = DBUtil.provideConnection(); + PreparedStatement ps = null; + ResultSet rs = null; + + try { + ps = con.prepareStatement("SELECT * FROM product WHERE used = 1 ORDER BY soldQ"); + + rs = ps.executeQuery(); + + while (rs.next()) { + + ProductBean product = new ProductBean(); + + product.setProdId(rs.getString(1)); + product.setProdName(rs.getString(2)); + product.setProdType(rs.getString(3)); + product.setProdInfo(rs.getString(4)); + product.setProdPrice(rs.getDouble(5)); + product.setProdQuantity(rs.getInt(6)); + product.setProdImage(rs.getAsciiStream(7)); + product.setSoldQ(rs.getInt(8)); + product.setUsed(rs.getInt(9)); + + products.add(product); + + } + + } catch (SQLException e) { + e.printStackTrace(); + } + + DBUtil.closeConnection(con); + DBUtil.closeConnection(ps); + DBUtil.closeConnection(rs); + Collections.reverse(products); + + return products; + } + @Override public List getAllProductsByType(String type) { List products = new ArrayList(); @@ -533,5 +620,36 @@ public int getProductQuantity(String prodId) { return quantity; } + @Override + public boolean increaseSoldQ(String prodId, int n) { + boolean flag = false; + + Connection con = DBUtil.provideConnection(); + + PreparedStatement ps = null; + + try { + + ps = con.prepareStatement("update product set soldQ=(psoldQ + ?) where pid=?"); + + ps.setInt(1, n); + + ps.setString(2, prodId); + + int k = ps.executeUpdate(); + + if (k > 0) + flag = true; + } catch (SQLException e) { + flag = false; + e.printStackTrace(); + } + + DBUtil.closeConnection(con); + DBUtil.closeConnection(ps); + + return flag; + } + } diff --git a/src/com/shashi/srv/AddProductSrv.java b/src/com/shashi/srv/AddProductSrv.java index 2bf353e6..5dca6e7a 100644 --- a/src/com/shashi/srv/AddProductSrv.java +++ b/src/com/shashi/srv/AddProductSrv.java @@ -48,7 +48,7 @@ else if (userName == null || password == null) { String prodInfo = request.getParameter("info"); double prodPrice = Double.parseDouble(request.getParameter("price")); int prodQuantity = Integer.parseInt(request.getParameter("quantity")); - + int prodUsed = Integer.parseInt(request.getParameter("used")); Part part = request.getPart("image"); InputStream inputStream = part.getInputStream(); @@ -57,7 +57,7 @@ else if (userName == null || password == null) { ProductServiceImpl product = new ProductServiceImpl(); - status = product.addProduct(prodName, prodType, prodInfo, prodPrice, prodQuantity, prodImage); + status = product.addProduct(prodName, prodType, prodInfo, prodPrice, prodQuantity, prodImage,prodUsed); RequestDispatcher rd = request.getRequestDispatcher("addProduct.jsp?message=" + status); rd.forward(request, response);