i added Customer name and google order number to the search feature

This commit is contained in:
2011-01-05 16:28:53 +00:00
parent d103d1a070
commit 9154fb87b9
4 changed files with 40 additions and 21 deletions

View File

@@ -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<Order>(0);
@@ -73,46 +74,64 @@ 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<Order> search(String text) {
long orderNumber = -1;
try {
orderNumber = Long.parseLong(text);
} catch (Exception e) {
// TO NOTHING
}
ArrayList<Order> list = new ArrayList<Order>();
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);
}
}
return list;
}

View File

@@ -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
*/

View File

@@ -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;

View File

@@ -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);