reorg
13
OrderProcessor/.classpath
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="version infomation"/>
|
||||
<classpathentry kind="src" path="images"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="lib" path="lib/jcalendar-1.3.3.jar"/>
|
||||
<classpathentry kind="lib" path="lib/ostermillerutils_1_07_00.jar"/>
|
||||
<classpathentry kind="lib" path="lib/mysql-connector-java-5.1.14-bin.jar"/>
|
||||
<classpathentry kind="lib" path="lib/sqlitejdbc-v056.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jasypt-1.7.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
9
OrderProcessor/.orderprocessor.properties
Normal file
@@ -0,0 +1,9 @@
|
||||
#---Order Processor Settings---
|
||||
#Sat Jan 29 09:08:26 EST 2011
|
||||
server_parrword=ghHagtj3wfMjx/hHetKlFmvfd9ho54c4
|
||||
database_name=Orders
|
||||
save_password=false
|
||||
server_location=tcdevsvn1
|
||||
use_remote_server=false
|
||||
server_port_number=3306
|
||||
server_user_name=ricky.barrette
|
||||
17
OrderProcessor/.project
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Order Processor</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
12
OrderProcessor/.settings/org.eclipse.jdt.core.prefs
Normal file
@@ -0,0 +1,12 @@
|
||||
#Sun Nov 21 20:19:35 EST 2010
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.6
|
||||
BIN
OrderProcessor/images/accept.png
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
OrderProcessor/images/calendar_date.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
OrderProcessor/images/database.png
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
OrderProcessor/images/database_accept.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
OrderProcessor/images/database_add.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
OrderProcessor/images/database_down.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
OrderProcessor/images/database_lock.png
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
OrderProcessor/images/database_next.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
OrderProcessor/images/database_previous.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
OrderProcessor/images/database_process.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
OrderProcessor/images/database_remove.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
OrderProcessor/images/database_search.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
OrderProcessor/images/database_up.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
OrderProcessor/images/floppy_disc.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
OrderProcessor/images/info.png
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
OrderProcessor/images/page.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
OrderProcessor/images/page_process.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
OrderProcessor/images/process.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
OrderProcessor/images/remove.png
Normal file
|
After Width: | Height: | Size: 2.1 KiB |
BIN
OrderProcessor/images/repeat.png
Normal file
|
After Width: | Height: | Size: 2.1 KiB |
BIN
OrderProcessor/lib/jasypt-1.7.jar
Normal file
BIN
OrderProcessor/lib/jcalendar-1.3.3.jar
Normal file
BIN
OrderProcessor/lib/mysql-connector-java-5.1.14-bin.jar
Normal file
BIN
OrderProcessor/lib/ostermillerutils_1_07_00.jar
Normal file
BIN
OrderProcessor/lib/sqlitejdbc-v056.jar
Normal file
@@ -0,0 +1,486 @@
|
||||
/**
|
||||
* OrderDB.java
|
||||
* @date Jan 8, 2011
|
||||
* @author ricky barrette
|
||||
* @author Twenty Codes, LLC
|
||||
*/
|
||||
package com.TwentyCodes.java.OrderProcessor.DB;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.net.SocketException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jasypt.util.text.BasicTextEncryptor;
|
||||
|
||||
import com.Ostermiller.util.CSVParser;
|
||||
import com.TwentyCodes.java.OrderProcessor.Date;
|
||||
import com.TwentyCodes.java.OrderProcessor.InvalidDateFormatException;
|
||||
import com.TwentyCodes.java.OrderProcessor.Main;
|
||||
import com.TwentyCodes.java.OrderProcessor.Order;
|
||||
import com.TwentyCodes.java.OrderProcessor.OrderExistsException;
|
||||
import com.TwentyCodes.java.OrderProcessor.ProgressListener;
|
||||
import com.TwentyCodes.java.OrderProcessor.Status;
|
||||
import com.TwentyCodes.java.OrderProcessor.UI.SettingsPanel;
|
||||
|
||||
/**
|
||||
* An SQLite Order Data Base
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public class OrderDB {
|
||||
|
||||
public final static String PASSWORD = "askjdhfui2ywpordhewpfiy2390uriyfu230rhuiyhew8fu293hro9yqewrfup9u34bh0yf3-eqwjf9834-fjud9i-he9-fhuj830uewfh";
|
||||
private final String CREATE_TABLE = "CREATE TABLE Orders (id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, item blob);";
|
||||
private final String CREATE_TABLE_LOCAL = "CREATE TABLE Orders (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 'item' blob);";
|
||||
private final String INSERT = "insert into Orders (item) values (?);";
|
||||
private ProgressListener mListener;
|
||||
private PreparedStatement prep;
|
||||
private String dbLocation;
|
||||
private boolean isLoadingFile = false;
|
||||
private ArrayList<Order> list;
|
||||
private boolean isUsingRemoteDatabase;
|
||||
|
||||
/**
|
||||
* Creates a new OrderDB
|
||||
* @throws ClassNotFoundException
|
||||
* @throws SQLException
|
||||
* @throws SocketException
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public OrderDB() throws ClassNotFoundException, SQLException, SocketException {
|
||||
|
||||
Properties props = getProperties();
|
||||
|
||||
isUsingRemoteDatabase = Boolean.parseBoolean(props.getProperty(SettingsPanel.IS_USING_REMOTE_SERVER, "false"));
|
||||
|
||||
if(isUsingRemoteDatabase) {
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
}
|
||||
else {
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
dbLocation = System.getProperty("user.home") +"/.TwentyCodesOrders";
|
||||
}
|
||||
|
||||
Connection conn = getConnection();
|
||||
|
||||
Statement stat = conn.createStatement();
|
||||
|
||||
// stat.executeUpdate("drop table if exists Orders;");
|
||||
try {
|
||||
if(isUsingRemoteDatabase)
|
||||
stat.executeUpdate(CREATE_TABLE);
|
||||
else
|
||||
stat.executeUpdate(CREATE_TABLE_LOCAL);
|
||||
} catch (SQLException e) {
|
||||
//most likely the table already exist
|
||||
e.printStackTrace();
|
||||
}
|
||||
conn.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new OrderDB
|
||||
* @param password for the database
|
||||
* @throws ClassNotFoundException
|
||||
* @throws SQLException
|
||||
* @throws SocketException
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public OrderDB(String password) throws ClassNotFoundException, SQLException, SocketException {
|
||||
|
||||
Properties props = getProperties();
|
||||
|
||||
isUsingRemoteDatabase = Boolean.parseBoolean(props.getProperty(SettingsPanel.IS_USING_REMOTE_SERVER, "false"));
|
||||
|
||||
if(isUsingRemoteDatabase) {
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
}
|
||||
else {
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
dbLocation = System.getProperty("user.home") +"/.TwentyCodesOrders";
|
||||
}
|
||||
|
||||
Connection conn = getConnection(password);
|
||||
|
||||
Statement stat = conn.createStatement();
|
||||
|
||||
// stat.executeUpdate("drop table if exists Orders;");
|
||||
try {
|
||||
if(isUsingRemoteDatabase)
|
||||
stat.executeUpdate(CREATE_TABLE);
|
||||
else
|
||||
stat.executeUpdate(CREATE_TABLE_LOCAL);
|
||||
} catch (SQLException e) {
|
||||
//most likely the table already exist
|
||||
e.printStackTrace();
|
||||
}
|
||||
conn.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* added the order to the database
|
||||
* @param order
|
||||
* @throws OrderExistsException
|
||||
* @throws ClassNotFoundException
|
||||
* @throws IOException
|
||||
* @throws SQLException
|
||||
*/
|
||||
public void addOrder(Order order) throws OrderExistsException, SQLException, IOException, ClassNotFoundException {
|
||||
|
||||
/*
|
||||
* check the current database for an orders with a matching order number
|
||||
*/
|
||||
for(Order item : list)
|
||||
|
||||
if(item.getGoogleOrderNumber() == order.getGoogleOrderNumber())
|
||||
if(item.getFulfillmentStatus() == Status.NEW )
|
||||
deleteOrder(item);
|
||||
else
|
||||
throw new OrderExistsException(order.toString());
|
||||
|
||||
list.add(order);
|
||||
|
||||
saveOrder(order);
|
||||
}
|
||||
|
||||
/**
|
||||
* counts the number of lines in a csv file
|
||||
* @param file to be read
|
||||
* @return number of lines in a file
|
||||
* @throws IOException
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public int countLines(File file) throws IOException {
|
||||
int cnt = 1;
|
||||
CSVParser csvParser = new CSVParser(new FileInputStream(file));
|
||||
while(csvParser.getLine() != null)
|
||||
cnt++;
|
||||
return cnt;
|
||||
}
|
||||
|
||||
/**
|
||||
* deletes the old order that IS BEING replaced
|
||||
* @throws SQLException
|
||||
* @throws IOException
|
||||
* @throws ClassNotFoundException
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private void deleteOrder(Order order) throws SQLException, IOException, ClassNotFoundException{
|
||||
int row = 1;
|
||||
int count = getCount();
|
||||
|
||||
Connection conn = getConnection();
|
||||
ResultSet rs = getOrders(conn);
|
||||
|
||||
ByteArrayInputStream bais;
|
||||
ObjectInputStream ins;
|
||||
Order item;
|
||||
while (rs.next()) {
|
||||
|
||||
if(mListener != null)
|
||||
mListener.onProgressUpdate("Deleting old Order", false, row++, count);
|
||||
bais = new ByteArrayInputStream(rs.getBytes("item"));
|
||||
ins = new ObjectInputStream(bais);
|
||||
item = (Order) ins.readObject();
|
||||
|
||||
if (order.getGoogleOrderNumber() == item.getGoogleOrderNumber()){
|
||||
conn.createStatement().execute("DELETE FROM Orders WHERE id="+rs.getInt("id")+";");
|
||||
System.out.println("deleting "+ item.toString());
|
||||
}
|
||||
ins.close();
|
||||
}
|
||||
rs.close();
|
||||
conn.close();
|
||||
|
||||
if(mListener != null)
|
||||
mListener.onProgressUpdate("Done", false, 1, 1);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* gets all orders from the database
|
||||
* @return a list of orders
|
||||
* @throws SQLException
|
||||
* @throws IOException
|
||||
* @throws ClassNotFoundException
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public ArrayList<Order> getAllOrders() throws SQLException, IOException, ClassNotFoundException {
|
||||
|
||||
int row = 1;
|
||||
int count = getCount();
|
||||
|
||||
Connection conn = getConnection();
|
||||
ResultSet rs = getOrders(conn);
|
||||
|
||||
ArrayList<Order> list = new ArrayList<Order>();
|
||||
|
||||
ByteArrayInputStream bais;
|
||||
ObjectInputStream ins;
|
||||
while (rs.next()) {
|
||||
if(mListener != null && ! isLoadingFile)
|
||||
mListener.onProgressUpdate("Getting All Orders", false, row++, count);
|
||||
bais = new ByteArrayInputStream(rs.getBytes("item"));
|
||||
ins = new ObjectInputStream(bais);
|
||||
list.add((Order) ins.readObject());
|
||||
ins.close();
|
||||
}
|
||||
rs.close();
|
||||
conn.close();
|
||||
Collections.sort(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all orders from the database
|
||||
* @param conn to database
|
||||
* @return ResultSet containing all orders
|
||||
* @throws SocketException
|
||||
* @throws SQLException
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private ResultSet getOrders(Connection conn) throws SocketException, SQLException {
|
||||
Statement stat = conn.createStatement();
|
||||
return stat.executeQuery("select * from Orders;");
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the connection to the data base
|
||||
* @return
|
||||
* @throws SQLException
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private Connection getConnection() throws SQLException, SocketException{
|
||||
Properties props = getProperties();
|
||||
BasicTextEncryptor passwordEncryptor = new BasicTextEncryptor();
|
||||
passwordEncryptor.setPassword(PASSWORD);
|
||||
|
||||
if(isUsingRemoteDatabase)
|
||||
return getConnection(passwordEncryptor.decrypt(props.getProperty(SettingsPanel.SERVER_PASSWORD)));
|
||||
else
|
||||
return DriverManager.getConnection("jdbc:sqlite:"+ dbLocation+".db");
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the connection to the database
|
||||
* @param password users password for the database
|
||||
* @return connection
|
||||
* @throws SQLException
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private Connection getConnection(String password) throws SQLException {
|
||||
Properties props = getProperties();
|
||||
|
||||
String url = "jdbc:mysql://"+props.getProperty(SettingsPanel.SERVER_LOCATION)+":"+props.getProperty(SettingsPanel.SERVER_PORT_NUMBER, "3306")+"/"+props.getProperty(SettingsPanel.DATABASE_NAME,"Orders");
|
||||
|
||||
if(props.getProperty(SettingsPanel.SERVER_USERNAME).length() > 0)
|
||||
url += "?user="+ props.getProperty(SettingsPanel.SERVER_USERNAME);
|
||||
|
||||
if(password.length() > 0)
|
||||
url += "&password="+ password;
|
||||
|
||||
return DriverManager.getConnection(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the row count
|
||||
* @return number orders in the database
|
||||
* @throws SQLException
|
||||
* @author ricky barrette
|
||||
* @throws SocketException
|
||||
*/
|
||||
public int getCount() throws SQLException, SocketException{
|
||||
int count = -1;
|
||||
Connection conn = getConnection();
|
||||
ResultSet rs = conn.createStatement().executeQuery("select COUNT(*) from Orders;");
|
||||
|
||||
if(rs.next())
|
||||
count = rs.getInt(1);
|
||||
conn.close();
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the properties from the properties file
|
||||
* @return properties
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private Properties getProperties() {
|
||||
Properties props = new java.util.Properties();
|
||||
try {
|
||||
FileInputStream in = new FileInputStream(SettingsPanel.PROPERTIES_FILE_NAME);
|
||||
props.load(in);
|
||||
in.close();
|
||||
return props;
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
return props;
|
||||
}
|
||||
|
||||
/**
|
||||
* loads the orders from the specified *.CSV file
|
||||
* @param file to be parsed
|
||||
* @author ricky barrette
|
||||
* @throws SQLException
|
||||
* @throws IOException
|
||||
* @throws ClassNotFoundException
|
||||
* @throws OrderExistsException
|
||||
*/
|
||||
public void load(File file) throws SQLException, IOException, ClassNotFoundException{
|
||||
|
||||
prep = null;
|
||||
list = null;
|
||||
|
||||
CSVParser csvParser = new CSVParser(new FileInputStream(file));
|
||||
list = new ArrayList<Order>(getAllOrders());
|
||||
|
||||
int line = 1;
|
||||
int lineCount = countLines(file);
|
||||
isLoadingFile = true;
|
||||
|
||||
Connection conn = getConnection();
|
||||
prep = conn.prepareStatement(INSERT);
|
||||
conn.setAutoCommit(true);
|
||||
try {
|
||||
while (csvParser.lastLineNumber() < lineCount) {
|
||||
|
||||
if (mListener != null)
|
||||
mListener.onProgressUpdate(file.toString() + " ~ Parsing Order: "+ line +" of "+ lineCount, false, line++, lineCount);
|
||||
|
||||
if (Main.DEBUG)
|
||||
System.out.println("\non line: " + line);
|
||||
|
||||
try {
|
||||
addOrder(new Order(csvParser.getLine()));
|
||||
} catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
} catch (OrderExistsException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidDateFormatException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
prep.close();
|
||||
conn.close();
|
||||
isLoadingFile = false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* saves an order to the database
|
||||
* @param order
|
||||
* @throws IOException
|
||||
* @throws SQLException
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private void saveOrder(Order order) throws IOException, SQLException {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(bos);
|
||||
|
||||
oos.writeObject(order);
|
||||
oos.flush();
|
||||
oos.close();
|
||||
bos.close();
|
||||
|
||||
prep.setBytes(1, bos.toByteArray());
|
||||
prep.executeUpdate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 isExclusive true if the search is excluding the string
|
||||
* @return an array list containing all orders meeting search criteria
|
||||
* @throws SQLException
|
||||
* @throws IOException
|
||||
* @throws ClassNotFoundException
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public ArrayList<Order> search(String text, boolean isExclusive) throws SQLException, IOException, ClassNotFoundException {
|
||||
long orderNumber = -1;
|
||||
try {
|
||||
orderNumber = Long.parseLong(text);
|
||||
} catch (Exception e) {
|
||||
// TO NOTHING
|
||||
}
|
||||
int row = 1;
|
||||
int count = getCount();
|
||||
|
||||
ArrayList<Order> list = new ArrayList<Order>();
|
||||
String[] parts = text.split(", ");
|
||||
|
||||
for(Order order : getAllOrders()){
|
||||
if(mListener != null && ! isLoadingFile)
|
||||
mListener.onProgressUpdate("Searching for: "+text, false, row++, count);
|
||||
|
||||
for (int i = 0; i < parts.length; i++) {
|
||||
if (isExclusive) {
|
||||
if (!order.getItemName().equalsIgnoreCase(parts[i]))
|
||||
list.add(order);
|
||||
} else if (order.getItemName().equalsIgnoreCase(parts[i])
|
||||
|| (orderNumber > 0)
|
||||
&& (order.getGoogleOrderNumber() == orderNumber)
|
||||
|| order.getCustomerName().toLowerCase(Locale.ENGLISH).contains(parts[i].toLowerCase(Locale.ENGLISH))
|
||||
|| order.getCustomerContry().toLowerCase(Locale.ENGLISH).contains(parts[i].toLowerCase(Locale.ENGLISH)))
|
||||
list.add(order);
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for a specific string in between specific dates
|
||||
* @param search string to search for
|
||||
* @param start date
|
||||
* @param end date
|
||||
* @param isExclusive true if the search is excluding the string
|
||||
* @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, boolean isExclusive) throws SQLException, IOException, ClassNotFoundException {
|
||||
ArrayList<Order> prelist = search(search, isExclusive);
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets a listener for db progress updates
|
||||
* @param listener
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void setOnProgressListerner(ProgressListener listener) {
|
||||
mListener = listener;
|
||||
}
|
||||
}
|
||||
141
OrderProcessor/src/com/TwentyCodes/java/OrderProcessor/Date.java
Normal file
@@ -0,0 +1,141 @@
|
||||
/**
|
||||
* Date.java
|
||||
* @date Jan 2, 2011
|
||||
* @author ricky barrette
|
||||
* @author Twenty Codes, LLC
|
||||
*/
|
||||
package com.TwentyCodes.java.OrderProcessor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* A Date object that represents a specific date and time
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public class Date implements Comparable<Date>, Serializable{
|
||||
|
||||
private static final long serialVersionUID = 5691938526283433531L;
|
||||
private byte mHour;
|
||||
private byte mMinute;
|
||||
private byte mSecond;
|
||||
private byte mMonth;
|
||||
private byte mDay;
|
||||
private int mYear;
|
||||
|
||||
/**
|
||||
* Creates a new Date from a string.
|
||||
* The string format will be 'YYYY-MM-DD HH:MM:SS' example: '2010-12-30 22:24:08'
|
||||
* @param time
|
||||
* @author ricky barrette
|
||||
* @throws InvalidDateFormatException
|
||||
*/
|
||||
public Date(String newDate) throws InvalidDateFormatException {
|
||||
String[] parts = newDate.split(" ");
|
||||
String[] date = parts[0].split("-");
|
||||
String[] time = parts[1].split(":");
|
||||
try {
|
||||
this.mYear = Integer.parseInt(date[0]);
|
||||
this.mDay = Byte.parseByte(date[2]);
|
||||
this.mMonth = Byte.parseByte(date[1]);
|
||||
this.mHour = Byte.parseByte(time[0]);
|
||||
this.mMinute = Byte.parseByte(time[1]);
|
||||
this.mSecond = Byte.parseByte(time[2]);
|
||||
} catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
throw new InvalidDateFormatException(newDate);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a human readable string that reprensts this object
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@Override
|
||||
public String toString(){
|
||||
return this.mHour +":"+ this.mMinute +":"+ this.mSecond +" "+ this.mMonth +"-"+ this.mDay +"-"+ this.mYear;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int compareTo(Date date) {
|
||||
// if(Main.DEBUG)
|
||||
// System.out.println("compareTo: "+ this.toString() +" to "+ date.toString());
|
||||
|
||||
if(this.mYear != date.getYear())
|
||||
return this.mYear > date.getYear() ? 1 : -1;
|
||||
else
|
||||
if(this.mMonth != date.getMonth())
|
||||
return this.mMonth > date.getMonth() ? 1 : -1;
|
||||
else
|
||||
if(this.mDay != date.getDay())
|
||||
return this.mDay > date.getDay() ? 1 : -1;
|
||||
else
|
||||
if(this.mHour != date.getHour())
|
||||
return this.mHour > date.getHour() ? 1 : -1;
|
||||
else
|
||||
if(this.mMinute != date.getMinute())
|
||||
return this.mMinute > date.getMinute() ? 1 : -1;
|
||||
else
|
||||
if(this.mSecond != date.getSecond())
|
||||
return this.mSecond > date.getSecond() ? 1 : -1;
|
||||
else
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* getter for second
|
||||
* @return seconds
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public byte getSecond() {
|
||||
return this.mSecond;
|
||||
}
|
||||
|
||||
/**
|
||||
* getter for minutes
|
||||
* @return minutes
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public byte getMinute() {
|
||||
return this.mMinute;
|
||||
}
|
||||
|
||||
/**
|
||||
* getter for hours
|
||||
* @return hours
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public byte getHour() {
|
||||
return this.mHour;
|
||||
}
|
||||
|
||||
/**
|
||||
* getter for day
|
||||
* @return day
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public byte getDay() {
|
||||
return this.mDay;
|
||||
}
|
||||
|
||||
/**
|
||||
* getter for month
|
||||
* @return month
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public byte getMonth() {
|
||||
return this.mMonth;
|
||||
}
|
||||
|
||||
/**
|
||||
* getter for year
|
||||
* @return year
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public int getYear() {
|
||||
return this.mYear;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* DatePickerInterface.java
|
||||
* @date Jan 10, 2011
|
||||
* @author ricky barrette
|
||||
* @author Twenty Codes, LLC
|
||||
*/
|
||||
package com.TwentyCodes.java.OrderProcessor;
|
||||
|
||||
|
||||
/**
|
||||
* the interface for the DatePicker
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public interface DatePickerListener {
|
||||
|
||||
public void onDatePicked(int resultCode, Date date);
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* FileFilter.java
|
||||
* @date Jan 7, 2011
|
||||
* @author ricky barrette
|
||||
* @author Twenty Codes, LLC
|
||||
*/
|
||||
package com.TwentyCodes.java.OrderProcessor;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* A file filter for the JFilechooser
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public class FileFilter extends javax.swing.filechooser.FileFilter {
|
||||
|
||||
public final static String csv = "csv";
|
||||
|
||||
/**
|
||||
* (non-Javadoc)
|
||||
* @see javax.swing.filechooser.FileFilter#accept(java.io.File)
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@Override
|
||||
public boolean accept(File f) {
|
||||
if (f.isDirectory()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String extension = getExtension(f);
|
||||
if (extension != null) {
|
||||
if (extension.equals(csv)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-Javadoc)
|
||||
* @see javax.swing.filechooser.FileFilter#getDescription()
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Google Checkout CSV files";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the extension of a file
|
||||
* @param f file
|
||||
* @return file's extension
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private String getExtension(File f) {
|
||||
String ext = null;
|
||||
String s = f.getName();
|
||||
int i = s.lastIndexOf('.');
|
||||
|
||||
if (i > 0 && i < s.length() - 1) {
|
||||
ext = s.substring(i+1).toLowerCase();
|
||||
}
|
||||
return ext;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* InvalidDateFormatException.java
|
||||
* @date Jan 2, 2011
|
||||
* @author ricky barrette
|
||||
* @author Twenty Codes, LLC
|
||||
*/
|
||||
package com.TwentyCodes.java.OrderProcessor;
|
||||
|
||||
/**
|
||||
* A InvalidDateFormatException is an exception that represents the string for a Date was not formated properly
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public class InvalidDateFormatException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 5169762604232405408L;
|
||||
|
||||
/**
|
||||
* Creates a new InvalidDateFormatException
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public InvalidDateFormatException() {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new InvalidDateFormatException
|
||||
* @param message
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public InvalidDateFormatException(String message) {
|
||||
super(message);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new InvalidDateFormatException
|
||||
* @param cause
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public InvalidDateFormatException(Throwable cause) {
|
||||
super(cause);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new InvalidDateFormatException
|
||||
* @param message
|
||||
* @param cause
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public InvalidDateFormatException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Main.java
|
||||
* @date Jan 6, 2011
|
||||
* @author ricky barrette
|
||||
* @author Twenty Codes, LLC
|
||||
*/
|
||||
package com.TwentyCodes.java.OrderProcessor;
|
||||
|
||||
import com.TwentyCodes.java.OrderProcessor.UI.MainWindow;
|
||||
|
||||
/**
|
||||
* Main class
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public class Main {
|
||||
|
||||
|
||||
public static final boolean DEBUG = true;
|
||||
|
||||
/**
|
||||
* called when the application first starts
|
||||
* @param args
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
new MainWindow();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Months.java
|
||||
* @date Jan 2, 2011
|
||||
* @author ricky barrette
|
||||
* @author Twenty Codes, LLC
|
||||
*/
|
||||
package com.TwentyCodes.java.OrderProcessor;
|
||||
|
||||
/**
|
||||
* represents a time of year
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public enum Months {
|
||||
|
||||
JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC, YEAR,
|
||||
|
||||
}
|
||||
@@ -0,0 +1,309 @@
|
||||
/**
|
||||
* @author Twenty Codes, LLC
|
||||
* @author ricky barrette
|
||||
* @date Nov 21, 2010
|
||||
*/
|
||||
|
||||
package com.TwentyCodes.java.OrderProcessor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
/**
|
||||
* This class will represent a single order
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public class Order implements Comparable<Order>, Serializable{
|
||||
|
||||
private static final long serialVersionUID = 810485062967800884L;
|
||||
private String mItemName;
|
||||
private long mGoogleOrderNumber;
|
||||
private Date mOrderCreationDate;
|
||||
private float mOrderAmount;
|
||||
private float mAmountCharged;
|
||||
private Status mFinancialStatus;
|
||||
private Status mFulfillmentStatus;
|
||||
private String mCustomerEmail;
|
||||
private String mCustomerName;
|
||||
private String mCustomerContry;
|
||||
|
||||
// /**
|
||||
// * Creates a new Order from a comma separated line from a *.csv file.
|
||||
// *
|
||||
// * Order ID,Merchant Order Number,Order Creation Date,Currency of Transaction,Order Amount,Amount Charged,Financial Status,Fulfillment Status,Link to Order,Total Tax,Total Shipping,Amount Refunded,Amount Charged Back,Chargeback Protection,Shipping Method,Email Marketing,Buyer Email Address,Buyer Name,Buyer Address 1,Buyer Address 2,Buyer City,Buyer State,Buyer Postal Code,Buyer Country,Buyer Phone Number,Tracking Data,Item 1 ID,Item 1 Name,Item 1 Description,Item 1 Price,Item 1 Quantity
|
||||
// *
|
||||
// * @param order
|
||||
// * @author ricky barrette
|
||||
// * @throws InvalidDateFormatException
|
||||
// * @throws IOException
|
||||
// */
|
||||
// public Order(String order) throws NumberFormatException, InvalidDateFormatException, IOException{
|
||||
// if(Main.DEBUG)
|
||||
// System.out.println("parsing in order: "+ order);
|
||||
//
|
||||
// CSVParser parsedOrder = new CSVParser(new StringReader(order));
|
||||
// String[] lineParts = parsedOrder.getLine();
|
||||
// parsedOrder.close();
|
||||
//
|
||||
// this.mGoogleOrderNumber = Long.parseLong(lineParts[0].split(" ")[1]);
|
||||
// this.mOrderCreationDate = new Date(lineParts[2]);
|
||||
// this.mOrderAmount = Float.parseFloat(lineParts[4]);
|
||||
// this.mAmountCharged = Float.parseFloat(lineParts[5]);
|
||||
// this.mFinancialStatus = Status.parseStatus(lineParts[6]);
|
||||
// this.mFulfillmentStatus = Status.parseStatus(lineParts[7]);
|
||||
// this.mCustomerEmail = lineParts[16];
|
||||
// this.mCustomerName = lineParts[17];
|
||||
// this.mItemName = lineParts[27];
|
||||
//
|
||||
// String [] lineParts;
|
||||
// lineParts = order.split(",");
|
||||
// System.out.println(lineParts[0].split(" ")[1]);
|
||||
// this.mGoogleOrderNumber = Long.parseLong(lineParts[0].split(" ")[1]);
|
||||
// this.mOrderCreationDate = new Date(lineParts[2].substring(1));
|
||||
// this.mOrderAmount = Float.parseFloat(lineParts[4]);
|
||||
// this.mAmountCharged = Float.parseFloat(lineParts[5]);
|
||||
// this.mFinancialStatus = Status.parseStatus(lineParts[6]);
|
||||
// this.mFulfillmentStatus = Status.parseStatus(lineParts[7]);
|
||||
// this.mCustomerEmail = removeFistAndLastChar(lineParts[16]);
|
||||
// this.mCustomerName = removeFistAndLastChar(lineParts[17]);
|
||||
// this.mItemName = removeFistAndLastChar(lineParts[27]);
|
||||
//
|
||||
// if (Main.DEBUG)
|
||||
// System.out.println(this.toString());
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * removes the last char from a string
|
||||
// * @param s
|
||||
// * @return
|
||||
// * @author ricky barrette
|
||||
// */
|
||||
// private String removeLastChar(String s) {
|
||||
// return s.substring(0, s.length() - 1);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * removes the first and last chars from a string
|
||||
// * @param s
|
||||
// * @return
|
||||
// * @author ricky barrette
|
||||
// */
|
||||
// private String removeFistAndLastChar(String s){
|
||||
// return s.substring(1, s.length()-1);
|
||||
// }
|
||||
|
||||
|
||||
public Order(String[] lineParts) throws InvalidDateFormatException, NumberFormatException {
|
||||
this.mGoogleOrderNumber = Long.parseLong(lineParts[0].split(" ")[1]);
|
||||
this.mOrderCreationDate = new Date(lineParts[2]);
|
||||
this.mOrderAmount = Float.parseFloat(lineParts[4]);
|
||||
this.mAmountCharged = Float.parseFloat(lineParts[5]);
|
||||
this.mFinancialStatus = Status.parseStatus(lineParts[6]);
|
||||
this.mFulfillmentStatus = Status.parseStatus(lineParts[7]);
|
||||
this.mCustomerEmail = lineParts[16];
|
||||
this.mCustomerName = lineParts[17];
|
||||
this.mItemName = lineParts[27];
|
||||
this.mCustomerContry = lineParts[23];
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a human readable string that represnets this object
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@Override
|
||||
public String toString(){
|
||||
return this.mGoogleOrderNumber +", "+ this.mOrderCreationDate.toString() +", "+ this.mItemName +", "+ this.mOrderAmount +", "+ this.mAmountCharged +", "+ this.mFinancialStatus +", "+ this.mFulfillmentStatus +", "+ this.mCustomerName +", "+ this.mCustomerEmail +", "+ this.mCustomerContry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares orders by orders creation date
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Comparable#compareTo(java.lang.Object)
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@Override
|
||||
public int compareTo(Order o) {
|
||||
return this.mOrderCreationDate.compareTo(o.getOrderCreationDate());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param mItemName the mItemName to set
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void setItemName(String mItemName) {
|
||||
this.mItemName = mItemName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the mItemName
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public String getItemName() {
|
||||
return mItemName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param googleOrderNumber the mGoogleOrderNumber to set
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void setGoogleOrderNumber(long googleOrderNumber) {
|
||||
this.mGoogleOrderNumber = googleOrderNumber;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the mGoogleOrderNumber
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public long getGoogleOrderNumber() {
|
||||
return mGoogleOrderNumber;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param orderCreationDate the mOrderCreationDate to set
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void setOrderCreationDate(Date orderCreationDate) {
|
||||
this.mOrderCreationDate = orderCreationDate;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the mOrderCreationDate
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public Date getOrderCreationDate() {
|
||||
return mOrderCreationDate;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param orderAmount the mOrderAmount to set
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void setOrderAmount(float orderAmount) {
|
||||
this.mOrderAmount = orderAmount;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the mOrderAmount
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public float getOrderAmount() {
|
||||
return mOrderAmount;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param amountCharged the mAmountCharged to set
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void setAmountCharged(float amountCharged) {
|
||||
this.mAmountCharged = amountCharged;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the mAmountCharged
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public float getAmountCharged() {
|
||||
return mAmountCharged;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param financialStatus the mFinancialStatus to set
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void setFinancialStatus(Status financialStatus) {
|
||||
this.mFinancialStatus = financialStatus;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the mFinancialStatus
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public Status getFinancialStatus() {
|
||||
return mFinancialStatus;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param fulfillmentStatus the mFulfillmentStatus to set
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void setFulfillmentStatus(Status fulfillmentStatus) {
|
||||
this.mFulfillmentStatus = fulfillmentStatus;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the mFulfillmentStatus
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public Status getFulfillmentStatus() {
|
||||
return mFulfillmentStatus;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param customerEmail the mCustomerEmail to set
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void setCustomerEmail(String customerEmail) {
|
||||
this.mCustomerEmail = customerEmail;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the mCustomerEmail
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public String getCustomerEmail() {
|
||||
return mCustomerEmail;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param customerName the mCustomerName to set
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void setCustomerName(String customerName) {
|
||||
this.mCustomerName = customerName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the mCustomerName
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public String getCustomerName() {
|
||||
return mCustomerName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param customerContry the mCustomerContry to set
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void setCustomerContry(String customerContry) {
|
||||
this.mCustomerContry = customerContry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the mCustomerContry
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public String getCustomerContry() {
|
||||
return mCustomerContry;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* @author Twenty Codes, LLC
|
||||
* @author ricky barrette
|
||||
* @date Dec 24, 2010
|
||||
*/
|
||||
|
||||
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 {
|
||||
|
||||
/**
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private static final long serialVersionUID = 4605163237489852355L;
|
||||
|
||||
/**
|
||||
* Creates a new OrderExistsException
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public OrderExistsException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new OrderExistsException
|
||||
* @param arg0
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public OrderExistsException(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new OrderExistsException
|
||||
* @param arg0
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public OrderExistsException(Throwable arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new AccountExistsException
|
||||
* @param arg0
|
||||
* @param arg1
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public OrderExistsException(String arg0, Throwable arg1) {
|
||||
super(arg0, arg1);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* ProgressListener.java
|
||||
* @date Jan 3, 2011
|
||||
* @author ricky barrette
|
||||
* @author Twenty Codes, LLC
|
||||
*/
|
||||
package com.TwentyCodes.java.OrderProcessor;
|
||||
|
||||
/**
|
||||
* A listener class that will be used to pass updates from the order DB to the client window
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public interface ProgressListener {
|
||||
|
||||
/**
|
||||
* called when the progress has ben updated
|
||||
* @param progress
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void onProgressUpdate(String string, boolean isIndeterminate, int progress, int max);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* Status.java
|
||||
* @date Jan 2, 2011
|
||||
* @author ricky barrette
|
||||
* @author Twenty Codes, LLC
|
||||
*/
|
||||
package com.TwentyCodes.java.OrderProcessor;
|
||||
|
||||
|
||||
/**
|
||||
* This enum will represent statuses that are associated with an order
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public enum Status {
|
||||
|
||||
/**
|
||||
* A financial status representing that the order has been charged to the customer
|
||||
*/
|
||||
CHARGED,
|
||||
|
||||
/**
|
||||
* A financial status representing that the order has been canceled by the customer
|
||||
*/
|
||||
CANCELLED,
|
||||
|
||||
|
||||
/**
|
||||
* A financial status representing that the order has been canceled by google, most likely due to an invalid credit card
|
||||
*/
|
||||
CANCELLED_BY_GOOGLE,
|
||||
|
||||
/**
|
||||
* A fulfillment status representing that the order has been delivered to the customer
|
||||
*/
|
||||
DELIVERED,
|
||||
|
||||
/**
|
||||
* A fulfillment status representing that the order has been canceled, and will not be delivered to the customer
|
||||
*/
|
||||
WILL_NOT_DELIVER,
|
||||
|
||||
/**
|
||||
* A financial status representing that the order is chargeable
|
||||
*/
|
||||
CHARGEABLE,
|
||||
|
||||
/**
|
||||
* A fulfillment status representing that the order is new
|
||||
*/
|
||||
NEW;
|
||||
;
|
||||
|
||||
|
||||
/**
|
||||
* Parses a string into a Status
|
||||
* @param s
|
||||
* @return the Status the represents the string or null if unparseable
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public static Status parseStatus(String s){
|
||||
if(Main.DEBUG)
|
||||
System.out.println("parsing status: "+ s);
|
||||
|
||||
if(s.equals(CHARGED.toString()))
|
||||
return CHARGED;
|
||||
|
||||
if(s.equals(CANCELLED.toString()))
|
||||
return CANCELLED;
|
||||
|
||||
if(s.equals(CANCELLED_BY_GOOGLE.toString()))
|
||||
return CANCELLED_BY_GOOGLE;
|
||||
|
||||
if(s.equals(DELIVERED.toString()))
|
||||
return DELIVERED;
|
||||
|
||||
if(s.equals(WILL_NOT_DELIVER.toString()))
|
||||
return WILL_NOT_DELIVER;
|
||||
|
||||
if(s.equals(CHARGEABLE.toString()))
|
||||
return CHARGEABLE;
|
||||
|
||||
if(s.equals(NEW.toString()))
|
||||
return NEW;
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Style.java
|
||||
* @date Jan 2, 2011
|
||||
* @author ricky barrette
|
||||
* @author Twenty Codes, LLC
|
||||
*/
|
||||
package com.TwentyCodes.java.OrderProcessor;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public enum TextStyle {
|
||||
|
||||
BOLD, ITALIC, REGULAR, RED, BLUE
|
||||
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/**
|
||||
* Test.java
|
||||
* @date Jan 10, 2011
|
||||
* @author ricky barrette
|
||||
* @author Twenty Codes, LLC
|
||||
*/
|
||||
package com.TwentyCodes.java.OrderProcessor.UI;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.HeadlessException;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import com.TwentyCodes.java.OrderProcessor.Date;
|
||||
import com.TwentyCodes.java.OrderProcessor.DatePickerListener;
|
||||
import com.TwentyCodes.java.OrderProcessor.InvalidDateFormatException;
|
||||
import com.toedter.calendar.JCalendar;
|
||||
import com.toedter.components.JSpinField;
|
||||
|
||||
/**
|
||||
* a simple date picker window that allows the user to easily pick a date
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public class DatePicker extends JFrame implements ActionListener {
|
||||
|
||||
private static final long serialVersionUID = -8460535573336456875L;
|
||||
public static final int END_DATE_RESULT = 1;
|
||||
public static final int START_DATE_RESULT = 0;
|
||||
private JCalendar mCalendar;
|
||||
private JButton mOkButton;
|
||||
private JSpinField mHours;
|
||||
private JSpinField mSeconds;
|
||||
private JSpinField mMinutes;
|
||||
private DatePickerListener mListener;
|
||||
private JLabel mFailLabel;
|
||||
private int mResultCode;
|
||||
|
||||
/**
|
||||
* Creates a new Test
|
||||
* @throws HeadlessException
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public DatePicker(int resultCode, DatePickerListener listener) {
|
||||
this.setTitle("Date Picker");
|
||||
setIconImage(new ImageIcon(getClass().getResource("/calendar_date.png")).getImage());
|
||||
|
||||
mResultCode = resultCode;
|
||||
mListener = listener;
|
||||
|
||||
//Time fields
|
||||
JPanel p = new JPanel();
|
||||
p.add(new JLabel("Hours:"));
|
||||
mHours = new JSpinField();
|
||||
mHours.setMinimum(0);
|
||||
mHours.setMaximum(23);
|
||||
mHours.adjustWidthToMaximumValue();
|
||||
p.add(mHours);
|
||||
p.add(new JLabel("Minutes:"));
|
||||
mMinutes = new JSpinField();
|
||||
mMinutes.setMinimum(0);
|
||||
mMinutes.setMaximum(59);
|
||||
mMinutes.adjustWidthToMaximumValue();
|
||||
p.add(mMinutes);
|
||||
p.add(new JLabel("Seconds:"));
|
||||
mSeconds = new JSpinField();
|
||||
mSeconds.setMinimum(0);
|
||||
mSeconds.setMaximum(59);
|
||||
mSeconds.adjustWidthToMaximumValue();
|
||||
p.add(mSeconds);
|
||||
this.getContentPane().add(p, BorderLayout.NORTH);
|
||||
|
||||
//Calender
|
||||
mCalendar = new JCalendar();
|
||||
this.getContentPane().add(mCalendar, BorderLayout.CENTER);
|
||||
|
||||
//ok button
|
||||
mOkButton = new JButton("Ok", new ImageIcon(getClass().getResource("/accept.png")));
|
||||
mOkButton.addActionListener(this);
|
||||
this.getContentPane().add(mOkButton, BorderLayout.SOUTH);
|
||||
|
||||
//fail label
|
||||
mFailLabel = new JLabel("Invalid entry");
|
||||
mFailLabel.setVisible(false);
|
||||
p.add(mFailLabel);
|
||||
|
||||
//if this is an end date, then set the time to the latest possible
|
||||
if(resultCode == END_DATE_RESULT){
|
||||
mHours.setValue(23);
|
||||
mMinutes.setValue(59);
|
||||
mSeconds.setValue(59);
|
||||
}
|
||||
|
||||
pack();
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
mListener.onDatePicked(mResultCode, new Date(
|
||||
mCalendar.getYearChooser().getYear()+"-"+ (mCalendar.getMonthChooser().getMonth()+1) +"-"+ mCalendar.getDayChooser().getDay() +
|
||||
" "+ mHours.getValue()+":"+ mMinutes.getValue()+":"+ mSeconds.getValue()));
|
||||
this.dispose();
|
||||
} catch (NumberFormatException e1) {
|
||||
e1.printStackTrace();
|
||||
mFailLabel.setVisible(true);
|
||||
pack();
|
||||
} catch (InvalidDateFormatException e1) {
|
||||
e1.printStackTrace();
|
||||
mFailLabel.setVisible(true);
|
||||
pack();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* ExceptionReportGUI.java
|
||||
* @date Jan 15, 2011
|
||||
* @author ricky barrette
|
||||
* @author Twenty Codes, LLC
|
||||
*/
|
||||
package com.TwentyCodes.java.OrderProcessor.UI;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.HeadlessException;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextArea;
|
||||
|
||||
/**
|
||||
* this simple frame will be used to display exception reports to the user
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public class ExceptionReportGUI extends JFrame implements ActionListener {
|
||||
|
||||
private static final long serialVersionUID = -4203182071311606914L;
|
||||
|
||||
/**
|
||||
* Creates a new ExceptionReportGUI
|
||||
* @throws HeadlessException
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public ExceptionReportGUI(String report) {
|
||||
super();
|
||||
setTitle("We're Sorry....");
|
||||
setIconImage(new ImageIcon(getClass().getResource("/info.png")).getImage());
|
||||
|
||||
JButton ok = new JButton("Ok", new ImageIcon(getClass().getResource("/accept.png")));
|
||||
ok.addActionListener(this);
|
||||
|
||||
JScrollPane scrollPane = new JScrollPane();
|
||||
|
||||
final JTextArea results = new JTextArea();
|
||||
scrollPane.setViewportView(results);
|
||||
|
||||
results.setEditable(false);
|
||||
results.setText(report);
|
||||
|
||||
this.getContentPane().add(scrollPane, BorderLayout.CENTER);
|
||||
this.getContentPane().add(ok, BorderLayout.SOUTH);
|
||||
pack();
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
this.dispose();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,280 @@
|
||||
/**
|
||||
|
||||
* @author ricky barrette
|
||||
* @date Dec 18, 2010
|
||||
*/
|
||||
|
||||
package com.TwentyCodes.java.OrderProcessor.UI;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.net.SocketException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JProgressBar;
|
||||
import javax.swing.JTabbedPane;
|
||||
|
||||
import com.TwentyCodes.java.OrderProcessor.FileFilter;
|
||||
import com.TwentyCodes.java.OrderProcessor.ProgressListener;
|
||||
import com.TwentyCodes.java.OrderProcessor.UncaughtExceptionHandler;
|
||||
import com.TwentyCodes.java.OrderProcessor.DB.OrderDB;
|
||||
import javax.swing.JPasswordField;
|
||||
|
||||
import org.jasypt.util.text.BasicTextEncryptor;
|
||||
|
||||
/**
|
||||
* this is the main window and class of this application
|
||||
*/
|
||||
public class MainWindow extends JFrame implements ActionListener, ProgressListener{
|
||||
|
||||
private static JButton mLoadFileButton;
|
||||
private JFileChooser fc;
|
||||
public static OrderDB db;
|
||||
private static final long serialVersionUID = 1841715561053331517L;
|
||||
private static JProgressBar mProgressBar;
|
||||
private String mCurrentFile;
|
||||
private UncaughtExceptionHandler mExceptionReport = new UncaughtExceptionHandler(this.getClass());
|
||||
private static JLabel orderCountLabel;
|
||||
private static JLabel mWarningLabel;
|
||||
private static JButton mConnectButton;
|
||||
private static JPasswordField mPassWord;
|
||||
private static boolean isUsingRemoteServer;
|
||||
private JLabel lblDatabasePassword;
|
||||
|
||||
/**
|
||||
* Creates a new MainWindow
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public MainWindow() {
|
||||
|
||||
Thread.setDefaultUncaughtExceptionHandler(mExceptionReport);
|
||||
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
|
||||
fc = new JFileChooser();
|
||||
fc.setFileFilter(new FileFilter());
|
||||
|
||||
JTabbedPane tabbedPane = new JTabbedPane();
|
||||
|
||||
tabbedPane.addTab("Main", initializeMainPanel());
|
||||
tabbedPane.addTab("Search Orders", new SearchPanel(this));
|
||||
tabbedPane.addTab("Show All Orders", new ShowAllPanel(this));
|
||||
tabbedPane.addTab("Settings", new SettingsPanel());
|
||||
|
||||
mProgressBar.setString(null);
|
||||
mProgressBar.setIndeterminate(false);
|
||||
this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
|
||||
|
||||
this.setVisible(true);
|
||||
this.pack();
|
||||
|
||||
loadDatabase();
|
||||
}
|
||||
|
||||
/**
|
||||
* initializes the main layout
|
||||
*
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private JPanel initializeMainPanel() {
|
||||
setTitle("Twenty Codes, LLC Order Database");
|
||||
setIconImage(new ImageIcon(getClass().getResource("/database.png")).getImage());
|
||||
|
||||
JPanel mainPanel = new JPanel(new BorderLayout());
|
||||
JPanel panel = new JPanel();
|
||||
mainPanel.add(panel);
|
||||
|
||||
//load button
|
||||
mLoadFileButton = new JButton("Load File", new ImageIcon(getClass().getResource("/database_add.png")));
|
||||
mLoadFileButton.addActionListener(this);
|
||||
|
||||
mWarningLabel = new JLabel("");
|
||||
orderCountLabel = new JLabel("");
|
||||
|
||||
panel.add(new JLabel("Total Orders in the database:"));
|
||||
panel.add(orderCountLabel);
|
||||
|
||||
panel.add(mLoadFileButton);
|
||||
|
||||
lblDatabasePassword = new JLabel("Database Password");
|
||||
panel.add(lblDatabasePassword);
|
||||
|
||||
mPassWord = new JPasswordField();
|
||||
mPassWord.setColumns(10);
|
||||
mPassWord.setEnabled(false);
|
||||
panel.add(mPassWord);
|
||||
|
||||
mConnectButton = new JButton("Connect", new ImageIcon(getClass().getResource("/repeat.png")));
|
||||
mConnectButton.addActionListener(this);
|
||||
panel.add(mConnectButton);
|
||||
|
||||
panel.add(mWarningLabel);
|
||||
|
||||
//progress bar
|
||||
mProgressBar = new JProgressBar();
|
||||
mProgressBar.setStringPainted(true);
|
||||
|
||||
mainPanel.add(mProgressBar, BorderLayout.SOUTH);
|
||||
|
||||
return mainPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* loads an instance of the order database using the most current settings
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public static void loadDatabase() {
|
||||
BasicTextEncryptor passwordEncryptor = new BasicTextEncryptor();
|
||||
passwordEncryptor.setPassword(OrderDB.PASSWORD);
|
||||
|
||||
isUsingRemoteServer = false;
|
||||
|
||||
try {
|
||||
Properties p = getProperties();
|
||||
|
||||
isUsingRemoteServer = Boolean.parseBoolean(p.getProperty(SettingsPanel.IS_USING_REMOTE_SERVER, "false"));
|
||||
|
||||
mPassWord.setEnabled((! Boolean.parseBoolean(p.getProperty(SettingsPanel.SAVE_PASSWORD, "false"))) && (isUsingRemoteServer));
|
||||
if(! mPassWord.isEnabled())
|
||||
mPassWord.setText(passwordEncryptor.decrypt(p.getProperty(SettingsPanel.SERVER_PASSWORD)));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
mConnectButton.setEnabled(false);
|
||||
mProgressBar.setString("Connecting to database");
|
||||
mProgressBar.setIndeterminate(true);
|
||||
java.util.concurrent.Executors.newSingleThreadExecutor().submit(new Runnable() {
|
||||
public void run() {
|
||||
|
||||
//order count labels
|
||||
try {
|
||||
db = isUsingRemoteServer ? new OrderDB(new String(mPassWord.getPassword())) : new OrderDB();
|
||||
orderCountLabel.setText(db.getCount()+"");
|
||||
mWarningLabel.setText("Connected");
|
||||
mPassWord.setEnabled(false);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
mWarningLabel.setText(e.getMessage());
|
||||
mWarningLabel.setVisible(true);
|
||||
mConnectButton.setEnabled(true);
|
||||
orderCountLabel.setText("");
|
||||
} catch (SocketException e) {
|
||||
mWarningLabel.setText(e.getMessage());
|
||||
mWarningLabel.setVisible(true);
|
||||
mConnectButton.setEnabled(true);
|
||||
orderCountLabel.setText("");
|
||||
} catch (NullPointerException e){
|
||||
mWarningLabel.setText("Database not avilable");
|
||||
mWarningLabel.setVisible(true);
|
||||
mConnectButton.setEnabled(true);
|
||||
orderCountLabel.setText("");
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
mProgressBar.setString(mWarningLabel.getText());
|
||||
mProgressBar.setIndeterminate(false);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* called when a button is clicked
|
||||
* (non-Javadoc)
|
||||
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
||||
*/
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
/**
|
||||
* Prepares the progress bar, and loads the file using an executer to prevent UI hangups
|
||||
*/
|
||||
if(e.getSource() == mLoadFileButton){
|
||||
if(fc.showOpenDialog(MainWindow.this) == JFileChooser.APPROVE_OPTION){
|
||||
mLoadFileButton.setEnabled(false);
|
||||
db.setOnProgressListerner(this);
|
||||
mProgressBar.setIndeterminate(true);
|
||||
mCurrentFile = fc.getSelectedFile().toString();
|
||||
mProgressBar.setString(mCurrentFile);
|
||||
|
||||
java.util.concurrent.Executors.newSingleThreadExecutor().submit(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
db.load(fc.getSelectedFile());
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
pack();
|
||||
} else {
|
||||
mProgressBar.setIndeterminate(false);
|
||||
}
|
||||
}
|
||||
|
||||
if(e.getSource() == mConnectButton){
|
||||
loadDatabase();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* called then the progress of the order db is updated
|
||||
* (non-Javadoc)
|
||||
* @see com.TwentyCodes.java.OrderProcessor.ProgressListener#onProgressUpdate(int)
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@Override
|
||||
public void onProgressUpdate(String string, boolean isIndeterminate, int progress, int max) {
|
||||
mProgressBar.setMaximum(max);
|
||||
mProgressBar.setValue(progress);
|
||||
mProgressBar.setString(string);
|
||||
if(mProgressBar.isIndeterminate()) {
|
||||
mProgressBar.setIndeterminate(isIndeterminate);
|
||||
pack();
|
||||
}
|
||||
if(progress >= mProgressBar.getMaximum()){
|
||||
mLoadFileButton.setEnabled(true);
|
||||
try {
|
||||
orderCountLabel.setText(db.getCount()+"");
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SocketException e) {
|
||||
mWarningLabel.setText(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the properties from the save file
|
||||
* @return
|
||||
* @throws IOException
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private static Properties getProperties() throws IOException{
|
||||
// create and load default properties
|
||||
Properties props = new Properties();
|
||||
FileInputStream in = new FileInputStream(SettingsPanel.PROPERTIES_FILE_NAME);
|
||||
props.load(in);
|
||||
in.close();
|
||||
return props;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
/**
|
||||
* OrderPanel.java
|
||||
* @date Jan 9, 2011
|
||||
* @author ricky barrette
|
||||
* @author Twenty Codes, LLC
|
||||
*/
|
||||
package com.TwentyCodes.java.OrderProcessor.UI;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextPane;
|
||||
import javax.swing.text.BadLocationException;
|
||||
import javax.swing.text.Style;
|
||||
import javax.swing.text.StyleConstants;
|
||||
import javax.swing.text.StyleContext;
|
||||
import javax.swing.text.StyledDocument;
|
||||
|
||||
import com.TwentyCodes.java.OrderProcessor.Order;
|
||||
import com.TwentyCodes.java.OrderProcessor.ProgressListener;
|
||||
import com.TwentyCodes.java.OrderProcessor.TextStyle;
|
||||
|
||||
/**
|
||||
* a pane to display orders in color code.
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public class OrderPane extends JScrollPane {
|
||||
|
||||
private static final long serialVersionUID = -8762146025822173375L;
|
||||
private JTextPane mOutput;
|
||||
private ProgressListener mListener;
|
||||
|
||||
/**
|
||||
* Creates a new OrderPanel
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public OrderPane() {
|
||||
mOutput = new JTextPane();
|
||||
mOutput.setEditable(false);
|
||||
setViewportView(mOutput);
|
||||
}
|
||||
|
||||
/**
|
||||
* displays orders
|
||||
* @param list of orders to display
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void displayOrders(ArrayList<Order> list) {
|
||||
ArrayList<TextStyle> styles = new ArrayList<TextStyle>();
|
||||
mOutput.setText(null);
|
||||
BigDecimal possible = new BigDecimal(0);
|
||||
BigDecimal actual = new BigDecimal(0);
|
||||
BigDecimal possibleNew = new BigDecimal(0);
|
||||
int total = 0;
|
||||
int newOrders = 0;
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
if(mListener != null)
|
||||
mListener.onProgressUpdate("Processing Order: "+ (i+1) +" of "+ list.size(), false, (i+1), list.size());
|
||||
|
||||
try {
|
||||
switch (list.get(i).getFulfillmentStatus()) {
|
||||
case WILL_NOT_DELIVER:
|
||||
styles.add(TextStyle.RED);
|
||||
break;
|
||||
case NEW:
|
||||
styles.add(TextStyle.BLUE);
|
||||
newOrders++;
|
||||
possibleNew = possibleNew.add(new BigDecimal(list.get(i).getOrderAmount()));
|
||||
break;
|
||||
default:
|
||||
styles.add(TextStyle.REGULAR);
|
||||
total++;
|
||||
actual = actual.add(new BigDecimal((list.get(i).getAmountCharged())));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
//This is just in case I missed a order status again
|
||||
styles.add(TextStyle.ITALIC);
|
||||
e.printStackTrace();
|
||||
}
|
||||
possible = possible.add(new BigDecimal((list.get(i).getOrderAmount())));
|
||||
}
|
||||
|
||||
updateTextPane(list, styles);
|
||||
updateTextPane("\nPossible sold: " + list.size()
|
||||
+"\nPossible sales: $" + possible.setScale(2, BigDecimal.ROUND_DOWN)
|
||||
+ ( (newOrders > 0) ? "\n\nTotal new sales: "+ newOrders + "\nPossible new sales: $"+ possibleNew.setScale(2, BigDecimal.ROUND_DOWN) : "")
|
||||
+ "\n\nTotal sold: " + total
|
||||
+ "\nActual sales: $" + actual.setScale(2, BigDecimal.ROUND_DOWN) , TextStyle.BOLD);
|
||||
}
|
||||
|
||||
/**
|
||||
* addeds the orders to the text pane
|
||||
* @param list of orders
|
||||
* @param styles for the orders
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private void updateTextPane(ArrayList<Order> list, ArrayList<TextStyle> styles) {
|
||||
StyledDocument doc = mOutput.getStyledDocument();
|
||||
addStylesToDocument(doc);
|
||||
// Load the text pane with styled text.
|
||||
try {
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
doc.insertString(doc.getLength(), "\n"+list.get(i).toString(),
|
||||
doc.getStyle(styles.get(i).toString()));
|
||||
}
|
||||
} catch (BadLocationException ble) {
|
||||
System.err.println("Couldn't insert initial text into text pane.");
|
||||
}
|
||||
mOutput.setDocument(doc);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the text contained by this order pane
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public String getText(){
|
||||
return mOutput.getText();
|
||||
}
|
||||
|
||||
/**
|
||||
* adds the following string to the order pane
|
||||
* @param string
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private void updateTextPane(String string, TextStyle style) {
|
||||
StyledDocument doc = mOutput.getStyledDocument();
|
||||
addStylesToDocument(doc);
|
||||
|
||||
// Load the text pane with styled text.
|
||||
try {
|
||||
doc.insertString(doc.getLength(), string, doc.getStyle(style.toString()));
|
||||
} catch (BadLocationException ble) {
|
||||
System.err.println("Couldn't insert initial text into text pane.");
|
||||
}
|
||||
mOutput.setDocument(doc);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* adds supported styles to the document
|
||||
* @param doc
|
||||
* @author ricky barrette
|
||||
*/
|
||||
protected void addStylesToDocument(StyledDocument doc) {
|
||||
// Initialize some styles.
|
||||
Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
|
||||
|
||||
Style regular = doc.addStyle("REGULAR", def);
|
||||
StyleConstants.setFontFamily(def, "Arial");
|
||||
StyleConstants.setFontSize(def, 14);
|
||||
|
||||
Style s = doc.addStyle("ITALIC", regular);
|
||||
StyleConstants.setItalic(s, true);
|
||||
StyleConstants.setBackground(s, Color.YELLOW);
|
||||
|
||||
s = doc.addStyle("BOLD", regular);
|
||||
StyleConstants.setBold(s, true);
|
||||
|
||||
s = doc.addStyle("RED", regular);
|
||||
StyleConstants.setForeground(s, Color.RED);
|
||||
StyleConstants.setBold(s, true);
|
||||
|
||||
s = doc.addStyle("BLUE", regular);
|
||||
StyleConstants.setForeground(s, Color.BLUE);
|
||||
StyleConstants.setBold(s, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* sets a listener for db progress updates
|
||||
* @param listener
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void setOnProgressListerner(ProgressListener listener) {
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets text of the order pane
|
||||
* @param message
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void setText(String message) {
|
||||
mOutput.setText(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,322 @@
|
||||
/**
|
||||
* Search.java
|
||||
* @date Jan 9, 2011
|
||||
* @author ricky barrette
|
||||
* @author Twenty Codes, LLC
|
||||
*/
|
||||
package com.TwentyCodes.java.OrderProcessor.UI;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Scanner;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JProgressBar;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import com.TwentyCodes.java.OrderProcessor.Date;
|
||||
import com.TwentyCodes.java.OrderProcessor.DatePickerListener;
|
||||
import com.TwentyCodes.java.OrderProcessor.FileFilter;
|
||||
import com.TwentyCodes.java.OrderProcessor.InvalidDateFormatException;
|
||||
import com.TwentyCodes.java.OrderProcessor.Order;
|
||||
import com.TwentyCodes.java.OrderProcessor.ProgressListener;
|
||||
|
||||
/**
|
||||
* This class will be the dialog that will ask the user for a specific make to show
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public class SearchPanel extends JPanel implements ActionListener, ProgressListener, MouseListener, DatePickerListener {
|
||||
|
||||
private static final long serialVersionUID = 1750326106927701404L;
|
||||
|
||||
private JButton mOkButton;
|
||||
private JTextField mTextField;
|
||||
private JProgressBar mProgressBar;
|
||||
private OrderPane mOrderPanel;
|
||||
private JTextField mStartDateField;
|
||||
private JTextField mEndDateField;
|
||||
private JCheckBox mExclusiveCheckBox;
|
||||
private JButton mExportButton;
|
||||
private JFileChooser fc;
|
||||
// private JCheckBox fcCheckBox;
|
||||
private JFrame mFrame;
|
||||
|
||||
/**
|
||||
* Creates a new ShowAllMakeDialog
|
||||
* @param frame
|
||||
*/
|
||||
public SearchPanel(JFrame frame) {
|
||||
super(new BorderLayout());
|
||||
mFrame = frame;
|
||||
|
||||
// mFrame.setTitle("Search");
|
||||
// mFrame.setIconImage(new ImageIcon(getClass().getResource("/database_search.png")).getImage());
|
||||
|
||||
//create a JPanel to hold the text area and button
|
||||
JPanel panel = new JPanel();
|
||||
|
||||
//add the JPanel to the frame, and display
|
||||
add(panel, BorderLayout.NORTH);
|
||||
|
||||
//search string
|
||||
panel.add(new JLabel("Search:"));
|
||||
mTextField = new JTextField();
|
||||
mTextField.setColumns(20);
|
||||
mTextField.addActionListener(this);
|
||||
panel.add(mTextField);
|
||||
|
||||
//exclusive check box
|
||||
mExclusiveCheckBox = new JCheckBox("Exclusive Search");
|
||||
panel.add(mExclusiveCheckBox);
|
||||
|
||||
//start date
|
||||
panel.add(new JLabel("Start Date:"));
|
||||
mStartDateField = new JTextField();
|
||||
panel.add(mStartDateField);
|
||||
mStartDateField.setColumns(12);
|
||||
mStartDateField.addMouseListener(this);
|
||||
|
||||
//end date
|
||||
panel.add(new JLabel("End Date:"));
|
||||
mEndDateField = new JTextField();
|
||||
panel.add(mEndDateField);
|
||||
mEndDateField.setColumns(12);
|
||||
mEndDateField.addMouseListener(this);
|
||||
|
||||
//ok button
|
||||
mOkButton = new JButton("Ok", new ImageIcon(getClass().getResource("/database_search.png")));
|
||||
mOkButton.addActionListener(this);
|
||||
panel.add(mOkButton);
|
||||
|
||||
//export button
|
||||
mExportButton = new JButton("Export", new ImageIcon(getClass().getResource("/floppy_disc.png")));
|
||||
panel.add(mExportButton);
|
||||
mExportButton.addActionListener(this);
|
||||
|
||||
//output orderpane
|
||||
mOrderPanel = new OrderPane();
|
||||
add(mOrderPanel, BorderLayout.CENTER);
|
||||
|
||||
//progress bar
|
||||
mProgressBar = new JProgressBar();
|
||||
add(mProgressBar, BorderLayout.SOUTH);
|
||||
mProgressBar.setStringPainted(true);
|
||||
|
||||
//file chooser
|
||||
fc = new JFileChooser();
|
||||
fc.setFileFilter(new FileFilter());
|
||||
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* called when the enter button is pressed when the mTextFieeld is focused, or when the ok button is clicked
|
||||
* (non-Javadoc)
|
||||
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
||||
*/
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(e.getSource() == mExportButton)
|
||||
exportToCSV();
|
||||
else
|
||||
if(! mStartDateField.getText().isEmpty() && !mEndDateField.getText().isEmpty()){
|
||||
mProgressBar.setIndeterminate(true);
|
||||
try {
|
||||
preformSearch(mTextField.getText(), new Date(mStartDateField.getText()), new Date(mEndDateField.getText()));
|
||||
} catch (InvalidDateFormatException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
else{
|
||||
mProgressBar.setIndeterminate(true);
|
||||
preformSearch(mTextField.getText(), null, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* displays a JFileChooser dialog, and saves the current search results to an *.CSV file
|
||||
* @return true is save was successfull
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private boolean exportToCSV() {
|
||||
if(fc.showDialog(SearchPanel.this, "Export") == JFileChooser.APPROVE_OPTION){
|
||||
int write = 0;
|
||||
boolean hasExtention;
|
||||
|
||||
String filename = fc.getSelectedFile().toString();
|
||||
String ext =filename.substring((filename.lastIndexOf(".")+1),filename.length());
|
||||
|
||||
hasExtention = ext.equalsIgnoreCase("csv");
|
||||
|
||||
//file exists dialog
|
||||
if(new File(filename + (( ! hasExtention ) ? ".csv" : "") ).exists()){
|
||||
//default icon, custom title
|
||||
write = JOptionPane.showConfirmDialog(
|
||||
mFrame, "Do you want to overwrite"+ filename + ((! hasExtention ) ? ".csv" : ""),
|
||||
"Overwrite?",
|
||||
JOptionPane.YES_NO_OPTION);
|
||||
System.out.print(write);
|
||||
}
|
||||
|
||||
if(write == 0){
|
||||
//prep the data for proper csv format
|
||||
StringBuffer sb = new StringBuffer("Order Number,Time & date,Product Name,Order Amount,Amount Charged,Financial Status,Fulfillment Status,Customer Name,Customer Email,Customer Country");
|
||||
Scanner scan = new Scanner(mOrderPanel.getText());
|
||||
String[] parts;
|
||||
String line;
|
||||
while(scan.hasNext()){
|
||||
line = scan.nextLine();
|
||||
parts = line.split(", ");
|
||||
try {
|
||||
sb.append(parts[0]+","+parts[1]+","+parts[2]+","+parts[3]+","+parts[4]+","+parts[5]+","+parts[6]+","+parts[7]+","+parts[8]+","+parts[9]+"\n");
|
||||
} catch (Exception e) {
|
||||
sb.append(line+"\n");
|
||||
}
|
||||
}
|
||||
//write to the selceted file
|
||||
try {
|
||||
FileOutputStream theFile = new FileOutputStream(filename + (( ! hasExtention ) ? ".csv" : ""));
|
||||
theFile.write(sb.toString().getBytes());
|
||||
theFile.flush();
|
||||
theFile.close();
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* executes a concurrent database search
|
||||
* @param search string
|
||||
* @param start date
|
||||
* @param end date
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private void preformSearch(final String search, final Date start, final Date end) {
|
||||
java.util.concurrent.Executors.newSingleThreadExecutor().submit(new Runnable() {
|
||||
public void run() {
|
||||
MainWindow.db.setOnProgressListerner(SearchPanel.this);
|
||||
|
||||
ArrayList<Order> list = null;
|
||||
try {
|
||||
if((start != null) && (end != null)){
|
||||
list = MainWindow.db.search(search, start, end, mExclusiveCheckBox.isSelected());
|
||||
} else{
|
||||
list = MainWindow.db.search(search, mExclusiveCheckBox.isSelected());
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
mOrderPanel.setOnProgressListerner(SearchPanel.this);
|
||||
mOrderPanel.displayOrders(list);
|
||||
|
||||
mFrame.pack();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* called by MainWindow.db on progress update, or internally from this window to update the progress bar
|
||||
* (non-Javadoc)
|
||||
* @see com.TwentyCodes.java.OrderProcessor.ProgressListener#onProgressUpdate(int)
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@Override
|
||||
public void onProgressUpdate(String string, boolean isIndeterminate, int progress, int max) {
|
||||
mProgressBar.setMaximum(max);
|
||||
mProgressBar.setValue(progress);
|
||||
mProgressBar.setIndeterminate(isIndeterminate);
|
||||
mProgressBar.setString(string);
|
||||
}
|
||||
|
||||
/**
|
||||
* called when either of the date fields are clicked
|
||||
* (non-Javadoc)
|
||||
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if(e.getSource() == mEndDateField){
|
||||
new DatePicker(DatePicker.END_DATE_RESULT, this);
|
||||
}
|
||||
|
||||
if(e.getSource() == mStartDateField){
|
||||
new DatePicker(DatePicker.START_DATE_RESULT, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* called when the date picker returns a vaid date
|
||||
* (non-Javadoc)
|
||||
* @see com.TwentyCodes.java.OrderProcessor.DatePickerListener#onDatePicked(int, com.TwentyCodes.java.OrderProcessor.Date)
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@Override
|
||||
public void onDatePicked(int resultCode, Date date) {
|
||||
switch(resultCode){
|
||||
case DatePicker.START_DATE_RESULT:
|
||||
mStartDateField.setText(date.getYear()+"-"+date.getMonth()+"-"+date.getDay()+" "+date.getHour()+":"+date.getMinute()+":"+date.getSecond());
|
||||
break;
|
||||
case DatePicker.END_DATE_RESULT:
|
||||
mEndDateField.setText(date.getYear()+"-"+date.getMonth()+"-"+date.getDay()+" "+date.getHour()+":"+date.getMinute()+":"+date.getSecond());
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,290 @@
|
||||
/**
|
||||
* SettingsPanel.java
|
||||
* @date Jan 19, 2011
|
||||
* @author ricky barrette
|
||||
* @author Twenty Codes, LLC
|
||||
*/
|
||||
package com.TwentyCodes.java.OrderProcessor.UI;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.swing.GroupLayout;
|
||||
import javax.swing.GroupLayout.Alignment;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JPasswordField;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.LayoutStyle.ComponentPlacement;
|
||||
|
||||
import org.jasypt.util.text.BasicTextEncryptor;
|
||||
|
||||
import com.TwentyCodes.java.OrderProcessor.DB.OrderDB;
|
||||
|
||||
/**
|
||||
* this panel will be used to display and handle application settings
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public class SettingsPanel extends JPanel implements ActionListener {
|
||||
|
||||
private static final long serialVersionUID = 2568209868143577096L;
|
||||
public static final String IS_USING_REMOTE_SERVER = "use_remote_server";
|
||||
public static final String SERVER_LOCATION = "server_location";
|
||||
public static final String SERVER_PORT_NUMBER = "server_port_number";
|
||||
public static final String SERVER_USERNAME = "server_user_name";
|
||||
public static final String SERVER_PASSWORD = "server_parrword";
|
||||
public static final String SAVE_PASSWORD = "save_password";
|
||||
public static final String DATABASE_NAME = "database_name";
|
||||
public static final String PROPERTIES_FILE_NAME = ".orderprocessor.properties";
|
||||
private JTextField mServerLocation;
|
||||
private JTextField mPortNumber;
|
||||
private JTextField mUserName;
|
||||
private JPasswordField mUserPassword;
|
||||
private boolean isUsingRemoteServer;
|
||||
private JButton mSaveButton;
|
||||
private JCheckBox mUseRemoteDatabase;
|
||||
private Properties mProps;
|
||||
private JTextField mDatabaseName;
|
||||
private JCheckBox mSavePassword;
|
||||
|
||||
/**
|
||||
* Creates a new SettingsPanel
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public SettingsPanel() {
|
||||
|
||||
JLabel lblMysqlServerLocation = new JLabel("MYsql server location:");
|
||||
|
||||
//mql database location
|
||||
mServerLocation = new JTextField();
|
||||
mServerLocation.setColumns(10);
|
||||
|
||||
//use remote database checkbox
|
||||
mUseRemoteDatabase = new JCheckBox("Use Remote Database?");
|
||||
mUseRemoteDatabase.addActionListener(this);
|
||||
|
||||
JLabel lblMysqlServerPort = new JLabel("MYsql server port:");
|
||||
|
||||
//server port number
|
||||
mPortNumber = new JTextField();
|
||||
mPortNumber.setEnabled(false);
|
||||
mPortNumber.setColumns(10);
|
||||
|
||||
JLabel lblMysql = new JLabel("MYsql server user name:");
|
||||
JLabel lblMysqlServerPassword = new JLabel("MYsql server password:");
|
||||
//username
|
||||
mUserName = new JTextField();
|
||||
mUserName.setColumns(10);
|
||||
|
||||
//user password
|
||||
mUserPassword = new JPasswordField();
|
||||
mUserPassword.setColumns(10);
|
||||
|
||||
//disable everything
|
||||
mServerLocation.setEnabled(false);
|
||||
mUserName.setEnabled(false);
|
||||
mUserPassword.setEnabled(false);
|
||||
|
||||
//save button
|
||||
mSaveButton = new JButton("Save", new ImageIcon(getClass().getResource("/floppy_disc.png")));
|
||||
mSaveButton.addActionListener(this);
|
||||
|
||||
mSavePassword = new JCheckBox("Save Password?");
|
||||
mSavePassword.addActionListener(this);
|
||||
|
||||
JLabel lblDatabaseName = new JLabel("Database Name:");
|
||||
|
||||
mDatabaseName = new JTextField();
|
||||
mDatabaseName.setEnabled(false);
|
||||
|
||||
mDatabaseName.setColumns(10);
|
||||
|
||||
//group layout bullshit
|
||||
GroupLayout groupLayout = new GroupLayout(this);
|
||||
groupLayout.setHorizontalGroup(
|
||||
groupLayout.createParallelGroup(Alignment.LEADING)
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addComponent(mUseRemoteDatabase)
|
||||
.addContainerGap(1087, Short.MAX_VALUE))
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addComponent(mSavePassword)
|
||||
.addContainerGap())
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
|
||||
.addComponent(lblMysqlServerLocation)
|
||||
.addComponent(lblMysqlServerPort)
|
||||
.addComponent(lblDatabaseName)
|
||||
.addComponent(lblMysql))
|
||||
.addPreferredGap(ComponentPlacement.RELATED)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
|
||||
.addComponent(mPortNumber, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 1079, Short.MAX_VALUE)
|
||||
.addComponent(mServerLocation, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 1079, Short.MAX_VALUE)
|
||||
.addComponent(mDatabaseName, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 1079, Short.MAX_VALUE)
|
||||
.addComponent(mUserName, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 1079, Short.MAX_VALUE))
|
||||
.addContainerGap())))
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addComponent(lblMysqlServerPassword)
|
||||
.addPreferredGap(ComponentPlacement.RELATED)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
|
||||
.addComponent(mUserPassword, GroupLayout.DEFAULT_SIZE, 313, Short.MAX_VALUE)
|
||||
.addComponent(mSaveButton, GroupLayout.DEFAULT_SIZE, 949, Short.MAX_VALUE))
|
||||
.addContainerGap())
|
||||
);
|
||||
groupLayout.setVerticalGroup(
|
||||
groupLayout.createParallelGroup(Alignment.LEADING)
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addComponent(mUseRemoteDatabase)
|
||||
.addPreferredGap(ComponentPlacement.RELATED)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
|
||||
.addComponent(lblMysqlServerLocation)
|
||||
.addComponent(mServerLocation, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(ComponentPlacement.RELATED)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
|
||||
.addComponent(lblMysqlServerPort)
|
||||
.addComponent(mPortNumber, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(ComponentPlacement.RELATED)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
|
||||
.addComponent(lblDatabaseName)
|
||||
.addComponent(mDatabaseName, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(ComponentPlacement.RELATED)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
|
||||
.addComponent(mUserName, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(lblMysql))
|
||||
.addPreferredGap(ComponentPlacement.RELATED)
|
||||
.addComponent(mSavePassword)
|
||||
.addPreferredGap(ComponentPlacement.RELATED)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
|
||||
.addComponent(lblMysqlServerPassword)
|
||||
.addComponent(mUserPassword, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(ComponentPlacement.RELATED)
|
||||
.addComponent(mSaveButton)
|
||||
.addContainerGap(264, Short.MAX_VALUE))
|
||||
);
|
||||
setLayout(groupLayout);
|
||||
|
||||
// create and load default properties
|
||||
mProps = new Properties();
|
||||
|
||||
try {
|
||||
FileInputStream in = new FileInputStream(PROPERTIES_FILE_NAME);
|
||||
mProps.load(in);
|
||||
in.close();
|
||||
isUsingRemoteServer = Boolean.parseBoolean(mProps.getProperty(IS_USING_REMOTE_SERVER, "false"));
|
||||
|
||||
if(isUsingRemoteServer){
|
||||
mServerLocation.setEnabled(true);
|
||||
mPortNumber.setEnabled(true);
|
||||
mUserName.setEnabled(true);
|
||||
mUserPassword.setEnabled( Boolean.parseBoolean(mProps.getProperty(SAVE_PASSWORD, "false")));
|
||||
mUseRemoteDatabase.setSelected(true);
|
||||
mDatabaseName.setEnabled(true);
|
||||
mSavePassword.setEnabled(true);
|
||||
}
|
||||
|
||||
mDatabaseName.setText(mProps.getProperty(DATABASE_NAME, "Orders"));
|
||||
mServerLocation.setText(mProps.getProperty(SERVER_LOCATION));
|
||||
mPortNumber.setText(mProps.getProperty(SERVER_PORT_NUMBER, "3306"));
|
||||
mUserName.setText(mProps.getProperty(SERVER_USERNAME));
|
||||
mSavePassword.setSelected(Boolean.parseBoolean(mProps.getProperty(SAVE_PASSWORD, "false")));
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
mDatabaseName.setText("Orders");
|
||||
mPortNumber.setText("3306");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* called when the save button is clicked, or the use remote database check box is clicked
|
||||
* (non-Javadoc)
|
||||
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
//save button
|
||||
if(e.getSource() == mSaveButton){
|
||||
BasicTextEncryptor passwordEncryptor = new BasicTextEncryptor();
|
||||
passwordEncryptor.setPassword(OrderDB.PASSWORD);
|
||||
mProps.put(SERVER_LOCATION, mServerLocation.getText());
|
||||
mProps.put(SERVER_PORT_NUMBER, mPortNumber.getText());
|
||||
mProps.put(SERVER_USERNAME, mUserName.getText());
|
||||
mProps.put(DATABASE_NAME, mDatabaseName.getText());
|
||||
|
||||
if(mSavePassword.isSelected())
|
||||
mProps.put(SERVER_PASSWORD, new String(passwordEncryptor.encrypt(new String(mUserPassword.getPassword()))));
|
||||
|
||||
writeProperties(mProps);
|
||||
|
||||
}
|
||||
|
||||
//use remote database checkbox
|
||||
if(e.getSource() == mUseRemoteDatabase){
|
||||
mProps.put(IS_USING_REMOTE_SERVER, Boolean.toString(mUseRemoteDatabase.isSelected()));
|
||||
writeProperties(mProps);
|
||||
|
||||
if(mUseRemoteDatabase.isSelected()){
|
||||
mServerLocation.setEnabled(true);
|
||||
mPortNumber.setEnabled(true);
|
||||
mUserName.setEnabled(true);
|
||||
mUserPassword.setEnabled(true);
|
||||
mDatabaseName.setEnabled(true);
|
||||
mSavePassword.setEnabled(true);
|
||||
} else {
|
||||
mServerLocation.setEnabled(false);
|
||||
mPortNumber.setEnabled(false);
|
||||
mUserName.setEnabled(false);
|
||||
mUserPassword.setEnabled(false);
|
||||
mDatabaseName.setEnabled(false);
|
||||
mSavePassword.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
if(e.getSource() == mSavePassword){
|
||||
mProps.setProperty(SAVE_PASSWORD, Boolean.toString(mSavePassword.isSelected()));
|
||||
writeProperties(mProps);
|
||||
if(mSavePassword.isSelected()){
|
||||
mUserPassword.setEnabled(true);
|
||||
return;
|
||||
} else {
|
||||
mUserPassword.setEnabled(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
MainWindow.loadDatabase();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* writes the Properties to a persitent file
|
||||
* @param p
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private void writeProperties(Properties p){
|
||||
try {
|
||||
FileOutputStream out = new FileOutputStream(PROPERTIES_FILE_NAME);
|
||||
p.store(out, "---Order Processor Settings---");
|
||||
out.close();
|
||||
} catch (FileNotFoundException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
/**
|
||||
* @author Twenty Codes, LLC
|
||||
* @author ricky barrette
|
||||
* @date Dec 18, 2010
|
||||
*/
|
||||
|
||||
package com.TwentyCodes.java.OrderProcessor.UI;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JProgressBar;
|
||||
|
||||
import com.TwentyCodes.java.OrderProcessor.ProgressListener;
|
||||
|
||||
/**
|
||||
* This panel will be used to display all orders in the order database
|
||||
*/
|
||||
public class ShowAllPanel extends JPanel implements ActionListener, ProgressListener {
|
||||
|
||||
private static final long serialVersionUID = -8416144493079733535L;
|
||||
private JProgressBar mProgressBar;
|
||||
private OrderPane mOutput;
|
||||
private JFrame mFrame;
|
||||
private JButton ok;
|
||||
private JButton clear;
|
||||
|
||||
/**
|
||||
* Creates a new ShowAllDialog
|
||||
*/
|
||||
public ShowAllPanel(final JFrame frame){
|
||||
super(new BorderLayout());
|
||||
mFrame = frame;
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
|
||||
// setTitle("Show All Orders");
|
||||
// setIconImage(new ImageIcon(getClass().getResource("/database.png")).getImage());
|
||||
|
||||
//ok button
|
||||
ok = new JButton("Refresh", new ImageIcon(getClass().getResource("/page_process.png")));
|
||||
ok.addActionListener(this);
|
||||
panel.add(ok);
|
||||
|
||||
//clear button
|
||||
clear = new JButton("Clear", new ImageIcon(getClass().getResource("/page.png")));
|
||||
clear.addActionListener(this);
|
||||
panel.add(clear);
|
||||
|
||||
mOutput = new OrderPane();
|
||||
mProgressBar = new JProgressBar();
|
||||
add(mProgressBar, BorderLayout.SOUTH);
|
||||
add(mOutput, BorderLayout.CENTER);
|
||||
add(panel, BorderLayout.NORTH);
|
||||
mProgressBar.setStringPainted(true);
|
||||
frame.pack();
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* called when the buttons are clicked
|
||||
* (non-Javadoc)
|
||||
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
//display all the orders
|
||||
if(e.getSource() == ok){
|
||||
MainWindow.db.setOnProgressListerner(this);
|
||||
java.util.concurrent.Executors.newSingleThreadExecutor().submit(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
mOutput.displayOrders(MainWindow.db.getAllOrders());
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
mFrame.pack();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//clear the output
|
||||
if(e.getSource() == clear){
|
||||
mOutput.setText(null);
|
||||
onProgressUpdate(null, false, 0, 1);
|
||||
mFrame.pack();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* called when there is a progress update
|
||||
* (non-Javadoc)
|
||||
* @see com.TwentyCodes.java.OrderProcessor.ProgressListener#onProgressUpdate(java.lang.String, boolean, int, int)
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@Override
|
||||
public void onProgressUpdate(String string, boolean isIndeterminate, int progress, int max) {
|
||||
mProgressBar.setMaximum(max);
|
||||
mProgressBar.setValue(progress);
|
||||
mProgressBar.setIndeterminate(isIndeterminate);
|
||||
mProgressBar.setString(string);
|
||||
if(progress >= mProgressBar.getMaximum()){
|
||||
mFrame.pack();
|
||||
mProgressBar.setString("Done");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
* UncaughtExceptionHandler.java
|
||||
* @date Jan 6, 2011
|
||||
* @author ricky barrette
|
||||
* @author Twenty Codes, LLC
|
||||
*/
|
||||
package com.TwentyCodes.java.OrderProcessor;
|
||||
|
||||
import com.TwentyCodes.java.OrderProcessor.UI.ExceptionReportGUI;
|
||||
|
||||
/**
|
||||
* An exception handler used to help report bugs in our applications
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public class UncaughtExceptionHandler implements java.lang.Thread.UncaughtExceptionHandler {
|
||||
|
||||
private java.lang.Thread.UncaughtExceptionHandler mDefaultUEH;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private Class mApp;
|
||||
|
||||
/**
|
||||
* Creates a new UncaughtExceptionHandler
|
||||
* @param c
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public UncaughtExceptionHandler(Class c) {
|
||||
mApp = c;
|
||||
mDefaultUEH = Thread.getDefaultUncaughtExceptionHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Thread.UncaughtExceptionHandler#uncaughtException(java.lang.Thread, java.lang.Throwable)
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@Override
|
||||
public void uncaughtException(Thread t, Throwable e) {
|
||||
new ExceptionReportGUI(getDebugReport(e));
|
||||
mDefaultUEH.uncaughtException(t,e);
|
||||
}
|
||||
|
||||
/**
|
||||
* generates a human readable report about the exception
|
||||
* @param e
|
||||
* @return
|
||||
* @author ricky barrette
|
||||
*/
|
||||
private String getDebugReport(Throwable e) {
|
||||
|
||||
StackTraceElement[] theStackTrace = e.getStackTrace();
|
||||
|
||||
StringBuffer report = new StringBuffer();
|
||||
|
||||
report.append("We're sorry, but there was an error with your application.\n" +
|
||||
" Please email this report to twentycodes@gmail.com to help make this application better. \n\n");
|
||||
|
||||
report.append("--------- Application ---------\n\n");
|
||||
|
||||
report.append(mApp.getPackage());
|
||||
|
||||
report.append(" generated the following exception:\n\n");
|
||||
|
||||
report.append(e.toString() + "\n\n");
|
||||
|
||||
report.append("-------------------------------\n\n");
|
||||
|
||||
report.append("--------- Stack trace ---------\n\n");
|
||||
for (int i = 0; i < theStackTrace.length; i++) {
|
||||
report.append(" " + theStackTrace[i].toString() + "\n");
|
||||
}
|
||||
report.append("-------------------------------\n\n");
|
||||
|
||||
// If the exception was thrown in a background thread inside
|
||||
// AsyncTask, then the actual exception can be found with getCause
|
||||
report.append("--------- Cause ---------------\n\n");
|
||||
Throwable cause = e.getCause();
|
||||
if (cause != null) {
|
||||
report.append(cause.toString() + "\n\n");
|
||||
theStackTrace = cause.getStackTrace();
|
||||
for (int i = 0; i < theStackTrace.length; i++) {
|
||||
report.append(" " + theStackTrace[i].toString() + "\n");
|
||||
}
|
||||
}
|
||||
report.append("-------------------------------\n\n");
|
||||
|
||||
return report.toString();
|
||||
}
|
||||
|
||||
}
|
||||
56
OrderProcessor/version infomation/changelog
Normal file
@@ -0,0 +1,56 @@
|
||||
1.0.0 b 28
|
||||
fixed the .CSV file parsing with an external lib.
|
||||
|
||||
1.0.1 b 29
|
||||
created a single window with a tabbed layout for a more fluid experience.
|
||||
added an overwrite file dialog.
|
||||
added the customer country to the order object.
|
||||
updated .CSV export
|
||||
|
||||
1.0.2 b 30
|
||||
i replaced the old sqlite driver (for local databases) with the mySQL driver to interface with TCDEVSVN1's order database
|
||||
|
||||
1.0.3 b 31
|
||||
i improved the speed of file parsing, be making less database hits
|
||||
|
||||
1.0.4 b 32
|
||||
fixed order processing to be more efficient, and i now use BigDecimal to cal money
|
||||
|
||||
1.0.5 b 33
|
||||
i created a settings panel that uses a .property file to save settings.
|
||||
i modified OrderDB to use the .property file
|
||||
|
||||
1.0.6 b 34
|
||||
created the static method MainWindow.loadDatabase() for easy database reloading
|
||||
|
||||
1.1.0 B 45
|
||||
created statuss for NEW and CHARGABLE, and added the options to the order pane.
|
||||
added the ability to remove existing orders if they are new, so they can be replaced
|
||||
added the ability to print all new order in blue
|
||||
improved order pane processing
|
||||
modified the date picker to be easier to use
|
||||
|
||||
1.1.1 b 46
|
||||
re-added the show all dialog.
|
||||
MainWinod.java, reorganized the constructor so the progress bar will be indeterminate when connecting to the database
|
||||
|
||||
1.1.2 b 47
|
||||
added clear button to the ShowAllPanel.java
|
||||
fixed the export save dialog to automatically handle extensions
|
||||
added new order stats to the order pane
|
||||
|
||||
1.1.3 b 48
|
||||
fixed processed order stats to only display new order stats when theres new orders
|
||||
added password encryption using jasypt
|
||||
|
||||
1.1.4 b 49
|
||||
added more options in settings allowing user to pick the database name.
|
||||
added an option to allow the user to save their password
|
||||
added a password field to the main panel to allow for easy password entry
|
||||
added a connect button to the main panel
|
||||
|
||||
1.1.5 b 50
|
||||
used similar code to remove redundant code
|
||||
created a static variable for PROPERTIES_FILE_NAME
|
||||
added a case to the order pane to highlight any orders with null statuses
|
||||
slight modification to order pane updateTextPane() s
|
||||
1
OrderProcessor/version infomation/version
Normal file
@@ -0,0 +1 @@
|
||||
1.1.5 b 50
|
||||