i added Customer name and google order number to the search feature
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* @author Twenty Codess, LLC
|
* @author Twenty Codes, LLC
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
* @data Dec 18, 2010
|
* @data Dec 18, 2010
|
||||||
*/
|
*/
|
||||||
@@ -15,7 +15,7 @@ import java.util.Scanner;
|
|||||||
import com.TwentyCodes.java.OrderProcessor.UI.MainWindow;
|
import com.TwentyCodes.java.OrderProcessor.UI.MainWindow;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class will be a account database
|
* This class will be a order database
|
||||||
*/
|
*/
|
||||||
public class OrderDB {
|
public class OrderDB {
|
||||||
|
|
||||||
@@ -23,7 +23,8 @@ public class OrderDB {
|
|||||||
private ProgressListener mListener;
|
private ProgressListener mListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new AccountDB
|
* Creates a new OrderDB
|
||||||
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public OrderDB() {
|
public OrderDB() {
|
||||||
array = new ArrayList<Order>(0);
|
array = new ArrayList<Order>(0);
|
||||||
@@ -73,45 +74,63 @@ public class OrderDB {
|
|||||||
mListener.onProgressUpdate(line++);
|
mListener.onProgressUpdate(line++);
|
||||||
|
|
||||||
if(MainWindow.DEBUG)
|
if(MainWindow.DEBUG)
|
||||||
System.out.println("on line: "+ line);
|
System.out.println("\non line: "+ line);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
addOrder(new Order(scan.nextLine()));
|
addOrder(new Order(scan.nextLine()));
|
||||||
} catch (OrderExistsException e) {
|
} catch (OrderExistsException e) {
|
||||||
// e.printStackTrace();
|
if(MainWindow.DEBUG)
|
||||||
|
e.printStackTrace();
|
||||||
} catch (NumberFormatException e1){
|
} catch (NumberFormatException e1){
|
||||||
// e1.printStackTrace();
|
if(MainWindow.DEBUG)
|
||||||
|
e1.printStackTrace();
|
||||||
} catch (InvalidDateFormatException e2) {
|
} catch (InvalidDateFormatException e2) {
|
||||||
// e2.printStackTrace();
|
if(MainWindow.DEBUG)
|
||||||
|
e2.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* added the account to the database
|
* added the order to the database
|
||||||
*
|
|
||||||
* @param order
|
* @param order
|
||||||
* @throws OrderExistsException
|
* @throws OrderExistsException
|
||||||
*/
|
*/
|
||||||
public void addOrder(Order 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);
|
array.add(order);
|
||||||
Collections.sort(array);
|
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
|
* @param text
|
||||||
* @return a list containing all possible orders
|
* @return a list containing all possible orders
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public ArrayList<Order> search(String text) {
|
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>();
|
ArrayList<Order> list = new ArrayList<Order>();
|
||||||
for(int i = 0; i < array.size(); i++){
|
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));
|
list.add(array.get(i));
|
||||||
mListener.onProgressUpdate(i);
|
|
||||||
}
|
mListener.onProgressUpdate(i);
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
package com.TwentyCodes.java.OrderProcessor;
|
package com.TwentyCodes.java.OrderProcessor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* An exception that represents that there is an order with that number that already exists
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public class OrderExistsException extends Exception {
|
public class OrderExistsException extends Exception {
|
||||||
@@ -18,7 +18,7 @@ public class OrderExistsException extends Exception {
|
|||||||
private static final long serialVersionUID = 4605163237489852355L;
|
private static final long serialVersionUID = 4605163237489852355L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new AccountExistsException
|
* Creates a new OrderExistsException
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public OrderExistsException() {
|
public OrderExistsException() {
|
||||||
@@ -26,7 +26,7 @@ public class OrderExistsException extends Exception {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new AccountExistsException
|
* Creates a new OrderExistsException
|
||||||
* @param arg0
|
* @param arg0
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
@@ -35,7 +35,7 @@ public class OrderExistsException extends Exception {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new AccountExistsException
|
* Creates a new OrderExistsException
|
||||||
* @param arg0
|
* @param arg0
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public class MainWindow extends JFrame implements ActionListener, ProgressListen
|
|||||||
private JFileChooser fc;
|
private JFileChooser fc;
|
||||||
public static OrderDB db;
|
public static OrderDB db;
|
||||||
private static final long serialVersionUID = 1841715561053331517L;
|
private static final long serialVersionUID = 1841715561053331517L;
|
||||||
public static final boolean DEBUG = false;
|
public static final boolean DEBUG = true;
|
||||||
private JProgressBar mProgressBar;
|
private JProgressBar mProgressBar;
|
||||||
private String mCurrentFile;
|
private String mCurrentFile;
|
||||||
|
|
||||||
|
|||||||
@@ -54,14 +54,14 @@ public class SearchDialog extends JFrame implements ActionListener, ProgressList
|
|||||||
//create a JPanel to hold the text area and button
|
//create a JPanel to hold the text area and button
|
||||||
JPanel panel = new JPanel();
|
JPanel panel = new JPanel();
|
||||||
mOkButton = new JButton("Ok");
|
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);
|
mOkButton.addActionListener(this);
|
||||||
|
|
||||||
//add the JPanel to the frame, and display
|
//add the JPanel to the frame, and display
|
||||||
getContentPane().add(panel, BorderLayout.NORTH);
|
getContentPane().add(panel, BorderLayout.NORTH);
|
||||||
|
|
||||||
mTextField = new JTextField();
|
mTextField = new JTextField();
|
||||||
mTextField.setColumns(10);
|
mTextField.setColumns(20);
|
||||||
mTextField.addActionListener(this);
|
mTextField.addActionListener(this);
|
||||||
|
|
||||||
panel.add(label);
|
panel.add(label);
|
||||||
|
|||||||
Reference in New Issue
Block a user