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

Examples of sg.edu.nus.iss.se07.bc.member.MemberSet


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

                                        String storekeeperName = storekeeperSet.get(i).getItem1().getValue();
                                        String storekeeperPassword = storekeeperSet.get(i).getItem2().getValue();
                                        StoreKeeper storekeeper = new StoreKeeper(storekeeperName, storekeeperPassword);
                                        String data = storekeeper.toCSVFormat(format);
                                        FileUtil.writeContents(bw, data);
                                }
                        } else {
                                throw new DataAccessException("[StoreKeeperDA::writeData]Failed to create filename " + fileName);
                        }
View Full Code Here


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

                                        if (lines.length < 1) {
                                                throw new DataAccessException("[StoreKeeperDA::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(StoreKeeperDA.class.getName()).log(Level.SEVERE, "[StoreKeeperDA::readData]Unable to read record no " + (String.valueOf(i + 1)));
                                                        throw new DataAccessException("[StoreKeeperDA::readData]Unable to read record no " + (String.valueOf(i + 1)));
                                                } else {
                                                        if (fields.length != 2) {
                                                                Logger.getLogger(StoreKeeperDA.class.getName()).log(Level.SEVERE, "[StoreKeeperDA::readData]Record no " + (String.valueOf(i + 1)) + " is corrupted");
                                                        } else {
                                                                String name = fields[0];
                                                                String password = fields[1];
                                                                if (storekeeperName.equalsIgnoreCase(name)) {
                                                                        dataObject = new StoreKeeper();
                                                                        dataObject.setStorekeeperName(name);
                                                                        dataObject.setStorekeeperPassword(password);
                                                                        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{
View Full Code Here

      String header1 = StringUtil.createFixedWidthString("Vendor Name",30);
      String header2 = StringUtil.createFixedWidthString("Description",70);
      String outputHeader = String.format(VENDOR_REPORT_FORMAT, header0,header1, header2);
      lstVendor.add(outputHeader);
      for (int i = 0; i < vendors.size(); i++) {
        Vendor vendor = vendors.get(i);
        int no = i + 1;
        String recordNo = StringUtil.createFixedWidthString(String.valueOf(no), 5);
        String vendorName = StringUtil.createFixedWidthString(vendor.getVendorName(), 30);
        String description = StringUtil.createFixedWidthString(vendor.getVendorDesc(), 70);

        String outputVendor = String.format(VENDOR_REPORT_FORMAT,
            recordNo, vendorName, description);
        // String outputVendor=String.valueOf(no)+"
        // "+vendor.getVendorName()+" "+vendor.getVendorDesc();
View Full Code Here

         *
         * @return
         * @throws sg.edu.nus.iss.se07.common.exceptions.AppException
         */
        public MemberSet readDataSet() throws AppException {
                MemberSet dataObjectSet = 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) {
                                        Logger.getLogger(MemberDA.class.getName()).log(Level.SEVERE, "[MemberDA::readDataSet]Record not found.");
                                        throw new IOException("[MemberDA::readDataSet]Record not found.");
                                } else {
                                        if (lines.length < 1) {
                                                Logger.getLogger(MemberDA.class.getName()).log(Level.SEVERE, "[MemberDA::readDataSet]Record not found.");
                                                throw new IOException("[MemberDA::readDataSet]Record not found.");
                                        }

                                        dataObjectSet = new MemberSet();
                                        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::readDataSet]Unable to read record no " + (String.valueOf(i + 1)));
                                                        throw new IOException("[MemberDA::readDataSet]Unable to read record no " + (String.valueOf(i + 1)));
                                                } else {
                                                        if (fields.length != 3) {
                                                                Logger.getLogger(MemberDA.class.getName()).log(Level.SEVERE, "[MemberDA::readDataSet]Record no " + (String.valueOf(i + 1)) + " is corrupted");
                                                        //throw new IOException("[MemberDA::readDataSet]Record no " + (String.valueOf(i + 1)) + " is corrupted");
                                                        } else {
                                                                Member member = new Member();
                                                                member.setMemberID(fields[0]);
                                                                member.setMemberName(fields[1]);
                                                                member.setMemberPoint(Integer.parseInt(fields[2]));
                                                                dataObjectSet.add(member);
                                                                member = null;
                                                        }
                                                }
                                        }
                                }
View Full Code Here

         * @param memberID
         * @return
         * @throws sg.edu.nus.iss.se07.common.exceptions.AppException
         */
        public MemberSet readDataSet(String memberID) throws AppException {
                MemberSet dataObjectSet = 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) {
                                        Logger.getLogger(MemberDA.class.getName()).log(Level.SEVERE, "[MemberDA::readDataSet]Record not found.");
                                        throw new IOException("[MemberDA::readDataSet]Record not found.");
                                } else {
                                        if (lines.length < 1) {
                                                Logger.getLogger(MemberDA.class.getName()).log(Level.SEVERE, "[MemberDA::readDataSet]Record not found.");
                                                throw new IOException("[MemberDA::readDataSet]Record not found.");
                                        }

                                        dataObjectSet = new MemberSet();
                                        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::readDataSet]Unable to read record no " + (String.valueOf(i + 1)));
                                                        throw new IOException("[MemberDA::readDataSet]Unable to read record no " + (String.valueOf(i + 1)));
                                                } else {
                                                        if (fields.length != 3) {
                                                                Logger.getLogger(MemberDA.class.getName()).log(Level.SEVERE, "[MemberDA::readDataSet]Record no " + (String.valueOf(i + 1)) + " is corrupted");
                                                        //throw new IOException("[MemberDA::readDataSet]Record no " + (String.valueOf(i + 1)) + " is corrupted");
                                                        } else {
                                                                String code = fields[0];
                                                                String name = fields[1];
                                                                if (memberID.equalsIgnoreCase(code)) {
                                                                        Member member = new Member();
                                                                        member.setMemberID(fields[0]);
                                                                        member.setMemberName(fields[1]);
                                                                        member.setMemberPoint(Integer.parseInt(fields[2]));
                                                                        dataObjectSet.add(member);
                                                                        member = null;
                                                                        i = lines.length;
                                                                }
                                                        }
                                                }
View Full Code Here

        }

        public void generateReport() {
                String reportFormat = "%1$3d\t%2$3s\t%3$s\t%4$-6d\n";
                MemberManager memberManager = null;
                MemberSet memberSet = null;
                try {
                        memberManager = new MemberManager();
                        memberSet = memberManager.list();
                        if (memberSet == null) {
                                return;
                        }
                        for (int i = 0; i < memberSet.length(); i++) {
                                System.out.format(reportFormat, (i + 1), memberSet.get(i).getMemberID(), memberSet.get(i).getMemberName(), memberSet.get(i).getMemberPoint());
                        }
                } catch (AppException ex) {
                        Logger.getLogger(CategoryRpt.class.getName()).log(Level.SEVERE, null, ex);
                } finally {
                        memberManager = null;
View Full Code Here

                                FileUtil.writeContents(bw, data);
                        } else {
                                throw new IOException("[ProductDA::writeData]Failed to create filename " + fileName);
                        }
                } catch (IOException ex) {
                        throw new DataAccessException(ex.getMessage(), ex);
                } finally {
                        try {
                                if (bw != null) {
                                        bw.close();
                                }
View Full Code Here

                                        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);
                        }
                } catch (IOException ex) {
                        throw new DataAccessException(ex.getMessage(), ex);
                } finally {
                        try {
                                if (bw != null) {
                                        bw.close();
                                }
View Full Code Here

                                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;
                                                                }
                                                        }
                                                }
                                        }
                                }
                        } else {
                                throw new DataAccessException("[ProductDA::readData]File not found.");
                        }
                } catch (IOException ex) {
                        throw new DataAccessException(ex.getMessage(), ex);
                } finally {
                        if (br != null) {
                                try {
                                        br.close();
                                } catch (IOException ex) {
View Full Code Here

TOP

Related Classes of sg.edu.nus.iss.se07.bc.member.MemberSet

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.