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,888 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

Đỗ Văn Huấn [T1907A]

Ngày viết: 12:51 08/04/2020



CREATE TABLE danhmuc(
    id_danhmuc int primary key auto_increment,
    tendanhmuc varchar(50)
)
create table sanpham (
	id_sanpham int primary key auto_increment,
	id_danhmuc int not null,
	tensanpham varchar(30),
	gia Float,
	ngaynhap date null,
	ngayban date null,
    hansudung date null,
    mota varchar(100) null,
    CONSTRAINT fk  FOREIGN KEY id_danhmuc REFERENCES danhmuc(id_danhmuc)
)



/*
 * 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 BaiTapNgay6_4_2020;

/**
 *
 * @author Admin
 */
public class DanhMuc {
    int id_danhmuc;
    String tenDanhMuc;

    public DanhMuc() {
    }

    public DanhMuc(int id_danhmuc, String tenDanhMuc) {
        this.id_danhmuc = id_danhmuc;
        this.tenDanhMuc = tenDanhMuc;
    }

    public int getId_danhmuc() {
        return id_danhmuc;
    }

    public void setId_danhmuc(int id_danhmuc) {
        this.id_danhmuc = id_danhmuc;
    }

    public String getTenDanhMuc() {
        return tenDanhMuc;
    }

    public void setTenDanhMuc(String tenDanhMuc) {
        this.tenDanhMuc = tenDanhMuc;
    }
    
}



/*
 * 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 BaiTapNgay6_4_2020;

/**
 *
 * @author Admin
 */
public class SanPham extends DanhMuc{
   int id_sanpham;
   float gia;
   String tenSanPhamString, ngayNhap,ngayban,ngayHetHan,moTa;

    public SanPham() {
    }

    public SanPham(int id_sanpham, float gia, String tenSanPhamString, String ngayNhap, String ngayban, String ngayHetHan, String moTa, int id_danhmuc, String tenDanhMuc) {
        super(id_danhmuc, tenDanhMuc);
        this.id_sanpham = id_sanpham;
        this.gia = gia;
        this.tenSanPhamString = tenSanPhamString;
        this.ngayNhap = ngayNhap;
        this.ngayban = ngayban;
        this.ngayHetHan = ngayHetHan;
        this.moTa = moTa;
    }

    public SanPham(int id_sanpham, float gia, String tenSanPhamString, String ngayNhap, String ngayban, String ngayHetHan, String moTa) {
        this.id_sanpham = id_sanpham;
        this.gia = gia;
        this.tenSanPhamString = tenSanPhamString;
        this.ngayNhap = ngayNhap;
        this.ngayban = ngayban;
        this.ngayHetHan = ngayHetHan;
        this.moTa = moTa;
    }
    

    public int getId_sanpham() {
        return id_sanpham;
    }

    public void setId_sanpham(int id_sanpham) {
        this.id_sanpham = id_sanpham;
    }

    public float getGia() {
        return gia;
    }

    public void setGia(float gia) {
        this.gia = gia;
    }

    public String getTenSanPhamString() {
        return tenSanPhamString;
    }

    public void setTenSanPhamString(String tenSanPhamString) {
        this.tenSanPhamString = tenSanPhamString;
    }

    public String getNgayNhap() {
        return ngayNhap;
    }

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

    public String getNgayban() {
        return ngayban;
    }

    public void setNgayban(String ngayban) {
        this.ngayban = ngayban;
    }

    public String getNgayHetHan() {
        return ngayHetHan;
    }

    public void setNgayHetHan(String ngayHetHan) {
        this.ngayHetHan = ngayHetHan;
    }

    public String getMoTa() {
        return moTa;
    }

    public void setMoTa(String moTa) {
        this.moTa = moTa;
    }
   
}



/*
 * 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 BaiTapNgay6_4_2020;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.JOptionPane;

/**
 *
 * @author Admin
 */
public class LogIn extends javax.swing.JFrame {

    /**
     * Creates new form LogIn
     */
    public LogIn() {
        initComponents();
    }

    public static ResultSet rs = null;
    public static PreparedStatement statement = null;

