IMG-LOGO
×

Tài Liệu Học

Khoá học lập trình Java Core nâng cao

Exception & Collection

[Video] Tìm hiểu exception + debug + package - lập trình Java Nâng Cao [Video] Tìm hiểu collections, Sets, Maps và Generic - lập trình java nâng cao [Video] Chương trình quản lý sinh viên bằng HashMap - Java Advanced

File

[Video] Hướng dẫn đọc ghi file FileInputStream, FileOutputStream, ObjectInputStream trong java - lập trình java nâng cao [Video] Bài tập quản lý sách & lưu thông tin trên Files [Video] File - Quản lý thông tin sinh viên [Video] Quản lý thông tin sinh & lưu object file - Java nâng cao [Video] Viết ứng dụng WinRar | WinZip | 7Zip bằng Java - Nén file Java & giải nén file Java - Khoá học Java [Video] Bài tập quản lý bán vé máy bay - java nâng cao

Thread

[Video] Phân tích quản lý ứng dụng trong HĐH (Window, Mac, Linux)-Phân tích Game đa luồng Java [Video] Tìm hiểu Thread - Đồng bộ Thread - lập trình java nâng cao - Bổ sung thêm lớp học mới. [Video] Giải thích synchronized + Lap trinh Java nang cao [Video] Thread thực hiện in ngẫu nhiên các số nguyên và ký tự - Phần 1 [Video] Thread thực hiện in ngẫu nhiên các số nguyên và ký tự & Đông bộ thread + wait notify + synchronized + Java nâng cao - Phần 2 [Video] Synchronized 2 Thread - Bài tập mảng tên + địa chỉ - Java nâng cao [Video] Bài tập ôn luyện tổng hợp File, OOP, Thread trong java [Video] Sử dụng MultiThreading sinh ký tự a-zA-Z trong java

CSDL

[Video] Kết nối MySQL trong java swing JDBC trong java - lập trình java nâng cao [Video] Kết nối CSDL bằng java swing phần 1 - lập trình java nâng cao [Video] Kết nối CSDL bằng java swing phần 2 - lập trình java nâng cao [Video] Chương trình quản lý thư viện Java + XML Java + CSDL Java- SQL Java [Video] Phần mềm quản lý sinh viên MySQL + Java - Chương trình quản lý sinh viên MySQL + Java - Lập Trình Java [Video] Bài Tập Quản Lý Sinh Viên - CSDL - Java Swing [Video] Chương trình quản lý sản phẩm - quản lý tin tức - quản lý bán hàng - Lập trình Java [Video] Chức năng register & login + CSDL - Lập trình Java nâng cao - Phần 1 [Video] Hướng dẫn sử dụng Persistence Java - Kết nối database Java - MySQL Java nâng cao

Design Pattern & Đa Ngôn Ngữ

[Video] Design Pattern lập trình java nâng cao - lập trình java nâng cao

XML & JSON & CSDL

[Video] C1 > Chương trình quản lý sinh viên Java + Import/Export JSON + File - Lập Trình Java [Video] C2 > Chương trình quản lý sinh viên Java + Import/Export JSON + File - Lập Trình Java

Ôn Tập Tổng Quát & Exmination

[Video] Bài tập - Chường trình quản lý sở thú - Lập trình Java - Lập trình Java nâng cao - Phần 1 [Video] Bài tập - Chường trình quản lý sở thú - Lập trình Java - Lập trình Java nâng cao - Phần 2




Trang Chủ Java Advanced [Assignment] >> Quản lý bán hàng + java swing

[Assignment] >> Quản lý bán hàng + java swing

by GokiSoft.com - 17:23 29/10/2021 20,889 Lượt Xem

Viết chương trình sau :

- Triển khai lớp đối tường sau

1. Danh mục sản phầm -> gồm các thuộc tính sau : mã danh mục, tên danh mục

- tạo hàm tạo và các bộ getter/setter cho chương trình

- Viết hàm nhập dữ liệu và hiển thị dữ liệu cho danh mục

2. Sản phẩm -> gồm các thuộc tính : mã sản phẩm, mã danh mục, tên sp, giá, ngày nhập, ngày bán, hạn sử dụng, mô tả sản phẩm.

- tạo hàm tạo và các bộ getter/setter cho chương trình

- Viết hàm nhập dữ liệu và hiển thị dữ liệu cho danh mục

Sử dụng swing thiết kế chương trình sau, hoặc java FX & Cơ sở dữ liệu

1. Form => Thêm, sửa, xoá danh mục sản phẩm và hiển thị danh mục sản phẩm

2. Form => Thêm, sửa, xoá sản phẩm và hiển thị danh mục sản phẩm, tạo các bộ lọc filter để lọc theo

2.1. Danh mục sản phẩm

2.2 Hạn sử dụng (còn hạn hay đã hết hạn) (lấy giờ hiện tại của hệ thống để kiểm tra với HSD của sản phẩm)

2.3 Báo các mặt hàng sắp hết hạn sử dụng  (lấy giờ hiện tại của hệ thống và kiểm tra vs HSD, nếu giờ hiện tại <= HSD và giờ hiện tại >= HSD - 7 ngày thì in  kết quả ra)

2.4 Thêm nhiều tính năng nữa cang tốt, tự mở rộng, ...

2.5 danh sách các sản phẩm đã bán

2.6 danh sách sản phầm còn tồn kho

2.7 Tìm kiểm sản phẩm

3. Thống kê

3.1. Báo cáo sản phẩm bán trong ngày

3.2 Bao cáo sản phẩm bán trong tuần

3.3 Báo cáo sản phẩm bán trong tháng

4. Viết đăng ký, đăng nhập tài khoản khi vào sử dụng hệ thống

Bình luận



Chia sẻ từ lớp học

Minh Nghia [T1907A]

Ngày viết: 14:26 09/04/2020



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package QuanLiBanHang.Console;

import java.util.Scanner;

/**
 *
 * @author Administrator
 */
