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

Phạm Ngọc Minh [T1907A]

Ngày viết: 16:35 12/04/2020



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




package Assignment;
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;

public class productModify {
    
public static ArrayList<Product> showAll() {
        ArrayList<Product> list = new ArrayList<>();
        Connection conn = null;
        Statement statement = null;
        try {
            conn = DriverManager.getConnection("jdbc:mysql://localhost/productAss?serverTimezone=UTC","root","");
            statement = conn.createStatement();
            String sql = "Select * from product" ;
            ResultSet resultset = statement.executeQuery(sql);
            while (resultset.next()) {                
                Product product = new Product(resultset.getString("proName"),
                        resultset.getString("importDate"),
                        resultset.getString("sellDate"),
                        resultset.getString("HSD"),
                        resultset.getFloat("price"));
                list.add(product);
            }
            
        } catch (SQLException ex) {
            Logger.getLogger(productModify.class.getName()).log(Level.SEVERE, null, ex);
        }finally{
            if (statement!= null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(productModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException ex) {
                    Logger.getLogger(productModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        

        return list;
    }

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

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

            String sql = "insert into product(proName,importDate,sellDate,HSD,price) values(?,Convert(?,Datetime),Convert(?,Datetime),Convert(?,Datetime),?)";
            statement = conn.prepareCall(sql);
            statement.setString(1, pro.getProductName());
            statement.setString(2, pro.getNgayNhap());
            statement.setString(3, pro.getNgayBan());
            statement.setString(4, pro.getHSD());
            statement.setFloat(5, pro.getPrice());
            statement.execute();
        } catch (SQLException ex) {
            Logger.getLogger(productModify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(productModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException ex) {
                    Logger.getLogger(productModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
    
    public static void delete(int id) {
        Connection connection = null;
        PreparedStatement statement = null;
        
        try {
            //lay tat ca danh sach sinh vien
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/productAss?serverTimezone=UTC", "root", "");

            String sql = "delete from product where ProID = ?";
            statement = connection.prepareCall(sql);
            
            statement.setInt(1, id);
            
            statement.execute();
        } catch (SQLException ex) {
            Logger.getLogger(productModify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if(statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(productModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(productModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
    public static void Edit(Product pro) {
        Connection connection = null;
        PreparedStatement statement = null;
        
        try {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        
        return list;
    }
}




package Assignment;
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;

public final class productFrame extends javax.swing.JFrame {

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

    DefaultTableModel tableModel;
    productModify productModify;

   
    public productFrame() {
        initComponents();
        tableModel = (DefaultTableModel) tblProduct.getModel();
        showall();
    }

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

    }

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

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

        jMenuItem1.setText("jMenuItem1");

        jMenuItem2.setText("jMenuItem2");

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

        jMenuItem3.setText("jMenuItem3");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

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

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

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

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

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

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

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

        jLabel4.setText("HSD : ");

        txtgia.setText("Price : ");

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

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

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

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

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

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

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

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

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

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

        jMenuItem4.setText("Search Product");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        mnFilter.add(jMenuItem4);

        jMenuItem5.setText("Product Inventory List");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        mnFilter.add(jMenuItem5);

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

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

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

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

        jMenuItem10.setText("Still Valid");
        jMenuItem10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem10ActionPerformed(evt);
            }
        });
        mnFilter.add(jMenuItem10);

        jMenuItem11.setText("Expired");
        jMenuItem11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem11ActionPerformed(evt);
            }
        });
        mnFilter.add(jMenuItem11);

        jMenuBar1.add(mnFilter);

        setJMenuBar(jMenuBar1);

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

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

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

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

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

        productModify.update(pr);

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

        showall();
    }                                         

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

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

    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        // TODO add your handling code here:
        String input = JOptionPane.showInputDialog(this, "Enter full name to search");
        if(input != null && input.length() > 0) {
            list = productModify.findByproName(input);
            
            tableModel.setRowCount(0);
        
            list.forEach((Product product) -> {
                tableModel.addRow(new Object[]{tableModel.getRowCount() + 1,
                    product.getProductName(),
                    product.getNgayNhap(),
                    product.getNgayBan(),
                    product.getHSD(),
                    product.getPrice()});
            });
        } else {
            showall();
        }
    }                                          

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

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

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

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

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

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

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

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

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

    // Variables declaration - do not modify                     
    private javax.swing.JButton btndelete;
    private javax.swing.JButton btnedit;
    private javax.swing.JButton btnupdate;
    private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItem1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem10;
    private javax.swing.JMenuItem jMenuItem11;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JMenuItem jMenuItem7;
    private javax.swing.JMenuItem jMenuItem8;
    private javax.swing.JMenuItem jMenuItem9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JMenu mnFilter;
    private javax.swing.JTable tblProduct;
    private javax.swing.JTextField txtHSD;
    private javax.swing.JTextField txtNgaynhap;
    private javax.swing.JLabel txtgia;
    private javax.swing.JTextField txtngayban;
    private javax.swing.JTextField txtprice;
    private javax.swing.JTextField txttensp;
    // End of variables declaration                   
}




package Assignment;

public class Product {
    
String  productName ,ngayNhap , ngayBan , HSD ;
    
    float price;
    int productId;

    public Product() {
    }

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

    public int getProductId() {
        return productId;
    }

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

    public String getProductName() {
        return productName;
    }

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

    public String getNgayNhap() {
        return ngayNhap;
    }

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

    public String getNgayBan() {
        return ngayBan;
    }

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

    public String getHSD() {
        return HSD;
    }

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

    public float getPrice() {
        return price;
    }

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

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


Trần Anh Quân [T1907A]

Ngày viết: 02:46 12/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 assignment;

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

    public Product() {
    }

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

    public int getProductId() {
        return productId;
    }

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

    public String getProductName() {
        return productName;
    }

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

    public String getNgayNhap() {
        return ngayNhap;
    }

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

    public String getNgayBan() {
        return ngayBan;
    }

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

    public String getHSD() {
        return HSD;
    }

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

    public float getPrice() {
        return price;
    }

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

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



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package assignment;
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 Anh Quan
 */
    
public final class productFrame extends javax.swing.JFrame {

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

    DefaultTableModel tableModel;
    productModify productModify;

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

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

    }

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

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

        jMenuItem1.setText("jMenuItem1");

        jMenuItem2.setText("jMenuItem2");

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

        jMenuItem3.setText("jMenuItem3");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

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

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

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

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

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

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

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

        jLabel4.setText("HSD : ");

        txtgia.setText("Price : ");

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

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

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

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

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

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

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

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

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

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

        jMenuItem4.setText("Search Product");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        mnFilter.add(jMenuItem4);

        jMenuItem5.setText("Product Inventory List");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        mnFilter.add(jMenuItem5);

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

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

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

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

        jMenuItem10.setText("Still Valid");
        jMenuItem10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem10ActionPerformed(evt);
            }
        });
        mnFilter.add(jMenuItem10);

        jMenuItem11.setText("Expired");
        jMenuItem11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem11ActionPerformed(evt);
            }
        });
        mnFilter.add(jMenuItem11);

        jMenuBar1.add(mnFilter);

        setJMenuBar(jMenuBar1);

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

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

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

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

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

        productModify.update(pr);

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

        showall();
    }                                         

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

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

    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        // TODO add your handling code here:
        String input = JOptionPane.showInputDialog(this, "Enter full name to search");
        if(input != null && input.length() > 0) {
            list = productModify.findByproName(input);
            
            tableModel.setRowCount(0);
        
            list.forEach((Product product) -> {
                tableModel.addRow(new Object[]{tableModel.getRowCount() + 1,
                    product.getProductName(),
                    product.getNgayNhap(),
                    product.getNgayBan(),
                    product.getHSD(),
                    product.getPrice()});
            });
        } else {
            showall();
        }
    }                                          

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

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

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

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

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

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

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

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

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

    // Variables declaration - do not modify                     
    private javax.swing.JButton btndelete;
    private javax.swing.JButton btnedit;
    private javax.swing.JButton btnupdate;
    private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItem1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem10;
    private javax.swing.JMenuItem jMenuItem11;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JMenuItem jMenuItem7;
    private javax.swing.JMenuItem jMenuItem8;
    private javax.swing.JMenuItem jMenuItem9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JMenu mnFilter;
    private javax.swing.JTable tblProduct;
    private javax.swing.JTextField txtHSD;
    private javax.swing.JTextField txtNgaynhap;
    private javax.swing.JLabel txtgia;
    private javax.swing.JTextField txtngayban;
    private javax.swing.JTextField txtprice;
    private javax.swing.JTextField txttensp;
    // End of variables declaration                   
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package assignment;
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 Anh Quan
 */
