From 9154fb87b9c7bedbc838cdd74d902f8fad82e252 Mon Sep 17 00:00:00 2001 From: ricky barrette Date: Wed, 5 Jan 2011 16:28:53 +0000 Subject: [PATCH] i added Customer name and google order number to the search feature --- .../java/OrderProcessor/OrderDB.java | 47 +++++++++++++------ .../OrderProcessor/OrderExistsException.java | 8 ++-- .../java/OrderProcessor/UI/MainWindow.java | 2 +- .../java/OrderProcessor/UI/SearchDialog.java | 4 +- 4 files changed, 40 insertions(+), 21 deletions(-) diff --git a/Order Processor/src/com/TwentyCodes/java/OrderProcessor/OrderDB.java b/Order Processor/src/com/TwentyCodes/java/OrderProcessor/OrderDB.java index 8451df3..8e53fb7 100644 --- a/Order Processor/src/com/TwentyCodes/java/OrderProcessor/OrderDB.java +++ b/Order Processor/src/com/TwentyCodes/java/OrderProcessor/OrderDB.java @@ -1,5 +1,5 @@ /** - * @author Twenty Codess, LLC + * @author Twenty Codes, LLC * @author ricky barrette * @data Dec 18, 2010 */ @@ -15,7 +15,7 @@ import java.util.Scanner; import com.TwentyCodes.java.OrderProcessor.UI.MainWindow; /** - * This class will be a account database + * This class will be a order database */ public class OrderDB { @@ -23,7 +23,8 @@ public class OrderDB { private ProgressListener mListener; /** - * Creates a new AccountDB + * Creates a new OrderDB + * @author ricky barrette */ public OrderDB() { array = new ArrayList(0); @@ -73,45 +74,63 @@ public class OrderDB { mListener.onProgressUpdate(line++); if(MainWindow.DEBUG) - System.out.println("on line: "+ line); + System.out.println("\non line: "+ line); try { addOrder(new Order(scan.nextLine())); } catch (OrderExistsException e) { -// e.printStackTrace(); + if(MainWindow.DEBUG) + e.printStackTrace(); } catch (NumberFormatException e1){ -// e1.printStackTrace(); + if(MainWindow.DEBUG) + e1.printStackTrace(); } catch (InvalidDateFormatException e2) { -// e2.printStackTrace(); + if(MainWindow.DEBUG) + e2.printStackTrace(); } } } /** - * added the account to the database - * + * added the order to the database * @param order * @throws OrderExistsException */ public void addOrder(Order order) throws OrderExistsException { - //TODO check if order exist already + + /* + * check the current database for an orders with a matching order number + */ + for(Order item : array) + if(item.getGoogleOrderNumber() == order.getGoogleOrderNumber()) + throw new OrderExistsException(order.toString()); + array.add(order); Collections.sort(array); } /** - * returns a list of orders that pertain any information being searched for + * returns a list of orders that pertain any information being searched for. + * possible seraches include: item name, google order number, customer name * @param text * @return a list containing all possible orders * @author ricky barrette */ public ArrayList search(String text) { + long orderNumber = -1; + try { + orderNumber = Long.parseLong(text); + } catch (Exception e) { + // TO NOTHING + } ArrayList list = new ArrayList(); for(int i = 0; i < array.size(); i++){ - if(array.get(i).getItemName().equalsIgnoreCase(text)){ + if(array.get(i).getItemName().equalsIgnoreCase(text) + || (orderNumber > 0) && (array.get(i).getGoogleOrderNumber() == orderNumber) + || array.get(i).getCustomerName().contains(text)) list.add(array.get(i)); - mListener.onProgressUpdate(i); - } + + mListener.onProgressUpdate(i); } return list; } diff --git a/Order Processor/src/com/TwentyCodes/java/OrderProcessor/OrderExistsException.java b/Order Processor/src/com/TwentyCodes/java/OrderProcessor/OrderExistsException.java index 96bb4b6..6241574 100644 --- a/Order Processor/src/com/TwentyCodes/java/OrderProcessor/OrderExistsException.java +++ b/Order Processor/src/com/TwentyCodes/java/OrderProcessor/OrderExistsException.java @@ -7,7 +7,7 @@ package com.TwentyCodes.java.OrderProcessor; /** - * + * An exception that represents that there is an order with that number that already exists * @author ricky barrette */ public class OrderExistsException extends Exception { @@ -18,7 +18,7 @@ public class OrderExistsException extends Exception { private static final long serialVersionUID = 4605163237489852355L; /** - * Creates a new AccountExistsException + * Creates a new OrderExistsException * @author ricky barrette */ public OrderExistsException() { @@ -26,7 +26,7 @@ public class OrderExistsException extends Exception { } /** - * Creates a new AccountExistsException + * Creates a new OrderExistsException * @param arg0 * @author ricky barrette */ @@ -35,7 +35,7 @@ public class OrderExistsException extends Exception { } /** - * Creates a new AccountExistsException + * Creates a new OrderExistsException * @param arg0 * @author ricky barrette */ diff --git a/Order Processor/src/com/TwentyCodes/java/OrderProcessor/UI/MainWindow.java b/Order Processor/src/com/TwentyCodes/java/OrderProcessor/UI/MainWindow.java index f5018da..38a2c14 100644 --- a/Order Processor/src/com/TwentyCodes/java/OrderProcessor/UI/MainWindow.java +++ b/Order Processor/src/com/TwentyCodes/java/OrderProcessor/UI/MainWindow.java @@ -35,7 +35,7 @@ public class MainWindow extends JFrame implements ActionListener, ProgressListen private JFileChooser fc; public static OrderDB db; private static final long serialVersionUID = 1841715561053331517L; - public static final boolean DEBUG = false; + public static final boolean DEBUG = true; private JProgressBar mProgressBar; private String mCurrentFile; diff --git a/Order Processor/src/com/TwentyCodes/java/OrderProcessor/UI/SearchDialog.java b/Order Processor/src/com/TwentyCodes/java/OrderProcessor/UI/SearchDialog.java index 6748a3e..9763108 100644 --- a/Order Processor/src/com/TwentyCodes/java/OrderProcessor/UI/SearchDialog.java +++ b/Order Processor/src/com/TwentyCodes/java/OrderProcessor/UI/SearchDialog.java @@ -54,14 +54,14 @@ public class SearchDialog extends JFrame implements ActionListener, ProgressList //create a JPanel to hold the text area and button JPanel panel = new JPanel(); mOkButton = new JButton("Ok"); - JLabel label = new JLabel("Enter a Product name:"); + JLabel label = new JLabel("Enter a Product name, Customer Name, or Google Order Number:"); mOkButton.addActionListener(this); //add the JPanel to the frame, and display getContentPane().add(panel, BorderLayout.NORTH); mTextField = new JTextField(); - mTextField.setColumns(10); + mTextField.setColumns(20); mTextField.addActionListener(this); panel.add(label);