public class Product {
    String maSP, maDM, tenSP;
    int id, price ;
    int ngayNhap, ngayBan ,hsd;
    String moTaSP;

    public Product() {
    }

    public Product(String maSP, String maDM, String tenSP, int id, int price, int ngayNhap, int ngayBan, int hsd, String moTaSP) {
        this.maSP = maSP;
        this.maDM = maDM;
        this.tenSP = tenSP;
        this.id = id;
        this.price = price;
        this.ngayNhap = ngayNhap;
        this.ngayBan = ngayBan;
        this.hsd = hsd;
        this.moTaSP = moTaSP;
    }

    public Product(String maSP, String maDM, String tenSP, int price, int ngayNhap, int ngayBan, int hsd, String moTaSP) {
        this.maSP = maSP;
        this.maDM = maDM;
        this.tenSP = tenSP;
        this.price = price;
        this.ngayNhap = ngayNhap;
        this.ngayBan = ngayBan;
        this.hsd = hsd;
        this.moTaSP = moTaSP;
    }
    
    public String getMaSP() {
        return maSP;
    }

    public void setMaSP(String maSP) {
        this.maSP = maSP;
    }

    public String getMaDM() {
        return maDM;
    }

    public void setMaDM(String maDM) {
        this.maDM = maDM;
    }

    public String getTenSP() {
        return tenSP;
    }

    public void setTenSP(String tenSP) {
        this.tenSP = tenSP;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public int getNgayNhap() {
        return ngayNhap;
    }

    public void setNgayNhap(int ngayNhap) {
        this.ngayNhap = ngayNhap;
    }

    public int getNgayBan() {
        return ngayBan;
    }

    public void setNgayBan(int ngayBan) {
        this.ngayBan = ngayBan;
    }

    public int getHsd() {
        return hsd;
    }

    public void setHsd(int hsd) {
        this.hsd = hsd;
    }

    public String getMoTaSP() {
        return moTaSP;
    }

    public void setMoTaSP(String moTaSP) {
        this.moTaSP = moTaSP;
    }

    
    
    public void input(){
        Scanner scan = new Scanner(System.in);
        System.out.println("Nhap id:");
        id = Integer.parseInt(scan.nextLine());
        System.out.println("Nhap ma san pham :");
        maSP = scan.nextLine();
        System.out.println("Nhap ma danh muc :");
        maDM = scan.nextLine();
        System.out.println("Nhap ten san pham :");
        tenSP = scan.nextLine();
        System.out.println("Nhap gia ban :");
        price = Integer.parseInt(scan.nextLine());
        System.out.println("Nhap ngay nhap :");
        ngayNhap = Integer.parseInt(scan.nextLine());
        System.out.println("Nhap ngay ban :");
        ngayBan = Integer.parseInt(scan.nextLine());
        System.out.println("Nhap han su dung :");
        hsd = Integer.parseInt(scan.nextLine());
        System.out.println("Mo ta san pham");
        moTaSP = scan.nextLine();
    }
    public void display(){
        System.out.println(toString());
    }

    @Override
    public String toString() {
        return "product{" + "maSP=" + maSP + ", maDM=" + maDM + ", tenSP=" + tenSP + ", price=" + price + ", ngayNhap=" + ngayNhap + ", ngayBan=" + ngayBan + ", hsd=" + hsd + ", moTaSP=" + moTaSP + '}';
    }
    
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package QuanLiBanHang.Console;

import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Administrator
 */
public class ProductFrame extends javax.swing.JFrame {

    List<Product> pList = new ArrayList<>();
    List<productPortfolio> ppList = new ArrayList<>();
    DefaultTableModel tableModel;
    ProductModify productModify;

    /**
     * Creates new form ProductFrame
     */
    public ProductFrame() {
        initComponents();
        tableModel = (DefaultTableModel) tblProduct.getModel();
        showAll();
    }

    private void showAll() {

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtMaDanhMuc = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtTenDanhMuc = new javax.swing.JTextField();
        btnUpdatePortfolio = new javax.swing.JButton();
        btnEditPortfolio = new javax.swing.JButton();
        btnDeletePortfolio = new javax.swing.JButton();
        btnSearchPortfolio = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblPortfolio = new javax.swing.JTable();
        jLabel8 = new javax.swing.JLabel();
        txtRollno = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        txtMaSp = new javax.swing.JTextField();
        txtMaDm = new javax.swing.JTextField();
        txtTenSp = new javax.swing.JTextField();
        txtGia = new javax.swing.JTextField();
        txtNgayNhap = new javax.swing.JTextField();
        txtNgayBan = new javax.swing.JTextField();
        txtHanSd = new javax.swing.JTextField();
        txtMoTaSp = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        NgayBan = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblProduct = new javax.swing.JTable();
        btnUpdate = new javax.swing.JButton();
        btnEdit = new javax.swing.JButton();
        btnDelete = new javax.swing.JButton();
        btnTimSp = new javax.swing.JButton();
        btnTonkho = new javax.swing.JButton();
        btnDaban = new javax.swing.JButton();
        btnTrongngay = new javax.swing.JButton();
        btnTrongtuan = new javax.swing.JButton();
        btnTrongthang = new javax.swing.JButton();
        btnConhan = new javax.swing.JButton();
        btnHethan = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Product-Frame");

        jLabel1.setText("MaDanhMuc");

        jLabel2.setText("TenDanhMuc");

        btnUpdatePortfolio.setText("Update");
        btnUpdatePortfolio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUpdatePortfolioActionPerformed(evt);
            }
        });

