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:
@@ -1,7 +1,7 @@
|
||||
#---Order Processor Settings---
|
||||
#Tue Feb 08 11:33:05 EST 2011
|
||||
#Wed Feb 09 13:48:50 EST 2011
|
||||
database_name=Orders
|
||||
server_parrword=3qR0VY2ngKq+4rxX59oRtmHOIBKKLb96
|
||||
server_parrword=Ekf4syi+03SEjxLksxRbuuxV4qpKog5G
|
||||
save_password=true
|
||||
use_remote_server=true
|
||||
server_location=tcdevsvn1
|
||||
|
||||
@@ -35,6 +35,7 @@ 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;
|
||||
|
||||
/**
|
||||
@@ -51,7 +52,7 @@ public class OrderDB {
|
||||
private PreparedStatement prep;
|
||||
private String dbLocation;
|
||||
private boolean isLoadingFile = false;
|
||||
private ArrayList<Order> list;
|
||||
private ArrayList<Order> mList;
|
||||
private boolean isUsingRemoteDatabase;
|
||||
|
||||
/**
|
||||
@@ -144,7 +145,7 @@ public class OrderDB {
|
||||
/*
|
||||
* 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.getFulfillmentStatus() == Status.NEW )
|
||||
@@ -152,11 +153,65 @@ public class OrderDB {
|
||||
else
|
||||
throw new OrderExistsException(order.toString());
|
||||
|
||||
list.add(order);
|
||||
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
|
||||
@@ -245,19 +300,6 @@ public class OrderDB {
|
||||
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
|
||||
@@ -314,6 +356,19 @@ 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
|
||||
@@ -344,10 +399,10 @@ public class OrderDB {
|
||||
public void load(File file) throws SQLException, IOException, ClassNotFoundException{
|
||||
|
||||
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);
|
||||
|
||||
@@ -46,11 +46,12 @@ public class MainWindow extends JFrame implements ActionListener, ProgressListen
|
||||
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
|
||||
@@ -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.addActionListener(this);
|
||||
|
||||
mWarningLabel = new JLabel("");
|
||||
// mWarningLabel = new JLabel("");
|
||||
orderCountLabel = new JLabel("");
|
||||
|
||||
panel.add(new JLabel("Total Orders in the database:"));
|
||||
@@ -118,7 +119,12 @@ public class MainWindow extends JFrame implements ActionListener, ProgressListen
|
||||
mConnectButton.addActionListener(this);
|
||||
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
|
||||
mProgressBar = new JProgressBar();
|
||||
@@ -161,28 +167,25 @@ public class MainWindow extends JFrame implements ActionListener, ProgressListen
|
||||
try {
|
||||
db = isUsingRemoteServer ? new OrderDB(new String(mPassWord.getPassword())) : new OrderDB();
|
||||
orderCountLabel.setText(db.getCount()+"");
|
||||
mWarningLabel.setText("Connected");
|
||||
mProgressBar.setString("Connected");
|
||||
mPassWord.setEnabled(false);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
mWarningLabel.setText(e.getMessage());
|
||||
mWarningLabel.setVisible(true);
|
||||
mProgressBar.setString(e.getMessage());
|
||||
mConnectButton.setEnabled(true);
|
||||
orderCountLabel.setText("");
|
||||
} catch (SocketException e) {
|
||||
mWarningLabel.setText(e.getMessage());
|
||||
mWarningLabel.setVisible(true);
|
||||
mProgressBar.setString(e.getMessage());
|
||||
mConnectButton.setEnabled(true);
|
||||
orderCountLabel.setText("");
|
||||
} catch (NullPointerException e){
|
||||
mWarningLabel.setText("Database not avilable");
|
||||
mWarningLabel.setVisible(true);
|
||||
mProgressBar.setString("Database not avilable");
|
||||
mConnectButton.setEnabled(true);
|
||||
orderCountLabel.setText("");
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
mProgressBar.setString(mWarningLabel.getText());
|
||||
mCheckout.setEnabled( (isUsingRemoteServer && ! mConnectButton.isEnabled()) );
|
||||
mProgressBar.setIndeterminate(false);
|
||||
}
|
||||
});
|
||||
@@ -233,6 +236,25 @@ public class MainWindow extends JFrame implements ActionListener, ProgressListen
|
||||
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();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -257,7 +279,7 @@ public class MainWindow extends JFrame implements ActionListener, ProgressListen
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SocketException e) {
|
||||
mWarningLabel.setText(e.getMessage());
|
||||
mProgressBar.setString(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,3 +57,7 @@ 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
|
||||
|
||||
@@ -1 +1 @@
|
||||
1.1.6 b 51
|
||||
1.1.7 b 52
|
||||
Reference in New Issue
Block a user