Untitled
unknown
plain_text
2 years ago
6.0 kB
5
Indexable
<%@page import="java.util.List"%> <%@page import="Models.Product"%> <%@page import="Models.Order"%> <%@page import="DAOs.ProductDAO"%> <%@page import="DAOs.OrderDAO"%> <%@page import="java.text.SimpleDateFormat"%> <%@ page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Product List</title> <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet"> <link rel="stylesheet" href="https://cdn.datatables.net/1.13.4/css/jquery.dataTables.min.css"> <style> .add-button { position: absolute; top: 10px; right: 10px; } </style> </head> <body> <nav class="navbar navbar-expand-lg navbar-light bg-light"> <div class="container"> <a class="navbar-brand" href="#">Product List</a> <div class="collapse navbar-collapse" id="navbarNav"> <ul class="navbar-nav ml-auto"> <li class="nav-item"> <span class="nav-link">Hello <%= session.getAttribute("fullname")%></span> </li> <li class="nav-item"> <button id="btnSignOut" onclick="signOut()" class="btn btn-link">Sign Out</button> </li> </ul> </div> </div> </nav> <div class="container mt-4"> <%-- Kiểm tra cookie đã được xóa thành công hay chưa --%> <% if (request.getParameter("logout") != null) { %> <div class="alert alert-success" role="alert"> Logout successful! Cookie has been removed. </div> <% } %> <h1>Show Data</h1> <h2>Products</h2> <table id="productTable" class="table table-bordered"> <thead> <tr> <th>Product ID</th> <th>Product Name</th> <th>Product Quantity</th> <th>Product Price</th> <th>Product Picture</th> <th>Product Description</th> <th>Actions</th> </tr> </thead> <tbody> <% ProductDAO productDAO = new ProductDAO(); List<Product> products = productDAO.getAllProducts(); if (!products.isEmpty()) { for (Product product : products) { %> <tr> <td><%= product.getPro_id()%></td> <td><%= product.getPro_name()%></td> <td><%= product.getPro_quan()%></td> <td><%= product.getPro_price()%></td> <td><%= product.getPro_pic()%></td> <td><%= product.getPro_des()%></td> <td> <a href="updateP.jsp?productId=<%= product.getPro_id()%>" class="btn btn-primary btn-sm">Update</a> <button onclick="deleteProduct('<%= product.getPro_id()%>')" class="btn btn-danger btn-sm">Delete</button> </td> </tr> <% } } else { %> <tr> <td colspan="7">No products found.</td> </tr> <% } %> </tbody> </table> <h2>Orders</h2> <table id="orderTable" class="table table-bordered"> <thead> <tr> <th>Order ID</th> <th>Customer Name</th> <th>Order Date</th> <th>Order Total</th> <th>Order Description</th> <th>Actions</th> </tr> </thead> <tbody> <% OrderDAO orderDAO = new OrderDAO(); List<Order> orders = orderDAO.getAllOrders(); if (!orders.isEmpty()) { for (Order order : orders) { %> <tr> <td><%= order.getOrder_id()%></td> <td><%= order.getUsername()%></td> <td><%= order.getOrder_date()%></td> <td><%= order.getOrder_total()%></td> <td><%= order.getOrder_des()%></td> <td> <!-- Nút "Update" --> <a href="updateO.jsp?orderId=<%= order.getOrder_id()%>" class="btn btn-primary btn-sm">Update</a> <!-- Nút "Delete" --> <button onclick="deleteOrder('<%= order.getOrder_id()%>')" class="btn btn-danger btn-sm">Delete</button> </td> </tr> <% } } else { %> <tr> <td colspan="6">No orders found.</td> </tr> <% } %> </tbody> </table> <div class="text-right mb-3"> <a href="addP.jsp" class="btn btn-primary">Add Product</a> <a href="addO.jsp" class="btn btn-primary">Add Order</a> </div> </div> <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script> <script src="https://cdn.datatables.net/1.13.4/js/jquery.dataTables.min.js"></script> <script> $(document).ready(function () { $('#productTable').DataTable(); $('#orderTable').DataTable(); }); function deleteProduct(productId) { if (confirm("Are you sure you want to delete this product?")) { window.location.href = "deleteP.jsp?productId=" + productId; } } function deleteOrder(orderId) { if (confirm("Are you sure you want to delete this order?")) { window.location.href = "deleteO.jsp?orderId=" + orderId; } } function signOut() { document.cookie = "username=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; document.cookie = "password=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; window.location.href = "index.jsp?logout=true"; } </script> </body> </html>
Editor is loading...