        btnEditPortfolio.setText("Edit");
        btnEditPortfolio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditPortfolioActionPerformed(evt);
            }
        });

        btnDeletePortfolio.setText("Delete");
        btnDeletePortfolio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeletePortfolioActionPerformed(evt);
            }
        });

        btnSearchPortfolio.setText("Search");
        btnSearchPortfolio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSearchPortfolioActionPerformed(evt);
            }
        });

        tblPortfolio.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "No", "MaDanhMuc", "TenDanhMuc"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, true, true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tblPortfolio);

        jLabel8.setText("RollNo :");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(37, 37, 37)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(75, 75, 75)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(btnUpdatePortfolio)
                        .addGap(57, 57, 57)
                        .addComponent(btnEditPortfolio, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(49, 49, 49)
                        .addComponent(btnDeletePortfolio)
                        .addGap(50, 50, 50)
                        .addComponent(btnSearchPortfolio))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtTenDanhMuc, javax.swing.GroupLayout.PREFERRED_SIZE, 427, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(txtRollno, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(txtMaDanhMuc, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 427, Short.MAX_VALUE)))
                .addContainerGap(232, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(79, 79, 79)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel8)
                    .addComponent(txtRollno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(46, 46, 46)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtMaDanhMuc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(52, 52, 52)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtTenDanhMuc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(43, 43, 43)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnUpdatePortfolio)
                    .addComponent(btnEditPortfolio)
                    .addComponent(btnDeletePortfolio)
                    .addComponent(btnSearchPortfolio))
                .addGap(66, 66, 66)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 238, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(432, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("ProductPortfolio", jPanel2);

        jLabel3.setText("MaSanPham");

        jLabel4.setText("MaDanhMuc");

        jLabel5.setText("TenSanPham");

        jLabel6.setText("NgayNhap");

        jLabel7.setText("Gia");

        NgayBan.setText("NgayBan");

        jLabel9.setText("HanSuDung");

        jLabel11.setText("MoTaSanPham");

        tblProduct.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "No", "MaSp", "MaDm", "TenSp", "Gia", "NgayNhap", "NgayBan", "HanSd", "MoTaSP"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, true, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane2.setViewportView(tblProduct);

        btnUpdate.setText("Update");
        btnUpdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUpdateActionPerformed(evt);
            }
        });

        btnEdit.setText("Edit");
        btnEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditActionPerformed(evt);
            }
        });

        btnDelete.setText("Delete");
        btnDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeleteActionPerformed(evt);
            }
        });

        btnTimSp.setText("Tim San Pham");
        btnTimSp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTimSpActionPerformed(evt);
            }
        });

        btnTonkho.setText("San Pham Ton Kho");
        btnTonkho.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTonkhoActionPerformed(evt);
            }
        });

        btnDaban.setText("San Pham Da Ban");
        btnDaban.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDabanActionPerformed(evt);
            }
        });

        btnTrongngay.setText("Thong ke sp ban trong ngay");
        btnTrongngay.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTrongngayActionPerformed(evt);
            }
        });

        btnTrongtuan.setText("Thong ke sp ban trong tuan");
        btnTrongtuan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTrongtuanActionPerformed(evt);
            }
        });

        btnTrongthang.setText("Thong ke sp ban trong thang");
        btnTrongthang.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTrongthangActionPerformed(evt);
            }
        });

        btnConhan.setText("San pham con han");
        btnConhan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnConhanActionPerformed(evt);
            }
        });

        btnHethan.setText("San pham het han");
        btnHethan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnHethanActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 813, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel9)
                            .addComponent(jLabel3)
                            .addComponent(NgayBan)
                            .addComponent(jLabel5)
                            .addComponent(jLabel7)
                            .addComponent(jLabel4)
                            .addComponent(jLabel6)
                            .addComponent(jLabel11))
                        .addGap(43, 43, 43)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(txtHanSd, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 338, Short.MAX_VALUE)
                            .addComponent(txtNgayBan, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtNgayNhap, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtGia, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtTenSp, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtMaDm, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtMaSp, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtMoTaSp)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel3Layout.createSequentialGroup()
                                .addComponent(btnUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(51, 51, 51)
                                .addComponent(btnEdit, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(btnDelete, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(120, 120, 120)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(btnConhan, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnTrongngay, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnTrongtuan, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnDaban, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnTonkho, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnTimSp, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnTrongthang, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnHethan, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap(27, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtMaSp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnTimSp))
                .addGap(43, 43, 43)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtMaDm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(btnTonkho))
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(37, 37, 37)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(txtTenSp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5)))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(47, 47, 47)
                        .addComponent(btnDaban)))
                .addGap(30, 30, 30)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtGia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(btnTrongngay))
                .addGap(34, 34, 34)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel6)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txtNgayNhap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(btnTrongtuan)))
                .addGap(34, 34, 34)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(NgayBan)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txtNgayBan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(btnTrongthang)))
                .addGap(26, 26, 26)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel9)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txtHanSd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(btnConhan)))
                .addGap(58, 58, 58)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtMoTaSp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnHethan)
                    .addComponent(jLabel11))
                .addGap(45, 45, 45)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnUpdate)
                    .addComponent(btnEdit)
                    .addComponent(btnDelete))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 134, Short.MAX_VALUE)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 244, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(108, 108, 108))
        );

        jTabbedPane1.addTab("Product", jPanel3);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.TRAILING)
        );

        pack();
    }// </editor-fold>                        

    private void btnUpdatePortfolioActionPerformed(java.awt.event.ActionEvent evt) {                                                   
        // TODO add your handling code here:
        int id = Integer.parseInt(txtRollno.getText());
        String maDM = txtMaDanhMuc.getText();
        String tenDM = txtTenDanhMuc.getText();
        productPortfolio pp = new productPortfolio(id, maDM, tenDM);
        pModify.update(pp);
        showAll();
    }                                                  

    private void btnEditPortfolioActionPerformed(java.awt.event.ActionEvent evt) {                                                 
        // TODO add your handling code here:
        int id = Integer.parseInt(txtRollno.getText());
        String maDM = txtMaDanhMuc.getText();
        String tenDM = txtTenDanhMuc.getText();
        productPortfolio pp = new productPortfolio(id, maDM, tenDM);
        int selectedIndex = tblPortfolio.getSelectedRow();
        if (selectedIndex >= 0) {
            productPortfolio pro = ppList.get(selectedIndex);
            pp.setId(pro.getId());
        }
        pModify.edit(pp);
        showAll();
    }                                                

    private void btnDeletePortfolioActionPerformed(java.awt.event.ActionEvent evt) {                                                   
        // TODO add your handling code here:
        int selectedIndex = tblPortfolio.getSelectedRow();
        if (selectedIndex >= 0) {
            productPortfolio pp = ppList.get(selectedIndex);
            int option = JOptionPane.showConfirmDialog(this, "Do you want to delete this item");
            System.out.println("option :" + option);

            if (option == 0) {
                pModify.delete(pp.getId());
                showAll();
            }
        }
    }                                                  
