POST
method.
- *
- * @param request servlet request
- * @param response servlet response
- * @throws ServletException if a servlet-specific error occurs
- * @throws IOException if an I/O error occurs
- *
- */
- @Override
- protected void doPost(HttpServletRequest request, HttpServletResponse response)
+ protected void doPostOrder(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
- if (request.getParameter("btnSubmit") != null
- && request.getParameter("btnSubmit").equals("SubmitOrder")) {
- int accountID = 0;
- if (request.getParameter("txtAccountID") != null
- && !request.getParameter("txtAccountID").isEmpty()) {
- accountID = Integer.parseInt(request.getParameter("txtAccountID"));
- }
-
- String lastname = request.getParameter("txtLastName");
- String firstname = request.getParameter("txtFirstName");
- String gender = request.getParameter("txtGender");
- String phone = request.getParameter("txtPhone");
- String address = request.getParameter("txtAddress");
- String note = request.getParameter("txtNote");
-
- // Trình tự đặt món: thêm Customer -> Cart -> tất cả Cartitem -> Order
- // Thêm Customer
- Customer customer = new Customer(firstname, lastname, gender, phone, address);
- CustomerDAO customerdao = new CustomerDAO();
- int customerID = 0;
-
- int result = 0;
- if (accountID != 0) {
- // Nếu có accountID -> đã login thành công
- AccountDAO accountDAO = new AccountDAO();
- Account account = accountDAO.getAccount(accountID);
- if (account.getCustomerID() != 0) {
- // Tài khoản này đã có thông tin KH
- customerID = account.getCustomerID();
- } else {
+ int accountID = 0;
+ if (request.getParameter("txtAccountID") != null
+ && !request.getParameter("txtAccountID").isEmpty()) {
+ accountID = Integer.parseInt(request.getParameter("txtAccountID"));
+ }
- result = customerdao.add(customer);
- if (result == 1) {
- Customer lastestCustomer = customerdao.getLatestCustomer();
- account.setCustomerID(lastestCustomer.getCustomerID());
- accountDAO.updateCustomerID(account);
- customerID = lastestCustomer.getCustomerID();
- } else {
- response.sendRedirect("/home#failure");
- return;
- }
-
- customer = customerdao.getLatestCustomer(); // customerId lay tu DB ra tang dan
- customerID = customer.getCustomerID();
- }
+ String lastname = request.getParameter("txtLastName");
+ String firstname = request.getParameter("txtFirstName");
+ String gender = request.getParameter("txtGender");
+ String phone = request.getParameter("txtPhone");
+ String address = request.getParameter("txtAddress");
+ String note = request.getParameter("txtNote");
+
+ // Trình tự đặt món: thêm Customer -> Cart -> tất cả Cartitem -> Order
+ // Thêm Customer
+ Customer customer = new Customer(firstname, lastname, gender, phone, address);
+ CustomerDAO customerdao = new CustomerDAO();
+ int customerID = 0;
+
+ int result = 0;
+ if (accountID != 0) {
+ // Nếu có accountID -> đã login thành công
+ AccountDAO accountDAO = new AccountDAO();
+ Account account = accountDAO.getAccount(accountID);
+ if (account.getCustomerID() != 0) {
+ // Tài khoản này đã có thông tin KH
+ customerID = account.getCustomerID();
} else {
- //POST
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ *
+ */
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ if (request.getParameter("btnSubmit") != null && request.getParameter("btnSubmit").equals("SubmitOrder")) {
+ doPostOrder(request, response);
+ } else if (request.getParameter("btnSubmit") != null && request.getParameter("btnSubmit").equals("Checkout")) {
+ doPostCheckout(request,response);
+ } else if (request.getParameter("btnSubmit") != null && request.getParameter("btnSubmit").equals("SubmitVoucher")) {
+ doPostVoucher(request,response);
}
}
diff --git a/src/main/java/DAOs/VoucherDAO.java b/src/main/java/DAOs/VoucherDAO.java
index df3361d0..cda62514 100644
--- a/src/main/java/DAOs/VoucherDAO.java
+++ b/src/main/java/DAOs/VoucherDAO.java
@@ -51,6 +51,21 @@ public Voucher getVoucher(byte id) {
return voucher;
}
+ public Voucher getVoucherByCode(String code) {
+ Voucher voucher = null;
+ try {
+ ps = conn.prepareStatement("select * from Voucher where voucher_code = ?");
+ ps.setString(1, code);
+ rs = ps.executeQuery();
+ if (rs.next()) {
+ voucher = new Voucher(rs.getByte("voucher_id"), rs.getString("voucher_name"), rs.getString("voucher_code"),rs.getByte("voucher_discount_percent"),rs.getByte("voucher_quantity"), rs.getByte("voucher_status"), rs.getTimestamp("voucher_date"));
+ }
+ } catch (SQLException ex) {
+ Logger.getLogger(VoucherDAO.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ return voucher;
+ }
+
public Voucher getVoucher(String voucher_name) {
Voucher voucher = null;
try {
@@ -169,5 +184,26 @@ public int update(Voucher voucher) {
return result;
}
-
+ public int updateQuantity(Voucher voucher) {
+ String sql = "update Voucher set voucher_quantity = ?, voucher_status = ? where voucher_id = ?";
+ int result = 0;
+ byte status = voucher.getVoucher_status();
+ byte quantity = voucher.getVoucher_quantity();
+ if (quantity == 1) {
+ status = 0;
+ quantity = 0;
+ } else {
+ quantity = (byte) (quantity - 1);
+ }
+ try {
+ PreparedStatement ps = conn.prepareStatement(sql);
+ ps.setByte(1, quantity);
+ ps.setByte(2, status);
+ ps.setByte(3, voucher.getVoucherID());
+ result = ps.executeUpdate();
+ } catch (SQLException ex) {
+ Logger.getLogger(VoucherDAO.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ return result;
+ }
}
diff --git a/src/main/java/Models/Voucher.java b/src/main/java/Models/Voucher.java
index 8382f1a7..745a637b 100644
--- a/src/main/java/Models/Voucher.java
+++ b/src/main/java/Models/Voucher.java
@@ -93,6 +93,13 @@ public void setVoucher_status(byte voucher_status) {
public byte getVoucher_discount_percent() {
return voucher_discount_percent;
}
+
+ public double getVoucherDiscount() {
+ int intValue = Byte.toUnsignedInt(voucher_discount_percent);
+ System.out.println("intValue " + intValue);
+ double percentage = (double) intValue / 100;
+ return percentage;
+ }
public void setVoucher_discount_percent(byte voucher_discount_percent) {
this.voucher_discount_percent = voucher_discount_percent;
diff --git a/src/main/webapp/WEB-INF/jspf/admin/roles.jspf b/src/main/webapp/WEB-INF/jspf/admin/roles.jspf
index d89c23fd..7b721511 100644
--- a/src/main/webapp/WEB-INF/jspf/admin/roles.jspf
+++ b/src/main/webapp/WEB-INF/jspf/admin/roles.jspf
@@ -44,7 +44,7 @@