diff --git a/init/full.sql b/init/full.sql
index 7786b4c7..ec020e99 100644
--- a/init/full.sql
+++ b/init/full.sql
@@ -22,7 +22,7 @@ create table Food (
food_status bit not null,
food_rate tinyint not null,
discount_percent tinyint not null,
- food_img_url varchar(255) null,
+ food_img_url varchar(255) not null,
food_type_id tinyint not null foreign key references FoodType(food_type_id)
);
@@ -52,7 +52,11 @@ go
create table Voucher (
voucher_id tinyint identity(1,1) not null primary key,
voucher_name nvarchar(200) not null,
- voucher_discount_percent tinyint not null
+ voucher_code char(16) not null,
+ voucher_discount_percent tinyint not null,
+ voucher_quantity tinyint not null,
+ voucher_status bit not null,
+ voucher_date datetime not null
);
go
@@ -378,12 +382,10 @@ insert into OrderStatus (order_status) values (N'Đã giao');
insert into OrderStatus (order_status) values (N'Đã hủy');
-- Voucher
-insert into Voucher (voucher_name , voucher_discount_percent) values ( N'Quốc tế phụ nữ', 30);
-insert into Voucher (voucher_name , voucher_discount_percent) values ( N'Khách hàng may mắn', 20);
-insert into Voucher (voucher_name , voucher_discount_percent) values (N'Quà tặng Noel', 40);
-insert into Voucher (voucher_name , voucher_discount_percent) values ( N'Người đặc biệt', 50);
-
-
+insert into Voucher (voucher_name, voucher_code, voucher_discount_percent, voucher_quantity, voucher_status, voucher_date) values ( N'Quốc tế phụ nữ', 'ADASD2FD23123DBE', 30, 100, 0,'20231019 00:00:01 AM' );
+insert into Voucher (voucher_name, voucher_code, voucher_discount_percent, voucher_quantity, voucher_status, voucher_date) values ( N'Khách hàng may mắn', 'ADEF38BDYOQM875V', 20, 10, 0,'20230808 00:00:01 AM');
+insert into Voucher (voucher_name, voucher_code, voucher_discount_percent, voucher_quantity, voucher_status, voucher_date) values (N'Quà tặng Noel', 'DUEMAHWOPUNH62GH', 40, 50, 1,'20231215 00:00:01 AM' );
+insert into Voucher (voucher_name, voucher_code, voucher_discount_percent, voucher_quantity, voucher_status, voucher_date) values ( N'Người đặc biệt', 'DJWOA975N4B92BH6', 50, 5, 1,'20231108 00:00:01 AM' );
-- Cart, CartItem, Order test data
insert into Cart (customer_id) values (1);
diff --git a/src/main/java/Controllers/AdminController.java b/src/main/java/Controllers/AdminController.java
index 772f82be..97f0048e 100644
--- a/src/main/java/Controllers/AdminController.java
+++ b/src/main/java/Controllers/AdminController.java
@@ -22,7 +22,10 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.time.LocalDateTime;
import java.util.ArrayList;
+import java.util.Date;
import java.util.List;
/**
@@ -196,6 +199,7 @@ private void doPostUpdateUser(HttpServletRequest request, HttpServletResponse re
int result = accountDAO.update(account);
+
if (result == 1) {
response.sendRedirect("/admin");
return;
@@ -209,10 +213,16 @@ private void doPostAddVoucher(HttpServletRequest request, HttpServletResponse re
throws ServletException, IOException {
String voucherName = (String) request.getParameter("txtvoucher_name");
- byte voucher_discount_percent = Byte.parseByte(request.getParameter("txtAddVoucher_discount_percent"));
-
+ String voucherCode = (String) request.getParameter("txtvoucher_code");
+ Byte voucher_discount_percent = Byte.parseByte(request.getParameter("txtvoucher_discount_percent"));
+ Byte voucher_quantity = Byte.parseByte(request.getParameter("txtvoucher_quantity"));
+ Byte voucher_status = Byte.parseByte(request.getParameter("txtvoucher_status"));
+ String datetimelocal = request.getParameter("txtvoucher_time");
+
+ Timestamp datetime = Timestamp.valueOf(datetimelocal.replace("T"," ")+":00");
+
VoucherDAO voucherDAO = new VoucherDAO();
- Voucher voucher = new Voucher(voucherName, voucher_discount_percent);
+ Voucher voucher = new Voucher(voucherName, voucherCode, voucher_discount_percent, voucher_quantity, voucher_status, datetime);
int result = voucherDAO.add(voucher);
@@ -227,12 +237,19 @@ private void doPostAddVoucher(HttpServletRequest request, HttpServletResponse re
private void doPostUpdateVoucher(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
- byte voucherID = Byte.parseByte(request.getParameter("txtvoucher_id"));
+ Byte voucherID = Byte.parseByte(request.getParameter("txtvoucher_id"));
String voucherName = (String) request.getParameter("txtvoucher_name");
- byte voucher_discount_percent = Byte.parseByte(request.getParameter("txtvoucher_discount_percent"));
-
+ String voucherCode = (String) request.getParameter("txtvoucher_code");
+ Byte voucher_discount_percent = Byte.parseByte(request.getParameter("txtvoucher_discount_percent"));
+ Byte voucher_quantity = Byte.parseByte(request.getParameter("txtvoucher_quantity"));
+ Byte voucher_status = Byte.parseByte(request.getParameter("txtvoucher_status"));
+
+ String datetimelocal = request.getParameter("txtvoucher_time");
+
+ Timestamp datetime = Timestamp.valueOf(datetimelocal.replace("T"," ")+":00");
+
VoucherDAO voucherDAO = new VoucherDAO();
- Voucher voucher = new Voucher(voucherName, voucher_discount_percent);
+ Voucher voucher = new Voucher(voucherName, voucherCode, voucher_discount_percent, voucher_quantity, voucher_status, datetime);
voucher.setVoucherID(voucherID);
int result = voucherDAO.update(voucher);
diff --git a/src/main/java/Controllers/PromotionManagerController.java b/src/main/java/Controllers/PromotionManagerController.java
index 18dd790c..e8d79b95 100644
--- a/src/main/java/Controllers/PromotionManagerController.java
+++ b/src/main/java/Controllers/PromotionManagerController.java
@@ -2,7 +2,6 @@
* 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 Controllers;
import DAOs.AccountDAO;
@@ -19,34 +18,38 @@
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
+import java.sql.Timestamp;
+import java.time.LocalDateTime;
import java.util.List;
public class PromotionManagerController extends HttpServlet {
-
- /**
- * Processes requests for both HTTP GET
and POST
methods.
+
+ /**
+ * Processes requests for both HTTP GET
and POST
+ * methods.
+ *
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
+ throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
- try (PrintWriter out = response.getWriter()) {
+ try ( PrintWriter out = response.getWriter()) {
/* TODO output your page here. You may use following sample code. */
out.println("");
out.println("");
out.println("
GET
method.
+ *
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
@@ -110,10 +130,10 @@ private void doPostUpdateVoucher(HttpServletRequest request, HttpServletResponse
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
+ throws ServletException, IOException {
String path = request.getRequestURI();
if (path.endsWith("/promotionManager")) {
-
+
VoucherDAO voucherDAO = new VoucherDAO();
ListPOST
method.
+ *
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
@@ -138,9 +159,9 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
+ throws ServletException, IOException {
if (request.getParameter("btnSubmit") != null) {
- switch (request.getParameter("btnSubmit")) {
+ switch (request.getParameter("btnSubmit")) {
case "SubmitAddVoucher":
doPostAddVoucher(request, response);
break;
@@ -153,8 +174,9 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
}
}
- /**
+ /**
* Returns a short description of the servlet.
+ *
* @return a String containing servlet description
*/
@Override
diff --git a/src/main/java/DAOs/VoucherDAO.java b/src/main/java/DAOs/VoucherDAO.java
index c589dd73..4816c799 100644
--- a/src/main/java/DAOs/VoucherDAO.java
+++ b/src/main/java/DAOs/VoucherDAO.java
@@ -43,7 +43,7 @@ public Voucher getVoucher(byte id) {
ps.setByte(1, id);
rs = ps.executeQuery();
if (rs.next()) {
- voucher = new Voucher(rs.getByte("voucher_id"), rs.getString("voucher_name"), rs.getByte("voucher_discount_percent"));
+ 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);
@@ -58,8 +58,13 @@ public List