//--------------------------------------------------------------------------------


    private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
        String maSP = txtMaSp.getText();
        String maDM = txtMaDm.getText();
        String TenSP = txtTenSp.getText();
        int price = Integer.parseInt(txtGia.getText());
        int ngayNhap = Integer.parseInt(txtNgayNhap.getText());
        int ngayBan = Integer.parseInt(txtNgayBan.getText());
        int hanSd = Integer.parseInt(txtHanSd.getText());
        String moTaSP = txtMoTaSp.getText();

        Product p = new Product();
        p.setMaSP(maSP);
        p.setMaDM(maDM);
        p.setTenSP(TenSP);
        p.setPrice(price);
        p.setNgayNhap(ngayNhap);
        p.setNgayBan(ngayBan);
        p.setHsd(hanSd);
        p.setMoTaSP(moTaSP);
        ProductModify.update(p);
        p.display();
        showAll();
    }                                         

    private void btnEditActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        String maSP = txtMaSp.getText();
        String maDM = txtMaDm.getText();
        String TenSP = txtTenSp.getText();
        int price = Integer.parseInt(txtGia.getText());
        int ngayNhap = Integer.parseInt(txtNgayNhap.getText());
        int ngayBan = Integer.parseInt(txtNgayBan.getText());
        int hanSd = Integer.parseInt(txtHanSd.getText());
        String moTaSP = txtMoTaSp.getText();

        Product p = new Product(maSP, maDM, TenSP, price, ngayNhap, ngayBan, hanSd, moTaSP);
        int selectedIndex = tblProduct.getSelectedRow();
        if (selectedIndex >= 0) {
            Product product = pList.get(selectedIndex);
            p.setId(p.getId());
        }
        ProductModify.edit(p);
        showAll();
    }                                       

    private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
        int selectIndex = tblProduct.getRowCount();
        if (selectIndex >= 0) {
            Product p = pList.get(selectIndex);

            int option = JOptionPane.showConfirmDialog(this, "Do you want to delete this item");
            System.out.println("option : " + option);

            if (option == 0) {
                productModify.delete(p.getId());

                showAll();
            }
        }
    }                                         

    private void btnTimSpActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        String input = JOptionPane.showInputDialog(this, "Enter full name to search");
        if (input != null && input.length() > 0) {
            pList = ProductModify.findByTenSp(input);
            tableModel.setRowCount(0);

            pList.forEach((product) -> {
                tableModel.addRow(new Object[]{tableModel.getRowCount() + 1,
                    product.getMaSP(), product.getMaDM(), product.getTenSP(),
                    product.getPrice(), product.getNgayNhap(), product.getNgayBan(),
                    product.getMoTaSP()});
            });
        } else {
            showAll();
        }
    }                                        

    private void btnTonkhoActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
        pList = ProductModify.tonkho();
        tableModel.setRowCount(0);

        pList.forEach((product) -> {
            tableModel.addRow(new Object[]{tableModel.getRowCount() + 1,
                product.getMaSP(), product.getMaDM(), product.getTenSP(),
                product.getPrice(), product.getNgayNhap(), product.getNgayBan(),
                product.getMoTaSP()});
        });
    }                                         

    private void btnDabanActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        pList = ProductModify.trongngay();
        tableModel.setRowCount(0);

        pList.forEach((product) -> {
            tableModel.addRow(new Object[]{tableModel.getRowCount() + 1,
                product.getMaSP(), product.getMaDM(), product.getTenSP(),
                product.getPrice(), product.getNgayNhap(), product.getNgayBan(),
                product.getMoTaSP()});
        });
    }                                        

    private void btnTrongngayActionPerformed(java.awt.event.ActionEvent evt) {                                             
        // TODO add your handling code here:
        pList = ProductModify.trongngay();
        tableModel.setRowCount(0);

        pList.forEach((product) -> {
            tableModel.addRow(new Object[]{tableModel.getRowCount() + 1,
                product.getMaSP(), product.getMaDM(), product.getTenSP(),
                product.getPrice(), product.getNgayNhap(), product.getNgayBan(),
                product.getMoTaSP()});
        });
    }                                            

    private void btnTrongtuanActionPerformed(java.awt.event.ActionEvent evt) {                                             
        // TODO add your handling code here:
        pList = ProductModify.trongtuan();
        tableModel.setRowCount(0);

        pList.forEach((product) -> {
            tableModel.addRow(new Object[]{tableModel.getRowCount() + 1,
                product.getMaSP(), product.getMaDM(), product.getTenSP(),
                product.getPrice(), product.getNgayNhap(), product.getNgayBan(),
                product.getMoTaSP()});
        });
    }                                            

    private void btnTrongthangActionPerformed(java.awt.event.ActionEvent evt) {                                              
        // TODO add your handling code here:
        pList = ProductModify.trongthang();
        tableModel.setRowCount(0);

        pList.forEach((product) -> {
            tableModel.addRow(new Object[]{tableModel.getRowCount() + 1,
                product.getMaSP(), product.getMaDM(), product.getTenSP(),
                product.getPrice(), product.getNgayNhap(), product.getNgayBan(),
                product.getMoTaSP()});
        });
    }                                             

    private void btnConhanActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
        pList = ProductModify.conhan();
        tableModel.setRowCount(0);

        pList.forEach((product) -> {
            tableModel.addRow(new Object[]{tableModel.getRowCount() + 1,
                product.getMaSP(), product.getMaDM(), product.getTenSP(),
                product.getPrice(), product.getNgayNhap(), product.getNgayBan(),
                product.getMoTaSP()});
        });
    }                                         

    private void btnHethanActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
        pList = ProductModify.hethan();
        tableModel.setRowCount(0);

        pList.forEach((product) -> {
            tableModel.addRow(new Object[]{tableModel.getRowCount() + 1,
                product.getMaSP(), product.getMaDM(), product.getTenSP(),
                product.getPrice(), product.getNgayNhap(), product.getNgayBan(),
                product.getMoTaSP()});
        });
    }                                         

    private void btnSearchPortfolioActionPerformed(java.awt.event.ActionEvent evt) {                                                   
        // TODO add your handling code here:
        String input = JOptionPane.showInputDialog(this, "Enter ten san pham to search");
        if (input != null && input.length() > 0) {
            ppList = pModify.search(input);
            tableModel.setRowCount(0);
            pList.forEach((product) -> {
                tableModel.addRow(new Object[]{tableModel.getRowCount() + 1, product.getId(),
                    product.getMaDM(), product.getMaSP()});
            });
        } else {
            showAll();
        }
    }                                                  

    /**
     * @param args the command line argumentss
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ProductFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ProductFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ProductFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ProductFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ProductFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JLabel NgayBan;
    private javax.swing.JButton btnConhan;
    private javax.swing.JButton btnDaban;
    private javax.swing.JButton btnDelete;
    private javax.swing.JButton btnDeletePortfolio;
    private javax.swing.JButton btnEdit;
    private javax.swing.JButton btnEditPortfolio;
    private javax.swing.JButton btnHethan;
    private javax.swing.JButton btnSearchPortfolio;
    private javax.swing.JButton btnTimSp;
    private javax.swing.JButton btnTonkho;
    private javax.swing.JButton btnTrongngay;
    private javax.swing.JButton btnTrongthang;
    private javax.swing.JButton btnTrongtuan;
    private javax.swing.JButton btnUpdate;
    private javax.swing.JButton btnUpdatePortfolio;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable tblPortfolio;
    private javax.swing.JTable tblProduct;
    private javax.swing.JTextField txtGia;
    private javax.swing.JTextField txtHanSd;
    private javax.swing.JTextField txtMaDanhMuc;
    private javax.swing.JTextField txtMaDm;
    private javax.swing.JTextField txtMaSp;
    private javax.swing.JTextField txtMoTaSp;
    private javax.swing.JTextField txtNgayBan;
    private javax.swing.JTextField txtNgayNhap;
    private javax.swing.JTextField txtRollno;
    private javax.swing.JTextField txtTenDanhMuc;
    private javax.swing.JTextField txtTenSp;
    // End of variables declaration                   

}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package QuanLiBanHang.Console;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Administrator
 */
