Package com.charitas.model

Examples of com.charitas.model.Category


        //List<Product> list = new ArrayList<>();
       
        Product prod = null;
        if (resultSet.next()){
           
            Category cat  = new Category();
            cat.setId(resultSet.getInt("category_id"));
            cat.setName(resultSet.getString("category_name"));
           
            prod = new Product();
            prod.setCategory(cat);
            prod.setDescription(resultSet.getString("description"));
            prod.setExpiredDate(resultSet.getDate("expireddate"));
View Full Code Here


       
        PreparedStatement statement = connection.prepareStatement(sql);
        ResultSet result = statement.executeQuery();
        List<Product> list = new ArrayList<Product>();
        while (result.next()){
            Category cat = new Category();
            cat.setId(result.getInt("category_id"));
            cat.setName(result.getString("category_name"));
           
            Product prod = new Product();
            prod.setCategory(cat);
            prod.setDescription(result.getString("description"));
            prod.setPrice(result.getDouble("price"));
View Full Code Here

    public static void main(String[] args) {
        try {
            ProductDAO productDAO = new ProductDAOImpl(DatabaseConnection.getInstance().getConnection());
            Calendar cal = Calendar.getInstance();
           
            Category cat1 = new Category();
            cat1.setId(1);
           
            Product prod1 =new Product();
            prod1.setCategory(cat1);
            prod1.setDescription("tes prod");
            prod1.setExpiredDate(cal.getTime());
            prod1.setName("permen");
            prod1.setPrice(7500);
            productDAO.save(prod1);
                   
            Product product = new Product();
            List<Product> allData = productDAO.findAll();
           
            for(int i = 0; i < allData.size(); i++ ){
                Category cat = new Category();
               
                product = allData.get(i);
                cat = product.getCategory();
                       
                System.out.println("Id produk = " + product.getId() + "  " + product.getName() + "  " + cat.getId()+ "  " + cat.getName());
            }
            /*
            try {       
                CategoryDAO categoryDAO = new CategoryDAOImpl(DatabaseConnection.getInstance().getConnection());
               
View Full Code Here

        int row = categories == null ? 0 : categories.size() );
        int col = 2;
        Object[][] data = new Object[row][col];
       
        for(int i = 0 ; categories != null && i < categories.size(); i++ ){
            Category category = categories.get(i);
            data[i][0] = category.getId();
            data[i][1] = category.getName();
        }
        String[] columnName = {"Id", "Name"};
       
        //TableModel tabelModel = new DefaultTableModel(data, columnName);
        TableModel tableModel = new CustomeTabelModel(data, columnName);
View Full Code Here

            dialog = new  DialogCategory(SwingUtil.getParentJFrame(this),true);
        }
        dialog.setVisible(true);
        if (dialog.getMode() == DialogCategory.SAVE_MODE ){
            try {
                Category  category = dialog.getCategory();
                categoryDAO.save(category);
            } catch (SQLException ex) {
                Logger.getLogger(InternalFrameCategory.class.getName()).log(Level.SEVERE, null, ex);
                JOptionPane.showMessageDialog(this, ex.getMessage(),"SQl exception",JOptionPane.ERROR_MESSAGE );
            }
View Full Code Here

                dialog = new DialogCategory(SwingUtil.getParentJFrame(this), true);
            }
           
            int id = ( Integer ) TableCategory.getValueAt(TableCategory.getSelectedRow(), 0);
           
            Category category=null;
            try {
            category = categoryDAO.findById(id);
               
            } catch (SQLException ex) {
                Logger.getLogger(InternalFrameCategory.class.getName()).log(Level.SEVERE, null, ex);
            }
            dialog.setCategory(category);
            dialog.setVisible(true);
           
            if ( dialog.getMode() == DialogCategory.SAVE_MODE ){
                //category = dialog.getCategory();
                dialog.packData();
                try {
                   
                    categoryDAO.update(category.getId(), category);
                } catch (SQLException ex) {
                    Logger.getLogger(InternalFrameCategory.class.getName()).log(Level.SEVERE, null, ex);
                    JOptionPane.showMessageDialog(this, "error " +  ex.getMessage(), "sql exception", JOptionPane.ERROR_MESSAGE);
                }
               
View Full Code Here

    /**
     * pack data = memindahkan text ke Class catg
     */
    public void packData(){
        if (category == null) {
            category = new Category();
        }
        category.setName(TxtName.getText());
    }
View Full Code Here

    public Category findById(int i) throws SQLException {
        String sql ="select * from category where category_id = ? ";
        PreparedStatement statement = connection.prepareStatement(sql);
        statement.setInt(1, i);
        ResultSet result = statement.executeQuery();
        Category cat = new Category();
        if ( result.next() ){           
            cat.setId(result.getInt("category_id") );
            cat.setName(result.getString("name") );
        }
        return cat;
    }
View Full Code Here

    @Override
    public List<Category> findAll() throws SQLException {
        String sql = "Select * from category ";
        PreparedStatement statement = connection.prepareStatement(sql);
        ResultSet result = statement.executeQuery();
        Category cat ;
        List<Category> list = new ArrayList<Category>();
        while (result.next() ){
            cat = new Category();
            cat.setId(result.getInt("category_id")  );
            cat.setName(result.getString("name")  );
            list.add (cat);
        }               
        return list ;
    }
View Full Code Here

    public List<Category> findByName(String name) throws SQLException {
        String sql ="select * from category where name = ? ";
        PreparedStatement statement = connection.prepareStatement(sql);
        ResultSet result = statement.executeQuery();
       
        Category cat;
        List<Category> list = new ArrayList<Category>();
        while (result.next()){
            cat = new Category();
            cat.setId(result.getInt("category_id"));
            cat.setName(result.getString("name"));
            list.add(cat);
        }
        return list;
    }
View Full Code Here

TOP

Related Classes of com.charitas.model.Category

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.