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

lê văn phương [T1907A]

Ngày viết: 09:30 09/04/2020



// bổ sung phần db 


CREATE TABLE sanpham(
    id_sanpham int(10) PRIMARY KEY NOT NULL,
    id_danhmuc int(10) NOT NULL,
    tensanpham VARCHAR(20) NOT NULL,
    gia float(20) NOT NULL,
    ngaynhap data(10) ,
    ngayban data(10),
    hansudung data(10),
    mota VARCHAR(100) NOT NULL
)
CREATE TABLE danhmuc(
    id_danhMuc int(10) FOREIGN KEY NOT NULL,
    tendanhmuc VARCHAR(50) NOT NULL
)


lê văn phương [T1907A]

Ngày viết: 23:05 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 QLHH;
import java.sql.*;
import javax.swing.*;
/**
 *
 * @author Admin
 */
public class CheckLog {
//    public static Connection conn = null;
//    public static String testConnect(){
//        try {
//            conn= SanPhamtModify.getConnection();
//            return "Ket noi co so du lieu thanh cong";
//        } catch (Exception e) {
//            return "Ket noi co so du lieu that bai";
//        }
//    }
//    public static ResultSet log(String use, String pass){
//        
//    }
}



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

/**
 *
 * @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 QLHH;


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.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(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)
                            .addComponent(jLabel4, 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.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(txtTensanpham, javax.swing.GroupLayout.DEFAULT_SIZE, 334, Short.MAX_VALUE)
                        .addComponent(txtmota)
                        .addComponent(txtgiaban)
                        .addComponent(txtngayban)
                        .addComponent(txtngayhethan)
                        .addComponent(txtngaynhap, javax.swing.GroupLayout.Alignment.TRAILING))
                    .addComponent(txtdanhmuc, javax.swing.GroupLayout.PREFERRED_SIZE, 334, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(52, 52, 52)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 847, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(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))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .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(18, 18, 18)
                        .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(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(txtTensanpham, 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(txtgiaban, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))
                        .addGap(15, 15, 15)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtngaynhap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtngayban, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtmota, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtngayhethan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(96, 96, 96))
        );

        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()
                .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))
        );
        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, 489, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0))
        );

        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                   
}



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

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 QLHH;

/**
 *
 * @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 QLHH;

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


thienphu [T1907A]

Ngày viết: 20:36 08/04/2020


code MySql
// login
CREATE TABLE login(
    id INT AUTO_INCREMENT PRIMARY KEY NOT NULL,
    username VARCHAR(30) NOT NULL,
    pass VARCHAR(30) NOT NULL
)
//sanpham
CREATE TABLE sanpham(
    idSp VARCHAR(10) PRIMARY KEY NOT NULL,
    idDM VARCHAR(10) NOT NULL,
    nameSp VARCHAR(20) NOT NULL,
    price VARCHAR(20) NOT NULL,
    inputDate VARCHAR(10) NOT NULL,
    outputDate VARCHAR(10),
    expiryDate VARCHAR(10),
    mota VARCHAR(100) NOT NULL
)
//Danh Muc
CREATE TABLE danhmuc(
    rollNo INT AUTO_INCREMENT PRIMARY KEY NOT NULL,
    idDanhMuc VARCHAR(30) NOT NULL,
    nameDanhMuc VARCHAR(30) NOT NULL
)


hoangduyminh [T1907A]

Ngày viết: 20:24 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 java2.lesson2.main;

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

/**
 *
 * @author Minh
 */
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();

    }

    public void showAll() {
        list = productModify.showAll();
        tableModel.setRowCount(0);
        for (Product product : list) {
            tableModel.addRow(new Object[]{tableModel.getRowCount() + 1,
                product.getProductName(),
                product.getnNhap(),
                product.getnBan(),
                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() {

        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();
        txtProductname = new javax.swing.JTextField();
        txtnNhap = new javax.swing.JTextField();
        txtnBan = new javax.swing.JTextField();
        txtHSD = new javax.swing.JTextField();
        txtgBan = new javax.swing.JTextField();
        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();
        jMenu3 = new javax.swing.JMenu();
        jCheckBoxMenuItem1 = new javax.swing.JCheckBoxMenuItem();
        jCheckBoxMenuItem2 = new javax.swing.JCheckBoxMenuItem();
        jCheckBoxMenuItem3 = new javax.swing.JCheckBoxMenuItem();
        jCheckBoxMenuItem4 = new javax.swing.JCheckBoxMenuItem();
        jCheckBoxMenuItem5 = new javax.swing.JCheckBoxMenuItem();
        jCheckBoxMenuItem6 = new javax.swing.JCheckBoxMenuItem();
        jCheckBoxMenuItem7 = new javax.swing.JCheckBoxMenuItem();
        jCheckBoxMenuItem8 = new javax.swing.JCheckBoxMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Ten San Pham:");
        jLabel1.setToolTipText("");

        jLabel2.setText("Ngay Nhap:");
        jLabel2.setToolTipText("");

        jLabel3.setText("Ngay Ban:");

        jLabel4.setText("HSD:");

        jLabel5.setText("Gia Ban:");

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

        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()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jLabel1)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(txtProductname))
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jLabel2)
                                    .addGap(36, 36, 36)
                                    .addComponent(txtnNhap, javax.swing.GroupLayout.PREFERRED_SIZE, 342, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel5)
                                    .addComponent(jLabel3))
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGap(49, 49, 49)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(txtHSD, javax.swing.GroupLayout.DEFAULT_SIZE, 342, Short.MAX_VALUE)
                                            .addComponent(txtgBan)))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 49, Short.MAX_VALUE)
                                        .addComponent(txtnBan, javax.swing.GroupLayout.PREFERRED_SIZE, 342, javax.swing.GroupLayout.PREFERRED_SIZE))))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(180, 180, 180)
                        .addComponent(btnUpdate)
                        .addGap(68, 68, 68)
                        .addComponent(btnEdit)
                        .addGap(52, 52, 52)
                        .addComponent(btnDelete)))
                .addContainerGap(453, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtProductname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(35, 35, 35)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtnNhap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(31, 31, 31)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtnBan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addGap(45, 45, 45)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtHSD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(49, 49, 49)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtgBan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(36, 36, 36)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnUpdate)
                    .addComponent(btnEdit)
                    .addComponent(btnDelete, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(61, Short.MAX_VALUE))
        );

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

            },
            new String [] {
                "ID", "Ten San Pham", "Ngay Nhap", "Ngay Ban", "HSD", "Gia Ban"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                true, false, true, false, false, false
            };

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

        jMenu3.setText("Fitler");

        jCheckBoxMenuItem1.setSelected(true);
        jCheckBoxMenuItem1.setText("Tim kiem san pham");
        jCheckBoxMenuItem1.setToolTipText("");
        jMenu3.add(jCheckBoxMenuItem1);

        jCheckBoxMenuItem2.setSelected(true);
        jCheckBoxMenuItem2.setText("Danh sach cac san pham ton kho");
        jMenu3.add(jCheckBoxMenuItem2);

        jCheckBoxMenuItem3.setSelected(true);
        jCheckBoxMenuItem3.setText("Danh sach cac san pham da ban");
        jMenu3.add(jCheckBoxMenuItem3);

        jCheckBoxMenuItem4.setSelected(true);
        jCheckBoxMenuItem4.setText("Bao cao san pham trong tuan");
        jMenu3.add(jCheckBoxMenuItem4);

        jCheckBoxMenuItem5.setSelected(true);
        jCheckBoxMenuItem5.setText("Bao cao san pham trong ngay");
        jMenu3.add(jCheckBoxMenuItem5);

        jCheckBoxMenuItem6.setSelected(true);
        jCheckBoxMenuItem6.setText("Bao cao san pham trong thang");
        jMenu3.add(jCheckBoxMenuItem6);

        jCheckBoxMenuItem7.setSelected(true);
        jCheckBoxMenuItem7.setText("San pham con han");
        jMenu3.add(jCheckBoxMenuItem7);

        jCheckBoxMenuItem8.setSelected(true);
        jCheckBoxMenuItem8.setText("San Pham het han");
        jMenu3.add(jCheckBoxMenuItem8);

        jMenuBar1.add(jMenu3);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING)
        );
        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(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

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

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

    private void btnEditActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        String productname = txtProductname.getText();
        String hsd = txtHSD.getText();
        String importproduct = txtnNhap.getText();
        String sellday = txtnBan.getText();
        float price = Float.parseFloat(txtgBan.getText());

        Product prt = new Product(productname, importproduct, sellday, hsd, price);
        int selectedIndex = tblProduct.getSelectedRow();
        if (selectedIndex >= 0) {
            Product pro = list.get(selectedIndex);
            prt.setProductId(pro.getProductId());
        }
        productModify.Edit(prt);
        showAll();

    }                                       

    private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
        String productname = txtProductname.getText();
        String importproduct = txtnNhap.getText();
        String sellday = txtnBan.getText();
        String hsd = txtHSD.getText();
        float price = Float.parseFloat(txtgBan.getText());
        Product prt = new Product();
        prt.setProductName(productname);
        prt.setnNhap(importproduct);
        prt.setnBan(sellday);
        prt.setHSD(hsd);
        prt.setPrice(price);

        productModify.update(prt);

        System.out.println(prt.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();

            }
        }
    }                                         

    /**
     * @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.JCheckBoxMenuItem jCheckBoxMenuItem2;
    private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItem3;
    private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItem4;
    private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItem5;
    private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItem6;
    private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItem7;
    private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItem8;
    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.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tblProduct;
    private javax.swing.JTextField txtHSD;
    private javax.swing.JTextField txtProductname;
    private javax.swing.JTextField txtgBan;
    private javax.swing.JTextField txtnBan;
    private javax.swing.JTextField txtnNhap;
    // 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 java2.lesson2.main;

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

/**
 *
 * @author Minh
 */
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();

    }

    public void showAll() {
        list = productModify.showAll();
        tableModel.setRowCount(0);
        for (Product product : list) {
            tableModel.addRow(new Object[]{tableModel.getRowCount() + 1,
                product.getProductName(),
                product.getnNhap(),
                product.getnBan(),
                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() {

        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();
        txtProductname = new javax.swing.JTextField();
        txtnNhap = new javax.swing.JTextField();
        txtnBan = new javax.swing.JTextField();
        txtHSD = new javax.swing.JTextField();
        txtgBan = new javax.swing.JTextField();
        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();
        jMenu3 = new javax.swing.JMenu();
        jCheckBoxMenuItem1 = new javax.swing.JCheckBoxMenuItem();
        jCheckBoxMenuItem2 = new javax.swing.JCheckBoxMenuItem();
        jCheckBoxMenuItem3 = new javax.swing.JCheckBoxMenuItem();
        jCheckBoxMenuItem4 = new javax.swing.JCheckBoxMenuItem();
        jCheckBoxMenuItem5 = new javax.swing.JCheckBoxMenuItem();
        jCheckBoxMenuItem6 = new javax.swing.JCheckBoxMenuItem();
        jCheckBoxMenuItem7 = new javax.swing.JCheckBoxMenuItem();
        jCheckBoxMenuItem8 = new javax.swing.JCheckBoxMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Ten San Pham:");
        jLabel1.setToolTipText("");

        jLabel2.setText("Ngay Nhap:");
        jLabel2.setToolTipText("");

        jLabel3.setText("Ngay Ban:");

        jLabel4.setText("HSD:");

        jLabel5.setText("Gia Ban:");

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

        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()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jLabel1)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(txtProductname))
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jLabel2)
                                    .addGap(36, 36, 36)
                                    .addComponent(txtnNhap, javax.swing.GroupLayout.PREFERRED_SIZE, 342, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel5)
                                    .addComponent(jLabel3))
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGap(49, 49, 49)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(txtHSD, javax.swing.GroupLayout.DEFAULT_SIZE, 342, Short.MAX_VALUE)
                                            .addComponent(txtgBan)))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 49, Short.MAX_VALUE)
                                        .addComponent(txtnBan, javax.swing.GroupLayout.PREFERRED_SIZE, 342, javax.swing.GroupLayout.PREFERRED_SIZE))))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(180, 180, 180)
                        .addComponent(btnUpdate)
                        .addGap(68, 68, 68)
                        .addComponent(btnEdit)
                        .addGap(52, 52, 52)
                        .addComponent(btnDelete)))
                .addContainerGap(453, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtProductname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(35, 35, 35)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtnNhap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(31, 31, 31)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtnBan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addGap(45, 45, 45)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtHSD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(49, 49, 49)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtgBan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(36, 36, 36)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnUpdate)
                    .addComponent(btnEdit)
                    .addComponent(btnDelete, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(61, Short.MAX_VALUE))
        );

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

            },
            new String [] {
                "ID", "Ten San Pham", "Ngay Nhap", "Ngay Ban", "HSD", "Gia Ban"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                true, false, true, false, false, false
            };

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

        jMenu3.setText("Fitler");

        jCheckBoxMenuItem1.setSelected(true);
        jCheckBoxMenuItem1.setText("Tim kiem san pham");
        jCheckBoxMenuItem1.setToolTipText("");
        jMenu3.add(jCheckBoxMenuItem1);

        jCheckBoxMenuItem2.setSelected(true);
        jCheckBoxMenuItem2.setText("Danh sach cac san pham ton kho");
        jMenu3.add(jCheckBoxMenuItem2);

        jCheckBoxMenuItem3.setSelected(true);
        jCheckBoxMenuItem3.setText("Danh sach cac san pham da ban");
        jMenu3.add(jCheckBoxMenuItem3);

        jCheckBoxMenuItem4.setSelected(true);
        jCheckBoxMenuItem4.setText("Bao cao san pham trong tuan");
        jMenu3.add(jCheckBoxMenuItem4);

        jCheckBoxMenuItem5.setSelected(true);
        jCheckBoxMenuItem5.setText("Bao cao san pham trong ngay");
        jMenu3.add(jCheckBoxMenuItem5);

        jCheckBoxMenuItem6.setSelected(true);
        jCheckBoxMenuItem6.setText("Bao cao san pham trong thang");
        jMenu3.add(jCheckBoxMenuItem6);

        jCheckBoxMenuItem7.setSelected(true);
        jCheckBoxMenuItem7.setText("San pham con han");
        jMenu3.add(jCheckBoxMenuItem7);

        jCheckBoxMenuItem8.setSelected(true);
        jCheckBoxMenuItem8.setText("San Pham het han");
        jMenu3.add(jCheckBoxMenuItem8);

        jMenuBar1.add(jMenu3);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING)
        );
        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(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

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

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

    private void btnEditActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        String productname = txtProductname.getText();
        String hsd = txtHSD.getText();
        String importproduct = txtnNhap.getText();
        String sellday = txtnBan.getText();
        float price = Float.parseFloat(txtgBan.getText());

        Product prt = new Product(productname, importproduct, sellday, hsd, price);
        int selectedIndex = tblProduct.getSelectedRow();
        if (selectedIndex >= 0) {
            Product pro = list.get(selectedIndex);
            prt.setProductId(pro.getProductId());
        }
        productModify.Edit(prt);
        showAll();

    }                                       

    private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
        String productname = txtProductname.getText();
        String importproduct = txtnNhap.getText();
        String sellday = txtnBan.getText();
        String hsd = txtHSD.getText();
        float price = Float.parseFloat(txtgBan.getText());
        Product prt = new Product();
        prt.setProductName(productname);
        prt.setnNhap(importproduct);
        prt.setnBan(sellday);
        prt.setHSD(hsd);
        prt.setPrice(price);

        productModify.update(prt);

        System.out.println(prt.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();

            }
        }
    }                                         

    /**
     * @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.JCheckBoxMenuItem jCheckBoxMenuItem2;
    private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItem3;
    private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItem4;
    private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItem5;
    private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItem6;
    private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItem7;
    private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItem8;
    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.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tblProduct;
    private javax.swing.JTextField txtHSD;
    private javax.swing.JTextField txtProductname;
    private javax.swing.JTextField txtgBan;
    private javax.swing.JTextField txtnBan;
    private javax.swing.JTextField txtnNhap;
    // 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 java2.lesson2.main;

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 Minh
 */