public class ProductModify {

    public static List<Product> ShowAll() {
        List<Product> pList = new ArrayList<>();

        Connection connection = null;
        Statement statement = null;

        try {
            //lay tat ca danh sach sinh vien
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/T1907A?serverTimezone=UTC", "root", "");
            String sql = "select * from sanpham";
            statement = connection.createStatement();

            ResultSet resultSet = statement.executeQuery(sql);
            while (resultSet.next()) {
                Product product = new Product(resultSet.getString("maSp"),
                        resultSet.getString("maDm"),
                        resultSet.getString("tenSp"),
                        resultSet.getInt("price"),
                        resultSet.getInt("ngayNhap"),
                        resultSet.getInt("ngayBan"),
                        resultSet.getInt("hsd"),
                        resultSet.getString("moTaSP"));
                pList.add(product);
            }
        } catch (SQLException ex) {
            Logger.getLogger(ProductModify.class.getName()).log(Level.SEVERE, null, ex);
        } //query
        finally {
            if (statement != null) {

                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(ProductModify.class.getName()).log(Level.SEVERE, null, ex);
                }

                if (connection != null) {

                    try {
                        connection.close();
                    } catch (SQLException ex) {
                        Logger.getLogger(ProductModify.class.getName()).log(Level.SEVERE, null, ex);
                    }

                }
            }
            //ket thuc.

        }
        return pList;
    }

    public static void update(Product p) {
        Connection conn = null;
        PreparedStatement statement = null;
        try {
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/T1907A?serverTimezone=UTC", "root", "");

            String sql = "insert into sanpham(id,MaSp, MaDm,TenSp, Gia, NgayNhap, NgayBan, HanSd, MoTaSp ) value(?,?,?,?,?,?,?,?,)";
            statement = conn.prepareCall(sql);

            statement.setInt(1, p.getId());
            statement.setString(2, p.getMaSP());
            statement.setString(3, p.getMaDM());
            statement.setString(4, p.getTenSP());
            statement.setInt(5, p.getPrice());
            statement.setInt(6, p.getNgayBan());
            statement.setInt(7, p.getNgayNhap());
            statement.setInt(8, p.getHsd());
            statement.setString(9, p.getMoTaSP());

            statement.execute();
        } catch (SQLException ex) {
            Logger.getLogger(ProductModify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {

                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(ProductModify.class.getName()).log(Level.SEVERE, null, ex);
                }

                if (conn != null) {

                    try {
                        conn.close();
                    } catch (SQLException ex) {
                        Logger.getLogger(ProductModify.class.getName()).log(Level.SEVERE, null, ex);
                    }

                }
            }
            //ket thuc.

        }

    }

    public static void edit(Product p) {
        Connection conn = null;
        PreparedStatement statement = null;
        try {
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/T1907A?serverTimezone=UTC", "root", "");

            String sql = "update sanpham set MaSp=?,MaDm=?,TenSp=?,gia=?,NgayNhap=?, NgayBan= ?, HanSd=?, MoTaSp=? where = id=?";
            statement = conn.prepareCall(sql);

            statement.setInt(1, p.getId());
            statement.setString(2, p.getMaSP());
            statement.setString(3, p.getMaDM());
            statement.setString(4, p.getTenSP());
            statement.setInt(5, p.getPrice());
            statement.setInt(6, p.getNgayBan());
            statement.setInt(7, p.getNgayNhap());
            statement.setInt(8, p.getHsd());
            statement.setString(9, p.getMoTaSP());

            statement.execute();
        } catch (SQLException ex) {
            Logger.getLogger(ProductModify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {

                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(ProductModify.class.getName()).log(Level.SEVERE, null, ex);
                }

                if (conn != null) {

                    try {
                        conn.close();
                    } catch (SQLException ex) {
                        Logger.getLogger(ProductModify.class.getName()).log(Level.SEVERE, null, ex);
                    }

                }
            }
            //ket thuc.

        }

    }

    public static void delete(int id) {
        Connection conn = null;
        PreparedStatement statement = null;
        try {
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/T1907A?serverTimezone=UTC", "root", "");

            String sql = "delete from sanpham where id = ?";
            statement = conn.prepareCall(sql);

            statement.setInt(1, id);
            statement.execute();
        } catch (SQLException ex) {
            Logger.getLogger(ProductModify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {

                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(ProductModify.class.getName()).log(Level.SEVERE, null, ex);
                }

                if (conn != null) {

                    try {
                        conn.close();
                    } catch (SQLException ex) {
                        Logger.getLogger(ProductModify.class.getName()).log(Level.SEVERE, null, ex);
                    }

                }
            }
            //ket thuc.

        }

    }

    public static List<Product> findByTenSp(String tenSp) {
        List<Product> pList = new ArrayList<>();
        Connection conn = null;
        PreparedStatement statement = null;
        try {
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/T1907A?serverTimezone=UTC", "root", "");

            String sql = "select * from sanpham where TenSp like ?";
            statement = conn.prepareCall(sql);

            statement.setString(1, "%" + tenSp + "%");
            ResultSet resultSet = statement.executeQuery(sql);
            while (resultSet.next()) {
                Product product = new Product(
                        resultSet.getString("maSp"),
                        resultSet.getString("maDm"),
                        resultSet.getString("tenSp"),
                        resultSet.getInt("price"),
                        resultSet.getInt("ngayNhap"),
                        resultSet.getInt("ngayBan"),
                        resultSet.getInt("hsd"),
                        resultSet.getString("moTaSP"));
                pList.add(product);
            }

        } catch (SQLException ex) {
            Logger.getLogger(ProductModify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {

                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(ProductModify.class.getName()).log(Level.SEVERE, null, ex);
                }

                if (conn != null) {

                    try {
                        conn.close();
                    } catch (SQLException ex) {
                        Logger.getLogger(ProductModify.class.getName()).log(Level.SEVERE, null, ex);
                    }

                }
            }
            //ket thuc.

        }
        return pList;
    }

    public static List<Product> tonkho() {
        List<Product> pList = new ArrayList<>();
        Connection conn = null;
        PreparedStatement statement = null;
        try {
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/T1907A?serverTimezone=UTC", "root", "");

            String sql = "select * from sanpham where (NgayBan ='' or NgayBan = '' or NgayBan = null)";
            statement = conn.prepareCall(sql);

            ResultSet resultSet = statement.executeQuery(sql);
            while (resultSet.next()) {
                Product product = new Product(resultSet.getString("maSp"),
                        resultSet.getString("maDm"),
                        resultSet.getString("tenSp"),
                        resultSet.getInt("price"),
                        resultSet.getInt("ngayNhap"),
                        resultSet.getInt("ngayBan"),
                        resultSet.getInt("hsd"),
                        resultSet.getString("moTaSP"));
                pList.add(product);
            }

        } catch (SQLException ex) {
            Logger.getLogger(ProductModify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {

                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(ProductModify.class.getName()).log(Level.SEVERE, null, ex);
                }

                if (conn != null) {

                    try {
                        conn.close();
                    } catch (SQLException ex) {
                        Logger.getLogger(ProductModify.class.getName()).log(Level.SEVERE, null, ex);
                    }

                }
            }
            //ket thuc.

        }
        return pList;
    }

    public static List<Product> trongngay() {
        List<Product> pList = new ArrayList<>();
        Connection conn = null;
        PreparedStatement statement = null;
        try {
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/T1907A?serverTimezone=UTC", "root", "");

            String sql = "select * from sanpham where (CURDATE() = NgayBan)";
            statement = conn.prepareCall(sql);

            ResultSet resultSet = statement.executeQuery(sql);
            while (resultSet.next()) {
                Product product = new Product(resultSet.getString("maSp"),
                        resultSet.getString("maDm"),
                        resultSet.getString("tenSp"),
                        resultSet.getInt("price"),
                        resultSet.getInt("ngayNhap"),
                        resultSet.getInt("ngayBan"),
                        resultSet.getInt("hsd"),
                        resultSet.getString("moTaSP"));
                pList.add(product);
            }

        } catch (SQLException ex) {
            Logger.getLogger(ProductModify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {

                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(ProductModify.class.getName()).log(Level.SEVERE, null, ex);
                }

                if (conn != null) {

                    try {
                        conn.close();
                    } catch (SQLException ex) {
                        Logger.getLogger(ProductModify.class.getName()).log(Level.SEVERE, null, ex);
                    }

                }
            }
            //ket thuc.

        }
        return pList;
    }

    public static List<Product> trongtuan() {
        List<Product> pList = new ArrayList<>();
        Connection conn = null;
        PreparedStatement statement = null;
        try {
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/T1907A?serverTimezone=UTC", "root", "");

            String sql = "select * from sanpham where (YEARWEEK(NgayNhap) = YEARDATE(NgayBan))";
            statement = conn.prepareCall(sql);

            ResultSet resultSet = statement.executeQuery(sql);
            while (resultSet.next()) {
                Product product = new Product(resultSet.getString("maSp"),
                        resultSet.getString("maDm"),
                        resultSet.getString("tenSp"),
                        resultSet.getInt("price"),
                        resultSet.getInt("ngayNhap"),
                        resultSet.getInt("ngayBan"),
                        resultSet.getInt("hsd"),
                        resultSet.getString("moTaSP"));
                pList.add(product);
            }

        } catch (SQLException ex) {
            Logger.getLogger(ProductModify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {

                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(ProductModify.class.getName()).log(Level.SEVERE, null, ex);
                }

                if (conn != null) {

                    try {
                        conn.close();
                    } catch (SQLException ex) {
                        Logger.getLogger(ProductModify.class.getName()).log(Level.SEVERE, null, ex);
                    }

                }
            }
            //ket thuc.

        }
        return pList;
    }

    public static List<Product> trongthang() {
        List<Product> pList = new ArrayList<>();
        Connection conn = null;
        PreparedStatement statement = null;
        try {
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/T1907A?serverTimezone=UTC", "root", "");

            String sql = "select * from sanpham where (MONTH(NgayNhap) = MONTH(NgayBan))";
            statement = conn.prepareCall(sql);

            ResultSet resultSet = statement.executeQuery(sql);
            while (resultSet.next()) {
                Product product = new Product(resultSet.getString("maSp"),
                        resultSet.getString("maDm"),
                        resultSet.getString("tenSp"),
                        resultSet.getInt("price"),
                        resultSet.getInt("ngayNhap"),
                        resultSet.getInt("ngayBan"),
                        resultSet.getInt("hsd"),
                        resultSet.getString("moTaSP"));
                pList.add(product);
            }

        } catch (SQLException ex) {
            Logger.getLogger(ProductModify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {

                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(ProductModify.class.getName()).log(Level.SEVERE, null, ex);
                }

                if (conn != null) {

                    try {
                        conn.close();
                    } catch (SQLException ex) {
                        Logger.getLogger(ProductModify.class.getName()).log(Level.SEVERE, null, ex);
                    }

                }
            }
            //ket thuc.

        }
        return pList;
    }

    public static List<Product> conhan() {
        List<Product> pList = new ArrayList<>();
        Connection conn = null;
        PreparedStatement statement = null;
        try {
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/T1907A?serverTimezone=UTC", "root", "");

            String sql = "select * from sanpham where (CURDATE() < HanSd)";
            statement = conn.prepareCall(sql);

            ResultSet resultSet = statement.executeQuery(sql);
            while (resultSet.next()) {
                Product product = new Product(resultSet.getString("maSp"),
                        resultSet.getString("maDm"),
                        resultSet.getString("tenSp"),
                        resultSet.getInt("price"),
                        resultSet.getInt("ngayNhap"),
                        resultSet.getInt("ngayBan"),
                        resultSet.getInt("hsd"),
                        resultSet.getString("moTaSP"));
                pList.add(product);
            }

        } catch (SQLException ex) {
            Logger.getLogger(ProductModify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {

                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(ProductModify.class.getName()).log(Level.SEVERE, null, ex);
                }

                if (conn != null) {

                    try {
                        conn.close();
                    } catch (SQLException ex) {
                        Logger.getLogger(ProductModify.class.getName()).log(Level.SEVERE, null, ex);
                    }

                }
            }
            //ket thuc.

        }
        return pList;
    }

    public static List<Product> hethan() {
        List<Product> pList = new ArrayList<>();
        Connection conn = null;
        PreparedStatement statement = null;
        try {
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/T1907A?serverTimezone=UTC", "root", "");

            String sql = "select * from sanpham where (CURDATE() > HanSd)";
            statement = conn.prepareCall(sql);

            ResultSet resultSet = statement.executeQuery(sql);
            while (resultSet.next()) {
                Product product = new Product(resultSet.getString("maSp"),
                        resultSet.getString("maDm"),
                        resultSet.getString("tenSp"),
                        resultSet.getInt("price"),
                        resultSet.getInt("ngayNhap"),
                        resultSet.getInt("ngayBan"),
                        resultSet.getInt("hsd"),
                        resultSet.getString("moTaSP"));
                pList.add(product);
            }

        } catch (SQLException ex) {
            Logger.getLogger(ProductModify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {

                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(ProductModify.class.getName()).log(Level.SEVERE, null, ex);
                }

                if (conn != null) {

                    try {
                        conn.close();
                    } catch (SQLException ex) {
                        Logger.getLogger(ProductModify.class.getName()).log(Level.SEVERE, null, ex);
                    }

                }
            }
            //ket thuc.

        }
        return pList;
    }

    public static List<Product> daban() {
        List<Product> pList = new ArrayList<>();
        Connection conn = null;
        PreparedStatement statement = null;
        try {
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/T1907A?serverTimezone=UTC", "root", "");

            String sql = "select * from sanpham where (NgayBan > 0)";
            statement = conn.prepareCall(sql);

            ResultSet resultSet = statement.executeQuery(sql);
            while (resultSet.next()) {
                Product product = new Product(resultSet.getString("maSp"),
                        resultSet.getString("maDm"),
                        resultSet.getString("tenSp"),
                        resultSet.getInt("price"),
                        resultSet.getInt("ngayNhap"),
                        resultSet.getInt("ngayBan"),
                        resultSet.getInt("hsd"),
                        resultSet.getString("moTaSP"));
                pList.add(product);
            }

        } catch (SQLException ex) {
            Logger.getLogger(ProductModify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {

                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(ProductModify.class.getName()).log(Level.SEVERE, null, ex);
                }

                if (conn != null) {

                    try {
                        conn.close();
                    } catch (SQLException ex) {
                        Logger.getLogger(ProductModify.class.getName()).log(Level.SEVERE, null, ex);
                    }

                }
            }
            //ket thuc.

        }
        return pList;
    }
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package QuanLiBanHang.Console;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Administrator
 */
