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

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


                        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 DataAccessException("[CategoryDA::writeData]Failed to create filename " + fileName);
                        }
View Full Code Here


         *
         * @param categoryCode
         * @return Category records in form Array List.
         */
        public Category readData(String categoryCode) throws DataAccessException {
                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 DataAccessException("[CategoryDA::readData]Record not found.");
                                } else {

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

                                        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) {
                                                        Logger.getLogger(CategoryDA.class.getName()).log(Level.SEVERE, "[CategoryDA::readData]Unable to read record no " + (String.valueOf(i + 1)));
                                                        throw new DataAccessException("[CategoryDA::readData]Unable to read record no " + (String.valueOf(i + 1)));
                                                } 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 code = fields[0];
                                                                String name = fields[1];
                                                                if (categoryCode.equalsIgnoreCase(code)) {
                                                                        dataObject = new Category();
                                                                        dataObject.setCategoryCode(code);
                                                                        dataObject.setCategoryName(name);
                                                                        i = lines.length;
                                                                }
                                                        }
                                                }
                                        }
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

                                for (int i = 0; i < memberSet.size(); i++) {

                                        String memberID = memberSet.get(i).getItem1().getValue();
                                        String memberName = memberSet.get(i).getItem2().getValue();
                                        int memberPoint = memberSet.get(i).getItem3().getValue();
                                        Member member = new Member(memberID, memberName, memberPoint);
                                        String data = member.toCSVFormat(format);
                                        FileUtil.writeContents(bw, data);
                                }
                        } else {
                                throw new DataAccessException("[MemberDA::writeData]Failed to create filename " + fileName);
                        }
View Full Code Here

         *
         * @param memberID
         * @return Member records in form Array List.
         */
        public Member readData(String memberID) throws DataAccessException {
                Member 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 DataAccessException("[MemberDA::readData]Record not found.");
                                } else {

                                        if (lines.length < 1) {
                                                throw new DataAccessException("[MemberDA::readData]Record not found.");
                                        }

                                        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) {
                                                        Logger.getLogger(MemberDA.class.getName()).log(Level.SEVERE, "[MemberDA::readData]Unable to read record no " + (String.valueOf(i + 1)));
                                                        throw new DataAccessException("[MemberDA::readData]Unable to read record no " + (String.valueOf(i + 1)));
                                                } else {
                                                        if (fields.length != 3) {
                                                                Logger.getLogger(MemberDA.class.getName()).log(Level.SEVERE, "[MemberDA::readData]Record no " + (String.valueOf(i + 1)) + " is corrupted");
                                                        } else {
                                                                //get all member value
                                                                String code = fields[0];
                                                                String name = fields[1];
                                                                int point = -1;
                                                                try {
                                                                        point = Integer.parseInt(fields[2]);
                                                                } catch (NumberFormatException nfx) {
                                                                        throw new DataAccessException(nfx.getMessage(), nfx);
                                                                }

                                                                //match
                                                                if (memberID.equalsIgnoreCase(code)) {
                                                                        dataObject = new Member();
                                                                        dataObject.setMemberID(code);
                                                                        dataObject.setMemberName(name);
                                                                        dataObject.setMemberPoint(point);
                                                                        i = lines.length;
                                                                }
                                                        }
                                                }
                                        }
View Full Code Here

                                        int productQty = productSet.get(i).getItem4().getValue();
                                        float productPrice = productSet.get(i).getItem5().getValue();
                                        String productBarcode = productSet.get(i).getItem6().getValue();
                                        int productReorderQty = productSet.get(i).getItem7().getValue();
                                        int productOrderQty = productSet.get(i).getItem8().getValue();
                                        Product product = new Product(productID, productName, productDesc, productQty, productPrice, productBarcode, productReorderQty, productOrderQty);
                                        String data = product.toCSVFormat(format);
                                        FileUtil.writeContents(bw, data);
                                }
                        } else {
                                throw new DataAccessException("[ProductDA::writeData]Failed to create filename " + fileName);
                        }
