finetuned the export feature

This commit is contained in:
2011-01-13 17:44:37 +00:00
parent 239218f6d4
commit 6113cde0d4

View File

@@ -16,6 +16,7 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Scanner;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JButton; import javax.swing.JButton;
@@ -154,9 +155,21 @@ public class SearchDialog extends JFrame implements ActionListener, ProgressList
*/ */
private boolean exportToCSV() { private boolean exportToCSV() {
if(fc.showDialog(SearchDialog.this, "Export") == JFileChooser.APPROVE_OPTION){ if(fc.showDialog(SearchDialog.this, "Export") == JFileChooser.APPROVE_OPTION){
StringBuffer sb = new StringBuffer("Order Number, Time & date, Product Name, Order Amount, Amount Charged, Financial Status, Fulfillment Status, Customer Name, Customer Email"); //prep the data for proper csv format
sb.append(mOrderPanel.getText()); StringBuffer sb = new StringBuffer("Order Number,Time & date,Product Name,Order Amount,Amount Charged,Financial Status,Fulfillment Status,Customer Name,Customer Email");
Scanner scan = new Scanner(mOrderPanel.getText());
String[] parts;
String line;
while(scan.hasNext()){
line = scan.nextLine();
parts = line.split(",");
try {
sb.append(parts[0].substring(1)+","+parts[1].substring(1)+","+parts[2].substring(1)+","+parts[3].substring(1)+","+parts[4].substring(1)+","+parts[5].substring(1)+","+parts[6].substring(1)+","+parts[7].substring(1)+","+parts[8].substring(1)+"\n");
} catch (Exception e) {
sb.append(line+"\n");
}
}
//write to the selceted file
try { try {
FileOutputStream theFile; FileOutputStream theFile;
if (fcCheckBox.isSelected()) if (fcCheckBox.isSelected())
@@ -214,7 +227,6 @@ public class SearchDialog extends JFrame implements ActionListener, ProgressList
mOrderPanel.setOnProgressListerner(SearchDialog.this); mOrderPanel.setOnProgressListerner(SearchDialog.this);
mOrderPanel.displayOrders(list); mOrderPanel.displayOrders(list);
//todo updates order panel
isProcessing = false; isProcessing = false;
pack(); pack();