Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Chuong fix profile #9

Merged
merged 4 commits into from
Nov 28, 2023
Merged
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
2 changes: 1 addition & 1 deletion flower_shop.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Nov 28, 2023 at 10:11 AM
-- Generation Time: Nov 28, 2023 at 10:41 AM
-- Server version: 10.4.28-MariaDB
-- PHP Version: 8.2.4

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
response.setContentType("text/html; charset=UTF-8");

List<Categories> listCAT = CategoriesDAO.getInstance().selectAll();
List<Product> listP = ProductDAO.getInstance().randomPd(8);
List<Product> listP = ProductDAO.getInstance().randProduct(2);

request.setAttribute("listCAT", listCAT);
request.setAttribute("listP", listP);
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/bakaqc/flower/controller/ProfileController.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.bakaqc.flower.controller;

import com.bakaqc.flower.dao.OrderDAO;
import com.bakaqc.flower.model.HistoryBuy;
import com.bakaqc.flower.model.User;
import java.io.*;
import java.util.List;
import javax.servlet.*;
import javax.servlet.http.*;

Expand All @@ -12,7 +15,16 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");

HttpSession session = request.getSession();
User us = (User) session.getAttribute("user");
int amountSold = OrderDAO.getInstance().quantitySold(us.getId());
int amountCan = OrderDAO.getInstance().amountCanceled(us.getId());
List<HistoryBuy> list = OrderDAO.getInstance().historyBuy(us.getId());

request.setAttribute("amountS", amountSold);
request.setAttribute("amountC", amountCan);
request.setAttribute("listBuy", list);
request.getRequestDispatcher("/view/user_profile.jsp").forward(request, response);
}

Expand Down
84 changes: 82 additions & 2 deletions src/main/java/com/bakaqc/flower/dao/OrderDAO.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bakaqc.flower.dao;

import com.bakaqc.flower.model.HistoryBuy;
import com.bakaqc.flower.model.Order;
import com.bakaqc.flower.model.option.OrderStatus;
import com.bakaqc.flower.model.option.Payment;
Expand Down Expand Up @@ -82,6 +83,52 @@ public List<Order> selectById(String id) {
return list;
}

public int quantitySold(int userID) {
int amount = 0;

try {
Connection conn = JDBC.getConnection();

PreparedStatement smt = conn.prepareStatement("SELECT o.id, o.user_id, d.amount FROM `data_order` d JOIN `order` o ON d.order_id = o.id WHERE o.status <> 'canceled' AND o.user_id = ?");
smt.setInt(1, userID);

ResultSet rs = smt.executeQuery();

while (rs.next()) {
amount = rs.getInt("amount");
}

JDBC.closeConnection(conn);
} catch (SQLException ex) {
System.err.println(ex.getMessage());
}

return amount;
}

public int amountCanceled(int userID) {
int amount = 0;

try {
Connection conn = JDBC.getConnection();

PreparedStatement smt = conn.prepareStatement("SELECT o.id, o.user_id, d.amount FROM `data_order` d JOIN `order` o ON d.order_id = o.id WHERE o.status = 'canceled' AND o.user_id = ?");
smt.setInt(1, userID);

ResultSet rs = smt.executeQuery();

while (rs.next()) {
amount = rs.getInt("amount");
}

JDBC.closeConnection(conn);
} catch (SQLException ex) {
System.err.println(ex.getMessage());
}

return amount;
}

@Override
public void insert(Order ob) {
try {
Expand Down Expand Up @@ -140,8 +187,41 @@ public void delete(String id) {
}
}

public List<HistoryBuy> historyBuy(int userId) {

List<HistoryBuy> list = new ArrayList<>();
try {
Connection conn = JDBC.getConnection();

PreparedStatement smt = conn.prepareStatement("SELECT o.user_id, p.banners, p.name, d.amount, o.total_price, o.payment, o.status, o.create_at "
+ "FROM `data_order` d JOIN `order` o ON d.order_id = o.id JOIN `product` p ON d.product_id = p.id WHERE o.user_id = ? ORDER BY o.id DESC");
smt.setInt(1, userId);

ResultSet rs = smt.executeQuery();

while (rs.next()) {
HistoryBuy hb = new HistoryBuy();
hb.setBannersP(rs.getString("banners"));
hb.setNameP(rs.getString("name"));
hb.setAmountP(rs.getInt("amount"));
hb.setTotalPriceP(rs.getInt("total_price"));
hb.setPaymentP(Payment.create(rs.getString("payment")));
hb.setStatusP(OrderStatus.create(rs.getString("status")));
hb.setCreateAtP(Convert.convert(rs.getTimestamp("create_at")));

list.add(hb);
}

JDBC.closeConnection(conn);
} catch (SQLException ex) {
System.err.println(ex.getMessage());
}
System.out.println(list);
return list;
}

public static void main(String[] args) {
getInstance().selectAll();
// getInstance().delete("31");
getInstance().historyBuy(2);

}
}
4 changes: 2 additions & 2 deletions src/main/java/com/bakaqc/flower/dao/ProductDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,12 @@ public String getNameCAT(String pid) {
return null;
}