public class productModify {
    
public static ArrayList<Product> showAll() {
        ArrayList<Product> list = new ArrayList<>();
        Connection conn = null;
        Statement statement = null;
        try {
            conn = DriverManager.getConnection("jdbc:mysql://localhost/productAss?serverTimezone=UTC","root","");
            statement = conn.createStatement();
            String sql = "Select * from product" ;
            ResultSet resultset = statement.executeQuery(sql);
            while (resultset.next()) {                
                Product product = new Product(resultset.getString("proName"),
                        resultset.getString("importDate"),
                        resultset.getString("sellDate"),
                        resultset.getString("HSD"),
                        resultset.getFloat("price"));
                list.add(product);
            }
            
        } catch (SQLException ex) {
            Logger.getLogger(productModify.class.getName()).log(Level.SEVERE, null, ex);
        }finally{
            if (statement!= null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(productModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException ex) {
                    Logger.getLogger(productModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        

        return list;
    }

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

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

            String sql = "insert into product(proName,importDate,sellDate,HSD,price) values(?,Convert(?,Datetime),Convert(?,Datetime),Convert(?,Datetime),?)";
            statement = conn.prepareCall(sql);
            statement.setString(1, pro.getProductName());
            statement.setString(2, pro.getNgayNhap());
            statement.setString(3, pro.getNgayBan());
            statement.setString(4, pro.getHSD());
            statement.setFloat(5, pro.getPrice());
            statement.execute();
        } catch (SQLException ex) {
            Logger.getLogger(productModify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(productModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException ex) {
                    Logger.getLogger(productModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
    
    public static void delete(int id) {
        Connection connection = null;
        PreparedStatement statement = null;
        
        try {
            //lay tat ca danh sach sinh vien
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/productAss?serverTimezone=UTC", "root", "");

            String sql = "delete from product where ProID = ?";
            statement = connection.prepareCall(sql);
            
            statement.setInt(1, id);
            
            statement.execute();
        } catch (SQLException ex) {
            Logger.getLogger(productModify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if(statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(productModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(productModify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
    public static void Edit(Product pro) {
        Connection connection = null;
        PreparedStatement statement = null;
        
        try {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        
        return list;
    }
}



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


NguyenHuuThanh [T1907A]

Ngày viết: 11:48 10/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 newprojectjavaswing;

/**
 *
 * @author abc
 */
public class SanPham {
    String id , maDanhMuc;
    String namesp ;
    Float price;
    String inputdate,outputdate,hsd,description;
    
    public SanPham()
    {
        
    }

    public SanPham(String id, String maDanhMuc, String namesp, Float price, String inputdate, String outputdate, String hsd, String description) {
        this.id = id;
        this.maDanhMuc = maDanhMuc;
        this.namesp = namesp;
        this.price = price;
        this.inputdate = inputdate;
        this.outputdate = outputdate;
        this.hsd = hsd;
        this.description = description;
    }

    
    
    

    public String getId() {
        return id;
    }

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

    public String getMaDanhMuc() {
        return maDanhMuc;
    }

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

    public String getNamesp() {
        return namesp;
    }

    public void setNamesp(String namesp) {
        this.namesp = namesp;
    }

    public Float getPrice() {
        return price;
    }

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

    public String getInputdate() {
        return inputdate;
    }

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

    public String getOutputdate() {
        return outputdate;
    }

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

    public String getHsd() {
        return hsd;
    }

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

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }
    

    
}
/*
 * 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 newprojectjavaswing;

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

/**
 *
 * @author abc
 */
public class FormSanPham extends javax.swing.JFrame {

    DefaultTableModel tableModel;
    
    List<SanPham> sanphamlist;
    /**
     * Creates new form FormSanPham
     */
    public FormSanPham() {
        initComponents();
         tableModel = (DefaultTableModel) jTable2.getModel();
         sanphamlist = new ArrayList<>();
    }

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

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        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();
        txtIDSP = new javax.swing.JTextField();
        txtIDDanhmuc = new javax.swing.JTextField();
        txtNameSP = new javax.swing.JTextField();
        txtPrice = new javax.swing.JTextField();
        txtInputDate = new javax.swing.JTextField();
        txtOutputDate = new javax.swing.JTextField();
        txtExpiryDate = new javax.swing.JTextField();
        txtDescription = new javax.swing.JTextField();
        btnSave = new javax.swing.JButton();
        btnDelete = new javax.swing.JButton();
        btnUpdate = new javax.swing.JButton();
        btnReset = new javax.swing.JButton();
        btnfindproduct = new javax.swing.JButton();
        btnSoldProduct = new javax.swing.JButton();
        btnRemainproduct = new javax.swing.JButton();
        txtExpiredProduct = new javax.swing.JButton();
        btnGoingexpiredproduct = new javax.swing.JButton();
        btnAllProduct = new javax.swing.JButton();
        btnProductDM = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();

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

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("IDSP");

        jLabel2.setText("ID Danh mục");

        jLabel3.setText("Name SP");

        jLabel4.setText("Price");

        jLabel5.setText("InputDate");

        jLabel6.setText("OutputDate");

        jLabel7.setText("ExpiryDate");

        jLabel8.setText("Description");

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

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

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

        btnReset.setText("Reset");
        btnReset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnResetActionPerformed(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()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(24, 24, 24)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7)
                            .addComponent(jLabel8))
                        .addGap(101, 101, 101)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtDescription, javax.swing.GroupLayout.DEFAULT_SIZE, 259, Short.MAX_VALUE)
                            .addComponent(txtExpiryDate)
                            .addComponent(txtOutputDate)
                            .addComponent(txtInputDate)
                            .addComponent(txtPrice)
                            .addComponent(txtNameSP)
                            .addComponent(txtIDDanhmuc)
                            .addComponent(txtIDSP)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(44, 44, 44)
                        .addComponent(btnSave)
                        .addGap(18, 18, 18)
                        .addComponent(btnDelete)
                        .addGap(18, 18, 18)
                        .addComponent(btnUpdate)
                        .addGap(29, 29, 29)
                        .addComponent(btnReset)))
                .addContainerGap(43, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(txtIDSP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(21, 21, 21)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtIDDanhmuc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(27, 27, 27)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtNameSP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(17, 17, 17)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(17, 17, 17)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtInputDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(27, 27, 27)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(txtOutputDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(26, 26, 26)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(txtExpiryDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(24, 24, 24)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(txtDescription, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnSave)
                    .addComponent(btnDelete)
                    .addComponent(btnUpdate)
                    .addComponent(btnReset))
                .addContainerGap(45, Short.MAX_VALUE))
        );

        btnfindproduct.setText("Find product ");
        btnfindproduct.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnfindproductActionPerformed(evt);
            }
        });

        btnSoldProduct.setText("Sold product");
        btnSoldProduct.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSoldProductActionPerformed(evt);
            }
        });

        btnRemainproduct.setText("Remain product");

        txtExpiredProduct.setText("Expired Product");

        btnGoingexpiredproduct.setText("Goingtoexpired Product");

        btnAllProduct.setText("AllProduct");

        btnProductDM.setText("ProductDM");

        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(96, 96, 96)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnfindproduct)
                    .addComponent(btnSoldProduct)
                    .addComponent(btnRemainproduct)
                    .addComponent(txtExpiredProduct)
                    .addComponent(btnGoingexpiredproduct)
                    .addComponent(btnAllProduct)
                    .addComponent(btnProductDM))
                .addGap(162, 162, 162)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(70, 70, 70)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(82, 82, 82)
                        .addComponent(btnfindproduct)
                        .addGap(26, 26, 26)
                        .addComponent(btnSoldProduct)
                        .addGap(30, 30, 30)
                        .addComponent(btnRemainproduct)
                        .addGap(39, 39, 39)
                        .addComponent(txtExpiredProduct)
                        .addGap(32, 32, 32)
                        .addComponent(btnGoingexpiredproduct)
                        .addGap(38, 38, 38)
                        .addComponent(btnAllProduct)
                        .addGap(41, 41, 41)
                        .addComponent(btnProductDM)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

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

            },
            new String [] {
                "IDSP", "IDDM", "NameSP", "Price", "InputDate", "OutputDate", "ExpiryDate", "Description"
            }
        ));
        jScrollPane2.setViewportView(jTable2);

        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(421, 421, 421)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(1698, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(173, 173, 173)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 464, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 12, Short.MAX_VALUE))
        );

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

    private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        // Save
        String idsp = txtIDSP.getText();
        String idDM = txtIDDanhmuc.getText();
        String namesp = txtNameSP.getText();
        Float price = Float.parseFloat(txtPrice.getText());
        String inputDate = txtInputDate.getText();
        String outputDate = txtOutputDate.getText();
        String expiryDate = txtExpiryDate.getText();
        String description = txtDescription.getText();
        
        SanPham sp = new SanPham(idsp,idDM,namesp,price,inputDate,outputDate,expiryDate,description);
        
        showSanpham();
        
    }                                       

    private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
        // Update
        String idsp = txtIDSP.getText();
        String idDM = txtIDDanhmuc.getText();
        String namesp = txtNameSP.getText();
        Float price = Float.parseFloat(txtPrice.getText());
        String inputDate = txtInputDate.getText();
        String outputDate = txtOutputDate.getText();
        String expiryDate = txtExpiryDate.getText();
        String description = txtDescription.getText();
        
        SanPham sp = new SanPham(idsp,idDM,namesp,price,inputDate,outputDate,expiryDate,description);
        
        Sanphammodify.insert(sp);
        
        txtIDSP.setText("");
        txtIDDanhmuc.setText("");
        txtNameSP.setText("");
        txtPrice.setText("");
        txtInputDate.setText("");
        txtOutputDate.setText("");
        txtExpiryDate.setText("");
        txtDescription.setText("");
    }                                         

    private void btnResetActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        txtIDSP.setText("");
        txtIDDanhmuc.setText("");
        txtNameSP.setText("");
        txtPrice.setText("");
        txtInputDate.setText("");
        txtOutputDate.setText("");
        txtExpiryDate.setText("");
        txtDescription.setText("");
    }                                        

    private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
        // Delete
        
        int selectedIndex = jTable2.getSelectedRow();
        if( selectedIndex >= 0 )
        {
            SanPham sp = sanphamlist.get(selectedIndex);
            
            
            int option = JOptionPane.showConfirmDialog(this, "Do you want to delete this item :");
            System.out.println("option : " + option);
            
            if ( option == 0 )
            {
                Sanphammodify.delete(sp.getId());
                
                
                showSanpham();
            }
            
            
        }
    }                                         

    private void btnfindproductActionPerformed(java.awt.event.ActionEvent evt) {                                               
        // TODO add your handling code here:
        // find product
         String input = JOptionPane.showInputDialog(this, "Enter id");
        if (input.length() > 0)
        {
            sanphamlist = Sanphammodify.findById(input);
            
            sanphamlist.forEach((SanPham) -> {
            tableModel.addRow(new Object[] {tableModel.getRowCount()+ 1 , SanPham.getId(),
                SanPham.getMaDanhMuc(), SanPham.getNamesp() , SanPham.getInputdate() , SanPham.getOutputdate() , SanPham.getHsd() , SanPham.getDescription()});
        });
        }
    }                                              

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

    /**
     * @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(FormSanPham.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FormSanPham.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FormSanPham.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FormSanPham.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 FormSanPham().setVisible(true);
            }
        });
    }
    
    private void showSanpham()
    {
        sanphamlist = Sanphammodify.findAll();
        
        tableModel.setRowCount(0);
        
        sanphamlist.forEach((SanPham) -> {
            tableModel.addRow(new Object[] {tableModel.getRowCount()+ 1 , SanPham.getId(),
                SanPham.getMaDanhMuc(), SanPham.getNamesp(), SanPham.getPrice() , SanPham.getInputdate() , SanPham.getOutputdate() , SanPham.getHsd() , SanPham.getDescription()});
            
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton btnAllProduct;
    private javax.swing.JButton btnDelete;
    private javax.swing.JButton btnGoingexpiredproduct;
    private javax.swing.JButton btnProductDM;
    private javax.swing.JButton btnRemainproduct;
    private javax.swing.JButton btnReset;
    private javax.swing.JButton btnSave;
    private javax.swing.JButton btnSoldProduct;
    private javax.swing.JButton btnUpdate;
    private javax.swing.JButton btnfindproduct;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable jTable2;
    private javax.swing.JTextField txtDescription;
    private javax.swing.JButton txtExpiredProduct;
    private javax.swing.JTextField txtExpiryDate;
    private javax.swing.JTextField txtIDDanhmuc;
    private javax.swing.JTextField txtIDSP;
    private javax.swing.JTextField txtInputDate;
    private javax.swing.JTextField txtNameSP;
    private javax.swing.JTextField txtOutputDate;
    private javax.swing.JTextField txtPrice;
    // 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 javaswingjava05;

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

/**
 *
 * @author abc
 */
