This repository has been archived by the owner on May 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bf8785c
commit ec2aca0
Showing
10 changed files
with
435 additions
and
10 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
src/main/java/com/bakaqc/flower/controller/CheckoutController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license | ||
* Click nbfs://nbhost/SystemFileSystem/Templates/JSP_Servlet/Servlet.java to edit this template | ||
*/ | ||
package com.bakaqc.flower.controller; | ||
|
||
import com.bakaqc.flower.dao.CheckoutDAO; | ||
import com.bakaqc.flower.dao.ProductDAO; | ||
import com.bakaqc.flower.model.Product; | ||
import com.bakaqc.flower.model.User; | ||
import java.io.IOException; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import javax.servlet.http.HttpSession; | ||
|
||
/** | ||
* | ||
* @author Admin | ||
*/ | ||
public class CheckoutController extends HttpServlet { | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
request.setCharacterEncoding("UTF-8"); | ||
response.setContentType("text/html; charset=UTF-8"); | ||
CheckoutDAO d = new CheckoutDAO(); | ||
HttpSession session = request.getSession(); | ||
String pid = request.getParameter("pid"); | ||
Product p = ProductDAO.getInstance().getById(pid); | ||
User user = (User) session.getAttribute("user"); | ||
d.addOder(user, p); | ||
|
||
|
||
session.setAttribute("successMessage", "Bạn đã đặt hàng thành công. Cảm ơn và chúc một ngày tốt lành!"); | ||
|
||
response.sendRedirect("home"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/main/java/com/bakaqc/flower/controller/PaymentController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.bakaqc.flower.controller; | ||
|
||
import com.bakaqc.flower.dao.ProductDAO; | ||
import com.bakaqc.flower.model.Product; | ||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import javax.servlet.http.HttpSession; | ||
|
||
public class PaymentController extends HttpServlet { | ||
|
||
// protected void processRequest(HttpServletRequest request, HttpServletResponse response) | ||
// throws ServletException, IOException { | ||
// response.setContentType("text/html;charset=UTF-8"); | ||
// try (PrintWriter out = response.getWriter()) { | ||
// /* TODO output your page here. You may use following sample code. */ | ||
// out.println("<!DOCTYPE html>"); | ||
// out.println("<html>"); | ||
// out.println("<head>"); | ||
// out.println("<title>Servlet PaymentController</title>"); | ||
// out.println("</head>"); | ||
// out.println("<body>"); | ||
// out.println("<h1>Servlet PaymentController at " + request.getContextPath() + "</h1>"); | ||
// out.println("</body>"); | ||
// out.println("</html>"); | ||
// } | ||
// } | ||
@Override | ||
protected void doGet(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
request.setCharacterEncoding("UTF-8"); | ||
response.setContentType("text/html; charset=UTF-8"); | ||
|
||
|
||
String proId = request.getParameter("proId"); | ||
|
||
Product p = ProductDAO.getInstance().getById(proId); | ||
int total = p.getPrice(); | ||
request.setAttribute("total", total); | ||
request.setAttribute("pid", proId); | ||
|
||
request.getRequestDispatcher("/view/payment.jsp").forward(request, response); | ||
|
||
} | ||
|
||
// @Override | ||
// protected void doPost(HttpServletRequest request, HttpServletResponse response) | ||
// throws ServletException, IOException { | ||
// | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.bakaqc.flower.dao; | ||
|
||
import com.bakaqc.flower.model.Product; | ||
import com.bakaqc.flower.model.User; | ||
import com.bakaqc.flower.service.Convert; | ||
import com.bakaqc.flower.service.JDBC; | ||
import java.sql.*; | ||
import java.time.LocalDateTime; | ||
|
||
public class CheckoutDAO { | ||
|
||
public void addOder(User user, Product p) { | ||
|
||
try { | ||
Connection conn = JDBC.getConnection(); | ||
|
||
|
||
|
||
//add oder | ||
PreparedStatement smt1 = conn.prepareStatement("INSERT INTO `order` (`user_id`, `total_price`, `payment`, `status`, `create_at`) VALUES (?, ?, ?, ?, ?)"); | ||
smt1.setInt(1, user.getId()); | ||
smt1.setInt(2, p.getPrice()); | ||
smt1.setString(3, "COD"); | ||
smt1.setString(4, "processing"); | ||
smt1.setString(5, Convert.convert(LocalDateTime.now())); | ||
smt1.executeUpdate(); | ||
|
||
// take oder_id | ||
PreparedStatement smt4 = conn.prepareStatement("SELECT id FROM `order` ORDER BY id DESC LIMIT 1"); | ||
ResultSet rs = smt4.executeQuery(); | ||
rs.next(); | ||
int orderId = rs.getInt("id"); | ||
|
||
//add data_oder | ||
PreparedStatement smt3 = conn.prepareStatement("INSERT INTO `data_order` (`order_id`, `product_id`, `amount`) VALUES (?, ?, ?)"); | ||
|
||
smt3.setInt(1, orderId); | ||
smt3.setInt(2, p.getId()); | ||
smt3.setInt(3, 1); | ||
|
||
smt3.executeUpdate(); | ||
|
||
JDBC.closeConnection(conn); | ||
} catch (SQLException ex) { | ||
System.err.println(ex.getMessage()); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
body { | ||
background-image: white; | ||
} | ||
|
||
.component { | ||
position: relative; | ||
width: 30%; | ||
margin: 5rem auto; | ||
padding: 1rem; | ||
|
||
box-shadow: 2px 2px 10px #454545; | ||
background-color: antiquewhite; | ||
|
||
text-align: center; | ||
} | ||
|
||
.credit-card h1 { | ||
color: rgba(4,99,128,1); | ||
} | ||
|
||
.component .credit-card form { | ||
display:flex; | ||
flex-direction: column; | ||
} | ||
|
||
.component .credit-card .line { | ||
display: flex; | ||
} | ||
|
||
.component .credit-card .line input { | ||
width: 20%; /* on définit une taille plus petite qu'il le faut, le flex-grow fera le reste */ | ||
flex: 1; | ||
margin: 0.4rem 0.3rem; | ||
} | ||
|
||
input { | ||
border: none; | ||
border-bottom: 1px solid rgba(0,0,0,.12); | ||
margin: 1rem 0; | ||
padding: 4px; | ||
font-size: 1rem; | ||
outline: none; | ||
} | ||
|
||
input::-webkit-input-placeholder { | ||
color: #AAAAAA; | ||
} | ||
.checkout-buttons { | ||
display: flex; | ||
justify-content: space-between; /* Các nút sẽ được căn giữa */ | ||
} | ||
.valid-button { | ||
border: 0; | ||
padding: 1rem 2rem; | ||
background-color: rgba(4,99,128,0.9); | ||
color: #EFECCA; | ||
font-weight:bold; | ||
margin-top:2rem; | ||
box-shadow: 1px 1px 1px black; | ||
text-decoration: none; | ||
} | ||
|
||
.valid-button:hover { | ||
background-color: rgba(4,99,128,1); | ||
box-shadow: none; | ||
text-decoration: none; | ||
} | ||
|
||
.total { | ||
position: absolute; | ||
top: 3em; | ||
left: -8em; | ||
z-index: -1; | ||
background: #002F2F; | ||
color: #A7A37E; | ||
width: auto; /* Thay đổi từ 100px thành auto */ | ||
transform: rotate(-35deg); | ||
display: flex; | ||
flex-wrap: wrap; | ||
justify-content: center; | ||
align-items: center; | ||
padding-right: 2rem; | ||
box-shadow: 1px 1px 5px black; | ||
overflow: hidden; /* Giữ cho nội dung không tràn ra khỏi total */ | ||
} | ||
|
||
.total p { | ||
font-size: 1.5rem; | ||
margin: 0; /* Loại bỏ margin mặc định của các trình duyệt */ | ||
white-space: nowrap; /* Ngăn chữ xuống dòng */ | ||
} | ||
.valid-button no-underline { | ||
text-decoration: none; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.