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
This commit is contained in:
2011-02-09 18:50:45 +00:00
parent d5d2221fb2
commit 8749006ea5
5 changed files with 115 additions and 34 deletions

View File

@@ -1,7 +1,7 @@
#---Order Processor Settings--- #---Order Processor Settings---
#Tue Feb 08 11:33:05 EST 2011 #Wed Feb 09 13:48:50 EST 2011
database_name=Orders database_name=Orders
server_parrword=3qR0VY2ngKq+4rxX59oRtmHOIBKKLb96 server_parrword=Ekf4syi+03SEjxLksxRbuuxV4qpKog5G
save_password=true save_password=true
use_remote_server=true use_remote_server=true
server_location=tcdevsvn1 server_location=tcdevsvn1

View File

@@ -35,6 +35,7 @@ import com.TwentyCodes.java.OrderProcessor.Order;
import com.TwentyCodes.java.OrderProcessor.OrderExistsException; import com.TwentyCodes.java.OrderProcessor.OrderExistsException;
import com.TwentyCodes.java.OrderProcessor.ProgressListener; import com.TwentyCodes.java.OrderProcessor.ProgressListener;
import com.TwentyCodes.java.OrderProcessor.Status; import com.TwentyCodes.java.OrderProcessor.Status;
import com.TwentyCodes.java.OrderProcessor.UI.MainWindow;
import com.TwentyCodes.java.OrderProcessor.UI.SettingsPanel; import com.TwentyCodes.java.OrderProcessor.UI.SettingsPanel;
/** /**
@@ -51,7 +52,7 @@ public class OrderDB {
private PreparedStatement prep; private PreparedStatement prep;
private String dbLocation; private String dbLocation;
private boolean isLoadingFile = false; private boolean isLoadingFile = false;
private ArrayList<Order> list; private ArrayList<Order> mList;
private boolean isUsingRemoteDatabase; private boolean isUsingRemoteDatabase;
/** /**
@@ -144,7 +145,7 @@ public class OrderDB {
/* /*
* check the current database for an orders with a matching order number * check the current database for an orders with a matching order number
*/ */
for(Order item : list) for(Order item : mList)
if(item.getGoogleOrderNumber() == order.getGoogleOrderNumber()) if(item.getGoogleOrderNumber() == order.getGoogleOrderNumber())
if(item.getFulfillmentStatus() == Status.NEW ) if(item.getFulfillmentStatus() == Status.NEW )
@@ -152,11 +153,65 @@ public class OrderDB {
else else
throw new OrderExistsException(order.toString()); throw new OrderExistsException(order.toString());
list.add(order); mList.add(order);
saveOrder(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 * counts the number of lines in a csv file
* @param file to be read * @param file to be read
@@ -171,7 +226,7 @@ public class OrderDB {
cnt++; cnt++;
return cnt; return cnt;
} }
/** /**
* deletes the old order that IS BEING replaced * deletes the old order that IS BEING replaced
* @throws SQLException * @throws SQLException
@@ -244,19 +299,6 @@ public class OrderDB {
Collections.sort(list); Collections.sort(list);
return 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 * gets the connection to the data base
@@ -314,6 +356,19 @@ public class OrderDB {
return count; 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 * gets the properties from the properties file
* @return properties * @return properties
@@ -344,10 +399,10 @@ public class OrderDB {
public void load(File file) throws SQLException, IOException, ClassNotFoundException{ public void load(File file) throws SQLException, IOException, ClassNotFoundException{
prep = null; prep = null;
list = null; mList = null;
CSVParser csvParser = new CSVParser(new FileInputStream(file)); CSVParser csvParser = new CSVParser(new FileInputStream(file));
list = new ArrayList<Order>(getAllOrders()); mList = new ArrayList<Order>(getAllOrders());
int line = 1; int line = 1;
int lineCount = countLines(file); int lineCount = countLines(file);

View File

@@ -46,11 +46,12 @@ public class MainWindow extends JFrame implements ActionListener, ProgressListen
private String mCurrentFile; private String mCurrentFile;
private UncaughtExceptionHandler mExceptionReport = new UncaughtExceptionHandler(this.getClass()); private UncaughtExceptionHandler mExceptionReport = new UncaughtExceptionHandler(this.getClass());
private static JLabel orderCountLabel; private static JLabel orderCountLabel;
private static JLabel mWarningLabel; // private static JLabel mWarningLabel;
private static JButton mConnectButton; private static JButton mConnectButton;
private static JPasswordField mPassWord; private static JPasswordField mPassWord;
private static boolean isUsingRemoteServer; private static boolean isUsingRemoteServer;
private JLabel lblDatabasePassword; private JLabel lblDatabasePassword;
private static JButton mCheckout;
/** /**
* Creates a new MainWindow * Creates a new MainWindow
@@ -98,7 +99,7 @@ public class MainWindow extends JFrame implements ActionListener, ProgressListen
mLoadFileButton = new JButton("Load File", new ImageIcon(getClass().getResource("/database_add.png"))); mLoadFileButton = new JButton("Load File", new ImageIcon(getClass().getResource("/database_add.png")));
mLoadFileButton.addActionListener(this); mLoadFileButton.addActionListener(this);
mWarningLabel = new JLabel(""); // mWarningLabel = new JLabel("");
orderCountLabel = new JLabel(""); orderCountLabel = new JLabel("");
panel.add(new JLabel("Total Orders in the database:")); panel.add(new JLabel("Total Orders in the database:"));
@@ -118,7 +119,12 @@ public class MainWindow extends JFrame implements ActionListener, ProgressListen
mConnectButton.addActionListener(this); mConnectButton.addActionListener(this);
panel.add(mConnectButton); panel.add(mConnectButton);
panel.add(mWarningLabel); 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 //progress bar
mProgressBar = new JProgressBar(); mProgressBar = new JProgressBar();
@@ -161,28 +167,25 @@ public class MainWindow extends JFrame implements ActionListener, ProgressListen
try { try {
db = isUsingRemoteServer ? new OrderDB(new String(mPassWord.getPassword())) : new OrderDB(); db = isUsingRemoteServer ? new OrderDB(new String(mPassWord.getPassword())) : new OrderDB();
orderCountLabel.setText(db.getCount()+""); orderCountLabel.setText(db.getCount()+"");
mWarningLabel.setText("Connected"); mProgressBar.setString("Connected");
mPassWord.setEnabled(false); mPassWord.setEnabled(false);
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
mWarningLabel.setText(e.getMessage()); mProgressBar.setString(e.getMessage());
mWarningLabel.setVisible(true);
mConnectButton.setEnabled(true); mConnectButton.setEnabled(true);
orderCountLabel.setText(""); orderCountLabel.setText("");
} catch (SocketException e) { } catch (SocketException e) {
mWarningLabel.setText(e.getMessage()); mProgressBar.setString(e.getMessage());
mWarningLabel.setVisible(true);
mConnectButton.setEnabled(true); mConnectButton.setEnabled(true);
orderCountLabel.setText(""); orderCountLabel.setText("");
} catch (NullPointerException e){ } catch (NullPointerException e){
mWarningLabel.setText("Database not avilable"); mProgressBar.setString("Database not avilable");
mWarningLabel.setVisible(true);
mConnectButton.setEnabled(true); mConnectButton.setEnabled(true);
orderCountLabel.setText(""); orderCountLabel.setText("");
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} }
mProgressBar.setString(mWarningLabel.getText()); mCheckout.setEnabled( (isUsingRemoteServer && ! mConnectButton.isEnabled()) );
mProgressBar.setIndeterminate(false); mProgressBar.setIndeterminate(false);
} }
}); });
@@ -233,6 +236,25 @@ public class MainWindow extends JFrame implements ActionListener, ProgressListen
if(e.getSource() == mConnectButton){ if(e.getSource() == mConnectButton){
loadDatabase(); 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();
}
}
});
} }
/** /**
@@ -257,7 +279,7 @@ public class MainWindow extends JFrame implements ActionListener, ProgressListen
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} catch (SocketException e) { } catch (SocketException e) {
mWarningLabel.setText(e.getMessage()); mProgressBar.setString(e.getMessage());
} }
} }
} }

View File

@@ -57,3 +57,7 @@ slight modification to order pane updateTextPane() s
1.1.6 b 51 1.1.6 b 51
added status PAYMENT_DECLINED 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

@@ -1 +1 @@
1.1.6 b 51 1.1.7 b 52