Compare commits

..

10 Commits

Author SHA1 Message Date
8749006ea5 added a checkout button to the Main Panel. It allows the user to "checkout" a remote database to a local database
removed the warning label from main panel, and moved all messages to the progress bar
2011-02-09 18:50:45 +00:00
d5d2221fb2 updated version info 2011-02-08 16:37:53 +00:00
f58c2219c5 Add status PAYMENT_DECLINED. 2011-02-08 16:36:25 +00:00
866505868e reorg 2011-02-01 17:46:31 +00:00
4ebe4a9910 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
2011-01-29 14:18:28 +00:00
4be7476de7 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
2011-01-27 18:49:30 +00:00
c85e599530 fixed processed order stats to only display new order stats when theres new orders
added password encryption using jasypt
2011-01-26 18:54:47 +00:00
21c7d0642b added clear button to the ShowAllPanel.java
fixed the export save dialog to automatically handle extensions
added new order stats to the order pane
2011-01-23 04:22:27 +00:00
7d1fe95e5a re-added the show all dialog.
MainWinod.java, reorganized the constructor so the progress bar will be indeterminate when connecting to the database
2011-01-23 02:51:58 +00:00
f9a805803c 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
2011-01-22 20:33:57 +00:00
54 changed files with 718 additions and 303 deletions

View File

@@ -1,7 +0,0 @@
#---No Comment---
#Thu Jan 20 12:15:15 EST 2011
server_parrword=S35-2n6t
use_remote_server=true
server_location=tcdevsvn1
server_port_number=3306
server_user_name=ricky.barrette

View File

@@ -1,24 +0,0 @@
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

View File

@@ -1 +0,0 @@
1.0.6 b 34

View File

@@ -8,5 +8,6 @@
<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>

View File

@@ -0,0 +1,9 @@
#---Order Processor Settings---
#Wed Feb 09 13:48:50 EST 2011
database_name=Orders
server_parrword=Ekf4syi+03SEjxLksxRbuuxV4qpKog5G
save_password=true
use_remote_server=true
server_location=tcdevsvn1
server_port_number=3306
server_user_name=ricky.barrette

View File

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

View File