public class productModify {

    public static ArrayList<Product> showAll() {
        ArrayList<Product> list = new ArrayList<>();
        Connection connection = null;
        Statement statement = null;
        try {
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/product?serverTimezone=UTC", "root", "");

            statement = connection.createStatement();
            String sql = "Select * from product";
            ResultSet resultSet = statement.executeQuery(sql);

            while (resultSet.next()) {
                Product product = new Product(resultSet.getString("productname"),
                        resultSet.getString("importproduct"),
                        resultSet.getString("sellday"),
                         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 void update(Product pro) {
         Connection conn = null;
        PreparedStatement statement = null;

        try {
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/assiment?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.getnNhap());
            statement.setString(3, pro.getnBan());
            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 {
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/assiment?serverTimezone=UTC","root","");

            String sql = "delete from product where id=?";
            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 prt) {
        Connection connection = null;
        PreparedStatement statement = null;
        try {
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/assiment?serverTimezone=UTC", "root", "");

            String sql = "update product set productname=?, importproduct=?, sellday=?,hsd=?,price=? where id=?";
            statement = connection.prepareCall(sql);

            statement.setString(1, prt.getProductName());
            statement.setString(2, prt.getnNhap());
            statement.setString(3, prt.getnBan());
            statement.setString(4, prt.getHSD());
            statement.setFloat(5, prt.getPrice());
            statement.setInt(6, prt.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 productname) {
        ArrayList<Product> list = new ArrayList<>();

        Connection connection = null;
        PreparedStatement statement = null;

        try {

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

            String sql = "select * from product where productname like ?";
            statement = connection.prepareCall(sql);
            statement.setString(1, "%" + productname + "%");

            ResultSet resultset = statement.executeQuery();

            while (resultset.next()) {
                Product product = new Product(resultset.getString("productname"),
                        resultset.getString("importproduct"),
                        resultset.getString("sellday"),
                        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/assiment?serverTimezone=UTC", "root", "");

            String sql = "select * from product where (sellday = '' or sellday = ' ' or sellday = null )";
            statement = connection.prepareCall(sql);

            ResultSet resultset = statement.executeQuery();

            while (resultset.next()) {
                Product product = new Product(resultset.getString("productname"),
                        resultset.getString("importproduct"),
                        resultset.getString("sellday"),
                        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/assiment?serverTimezone=UTC", "root", "");

            String sql = "select * from product where (CURDATE() = sellday)";
            statement = connection.prepareCall(sql);

            ResultSet resultset = statement.executeQuery();

            while (resultset.next()) {
                Product product = new Product(resultset.getString("productname"),
                        resultset.getString("importproduct"),
                        resultset.getString("sellday"),
                        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/assiment?serverTimezone=UTC", "root", "");

            String sql = "select * from product where (YEARWEEK(importproduct) = YEARWEEK(sellday))";
            statement = connection.prepareCall(sql);

            ResultSet resultset = statement.executeQuery();

            while (resultset.next()) {
                Product product = new Product(resultset.getString("productname"),
                        resultset.getString("importproduct"),
                        resultset.getString("sellday"),
                        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/assiment?serverTimezone=UTC", "root", "");

            String sql = "select * from product where (MONTH(importproduct) = MONTH(sellday))";
            statement = connection.prepareCall(sql);

            ResultSet resultset = statement.executeQuery();

            while (resultset.next()) {
                Product product = new Product(resultset.getString("productname"),
                        resultset.getString("importproduct"),
                        resultset.getString("sellday"),
                        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/assiment?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("productname"),
                        resultset.getString("importproduct"),
                        resultset.getString("sellday"),
                        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/assiment?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("productname"),
                        resultset.getString("importproduct"),
                        resultset.getString("sellday"),
                        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/assiment?serverTimezone=UTC", "root", "");

            String sql = "select * from product where (sellday > 0)";
            statement = connection.prepareCall(sql);

            ResultSet resultset = statement.executeQuery();

            while (resultset.next()) {
                Product product = new Product(resultset.getString("productname"),
                        resultset.getString("importproduct"),
                        resultset.getString("sellday"),
                        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;
    }
}



/*
 * 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 java2.lesson2.main;

/**
 *
 * @author Minh
 */
public class Product {
    String ProductName, nNhap,nBan,HSD;
    float Price;
    int ProductId;

    public Product() {
    }

    public Product(String ProductName, String nNhap, String nBan, String HSD, float Price) {
        this.ProductName = ProductName;
        this.nNhap = nNhap;
        this.nBan = nBan;
        this.HSD = HSD;
        this.Price = Price;
    }

    public String getProductName() {
        return ProductName;
    }

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

    public String getnNhap() {
        return nNhap;
    }

    public void setnNhap(String nNhap) {
        this.nNhap = nNhap;
    }

    public String getnBan() {
        return nBan;
    }

    public void setnBan(String nBan) {
        this.nBan = nBan;
    }

    public String getHSD() {
        return HSD;
    }

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

    public int getProductId() {
        return ProductId;
    }

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

    public float getPrice() {
        return Price;
    }

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

    @Override
    public String toString() {
        return "Product{" + "ProductName=" + ProductName + ", nNhap=" + nNhap + ", nBan=" + nBan + ", HSD=" + HSD + ", ProductId=" + ProductId + ", Price=" + Price + '}';
    }
    
    
}



create table product (
   id int primary key auto_increment,
   productname varchar(100),
   price float default 0,
   importproduct datetime,
   sellday datetime,
   hsd datetime
)


Trần Mạnh Dũng [T1907A]

Ngày viết: 18:17 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 assignmentjavaswing;

/**
 *
 * @author admin
 */
public class Product {
    String ProductName, DayIn, DayOut, ExpiryDate;
    float Price;
    int ProductId;

    public Product() {
    }

    public Product(String ProductName, String DayIn, String DayOut, String ExpiryDate, float Price) {
        this.ProductName = ProductName;
        this.DayIn = DayIn;
        this.DayOut = DayOut;
        this.ExpiryDate = ExpiryDate;
        this.Price = Price;
       
    }

    
    

   
 
    public String getProductName() {
        return ProductName;
    }

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

    public String getDayIn() {
        return DayIn;
    }

    public void setDayIn(String DayIn) {
        this.DayIn = DayIn;
    }

    public String getDayOut() {
        return DayOut;
    }

    public void setDayOut(String DayOut) {
        this.DayOut = DayOut;
    }

    public String getExpiryDate() {
        return ExpiryDate;
    }

    public void setExpiryDate(String ExpiryDate) {
        this.ExpiryDate = ExpiryDate;
    }

    public float getPrice() {
        return Price;
    }

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

    public int getProductId() {
        return ProductId;
    }

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

    @Override
    public String toString() {
        return "Product{" + "ProductName=" + ProductName + ", DayIn=" + DayIn + ", DayOut=" + DayOut + ", ExpiryDate=" + ExpiryDate + ", 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 assignmentjavaswing;

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 admin
 */
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/assignmentjavaswing?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/assignmentjavaswing?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.getDayIn());
            statement.setString(3, pro.getDayOut());
            statement.setString(4, pro.getExpiryDate());
            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/assignmentjavaswing?serverTimezone=UTC", "root", "");

            String sql = "delete from product where id = ?";
            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/assignmentjavaswing?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.getDayIn() );
            statement.setString(3,pro.getDayOut() );
            statement.setString(4, pro.getExpiryDate());
            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/assignmentjavaswing?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/assignmentjavaswing?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/assignmentjavaswing?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/assignmentjavaswing?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/assignmentjavaswing?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/assignmentjavaswing?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/assignmentjavaswing?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/assignmentjavaswing?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;
    }
}



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

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 admin
 */
public class AssignmentJFrame extends javax.swing.JFrame {

    ArrayList<Product>list = new ArrayList<>();
    DefaultTableModel tableModel;
    productModify proModify;
    
    public AssignmentJFrame() {
        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.getDayIn(),
                product.getDayOut(),
                product.getExpiryDate(),
                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() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txttensp = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtngaynhap = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        txtngayban = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtHSD = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txtprice = new javax.swing.JTextField();
        btnadd = new javax.swing.JButton();
        btnedit = new javax.swing.JButton();
        btndelete = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblProduct = new javax.swing.JTable();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();
        jMenu3 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenuItem6 = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenuItem7 = new javax.swing.JMenuItem();
        jMenuItem8 = new javax.swing.JMenuItem();

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

        jLabel1.setText("Product's Name:");

        jLabel2.setText("Day In:");

        txtngaynhap.setText("yyyy-mm-dd");

        jLabel3.setText("Day Out");

        txtngayban.setText("yyyy-mm-dd");

        jLabel4.setText("Expiry Date:");

        txtHSD.setText("yyyy-mm-dd");
        txtHSD.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtHSDActionPerformed(evt);
            }
        });

        jLabel5.setText("Price:");

        txtprice.setText("$");

        btnadd.setText("Add");
        btnadd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnaddActionPerformed(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()
                .addGap(27, 27, 27)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5))
                .addGap(77, 77, 77)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txttensp)
                    .addComponent(txtngaynhap)
                    .addComponent(txtngayban)
                    .addComponent(txtHSD)
                    .addComponent(txtprice)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(btnadd)
                        .addGap(33, 33, 33)
                        .addComponent(btnedit)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 42, Short.MAX_VALUE)
                        .addComponent(btndelete)
                        .addGap(29, 29, 29)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .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(24, 24, 24)
                .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))
                .addGap(28, 28, 28)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(txtngayban, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(27, 27, 27)
                .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))
                .addGap(24, 24, 24)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtprice, 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(btnadd)
                    .addComponent(btnedit)
                    .addComponent(btndelete))
                .addContainerGap(31, Short.MAX_VALUE))
        );

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

            },
            new String [] {
                "Product_ID", "Product_Name", "Day In", "Day uot", "Expiry Date", "Price"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, true, false
            };

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

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

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

        jMenu3.setText("Filter");

        jMenuItem1.setText("Search Product");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem1);

        jMenuItem2.setText("Product Inventory List");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem2);

        jMenuItem3.setText("List Of Products Sold");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem3);

        jMenuItem4.setText("Products Sold During The Week");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem4);

        jMenuItem6.setText("Products Sold During The Month");
        jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem6ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem6);

        jMenuItem5.setText("Products Sold During The Day");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem5);

