Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iuser/moetaz mohamed/check #26

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions WebContent/addProduct.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@
placeholder="Select Image" name="image" class="form-control"
id="last_name" required>
</div>
<div class="col-md-2 form-group">
<label for="featuredProduct">Used</label> <input
type="hidden" name="used" value="0"> <input
type="checkbox" class="form-control" id="last_name"
name="used" value="1">
</div>

</div>
<div class="row">
<div class="col-md-6 text-center" style="margin-bottom: 2px;">
Expand Down
11 changes: 11 additions & 0 deletions WebContent/header.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
<li><a href="index.jsp?type=camera">Camera</a></li>
<li><a href="index.jsp?type=speaker">Speakers</a></li>
<li><a href="index.jsp?type=tablet">Tablets</a></li>
<li><a href="index.jsp?type=mostSelling">most selling</a></li>
<li><a href="index.jsp?type=leastSelling">least selling</a></li>
<li><a href="index.jsp?type=used">Used</a></li>
</ul></li>
</ul>
</div>
Expand Down Expand Up @@ -109,6 +112,10 @@
<li><a href="userHome.jsp?type=camera">Camera</a></li>
<li><a href="userHome.jsp?type=speaker">Speakers</a></li>
<li><a href="userHome.jsp?type=tablet">Tablets</a></li>
<li><a href="userHome.jsp?type=mostSelling">most selling</a></li>
<li><a href="userHome.jsp?type=leastSelling">least selling</a></li>
<li><a href="userHome.jsp?type=used">Used</a></li>

</ul></li>
<%
if (notf == 0) {
Expand Down Expand Up @@ -163,6 +170,10 @@
<li><a href="adminViewProduct.jsp?type=camera">Camera</a></li>
<li><a href="adminViewProduct.jsp?type=speaker">Speakers</a></li>
<li><a href="adminViewProduct.jsp?type=tablet">Tablets</a></li>
<li><a href="adminViewProduct.jsp?type=mostSelling">most selling</a></li>
<li><a href="adminViewProduct.jsp?type=leastSelling">least selling</a></li>
<li><a href="adminViewProduct.jsp?type=used">Used</a></li>

</ul></li>
<li><a href="adminStock.jsp">Stock</a></li>
<li><a href="shippedItems.jsp">Shipped</a></li>
Expand Down
18 changes: 16 additions & 2 deletions WebContent/userHome.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
26 changes: 26 additions & 0 deletions src/com/shashi/beans/ProductBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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() {
Expand Down Expand Up @@ -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;
}


}
9 changes: 8 additions & 1 deletion src/com/shashi/service/ProductService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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<ProductBean> getMostSelling();

public boolean increaseSoldQ(String prodId,int n);

public List<ProductBean> getAllUsed();
}
1 change: 1 addition & 0 deletions src/com/shashi/service/impl/OrderServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
120 changes: 119 additions & 1 deletion src/com/shashi/service/impl/ProductServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -224,6 +224,93 @@ public List<ProductBean> getAllProducts() {
return products;
}


@Override
public List<ProductBean> getMostSelling(){
List<ProductBean> products = new ArrayList<ProductBean>();

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<ProductBean> getAllUsed(){
List<ProductBean> products = new ArrayList<ProductBean>();

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<ProductBean> getAllProductsByType(String type) {
List<ProductBean> products = new ArrayList<ProductBean>();
Expand Down Expand Up @@ -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;
}


}
4 changes: 2 additions & 2 deletions src/com/shashi/srv/AddProductSrv.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down