@@ -25,6 +25,8 @@ 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;
@@ -32,6 +34,8 @@ 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.MainWindow;
import com.TwentyCodes.java.OrderProcessor.UI.SettingsPanel;
/**
@@ -40,6 +44,7 @@ import com.TwentyCodes.java.OrderProcessor.UI.SettingsPanel;
*/
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 (?);";
@@ -47,16 +52,15 @@ public class OrderDB {
private PreparedStatement prep;
private String dbLocation;
private boolean isLoadingFile = false;
private ArrayList<Order> list;
private ArrayList<Order> mList;
private boolean isUsingRemoteDatabase;
/**
* Creates a new OrderDB
* @author ricky barrette
* @throws ClassNotFoundException
* @throws SQLException
* @throws SocketException
* @throws Exception
* @author ricky barrette
*/
public OrderDB() throws ClassNotFoundException, SQLException, SocketException {
@@ -72,7 +76,8 @@ public class OrderDB {
dbLocation = System.getProperty("user.home") +"/.TwentyCodesOrders";
}
Connection conn = getConnection();
Connection conn = getConnection();
Statement stat = conn.createStatement();
// stat.executeUpdate("drop table if exists Orders;");
@@ -89,40 +94,42 @@ public class OrderDB {
}
/**
* gets the properties from the properties file
* @return properties
* Creates a new OrderDB
* @param password for the database
* @throws ClassNotFoundException
* @throws SQLException
* @throws SocketException
* @author ricky barrette
*/
private Properties getProperties() {
Properties props = new java.util.Properties();
try {
FileInputStream in = new FileInputStream(".settings.propertys");
props.load(in);
in.close();
return props;
} catch (IOException e1) {
e1.printStackTrace();
}
return props;
}
public OrderDB(String password) throws ClassNotFoundException, SQLException, SocketException {
/**
* 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 {
// LineNumberReader reader = new LineNumberReader(new FileReader(file));
int cnt = 1;
// while ((reader.readLine()) != null) ;
// cnt = reader.getLineNumber();
// reader.close();
CSVParser csvParser = new CSVParser(new FileInputStream(file));
while(csvParser.getLine() != null)
cnt++;
return cnt;
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();
}
/**
@@ -138,15 +145,127 @@ public class OrderDB {
/*
* check the current database for an orders with a matching order number
*/
for(Order item : list)
if(item.getGoogleOrderNumber() == order.getGoogleOrderNumber())
throw new OrderExistsException(order.toString());
for(Order item : mList)
list.add(order);
if(item.getGoogleOrderNumber() == order.getGoogleOrderNumber())
if(item.getFulfillmentStatus() == Status.NEW )
deleteOrder(item);
else
throw new OrderExistsException(order.toString());
mList.add(order);
saveOrder(order);
}
/**
* copies remote database to local DB
* @throws SQLException
* @throws IOException
* @throws ClassNotFoundException
* @author ricky barrette
*/
public void checkoutDatabase() throws SQLException, IOException, ClassNotFoundException{
//get all from remote DB
ArrayList<Order> list = this.getAllOrders();
//switch over to local DB
Class.forName("org.sqlite.JDBC");
dbLocation = System.getProperty("user.home") +"/.TwentyCodesOrders";
isUsingRemoteDatabase = false;
//connect to local DB
Connection conn = this.getConnection();
Statement stat = conn.createStatement();
// //remove old table
// stat.executeUpdate("drop table if exists Orders;");
//create tabe if it needs to be created
try {
stat.executeUpdate(CREATE_TABLE_LOCAL);
} catch (Exception e1) {
e1.printStackTrace();
}
mList = this.getAllOrders();
//the insert statement
prep = conn.prepareStatement(INSERT);
conn.setAutoCommit(true);
//copy the orders over
int i = 1;
for(Order item : list) {
if(mListener != null)
mListener.onProgressUpdate("Checking out order "+ i++ +" of "+ list.size(), false, i, list.size());
try {
addOrder(item);
} catch (OrderExistsException e) {
e.printStackTrace();
}
}
//reload the remote DB
MainWindow.loadDatabase();
mList = null;
}
/**
* 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
@@ -159,9 +278,10 @@ public class OrderDB {
int row = 1;
int count = getCount();
Connection conn = getConnection();
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("select * from Orders;");
ResultSet rs = getOrders(conn);
ArrayList<Order> list = new ArrayList<Order>();
ByteArrayInputStream bais;
@@ -188,23 +308,36 @@ public class OrderDB {
*/
private Connection getConnection() throws SQLException, SocketException{
Properties props = getProperties();
BasicTextEncryptor passwordEncryptor = new BasicTextEncryptor();
passwordEncryptor.setPassword(PASSWORD);
if(isUsingRemoteDatabase){
String url = "jdbc:mysql://"+props.getProperty(SettingsPanel.SERVER_LOCATION)+":"+props.getProperty(SettingsPanel.SERVER_PORT_NUMBER, "3306")+"/Orders";
if(props.getProperty(SettingsPanel.SERVER_USERNAME).length() > 0)
url += "?user="+ props.getProperty(SettingsPanel.SERVER_USERNAME);
if(props.getProperty(SettingsPanel.SERVER_PASSWORD).length() > 0)
url += "&password="+ props.getProperty(SettingsPanel.SERVER_PASSWORD);
return DriverManager.getConnection(url);
}
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
@@ -223,6 +356,37 @@ public class OrderDB {
return count;
}
/**
* 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 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
@@ -234,12 +398,11 @@ public class OrderDB {
*/
public void load(File file) throws SQLException, IOException, ClassNotFoundException{
// Scanner scan = new Scanner(file);
prep = null;
list = null;
mList = null;
CSVParser csvParser = new CSVParser(new FileInputStream(file));
list = new ArrayList<Order>(getAllOrders());
mList = new ArrayList<Order>(getAllOrders());
int line = 1;
int lineCount = countLines(file);
@@ -267,7 +430,6 @@ public class OrderDB {
e.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
@@ -276,8 +438,8 @@ public class OrderDB {
prep.close();
conn.close();
isLoadingFile = false;
}
}
/**
* saves an order to the database
@@ -297,7 +459,6 @@ public class OrderDB {
prep.setBytes(1, bos.toByteArray());
prep.executeUpdate();
// prep.addBatch();
}
/**

View File

@@ -16,7 +16,6 @@ public class Main {
public static final boolean DEBUG = true;
public static final boolean USE_REMOTE_DB = true;
/**
* called when the application first starts

View File

@@ -37,7 +37,25 @@ public enum Status {
/**
* A fulfillment status representing that the order has been canceled, and will not be delivered to the customer
*/
WILL_NOT_DELIVER;
WILL_NOT_DELIVER,
/**
* A financial status representing that the order is chargeable
*/
CHARGEABLE,
/**
* A fulfillment status representing that the order is new
*/
NEW,
/**
* A financial status representing that the authorization of the customer's credit card failed.
* Google has sent an email instructing the customer to update their card.
* If they fail to provide a valid card within 7 days, this order will be automatically canceled by Google.
*/
PAYMENT_DECLINED
;
/**
@@ -65,6 +83,15 @@ public enum Status {
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;
if(s.equals(PAYMENT_DECLINED.toString()))
return PAYMENT_DECLINED;
return null;
}

View File

@@ -12,6 +12,6 @@ package com.TwentyCodes.java.OrderProcessor;
*/
public enum TextStyle {
BOLD, ITALIC, REGULAR, RED, GREEN
BOLD, ITALIC, REGULAR, RED, BLUE
}

View File

@@ -16,12 +16,12 @@ import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
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
@@ -30,11 +30,13 @@ import com.toedter.calendar.JCalendar;
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 JTextField mHours;
private JTextField mSeconds;
private JTextField mMinutes;
private JSpinField mHours;
private JSpinField mSeconds;
private JSpinField mMinutes;
private DatePickerListener mListener;
private JLabel mFailLabel;
private int mResultCode;
@@ -54,16 +56,22 @@ public class DatePicker extends JFrame implements ActionListener {
//Time fields
JPanel p = new JPanel();
p.add(new JLabel("Hours:"));
mHours = new JTextField();
mHours.setColumns(10);
mHours = new JSpinField();
mHours.setMinimum(0);
mHours.setMaximum(23);
mHours.adjustWidthToMaximumValue();
p.add(mHours);
p.add(new JLabel("Minutes:"));
mMinutes = new JTextField();
mMinutes.setColumns(10);
mMinutes = new JSpinField();
mMinutes.setMinimum(0);
mMinutes.setMaximum(59);
mMinutes.adjustWidthToMaximumValue();
p.add(mMinutes);
p.add(new JLabel("Seconds:"));
mSeconds = new JTextField();
mSeconds.setColumns(10);
mSeconds = new JSpinField();
mSeconds.setMinimum(0);
mSeconds.setMaximum(59);
mSeconds.adjustWidthToMaximumValue();
p.add(mSeconds);
this.getContentPane().add(p, BorderLayout.NORTH);
@@ -81,6 +89,13 @@ public class DatePicker extends JFrame implements ActionListener {
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);
}
@@ -90,7 +105,7 @@ public class DatePicker extends JFrame implements ActionListener {
try {
mListener.onDatePicked(mResultCode, new Date(
mCalendar.getYearChooser().getYear()+"-"+ (mCalendar.getMonthChooser().getMonth()+1) +"-"+ mCalendar.getDayChooser().getDay() +
" "+ Integer.parseInt(mHours.getText())+":"+ Integer.parseInt(mMinutes.getText())+":"+ Integer.parseInt(mSeconds.getText())));
" "+ mHours.getValue()+":"+ mMinutes.getValue()+":"+ mSeconds.getValue()));
this.dispose();
} catch (NumberFormatException e1) {
e1.printStackTrace();

View File

@@ -9,10 +9,12 @@ 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;
@@ -27,6 +29,9 @@ 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
@@ -37,11 +42,16 @@ public class MainWindow extends JFrame implements ActionListener, ProgressListen
private JFileChooser fc;
public static OrderDB db;
private static final long serialVersionUID = 1841715561053331517L;
private JProgressBar mProgressBar;
private static JProgressBar mProgressBar;
private String mCurrentFile;
private UncaughtExceptionHandler mExceptionReport = new UncaughtExceptionHandler(this.getClass());
private static JLabel orderCountLabel;
private static JLabel mWarningLabel;
// private static JLabel mWarningLabel;
private static JButton mConnectButton;
private static JPasswordField mPassWord;
private static boolean isUsingRemoteServer;
private JLabel lblDatabasePassword;
private static JButton mCheckout;
/**
* Creates a new MainWindow
@@ -59,14 +69,17 @@ public class MainWindow extends JFrame implements ActionListener, ProgressListen
tabbedPane.addTab("Main", initializeMainPanel());
tabbedPane.addTab("Search Orders", new SearchPanel(this));
// tabbedPane.addTab("Show All Orders", new ShowAllPanel(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();
}
/**
@@ -82,53 +95,100 @@ public class MainWindow extends JFrame implements ActionListener, ProgressListen
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("");
// mWarningLabel = new JLabel("");
orderCountLabel = new JLabel("");
panel.add(new JLabel("Total Orders in the database:"));
panel.add(orderCountLabel);
loadDatabase();
panel.add(mLoadFileButton);
panel.add(mWarningLabel);
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);
mCheckout = new JButton("Checkout Remote Database", new ImageIcon(getClass().getResource("/database_down.png")));
mCheckout.addActionListener(this);
mCheckout.setEnabled(false);
panel.add(mCheckout);
// 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() {
//order count labels
BasicTextEncryptor passwordEncryptor = new BasicTextEncryptor();
passwordEncryptor.setPassword(OrderDB.PASSWORD);
isUsingRemoteServer = false;
try {
db = new OrderDB();
orderCountLabel.setText(db.getCount()+"");
mWarningLabel.setText("");
} catch (SQLException e) {
e.printStackTrace();
mWarningLabel.setText(e.getMessage());
mWarningLabel.setVisible(true);
} catch (SocketException e) {
mWarningLabel.setText(e.getMessage());
mWarningLabel.setVisible(true);
} catch (NullPointerException e){
mWarningLabel.setText("Database not avilable");
mWarningLabel.setVisible(true);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
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()+"");
mProgressBar.setString("Connected");
mPassWord.setEnabled(false);
} catch (SQLException e) {
e.printStackTrace();
mProgressBar.setString(e.getMessage());
mConnectButton.setEnabled(true);
orderCountLabel.setText("");
} catch (SocketException e) {
mProgressBar.setString(e.getMessage());
mConnectButton.setEnabled(true);
orderCountLabel.setText("");
} catch (NullPointerException e){
mProgressBar.setString("Database not avilable");
mConnectButton.setEnabled(true);
orderCountLabel.setText("");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
mCheckout.setEnabled( (isUsingRemoteServer && ! mConnectButton.isEnabled()) );
mProgressBar.setIndeterminate(false);
}
});
}
@@ -155,7 +215,6 @@ public class MainWindow extends JFrame implements ActionListener, ProgressListen
public void run() {
try {
db.load(fc.getSelectedFile());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
@@ -173,6 +232,29 @@ public class MainWindow extends JFrame implements ActionListener, ProgressListen
mProgressBar.setIndeterminate(false);
}
}
if(e.getSource() == mConnectButton){
loadDatabase();
}
if(e.getSource() == mCheckout)
java.util.concurrent.Executors.newSingleThreadExecutor().submit(new Runnable() {
public void run() {
db.setOnProgressListerner(MainWindow.this);
try {
db.checkoutDatabase();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
/**
@@ -197,9 +279,24 @@ public class MainWindow extends JFrame implements ActionListener, ProgressListen
} catch (SQLException e) {
e.printStackTrace();
} catch (SocketException e) {
mWarningLabel.setText(e.getMessage());
mProgressBar.setString(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;
}
}

View File

@@ -44,36 +44,51 @@ public class OrderPane extends JScrollPane {
/**
* displays orders
*
* @param list
* of orders to display
* @param list of orders to display
* @author ricky barrette
*/
public void displayOrders(ArrayList<Order> list) {
ArrayList<String> styles = new ArrayList<String>();
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;
for (Order item : list) {
int newOrders = 0;
for (int i = 0; i < list.size(); i++) {
if(mListener != null)
mListener.onProgressUpdate("Processing Order: "+ (total+1) +" of "+ list.size(), false, total, list.size());
mListener.onProgressUpdate("Processing Order: "+ (i+1) +" of "+ list.size(), false, (i+1), list.size());
switch (item.getFulfillmentStatus()) {
case WILL_NOT_DELIVER:
styles.add(TextStyle.RED.toString());
break;
default:
styles.add(TextStyle.REGULAR.toString());
total++;
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(item.getOrderAmount()));
actual = actual.add(new BigDecimal(item.getAmountCharged()));
possible = possible.add(new BigDecimal((list.get(i).getOrderAmount())));
}
updateTextPane(list, styles);
updateTextPane("\nPossible sales: $" + possible.setScale(2, BigDecimal.ROUND_DOWN) + "\nActual sales: $" + actual.setScale(2, BigDecimal.ROUND_DOWN) + "\nPossible sold:" + list.size() + "\nTotal sold: " + total, TextStyle.BOLD);
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);
}
/**
@@ -82,14 +97,14 @@ public class OrderPane extends JScrollPane {
* @param styles for the orders
* @author ricky barrette
*/
private void updateTextPane(ArrayList<Order> list, ArrayList<String> styles) {
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)));
doc.getStyle(styles.get(i).toString()));
}
} catch (BadLocationException ble) {
System.err.println("Couldn't insert initial text into text pane.");
@@ -97,29 +112,26 @@ public class OrderPane extends JScrollPane {
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 textpane
*
* adds the following string to the order pane
* @param string
* @author ricky barrette
*/
private void updateTextPane(String string, TextStyle style) {
String[] initString = { "\n" + string };
String[] initStyles = { style.toString() };
StyledDocument doc = mOutput.getStyledDocument();
addStylesToDocument(doc);
// Load the text pane with styled text.
try {
for (int i = 0; i < initString.length; i++) {
doc.insertString(doc.getLength(), initString[i],
doc.getStyle(initStyles[i]));
}
doc.insertString(doc.getLength(), string, doc.getStyle(style.toString()));
} catch (BadLocationException ble) {
System.err.println("Couldn't insert initial text into text pane.");
}
@@ -129,7 +141,6 @@ public class OrderPane extends JScrollPane {
/**
* adds supported styles to the document
*
* @param doc
* @author ricky barrette
*/
@@ -143,6 +154,7 @@ public class OrderPane extends JScrollPane {
Style s = doc.addStyle("ITALIC", regular);
StyleConstants.setItalic(s, true);
StyleConstants.setBackground(s, Color.YELLOW);
s = doc.addStyle("BOLD", regular);
StyleConstants.setBold(s, true);
@@ -151,13 +163,13 @@ public class OrderPane extends JScrollPane {
StyleConstants.setForeground(s, Color.RED);
StyleConstants.setBold(s, true);
s = doc.addStyle("GREEN", regular);
StyleConstants.setForeground(s, Color.GREEN);
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
*/

View File

@@ -14,7 +14,6 @@ import java.awt.event.MouseListener;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.SocketException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Scanner;
@@ -34,7 +33,6 @@ 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.Main;
import com.TwentyCodes.java.OrderProcessor.Order;
import com.TwentyCodes.java.OrderProcessor.ProgressListener;
@@ -45,20 +43,17 @@ import com.TwentyCodes.java.OrderProcessor.ProgressListener;
public class SearchPanel extends JPanel implements ActionListener, ProgressListener, MouseListener, DatePickerListener {
private static final long serialVersionUID = 1750326106927701404L;
private static final int END_DATE_RESULT = 1;
private static final int START_DATE_RESULT = 0;
private JButton mOkButton;
private JTextField mTextField;
private JProgressBar mProgressBar;
private boolean isProcessing = false;
private int mListSize;
private OrderPane mOrderPanel;
private JTextField mStartDateField;
private JTextField mEndDateField;
private JCheckBox mExclusiveCheckBox;
private JButton mExportButton;
private JFileChooser fc;
private JCheckBox fcCheckBox;
// private JCheckBox fcCheckBox;
private JFrame mFrame;
/**
@@ -120,12 +115,11 @@ public class SearchPanel extends JPanel implements ActionListener, ProgressListe
//progress bar
mProgressBar = new JProgressBar();
add(mProgressBar, BorderLayout.SOUTH);
mProgressBar.setStringPainted(true);
//file chooser
fc = new JFileChooser();
fc.setFileFilter(new FileFilter());
fcCheckBox = new JCheckBox("Automatically append extention");
fcCheckBox.setSelected(true);
fc.setAccessory(fcCheckBox);
setVisible(true);
}
@@ -164,15 +158,21 @@ public class SearchPanel extends JPanel implements ActionListener, ProgressListe
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(fc.getSelectedFile().exists()){
if(new File(filename + (( ! hasExtention ) ? ".csv" : "") ).exists()){
//default icon, custom title
write = JOptionPane.showConfirmDialog(
mFrame,
"Do you want to overwrite"+ fc.getSelectedFile().toString(),
mFrame, "Do you want to overwrite"+ filename + ((! hasExtention ) ? ".csv" : ""),
"Overwrite?",
JOptionPane.YES_NO_OPTION);
System.out.print(write);
}
if(write == 0){
@@ -192,11 +192,7 @@ public class SearchPanel extends JPanel implements ActionListener, ProgressListe
}
//write to the selceted file
try {
FileOutputStream theFile;
if (fcCheckBox.isSelected())
theFile = new FileOutputStream(new File(fc.getSelectedFile().toString()+".csv"));
else
theFile = new FileOutputStream(fc.getSelectedFile());
FileOutputStream theFile = new FileOutputStream(filename + (( ! hasExtention ) ? ".csv" : ""));
theFile.write(sb.toString().getBytes());
theFile.flush();
theFile.close();
@@ -220,8 +216,6 @@ public class SearchPanel extends JPanel implements ActionListener, ProgressListe
private void preformSearch(final String search, final Date start, final Date end) {
java.util.concurrent.Executors.newSingleThreadExecutor().submit(new Runnable() {
public void run() {
mProgressBar.setString("Searching for: "+search);
mProgressBar.setStringPainted(true);
MainWindow.db.setOnProgressListerner(SearchPanel.this);
ArrayList<Order> list = null;
@@ -239,18 +233,10 @@ public class SearchPanel extends JPanel implements ActionListener, ProgressListe
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
mListSize = list.size();
mProgressBar.setMaximum(mProgressBar.getMaximum() + mListSize);
isProcessing = true;
mProgressBar.setString("Processing Order: "+ 1 +" of "+ mListSize);
mFrame.pack();
mOrderPanel.setOnProgressListerner(SearchPanel.this);
mOrderPanel.displayOrders(list);
isProcessing = false;
mFrame.pack();
}
});
@@ -268,24 +254,6 @@ public class SearchPanel extends JPanel implements ActionListener, ProgressListe
mProgressBar.setValue(progress);
mProgressBar.setIndeterminate(isIndeterminate);
mProgressBar.setString(string);
if(Main.DEBUG)
System.out.println("search progress = "+ progress);
progress++;
if(isProcessing){
try {
mProgressBar.setValue(progress + MainWindow.db.getCount());
} catch (SQLException e) {
e.printStackTrace();
} catch (SocketException e) {
mOrderPanel.setText(e.getMessage());
}
} else {
mProgressBar.setValue(progress);
mProgressBar.setMaximum(max);
}
}
/**
@@ -297,11 +265,11 @@ public class SearchPanel extends JPanel implements ActionListener, ProgressListe
@Override
public void mouseClicked(MouseEvent e) {
if(e.getSource() == mEndDateField){
new DatePicker(END_DATE_RESULT, this);
new DatePicker(DatePicker.END_DATE_RESULT, this);
}
if(e.getSource() == mStartDateField){
new DatePicker(START_DATE_RESULT, this);
new DatePicker(DatePicker.START_DATE_RESULT, this);
}
}
@@ -342,10 +310,10 @@ public class SearchPanel extends JPanel implements ActionListener, ProgressListe
@Override
public void onDatePicked(int resultCode, Date date) {
switch(resultCode){
case START_DATE_RESULT:
case DatePicker.START_DATE_RESULT:
mStartDateField.setText(date.getYear()+"-"+date.getMonth()+"-"+date.getDay()+" "+date.getHour()+":"+date.getMinute()+":"+date.getSecond());
break;
case END_DATE_RESULT:
case DatePicker.END_DATE_RESULT:
mEndDateField.setText(date.getYear()+"-"+date.getMonth()+"-"+date.getDay()+" "+date.getHour()+":"+date.getMinute()+":"+date.getSecond());
break;
}

View File

@@ -16,6 +16,7 @@ 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;
@@ -24,6 +25,10 @@ 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
@@ -36,6 +41,9 @@ public class SettingsPanel extends JPanel implements ActionListener {
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;
@@ -44,6 +52,8 @@ public class SettingsPanel extends JPanel implements ActionListener {
private JButton mSaveButton;
private JCheckBox mUseRemoteDatabase;
private Properties mProps;
private JTextField mDatabaseName;
private JCheckBox mSavePassword;
/**
* Creates a new SettingsPanel
@@ -53,59 +63,85 @@ public class SettingsPanel extends JPanel implements ActionListener {
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);
mPortNumber.setText("3306");
JLabel lblMysql = new JLabel("MYsql serevr username:");
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);
mPortNumber.setEnabled(false);
mUserName.setEnabled(false);
mUserPassword.setEnabled(false);
mSaveButton = new JButton("Save");
//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(mUseRemoteDatabase)
.addComponent(mSavePassword)
.addContainerGap())
.addGroup(groupLayout.createSequentialGroup()
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addComponent(lblMysqlServerLocation)
.addComponent(lblMysqlServerPort)
.addComponent(lblMysql)
.addComponent(lblMysqlServerPassword))
.addComponent(lblDatabaseName)
.addComponent(lblMysql))
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
.addComponent(mServerLocation)
.addComponent(mSaveButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(mUserPassword)
.addComponent(mUserName)
.addComponent(mPortNumber))
.addContainerGap(139, Short.MAX_VALUE))))
.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)
@@ -121,27 +157,30 @@ public class SettingsPanel extends JPanel implements ActionListener {
.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(lblMysql)
.addComponent(mUserName, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.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(142, Short.MAX_VALUE))
.addContainerGap(264, Short.MAX_VALUE))
);
setLayout(groupLayout);
// create and load default properties
mProps = new Properties();
mProps = new java.util.Properties();
try {
FileInputStream in = new FileInputStream(".settings.propertys");
FileInputStream in = new FileInputStream(PROPERTIES_FILE_NAME);
mProps.load(in);
in.close();
isUsingRemoteServer = Boolean.parseBoolean(mProps.getProperty(IS_USING_REMOTE_SERVER, "false"));
@@ -150,70 +189,102 @@ public class SettingsPanel extends JPanel implements ActionListener {
mServerLocation.setEnabled(true);
mPortNumber.setEnabled(true);
mUserName.setEnabled(true);
mUserPassword.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));;
mUserName.setText(mProps.getProperty(SERVER_USERNAME));;
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(SERVER_PASSWORD, new String(mUserPassword.getPassword()));
try {
FileOutputStream out = new FileOutputStream(".settings.propertys");
mProps.store(out, "---No Comment---");
out.close();
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-gene1rated catch block
e1.printStackTrace();
}
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()));
try {
FileOutputStream out = new FileOutputStream(".settings.propertys");
mProps.store(out, "---No Comment---");
out.close();
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
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();
}
}
}

View File

@@ -21,7 +21,7 @@ import javax.swing.JProgressBar;
import com.TwentyCodes.java.OrderProcessor.ProgressListener;
/**
* This panel will be used to display all Vehicles in the VechicleDB
* This panel will be used to display all orders in the order database
*/
public class ShowAllPanel extends JPanel implements ActionListener, ProgressListener {
@@ -29,6 +29,8 @@ public class ShowAllPanel extends JPanel implements ActionListener, ProgressList
private JProgressBar mProgressBar;
private OrderPane mOutput;
private JFrame mFrame;
private JButton ok;
private JButton clear;
/**
* Creates a new ShowAllDialog
@@ -37,52 +39,73 @@ public class ShowAllPanel extends JPanel implements ActionListener, ProgressList
super(new BorderLayout());
mFrame = frame;
JPanel panel = new JPanel();
// setTitle("Show All Orders");
// setIconImage(new ImageIcon(getClass().getResource("/database.png")).getImage());
JButton ok = new JButton("Refresh", new ImageIcon(getClass().getResource("/process.png")));
//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(ok, BorderLayout.NORTH);
mProgressBar.setString("Loading from Database");
add(panel, BorderLayout.NORTH);
mProgressBar.setStringPainted(true);
try {
MainWindow.db.setOnProgressListerner(this);
} catch (NullPointerException e) {
e.printStackTrace();
mOutput.setText("Database not initialized");
}
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 arg0) {
java.util.concurrent.Executors.newSingleThreadExecutor().submit(new Runnable() {
public void run() {
try {
mOutput.displayOrders(MainWindow.db.getAllOrders());
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
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();
}
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);

View File

@@ -0,0 +1,63 @@
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.1.6 b 51
added status PAYMENT_DECLINED
1.1.7 b 52
added a checkout button to the Main Panel. It allows the user to "checkout" a remote database to a local database
removed the warning label from main panel, and moved all messages to the progress bar

View File

@@ -0,0 +1 @@
1.1.7 b 52