i updated the search to allow for time variables
This commit is contained in:
@@ -23,6 +23,7 @@ import java.util.Collections;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
import com.TwentyCodes.java.OrderProcessor.Date;
|
||||||
import com.TwentyCodes.java.OrderProcessor.InvalidDateFormatException;
|
import com.TwentyCodes.java.OrderProcessor.InvalidDateFormatException;
|
||||||
import com.TwentyCodes.java.OrderProcessor.Main;
|
import com.TwentyCodes.java.OrderProcessor.Main;
|
||||||
import com.TwentyCodes.java.OrderProcessor.Order;
|
import com.TwentyCodes.java.OrderProcessor.Order;
|
||||||
@@ -246,4 +247,27 @@ public class OrderDB {
|
|||||||
|
|
||||||
saveOrder(order);
|
saveOrder(order);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Searches for a specific string in between specific dates
|
||||||
|
* @param search string to search for
|
||||||
|
* @param start date
|
||||||
|
* @param end date
|
||||||
|
* @return list of orders that meet requirements
|
||||||
|
* @throws SQLException
|
||||||
|
* @throws IOException
|
||||||
|
* @throws ClassNotFoundException
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public ArrayList<Order> search(String search, Date start, Date end) throws SQLException, IOException, ClassNotFoundException {
|
||||||
|
ArrayList<Order> prelist = search(search);
|
||||||
|
ArrayList<Order> list = new ArrayList<Order>();
|
||||||
|
|
||||||
|
for(Order item : prelist){
|
||||||
|
if(start.compareTo(item.getOrderCreationDate()) != 1)
|
||||||
|
if(end.compareTo(item.getOrderCreationDate()) != -1)
|
||||||
|
list.add(item);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,7 @@ public class Date implements Comparable<Date>, Serializable{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new Date from a string.
|
* Creates a new Date from a string.
|
||||||
* The string format will be 2010-12-30 22:24:08
|
* The string format will be 'YYYY-MM-DD HH:MM:SS' example: '2010-12-30 22:24:08'
|
||||||
* @param time
|
* @param time
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
* @throws InvalidDateFormatException
|
* @throws InvalidDateFormatException
|
||||||
@@ -80,6 +80,9 @@ public class Date implements Comparable<Date>, Serializable{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(Date date) {
|
public int compareTo(Date date) {
|
||||||
|
// if(Main.DEBUG)
|
||||||
|
// System.out.println("compareTo: "+ this.toString() +" to "+ date.toString());
|
||||||
|
|
||||||
if(this.mYear != date.getYear())
|
if(this.mYear != date.getYear())
|
||||||
return this.mYear > date.getYear() ? 1 : -1;
|
return this.mYear > date.getYear() ? 1 : -1;
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -1,158 +0,0 @@
|
|||||||
/**
|
|
||||||
* @author Twenty Codes, LLC
|
|
||||||
* @author ricky barrette
|
|
||||||
* @data Dec 18, 2010
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.TwentyCodes.java.OrderProcessor;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class will be a order database
|
|
||||||
*/
|
|
||||||
public class OrderDB {
|
|
||||||
|
|
||||||
private ArrayList<Order> array;
|
|
||||||
private ProgressListener mListener;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new OrderDB
|
|
||||||
* @author ricky barrette
|
|
||||||
*/
|
|
||||||
public OrderDB() {
|
|
||||||
array = new ArrayList<Order>(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* returns a human readable string (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see java.lang.Object#toString()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
StringBuffer sb = new StringBuffer();
|
|
||||||
for (Order item : array)
|
|
||||||
sb.append(item.toString() + "\n");
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * saves the database to a text file
|
|
||||||
// * @param file to be saved to
|
|
||||||
// * @author ricky barrette
|
|
||||||
// * @throws IOException
|
|
||||||
// */
|
|
||||||
// public void save(File file) throws IOException{
|
|
||||||
// StringBuffer sb = new StringBuffer();
|
|
||||||
// for(Order item : array)
|
|
||||||
// sb.append(item.getBalance()+","+item.getOwner()+","+item.getAccount()+"\n");
|
|
||||||
// FileOutputStream theFile = new FileOutputStream(file);
|
|
||||||
// theFile.write(sb.toString().getBytes());
|
|
||||||
// theFile.flush();
|
|
||||||
// theFile.close();
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* loads the orders from the specified order
|
|
||||||
* @param file to be parsed
|
|
||||||
* @throws FileNotFoundException
|
|
||||||
* @author ricky barrette
|
|
||||||
*/
|
|
||||||
public void load(File file) throws FileNotFoundException{
|
|
||||||
Scanner scan = new Scanner(file);
|
|
||||||
int line = 1;
|
|
||||||
while(scan.hasNextLine()){
|
|
||||||
|
|
||||||
if(mListener != null)
|
|
||||||
mListener.onProgressUpdate(line++);
|
|
||||||
|
|
||||||
if(Main.DEBUG)
|
|
||||||
System.out.println("\non line: "+ line);
|
|
||||||
|
|
||||||
try {
|
|
||||||
addOrder(new Order(scan.nextLine()));
|
|
||||||
} catch (OrderExistsException e) {
|
|
||||||
if(Main.DEBUG)
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (NumberFormatException e1){
|
|
||||||
if(Main.DEBUG)
|
|
||||||
e1.printStackTrace();
|
|
||||||
} catch (InvalidDateFormatException e2) {
|
|
||||||
if(Main.DEBUG)
|
|
||||||
e2.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* added the order to the database
|
|
||||||
* @param order
|
|
||||||
* @throws OrderExistsException
|
|
||||||
*/
|
|
||||||
public void addOrder(Order order) throws OrderExistsException {
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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.
|
|
||||||
* 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)
|
|
||||||
|| (orderNumber > 0) && (array.get(i).getGoogleOrderNumber() == orderNumber)
|
|
||||||
|| array.get(i).getCustomerName().toLowerCase(Locale.ENGLISH).contains(text.toLowerCase(Locale.ENGLISH)))
|
|
||||||
list.add(array.get(i));
|
|
||||||
|
|
||||||
if(mListener != null)
|
|
||||||
mListener.onProgressUpdate(i);
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* sets a listener for db progress updates
|
|
||||||
* @param listener
|
|
||||||
* @author ricky barrette
|
|
||||||
*/
|
|
||||||
public void setOnProgressListerner(ProgressListener listener) {
|
|
||||||
mListener = listener;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* returns the size of the data base
|
|
||||||
* @return
|
|
||||||
* @author ricky barrette
|
|
||||||
*/
|
|
||||||
public int getSize() {
|
|
||||||
return array.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -21,6 +21,8 @@ import javax.swing.JTextField;
|
|||||||
import javax.swing.LayoutStyle.ComponentPlacement;
|
import javax.swing.LayoutStyle.ComponentPlacement;
|
||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
|
|
||||||
|
import com.TwentyCodes.java.OrderProcessor.Date;
|
||||||
|
import com.TwentyCodes.java.OrderProcessor.InvalidDateFormatException;
|
||||||
import com.TwentyCodes.java.OrderProcessor.Months;
|
import com.TwentyCodes.java.OrderProcessor.Months;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -47,8 +49,9 @@ public class GetStatsDialog extends JFrame implements ActionListener {
|
|||||||
private JRadioButton mOct;
|
private JRadioButton mOct;
|
||||||
private JTextField textField;
|
private JTextField textField;
|
||||||
private JButton mOkButton;
|
private JButton mOkButton;
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private Months mTimeFrame = Months.JAN;
|
private Months mTimeFrame = Months.JAN;
|
||||||
|
private Date mStartDate;
|
||||||
|
private Date mEndDate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the frame.
|
* Create the frame.
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* @author Twenty Codes, LLC
|
* Search.java
|
||||||
|
* @date Jan 9, 2011
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
* @data Dec 18, 2010
|
* @author Twenty Codes, LLC
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.TwentyCodes.java.OrderProcessor.UI;
|
package com.TwentyCodes.java.OrderProcessor.UI;
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
@@ -20,12 +20,15 @@ import javax.swing.JPanel;
|
|||||||
import javax.swing.JProgressBar;
|
import javax.swing.JProgressBar;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
|
|
||||||
|
import com.TwentyCodes.java.OrderProcessor.Date;
|
||||||
|
import com.TwentyCodes.java.OrderProcessor.InvalidDateFormatException;
|
||||||
import com.TwentyCodes.java.OrderProcessor.Main;
|
import com.TwentyCodes.java.OrderProcessor.Main;
|
||||||
import com.TwentyCodes.java.OrderProcessor.Order;
|
import com.TwentyCodes.java.OrderProcessor.Order;
|
||||||
import com.TwentyCodes.java.OrderProcessor.ProgressListener;
|
import com.TwentyCodes.java.OrderProcessor.ProgressListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class will be the dialog that will ask the user for a specific make to show
|
* This class will be the dialog that will ask the user for a specific make to show
|
||||||
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public class SearchDialog extends JFrame implements ActionListener, ProgressListener {
|
public class SearchDialog extends JFrame implements ActionListener, ProgressListener {
|
||||||
|
|
||||||
@@ -36,37 +39,54 @@ public class SearchDialog extends JFrame implements ActionListener, ProgressList
|
|||||||
private boolean isProcessing = false;
|
private boolean isProcessing = false;
|
||||||
private int mListSize;
|
private int mListSize;
|
||||||
private OrderPane mOrderPanel;
|
private OrderPane mOrderPanel;
|
||||||
|
private JTextField mStartDateField;
|
||||||
|
private JTextField mEndDateField;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new ShowAllMakeDialog
|
* Creates a new ShowAllMakeDialog
|
||||||
*/
|
*/
|
||||||
public SearchDialog() {
|
public SearchDialog() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
setTitle("Search");
|
setTitle("Search");
|
||||||
|
|
||||||
//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");
|
|
||||||
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
|
//add the JPanel to the frame, and display
|
||||||
getContentPane().add(panel, BorderLayout.NORTH);
|
getContentPane().add(panel, BorderLayout.NORTH);
|
||||||
|
|
||||||
mOrderPanel = new OrderPane();
|
//search string
|
||||||
this.getContentPane().add(mOrderPanel, BorderLayout.CENTER);
|
panel.add(new JLabel("Enter a Product name, Customer Name, or Google Order Number:"));
|
||||||
|
|
||||||
mTextField = new JTextField();
|
mTextField = new JTextField();
|
||||||
mTextField.setColumns(20);
|
mTextField.setColumns(20);
|
||||||
mTextField.addActionListener(this);
|
mTextField.addActionListener(this);
|
||||||
|
|
||||||
panel.add(label);
|
|
||||||
panel.add(mTextField);
|
panel.add(mTextField);
|
||||||
|
|
||||||
|
//start date
|
||||||
|
panel.add(new JLabel("Start Date:"));
|
||||||
|
mStartDateField = new JTextField();
|
||||||
|
panel.add(mStartDateField);
|
||||||
|
mStartDateField.setColumns(12);
|
||||||
|
|
||||||
|
//end date
|
||||||
|
panel.add(new JLabel("End Date:"));
|
||||||
|
mEndDateField = new JTextField();
|
||||||
|
panel.add(mEndDateField);
|
||||||
|
mEndDateField.setColumns(12);
|
||||||
|
|
||||||
|
//ok button
|
||||||
|
mOkButton = new JButton("Ok");
|
||||||
|
mOkButton.addActionListener(this);
|
||||||
panel.add(mOkButton);
|
panel.add(mOkButton);
|
||||||
|
|
||||||
|
//progress bar
|
||||||
mProgressBar = new JProgressBar();
|
mProgressBar = new JProgressBar();
|
||||||
getContentPane().add(mProgressBar, BorderLayout.SOUTH);
|
getContentPane().add(mProgressBar, BorderLayout.SOUTH);
|
||||||
|
|
||||||
|
//output orderpane
|
||||||
|
mOrderPanel = new OrderPane();
|
||||||
|
this.getContentPane().add(mOrderPanel, BorderLayout.CENTER);
|
||||||
|
|
||||||
pack();
|
pack();
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
@@ -74,15 +94,26 @@ public class SearchDialog extends JFrame implements ActionListener, ProgressList
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* called when the enter button is pressed when the mTextFieeld is focused, or when the ok button is clicked
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if(! mStartDateField.getText().isEmpty() && !mEndDateField.getText().isEmpty())
|
||||||
|
try {
|
||||||
|
preformSearch(mTextField.getText(), new Date("\""+mStartDateField.getText()+"\""), new Date("\""+mEndDateField.getText()+"\""));
|
||||||
|
} catch (InvalidDateFormatException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
preformSearch(mTextField.getText(), null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void preformSearch(final String search, final Date start, final Date end) {
|
||||||
java.util.concurrent.Executors.newSingleThreadExecutor().submit(new Runnable() {
|
java.util.concurrent.Executors.newSingleThreadExecutor().submit(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
mProgressBar.setString("Searching for: "+mTextField.getText());
|
mProgressBar.setString("Searching for: "+search);
|
||||||
mProgressBar.setStringPainted(true);
|
mProgressBar.setStringPainted(true);
|
||||||
try {
|
try {
|
||||||
mProgressBar.setMaximum(MainWindow.db.getCount());
|
mProgressBar.setMaximum(MainWindow.db.getCount());
|
||||||
@@ -93,7 +124,12 @@ public class SearchDialog extends JFrame implements ActionListener, ProgressList
|
|||||||
|
|
||||||
ArrayList<Order> list = null;
|
ArrayList<Order> list = null;
|
||||||
try {
|
try {
|
||||||
list = MainWindow.db.search(mTextField.getText());
|
if((start != null) && (end != null)){
|
||||||
|
list = MainWindow.db.search(search, start, end);
|
||||||
|
} else{
|
||||||
|
list = MainWindow.db.search(search);
|
||||||
|
}
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -117,12 +153,8 @@ public class SearchDialog extends JFrame implements ActionListener, ProgressList
|
|||||||
pack();
|
pack();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* called by MainWindow.db on progress update, or internally from this window to update the progress bar
|
* called by MainWindow.db on progress update, or internally from this window to update the progress bar
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
@@ -141,7 +173,11 @@ public class SearchDialog extends JFrame implements ActionListener, ProgressList
|
|||||||
}
|
}
|
||||||
if(isProcessing){
|
if(isProcessing){
|
||||||
mProgressBar.setString("Processing Order: "+ mListSize +" of "+ progress);
|
mProgressBar.setString("Processing Order: "+ mListSize +" of "+ progress);
|
||||||
// mProgressBar.setValue(progress + MainWindow.db.getSize()+1);
|
try {
|
||||||
|
mProgressBar.setValue(progress + MainWindow.db.getCount());
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
} else
|
} else
|
||||||
mProgressBar.setValue(progress);
|
mProgressBar.setValue(progress);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user