public List<Product> randomPd(int limit) {
public List<Product> randProduct(int limit) {
List<Product> list = new ArrayList<>();
try {
Connection c = JDBC.getConnection();

PreparedStatement st = c.prepareStatement("SELECT * FROM product ORDER BY RAND() LIMIT ?");
PreparedStatement st = c.prepareStatement("SELECT * FROM ( SELECT p.*, ROW_NUMBER() OVER (PARTITION BY p.category_id ORDER BY RAND()) as row_num FROM product p ) AS ranked WHERE row_num <= ? ORDER BY RAND();");
st.setInt(1, limit);

ResultSet rs = st.executeQuery();
Expand Down
111 changes: 111 additions & 0 deletions src/main/java/com/bakaqc/flower/model/HistoryBuy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package com.bakaqc.flower.model;

import com.bakaqc.flower.model.option.OrderStatus;
import com.bakaqc.flower.model.option.Payment;
import java.time.LocalDateTime;

public class HistoryBuy {
private int userID;
private String bannersP;
private String nameP;
private int amountP;
private int totalPriceP;
private Payment paymentP;
private OrderStatus statusP;
private LocalDateTime createAtP;

public HistoryBuy() {
}

public HistoryBuy(int userID, String bannersP, String nameP, int amountP, int totalPriceP, Payment paymentP, OrderStatus statusP, LocalDateTime createAtP) {
this.userID = userID;
this.bannersP = bannersP;
this.nameP = nameP;
this.amountP = amountP;
this.totalPriceP = totalPriceP;
this.paymentP = paymentP;
this.statusP = statusP;
this.createAtP = createAtP;
}

public HistoryBuy(String bannersP, String nameP, int amountP, int totalPriceP, Payment paymentP, OrderStatus statusP, LocalDateTime createAtP) {
this.bannersP = bannersP;
this.nameP = nameP;
this.amountP = amountP;
this.totalPriceP = totalPriceP;
this.paymentP = paymentP;
this.statusP = statusP;
this.createAtP = createAtP;
}

public int getUserID() {
return userID;
}

public void setUserID(int userID) {
this.userID = userID;
}

public String getBannersP() {
return bannersP;
}

public void setBannersP(String bannersP) {
this.bannersP = bannersP;
}

public String getNameP() {
return nameP;
}

public void setNameP(String nameP) {
this.nameP = nameP;
}

public int getAmountP() {
return amountP;
}

public void setAmountP(int amountP) {
this.amountP = amountP;
}

public int getTotalPriceP() {
return totalPriceP;
}

public void setTotalPriceP(int totalPriceP) {
this.totalPriceP = totalPriceP;
}

public Payment getPaymentP() {
return paymentP;
}

public void setPaymentP(Payment paymentP) {
this.paymentP = paymentP;
}

public OrderStatus getStatusP() {
return statusP;
}

public void setStatusP(OrderStatus statusP) {
this.statusP = statusP;
}

public LocalDateTime getCreateAtP() {
return createAtP;
}

public void setCreateAtP(LocalDateTime createAtP) {
this.createAtP = createAtP;
}

@Override
public String toString() {
return "HistoryBuy{" + "userID=" + userID + ", bannersP=" + bannersP + ", nameP=" + nameP + ", amountP=" + amountP + ", totalPriceP=" + totalPriceP + ", paymentP=" + paymentP + ", statusP=" + statusP + ", createAtP=" + createAtP + '}';
}


}
Binary file added src/main/webapp/img/product_img/bo-hong-tuoi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/main/webapp/js/profile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function activateTab(tab){
$('.nav-tabs a[href="#' + tab + '"]').tab('show');
};
4 changes: 2 additions & 2 deletions src/main/webapp/style/home.css
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ a.buy {
position: absolute;
height: 40px;
width: 100%;
bottom: -36px;
bottom: -40px;
transition: 0.25s ease-in-out;
opacity: 0.9;
opacity: 0.8;
}

.fa-solid {
Expand Down
58 changes: 35 additions & 23 deletions src/main/webapp/style/profile.css
Original file line number Diff line number Diff line change
@@ -1,56 +1,64 @@
.snippet{
background-color: antiquewhite!important;
}

.shop-name:hover {
background-color: antiquewhite;
color: orange;
background-color: antiquewhite;
color: orange;
}

.shop-name > a {
color: orange;
font-weight: bold;
text-decoration: none;
color: orange;
font-weight: bold;
text-decoration: none;
}

.shop-name > a:hover {
color: orange;
text-decoration: none;
color: orange;
text-decoration: none;
}

.col-xs-12 {
margin-top: 20px;
margin-top: 20px;
}

.col-xs-6 {
margin-top: 20px;
margin-top: 20px;
}

.col-xs-4 {
margin-top: 20px;
}

.return {
margin-top: 20px;
width: 180px;
border-radius: 10px;
background-color: antiquewhite;
color: black;
font-size: 18px;
margin-top: 20px;
width: 180px;
border-radius: 10px;
background-color: orange;
color: black;
font-size: 18px;
}

.return:hover {
background-color: orange;
background-color: white;
}

.return > a {
color: black;
color: black;
}

.return > a:hover {
text-decoration: none;
text-decoration: none;
}

a.cart {
text-decoration: none;
color: black;
text-decoration: none;
color: black;
}

a.cart:hover {
text-decoration: none;
color: orange;
text-decoration: none;
color: orange;
}

.row {
Expand All @@ -64,4 +72,8 @@ a.cart:hover {

.tab-pane > input {
font-size: 20px;
}
}

.setup {
font-size: 18px!important;
}
Loading