    /**
     * 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.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jButton2 = new javax.swing.JButton();
        jTabbedPane4 = new javax.swing.JTabbedPane();
        jTabbedPane5 = new javax.swing.JTabbedPane();
        jPanel4 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        txttaopass = new javax.swing.JPasswordField();
        txtnhaplaipass = new javax.swing.JPasswordField();
        txttaotaikhoan = new javax.swing.JTextField();
        txtemail = new javax.swing.JTextField();
        dangki = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txttaikhoan = new javax.swing.JTextField();
        dangnhap = new javax.swing.JButton();
        thoat = new javax.swing.JButton();
        txtpass = new javax.swing.JPasswordField();

        jButton2.setText("jButton2");

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("LOG IN / SiGN IN");

        jLabel5.setText("Nhap tai khoan");

        jLabel6.setText("Nhap mat khau");

        jLabel7.setText("Nhap lai mat khau");

        jLabel8.setText("Nhap email");

        dangki.setText("Dang ki");
        dangki.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dangkiActionPerformed(evt);
            }
        });

        jButton3.setText("Thoat");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(40, 40, 40)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel8)
                    .addComponent(jLabel7)
                    .addComponent(jLabel6)
                    .addComponent(jLabel5))
                .addGap(60, 60, 60)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(dangki)
                        .addGap(46, 46, 46)
                        .addComponent(jButton3))
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(txtnhaplaipass)
                        .addComponent(txttaopass)
                        .addComponent(txttaotaikhoan)
                        .addComponent(txtemail, javax.swing.GroupLayout.DEFAULT_SIZE, 229, Short.MAX_VALUE)))
                .addContainerGap(27, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txttaotaikhoan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(20, 20, 20)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(txttaopass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(24, 24, 24)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(txtnhaplaipass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(26, 26, 26)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(txtemail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(47, 47, 47)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(dangki)
                    .addComponent(jButton3))
                .addContainerGap(131, Short.MAX_VALUE))
        );

        jTabbedPane5.addTab("Nhap thong dang ki", jPanel4);

        jTabbedPane4.addTab("Dang ki", jTabbedPane5);

        jLabel2.setText("Tai khoan");

        jLabel3.setText("Mat khau");

        dangnhap.setText("Dang nhap");
        dangnhap.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dangnhapActionPerformed(evt);
            }
        });

        thoat.setText("thoat");
        thoat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                thoatActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(43, 43, 43)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(44, 44, 44)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(dangnhap)
                                .addGap(57, 57, 57)
                                .addComponent(thoat, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(txtpass, javax.swing.GroupLayout.PREFERRED_SIZE, 258, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(txttaikhoan, javax.swing.GroupLayout.PREFERRED_SIZE, 258, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(59, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txttaikhoan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(41, 41, 41)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtpass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(56, 56, 56)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(dangnhap)
                    .addComponent(thoat))
                .addContainerGap(222, Short.MAX_VALUE))
        );

        jTabbedPane4.addTab("Dang nhap", jPanel1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(57, 57, 57)
                .addComponent(jTabbedPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 461, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(67, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addComponent(jTabbedPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 458, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(137, Short.MAX_VALUE))
        );

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

    private void dangnhapActionPerformed(java.awt.event.ActionEvent evt) {                                         
        if (txtpass.getPassword().length > 0 && txttaikhoan.getText().length() > 0) {
            try {
                Form_SanPham fsp = new Form_SanPham();
                this.setVisible(false);
                fsp.setVisible(true);
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, e, "Thong bao", 1);
            }
        } else {
            JOptionPane.showMessageDialog(null, "Ban chua nhap thong tin tai khoan hoac mat khau", "Thong bao", 1);
        }

    }                                        

    private void thoatActionPerformed(java.awt.event.ActionEvent evt) {                                      
        if (JOptionPane.showConfirmDialog(rootPane, "Ban co muon thoat chuong trinh nay hay khong ?", "Thong bao", 2) == 0) {
            this.dispose();
        }

    }                                     

    private void dangkiActionPerformed(java.awt.event.ActionEvent evt) {                                       

        if (txttaopass.getPassword().length > 0 && txttaotaikhoan.getText().length() > 0
                && txtemail.getText().length() > 0 && txtnhaplaipass.getPassword().length > 0) {
            if ( txtnhaplaipass.getPassword() == txttaopass.getPassword()) {
                try {
                    Form_SanPham fsp = new Form_SanPham();
                    this.setVisible(false);
                    fsp.setVisible(true);
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(null, e, "Thong bao", 1);
                }
            }else{
                JOptionPane.showMessageDialog(null, "Ban nhap lai mat khau chua dung", "Thong bao", 1);
            }
        } else {
            JOptionPane.showMessageDialog(null, "Ban chua nhap day du thong tin vao form", "Thong bao", 1);
        }
    }                                      

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        if (JOptionPane.showConfirmDialog(rootPane, "Ban co muon thoat chuong trinh nay hay khong ?", "Thong bao", 2) == 0) {
            this.dispose();
        }
    }                                        

    /**
     * @param args the command line arguments
     */
    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(LogIn.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(LogIn.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(LogIn.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(LogIn.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 LogIn().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton dangki;
    private javax.swing.JButton dangnhap;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JTabbedPane jTabbedPane4;
    private javax.swing.JTabbedPane jTabbedPane5;
    private javax.swing.JButton thoat;
    private javax.swing.JTextField txtemail;
    private javax.swing.JPasswordField txtnhaplaipass;
    private javax.swing.JPasswordField txtpass;
    private javax.swing.JTextField txttaikhoan;
    private javax.swing.JPasswordField txttaopass;
    private javax.swing.JTextField txttaotaikhoan;
    // 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 BaiTapNgay6_4_2020;

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 Admin
 */
public class SanPhamtModify {
    
    

    public static List<SanPham> findAll() {
        List<SanPham> list = new ArrayList<>();
        Connection connection = null;
        Statement statement = null;
        try {
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/hanghoa?serverTimezone=UTC", "root", "");
            String sql = "SELECT sanpham.*, danhmuc.* FROM `sanpham` inner join danhmuc on sanpham.id_danhmuc = danhmuc.id_danhmuc";
            statement = connection.createStatement();
            ResultSet resultSet = statement.executeQuery(sql);

            while (resultSet.next()) {
                SanPham sanPham = new SanPham(
                        resultSet.getInt("id_sanpham"),
                        resultSet.getFloat("gia"),
                        resultSet.getString("tensanpham"),
                        resultSet.getString("ngaynhap"),
                        resultSet.getString("ngayban"),
                        resultSet.getString("hansudung"),
                        resultSet.getString("mota"),
                        resultSet.getInt("id_danhmuc"),
                        resultSet.getString("tendanhmuc")
                );
                list.add(sanPham);
            }

        } catch (SQLException ex) {
            Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        return list;
    }

   

    public static void insertdanhmuc(DanhMuc dm) {
        Connection connection = null;
        PreparedStatement statement = null;
        try {
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/hanghoa?serverTimezone=UTC", "root", "");
            String sql = "insert into danhmuc(id_danhmuc, tendanhmuc) values(?,?)";
            statement = connection.prepareCall(sql);
            statement.setInt(1, dm.getId_danhmuc());
            statement.setString(2, dm.getTenDanhMuc());
            statement.execute();
        } catch (SQLException ex) {
            Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

    }

    public static void insertsanpham(SanPham sp, DanhMuc dm) {
        Connection connection = null;
        PreparedStatement statement = null;
        try {
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/hanghoa?serverTimezone=UTC", "root", "");
            String sql = "insert into sanpham(id_sanpham,id_danhmuc, tensanpham,gia,ngaynhap,ngayban,hansudung,mota) values(?,?,?,?,?,?,?,?)";
            statement = connection.prepareCall(sql);
            statement.setInt(1, sp.getId_sanpham());
            statement.setInt(2, dm.getId_danhmuc());
            statement.setString(3, sp.getTenSanPhamString());
            statement.setFloat(4, sp.getGia());
            statement.setString(5, sp.getNgayNhap());
            statement.setString(6, sp.getNgayban());
            statement.setString(7, sp.getNgayHetHan());
            statement.setString(8, sp.getMoTa());
            statement.execute();
        } catch (SQLException ex) {
            Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

    }
    
     public static void deletesanpham(int id) {
        Connection connection = null;
        PreparedStatement statement = null;
        
        try {
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/hanghoa?serverTimezone=UTC", "root", "");
            String sql = "delete from sanpham where id_sanpham = ?";
            statement = connection.prepareCall(sql);
            statement.setInt(1, id);           
            statement.execute();
        } catch (SQLException ex) {
            Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if(statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
     
     public static void deletedanhmuc(int id) {
        Connection connection = null;
        PreparedStatement statement = null;
        
        try {
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/hanghoa?serverTimezone=UTC", "root", "");
            String sql = "delete from danhmuc where id_danhmuc = ?";
            statement = connection.prepareCall(sql);
            statement.setInt(1, id);           
            statement.execute();
        } catch (SQLException ex) {
            Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if(statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
     
     public static List<SanPham> timkiem(String tensanpham) {
        List<SanPham> list = new ArrayList<>();
        Connection connection = null;
        PreparedStatement statement = null;
        try {
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/hanghoa?serverTimezone=UTC", "root", "");
            String sql = "SELECT sanpham.*, danhmuc.* FROM `sanpham` inner "
                    + "join danhmuc on sanpham.id_danhmuc = danhmuc.id_danhmuc where sanpham.tensanpham like ?";
            statement = connection.prepareCall(sql);
            statement.setString(1,"%"+tensanpham+"%");
            ResultSet resultSet = statement.executeQuery();
            while (resultSet.next()) {
                SanPham sanPham = new SanPham(
                        resultSet.getInt("id_sanpham"),
                        resultSet.getFloat("gia"),
                        resultSet.getString("tensanpham"),
                        resultSet.getString("ngaynhap"),
                        resultSet.getString("ngayban"),
                        resultSet.getString("hansudung"),
                        resultSet.getString("mota"),
                        resultSet.getInt("id_danhmuc"),
                        resultSet.getString("tendanhmuc")
                );
                list.add(sanPham);
            }

        } catch (SQLException ex) {
            Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        return list;
    }

   
public static List<SanPham> tonkho() {
        List<SanPham> list = new ArrayList<>();
        Connection connection = null;
        Statement statement = null;
        try {
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/hanghoa?serverTimezone=UTC", "root", "");
            String sql = "SELECT sanpham.*, danhmuc.* FROM `sanpham` inner join danhmuc on sanpham.id_danhmuc = danhmuc.id_danhmuc WHERE sanpham.ngayban is null";
            statement = connection.createStatement();
            ResultSet resultSet = statement.executeQuery(sql);

            while (resultSet.next()) {
                SanPham sanPham = new SanPham(
                        resultSet.getInt("id_sanpham"),
                        resultSet.getFloat("gia"),
                        resultSet.getString("tensanpham"),
                        resultSet.getString("ngaynhap"),
                        resultSet.getString("ngayban"),
                        resultSet.getString("hansudung"),
                        resultSet.getString("mota"),
                        resultSet.getInt("id_danhmuc"),
                        resultSet.getString("tendanhmuc")
                );
                list.add(sanPham);
            }

        } catch (SQLException ex) {
            Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        return list;
    }
  
public static List<SanPham> daban() {
        List<SanPham> list = new ArrayList<>();
        Connection connection = null;
        Statement statement = null;
        try {
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/hanghoa?serverTimezone=UTC", "root", "");
            String sql = "SELECT sanpham.*, danhmuc.* FROM `sanpham` inner join danhmuc on sanpham.id_danhmuc = danhmuc.id_danhmuc WHERE sanpham.ngayban is not null";
            statement = connection.createStatement();
            ResultSet resultSet = statement.executeQuery(sql);

            while (resultSet.next()) {
                SanPham sanPham = new SanPham(
                        resultSet.getInt("id_sanpham"),
                        resultSet.getFloat("gia"),
                        resultSet.getString("tensanpham"),
                        resultSet.getString("ngaynhap"),
                        resultSet.getString("ngayban"),
                        resultSet.getString("hansudung"),
                        resultSet.getString("mota"),
                        resultSet.getInt("id_danhmuc"),
                        resultSet.getString("tendanhmuc")
                );
                list.add(sanPham);
            }

        } catch (SQLException ex) {
            Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        return list;
    }

public static List<SanPham> conhansudung() {
        List<SanPham> list = new ArrayList<>();
        Connection connection = null;
        Statement statement = null;
        try {
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/hanghoa?serverTimezone=UTC", "root", "");
            String sql = "SELECT sanpham.*, danhmuc.* FROM `sanpham` inner join danhmuc on sanpham.id_danhmuc = danhmuc.id_danhmuc WHERE (CURDATE() > sanpham.hansudung)";
            statement = connection.createStatement();
            ResultSet resultSet = statement.executeQuery(sql);

            while (resultSet.next()) {
                SanPham sanPham = new SanPham(
                        resultSet.getInt("id_sanpham"),
                        resultSet.getFloat("gia"),
                        resultSet.getString("tensanpham"),
                        resultSet.getString("ngaynhap"),
                        resultSet.getString("ngayban"),
                        resultSet.getString("hansudung"),
                        resultSet.getString("mota"),
                        resultSet.getInt("id_danhmuc"),
                        resultSet.getString("tendanhmuc")
                );
                list.add(sanPham);
            }

        } catch (SQLException ex) {
            Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        return list;
    }

public static List<SanPham> hethansudung() {
        List<SanPham> list = new ArrayList<>();
        Connection connection = null;
        Statement statement = null;
        try {
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/hanghoa?serverTimezone=UTC", "root", "");
            String sql = "SELECT sanpham.*, danhmuc.* FROM `sanpham` inner join danhmuc on sanpham.id_danhmuc = danhmuc.id_danhmuc WHERE (CURDATE() < sanpham.hansudung)";
            statement = connection.createStatement();
            ResultSet resultSet = statement.executeQuery(sql);

            while (resultSet.next()) {
                SanPham sanPham = new SanPham(
                        resultSet.getInt("id_sanpham"),
                        resultSet.getFloat("gia"),
                        resultSet.getString("tensanpham"),
                        resultSet.getString("ngaynhap"),
                        resultSet.getString("ngayban"),
                        resultSet.getString("hansudung"),
                        resultSet.getString("mota"),
                        resultSet.getInt("id_danhmuc"),
                        resultSet.getString("tendanhmuc")
                );
                list.add(sanPham);
            }

        } catch (SQLException ex) {
            Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        return list;
    }

public static List<SanPham> bantrongngay() {
        List<SanPham> list = new ArrayList<>();
        Connection connection = null;
        Statement statement = null;
        try {
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/hanghoa?serverTimezone=UTC", "root", "");
            String sql = "SELECT sanpham.*, danhmuc.* FROM `sanpham` inner join danhmuc on sanpham.id_danhmuc = danhmuc.id_danhmuc WHERE (CURDATE() = ngayban)";
            statement = connection.createStatement();
            ResultSet resultSet = statement.executeQuery(sql);

            while (resultSet.next()) {
                SanPham sanPham = new SanPham(
                        resultSet.getInt("id_sanpham"),
                        resultSet.getFloat("gia"),
                        resultSet.getString("tensanpham"),
                        resultSet.getString("ngaynhap"),
                        resultSet.getString("ngayban"),
                        resultSet.getString("hansudung"),
                        resultSet.getString("mota"),
                        resultSet.getInt("id_danhmuc"),
                        resultSet.getString("tendanhmuc")
                );
                list.add(sanPham);
            }

        } catch (SQLException ex) {
            Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        return list;
    }

public static List<SanPham> bantrongthang() {
        List<SanPham> list = new ArrayList<>();
        Connection connection = null;
        Statement statement = null;
        try {
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/hanghoa?serverTimezone=UTC", "root", "");
            String sql = "SELECT sanpham.*, danhmuc.* FROM `sanpham` inner join danhmuc on sanpham.id_danhmuc = danhmuc.id_danhmuc WHERE (MONTH(ngaythem) = MONTH(ngayban))";
            statement = connection.createStatement();
            ResultSet resultSet = statement.executeQuery(sql);

            while (resultSet.next()) {
                SanPham sanPham = new SanPham(
                        resultSet.getInt("id_sanpham"),
                        resultSet.getFloat("gia"),
                        resultSet.getString("tensanpham"),
                        resultSet.getString("ngaynhap"),
                        resultSet.getString("ngayban"),
                        resultSet.getString("hansudung"),
                        resultSet.getString("mota"),
                        resultSet.getInt("id_danhmuc"),
                        resultSet.getString("tendanhmuc")
                );
                list.add(sanPham);
            }

        } catch (SQLException ex) {
            Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        return list;
    }

public static List<SanPham> bantrongtuan() {
        List<SanPham> list = new ArrayList<>();
        Connection connection = null;
        Statement statement = null;
        try {
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/hanghoa?serverTimezone=UTC", "root", "");
            String sql = "SELECT sanpham.*, danhmuc.* FROM `sanpham` inner join danhmuc on sanpham.id_danhmuc = danhmuc.id_danhmuc WHERE (YEARWEEK(ngaynhap) = YEARWEEK(ngayban))";
            statement = connection.createStatement();
            ResultSet resultSet = statement.executeQuery(sql);

            while (resultSet.next()) {
                SanPham sanPham = new SanPham(
                        resultSet.getInt("id_sanpham"),
                        resultSet.getFloat("gia"),
                        resultSet.getString("tensanpham"),
                        resultSet.getString("ngaynhap"),
                        resultSet.getString("ngayban"),
                        resultSet.getString("hansudung"),
                        resultSet.getString("mota"),
                        resultSet.getInt("id_danhmuc"),
                        resultSet.getString("tendanhmuc")
                );
                list.add(sanPham);
            }

        } catch (SQLException ex) {
            Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        return list;
    }

public static List<DanhMuc> danhmuc() {
        List<DanhMuc> list12 = new ArrayList<>();
        Connection connection = null;
        Statement statement = null;
        try {
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/hanghoa?serverTimezone=UTC", "root", "");
            String sql = "SELECT * FROM danhmuc";
            statement = connection.createStatement();
            ResultSet resultSet = statement.executeQuery(sql);

            while (resultSet.next()) {
                DanhMuc dm = new DanhMuc(
                resultSet.getInt("id_danhmuc"),
                resultSet.getString("tendanhmuc")
                );
                list12.add(dm);
            }

        } catch (SQLException ex) {
            Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(SanPhamtModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        return list12;
    }
}



/*
 * 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 BaiTapNgay6_4_2020;


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

/**
 *
 * @author Admin
 */
public class Form_SanPham extends javax.swing.JFrame {

    List<SanPham> list = new ArrayList<>();
    List<DanhMuc>  list12 = new ArrayList<>();
    DefaultTableModel tableModel;

    /**
     * Creates new form Form_SanPham
     */
    public Form_SanPham() {
        initComponents();
        tableModel = (DefaultTableModel) jTable1.getModel();
        showhanghoa();
    }

    public void showhanghoa() {
        list = SanPhamtModify.findAll();
        list.stream().forEach((list1) -> {
            tableModel.addRow(new Object[]{
                list1.getId_danhmuc(),
                list1.getTenDanhMuc(),
                list1.getId_sanpham(),
                list1.getTenSanPhamString(),
                list1.getGia(),
                list1.getNgayNhap(),
                list1.getNgayban(),
                list1.getNgayHetHan(),
                list1.getMoTa()
            });
        });
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jMenuItem1 = new javax.swing.JMenuItem();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        txtIDdanhmuc = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        txtdanhmuc = new javax.swing.JTextField();
        txtTensanpham = new javax.swing.JTextField();
        txtIDsanpham = new javax.swing.JTextField();
        txtgiaban = new javax.swing.JTextField();
        txtmota = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        them = new javax.swing.JButton();
        xoa = new javax.swing.JButton();
        timkiem1 = new javax.swing.JButton();
        txtngayban = new javax.swing.JFormattedTextField();
        txtngayhethan = new javax.swing.JFormattedTextField();
        txtngaynhap = new javax.swing.JFormattedTextField();
        jMenuBar2 = new javax.swing.JMenuBar();
        jMenu11 = new javax.swing.JMenu();
        jMenu12 = new javax.swing.JMenu();
        jMenu13 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenuItem6 = new javax.swing.JMenuItem();
        jMenuItem7 = new javax.swing.JMenuItem();
        jMenuItem8 = new javax.swing.JMenuItem();
        jMenuItem9 = new javax.swing.JMenuItem();

        jMenuItem1.setText("jMenuItem1");

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Thong tin san pham");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Nhap thong tin cho san pham"));

        jLabel1.setText("ID danh muc");

        jLabel2.setText("Ten danh muc");

        jLabel3.setText("ID san pham");

        jLabel4.setText("Ten san pham");

        jLabel5.setText("Gia ban");

        jLabel6.setText("Mo ta");

        jLabel7.setText("Ngay ban");

        jLabel8.setText("Ngay nhap");

        jLabel9.setText("Ngay het han");

        txtIDdanhmuc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtIDdanhmucActionPerformed(evt);
            }
        });

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

            },
            new String [] {
                "ID danh muc", "Ten danh muc", "ID san pham", "Ten san pham", "Gia ban", "Ngay nhap", "Ngay ban", "Ngay het han", "mota"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        txtdanhmuc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtdanhmucActionPerformed(evt);
            }
        });

        txtTensanpham.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtTensanphamActionPerformed(evt);
            }
        });

        txtIDsanpham.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtIDsanphamActionPerformed(evt);
            }
        });

        txtgiaban.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtgiabanActionPerformed(evt);
            }
        });

        txtmota.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtmotaActionPerformed(evt);
            }
        });

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Chon chuc nang"));

        them.setText("Them san pham");
        them.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                themActionPerformed(evt);
            }
        });

        xoa.setText("Xoa san pham");
        xoa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                xoaActionPerformed(evt);
            }
        });

        timkiem1.setText("Tim kiem san pham");
        timkiem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                timkiem1ActionPerformed(evt);
            }
        });

        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(21, 21, 21)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(timkiem1, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(them, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(xoa, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(22, 22, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addComponent(them)
                .addGap(37, 37, 37)
                .addComponent(xoa)
                .addGap(37, 37, 37)
                .addComponent(timkiem1)
                .addContainerGap(45, Short.MAX_VALUE))
        );

        txtngayban.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("yyyy-mm-dd"))));
        txtngayban.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtngaybanActionPerformed(evt);
            }
        });

        txtngayhethan.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("yyyy-mm-dd"))));
        txtngayhethan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtngayhethanActionPerformed(evt);
            }
        });

        try {
            txtngaynhap.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        txtngaynhap.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtngaynhapActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(47, 47, 47)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(34, 34, 34)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtIDsanpham, javax.swing.GroupLayout.PREFERRED_SIZE, 334, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtIDdanhmuc, javax.swing.GroupLayout.PREFERRED_SIZE, 334, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(txtTensanpham, javax.swing.GroupLayout.DEFAULT_SIZE, 334, Short.MAX_VALUE)
                                    .addComponent(txtmota, javax.swing.GroupLayout.DEFAULT_SIZE, 334, Short.MAX_VALUE)
                                    .addComponent(txtgiaban, javax.swing.GroupLayout.DEFAULT_SIZE, 334, Short.MAX_VALUE)
                                    .addComponent(txtngayban)
                                    .addComponent(txtngayhethan)
                                    .addComponent(txtngaynhap, javax.swing.GroupLayout.Alignment.TRAILING))
                                .addGap(115, 115, 115)
                                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(txtdanhmuc, javax.swing.GroupLayout.PREFERRED_SIZE, 334, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addGap(14, 14, 14)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 936, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(45, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(9, 9, 9)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtIDdanhmuc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(39, 39, 39)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtdanhmuc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(39, 39, 39)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtIDsanpham, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addGap(39, 39, 39)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(txtTensanpham, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(39, 39, 39)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(txtgiaban, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(41, 41, 41)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(txtngaynhap, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 47, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtngayban, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7))
                        .addGap(44, 44, 44)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9)
                            .addComponent(txtngayhethan, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(36, 36, 36))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtmota, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addGap(43, 43, 43)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 245, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(28, 28, 28))
        );

        jMenu11.setText("File");
        jMenuBar2.add(jMenu11);

        jMenu12.setText("Edit");
        jMenuBar2.add(jMenu12);

        jMenu13.setText("Hien thi");

        jMenuItem2.setText("San pham con han su dung");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu13.add(jMenuItem2);

        jMenuItem3.setText("San pham het han su dung");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu13.add(jMenuItem3);

        jMenuItem4.setText("San pham da ban");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        jMenu13.add(jMenuItem4);

        jMenuItem5.setText("San pham ton kho");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        jMenu13.add(jMenuItem5);

        jMenuItem6.setText("San pham ban trong ngay");
        jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem6ActionPerformed(evt);
            }
        });
        jMenu13.add(jMenuItem6);

        jMenuItem7.setText("san pham ban trong tuan");
        jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem7ActionPerformed(evt);
            }
        });
        jMenu13.add(jMenuItem7);

        jMenuItem8.setText("San pham ban trong thang");
        jMenuItem8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem8ActionPerformed(evt);
            }
        });
        jMenu13.add(jMenuItem8);

        jMenuItem9.setText("Cac danh muc");
        jMenuItem9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem9ActionPerformed(evt);
            }
        });
        jMenu13.add(jMenuItem9);

        jMenuBar2.add(jMenu13);

        setJMenuBar(jMenuBar2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(36, 36, 36)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(17, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(25, 25, 25))
        );

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

    private void xoaActionPerformed(java.awt.event.ActionEvent evt) {                                    
        int selec = jTable1.getSelectedRow();
        if (selec >= 0) {
            SanPham sp = list.get(selec);
            DanhMuc dm = list.get(selec);
            int op = JOptionPane.showConfirmDialog(this, "ban co muon xoa san pham ???");
            if (op == 0) {
                SanPhamtModify.deletesanpham(sp.getId_sanpham());
                SanPhamtModify.deletedanhmuc(dm.getId_danhmuc());
                showhanghoa();
            }
        }

    }                                   

    private void txtmotaActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
    }                                       

    private void txtgiabanActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
    }                                         

    private void txtIDsanphamActionPerformed(java.awt.event.ActionEvent evt) {                                             
        // TODO add your handling code here:
    }                                            

    private void txtTensanphamActionPerformed(java.awt.event.ActionEvent evt) {                                              
        // TODO add your handling code here:
    }                                             

    private void txtdanhmucActionPerformed(java.awt.event.ActionEvent evt) {                                           
        // TODO add your handling code here:
    }                                          

    private void txtIDdanhmucActionPerformed(java.awt.event.ActionEvent evt) {                                             
        // TODO add your handling code here:
    }                                            

    private void themActionPerformed(java.awt.event.ActionEvent evt) {                                     
        int id_danhmuc = Integer.parseInt(txtIDdanhmuc.getText());
        String tendanhuc = txtdanhmuc.getText();
        int id_sanpham = Integer.parseInt(txtIDsanpham.getText());
        String tensanpham = txtTensanpham.getText();
        float gia = Float.parseFloat(txtgiaban.getText());
        String ngaynhap = txtngaynhap.getText();
        String ngayban = txtngayban.getText();
        String hansudung = txtngayhethan.getText();
        String mota = txtmota.getText();

        DanhMuc danhMuc = new DanhMuc(id_danhmuc, tendanhuc);
        SanPhamtModify.insertdanhmuc(danhMuc);

        SanPham sanPham = new SanPham(id_sanpham, gia, tensanpham, ngaynhap, ngayban, hansudung, mota);
        SanPhamtModify.insertsanpham(sanPham, danhMuc);

        showhanghoa();
    }                                    

    private void timkiem1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        String input = JOptionPane.showInputDialog(this, "Nhap ten cua san pham can tim: ");

        if ( input != null && input.length()>0) {
            list = SanPhamtModify.timkiem(input);
            list.stream().forEach((list1) -> {
                tableModel.addRow(new Object[]{
                    list1.getId_danhmuc(),
                    list1.getTenDanhMuc(),
                    list1.getId_sanpham(),
                    list1.getTenSanPhamString(),
                    list1.getGia(),
                    list1.getNgayNhap(),
                    list1.getNgayban(),
                    list1.getNgayHetHan(),
                    list1.getMoTa()
                });
            });
        }else{
            showhanghoa();
        }
    }                                        

    private void txtngaybanActionPerformed(java.awt.event.ActionEvent evt) {                                           
        // TODO add your handling code here:
    }                                          

    private void txtngayhethanActionPerformed(java.awt.event.ActionEvent evt) {                                              
        // TODO add your handling code here:
    }                                             

    private void txtngaynhapActionPerformed(java.awt.event.ActionEvent evt) {                                            
        // TODO add your handling code here:
    }                                           

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        
         list = SanPhamtModify.conhansudung();
        list.stream().forEach((list1) -> {
            tableModel.addRow(new Object[]{
                list1.getId_danhmuc(),
                list1.getTenDanhMuc(),
                list1.getId_sanpham(),
                list1.getTenSanPhamString(),
                list1.getGia(),
                list1.getNgayNhap(),
                list1.getNgayban(),
                list1.getNgayHetHan(),
                list1.getMoTa()
            });
        });
        
        
    }                                          

    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        list = SanPhamtModify.daban();
        list.stream().forEach((list1) -> {
            tableModel.addRow(new Object[]{
                list1.getId_danhmuc(),
                list1.getTenDanhMuc(),
                list1.getId_sanpham(),
                list1.getTenSanPhamString(),
                list1.getGia(),
                list1.getNgayNhap(),
                list1.getNgayban(),
                list1.getNgayHetHan(),
                list1.getMoTa()
            });
        });
        
    }                                          

    private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {                                           
       
        list = SanPhamtModify.tonkho();
        list.stream().forEach((list1) -> {
            tableModel.addRow(new Object[]{
                list1.getId_danhmuc(),
                list1.getTenDanhMuc(),
                list1.getId_sanpham(),
                list1.getTenSanPhamString(),
                list1.getGia(),
                list1.getNgayNhap(),
                list1.getNgayban(),
                list1.getNgayHetHan(),
                list1.getMoTa()
            });
        });
    }                                          

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {                                           
      list = SanPhamtModify.hethansudung();
        list.stream().forEach((list1) -> {
            tableModel.addRow(new Object[]{
                list1.getId_danhmuc(),
                list1.getTenDanhMuc(),
                list1.getId_sanpham(),
                list1.getTenSanPhamString(),
                list1.getGia(),
                list1.getNgayNhap(),
                list1.getNgayban(),
                list1.getNgayHetHan(),
                list1.getMoTa()
            });
        });       
    }                                          

    private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {                                           
       list = SanPhamtModify.bantrongtuan();
        list.stream().forEach((list1) -> {
            tableModel.addRow(new Object[]{
                list1.getId_danhmuc(),
                list1.getTenDanhMuc(),
                list1.getId_sanpham(),
                list1.getTenSanPhamString(),
                list1.getGia(),
                list1.getNgayNhap(),
                list1.getNgayban(),
                list1.getNgayHetHan(),
                list1.getMoTa()
            });
        });      
    }                                          

    private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {                                           
       list = SanPhamtModify.bantrongngay();
        list.stream().forEach((list1) -> {
            tableModel.addRow(new Object[]{
                list1.getId_danhmuc(),
                list1.getTenDanhMuc(),
                list1.getId_sanpham(),
                list1.getTenSanPhamString(),
                list1.getGia(),
                list1.getNgayNhap(),
                list1.getNgayban(),
                list1.getNgayHetHan(),
                list1.getMoTa()
            });
        });       
        
    }                                          

    private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {                                           
         list = SanPhamtModify.bantrongthang();
        list.stream().forEach((list1) -> {
            tableModel.addRow(new Object[]{
                list1.getId_danhmuc(),
                list1.getTenDanhMuc(),
                list1.getId_sanpham(),
                list1.getTenSanPhamString(),
                list1.getGia(),
                list1.getNgayNhap(),
                list1.getNgayban(),
                list1.getNgayHetHan(),
                list1.getMoTa()
            });
        });       
    }                                          

    private void jMenuItem9ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        list12 = SanPhamtModify.danhmuc();
        list12.stream().forEach((list1) -> {
            tableModel.addRow(new Object[]{
                list1.getId_danhmuc(),
                list1.getTenDanhMuc(),
            });
        });  
        
        
    }                                          

    /**
     * @param args the command line arguments
     */
    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 | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Form_SanPham.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(() -> {
            new Form_SanPham().setVisible(true);
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JLabel jLabel1;
    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.JMenu jMenu11;
    private javax.swing.JMenu jMenu12;
    private javax.swing.JMenu jMenu13;
    private javax.swing.JMenuBar jMenuBar2;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JMenuItem jMenuItem7;
    private javax.swing.JMenuItem jMenuItem8;
    private javax.swing.JMenuItem jMenuItem9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JButton them;
    private javax.swing.JButton timkiem1;
    private javax.swing.JTextField txtIDdanhmuc;
    private javax.swing.JTextField txtIDsanpham;
    private javax.swing.JTextField txtTensanpham;
    private javax.swing.JTextField txtdanhmuc;
    private javax.swing.JTextField txtgiaban;
    private javax.swing.JTextField txtmota;
    private javax.swing.JFormattedTextField txtngayban;
    private javax.swing.JFormattedTextField txtngayhethan;
    private javax.swing.JFormattedTextField txtngaynhap;
    private javax.swing.JButton xoa;
    // End of variables declaration                   
}


thienphu [T1907A]

Ngày viết: 12:41 08/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 QuanLiSanPham;

import java.util.Scanner;

/**
 *
 * @author Thien Phu
 */
public class DanhMucSanPham {

    int rollNo;
    String idDM;
    String nameDm;

    public DanhMucSanPham() {
    }

    public DanhMucSanPham(int rollNo, String idDM, String nameDm) {
        this.rollNo = rollNo;
        this.idDM = idDM;
        this.nameDm = nameDm;
    }

    public DanhMucSanPham(String idDM, String nameDm) {
        this.idDM = idDM;
        this.nameDm = nameDm;
    }
    
    public int getRollNo() {
        return rollNo;
    }

    public void setRollNo(int rollNo) {
        this.rollNo = rollNo;
    }

    public String getIdDM() {
        return idDM;
    }

    public void setIdDM(String idDM) {
        this.idDM = idDM;
    }

    public String getNameDm() {
        return nameDm;
    }

    public void setNameDm(String nameDm) {
        this.nameDm = nameDm;
    }

    @Override
    public String toString() {
        return "DanhMucSanPham{" + "rollNo=" + rollNo + ", idDM=" + idDM + ", nameDm=" + nameDm + '}';
    }

    void display() {
        System.out.println(toString());
    }

    void input() {
        Scanner sc = new Scanner(System.in);
        System.out.println("Nhap rollNo danh muc");
        rollNo = Integer.parseInt(sc.nextLine());
        System.out.println("Nhap id danh muc ");
        idDM = sc.nextLine();
        System.out.println("Nhap ten danh muc");
        nameDm = sc.nextLine();
    }
}



/*
 * 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 QuanLiSanPham;

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;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Thien Phu
 */
public class FormDanhMuc extends javax.swing.JFrame {

    /**
     * Creates new form FormDanhMuc
     */
    List<DanhMucSanPham> listdm;
    DefaultTableModel tableModel;
    int index = 0;

    public FormDanhMuc() {
        initComponents();
        listdm = new ArrayList<>();
        tableModel = (DefaultTableModel) jtableDanhMuc.getModel();
        readData();
    }

    /**
     * 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() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        tfIDDM = new javax.swing.JTextField();
        tfNameDm = new javax.swing.JTextField();
        btsave = new javax.swing.JButton();
        btdelete = new javax.swing.JButton();
        btupdate = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        jtableDanhMuc = new javax.swing.JTable();

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(jTable2);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Quản Lí Danh Mục", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14))); // NOI18N

        jLabel1.setText("ID Danh Muc");

        jLabel2.setText("Name Danh Muc");

        tfIDDM.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfIDDMActionPerformed(evt);
            }
        });

        btsave.setText("Save");
        btsave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btsaveActionPerformed(evt);
            }
        });

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

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

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

            },
            new String [] {
                "RollNo", "ID Danh Muc", "Name Danh Muc"
            }
        ));
        jtableDanhMuc.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jtableDanhMucMouseClicked(evt);
            }
        });
        jScrollPane3.setViewportView(jtableDanhMuc);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(58, 58, 58)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1)
                    .addComponent(btsave, javax.swing.GroupLayout.Alignment.TRAILING))
                .addGap(34, 34, 34)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(btdelete)
                        .addGap(18, 18, 18)
                        .addComponent(btupdate))
                    .addComponent(tfIDDM, javax.swing.GroupLayout.DEFAULT_SIZE, 163, Short.MAX_VALUE)
                    .addComponent(tfNameDm))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 376, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(tfIDDM, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(33, 33, 33)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(tfNameDm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(42, 42, 42)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btsave)
                    .addComponent(btdelete)
                    .addComponent(btupdate))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(31, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

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

    private void tfIDDMActionPerformed(java.awt.event.ActionEvent evt) {                                       
        // TODO add your handling code here:
    }                                      

    private void btsaveActionPerformed(java.awt.event.ActionEvent evt) {                                       
        // TODO add your handling code here:
        DanhMucSanPham dm = new DanhMucSanPham(tfIDDM.getText(), tfNameDm.getText());
        inserIntoMySql(dm);
        readData();
        reset();

    }                                      

    private void jtableDanhMucMouseClicked(java.awt.event.MouseEvent evt) {                                           
        // TODO add your handling code here:
        index = jtableDanhMuc.getSelectedRow();
        tfIDDM.setText(listdm.get(index).getIdDM());
        tfNameDm.setText(listdm.get(index).getNameDm());
    }                                          

    private void btdeleteActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        if (tfIDDM.getText().equals("")) {
            JOptionPane.showMessageDialog(rootPane, "Chọn danh muc sp cần xóa dưới bảng thông tin");
        } else {
            delete(tfIDDM.getText());
            JOptionPane.showMessageDialog(rootPane, "Xoa thanh cong id san pham : " + tfIDDM.getText());
            readData();
            reset();
        }
    }                                        
    private void reset(){
        tfIDDM.setText("");
        tfNameDm.setText("");
    }
    private void btupdateActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
//lay rollNo cua danh muc update
        int roll = listdm.get(index).getRollNo();
        System.out.println("Roll: "+roll);
        //update sql
        Connection conn = null;
        Statement statement = null;
        System.out.println(tfIDDM.getText()+"\t"+tfNameDm.getText());

        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/t1907a", "root", "");
            String sql = "UPDATE danhmuc SET idDanhMuc= '" + tfIDDM.getText() + "',nameDanhMuc= '" + tfNameDm.getText() + "' where rollNo = '"
                    + roll + "'";
            statement = conn.createStatement();
             statement.executeUpdate(sql);
        } catch (ClassNotFoundException | SQLException ex) {
            Logger.getLogger(FormDanhMuc.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException ex) {
                    Logger.getLogger(FormDanhMuc.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(FormDanhMuc.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        readData();
        reset();
    }                                        
    private void inserIntoMySql(DanhMucSanPham sp) {
        Connection conn = null;
        PreparedStatement preparedStatement = null;

        try {

            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/t1907a", "root", "");
            //query

            String sql = "insert into danhmuc(idDanhMuc,nameDanhMuc )values (?,?)";

            //  System.out.println("Chay qua day");
            preparedStatement = conn.prepareStatement(sql);

            preparedStatement.setString(1, sp.getIdDM());
            preparedStatement.setString(2, sp.getNameDm());

            preparedStatement.execute();

        } catch (SQLException ex) {
            Logger.getLogger(FormDanhMuc.class
                    .getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(FormDanhMuc.class
                    .getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (preparedStatement != null) {
                try {
                    preparedStatement.close();

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

                } catch (SQLException ex) {
                    Logger.getLogger(FormDanhMuc.class
                            .getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        // System.err.println("Chay qua day");
    }

    private void readData() {
        listdm.clear();
        Connection conn = null;
        Statement statement = null;

        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/t1907a", "root", "");
            String sql = "select * from danhmuc";

            statement = conn.createStatement();
            ResultSet resultSet = statement.executeQuery(sql);
            //doc du lieu từng hàng trong mysql
            while (resultSet.next()) {

                DanhMucSanPham sp = new DanhMucSanPham(Integer.parseInt(resultSet.getString("rollNo")), resultSet.getString("idDanhMuc"),
                        resultSet.getString("nameDanhMuc"));

                listdm.add(sp);

            }
        } catch (SQLException ex) {
            Logger.getLogger(QuanLiSp.class
                    .getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(QuanLiSp.class
                    .getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (conn != null) {
                try {
                    conn.close();

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

                } catch (SQLException ex) {
                    Logger.getLogger(QuanLiSp.class
                            .getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        display();
    }

    private void delete(String data) {
        Connection conn = null;
        Statement statement = null;

        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/t1907a", "root", "");

            String sql = "DELETE FROM danhmuc WHERE idDanhMuc =" + "'" + data + "'";

            statement = conn.createStatement();
            statement.executeUpdate(sql);
        } catch (ClassNotFoundException | SQLException ex) {
            Logger.getLogger(QuanLiSp.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException ex) {
                    Logger.getLogger(QuanLiSp.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(QuanLiSp.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }

    public void display() {
        tableModel.setRowCount(0);
        for (DanhMucSanPham listdm1 : listdm) {
            tableModel.addRow(new Object[]{tableModel.getRowCount() + 1, listdm1.getIdDM(), listdm1.getNameDm()});
        }
    }

    /**
     * @param args the command line arguments
     */
    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(FormDanhMuc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FormDanhMuc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FormDanhMuc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FormDanhMuc.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 FormDanhMuc().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton btdelete;
    private javax.swing.JButton btsave;
    private javax.swing.JButton btupdate;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable jTable2;
    private javax.swing.JTable jtableDanhMuc;
    private javax.swing.JTextField tfIDDM;
    private javax.swing.JTextField tfNameDm;
    // 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 QuanLiSanPham;

/**
 *
 * @author Thien Phu
 */
public class SanPham {

    String idSp, maDanhMuc;
    String nameSp, price;
    String inputdate, outputdate, hsd, mota;

    public SanPham() {
    }

    public SanPham(String idSp, String maDanhMuc, String nameSp, String price, String inputdate, String outputdate, String hsd, String mota) {
        this.idSp = idSp;
        this.maDanhMuc = maDanhMuc;
        this.nameSp = nameSp;
        this.price = price;
        this.inputdate = inputdate;
        this.outputdate = outputdate;
        this.hsd = hsd;
        this.mota = mota;
    }

    public String getIdSp() {
        return idSp;
    }

    public void setIdSp(String idSp) {
        this.idSp = idSp;
    }

    public String getMaDanhMuc() {
        return maDanhMuc;
    }

    public void setMaDanhMuc(String maDanhMuc) {
        this.maDanhMuc = maDanhMuc;
    }

    public String getNameSp() {
        return nameSp;
    }

    public void setNameSp(String nameSp) {
        this.nameSp = nameSp;
    }

    public String getPrice() {
        return price;
    }

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

    public String getInputdate() {
        return inputdate;
    }

    public void setInputdate(String inputdate) {
        this.inputdate = inputdate;
    }

    public String getOutputdate() {
        return outputdate;
    }

    public void setOutputdate(String outputdate) {
        this.outputdate = outputdate;
    }

    public String getHsd() {
        return hsd;
    }

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

    public String getMota() {
        return mota;
    }

    public void setMota(String mota) {
        this.mota = mota;
    }

    @Override
    public String toString() {
        return "SanPham{" + "idSp=" + idSp + ", maDanhMuc=" + maDanhMuc + ", nameSp=" + nameSp + ", price=" + price + ", inputdate=" + inputdate + ", outputdate=" + outputdate + ", hsd=" + hsd + ", mota=" + mota + '}';
    }

    void display() {
        System.out.println(toString());
    }
}



/*
 * 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 QuanLiSanPham;

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.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Thien Phu
 */
public class QuanLiSp extends javax.swing.JFrame {

    /**
     * Creates new form QuanLiSp
     */
    String getdata;
    List<SanPham> listSanPham;
    DefaultTableModel tableModel;
    List<SanPham> listSpSell;
    List<SanPham> listSpTonKho;
    List<SanPham> listSpHetHSd;
    List<SanPham> listSaphetHsd;//sp sap het han su dung

    public QuanLiSp() {
        initComponents();
        listSanPham = new ArrayList<>();
        tableModel = (DefaultTableModel) showthongtin.getModel();
        readData();
        listSpSell = new ArrayList<>();
        listSpTonKho = new ArrayList<>();
        listSpHetHSd = new ArrayList<>();
        listSaphetHsd = new ArrayList<>();
        setLocationRelativeTo(this);
        //tfIDSp.setEditable(false);
    }

    /**
     * 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() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        tfIDSp = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        tfIDDM = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        tfNameSp = new javax.swing.JTextField();
        tfPrice = new javax.swing.JTextField();
        tfinputDate = new javax.swing.JTextField();
        tfOutputDate = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        tfHSd = new javax.swing.JTextField();
        tfMota = new javax.swing.JTextField();
        btSave = new javax.swing.JButton();
        btDelete = new javax.swing.JButton();
        btUpdate = new javax.swing.JButton();
        btReset = new javax.swing.JButton();
        btTonkho = new javax.swing.JButton();
        btSaphetHSd = new javax.swing.JButton();
        btSpSell = new javax.swing.JButton();
        btFind = new javax.swing.JButton();
        btSanphamHetHsd = new javax.swing.JButton();
        btAllSanpham = new javax.swing.JButton();
        btdanhmuc = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        showthongtin = new javax.swing.JTable();

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Quan Li San Pham", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 18))); // NOI18N

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Nhap Thong Tin San Pham", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        jLabel1.setText("ID SP");
        jLabel1.setMaximumSize(new java.awt.Dimension(26, 20));
        jLabel1.setMinimumSize(new java.awt.Dimension(26, 20));
        jLabel1.setPreferredSize(new java.awt.Dimension(26, 20));

        jLabel2.setText("ID Danh Muc");
        jLabel2.setMaximumSize(new java.awt.Dimension(26, 20));
        jLabel2.setMinimumSize(new java.awt.Dimension(26, 20));
        jLabel2.setPreferredSize(new java.awt.Dimension(26, 20));

        jLabel3.setText("Name SP");
        jLabel3.setMaximumSize(new java.awt.Dimension(26, 20));
        jLabel3.setMinimumSize(new java.awt.Dimension(26, 20));
        jLabel3.setPreferredSize(new java.awt.Dimension(26, 20));

        jLabel4.setText("Price");
        jLabel4.setMaximumSize(new java.awt.Dimension(26, 20));
        jLabel4.setMinimumSize(new java.awt.Dimension(26, 20));
        jLabel4.setPreferredSize(new java.awt.Dimension(26, 20));

        jLabel5.setText("Input Date");
        jLabel5.setMaximumSize(new java.awt.Dimension(26, 20));
        jLabel5.setMinimumSize(new java.awt.Dimension(26, 20));
        jLabel5.setPreferredSize(new java.awt.Dimension(26, 20));

        jLabel6.setText("Output Date");
        jLabel6.setMaximumSize(new java.awt.Dimension(26, 20));
        jLabel6.setMinimumSize(new java.awt.Dimension(26, 20));
        jLabel6.setPreferredSize(new java.awt.Dimension(26, 20));

        jLabel7.setText("Expiry Date");
        jLabel7.setMaximumSize(new java.awt.Dimension(26, 20));
        jLabel7.setMinimumSize(new java.awt.Dimension(26, 20));
        jLabel7.setPreferredSize(new java.awt.Dimension(26, 20));

        jLabel8.setText("Describe");
        jLabel8.setMaximumSize(new java.awt.Dimension(26, 20));
        jLabel8.setMinimumSize(new java.awt.Dimension(26, 20));
        jLabel8.setPreferredSize(new java.awt.Dimension(26, 20));

        btSave.setText("Save");
        btSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSaveActionPerformed(evt);
            }
        });

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

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

        btReset.setText("Reset");
        btReset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btResetActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(77, 77, 77)
                        .addComponent(btSave, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(32, 32, 32)
                        .addComponent(btDelete)
                        .addGap(29, 29, 29)
                        .addComponent(btUpdate)
                        .addGap(18, 18, 18)
                        .addComponent(btReset, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(54, 54, 54)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(tfMota, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(tfHSd, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(tfOutputDate, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(tfinputDate, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(tfPrice, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(tfNameSp, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE)
                                .addComponent(tfIDDM, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(tfIDSp, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addGap(75, 75, 75))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(48, 48, 48)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tfIDSp, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfIDDM, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfNameSp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfinputDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfOutputDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfHSd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfMota, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(56, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btSave)
                    .addComponent(btDelete)
                    .addComponent(btUpdate)
                    .addComponent(btReset))
                .addContainerGap())
        );

        btTonkho.setText("Sản Phẩm Tồn Kho");
        btTonkho.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btTonkhoActionPerformed(evt);
            }
        });

        btSaphetHSd.setText("Sản Phẩm Sắp Hết HSD");
        btSaphetHSd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSaphetHSdActionPerformed(evt);
            }
        });

        btSpSell.setText("Sản Phẩm Đã bán");
        btSpSell.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSpSellActionPerformed(evt);
            }
        });

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

        btSanphamHetHsd.setText("Sản Phẩm Hết HSd");
        btSanphamHetHsd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSanphamHetHsdActionPerformed(evt);
            }
        });

        btAllSanpham.setText("Thống Kê Sản Phẩm");
        btAllSanpham.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAllSanphamActionPerformed(evt);
            }
        });

        btdanhmuc.setText("Quản Lí Danh Mục");
        btdanhmuc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btdanhmucActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(66, 66, 66)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(btSaphetHSd, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btSanphamHetHsd, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btTonkho, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btSpSell, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btFind, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btAllSanpham, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btdanhmuc, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 66, Short.MAX_VALUE)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(58, 58, 58))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(btFind, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btSpSell, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btTonkho, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(30, 30, 30)
                        .addComponent(btSanphamHetHsd, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(33, 33, 33)
                        .addComponent(btSaphetHSd, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(32, 32, 32)
                        .addComponent(btAllSanpham, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(26, 26, 26)
                        .addComponent(btdanhmuc, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

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

            },
            new String [] {
                "IDSP", "IDDM", "NameSP", "Price", "InputDate", "outputDate", "ExpỉyDate", "Describe"
            }
        ));
        showthongtin.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                showthongtinMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(showthongtin);

        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()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jScrollPane2)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(26, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 11, Short.MAX_VALUE))
        );

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

    private void btFindActionPerformed(java.awt.event.ActionEvent evt) {                                       
        String input = JOptionPane.showInputDialog(rootPane, "Nhập id sản phẩm cần tìm");
        List<SanPham> findSp = new ArrayList<>();
        boolean check = false;
        if (input != null && input.length() > 0) {
            for (SanPham sp : listSanPham) {
                if (sp.getIdSp().equalsIgnoreCase(input)) {
                    findSp.add(sp);
                    check = true;
                }
            }
            if (check) {
                tableModel.setRowCount(0);
                for (SanPham sp : findSp) {
                    tableModel.addRow(new Object[]{sp.getIdSp(),
                        sp.getMaDanhMuc(), sp.getNameSp(), sp.getPrice(), sp.getInputdate(), sp.getOutputdate(),
                        sp.getHsd(), sp.getMota()});
                }

            } else {
                JOptionPane.showMessageDialog(rootPane, input + " không tồn tại");
            }

        }
    }                                      

    private void btSaveActionPerformed(java.awt.event.ActionEvent evt) {                                       
        //save
        SanPham sp = new SanPham();
        sp.setIdSp(tfIDSp.getText());
        sp.setMaDanhMuc(tfIDDM.getText());
        sp.setNameSp(tfNameSp.getText());
        sp.setPrice(tfPrice.getText());
        sp.setInputdate(tfinputDate.getText());
        sp.setOutputdate(tfOutputDate.getText());
        sp.setHsd(tfHSd.getText());
        sp.setMota(tfMota.getText());
        inserIntoMySql(sp);
        //ghi xuong my sql
        readData();
    }                                      

    private void btSpSellActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        listSpSell.clear();
        for (SanPham sanpham1 : listSanPham) {
            if (!"".equals(sanpham1.getOutputdate())) {
                listSpSell.add(sanpham1);
            }
        }
        //System.out.println("San pham da ban");
        display(listSpSell);


    }                                        

    private void btTonkhoActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        //danh sach san pham ton kho
        listSpTonKho.clear();
        for (SanPham sanpham1 : listSanPham) {
            if ("".equals(sanpham1.getOutputdate())) {
                listSpTonKho.add(sanpham1);
            }
        }
        //System.out.println("San pham da ban");
        display(listSpTonKho);

    }                                        

    private void btSanphamHetHsdActionPerformed(java.awt.event.ActionEvent evt) {                                                
        // TODO add your handling code here:
        //danh sach sp het han su dung
        listSpHetHSd.clear();
        listSpTonKho.clear();
        for (SanPham sanpham1 : listSanPham) {
            if ("".equals(sanpham1.getOutputdate())) {
                listSpTonKho.add(sanpham1);
            }
        }
        for (int i = 0; i < listSpTonKho.size(); i++) {
            if (checkHsd(listSpTonKho.get(i).getHsd()) > 0) {
                listSpHetHSd.add(listSpTonKho.get(i));
            }
        }
        System.out.println("Danh sach san pham het hsd:\n");
        display(listSpHetHSd);
    }                                               

    private void btSaphetHSdActionPerformed(java.awt.event.ActionEvent evt) {                                            
        // TODO add your handling code here:
        //danh sach sp sap het han su dung
        listSaphetHsd.clear();
        listSpTonKho.clear();
        for (SanPham sanpham1 : listSanPham) {
            if ("".equals(sanpham1.getOutputdate())) {
                listSpTonKho.add(sanpham1);
            }
        }
        for (SanPham sp : listSpTonKho) {
            if ((checkHsd(sp.getHsd())) >= -7 && checkHsd(sp.getHsd()) < 0) {

                listSaphetHsd.add(sp);
            }
        }
        if (listSaphetHsd.isEmpty()) {
            JOptionPane.showMessageDialog(rootPane, "Không có sản phẩm nào sắp hết hạn ");

        } else {
            display(listSaphetHsd);
        }
        System.out.println("Danh sach sp sap het han su dung:\n");
        for (SanPham sp : listSaphetHsd) {
            sp.display();
        }
    }                                           

    private void btAllSanphamActionPerformed(java.awt.event.ActionEvent evt) {                                             
        readData();
    }                                            

    private void showthongtinMouseClicked(java.awt.event.MouseEvent evt) {                                          
        // TODO add your handling code here:
        int index = showthongtin.getSelectedRow();
        tfIDSp.setText(listSanPham.get(index).getIdSp());
        tfIDDM.setText(listSanPham.get(index).getMaDanhMuc());
        tfNameSp.setText(listSanPham.get(index).getNameSp());
        tfPrice.setText(listSanPham.get(index).getPrice());
        tfinputDate.setText(listSanPham.get(index).getInputdate());
        tfOutputDate.setText(listSanPham.get(index).getOutputdate());
        tfHSd.setText(listSanPham.get(index).getHsd());
        tfMota.setText(listSanPham.get(index).getMota());
        getdata = tfIDSp.getText();
        System.out.println("Data:" + getdata);
    }                                         

    private void btDeleteActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        if (tfIDSp.getText().equals("")) {
            JOptionPane.showMessageDialog(rootPane, "Chọn sản phẩm cần xóa dưới bảng thông tin");
        } else {
            delete(tfIDSp.getText());
            JOptionPane.showMessageDialog(rootPane, "Xoa thanh cong id san pham : " + tfIDSp.getText());
            readData();
        }
    }                                        

    private void btResetActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        tfIDSp.setText("");
        tfIDDM.setText("");
        tfNameSp.setText("");
        tfPrice.setText("");
        tfinputDate.setText("");
        tfOutputDate.setText("");
        tfHSd.setText("");
        tfMota.setText("");


    }                                       

    private void btUpdateActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:

        //update
        if (tfIDSp.getText().equalsIgnoreCase(getdata)) {
            String idDM = tfIDDM.getText();
            String nameSp = tfNameSp.getText();
            String price = tfPrice.getText();
            String inputDate = tfinputDate.getText();
            String outputDate = tfOutputDate.getText();
            String hs = tfHSd.getText();
            String mota = tfMota.getText();

            //ket noi sql
            Connection conn = null;
            Statement statement = null;

            try {
                Class.forName("com.mysql.jdbc.Driver");
                conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/t1907a", "root", "");
                String sql = "UPDATE sanpham SET idDM=" + "'" + idDM + "'" + ",nameSp=" + "'" + nameSp + "',price="
                        + "'" + price + "',inputDate= '" + inputDate + "',outputDate= '" + outputDate + "',expiryDate= '"
                        + hs + "',mota = '" + mota + "' where idSp= '" + getdata+"'";
                statement = conn.createStatement();
                statement.executeUpdate(sql);
            } catch (ClassNotFoundException | SQLException ex) {
                Logger.getLogger(QuanLiSp.class.getName()).log(Level.SEVERE, null, ex);
            } finally {
                if (conn != null) {
                    try {
                        conn.close();
                    } catch (SQLException ex) {
                        Logger.getLogger(QuanLiSp.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
                if (statement != null) {
                    try {
                        statement.close();
                    } catch (SQLException ex) {
                        Logger.getLogger(QuanLiSp.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
            readData();
        } else {
            JOptionPane.showMessageDialog(rootPane, "không được sửa idSP");
        }

    }                                        

    private void btdanhmucActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
        FormDanhMuc dm = new FormDanhMuc();
        dm.setVisible(true);
    }                                         
    private int checkHsd(String d1) {
        SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
        int detDiff = 0;
        boolean check = false;
        try {
            // String ngay = "2020-04-01";
            Date curent = new Date();
            String nowDate = sdf.format(curent);
            Date date1 = sdf.parse(d1);
            Date date2 = sdf.parse(nowDate);

            detDiff = (int) (date2.getTime() - date1.getTime());
            detDiff = detDiff / (24 * 60 * 60 * 1000);
            System.out.println("Date khoangcach: " + detDiff);

        } catch (ParseException ex) {
            Logger.getLogger(QuanLiSp.class.getName()).log(Level.SEVERE, null, ex);
        }
        return detDiff;
    }

    private void inserIntoMySql(SanPham sp) {
        Connection conn = null;
        PreparedStatement preparedStatement = null;

        try {

            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/t1907a", "root", "");
            //query

            String sql = "insert into sanpham(idSp,idDM,nameSp,price,inputDate,outputDate,expiryDate,mota)values (?,?,?,?,?,?,?,?)";

            //  System.out.println("Chay qua day");
            preparedStatement = conn.prepareStatement(sql);

            preparedStatement.setString(1, sp.getIdSp());
            preparedStatement.setString(2, sp.getMaDanhMuc());
            preparedStatement.setString(3, sp.getNameSp());
            preparedStatement.setString(4, sp.getPrice());
            preparedStatement.setString(5, sp.getInputdate());
            preparedStatement.setString(6, sp.getOutputdate());
            preparedStatement.setString(7, sp.getHsd());
            preparedStatement.setString(8, sp.getMota());
            preparedStatement.execute();

        } catch (SQLException ex) {
            Logger.getLogger(QuanLiSp.class
                    .getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(QuanLiSp.class
                    .getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (preparedStatement != null) {
                try {
                    preparedStatement.close();

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

                } catch (SQLException ex) {
                    Logger.getLogger(QuanLiSp.class
                            .getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        // System.err.println("Chay qua day");
    }

    private void readData() {
        listSanPham.clear();
        Connection conn = null;
        Statement statement = null;

        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/t1907a", "root", "");
            String sql = "select * from sanpham";

            statement = conn.createStatement();
            ResultSet resultSet = statement.executeQuery(sql);
            //doc du lieu từng hàng trong mysql
            while (resultSet.next()) {

                SanPham sp = new SanPham(resultSet.getString("idSp"),
                        resultSet.getString("idDM"),
                        resultSet.getString("nameSp"),
                        resultSet.getString("price"),
                        resultSet.getString("inputDate"),
                        resultSet.getString("outputDate"),
                        resultSet.getString("expiryDate"),
                        resultSet.getString("mota"));
                listSanPham.add(sp);

            }
        } catch (SQLException ex) {
            Logger.getLogger(QuanLiSp.class
                    .getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(QuanLiSp.class
                    .getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (conn != null) {
                try {
                    conn.close();

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

                } catch (SQLException ex) {
                    Logger.getLogger(QuanLiSp.class
                            .getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

        display(listSanPham);
    }

    private void delete(String data) {
        Connection conn = null;
        Statement statement = null;

        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/t1907a", "root", "");

            String sql = "DELETE FROM sanpham WHERE idSp =" + "'" + data + "'";

            statement = conn.createStatement();
            statement.executeUpdate(sql);
        } catch (ClassNotFoundException | SQLException ex) {
            Logger.getLogger(QuanLiSp.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException ex) {
                    Logger.getLogger(QuanLiSp.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(QuanLiSp.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }

    public void display(List<SanPham> list) {
        tableModel.setRowCount(0);
        for (SanPham sp : list) {
            Vector vtdata = new Vector();
            vtdata.add(sp.getIdSp());
            vtdata.add(sp.getMaDanhMuc());
            vtdata.add(sp.getNameSp());
            vtdata.add(sp.getPrice());
            vtdata.add(sp.getInputdate());
            vtdata.add(sp.getOutputdate());
            vtdata.add(sp.getHsd());
            vtdata.add(sp.getMota());
            tableModel.addRow(vtdata);
        }
        for (SanPham list1 : list) {
            list1.display();
        }
    }

    /**
     * @param args the command line arguments
     */
    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(QuanLiSp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(QuanLiSp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(QuanLiSp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(QuanLiSp.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 QuanLiSp().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton btAllSanpham;
    private javax.swing.JButton btDelete;
    private javax.swing.JButton btFind;
    private javax.swing.JButton btReset;
    private javax.swing.JButton btSanphamHetHsd;
    private javax.swing.JButton btSaphetHSd;
    private javax.swing.JButton btSave;
    private javax.swing.JButton btSpSell;
    private javax.swing.JButton btTonkho;
    private javax.swing.JButton btUpdate;
    private javax.swing.JButton btdanhmuc;
    private javax.swing.JLabel jLabel1;
    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.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable showthongtin;
    private javax.swing.JTextField tfHSd;
    private javax.swing.JTextField tfIDDM;
    private javax.swing.JTextField tfIDSp;
    private javax.swing.JTextField tfMota;
    private javax.swing.JTextField tfNameSp;
    private javax.swing.JTextField tfOutputDate;
    private javax.swing.JTextField tfPrice;
    private javax.swing.JTextField tfinputDate;
    // 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 QuanLiSanPham;

/**
 *
 * @author Thien Phu
 */
public class login {

    int rollNo;
    String username, pass;

    public login() {
    }

    public login(int rollNo, String username, String pass) {
        this.rollNo = rollNo;
        this.username = username;
        this.pass = pass;
    }

    public int getRollNo() {
        return rollNo;
    }

    public void setRollNo(int rollNo) {
        this.rollNo = rollNo;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPass() {
        return pass;
    }

    public void setPass(String pass) {
        this.pass = pass;
    }

    @Override
    public String toString() {
        return "login{" + "rollNo=" + rollNo + ", username=" + username + ", pass=" + pass + '}';
    }

    void display() {
        System.out.println(toString());
    }
}



/*
 * 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 QuanLiSanPham;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author Thien Phu
 */
public class DangNhap extends javax.swing.JFrame {

    /**
     * Creates new form DangNhap
     */
    public DangNhap() {
        initComponents();
    }

    /**
     * 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() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        tfusername = new javax.swing.JTextField();
        tfpassword = new javax.swing.JTextField();
        btDangNhap = new javax.swing.JButton();
        btExit = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Đăng nhập hệ thống", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 18))); // NOI18N

        jLabel1.setText("UserName");

        jLabel2.setText("Pass word");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(29, 29, 29)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(18, 18, 18)
                        .addComponent(tfpassword, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(tfusername, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(21, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfusername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfpassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(38, Short.MAX_VALUE))
        );

        btDangNhap.setText("Dang Nhap");
        btDangNhap.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btDangNhapActionPerformed(evt);
            }
        });

        btExit.setText("Thoat");
        btExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btExitActionPerformed(evt);
            }
        });

        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(20, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btDangNhap)
                        .addGap(33, 33, 33)
                        .addComponent(btExit))
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(31, 31, 31))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btDangNhap)
                    .addComponent(btExit))
                .addContainerGap(19, Short.MAX_VALUE))
        );

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

    private void btDangNhapActionPerformed(java.awt.event.ActionEvent evt) {                                           
        // TODO add your handling code here:
        readData();
    }                                          

    private void btExitActionPerformed(java.awt.event.ActionEvent evt) {                                       
        // TODO add your handling code here:
        System.exit(0);
    }                                      
    private void readData() {
        login lg = new login();
        Connection conn = null;
        Statement statement = null;

        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/t1907a", "root", "");
            String sql = "select * from login";

            statement = conn.createStatement();
            ResultSet resultSet = statement.executeQuery(sql);
            //doc du lieu từng hàng trong mysql
            while (resultSet.next()) {

                lg.setRollNo(Integer.parseInt(resultSet.getString("id")));
                lg.setUsername(resultSet.getString("username"));
                lg.setPass(resultSet.getString("pass"));
                ;

            }
        } catch (SQLException ex) {
            Logger.getLogger(DangNhap.class
                    .getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(DangNhap.class
                    .getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (conn != null) {
                try {
                    conn.close();

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

                } catch (SQLException ex) {
                    Logger.getLogger(DangNhap.class
                            .getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        if (tfusername.getText().equals("") || tfpassword.getText().equals("")) {
            JOptionPane.showMessageDialog(rootPane, "Nhập dữ liệu");
        } else {
            if (lg.getUsername().equals(tfusername.getText()) && lg.getPass().equals(tfpassword.getText())) {
                QuanLiSp sp = new QuanLiSp();
                sp.setVisible(true);
                this.setVisible(false);
            } else {
                JOptionPane.showConfirmDialog(rootPane, "Nhập sai mời nhập lại");
            }
        }

    }

    /**
     * @param args the command line arguments
     */
    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(DangNhap.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(DangNhap.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(DangNhap.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(DangNhap.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 DangNhap().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton btDangNhap;
    private javax.swing.JButton btExit;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField tfpassword;
    private javax.swing.JTextField tfusername;
    // End of variables declaration                   
}


Trương Công Vinh [T1907A]

Ngày viết: 15:29 07/04/2020

Frame

Trương Công Vinh [T1907A]

Ngày viết: 15:07 07/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 asiment;

/**
 *
 * @author DELL
 */
public class Product {
    String  productName ,ngayNhap , ngayBan , HSD ;
    
    float price;
    int productId;

    public Product() {
    }

    public Product( String productName, String ngayNhap, String ngayBan, String HSD, float price) {
        
        this.productName = productName;
        this.ngayNhap = ngayNhap;
        this.ngayBan = ngayBan;
        this.HSD = HSD;
        this.price = price;
    }

    public int getProductId() {
        return productId;
    }

    public void setProductId(int productId) {
        this.productId = productId;
    }

    public String getProductName() {
        return productName;
    }

    public void setProductName(String productName) {
        this.productName = productName;
    }

    public String getNgayNhap() {
        return ngayNhap;
    }

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

    public String getNgayBan() {
        return ngayBan;
    }

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

    public String getHSD() {
        return HSD;
    }

    public void setHSD(String HSD) {
        this.HSD = HSD;
    }

    public float getPrice() {
        return price;
    }

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

    @Override
    public String toString() {
        return "Product{" + "productName=" + productName + ", ngayNhap=" + ngayNhap + ", ngayBan=" + ngayBan + ", HSD=" + HSD + ", price=" + price + ", productId=" + productId + '}';
    }
    
}



/*
 * 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 asiment;

import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author DELL
 */
public class productFrame extends javax.swing.JFrame {

    ArrayList<Product> list = new ArrayList<>();

    DefaultTableModel tableModel;
    productModify productModify;

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

    public void showall() {
        list = productModify.showAll();
        tableModel.setRowCount(0);
        for (Product product : list) {
            tableModel.addRow(new Object[]{tableModel.getRowCount() + 1,
                product.getProductName(),
                product.getNgayNhap(),
                product.getNgayBan(),
                product.getHSD(),
                product.getPrice()});
        }

    }

    /**
     * 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() {

        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jCheckBoxMenuItem1 = new javax.swing.JCheckBoxMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txttensp = new javax.swing.JTextField();
        txtNgaynhap = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtngayban = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        txtHSD = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtprice = new javax.swing.JTextField();
        txtgia = new javax.swing.JLabel();
        btnupdate = new javax.swing.JButton();
        btnedit = new javax.swing.JButton();
        btndelete = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblProduct = new javax.swing.JTable();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();
        mnFilter = new javax.swing.JMenu();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenuItem6 = new javax.swing.JMenuItem();
        jMenuItem7 = new javax.swing.JMenuItem();
        jMenuItem8 = new javax.swing.JMenuItem();
        jMenuItem9 = new javax.swing.JMenuItem();
        jMenuItem10 = new javax.swing.JMenuItem();
        jMenuItem11 = new javax.swing.JMenuItem();

        jMenuItem1.setText("jMenuItem1");

        jMenuItem2.setText("jMenuItem2");

        jCheckBoxMenuItem1.setSelected(true);
        jCheckBoxMenuItem1.setText("jCheckBoxMenuItem1");

        jMenuItem3.setText("jMenuItem3");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Tên sản Phẩm : ");

        txttensp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txttenspActionPerformed(evt);
            }
        });

        txtNgaynhap.setText("YYYY-MM-DD");

        jLabel2.setText("Ngày nhập  : ");

        txtngayban.setText("YYYY-MM-DD");

        jLabel3.setText("Ngày bán : ");

        txtHSD.setText("YYYY-MM-DD");

        jLabel4.setText("HSD : ");

        txtgia.setText("Price : ");

        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);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(txtHSD, javax.swing.GroupLayout.PREFERRED_SIZE, 401, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(txtngayban, javax.swing.GroupLayout.PREFERRED_SIZE, 401, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(txtNgaynhap, javax.swing.GroupLayout.PREFERRED_SIZE, 401, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(38, 38, 38)
                                .addComponent(txttensp, javax.swing.GroupLayout.PREFERRED_SIZE, 401, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(txtgia)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addComponent(btnupdate)
                                .addGap(18, 18, 18)
                                .addComponent(btnedit)
                                .addGap(18, 18, 18)
                                .addComponent(btndelete)
                                .addGap(234, 234, 234))
                            .addComponent(txtprice, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 401, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txttensp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtNgaynhap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtngayban, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtHSD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtgia)
                    .addComponent(txtprice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnupdate)
                    .addComponent(btnedit)
                    .addComponent(btndelete))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

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

            },
            new String [] {
                "ProductId", "ProductName", "inportDate", "sellDate", "HSD", "Price"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, true, true
            };

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

        jMenu1.setText("File");
        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");
        jMenuBar1.add(jMenu2);

        mnFilter.setText("Filter");
        mnFilter.setActionCommand("Filter");

        jMenuItem4.setText(" Tìm kiểm sản phẩm");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        mnFilter.add(jMenuItem4);

        jMenuItem5.setText("Danh sách sản phầm còn tồn kho");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        mnFilter.add(jMenuItem5);

        jMenuItem6.setText("Danh sách các sản phẩm đã bán");
        jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem6ActionPerformed(evt);
            }
        });
        mnFilter.add(jMenuItem6);

        jMenuItem7.setText("Bao cáo sản phẩm bán trong tuần");
        jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem7ActionPerformed(evt);
            }
        });
        mnFilter.add(jMenuItem7);

        jMenuItem8.setText("Báo cáo sản phẩm bán trong tháng");
        jMenuItem8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem8ActionPerformed(evt);
            }
        });
        mnFilter.add(jMenuItem8);

        jMenuItem9.setText("Báo cáo sản phẩm bán trong ngày");
        jMenuItem9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem9ActionPerformed(evt);
            }
        });
        mnFilter.add(jMenuItem9);

        jMenuItem10.setText("còn hạn");
        jMenuItem10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem10ActionPerformed(evt);
            }
        });
        mnFilter.add(jMenuItem10);

        jMenuItem11.setText("Hết hạn");
        jMenuItem11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem11ActionPerformed(evt);
            }
        });
        mnFilter.add(jMenuItem11);

        jMenuBar1.add(mnFilter);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 657, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(32, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 249, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

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

    private void txttenspActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
    }                                        

    private void btnupdateActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:

        String proName = txttensp.getText();
        String HSD = txtHSD.getText();
        String importDate = txtNgaynhap.getText();
        String sellDate = txtngayban.getText();
        float price = Float.parseFloat(txtprice.getText());
        Product pr = new Product();
        pr.setProductName(proName);
        pr.setHSD(HSD);
        pr.setNgayBan(sellDate);
        pr.setNgayNhap(importDate);
        pr.setPrice(price);

        productModify.update(pr);

        System.out.println(pr.toString());

        showall();
    }                                         

    private void btndeleteActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
       int selectedIndex = tblProduct.getSelectedRow();
        if(selectedIndex >= 0) {
            Product pro = list.get(selectedIndex);
            
            int option = JOptionPane.showConfirmDialog(this, "Do you want to delete this item?");
            System.out.println("option : " + option);
            
            if(option == 0) {
                productModify.delete(pro.getProductId());
                
                showall();
            }
        }
        
    }                                         

    private void btneditActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        String proName = txttensp.getText();
        String HSD = txtHSD.getText();
        String importDate = txtNgaynhap.getText();
        String sellDate = txtngayban.getText();
        float price = Float.parseFloat(txtprice.getText());
        Product pr = new Product(proName,importDate,sellDate,HSD,price);
        int selectedIndex = tblProduct.getSelectedRow();
        if(selectedIndex >= 0){
            Product pro = list.get(selectedIndex);
            pr.setProductId(pro.getProductId());
        }
        productModify.Edit(pr);
        showall();
    }                                       

    private void jMenuItem4ActionPerformed(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) {
            list = productModify.findByproName(input);
            
            tableModel.setRowCount(0);
        
            list.forEach((Product product) -> {
                tableModel.addRow(new Object[]{tableModel.getRowCount() + 1,
                    product.getProductName(),
                    product.getNgayNhap(),
                    product.getNgayBan(),
                    product.getHSD(),
                    product.getPrice()});
            });
        } else {
            showall();
        }
    }                                          

    private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        // TODO add your handling code here:
        list = productModify.tonkho();
        tableModel.setRowCount(0);
        
            list.forEach((Product product) -> {
                tableModel.addRow(new Object[]{tableModel.getRowCount() + 1,
                    product.getProductName(),
                    product.getNgayNhap(),
                    product.getNgayBan(),
                    product.getHSD(),
                    product.getPrice()});
            });
    }                                          

    private void jMenuItem9ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        // TODO add your handling code here:
        list = productModify.trongngay();
        tableModel.setRowCount(0);
        
            list.forEach((Product product) -> {
                tableModel.addRow(new Object[]{tableModel.getRowCount() + 1,
                    product.getProductName(),
                    product.getNgayNhap(),
                    product.getNgayBan(),
                    product.getHSD(),
                    product.getPrice()});
            });
    }                                          

    private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        // TODO add your handling code here:
        list = productModify.trongtuan();
        tableModel.setRowCount(0);
        
            list.forEach((Product product) -> {
                tableModel.addRow(new Object[]{tableModel.getRowCount() + 1,
                    product.getProductName(),
                    product.getNgayNhap(),
                    product.getNgayBan(),
                    product.getHSD(),
                    product.getPrice()});
            });
    }                                          

    private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        // TODO add your handling code here:
        list = productModify.trongthang();
        tableModel.setRowCount(0);
        
            list.forEach((Product product) -> {
                tableModel.addRow(new Object[]{tableModel.getRowCount() + 1,
                    product.getProductName(),
                    product.getNgayNhap(),
                    product.getNgayBan(),
                    product.getHSD(),
                    product.getPrice()});
            });
    }                                          

    private void jMenuItem11ActionPerformed(java.awt.event.ActionEvent evt) {                                            
        // TODO add your handling code here:
        list = productModify.hethan();
        tableModel.setRowCount(0);
        
            list.forEach((Product product) -> {
                tableModel.addRow(new Object[]{tableModel.getRowCount() + 1,
                    product.getProductName(),
                    product.getNgayNhap(),
                    product.getNgayBan(),
                    product.getHSD(),
                    product.getPrice()});
            });
    }                                           

    private void jMenuItem10ActionPerformed(java.awt.event.ActionEvent evt) {                                            
        // TODO add your handling code here:
        list = productModify.conhan();
        tableModel.setRowCount(0);
        
            list.forEach((Product product) -> {
                tableModel.addRow(new Object[]{tableModel.getRowCount() + 1,
                    product.getProductName(),
                    product.getNgayNhap(),
                    product.getNgayBan(),
                    product.getHSD(),
                    product.getPrice()});
            });
    }                                           

    private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        // TODO add your handling code here:
        list = productModify.daban();
        tableModel.setRowCount(0);
        
            list.forEach((Product product) -> {
                tableModel.addRow(new Object[]{tableModel.getRowCount() + 1,
                    product.getProductName(),
                    product.getNgayNhap(),
                    product.getNgayBan(),
                    product.getHSD(),
                    product.getPrice()});
            });
    }                                          

    /**
     * @param args the command line arguments
     */
    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.JButton btndelete;
    private javax.swing.JButton btnedit;
    private javax.swing.JButton btnupdate;
    private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItem1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem10;
    private javax.swing.JMenuItem jMenuItem11;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JMenuItem jMenuItem7;
    private javax.swing.JMenuItem jMenuItem8;
    private javax.swing.JMenuItem jMenuItem9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JMenu mnFilter;
    private javax.swing.JTable tblProduct;
    private javax.swing.JTextField txtHSD;
    private javax.swing.JTextField txtNgaynhap;
    private javax.swing.JLabel txtgia;
    private javax.swing.JTextField txtngayban;
    private javax.swing.JTextField txtprice;
    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 asiment;

import java.awt.List;
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.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author DELL
 */
public class productModify {
    
    

    public static ArrayList<Product> showAll() {
        ArrayList<Product> list = new ArrayList<>();
        Connection conn = null;
        Statement statement = null;
        try {
            conn = DriverManager.getConnection("jdbc:mysql://localhost/productAss?serverTimezone=UTC","root","");
            statement = conn.createStatement();
            String sql = "Select * from product" ;
            ResultSet resultset = statement.executeQuery(sql);
            while (resultset.next()) {                
                Product product = new Product(resultset.getString("proName"),
                        resultset.getString("importDate"),
                        resultset.getString("sellDate"),
                        resultset.getString("HSD"),
                        resultset.getFloat("price"));
                list.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);
                }
            }
        }
        

        return list;
    }

    public static void update(Product pro) {
        Connection conn = null;
        PreparedStatement statement = null;

        try {
            conn = DriverManager.getConnection("jdbc:mysql://localhost/productAss?serverTimezone=UTC","root","");

            String sql = "insert into product(proName,importDate,sellDate,HSD,price) values(?,Convert(?,Datetime),Convert(?,Datetime),Convert(?,Datetime),?)";
            statement = conn.prepareCall(sql);
            statement.setString(1, pro.getProductName());
            statement.setString(2, pro.getNgayNhap());
            statement.setString(3, pro.getNgayBan());
            statement.setString(4, pro.getHSD());
            statement.setFloat(5, pro.getPrice());
            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);
                }
            }
        }
    }
    
    public static void delete(int id) {
        Connection connection = null;
        PreparedStatement statement = null;
        
        try {
            //lay tat ca danh sach sinh vien
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/productAss?serverTimezone=UTC", "root", "");

            String sql = "delete from product where ProID = ?";
            statement = connection.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 (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(productModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
    public static void Edit(Product pro) {
        Connection connection = null;
        PreparedStatement statement = null;
        
        try {

            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/productAss?serverTimezone=UTC", "root", "");

            String sql = "update product set proName=?,importDate=?,sellDate=?,HSD=?,price=? where ProID = ?";
            statement = connection.prepareCall(sql);
            statement.setString(1,pro.getProductName() );
            statement.setString(2,pro.getNgayNhap() );
            statement.setString(3,pro.getNgayBan() );
            statement.setString(4, pro.getHSD());
            statement.setFloat(5,pro.getPrice() );
            statement.setInt(6, pro.getProductId());
            
            
            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 (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(productModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
    
    public static ArrayList<Product> findByproName(String proName) {
        ArrayList<Product> list = new ArrayList<>();
        
        Connection connection = null;
        PreparedStatement statement = null;
        
        try {

            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/productAss?serverTimezone=UTC", "root", "");

            String sql = "select * from product where proName like ?";
            statement = connection.prepareCall(sql);
            statement.setString(1, "%"+proName+"%");
            
            ResultSet resultset = statement.executeQuery();
            
            while (resultset.next()) {                
                Product product = new Product(resultset.getString("proName"),
                        resultset.getString("importDate"),
                        resultset.getString("sellDate"),
                        resultset.getString("HSD"),
                        resultset.getFloat("price"));
                list.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 (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(productModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

        
        return list;
    }
    public static ArrayList<Product> tonkho() {
        ArrayList<Product> list = new ArrayList<>();
        
        Connection connection = null;
        PreparedStatement statement = null;
        
        try {

            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/productAss?serverTimezone=UTC", "root", "");

            String sql = "select * from product where (sellDate = '' or sellDate = ' ' or sellDate = null )";
            statement = connection.prepareCall(sql);
            
            ResultSet resultset = statement.executeQuery();
            
            while (resultset.next()) {                
                Product product = new Product(resultset.getString("proName"),
                        resultset.getString("importDate"),
                        resultset.getString("sellDate"),
                        resultset.getString("HSD"),
                        resultset.getFloat("price"));
                list.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 (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(productModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

        
        return list;
    }
    public static ArrayList<Product> trongngay() {
        ArrayList<Product> list = new ArrayList<>();
        
        Connection connection = null;
        PreparedStatement statement = null;
        
        try {

            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/productAss?serverTimezone=UTC", "root", "");

            String sql = "select * from product where (CURDATE() = sellDate)";
            statement = connection.prepareCall(sql);
            
            ResultSet resultset = statement.executeQuery();
            
            while (resultset.next()) {                
                Product product = new Product(resultset.getString("proName"),
                        resultset.getString("importDate"),
                        resultset.getString("sellDate"),
                        resultset.getString("HSD"),
                        resultset.getFloat("price"));
                list.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 (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(productModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

        
        return list;
    }
    public static ArrayList<Product> trongtuan() {
        ArrayList<Product> list = new ArrayList<>();
        
        Connection connection = null;
        PreparedStatement statement = null;
        
        try {

            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/productAss?serverTimezone=UTC", "root", "");

            String sql = "select * from product where (YEARWEEK(importDate) = YEARWEEK(sellDate))";
            statement = connection.prepareCall(sql);
            
            ResultSet resultset = statement.executeQuery();
            
            while (resultset.next()) {                
                Product product = new Product(resultset.getString("proName"),
                        resultset.getString("importDate"),
                        resultset.getString("sellDate"),
                        resultset.getString("HSD"),
                        resultset.getFloat("price"));
                list.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 (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(productModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

        
        return list;
    }
    public static ArrayList<Product> trongthang() {
        ArrayList<Product> list = new ArrayList<>();
        
        Connection connection = null;
        PreparedStatement statement = null;
        
        try {

            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/productAss?serverTimezone=UTC", "root", "");

            String sql = "select * from product where (MONTH(importDate) = MONTH(sellDate))";
            statement = connection.prepareCall(sql);
            
            ResultSet resultset = statement.executeQuery();
            
            while (resultset.next()) {                
                Product product = new Product(resultset.getString("proName"),
                        resultset.getString("importDate"),
                        resultset.getString("sellDate"),
                        resultset.getString("HSD"),
                        resultset.getFloat("price"));
                list.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 (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(productModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

        
        return list;
    }
    
    
    public static ArrayList<Product> conhan() {
        ArrayList<Product> list = new ArrayList<>();
        
        Connection connection = null;
        PreparedStatement statement = null;
        
        try {

            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/productAss?serverTimezone=UTC", "root", "");

            String sql = "select * from product where (CURDATE() < HSD )";
            statement = connection.prepareCall(sql);
            
            ResultSet resultset = statement.executeQuery();
            
            while (resultset.next()) {                
                Product product = new Product(resultset.getString("proName"),
                        resultset.getString("importDate"),
                        resultset.getString("sellDate"),
                        resultset.getString("HSD"),
                        resultset.getFloat("price"));
                list.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 (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(productModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

        
        return list;
    }
    public static ArrayList<Product> hethan() {
        ArrayList<Product> list = new ArrayList<>();
        
        Connection connection = null;
        PreparedStatement statement = null;
        
        try {

            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/productAss?serverTimezone=UTC", "root", "");

            String sql = "select * from product where (CURDATE() > HSD)";
            statement = connection.prepareCall(sql);
            
            ResultSet resultset = statement.executeQuery();
            
            while (resultset.next()) {                
                Product product = new Product(resultset.getString("proName"),
                        resultset.getString("importDate"),
                        resultset.getString("sellDate"),
                        resultset.getString("HSD"),
                        resultset.getFloat("price"));
                list.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 (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(productModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

        
        return list;
    }
    public static ArrayList<Product> daban() {
        ArrayList<Product> list = new ArrayList<>();
        
        Connection connection = null;
        PreparedStatement statement = null;
        
        try {

            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/productAss?serverTimezone=UTC", "root", "");

            String sql = "select * from product where (selldate > 0)";
            statement = connection.prepareCall(sql);
            
            ResultSet resultset = statement.executeQuery();
            
            while (resultset.next()) {                
                Product product = new Product(resultset.getString("proName"),
                        resultset.getString("importDate"),
                        resultset.getString("sellDate"),
                        resultset.getString("HSD"),
                        resultset.getFloat("price"));
                list.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 (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(productModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

        
        return list;
    }
}


Tài Liệu Tham Khảo

Ứng Dụng Tiện Ích



Đã sao chép!!!