Package sg.edu.nus.iss.se07.bc

Examples of sg.edu.nus.iss.se07.bc.Category


                        appController = AppController.getInstance();
                        categories = appController.listCategories();
                        if (categories != null) {

                                for (int i = 0; i < categories.size(); i++) {
                                        Category item = categories.get(i);
                                        int no = i + 1;
                                        String recordNo = StringUtil.createFixedWidthString(String.valueOf(no), 5);
                                        String categoryCode = StringUtil.createFixedWidthString(item.getCategoryCode(), 30);
                                        String categoryName = StringUtil.createFixedWidthString(item.getCategoryName(), 30);
                                        String outputCategory = String.format(CategoryReport.CATEGORY_REPORT_FORMAT, recordNo, categoryCode, categoryName);
                                        lstCategory.add(outputCategory);
                                }
                        }
                } catch (AppException ex) {
View Full Code Here


                categoryList = new ArrayList<Category>();
                this.loadCategory();
                cboCategoryCode = new Choice();
                cboCategoryCode.addItem("Choose Item Category");
                for (int i = 0; i < categoryList.size(); i++) {
                        Category dataObject = categoryList.get(i);
                        cboCategoryCode.addItem(dataObject.getCategoryCode());
                }
                ItemListener itemListener = new ItemListener() {

                        public void itemStateChanged(ItemEvent e) {
                                Category category = getSelectedCategory();
                                if (category != null) {
                                        appController = AppController.getInstance();
                                        Hashtable<String, Category> categoryDataSet = DataSet.getCategoryDataSet();
                                        int sequence = 0;                                       
                                        Category dataObject = categoryDataSet.get(category.getCategoryCode());
                                        if (dataObject != null) {
                                                Enumeration<Product> enumeration = dataObject.getProducts().elements();
                                                while(enumeration.hasMoreElements()) {
                                                        Product object = enumeration.nextElement();
                                                        String id = object.getProductID();
                                                        String temp[] = StringUtil.parse(id, "/");
                                                        if (temp!=null) {                                                               
View Full Code Here

                Button b = new Button("Update");
                ActionListener l = new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                                Category category = getSelectedCategory();
                                if (category != null) {
                                        updateCategory = new UpdateCategoryDialog(mainForm, "Update Category Detail", category);
                                        updateCategory.pack();
                                        updateCategory.setVisible(true);
                                        refreshCategory();
                                }
                        }
                };
                b.addActionListener(l);
                p.add(b);

                b = new Button("Delete");
                l = new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                                category = getSelectedCategory();
                                if (category != null) {
                                        ConfirmDialog d = new ConfirmDialog(mainForm, "Delete Category", "Are you sure to delete " + category.getCategoryCode() + "?") {

                                                private static final long serialVersionUID = 1L;

                                                protected boolean performOKAction() {
                                                        boolean success = false;
                                                        try {
                                                                success = appController.removeCategory(category.getCategoryCode(), category.getCategoryName());
                                                                if (success) {
                                                                        refreshCategory();
                                                                }
                                                        } catch (AppException ex) {
                                                                Logger.getLogger(ViewCategoryPanel.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
View Full Code Here

                                String header1 = StringUtil.createFixedWidthString("Category Code", 30);
                                String header2 = StringUtil.createFixedWidthString("Category Name", 30);
                                String outputHeader = String.format(CategoryReport.CATEGORY_REPORT_FORMAT, header0, header1, header2);
                                lstCategory.add(outputHeader);
                                for (int i = 0; i < categories.size(); i++) {
                                        Category item = categories.get(i);
                                        int no = i + 1;
                                        String recordNo = StringUtil.createFixedWidthString(String.valueOf(no), 5);
                                        String categoryCode = StringUtil.createFixedWidthString(item.getCategoryCode(), 30);
                                        String categoryName = StringUtil.createFixedWidthString(item.getCategoryName(), 30);
                                        String outputCategory = String.format(CategoryReport.CATEGORY_REPORT_FORMAT, recordNo, categoryCode, categoryName);
                                        lstCategory.add(outputCategory);
                                }
                        }
                } catch (AppException ex) {
View Full Code Here

                        if (bw != null) {
                                for (int i = 0; i < categorySet.size(); i++) {

                                        String categoryCode = categorySet.get(i).getItem1().getValue();
                                        String categoryName = categorySet.get(i).getItem2().getValue();
                                        Category category = new Category(categoryCode, categoryName);
                                        String data = category.toCSVFormat(format);
                                        FileUtil.writeContents(bw, data);
                                }
                        } else {
                                throw new AppException("Failed to create filename " + fileName, "[CategoryDA::writeDataSet]", null);
                        }
View Full Code Here

         * @param categoryCode
         * @return Category records in form Array List.
         * @throws AppException
         */
        public Category readData(String categoryCode) throws AppException {
                Category dataObject = null;
                BufferedReader br = null;

                try {
                        br = FileUtil.getBufferedReader(fileName);
                        if (br != null) {
                                String contents = FileUtil.getContents(br);
                                if (contents == null) {
                                        return null;
                                }
                                String[] lines = StringUtil.parse(contents, format.getEndOfLineSymbols());
                                if (lines == null) {
                                        throw new AppException("Record not found.", "[CategoryDA::readData]", null);
                                } else {

                                        if (lines.length < 1) {
                                                throw new AppException("Record not found.", "[CategoryDA::readData]", null);
                                        }

                                        for (int i = 0; i < lines.length; i++) {
                                                String record = lines[i];
                                                String[] fields = StringUtil.parse(record, String.valueOf((char) format.getDelimiterChar()));
                                                if (fields == null) {
                                                        throw new AppException("Unable to read record no " + (String.valueOf(i + 1)), "[CategoryDA::readData]", null);
                                                } else {
                                                        if (fields.length != 2) {
                                                                Logger.getLogger(CategoryDA.class.getName()).log(Level.SEVERE, "[CategoryDA::readData]Record no " + (String.valueOf(i + 1)) + " is corrupted");
                                                        } else {
                                                                String catCode = fields[0];
                                                                String catName = fields[1];
                                                                if (catCode == null) {
                                                                        catCode = "";
                                                                }

                                                                if (catName == null) {
                                                                        catName = "";
                                                                }

                                                                if (categoryCode.equalsIgnoreCase(catCode)) {
                                                                        dataObject = new Category();
                                                                        dataObject.setCategoryCode(catCode);
                                                                        dataObject.setCategoryName(catName);
                                                                        i = lines.length;
                                                                }
                                                        }
                                                }
                                        }
View Full Code Here

* @author Isak
*/
public class TestCategory {

        public static void main(String[] args) {
                Category category1 = new Category("TEST1", "Testing 1");
                Category category2 = new Category("TEST2", "Testing 2");

                CategoryManager categoryManager = new CategoryManager();
                try {
                        categoryManager.createCategory(category1);
                } catch (DataAccessException ex) {
View Full Code Here

        }

        public boolean addCategory(String id, String name) throws AppException {
                boolean success = true;

                Category dataObject = new Category(id, name);
                CategoryManager dataObjectManager = new CategoryManager();

                try {
                        success = dataObjectManager.addCategory(dataObject);
                } catch (AppException ex) {
View Full Code Here

        public boolean updateCategory(String id, String name) throws AppException {
                boolean success = true;

                CategoryManager dataObjectManager = new CategoryManager();

                Category oldDataObject = null;
                try {
                        oldDataObject = dataObjectManager.selectCategory(id);
                } catch (AppException ex) {
                        Logger.getLogger(AppController.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
                        throw ex;
                }

                if (oldDataObject != null) {
                        Category newDataObject = new Category(id, name);
                        try {
                                success = dataObjectManager.updateCategory(oldDataObject, newDataObject);
                        } catch (AppException ex) {
                                Logger.getLogger(AppController.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
                                throw ex;
View Full Code Here

         */
        public boolean addCategory(String id, String name) throws AppException {
                boolean success = true;

                Category dataObject = new Category(id, name);
                CategoryManager dataObjectManager = new CategoryManager();

                try {
                        success = dataObjectManager.addCategory(dataObject);
                        if (success) {
                                //update cache
                                Hashtable<String, Category> categoryDataSet = DataSet.getCategoryDataSet();
                                if (categoryDataSet != null) {

View Full Code Here

TOP

Related Classes of sg.edu.nus.iss.se07.bc.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.