public class Studentmodify {
   public static List<Student> findAll() {
        List<Student> studentlist = new ArrayList<>();

        Connection connection = null;

        // an instruction that explains what should happen
        java.sql.Statement statement = null;
        try {
            // Ket noi toi database : jdbc : mysql://localhost:3306/ ten ; tai khoan + mat khau
            //muc dich lay danh sach tat ca sinh vien :
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/student04?serverTimezone=UTC", "root", "");

            //Query
            String sql = "select * from student";
            // Creates a Statement object for sending SQL statements to the database
            statement = connection.createStatement();
            // A table of data representing a database result set, which is usually generated by executing a statement that queries the database.
            ResultSet resultSet = statement.executeQuery(sql);
            // reselutSet.next() == moves the pointer of the current (ResultSet) object to the next row, from the current position
            while (resultSet.next()) {
                
                // Create a student getting from resultSet ( database ) 
                Student std = new Student(
                        resultSet.getInt("id"),
                        resultSet.getString("fullname"),
                        resultSet.getString("gender"),
                        resultSet.getString("rollno"),
                        resultSet.getString("email"),
                        resultSet.getString("address"));

                studentlist.add(std);
            }

        } catch (SQLException ex) {
            Logger.getLogger(Studentmodify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Studentmodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            // neu connection da chay , dong connection.
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Studentmodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

        return studentlist;
    }
   
   public static void update(Student std) {
        Connection connection = null;

        // for parametirized query
        PreparedStatement statement = null;
        try {
            // Ket noi toi database : jdbc : mysql://localhost:3306/ ten ; tai khoan + mat khau
            //muc dich lay danh sach tat ca sinh vien :
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/student04?serverTimezone=UTC", "root", "");

            //Query
            String sql = "update student set fullname = ?, gender = ? , rollno = ? , email = ? , address = ? where id = ?";
            
            //
            statement = connection.prepareCall(sql);
            
            statement.setString(1, std.getFullname());
            statement.setString(2, std.getGender());
            statement.setString(3, std.getRollno());
            statement.setString(4, std.getEmail());
            statement.setString(5, std.getAddress());
            statement.setInt(6, std.getId());
            
            statement.execute();
            

        } catch (SQLException ex) {
            Logger.getLogger(Studentmodify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Studentmodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            // neu connection da chay , dong connection.
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Studentmodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
     
   
   public static List<Student> findByRollno( String rollno ) {
        List<Student> studentlist = new ArrayList<>();

        Connection connection = null;

        // an instruction that explains what should happen
        PreparedStatement statement = null;
        try {
            // Ket noi toi database : jdbc : mysql://localhost:3306/ ten ; tai khoan + mat khau
            //muc dich lay danh sach tat ca sinh vien :
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/student04?serverTimezone=UTC", "root", "");

            //Query
            String sql = "select * from student WHERE rollno = ?";
            // Creates a Statement object for sending SQL statements to the database
            statement = connection.prepareCall(sql);
            
            statement.setString(1, rollno);
            
            
            // A table of data representing a database result set, which is usually generated by executing a statement that queries the database.
            ResultSet resultSet = statement.executeQuery(sql);
            // reselutSet.next() == moves the pointer of the current (ResultSet) object to the next row, from the current position
            while (resultSet.next()) {
                
                // Create a student getting from resultSet ( database ) 
                Student std = new Student(resultSet.getInt("id"),
                        resultSet.getString("fullname"),
                        resultSet.getString("gender"),
                        resultSet.getString("rollno"),
                        resultSet.getString("email"),
                        resultSet.getString("address"));
                        

                studentlist.add(std);
            }

        } catch (SQLException ex) {
            Logger.getLogger(Studentmodify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Studentmodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            // neu connection da chay , dong connection.
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Studentmodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

        return studentlist;
    }
   
   public static void insert(Student std) {
        Connection connection = null;

        // for parametirized query
        PreparedStatement statement = null;
        try {
            // Ket noi toi database : jdbc : mysql://localhost:3306/ ten ; tai khoan + mat khau
            //muc dich lay danh sach tat ca sinh vien :
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/student04?serverTimezone=UTC", "root", "");

            //Query
            String sql = "insert into student(fullname , gender , rollno , email , address) values(?,?,?,?,?)";
            //
            statement = connection.prepareCall(sql);

            statement.setString(1, std.getFullname());
            statement.setString(2, std.getGender());
            statement.setString(3, std.getRollno());
            statement.setString(4, std.getEmail());
            statement.setString(5, std.getAddress());

            statement.execute();

        } catch (SQLException ex) {
            Logger.getLogger(Studentmodify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Studentmodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            // neu connection da chay , dong connection.
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Studentmodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
}
/*
 * 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 newprojectjavaswing;

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 abc
 */
public class Sanphammodify {
    public static List<SanPham> findAll()
    {
        List<SanPham> sanphamlist = new ArrayList<>();
        Connection connection = null;
        
        Statement statement = null;
        
        
        try {
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/sanpham?serverTimezone=UTC","root","");
            
            String sql = "select * from sanpham";
            
            statement = connection.createStatement();
            
            ResultSet resultset = statement.executeQuery(sql);
            
            while(resultset.next())
            {
                SanPham sp = new SanPham(resultset.getString("id"),resultset.getString("idDM"),resultset.getString("nameSP"),resultset.getFloat("price"),resultset.getString("inputDate"),resultset.getString("outputDate"),resultset.getString("expiryDate"),resultset.getString("description"));
                
                
                sanphamlist.add(sp);
            }
        } catch (SQLException ex) {
            Logger.getLogger(Sanphammodify.class.getName()).log(Level.SEVERE, null, ex);
        }
        finally
        {
            if(connection != null)
            {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Sanphammodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if(statement != null)
            {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Sanphammodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        
        return sanphamlist;
    }
    
    public static void insert(SanPham sp) {
        Connection connection = null;

        // for parametirized query
        PreparedStatement statement = null;
        try {
            // Ket noi toi database : jdbc : mysql://localhost:3306/ ten ; tai khoan + mat khau
            //muc dich lay danh sach tat ca sinh vien :
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/sanpham?serverTimezone=UTC", "root", "");

            //Query
            String sql = "insert into sanpham(id , idDM , nameSP , price ,inputDate ,outputDate, expiryDate ,description) values(?,?,?,?,?)";
            //
            statement = connection.prepareCall(sql);

            statement.setString(1, sp.getId());
            statement.setString(2, sp.getMaDanhMuc());
            statement.setString(3, sp.getNamesp());
            statement.setFloat(4, sp.getPrice());
            statement.setString(5, sp.getInputdate());
            statement.setString(6, sp.getOutputdate());
            statement.setString(7, sp.getHsd());
            statement.setString(8, sp.getDescription());

            statement.execute();

        } catch (SQLException ex) {
            Logger.getLogger(Sanphammodify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Sanphammodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            // neu connection da chay , dong connection.
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Sanphammodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
    
     public static void update(SanPham sp) {
        Connection connection = null;

        // for parametirized query
        PreparedStatement statement = null;
        try {
            // Ket noi toi database : jdbc : mysql://localhost:3306/ ten ; tai khoan + mat khau
            //muc dich lay danh sach tat ca sinh vien :
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/sanpham?serverTimezone=UTC", "root", "");

            //Query
            String sql = "update sanpham set idDM = ? , namesp = ? , price = ? ,inputDate = ? , outputDate = ? ,expiryDate = ? , description = ? where id = ?";
            
            //
            statement = connection.prepareCall(sql);
            
            statement.setString(1, sp.getMaDanhMuc());
            statement.setString(2, sp.getNamesp());
            statement.setFloat(3, sp.getPrice());
            statement.setString(4, sp.getInputdate());
            statement.setString(5, sp.getOutputdate());
            statement.setString(6, sp.getHsd());
            statement.setString(7, sp.getDescription());
            statement.setString(8, sp.getId());
            
            
            statement.execute();
            

        } catch (SQLException ex) {
            Logger.getLogger(Sanphammodify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Sanphammodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            // neu connection da chay , dong connection.
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Sanphammodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
     
     public static void delete(String id) {
        Connection connection = null;

        // for parametirized query
        PreparedStatement statement = null;
        try {
            // Ket noi toi database : jdbc : mysql://localhost:3306/ ten ; tai khoan + mat khau
            //muc dich lay danh sach tat ca sinh vien :
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/sanpham?serverTimezone=UTC", "root", "");

            //Query
            String sql = "delete from sanpham where id = ?";
            
            //
            statement = connection.prepareCall(sql);
            
            statement.setString(1, id);
            
            statement.execute();
            

        } catch (SQLException ex) {
            Logger.getLogger(Sanphammodify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Sanphammodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            // neu connection da chay , dong connection.
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Sanphammodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
    
     
     public static List<SanPham> findById( String id ) {
        List<SanPham> sanphamlist = new ArrayList<>();

        Connection connection = null;

        // an instruction that explains what should happen
        PreparedStatement statement = null;
        try {
            // Ket noi toi database : jdbc : mysql://localhost:3306/ ten ; tai khoan + mat khau
            //muc dich lay danh sach tat ca sinh vien :
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/sanpham?serverTimezone=UTC", "root", "");

            //Query
            String sql = "select * from sanpham WHERE id = ?";
            // Creates a Statement object for sending SQL statements to the database
            statement = connection.prepareCall(sql);
            
            statement.setString(1, id);
            
            
            // A table of data representing a database result set, which is usually generated by executing a statement that queries the database.
            ResultSet resultSet = statement.executeQuery(sql);
            // reselutSet.next() == moves the pointer of the current (ResultSet) object to the next row, from the current position
            while (resultSet.next()) {
                
                // Create a student getting from resultSet ( database ) 
                SanPham sp = new SanPham(resultSet.getString("id"),
                        resultSet.getString("idDM"),
                        resultSet.getString("namesp"),
                        resultSet.getFloat("price"),
                        resultSet.getString("inputDate"),
                        resultSet.getString("outputDate"),
                        resultSet.getString("expiryDate"),
                        resultSet.getString("description"));
                        

                sanphamlist.add(sp);
            }

        } catch (SQLException ex) {
            Logger.getLogger(Sanphammodify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Sanphammodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            // neu connection da chay , dong connection.
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Sanphammodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

        return sanphamlist;
    }
}
/*
 * 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 newprojectjavaswing;

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 abc
 */
public class FormDanhMucmodify {
    public static void insert(Danhmucsanpham sp)
    {
        Connection connection = null;
        PreparedStatement statement = null;
        
        try {
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/danhmuc?serverTimezone=UTC", "root" ,"");
            
            String sql = "insert into danhmuc(idDanhMuc,nameDanhMuc) values (?,?)";
            
            statement = connection.prepareCall(sql);
            
            statement.setString(1,sp.getIdDM());
            statement.setString(2,sp.getNameDM());
            
            statement.execute();
        } catch (SQLException ex) {
            Logger.getLogger(FormDanhMuc.class.getName()).log(Level.SEVERE, null, ex);
        } finally
        {
            if (statement != null)
            {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(FormDanhMuc.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if(connection != null)
            {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(FormDanhMuc.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        
    }
    
    public static  List<Danhmucsanpham> findAll() {
        List<Danhmucsanpham> listdm = new ArrayList<>();

        Connection connection = null;

        // an instruction that explains what should happen
        Statement statement = null;
        try {
            // Ket noi toi database : jdbc : mysql://localhost:3306/ ten ; tai khoan + mat khau
            //muc dich lay danh sach tat ca sinh vien :
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/danhmuc?serverTimezone=UTC", "root", "");

            //Query
            String sql = "select * from danhmuc";
            // Creates a Statement object for sending SQL statements to the database
            statement = connection.createStatement();
            // A table of data representing a database result set, which is usually generated by executing a statement that queries the database.
            ResultSet resultSet = statement.executeQuery(sql);
            // reselutSet.next() == moves the pointer of the current (ResultSet) object to the next row, from the current position
            while (resultSet.next()) {
                
                // Create a student getting from resultSet ( database ) 
                Danhmucsanpham sp = new Danhmucsanpham(resultSet.getInt("rollNo"),resultSet.getString("idDanhMuc"), resultSet.getString("nameDanhMuc"));

                listdm.add(sp);
            }

        } catch (SQLException ex) {
            Logger.getLogger(FormDanhMucmodify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(FormDanhMucmodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            // neu connection da chay , dong connection.
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(FormDanhMucmodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

        return listdm;
    }
    
    public static void delete(int rollNo) {
        Connection connection = null;

        // for parametirized query
        PreparedStatement statement = null;
        try {
            // Ket noi toi database : jdbc : mysql://localhost:3306/ ten ; tai khoan + mat khau
            //muc dich lay danh sach tat ca sinh vien :
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/danhmuc?serverTimezone=UTC", "root", "");

            //Query
            String sql = "delete from danhmuc where rollNo = ?";
            
            //
            statement = connection.prepareCall(sql);
            
            statement.setInt(1, rollNo);
            
            statement.execute();
            

        } catch (SQLException ex) {
            Logger.getLogger(FormDanhMucmodify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(FormDanhMucmodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            // neu connection da chay , dong connection.
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(FormDanhMucmodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
    
     public static void update(Danhmucsanpham sp) {
        Connection connection = null;

        // for parametirized query
        PreparedStatement statement = null;
        try {
            // Ket noi toi database : jdbc : mysql://localhost:3306/ ten ; tai khoan + mat khau
            //muc dich lay danh sach tat ca sinh vien :
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/danhmuc?serverTimezone=UTC", "root", "");

            //Query
            String sql = "update danhmuc set idDanhmuc = ? ,nameDanhmuc = ? where rollNo = ?";
            
            //
            statement = connection.prepareCall(sql);
            
            statement.setString(1, sp.getIdDM());
            statement.setString(2, sp.getNameDM());
            statement.setInt(3, sp.getRollNo());
            
            statement.execute();
            

        } catch (SQLException ex) {
            Logger.getLogger(FormDanhMucmodify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(FormDanhMucmodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            // neu connection da chay , dong connection.
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(FormDanhMucmodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
    
    
    
    
}


NguyenHuuThanh [T1907A]

Ngày viết: 11:48 10/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 newprojectjavaswing;

/**
 *
 * @author abc
 */
public class SanPham {
    String id , maDanhMuc;
    String namesp ;
    Float price;
    String inputdate,outputdate,hsd,description;
    
    public SanPham()
    {
        
    }

    public SanPham(String id, String maDanhMuc, String namesp, Float price, String inputdate, String outputdate, String hsd, String description) {
        this.id = id;
        this.maDanhMuc = maDanhMuc;
        this.namesp = namesp;
        this.price = price;
        this.inputdate = inputdate;
        this.outputdate = outputdate;
        this.hsd = hsd;
        this.description = description;
    }

    
    
    

    public String getId() {
        return id;
    }

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

    public String getMaDanhMuc() {
        return maDanhMuc;
    }

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

    public String getNamesp() {
        return namesp;
    }

    public void setNamesp(String namesp) {
        this.namesp = namesp;
    }

    public Float getPrice() {
        return price;
    }

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

    public String getInputdate() {
        return inputdate;
    }

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

    public String getOutputdate() {
        return outputdate;
    }

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

    public String getHsd() {
        return hsd;
    }

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

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }
    

    
}
/*
 * 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 newprojectjavaswing;

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

/**
 *
 * @author abc
 */
public class FormSanPham extends javax.swing.JFrame {

    DefaultTableModel tableModel;
    
    List<SanPham> sanphamlist;
    /**
     * Creates new form FormSanPham
     */
    public FormSanPham() {
        initComponents();
         tableModel = (DefaultTableModel) jTable2.getModel();
         sanphamlist = new ArrayList<>();
    }

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

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        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();
        txtIDSP = new javax.swing.JTextField();
        txtIDDanhmuc = new javax.swing.JTextField();
        txtNameSP = new javax.swing.JTextField();
        txtPrice = new javax.swing.JTextField();
        txtInputDate = new javax.swing.JTextField();
        txtOutputDate = new javax.swing.JTextField();
        txtExpiryDate = new javax.swing.JTextField();
        txtDescription = new javax.swing.JTextField();
        btnSave = new javax.swing.JButton();
        btnDelete = new javax.swing.JButton();
        btnUpdate = new javax.swing.JButton();
        btnReset = new javax.swing.JButton();
        btnfindproduct = new javax.swing.JButton();
        btnSoldProduct = new javax.swing.JButton();
        btnRemainproduct = new javax.swing.JButton();
        txtExpiredProduct = new javax.swing.JButton();
        btnGoingexpiredproduct = new javax.swing.JButton();
        btnAllProduct = new javax.swing.JButton();
        btnProductDM = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();

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

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("IDSP");

        jLabel2.setText("ID Danh mục");

        jLabel3.setText("Name SP");

        jLabel4.setText("Price");

        jLabel5.setText("InputDate");

        jLabel6.setText("OutputDate");

        jLabel7.setText("ExpiryDate");

        jLabel8.setText("Description");

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

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

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

        btnReset.setText("Reset");
        btnReset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnResetActionPerformed(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()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(24, 24, 24)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7)
                            .addComponent(jLabel8))
                        .addGap(101, 101, 101)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtDescription, javax.swing.GroupLayout.DEFAULT_SIZE, 259, Short.MAX_VALUE)
                            .addComponent(txtExpiryDate)
                            .addComponent(txtOutputDate)
                            .addComponent(txtInputDate)
                            .addComponent(txtPrice)
                            .addComponent(txtNameSP)
                            .addComponent(txtIDDanhmuc)
                            .addComponent(txtIDSP)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(44, 44, 44)
                        .addComponent(btnSave)
                        .addGap(18, 18, 18)
                        .addComponent(btnDelete)
                        .addGap(18, 18, 18)
                        .addComponent(btnUpdate)
                        .addGap(29, 29, 29)
                        .addComponent(btnReset)))
                .addContainerGap(43, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(txtIDSP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(21, 21, 21)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtIDDanhmuc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(27, 27, 27)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtNameSP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(17, 17, 17)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(17, 17, 17)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtInputDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(27, 27, 27)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(txtOutputDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(26, 26, 26)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(txtExpiryDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(24, 24, 24)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(txtDescription, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnSave)
                    .addComponent(btnDelete)
                    .addComponent(btnUpdate)
                    .addComponent(btnReset))
                .addContainerGap(45, Short.MAX_VALUE))
        );

        btnfindproduct.setText("Find product ");
        btnfindproduct.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnfindproductActionPerformed(evt);
            }
        });

        btnSoldProduct.setText("Sold product");
        btnSoldProduct.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSoldProductActionPerformed(evt);
            }
        });

        btnRemainproduct.setText("Remain product");

        txtExpiredProduct.setText("Expired Product");

        btnGoingexpiredproduct.setText("Goingtoexpired Product");

        btnAllProduct.setText("AllProduct");

        btnProductDM.setText("ProductDM");

        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(96, 96, 96)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnfindproduct)
                    .addComponent(btnSoldProduct)
                    .addComponent(btnRemainproduct)
                    .addComponent(txtExpiredProduct)
                    .addComponent(btnGoingexpiredproduct)
                    .addComponent(btnAllProduct)
                    .addComponent(btnProductDM))
                .addGap(162, 162, 162)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(70, 70, 70)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(82, 82, 82)
                        .addComponent(btnfindproduct)
                        .addGap(26, 26, 26)
                        .addComponent(btnSoldProduct)
                        .addGap(30, 30, 30)
                        .addComponent(btnRemainproduct)
                        .addGap(39, 39, 39)
                        .addComponent(txtExpiredProduct)
                        .addGap(32, 32, 32)
                        .addComponent(btnGoingexpiredproduct)
                        .addGap(38, 38, 38)
                        .addComponent(btnAllProduct)
                        .addGap(41, 41, 41)
                        .addComponent(btnProductDM)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

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

            },
            new String [] {
                "IDSP", "IDDM", "NameSP", "Price", "InputDate", "OutputDate", "ExpiryDate", "Description"
            }
        ));
        jScrollPane2.setViewportView(jTable2);

        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(421, 421, 421)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(1698, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(173, 173, 173)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 464, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 12, Short.MAX_VALUE))
        );

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

    private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        // Save
        String idsp = txtIDSP.getText();
        String idDM = txtIDDanhmuc.getText();
        String namesp = txtNameSP.getText();
        Float price = Float.parseFloat(txtPrice.getText());
        String inputDate = txtInputDate.getText();
        String outputDate = txtOutputDate.getText();
        String expiryDate = txtExpiryDate.getText();
        String description = txtDescription.getText();
        
        SanPham sp = new SanPham(idsp,idDM,namesp,price,inputDate,outputDate,expiryDate,description);
        
        showSanpham();
        
    }                                       

    private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
        // Update
        String idsp = txtIDSP.getText();
        String idDM = txtIDDanhmuc.getText();
        String namesp = txtNameSP.getText();
        Float price = Float.parseFloat(txtPrice.getText());
        String inputDate = txtInputDate.getText();
        String outputDate = txtOutputDate.getText();
        String expiryDate = txtExpiryDate.getText();
        String description = txtDescription.getText();
        
        SanPham sp = new SanPham(idsp,idDM,namesp,price,inputDate,outputDate,expiryDate,description);
        
        Sanphammodify.insert(sp);
        
        txtIDSP.setText("");
        txtIDDanhmuc.setText("");
        txtNameSP.setText("");
        txtPrice.setText("");
        txtInputDate.setText("");
        txtOutputDate.setText("");
        txtExpiryDate.setText("");
        txtDescription.setText("");
    }                                         

    private void btnResetActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        txtIDSP.setText("");
        txtIDDanhmuc.setText("");
        txtNameSP.setText("");
        txtPrice.setText("");
        txtInputDate.setText("");
        txtOutputDate.setText("");
        txtExpiryDate.setText("");
        txtDescription.setText("");
    }                                        

    private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
        // Delete
        
        int selectedIndex = jTable2.getSelectedRow();
        if( selectedIndex >= 0 )
        {
            SanPham sp = sanphamlist.get(selectedIndex);
            
            
            int option = JOptionPane.showConfirmDialog(this, "Do you want to delete this item :");
            System.out.println("option : " + option);
            
            if ( option == 0 )
            {
                Sanphammodify.delete(sp.getId());
                
                
                showSanpham();
            }
            
            
        }
    }                                         

    private void btnfindproductActionPerformed(java.awt.event.ActionEvent evt) {                                               
        // TODO add your handling code here:
        // find product
         String input = JOptionPane.showInputDialog(this, "Enter id");
        if (input.length() > 0)
        {
            sanphamlist = Sanphammodify.findById(input);
            
            sanphamlist.forEach((SanPham) -> {
            tableModel.addRow(new Object[] {tableModel.getRowCount()+ 1 , SanPham.getId(),
                SanPham.getMaDanhMuc(), SanPham.getNamesp() , SanPham.getInputdate() , SanPham.getOutputdate() , SanPham.getHsd() , SanPham.getDescription()});
        });
        }
    }                                              

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

    /**
     * @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(FormSanPham.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FormSanPham.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FormSanPham.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FormSanPham.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 FormSanPham().setVisible(true);
            }
        });
    }
    
    private void showSanpham()
    {
        sanphamlist = Sanphammodify.findAll();
        
        tableModel.setRowCount(0);
        
        sanphamlist.forEach((SanPham) -> {
            tableModel.addRow(new Object[] {tableModel.getRowCount()+ 1 , SanPham.getId(),
                SanPham.getMaDanhMuc(), SanPham.getNamesp(), SanPham.getPrice() , SanPham.getInputdate() , SanPham.getOutputdate() , SanPham.getHsd() , SanPham.getDescription()});
            
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton btnAllProduct;
    private javax.swing.JButton btnDelete;
    private javax.swing.JButton btnGoingexpiredproduct;
    private javax.swing.JButton btnProductDM;
    private javax.swing.JButton btnRemainproduct;
    private javax.swing.JButton btnReset;
    private javax.swing.JButton btnSave;
    private javax.swing.JButton btnSoldProduct;
    private javax.swing.JButton btnUpdate;
    private javax.swing.JButton btnfindproduct;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable jTable2;
    private javax.swing.JTextField txtDescription;
    private javax.swing.JButton txtExpiredProduct;
    private javax.swing.JTextField txtExpiryDate;
    private javax.swing.JTextField txtIDDanhmuc;
    private javax.swing.JTextField txtIDSP;
    private javax.swing.JTextField txtInputDate;
    private javax.swing.JTextField txtNameSP;
    private javax.swing.JTextField txtOutputDate;
    private javax.swing.JTextField txtPrice;
    // 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 javaswingjava05;

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

/**
 *
 * @author abc
 */
public class Studentmodify {
   public static List<Student> findAll() {
        List<Student> studentlist = new ArrayList<>();

        Connection connection = null;

        // an instruction that explains what should happen
        java.sql.Statement statement = null;
        try {
            // Ket noi toi database : jdbc : mysql://localhost:3306/ ten ; tai khoan + mat khau
            //muc dich lay danh sach tat ca sinh vien :
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/student04?serverTimezone=UTC", "root", "");

            //Query
            String sql = "select * from student";
            // Creates a Statement object for sending SQL statements to the database
            statement = connection.createStatement();
            // A table of data representing a database result set, which is usually generated by executing a statement that queries the database.
            ResultSet resultSet = statement.executeQuery(sql);
            // reselutSet.next() == moves the pointer of the current (ResultSet) object to the next row, from the current position
            while (resultSet.next()) {
                
                // Create a student getting from resultSet ( database ) 
                Student std = new Student(
                        resultSet.getInt("id"),
                        resultSet.getString("fullname"),
                        resultSet.getString("gender"),
                        resultSet.getString("rollno"),
                        resultSet.getString("email"),
                        resultSet.getString("address"));

                studentlist.add(std);
            }

        } catch (SQLException ex) {
            Logger.getLogger(Studentmodify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Studentmodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            // neu connection da chay , dong connection.
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Studentmodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

        return studentlist;
    }
   
   public static void update(Student std) {
        Connection connection = null;

        // for parametirized query
        PreparedStatement statement = null;
        try {
            // Ket noi toi database : jdbc : mysql://localhost:3306/ ten ; tai khoan + mat khau
            //muc dich lay danh sach tat ca sinh vien :
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/student04?serverTimezone=UTC", "root", "");

            //Query
            String sql = "update student set fullname = ?, gender = ? , rollno = ? , email = ? , address = ? where id = ?";
            
            //
            statement = connection.prepareCall(sql);
            
            statement.setString(1, std.getFullname());
            statement.setString(2, std.getGender());
            statement.setString(3, std.getRollno());
            statement.setString(4, std.getEmail());
            statement.setString(5, std.getAddress());
            statement.setInt(6, std.getId());
            
            statement.execute();
            

        } catch (SQLException ex) {
            Logger.getLogger(Studentmodify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Studentmodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            // neu connection da chay , dong connection.
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Studentmodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
     
   
   public static List<Student> findByRollno( String rollno ) {
        List<Student> studentlist = new ArrayList<>();

        Connection connection = null;

        // an instruction that explains what should happen
        PreparedStatement statement = null;
        try {
            // Ket noi toi database : jdbc : mysql://localhost:3306/ ten ; tai khoan + mat khau
            //muc dich lay danh sach tat ca sinh vien :
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/student04?serverTimezone=UTC", "root", "");

            //Query
            String sql = "select * from student WHERE rollno = ?";
            // Creates a Statement object for sending SQL statements to the database
            statement = connection.prepareCall(sql);
            
            statement.setString(1, rollno);
            
            
            // A table of data representing a database result set, which is usually generated by executing a statement that queries the database.
            ResultSet resultSet = statement.executeQuery(sql);
            // reselutSet.next() == moves the pointer of the current (ResultSet) object to the next row, from the current position
            while (resultSet.next()) {
                
                // Create a student getting from resultSet ( database ) 
                Student std = new Student(resultSet.getInt("id"),
                        resultSet.getString("fullname"),
                        resultSet.getString("gender"),
                        resultSet.getString("rollno"),
                        resultSet.getString("email"),
                        resultSet.getString("address"));
                        

                studentlist.add(std);
            }

        } catch (SQLException ex) {
            Logger.getLogger(Studentmodify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Studentmodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            // neu connection da chay , dong connection.
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Studentmodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

        return studentlist;
    }
   
   public static void insert(Student std) {
        Connection connection = null;

        // for parametirized query
        PreparedStatement statement = null;
        try {
            // Ket noi toi database : jdbc : mysql://localhost:3306/ ten ; tai khoan + mat khau
            //muc dich lay danh sach tat ca sinh vien :
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/student04?serverTimezone=UTC", "root", "");

            //Query
            String sql = "insert into student(fullname , gender , rollno , email , address) values(?,?,?,?,?)";
            //
            statement = connection.prepareCall(sql);

            statement.setString(1, std.getFullname());
            statement.setString(2, std.getGender());
            statement.setString(3, std.getRollno());
            statement.setString(4, std.getEmail());
            statement.setString(5, std.getAddress());

            statement.execute();

        } catch (SQLException ex) {
            Logger.getLogger(Studentmodify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Studentmodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            // neu connection da chay , dong connection.
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Studentmodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
}
/*
 * 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 newprojectjavaswing;

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 abc
 */
public class Sanphammodify {
    public static List<SanPham> findAll()
    {
        List<SanPham> sanphamlist = new ArrayList<>();
        Connection connection = null;
        
        Statement statement = null;
        
        
        try {
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/sanpham?serverTimezone=UTC","root","");
            
            String sql = "select * from sanpham";
            
            statement = connection.createStatement();
            
            ResultSet resultset = statement.executeQuery(sql);
            
            while(resultset.next())
            {
                SanPham sp = new SanPham(resultset.getString("id"),resultset.getString("idDM"),resultset.getString("nameSP"),resultset.getFloat("price"),resultset.getString("inputDate"),resultset.getString("outputDate"),resultset.getString("expiryDate"),resultset.getString("description"));
                
                
                sanphamlist.add(sp);
            }
        } catch (SQLException ex) {
            Logger.getLogger(Sanphammodify.class.getName()).log(Level.SEVERE, null, ex);
        }
        finally
        {
            if(connection != null)
            {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Sanphammodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if(statement != null)
            {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Sanphammodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        
        return sanphamlist;
    }
    
    public static void insert(SanPham sp) {
        Connection connection = null;

        // for parametirized query
        PreparedStatement statement = null;
        try {
            // Ket noi toi database : jdbc : mysql://localhost:3306/ ten ; tai khoan + mat khau
            //muc dich lay danh sach tat ca sinh vien :
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/sanpham?serverTimezone=UTC", "root", "");

            //Query
            String sql = "insert into sanpham(id , idDM , nameSP , price ,inputDate ,outputDate, expiryDate ,description) values(?,?,?,?,?)";
            //
            statement = connection.prepareCall(sql);

            statement.setString(1, sp.getId());
            statement.setString(2, sp.getMaDanhMuc());
            statement.setString(3, sp.getNamesp());
            statement.setFloat(4, sp.getPrice());
            statement.setString(5, sp.getInputdate());
            statement.setString(6, sp.getOutputdate());
            statement.setString(7, sp.getHsd());
            statement.setString(8, sp.getDescription());

            statement.execute();

        } catch (SQLException ex) {
            Logger.getLogger(Sanphammodify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Sanphammodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            // neu connection da chay , dong connection.
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Sanphammodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
    
     public static void update(SanPham sp) {
        Connection connection = null;

        // for parametirized query
        PreparedStatement statement = null;
        try {
            // Ket noi toi database : jdbc : mysql://localhost:3306/ ten ; tai khoan + mat khau
            //muc dich lay danh sach tat ca sinh vien :
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/sanpham?serverTimezone=UTC", "root", "");

            //Query
            String sql = "update sanpham set idDM = ? , namesp = ? , price = ? ,inputDate = ? , outputDate = ? ,expiryDate = ? , description = ? where id = ?";
            
            //
            statement = connection.prepareCall(sql);
            
            statement.setString(1, sp.getMaDanhMuc());
            statement.setString(2, sp.getNamesp());
            statement.setFloat(3, sp.getPrice());
            statement.setString(4, sp.getInputdate());
            statement.setString(5, sp.getOutputdate());
            statement.setString(6, sp.getHsd());
            statement.setString(7, sp.getDescription());
            statement.setString(8, sp.getId());
            
            
            statement.execute();
            

        } catch (SQLException ex) {
            Logger.getLogger(Sanphammodify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Sanphammodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            // neu connection da chay , dong connection.
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Sanphammodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
     
     public static void delete(String id) {
        Connection connection = null;

        // for parametirized query
        PreparedStatement statement = null;
        try {
            // Ket noi toi database : jdbc : mysql://localhost:3306/ ten ; tai khoan + mat khau
            //muc dich lay danh sach tat ca sinh vien :
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/sanpham?serverTimezone=UTC", "root", "");

            //Query
            String sql = "delete from sanpham where id = ?";
            
            //
            statement = connection.prepareCall(sql);
            
            statement.setString(1, id);
            
            statement.execute();
            

        } catch (SQLException ex) {
            Logger.getLogger(Sanphammodify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Sanphammodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            // neu connection da chay , dong connection.
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Sanphammodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
    
     
     public static List<SanPham> findById( String id ) {
        List<SanPham> sanphamlist = new ArrayList<>();

        Connection connection = null;

        // an instruction that explains what should happen
        PreparedStatement statement = null;
        try {
            // Ket noi toi database : jdbc : mysql://localhost:3306/ ten ; tai khoan + mat khau
            //muc dich lay danh sach tat ca sinh vien :
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/sanpham?serverTimezone=UTC", "root", "");

            //Query
            String sql = "select * from sanpham WHERE id = ?";
            // Creates a Statement object for sending SQL statements to the database
            statement = connection.prepareCall(sql);
            
            statement.setString(1, id);
            
            
            // A table of data representing a database result set, which is usually generated by executing a statement that queries the database.
            ResultSet resultSet = statement.executeQuery(sql);
            // reselutSet.next() == moves the pointer of the current (ResultSet) object to the next row, from the current position
            while (resultSet.next()) {
                
                // Create a student getting from resultSet ( database ) 
                SanPham sp = new SanPham(resultSet.getString("id"),
                        resultSet.getString("idDM"),
                        resultSet.getString("namesp"),
                        resultSet.getFloat("price"),
                        resultSet.getString("inputDate"),
                        resultSet.getString("outputDate"),
                        resultSet.getString("expiryDate"),
                        resultSet.getString("description"));
                        

                sanphamlist.add(sp);
            }

        } catch (SQLException ex) {
            Logger.getLogger(Sanphammodify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Sanphammodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            // neu connection da chay , dong connection.
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Sanphammodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

        return sanphamlist;
    }
}
/*
 * 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 newprojectjavaswing;

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 abc
 */
public class FormDanhMucmodify {
    public static void insert(Danhmucsanpham sp)
    {
        Connection connection = null;
        PreparedStatement statement = null;
        
        try {
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/danhmuc?serverTimezone=UTC", "root" ,"");
            
            String sql = "insert into danhmuc(idDanhMuc,nameDanhMuc) values (?,?)";
            
            statement = connection.prepareCall(sql);
            
            statement.setString(1,sp.getIdDM());
            statement.setString(2,sp.getNameDM());
            
            statement.execute();
        } catch (SQLException ex) {
            Logger.getLogger(FormDanhMuc.class.getName()).log(Level.SEVERE, null, ex);
        } finally
        {
            if (statement != null)
            {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(FormDanhMuc.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if(connection != null)
            {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(FormDanhMuc.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        
    }
    
    public static  List<Danhmucsanpham> findAll() {
        List<Danhmucsanpham> listdm = new ArrayList<>();

        Connection connection = null;

        // an instruction that explains what should happen
        Statement statement = null;
        try {
            // Ket noi toi database : jdbc : mysql://localhost:3306/ ten ; tai khoan + mat khau
            //muc dich lay danh sach tat ca sinh vien :
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/danhmuc?serverTimezone=UTC", "root", "");

            //Query
            String sql = "select * from danhmuc";
            // Creates a Statement object for sending SQL statements to the database
            statement = connection.createStatement();
            // A table of data representing a database result set, which is usually generated by executing a statement that queries the database.
            ResultSet resultSet = statement.executeQuery(sql);
            // reselutSet.next() == moves the pointer of the current (ResultSet) object to the next row, from the current position
            while (resultSet.next()) {
                
                // Create a student getting from resultSet ( database ) 
                Danhmucsanpham sp = new Danhmucsanpham(resultSet.getInt("rollNo"),resultSet.getString("idDanhMuc"), resultSet.getString("nameDanhMuc"));

                listdm.add(sp);
            }

        } catch (SQLException ex) {
            Logger.getLogger(FormDanhMucmodify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(FormDanhMucmodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            // neu connection da chay , dong connection.
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(FormDanhMucmodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

        return listdm;
    }
    
    public static void delete(int rollNo) {
        Connection connection = null;

        // for parametirized query
        PreparedStatement statement = null;
        try {
            // Ket noi toi database : jdbc : mysql://localhost:3306/ ten ; tai khoan + mat khau
            //muc dich lay danh sach tat ca sinh vien :
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/danhmuc?serverTimezone=UTC", "root", "");

            //Query
            String sql = "delete from danhmuc where rollNo = ?";
            
            //
            statement = connection.prepareCall(sql);
            
            statement.setInt(1, rollNo);
            
            statement.execute();
            

        } catch (SQLException ex) {
            Logger.getLogger(FormDanhMucmodify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(FormDanhMucmodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            // neu connection da chay , dong connection.
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(FormDanhMucmodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
    
     public static void update(Danhmucsanpham sp) {
        Connection connection = null;

        // for parametirized query
        PreparedStatement statement = null;
        try {
            // Ket noi toi database : jdbc : mysql://localhost:3306/ ten ; tai khoan + mat khau
            //muc dich lay danh sach tat ca sinh vien :
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/danhmuc?serverTimezone=UTC", "root", "");

            //Query
            String sql = "update danhmuc set idDanhmuc = ? ,nameDanhmuc = ? where rollNo = ?";
            
            //
            statement = connection.prepareCall(sql);
            
            statement.setString(1, sp.getIdDM());
            statement.setString(2, sp.getNameDM());
            statement.setInt(3, sp.getRollNo());
            
            statement.execute();
            

        } catch (SQLException ex) {
            Logger.getLogger(FormDanhMucmodify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(FormDanhMucmodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            // neu connection da chay , dong connection.
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(FormDanhMucmodify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
    
    
    
    
}


Minh Nghia [T1907A]

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



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

import java.util.Scanner;

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

    public Product() {
    }

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

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

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

    public String getMaDM() {
        return maDM;
    }

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

    public String getTenSP() {
        return tenSP;
    }

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

    public int getId() {
        return id;
    }

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

    public int getPrice() {
        return price;
    }

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

    public int getNgayNhap() {
        return ngayNhap;
    }

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

    public int getNgayBan() {
        return ngayBan;
    }

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

    public int getHsd() {
        return hsd;
    }

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

    public String getMoTaSP() {
        return moTaSP;
    }

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

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

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



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

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

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

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

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

    private void showAll() {

    }

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

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

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

        jLabel1.setText("MaDanhMuc");

        jLabel2.setText("TenDanhMuc");

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

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

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

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

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

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

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

        jLabel8.setText("RollNo :");

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

        jTabbedPane1.addTab("ProductPortfolio", jPanel2);

        jLabel3.setText("MaSanPham");

        jLabel4.setText("MaDanhMuc");

        jLabel5.setText("TenSanPham");

        jLabel6.setText("NgayNhap");

        jLabel7.setText("Gia");

        NgayBan.setText("NgayBan");

        jLabel9.setText("HanSuDung");

        jLabel11.setText("MoTaSanPham");

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        jTabbedPane1.addTab("Product", jPanel3);

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

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

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

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

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

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


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

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

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

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

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

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

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

                showAll();
            }
        }
    }                                         

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

}



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

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

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

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

        Connection connection = null;
        Statement statement = null;

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

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

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

                if (connection != null) {

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

                }
            }
            //ket thuc.

        }
        return pList;
    }

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

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

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

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

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

                if (conn != null) {

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

                }
            }
            //ket thuc.

        }

    }

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

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

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

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

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

                if (conn != null) {

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

                }
            }
            //ket thuc.

        }

    }

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

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

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

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

                if (conn != null) {

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

                }
            }
            //ket thuc.

        }

    }

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

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

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

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

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

                if (conn != null) {

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

                }
            }
            //ket thuc.

        }
        return pList;
    }

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

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

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

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

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

                if (conn != null) {

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

                }
            }
            //ket thuc.

        }
        return pList;
    }

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

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

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

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

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

                if (conn != null) {

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

                }
            }
            //ket thuc.

        }
        return pList;
    }

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

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

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

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

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

                if (conn != null) {

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

                }
            }
            //ket thuc.

        }
        return pList;
    }

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

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

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

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

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

                if (conn != null) {

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

                }
            }
            //ket thuc.

        }
        return pList;
    }

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

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

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

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

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

                if (conn != null) {

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

                }
            }
            //ket thuc.

        }
        return pList;
    }

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

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

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

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

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

                if (conn != null) {

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

                }
            }
            //ket thuc.

        }
        return pList;
    }

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

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

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

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

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

                if (conn != null) {

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

                }
            }
            //ket thuc.

        }
        return pList;
    }
}



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

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

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



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

import java.util.Scanner;

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

    public productPortfolio() {
    }

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

    public int getId() {
        return id;
    }

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

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

    public String getTenDM() {
        return tenDM;
    }

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

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


Phân Loại Bài Viết

Tài Liệu Tham Khảo

Đã sao chép!!!