From f9a805803cb9c3392c39ccc287403c2017d85d93 Mon Sep 17 00:00:00 2001 From: ricky barrette Date: Sat, 22 Jan 2011 20:33:57 +0000 Subject: [PATCH] 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 --- Order Processor/.settings.propertys | 4 +- .../java/OrderProcessor/DB/OrderDB.java | 124 +++++++++++------- .../TwentyCodes/java/OrderProcessor/Main.java | 1 - .../java/OrderProcessor/Status.java | 19 ++- .../java/OrderProcessor/TextStyle.java | 2 +- .../java/OrderProcessor/UI/DatePicker.java | 37 ++++-- .../java/OrderProcessor/UI/OrderPane.java | 42 +++--- .../java/OrderProcessor/UI/SearchPanel.java | 45 +------ Order Processor/version infomation/changelog | 9 +- Order Processor/version infomation/version | 2 +- 10 files changed, 169 insertions(+), 116 deletions(-) diff --git a/Order Processor/.settings.propertys b/Order Processor/.settings.propertys index e4e76ec..d8a4d9a 100644 --- a/Order Processor/.settings.propertys +++ b/Order Processor/.settings.propertys @@ -1,7 +1,7 @@ #---No Comment--- -#Thu Jan 20 12:15:15 EST 2011 +#Sat Jan 22 14:59:35 EST 2011 server_parrword=S35-2n6t -use_remote_server=true server_location=tcdevsvn1 +use_remote_server=true server_port_number=3306 server_user_name=ricky.barrette diff --git a/Order Processor/src/com/TwentyCodes/java/OrderProcessor/DB/OrderDB.java b/Order Processor/src/com/TwentyCodes/java/OrderProcessor/DB/OrderDB.java index ed1f0ef..d93e99a 100644 --- a/Order Processor/src/com/TwentyCodes/java/OrderProcessor/DB/OrderDB.java +++ b/Order Processor/src/com/TwentyCodes/java/OrderProcessor/DB/OrderDB.java @@ -32,6 +32,7 @@ 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; /** @@ -88,43 +89,6 @@ public class OrderDB { conn.close(); } - /** - * 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(".settings.propertys"); - props.load(in); - in.close(); - return props; - } catch (IOException e1) { - e1.printStackTrace(); - } - return props; - } - - /** - * 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; - } - /** * added the order to the database * @param order @@ -139,13 +103,70 @@ 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()); + 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(); + Statement stat = conn.createStatement(); + ResultSet rs = stat.executeQuery("select * from Orders;"); + 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 @@ -223,6 +244,24 @@ public class OrderDB { 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(".settings.propertys"); + 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 @@ -233,14 +272,13 @@ public class OrderDB { * @throws OrderExistsException */ public void load(File file) throws SQLException, IOException, ClassNotFoundException{ - -// Scanner scan = new Scanner(file); + prep = null; list = null; CSVParser csvParser = new CSVParser(new FileInputStream(file)); list = new ArrayList(getAllOrders()); - + int line = 1; int lineCount = countLines(file); isLoadingFile = true; @@ -267,7 +305,6 @@ public class OrderDB { e.printStackTrace(); } - } } catch (Exception e) { e.printStackTrace(); @@ -276,9 +313,9 @@ public class OrderDB { prep.close(); conn.close(); isLoadingFile = false; + } - /** * saves an order to the database * @param order @@ -297,7 +334,6 @@ public class OrderDB { prep.setBytes(1, bos.toByteArray()); prep.executeUpdate(); -// prep.addBatch(); } /** diff --git a/Order Processor/src/com/TwentyCodes/java/OrderProcessor/Main.java b/Order Processor/src/com/TwentyCodes/java/OrderProcessor/Main.java index 7278ddd..7d87a97 100644 --- a/Order Processor/src/com/TwentyCodes/java/OrderProcessor/Main.java +++ b/Order Processor/src/com/TwentyCodes/java/OrderProcessor/Main.java @@ -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 diff --git a/Order Processor/src/com/TwentyCodes/java/OrderProcessor/Status.java b/Order Processor/src/com/TwentyCodes/java/OrderProcessor/Status.java index 1a47266..23bdb7d 100644 --- a/Order Processor/src/com/TwentyCodes/java/OrderProcessor/Status.java +++ b/Order Processor/src/com/TwentyCodes/java/OrderProcessor/Status.java @@ -37,7 +37,18 @@ 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; + ; /** @@ -64,6 +75,12 @@ 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; return null; diff --git a/Order Processor/src/com/TwentyCodes/java/OrderProcessor/TextStyle.java b/Order Processor/src/com/TwentyCodes/java/OrderProcessor/TextStyle.java index 7b4cd8c..6fc8710 100644 --- a/Order Processor/src/com/TwentyCodes/java/OrderProcessor/TextStyle.java +++ b/Order Processor/src/com/TwentyCodes/java/OrderProcessor/TextStyle.java @@ -12,6 +12,6 @@ package com.TwentyCodes.java.OrderProcessor; */ public enum TextStyle { - BOLD, ITALIC, REGULAR, RED, GREEN + BOLD, ITALIC, REGULAR, RED, BLUE } \ No newline at end of file diff --git a/Order Processor/src/com/TwentyCodes/java/OrderProcessor/UI/DatePicker.java b/Order Processor/src/com/TwentyCodes/java/OrderProcessor/UI/DatePicker.java index 7777711..6cbf477 100644 --- a/Order Processor/src/com/TwentyCodes/java/OrderProcessor/UI/DatePicker.java +++ b/Order Processor/src/com/TwentyCodes/java/OrderProcessor/UI/DatePicker.java @@ -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(); diff --git a/Order Processor/src/com/TwentyCodes/java/OrderProcessor/UI/OrderPane.java b/Order Processor/src/com/TwentyCodes/java/OrderProcessor/UI/OrderPane.java index 82ab3f0..46e7969 100644 --- a/Order Processor/src/com/TwentyCodes/java/OrderProcessor/UI/OrderPane.java +++ b/Order Processor/src/com/TwentyCodes/java/OrderProcessor/UI/OrderPane.java @@ -55,23 +55,32 @@ public class OrderPane extends JScrollPane { BigDecimal possible = new BigDecimal(0); BigDecimal actual = new BigDecimal(0); int total = 0; - for (Order item : list) { - if(mListener != null) - mListener.onProgressUpdate("Processing Order: "+ (total+1) +" of "+ list.size(), false, total, list.size()); - - switch (item.getFulfillmentStatus()) { - case WILL_NOT_DELIVER: - styles.add(TextStyle.RED.toString()); - break; - default: + + for (int i = 0; i < list.size(); i++) { + if(mListener != null) + mListener.onProgressUpdate("Processing Order: "+ (i+1) +" of "+ list.size(), false, i, list.size()); + + try { + switch (list.get(i).getFulfillmentStatus()) { + case WILL_NOT_DELIVER: + styles.add(TextStyle.RED.toString()); + break; + case NEW: + styles.add(TextStyle.BLUE.toString()); + break; + default: + styles.add(TextStyle.REGULAR.toString()); + total++; + actual = actual.add(new BigDecimal((list.get(i).getAmountCharged()))); + } + } catch (Exception e) { + e.printStackTrace(); styles.add(TextStyle.REGULAR.toString()); - total++; + } + possible = possible.add(new BigDecimal((list.get(i).getOrderAmount()))); + } - possible = possible.add(new BigDecimal(item.getOrderAmount())); - actual = actual.add(new BigDecimal(item.getAmountCharged())); - } - 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); } @@ -151,8 +160,9 @@ 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); } /** diff --git a/Order Processor/src/com/TwentyCodes/java/OrderProcessor/UI/SearchPanel.java b/Order Processor/src/com/TwentyCodes/java/OrderProcessor/UI/SearchPanel.java index 69e65bd..ff64f3a 100644 --- a/Order Processor/src/com/TwentyCodes/java/OrderProcessor/UI/SearchPanel.java +++ b/Order Processor/src/com/TwentyCodes/java/OrderProcessor/UI/SearchPanel.java @@ -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,13 +43,10 @@ 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; @@ -120,6 +115,8 @@ 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()); @@ -220,8 +217,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 list = null; @@ -239,18 +234,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 +255,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 +266,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 +311,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; } diff --git a/Order Processor/version infomation/changelog b/Order Processor/version infomation/changelog index 84d9fcd..dcce478 100644 --- a/Order Processor/version infomation/changelog +++ b/Order Processor/version infomation/changelog @@ -21,4 +21,11 @@ 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 \ No newline at end of file +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 \ No newline at end of file diff --git a/Order Processor/version infomation/version b/Order Processor/version infomation/version index 34d85be..54d1b07 100644 --- a/Order Processor/version infomation/version +++ b/Order Processor/version infomation/version @@ -1 +1 @@ -1.0.6 b 34 \ No newline at end of file +1.1.0 b 35 \ No newline at end of file