public class pModify {
    public static List<productPortfolio> showAll(){
        List<productPortfolio> pProList = new ArrayList<>();
        Connection conn = null;
        Statement statement = null;
        
        try {
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/T1907A?serverTimezone=UTC", "root", "");
            statement = conn.createStatement();
            String sql = "select * from danhmucsanpham";
            
            ResultSet resultSet = statement.executeQuery(sql);
            
            while(resultSet.next()){
                productPortfolio pp = new productPortfolio(resultSet.getInt("id"),
                resultSet.getString("maDM"), resultSet.getString("TenDM"));
                
                pProList.add(pp);
            }
        } catch (SQLException ex) {
            Logger.getLogger(pModify.class.getName()).log(Level.SEVERE, null, ex);
        }finally{
            if(conn != null){
                try {
                    conn.close();
                } catch (SQLException ex) {
                    Logger.getLogger(pModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if(statement != null){
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(pModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        return pProList;
    }
    public static void update(productPortfolio pp){
        Connection conn = null;
        PreparedStatement ps = null;
        
        try {
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/T1907A?serverTimezone=UTC", "root", "");
            String sql = "insert into danhmucsanpham(id,MaDanhMuc,TenDanhMuc)";
            ps = conn.prepareCall(sql);
            
            ps.setInt(1, pp.getId());
            ps.setString(2, pp.getMaDM());
            ps.setString(3, pp.getTenDM());
            
            ps.execute();
        } catch (SQLException ex) {
            Logger.getLogger(pModify.class.getName()).log(Level.SEVERE, null, ex);
        }finally{
            if(conn != null){
                try {
                    conn.close();
                } catch (SQLException ex) {
                    Logger.getLogger(pModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if(ps != null){
                try {
                    ps.close();
                } catch (SQLException ex) {
                    Logger.getLogger(pModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        
    }
    public static void edit(productPortfolio pp){
        Connection conn = null;
        PreparedStatement ps = null;
        
        try {
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/T1907A?serverTimezone=UTC", "root", "");
            String sql = "update danhmucsanpham set  MaDanhMuc=?,TenSanPham=? where id = ?";
            ps = conn.prepareCall(sql);
            
            ps.setInt(1, pp.getId());
            ps.setString(2, pp.getMaDM());
            ps.setString(3, pp.getTenDM());
            
            ps.execute();
        } catch (SQLException ex) {
            Logger.getLogger(pModify.class.getName()).log(Level.SEVERE, null, ex);
        }finally{
            if(conn != null){
                try {
                    conn.close();
                } catch (SQLException ex) {
                    Logger.getLogger(pModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if(ps != null){
                try {
                    ps.close();
                } catch (SQLException ex) {
                    Logger.getLogger(pModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
    public static void delete(int id){
        Connection conn = null;
        PreparedStatement ps = null;
        
        try {
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/T1907A?serverTimezone=UTC", "root", "");
            String sql = "delete from danhmucsanpham where id = ?";
            ps = conn.prepareCall(sql);
            
            ps.setInt(1, id);
            
            
            ps.execute();
        } catch (SQLException ex) {
            Logger.getLogger(pModify.class.getName()).log(Level.SEVERE, null, ex);
        }finally{
            if(conn != null){
                try {
                    conn.close();
                } catch (SQLException ex) {
                    Logger.getLogger(pModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if(ps != null){
                try {
                    ps.close();
                } catch (SQLException ex) {
                    Logger.getLogger(pModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
    public static List<productPortfolio> search(String tenDM){
        List<productPortfolio> pProList = new ArrayList<>();
        Connection conn = null;
        PreparedStatement ps = null;
        
        try {
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/T1907A?serverTimezone=UTC", "root", "");
            String sql = "select * from danhmucsanpham where TenDanhMuc like ?";
            
            ps = conn.prepareCall(sql);
            
            ResultSet resultSet = ps.executeQuery();
            while(resultSet.next()){
                productPortfolio pp = new productPortfolio(resultSet.getInt("id"),
                        resultSet.getString("maDM"), resultSet.getString("tenDM"));
                pProList.add(pp);
            }
           
        } catch (SQLException ex) {
            Logger.getLogger(pModify.class.getName()).log(Level.SEVERE, null, ex);
        }finally{
            if(conn != null){
                try {
                    conn.close();
                } catch (SQLException ex) {
                    Logger.getLogger(pModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if(ps != null){
                try {
                    ps.close();
                } catch (SQLException ex) {
                    Logger.getLogger(pModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        return pProList;
    }
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package QuanLiBanHang.Console;

import java.util.Scanner;

/**
 *
 * @author Administrator
 */
public class productPortfolio {
    int id;
    String maDM, tenDM;

    public productPortfolio() {
    }

    public productPortfolio(int id,String maDM, String tenDM) {
        this.id = id;
        this.maDM = maDM;
        this.tenDM = tenDM;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }
    
    
    public String getMaDM() {
        return maDM;
    }

    public void setMaDM(String maDM) {
        this.maDM = maDM;
    }

    public String getTenDM() {
        return tenDM;
    }

    public void setTenDM(String tenDM) {
        this.tenDM = tenDM;
    }
    public void input(){
        Scanner scan = new Scanner(System.in);
        System.out.println("Nhap ma id :");
        id = Integer.parseInt(scan.nextLine());
        System.out.println("Nhap ma danh muc :");
        maDM = scan.nextLine();
        System.out.println("Nhap ten danh muc :");
        tenDM = scan.nextLine();
        
    }
    public void display(){
        System.out.println(toString());
    }

    @Override
    public String toString() {
        return "productPortfolio{"+ "id" + id + "maDM=" + maDM + ", tenDM=" + tenDM + '}';
    }
    
}


Tài Liệu Tham Khảo

Đã sao chép!!!