View Full Code Here

         *
         * @param productCode
         * @return Product records in form Array List.
         */
        public Product readData(String productCode) throws DataAccessException {
                Product 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 DataAccessException("[ProductDA::readData]Record not found.");
                                } else {

                                        if (lines.length < 1) {
                                                throw new DataAccessException("[ProductDA::readData]Record not found.");
                                        }

                                        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) {
                                                        Logger.getLogger(ProductDA.class.getName()).log(Level.SEVERE, "[ProductDA::readData]Unable to read record no " + (String.valueOf(i + 1)));
                                                        throw new DataAccessException("[ProductDA::readData]Unable to read record no " + (String.valueOf(i + 1)));
                                                } else {
                                                        if (fields.length != 8) {
                                                                Logger.getLogger(ProductDA.class.getName()).log(Level.SEVERE, "[ProductDA::readData]Record no " + (String.valueOf(i + 1)) + " is corrupted");
                                                        } else {
                                                                String id = fields[0];
                                                                String name = fields[1];
                                                                String desc = fields[2];

                                                                int qty = -1;
                                                                try {
                                                                        qty = Integer.parseInt(fields[3]);
                                                                } catch (NumberFormatException nfx) {
                                                                        throw new DataAccessException(nfx.getMessage(), nfx);
                                                                }

                                                                float price = 0f;
                                                                try {
                                                                        price = Float.parseFloat(fields[4]);
                                                                } catch (NumberFormatException nfx) {
                                                                        throw new DataAccessException(nfx.getMessage(), nfx);
                                                                }

                                                                String barcode = fields[5];

                                                                int reorderQty = -1;
                                                                try {
                                                                        reorderQty = Integer.parseInt(fields[6]);
                                                                } catch (NumberFormatException nfx) {
                                                                        throw new DataAccessException(nfx.getMessage(), nfx);
                                                                }

                                                                int orderQty = -1;
                                                                try {
                                                                        orderQty = Integer.parseInt(fields[7]);
                                                                } catch (NumberFormatException nfx) {
                                                                        throw new DataAccessException(nfx.getMessage(), nfx);
                                                                }


                                                                if (productCode.equalsIgnoreCase(id)) {
                                                                        dataObject = new Product();
                                                                        dataObject.setProductID(id);
                                                                        dataObject.setProductName(name);
                                                                        dataObject.setProductDescription(desc);
                                                                        dataObject.setQuantityAvailable(qty);
                                                                        dataObject.setProductPrice(price);
                                                                        dataObject.setBarcodeNumber(barcode);
                                                                        dataObject.setReorderQuantity(reorderQty);
                                                                        dataObject.setOrderQuantity(orderQty);
                                                                        i = lines.length;
                                                                }
                                                        }
                                                }
                                        }
View Full Code Here

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

                        public void actionPerformed(ActionEvent e) {
                          Vendor v=getSelectedVendor();
                          final Product product=getSelectedProduct();
                          if(v!=null){

                            String ConfirmMessage="Are you sure to order this "+product.getProductName()+" from "+v.getVendorName()+"with $"+ product.getProductPrice()+"\n and "+product.getOrderQuantity() ;
                            ConfirmDialog d=new ConfirmDialog(mainForm,"Order Confirmation",ConfirmMessage){

                  protected boolean performOKAction() {
                    boolean success=false;
                    try{
                     
                    if(appController.increaseProductQty(product.getProductID(),product.getReorderQuantity())==true){
                      String Message=product.getProductName()+"with $"+ product.getProductPrice()+" and "+product.getReorderQuantity()+ "\n has been ordered successfully.";
                      MessageDialog m=new MessageDialog(mainForm,"Ordering Product Successfully",Message);
                      m.setVisible(true);
                      refreshProductListPanel();
                      lstVendor.removeAll();
                      success=true;
View Full Code Here

                lstPanelProduct = new List(10);
                ItemListener l =new ItemListener(){

          public void itemStateChanged(ItemEvent e) {
       
            Product p=getSelectedProduct();
            if (p != null) {
              refreshVendorList(p);
            }
            else
            {
               MessageDialog m = new MessageDialog(mainForm, "Please select a product", "Please select a product to proceed deleting.");
                            m.setResizable(false);
                            m.setVisible(true);
                            refreshProductListPanel();
            }
          }
                 
                };
                lstPanelProduct.addItemListener(l);
                lstPanelProduct.setMultipleMode(false);
                lstPanelProduct.setFont(new Font("Courier", Font.BOLD, 14));

                p.add("North", lblProduct);
                p.add("Center", lstPanelProduct);
                this.refreshProductListPanel();
                return p;
        }
View Full Code Here

TOP

Related Classes of sg.edu.nus.iss.se07.bc.Product

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.