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

Commit

Permalink
perfectdone
Browse files Browse the repository at this point in the history
  • Loading branch information
dwttlduong committed Dec 7, 2023
1 parent 2b95b71 commit 3816f59
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 96 deletions.
147 changes: 73 additions & 74 deletions flower_shop.sql

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)

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!");

request.getRequestDispatcher("home").forward(request, response);
response.sendRedirect("home");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
String pid = (String) request.getParameter("pid");//dương thêm
String quantity = request.getParameter("quantity");//dương thêm

response.sendRedirect(request.getContextPath() + "/payment?quantity=" + quantity + "&proId=" + pid);//dương thêm
response.sendRedirect(request.getContextPath() + "/pay?quantity=" + quantity + "&proId=" + pid);//dương thêm
} else {//dương thêm
response.sendRedirect("../profile");
}//dương thêm
Expand Down
28 changes: 10 additions & 18 deletions src/main/java/com/bakaqc/flower/dao/CheckoutDAO.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
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 cart
PreparedStatement smt = conn.prepareStatement("INSERT INTO `cart` (`user_id`, `product_id`, `amount`) VALUES (?, ?, ?)");
smt.setInt(1, user.getId());
smt.setInt(2, p.getPrice());
smt.setInt(3, 1);
smt.executeUpdate();


//add oder
PreparedStatement smt1 = conn.prepareStatement("INSERT INTO `order` (`user_id`, `total_price`, `payment`, `status`, `create_at`) VALUES (?, ?, ?, ?, ?)");
Expand All @@ -33,21 +26,20 @@ public void addOder(User user, Product p) {
smt1.executeUpdate();

// take oder_id
PreparedStatement smt4 = conn.prepareStatement("Select top 1 id from `oder` oder by id decs");
ResultSet rs=smt4.executeQuery();


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, rs.getInt("id"));

smt3.setInt(1, orderId);
smt3.setInt(2, p.getId());
smt3.setInt(3,1);
smt3.setInt(3, 1);

smt3.executeUpdate();

smt.executeUpdate();



JDBC.closeConnection(conn);
} catch (SQLException ex) {
System.err.println(ex.getMessage());
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
</servlet-mapping>
<servlet-mapping>
<servlet-name>PaymentController</servlet-name>
<url-pattern>/payment</url-pattern>
<url-pattern>/pay</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>CheckoutController</servlet-name>
Expand Down
1 change: 1 addition & 0 deletions src/main/webapp/view/payment.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
String date = curDate.toString();
%>
<input type="text" placeholder="DATE" value="<%=date%>" readonly />
<input type="text" value="Thanh toán khi nhận hàng" readonly />
<div>
<h2>Tổng tiền:
<script>
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/view/product_detail.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
</div>
code gốc </div>-->
<form action="payment" method="get"> <!-- duong them -->
<form action="pay" method="get"> <!-- duong them -->

<div class="col-lg-12 mt-3">
<div class="row">
Expand Down

0 comments on commit 3816f59

Please sign in to comment.