        jMenuItem7.setText("Still Valid");
        jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem7ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem7);

        jMenuItem8.setText("Expired");
        jMenuItem8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem8ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem8);

        jMenuBar1.add(jMenu3);

        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()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 567, 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)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

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

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

    private void jMenuItem1ActionPerformed(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.getDayIn(),
                    product.getDayOut(),
                    product.getExpiryDate(),
                    product.getPrice()});
            });
        }
        else {
            showAll();
        }
    }                                          

    private void jMenuItem2ActionPerformed(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.getDayIn(),
                    product.getDayOut(),
                    product.getExpiryDate(),
                    product.getPrice()});
            });
    }                                          

    private void jMenuItem3ActionPerformed(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.getDayIn(),
                    product.getDayOut(),
                    product.getExpiryDate(),
                    product.getPrice()});
            });
    }                                          

    private void jMenuItem4ActionPerformed(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.getDayIn(),
                    product.getDayOut(),
                    product.getExpiryDate(),
                    product.getPrice()});
            });
    }                                          

    private void jMenuItem6ActionPerformed(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.getDayIn(),
                    product.getDayOut(),
                    product.getExpiryDate(),
                    product.getPrice()});
            });
    }                                          

    private void jMenuItem5ActionPerformed(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.getDayIn(),
                    product.getDayOut(),
                    product.getExpiryDate(),
                    product.getPrice()});
            });
    }                                          

    private void jMenuItem7ActionPerformed(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.getDayIn(),
                    product.getDayOut(),
                    product.getExpiryDate(),
                    product.getPrice()});
            });
    }                                          

    private void jMenuItem8ActionPerformed(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.getDayIn(),
                    product.getDayOut(),
                    product.getExpiryDate(),
                    product.getPrice()});
            });
    }                                          

    private void btnaddActionPerformed(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.setExpiryDate(HSD);
        pr.setDayOut(sellDate);
        pr.setDayIn(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();
    }                                       

    /**
     * @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(AssignmentJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(AssignmentJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(AssignmentJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(AssignmentJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
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(AssignmentJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(AssignmentJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(AssignmentJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(AssignmentJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new AssignmentJFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton btnadd;
    private javax.swing.JButton btndelete;
    private javax.swing.JButton btnedit;
    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.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuBar jMenuBar1;
    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.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable tblProduct;
    private javax.swing.JTextField txtHSD;
    private javax.swing.JTextField txtngayban;
    private javax.swing.JTextField txtngaynhap;
    private javax.swing.JTextField txtprice;
    private javax.swing.JTextField txttensp;
    // End of variables declaration                   
}



create table product (
   id int primary key auto_increment,
   proName varchar(100),
   price float default 0,
   importDate datetime,
   sellDate datetime,
   HSD datetime
)


Tài Liệu Tham Khảo

Ứng Dụng Tiện Ích



Đã sao chép!!!