Clicky

Hi All,
I have a Netbeans project which is to convert two csv files into the correct format for input into our database.  The postcode is usually the code for the company in the database, except where there is no proper postcode as its going to Ireland where there is a separate csv file which gives the correct code for that destination.  However, I also have a problem with some postcodes where there is the same postcode for two different destinations - in that case we have to change it to a code which is unique to the destination.  Is it possible to add a bean to this project that if the code is in the list which would ideally be in a separate csv file, it looks it up and in the same row the destination name, and it changes the code in the new csv to the unique code for that destination? It would have to do it in Indata and Outdata.  Any help would be appreciated! Thanks
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package imoprtconverter;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;
import java.util.ArrayList;
/**
 *
 * @author rellis
 */
public class OutDataScanner {
    public static Set<OutData> readFile(File fileName) {
        Set<OutData> outDataFile = new TreeSet<OutData>();
        try {
            Scanner scanner = new Scanner(fileName);
            scanner.useDelimiter(System.getProperty("line.separator"));
            ArrayList<String> header = readHeader(scanner.next());
            while (scanner.hasNext()) {
                OutData newOutData = parseLine(header, scanner.next());
                if (newOutData != null)
                {
                    outDataFile.add(newOutData);
                }
            }
            scanner.close();
        }
        catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        return outDataFile;
    }
    public static Set<OutData> readFile(File fileName, Set<OutData> oldOutDataFile) {
        Set<OutData> outDataFile;
        if (oldOutDataFile.isEmpty()) { outDataFile = new TreeSet<OutData>(); }
        else { outDataFile = oldOutDataFile; }
        try {
            Scanner scanner = new Scanner(fileName);
            scanner.useDelimiter(System.getProperty("line.separator"));
            ArrayList<String> header = readHeader(scanner.next());
            while (scanner.hasNext()) {
                OutData newOutData = parseLine(header, scanner.next());
                if (newOutData != null)
                {
                    outDataFile.add(newOutData);
                }
            }
            scanner.close();
        }
        catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        return outDataFile;
    }
    private static  ArrayList<String> readHeader(String line)
    {
        ArrayList<String> header = new ArrayList<String>();
        Scanner lineScanner = new Scanner(line);
        lineScanner.useDelimiter(",");
        while (lineScanner.hasNext()) {
            header.add(lineScanner.next().replace('"', ' ').trim());
        }
        return header;
    }

    private static OutData parseLine( ArrayList<String> header, String line) {
        Scanner lineScanner = new Scanner(line);
        lineScanner.useDelimiter(",");
        String MDC = "", div = "", orderNo = "", pickTicket = "", PONo = "", 
            invoiceNo = "", currency = "", price = "", noOfCartons = "",
            units = "", weight = "", soldTo = "", shipTo = "",
            shipToName = "", shipToAddress1 = "", shipToAddress2 = "",
            shipToCity = "", shipToPostCode = "", shipToTelephone = "";

        int i = 0;
        while (lineScanner.hasNext() && i < header.size()) {
            String field = lineScanner.next();
            if (field.startsWith(""") && (!field.endsWith("""))
                  && lineScanner.hasNext())
            {
                field = field.replace('"', ' ').trim();
                String nextField = lineScanner.next();
                while (!nextField.endsWith("""))
                {
                    field = field + " " + nextField;
                    nextField = lineScanner.next();
                }
            }
            else
            {
                field = field.replace('"', ' ').trim();
            }
            if (header.get(i).equals("Manifest Date Customer")
                 || header.get(i).equals("Manifest/Date/Cust"))
            {
                MDC = field;
            }
            if (header.get(i).equals("Division")
                   || header.get(i).equals("Div"))
            {
                div = field;
            }
            else if (header.get(i).equals("Order Number")
                    || header.get(i).equals("Order"))
            {
                orderNo = field;
            }
            else if (header.get(i).equals("PickTicket / Reference")
                    || header.get(i).equals("PT"))
            {
                pickTicket = field;
            }
            else if (header.get(i).equals("Customer PO Number")
                    || header.get(i).equals("PO Number"))
            {
                PONo = field;
            }
            else if (header.get(i).equals("Invoice Number")
                    || header.get(i).equals("Invoice"))
            {
                invoiceNo = field;
            }
            else if (header.get(i).equals("Currency")
                    || header.get(i).equals("Cur"))
            {
                currency = field;
            }
            else if (header.get(i).equals("Price")
                    || header.get(i).equals("PRICE TOTAL"))
            {
                try
                {
                    price = Double.toString(Double.parseDouble(field));
                }
                catch(NumberFormatException nfe)
                {
                    price = field;
                }
            }
            else if (header.get(i).equals("Total Cartons")
                    || header.get(i).equals("Ctns"))
            {
                try
                {
                    noOfCartons = Integer.toString((int) Double.parseDouble(field));
                }
                catch(NumberFormatException nfe)
                {
                    noOfCartons = field;
                }
            }
            else if (header.get(i).equals("Total Units")
                    || header.get(i).equals("units"))
            {
                try
                {
                    units = Integer.toString((int) Double.parseDouble(field));
                }
                catch(NumberFormatException nfe)
                {
                    units = field;
                }
            }
            else if (header.get(i).equals("Weights")
                    || header.get(i).equals("Weight"))
            {
                try
                {
                    weight = Double.toString(Double.parseDouble(field));
                }
                catch(NumberFormatException nfe)
                {
                    weight = field;
                }
            }
            else if (header.get(i).equals("Ship To"))
            {
                shipTo = field;
            }
            else if (header.get(i).equals("Sold To"))
            {
                soldTo = field;
            }
            else if (header.get(i).equals("Name"))
            {
                shipToName = field;
            }
            else if (header.get(i).equals("Address 1st Line")
                    || header.get(i).equals("Address Line 1"))
            {
                shipToAddress1 = field;
            }
            else if (header.get(i).equals("Address 2nd Line")
                    || header.get(i).equals("Address Line 2"))
            {
                shipToAddress2 = field;
            }
            else if (header.get(i).equals("City"))
            {
                shipToCity = field;
            }
             else if (header.get(i).equals("Zip"))
            {
                shipToPostCode = field;
            }
            else if (header.get(i).equals("Telephone Number")
                    || header.get(i).equals("CUPHN"))
            {
                shipToTelephone = field;
            }
            i++;
        }
        OutData newOutData;
        if (!orderNo.equals(""))
        {
            newOutData = new OutData(MDC, div, orderNo, pickTicket, PONo,
                invoiceNo, currency, price, noOfCartons, units, weight,
                soldTo, shipTo, shipToName, shipToAddress1, shipToAddress2,
                shipToCity, shipToPostCode, shipToTelephone);
        }
        else
        {
            newOutData = null;
        }
        return newOutData;

    }
}
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package imoprtconverter;

/**
 *
 * @author rellis
 */
public class OutData implements Comparable {
    private String ManifestDateCustomer;
    private String div;
    private String orderNo;
    private String pickTicket;
    private String PONo;
    private String invoiceNo;
    private String currency;
    private String price;
    private String noOfCartons;
    private String units;
    private String weight;
    private String soldTo;
    private String shipTo;
    private String shipToName;
    private String shipToAddress1;
    private String shipToAddress2;
    private String shipToCity;
    private String originalPostCode;
    private String shipToPostCode;
    private String shipToTelephone;



    public OutData(String aMDC, String aDiv, String aOrderNo, String aPickTicket,
            String aPONo, String aInvoiceNo, String aCurrency, String aPrice,
            String aNoOfCartons, String aUnits, String aWeight, String aSoldTo,
            String aShipTo, String aShipToName, String aShipToAddress1,
            String aShipToAddress2,
            String aShipToCity, String aShipToPostCode, String aShipToTelephone)
    {
        ManifestDateCustomer = aMDC;
        div = aDiv;
        orderNo = aOrderNo;
        pickTicket = aPickTicket;
        PONo = aPONo;
        invoiceNo = aInvoiceNo;
        currency = aCurrency;
        price = aPrice;
        noOfCartons = aNoOfCartons;
        units = aUnits;
        weight = aWeight;
        soldTo = aSoldTo;
        shipTo = aShipTo;
        shipToName = aShipToName;
        shipToAddress1 = aShipToAddress1;
        shipToAddress2 = aShipToAddress2;
        shipToCity = aShipToCity;
        originalPostCode = aShipToPostCode;
        shipToPostCode = aShipToPostCode;
        if (shipToPostCode.equals("0") || shipToPostCode.equals("1")
               || shipToPostCode.equals("") )
        {
            shipToPostCode = shipToName;
        }
        shipToTelephone = aShipToTelephone;
    }
    public String[] getarray()
    {
        return new String[]{getManifestDateCustomer(), getDiv(), getOrderNo(), getPickTicket(),
            getPONo(), getInvoiceNo(), getCurrency(), getPrice(),
            getNoOfCartons(), getUnits(), getWeight(),
            getSoldTo(), getShipTo(), getShipToName(),
            getShipToAddress1(), getShipToAddress2(), getShipToCity(),
            getShipToPostCode(), getShipToTelephone()};
    }

    public boolean equals(OutData other)
    {
        if (!(this.getPickTicket()).equals(other.getPickTicket()))
        {
            return false;
        }
        else
        {
            return true;
        }
    }

    public Boolean matchPostCodes() {
        Boolean r = false;
        if (getOriginalPostCode().equals("0") || getOriginalPostCode().equals("1")
               || getOriginalPostCode().equals("") )
        {
            if (PostCodes.contains(getShipToName()))
            {
                String newpc = PostCodes.getPostCode(getShipToName());
                if (!getShipToPostCode().equals(newpc))
                {
                    setShipToPostCode(newpc);
                    r = true;
                }
            }
        }
        return r;
    }

    public void setShipToPostCode(String aPostCode)
    {
        shipToPostCode = aPostCode;
    }
    public String getType()
    {
        String divType;
        if (Character.isDigit(this.getDiv().charAt(0)))
        {
            divType="A";
        }
        else { divType="F"; }
        String postCodeType;
        if (getOriginalPostCode().equals("0") || getOriginalPostCode().equals("1")
               || getOriginalPostCode().equals("") )
        {
            postCodeType = "I";
        }
        else
        {
            postCodeType = "U";
        }
        return divType + postCodeType;
    }
    @Override
    public String toString() {
        return "OutData[postCode=" + this.getShipToPostCode() + "]";
    }
    public int compareTo(Object other)
    {



        if (!(other instanceof OutData))
            throw new ClassCastException("A OutData expected");
        String otherC = ((OutData) other).getType()
                + ((OutData) other).getShipToPostCode()
                + ((OutData) other).getPickTicket();
        String thisC = this.getType()
                + this.getShipToPostCode()
                + this.getPickTicket();
        return otherC.compareTo(thisC);
    }

    /**
     * @return the div
     */
    public String getDiv() {
        return div;
    }


    /**
     * @return the ManifestDateCustomer
     */
    public String getManifestDateCustomer() {
        return ManifestDateCustomer;
    }

    /**
     * @return the orderNo
     */
    public String getOrderNo() {
        return orderNo;
    }

    /**
     * @return the pickTicket
     */
    public String getPickTicket() {
        return div+'0'+pickTicket.substring(0, 7);
    }

    /**
     * @return the PONo
     */
    public String getPONo() {
        return PONo;
    }

    /**
     * @return the invoiceNo
     */
    public String getInvoiceNo() {
        return invoiceNo;
    }

    /**
     * @return the currency
     */
    public String getCurrency() {
        return currency;
    }

    /**
     * @return the price
     */
    public String getPrice() {
        return currency + price;
    }

    /**
     * @return the noOfCartons
     */
    public String getNoOfCartons() {
        return noOfCartons;
    }

    /**
     * @return the units
     */
    public String getUnits() {
        return units;
    }

    /**
     * @return the weight
     */
    public String getWeight() {
        return weight;
    }

    /**
     * @return the soldTo
     */
    public String getSoldTo() {
        return soldTo;
    }

    /**
     * @return the shipTo
     */
    public String getShipTo() {
        return shipTo;
    }

    /**
     * @return the shipToName
     */
    public String getShipToName() {
        return shipToName;
    }

    /**
     * @return the shipToAddress1
     */
    public String getShipToAddress1() {
        return shipToAddress1;
    }

    /**
     * @return the shipToAddress2
     */
    public String getShipToAddress2() {
        return shipToAddress2;
    }

    /**
     * @return the shipToCity
     */
    public String getShipToCity() {
        return shipToCity;
    }

    /**
     * @return the shipToPostCode
     */
    public String getShipToPostCode() {
        return shipToPostCode;
    }

    /**
     * @return the originalPostCode
     */
    public String getOriginalPostCode() {
        return originalPostCode;
    }

    /**
     * @return the shipToTelephone
     */
    public String getShipToTelephone() {
        return shipToTelephone;
    }
}
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package imoprtconverter;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;
import java.util.ArrayList;
/**
 *
 * @author rellis
 */
public class InDataScanner {
    public static Set<InData> readFile(File fileName) {
        Set<InData> inDataFile = new TreeSet<InData>();
        try {
            Scanner scanner = new Scanner(fileName);
            scanner.useDelimiter(System.getProperty("line.separator"));
            ArrayList<String> header = readHeader(scanner.next());
            while (scanner.hasNext()) {
                InData newInData = parseLine(header, scanner.next());
                if (newInData != null)
                {
                    inDataFile.add(newInData);
                }
            }
            scanner.close();
        }
        catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        return inDataFile;
    }

    public static Set<InData> readFile(File fileName, Set<InData> oldInDataFile) {
        Set<InData> inDataFile;
        if (oldInDataFile.isEmpty()) { inDataFile = new TreeSet<InData>(); }
        else { inDataFile = oldInDataFile; }
        try {
            Scanner scanner = new Scanner(fileName);
            scanner.useDelimiter(System.getProperty("line.separator"));
            ArrayList<String> header = readHeader(scanner.next());
            while (scanner.hasNext()) {
                InData newInData = parseLine(header, scanner.next());
                if (newInData != null)
                {
                    inDataFile.add(newInData);
                }
            }
            scanner.close();
        }
        catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        return inDataFile;
    }

    private static  ArrayList<String> readHeader(String line)
    {
        ArrayList<String> header = new ArrayList<String>();
        Scanner lineScanner = new Scanner(line);
        lineScanner.useDelimiter(",");
        while (lineScanner.hasNext()) {
            header.add(lineScanner.next().replace('"', ' ').trim());
        }
        return header;
    }

    private static InData parseLine( ArrayList<String> header, String line) {
        Scanner lineScanner = new Scanner(line);
        lineScanner.useDelimiter(",");
        String plannedLoad = "", plannedShipment = "", div = "",
            pickTicket = "", aCS = "", soldTo  = "", shipTo = "",
            soldToName = "", shipToName = "", shipToAddr1 = "",
            shipToCity = "", shipToAddr3 = "", shipToPostCode = "",
            shipToCountry = "", custPO = "", palletId = "", shipDate = "",
            orderNo = "", units = "", postCode = "",
            cartonNo = "", weight = "";

        int i = 0;
        while (lineScanner.hasNext() && i < header.size()) {
            String field = lineScanner.next();
            if (field.startsWith(""") && (!field.endsWith("""))
                  && lineScanner.hasNext())
            {
                field = field.replace('"', ' ').trim();
                String nextField = lineScanner.next();
                while (!nextField.endsWith("""))
                {
                    field = field + " " + nextField;
                    nextField = lineScanner.next();
                }
            }
            else
            {
                field = field.replace('"', ' ').trim();
            }
            if (header.get(i).equals("Planned Load #"))
            {
                plannedLoad = field;
            }
            if (header.get(i).equals("Planned Shipment #"))
            {
                plannedShipment = field;
            }
            if ((header.get(i).equals("DIV"))
                    || (header.get(i).equals("DIV")))
            {
                div = field;
            }
            else if (header.get(i).equals("PICKTICKET")
                    || header.get(i).equals("Pickticket Control Number"))
            {
                pickTicket = field;
            }
            else if (header.get(i).equals("ACS"))
            {
                aCS = field;
            }
            else if (header.get(i).equals("SOLD_TO"))
            {
                soldTo = field;
            }
            else if (header.get(i).equals("SHIP_TO")
                    || header.get(i).equals("Ship-To"))
            {
                shipTo = field;
            }
            else if (header.get(i).equals("Sold-To Name"))
            {
                soldToName = field;
            }
            else if (header.get(i).equals("Ship To Name")
                    || header.get(i).equals("Ship-To Name"))
            {
                shipToName = field;
            }
            else if (header.get(i).equals("Address-1"))
            {
                shipToAddr1 = field;
            }
            else if (header.get(i).equals("City"))
            {
                shipToCity = field;
            }
            else if (header.get(i).equals("Address-3"))
            {
                shipToAddr3 = field;
            }
            else if (header.get(i).equals("Zip"))
            {
                postCode = field;
            }
            else if (header.get(i).equals("Shipto Country"))
            {
                shipToCountry = field;
            }
            else if (header.get(i).equals("Cust PO#"))
            {
                custPO = field;
            }
            else if (header.get(i).equals("Ship Date"))
            {
                shipDate = field;
            }
            else if (header.get(i).equals("Pallet ID"))
            {
                palletId = field;
            }
            else if (header.get(i).equals("Order Number"))
            {
                orderNo = field;
            }
            else if (header.get(i).equals("Tot Nbr Of Units"))
            {
                try
                {
                    units = Integer.toString((int) Double.parseDouble(field));
                }
                catch(NumberFormatException nfe)
                {
                    units = field;
                }
            }
            else if (header.get(i).equals("Carton Number"))
            {
                cartonNo = field;
            }
            else if (header.get(i).equals("Actual Weight"))
            {
                try
                {
                    weight = Double.toString(Double.parseDouble(field));
                }
                catch(NumberFormatException nfe)
                {
                    weight = field;
                }
            }
            i++;
        }

        InData newInData;
        if (!cartonNo.equals(""))
        {
            newInData = new InData(plannedLoad, plannedShipment, div,
            pickTicket, aCS, soldTo, shipTo, soldToName, shipToName,
            shipToAddr1, shipToCity, shipToAddr3, shipToPostCode,
            shipToCountry, custPO, palletId, shipDate, orderNo, units,
            cartonNo, weight, postCode);

        }
        else
        {
            newInData = null;
        }
        return newInData;
    }
}
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package imoprtconverter;

/**
 *
 * @author rellis
 */
public class InData implements Comparable {
    private String plannedLoad;
    private String plannedShipment;
    private String div;
    private String pickTicket;
    private String aCS;
    private String soldTo;
    private String shipTo;
    private String soldToName;
    private String shipToName;
    private String shipToAddr1;
    private String shipToCity;
    private String shipToAddr3;
    private String shipToPostCode;
    private String shipToCountry;
    private String custPO;
    private String palletId;
    private String shipDate;
    private String orderNo;
    private String units;
    private String cartonNo;
    private String weight;

    public InData(String aPlannedLoad, String aPlannedShipment, String aDiv,
            String aPickTicket, String aACS, String aSoldTo, String aShipTo,
            String aSoldToName, String aShipToName, String aShipToAddr1,
            String aShipToCity, String aShipToAddr3, String aShipToPostCode,
            String aShipToCountry, String aCustPO, String aPalletId, 
            String aShipDate, String aOrderNo, String aUnits, String aCartonNo,
            String aWeight, String aPostCode)
    {
        plannedLoad = aPlannedLoad;
        plannedShipment = aPlannedShipment;
        div = aDiv;
        pickTicket = aPickTicket;
        aCS = aACS;
        soldTo = aSoldTo;
        shipTo = aShipTo;
        soldToName = aSoldToName;
        shipToName = aShipToName;
        shipToAddr1 = aShipToAddr1;
        shipToCity = aShipToCity;
        shipToAddr3 = aShipToAddr3;

         if (shipToCountry.equals("826"))
        {

            shipToPostCode = aPostCode;
        }

        else
        {
          shipToPostCode = shipToName;
        }
        
        custPO = aCustPO;
        palletId = aPalletId;
        shipDate = aShipDate;
        orderNo = aOrderNo;
        units = aUnits;
        cartonNo = aCartonNo;
        weight = aWeight;
    }
    public String[] getarray()
    {
        return new String[]{"LI", getPlannedLoad(), getPlannedShipment(), 
            getDiv(), getPickTicket(), getACS(), getShipTo(), getShipToName(),
            getShipToAddr1(), getShipToCity(), getShipToAddr3(),
            getShipToPostCode(), getShipToCountry(), getCustPO(),
            getPalletId(), getCartonNo(), getWeight()};
    }

    public Boolean matchPostCodes() {
        Boolean r = false;
        if (!getShipToCountry().equals("826"))
        {
            if (PostCodes.contains(getShipToName()))
            {
                String newPC = PostCodes.getPostCode(getShipToName());
                if (!getShipToPostCode().equals(newPC))
                {
                    setShipToPostCode(PostCodes.getPostCode(getShipToName()));
                    r = true;
                }
            }
        }
        return r;
    }

    /**
     * @return the div
     */
    public String getDiv() {
        return div;
    }

    /**
     * @return the pickTicket
     */
    public String getPickTicket() {
        return pickTicket;
    }

    /**
     * @return the shipToName
     */
    public String getShipToName() {
        return shipToName;
    }


    /**
     * @return the soldTo
     */
    public String getSoldTo() {
        return soldTo;
    }


    /**
     * @return the shipTo
     */
    public String getShipTo() {
        return shipTo;
    }
    /**
     * @return the soldToName
     */
    public String getSoldToName() {
        return soldToName;
    }
    /**
     * @return the shipToPostCode
     */
    public String getShipToPostCode() {
        return shipToPostCode;
    }

    /**
     * @return the shipDate
     */
    public String getShipDate() {
        return shipDate;
    }

    /**
     * @return the orderNo
     */
    public String getOrderNo() {
        return orderNo;
    }

    /**
     * @return the units
     */
    public String getUnits() {
        return units;
    }

    /**
     * @return the cartonNo
     */
    public String getCartonNo() {
        return cartonNo;
    }

    /**
     * @return the weight
     */
    public String getWeight() {
        return weight;
    }
    public boolean equals(InData other)
    {
        if (!(this.getCartonNo()).equals(other.getCartonNo()))
        {
            return false;
        }
        else
        {
            return true;
        }
    }

    @Override
    public String toString() {
        return "InData[cartonNo=" + this.getCartonNo() + "]";
    }
    public int compareTo(Object other)
    {
        if (!(other instanceof InData))
            throw new ClassCastException("An InData expected");
        String otherC = ((InData) other).getShipToCountry() +
                ((InData) other).getShipToPostCode() +
                ((InData) other).getShipToName() + ((InData) other).getCartonNo();
        String thisC = this.getShipToCountry() + this.getShipToPostCode()
                + this.getShipToName()+this.getCartonNo();
        return otherC.compareTo(thisC);
    }

    /**
     * @param shipToPostCode the shipToPostCode to set
     */
    public void setShipToPostCode(String shipToPostCode) {
        this.shipToPostCode = shipToPostCode;
    }

    /**
     * @return the plannedLoad
     */
    public String getPlannedLoad() {
        return plannedLoad;
    }

    /**
     * @return the plannedShipment
     */
    public String getPlannedShipment() {
        return plannedShipment;
    }

    /**
     * @return the aCS
     */
    public String getACS() {
        return aCS;
    }

    /**
     * @return the shipToAddr1
     */
    public String getShipToAddr1() {
        return shipToAddr1;
    }

    /**
     * @return the shipToCity
     */
    public String getShipToCity() {
        return shipToCity;
    }

    /**
     * @return the shipToAddr3
     */
    public String getShipToAddr3() {
        return shipToAddr3;
    }

    /**
     * @return the shipToCountry
     */
    public String getShipToCountry() {
        return shipToCountry;
    }

    /**
     * @return the custPO
     */
    public String getCustPO() {
        return custPO;
    }

    /**
     * @return the palletId
     */
    public String getPalletId() {
        return palletId;
    }
}
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package imoprtconverter;
import java.io.*;
import javax.swing.table.*;
/**
 *
 * @author rellis
 */
public class SaveFile {
    public static void SaveFile(DefaultTableModel table, String fileName) {
        try
        {
            FileWriter writer = new FileWriter(fileName);
            int columnSize = table.getColumnCount();
            int rowSize = table.getRowCount();
            for(int y = 0; y < columnSize; y++)
            {
                writer.append(table.getColumnName(y));
                if(y < columnSize - 1)
                   writer.append(',');
            }
            writer.append("
");
            for(int x = 0; x < rowSize; x++)
            {
                for(int y = 0; y < columnSize; y++)
                {
                    writer.append((String) table.getValueAt(x, y));
                    if(y < columnSize - 1)
                       writer.append(',');
                }
                writer.append("
");

            }
            writer.close();

        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }








}
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
/*
 * ImoprtConverterAboutBox.java
 */

package imoprtconverter;

import org.jdesktop.application.Action;
import javax.swing.table.*;
import java.util.*;
public class PostCodesEditor extends javax.swing.JDialog {

    public PostCodesEditor(java.awt.Frame parent) {
        super(parent);
        pcTableModel = new DefaultTableModel();
        pcTableModel.addColumn("Ship To Name");
        pcTableModel.addColumn("Ship To Post Code");
        Iterator it = PostCodes.getPostCodes().entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry pc = (Map.Entry)it.next();
            pcTableModel.addRow(new Object[] { pc.getKey(), pc.getValue() });
        }
        initComponents();
        getRootPane().setDefaultButton(closeButton);
    }

    @Action public void closeBox() {
        dispose();
    }

    @Action public void savePCs() {
        if (pcTable.isEditing()) { pcTable.getCellEditor().stopCellEditing(); }
        PostCodes.updatePostCodes(pcTableModel);
        dispose();
    }
    @Action public void addRow() {
        pcTableModel.addRow(new Object[] {"", ""});
    }

    @Action public void deleteRow() {
        pcTableModel.removeRow(pcTable.getSelectedRow());
    }   

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        closeButton = new javax.swing.JButton();
        saveButton = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        pcTable = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(imoprtconverter.ImoprtConverterApp.class).getContext().getResourceMap(PostCodesEditor.class);
        setTitle(resourceMap.getString("title")); // NOI18N
        setModal(true);
        setName("aboutBox"); // NOI18N
        setResizable(false);

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(imoprtconverter.ImoprtConverterApp.class).getContext().getActionMap(PostCodesEditor.class, this);
        closeButton.setAction(actionMap.get("closeBox")); // NOI18N
        closeButton.setText(resourceMap.getString("closeButton.text")); // NOI18N
        closeButton.setName("closeButton"); // NOI18N

        saveButton.setAction(actionMap.get("savePCs")); // NOI18N
        saveButton.setText(resourceMap.getString("saveButton.text")); // NOI18N
        saveButton.setName("saveButton"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        pcTable.setModel(pcTableModel);
        pcTable.setName("pcTable"); // NOI18N
        pcTable.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(pcTable);

        jButton1.setAction(actionMap.get("addRow")); // NOI18N
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N

        jButton2.setAction(actionMap.get("deleteRow")); // NOI18N
        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 442, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 142, Short.MAX_VALUE)
                        .addComponent(saveButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(closeButton)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 296, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(closeButton)
                    .addComponent(saveButton)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>                        
    
    // Variables declaration - do not modify                     
    private javax.swing.JButton closeButton;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable pcTable;
    private javax.swing.JButton saveButton;
    // End of variables declaration                   
    private DefaultTableModel pcTableModel;
}
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package imoprtconverter;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;
import java.util.ArrayList;
import javax.swing.table.*;
/**
 *
 * @author rellis
 */
public class PostCodes {
private static SortedMap<String, String> pcs = new TreeMap<String, String>();
private final static String PCFILENAME = "lib\irishpostcodes.csv";

   public static void setPostCodes() {
        File pcFile = new File(PCFILENAME);
        pcs.clear();
        try {
            Scanner scanner = new Scanner(pcFile);
            scanner.useDelimiter(System.getProperty("line.separator"));
            scanner.next(); // skip header
            while (scanner.hasNext()) {
                Scanner lineScanner = new Scanner(scanner.next());
                lineScanner.useDelimiter(",");
                pcs.put(lineScanner.next(), lineScanner.next());
            }
            scanner.close();
        }
        catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

   public static Map<String, String> getPostCodes()
   {
       return pcs;
   }
   public static boolean contains(String name)
   {
       return name.isEmpty() || pcs.containsKey(name);
   }
   public static String getPostCode(String name)
   {
       return pcs.get(name);
   }
   public static void updatePostCodes(DefaultTableModel pcTableModel)
   {
       SaveFile.SaveFile(pcTableModel, PCFILENAME);
       setPostCodes();
   }
}
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package imoprtconverter;
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;

public class FileChooserDialog {
        public static File FileChooserDialog(String text) {
            File currentDirectory = new File(Settings.getSetting("Default Directory"));
            FileFilter filter = new FileNameExtensionFilter("csv files", "csv");
            JFileChooser fileopen = new JFileChooser(currentDirectory);
            fileopen.addChoosableFileFilter(filter);
            int ret = fileopen.showDialog(null, text);
            File file = null;
            if (ret == JFileChooser.APPROVE_OPTION) {
                file = fileopen.getSelectedFile();
            }
            return file;
        }
}
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
360:
361:
362:
363:
364:
365:
366:
367:
368:
369:
370:
371:
372:
373:
374:
375:
376:
377:
378:
379:
380:
381:
382:
383:
384:
385:
386:
387:
388:
389:
390:
391:
392:
393:
394:
395:
396:
397:
398:
399:
400:
401:
402:
403:
404:
405:
406:
407:
408:
409:
410:
411:
412:
413:
414:
415:
416:
417:
418:
419:
420:
421:
422:
423:
424:
425:
426:
427:
428:
429:
430:
431:
432:
433:
434:
435:
436:
437:
438:
439:
440:
441:
442:
443:
444:
445:
446:
447:
448:
449:
450:
451:
452:
453:
454:
455:
456:
457:
458:
459:
460:
461:
462:
463:
464:
465:
466:
467:
468:
469:
470:
471:
472:
473:
474:
475:
476:
477:
478:
479:
480:
481:
482:
483:
484:
485:
486:
487:
488:
489:
490:
491:
492:
493:
494:
495:
496:
497:
498:
499:
500:
501:
502:
503:
504:
505:
506:
507:
508:
509:
510:
511:
512:
513:
514:
515:
516:
517:
518:
519:
520:
521:
522:
523:
524:
525:
526:
527:
528:
529:
530:
531:
532:
533:
534:
535:
536:
537:
538:
539:
540:
541:
542:
543:
544:
545:
546:
547:
548:
549:
550:
551:
552:
553:
554:
555:
556:
557:
558:
559:
560:
561:
562:
563:
/*
 * ImoprtConverterView.java
 */

package imoprtconverter;

import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.table.*;
import java.io.*;
import java.util.*;
/**
 * The application's main frame.
 */
public class ImoprtConverterView extends FrameView {

    Set<InData> inDataFile = new TreeSet<InData>();
    Set<OutData> outDataFile = new TreeSet<OutData>();

    public ImoprtConverterView(SingleFrameApplication app) {
        super(app);
        inTableModel = new DefaultTableModel();
        outTableModel = new DefaultTableModel();

        this.setInTableModle();
        this.setOutTableModle();
        initComponents();

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
    }
    public void print(String text) {
        outputBox.append(text + "
");
    }
    private void setInTableModle() {
        inTableModel.addColumn("HI");
        inTableModel.addColumn("Planned Load");
        inTableModel.addColumn("Planned Shipment");
        inTableModel.addColumn("Div");
        inTableModel.addColumn("Pick Ticket");
        inTableModel.addColumn("ACS");
        inTableModel.addColumn("Ship To");
        inTableModel.addColumn("Ship To Name");
        inTableModel.addColumn("Address 1");
        inTableModel.addColumn("City");
        inTableModel.addColumn("Address 3");
        inTableModel.addColumn("Ship To Post Code");
        inTableModel.addColumn("Country");
        inTableModel.addColumn("Cust PO");
        inTableModel.addColumn("PalletId");
        inTableModel.addColumn("Carton No");
        inTableModel.addColumn("Weight");
    }
    private void setOutTableModle() {
        outTableModel.addColumn("Manifest Date Customer");
        outTableModel.addColumn("Div");
        outTableModel.addColumn("Order No");
        outTableModel.addColumn("Pick Ticket");
        outTableModel.addColumn("PO No");
        outTableModel.addColumn("Invoice No");
        outTableModel.addColumn("Currency");
        outTableModel.addColumn("Price");
        outTableModel.addColumn("No Of Cartons");
        outTableModel.addColumn("Units");
        outTableModel.addColumn("Weight");
        outTableModel.addColumn("Sold To");
        outTableModel.addColumn("Ship To");
        outTableModel.addColumn("Name");
        outTableModel.addColumn("Address 1");
        outTableModel.addColumn("Address 2");
        outTableModel.addColumn("City");
        outTableModel.addColumn("Post Code");
        outTableModel.addColumn("Telephone");
    }

    public void addInRow(String[] inData)
    {
        inTableModel.insertRow(0, inData);
    }
    public void addOutRow(String[] outData)
    {
        outTableModel.insertRow(0, outData);
    }
    @Action
    public void addInData()
    {
        File inFilename = FileChooserDialog.FileChooserDialog("Select the In import file");
        if (inFilename == null) {
            this.print("Error No in file Selected!");
        }
        else
        {
            int i = inDataFile.size();
            inDataFile = InDataScanner.readFile(inFilename, inDataFile);
            this.print(inDataFile.size()-i + " lines in read successfully.");

            // display in data in table
            this.displayData();
        }
    }

    @Action
    public void addOutData()
    {
        File outFilename = FileChooserDialog.FileChooserDialog("Select the out import file");
        if (outFilename == null) {
            this.print("Error No out file Selected!");
        }
        else
        {
            int i = outDataFile.size();
            outDataFile = OutDataScanner.readFile(outFilename, outDataFile);
            this.print(outDataFile.size()-i + " lines out read successfully.");

            // display in data in table
            this.displayData();
        }

    }

    private void displayData()
    {
        //delete any data already in tables
        inTableModel.getDataVector().removeAllElements();
        inTableModel.fireTableDataChanged();
        outTableModel.getDataVector().removeAllElements();
        outTableModel.fireTableDataChanged();
        //deletes ALL the rows
        // display in data in table
        Iterator itr = inDataFile.iterator();
        int matchingPostCodes = 0;
        int matchedIrishIn = 0;
        int matchedIrishOut = 0;
        // display out data in table
        Iterator outItr2 = outDataFile.iterator();
        while(outItr2.hasNext())
        {
            OutData outData = (OutData) outItr2.next();
            if (outData.matchPostCodes()) { matchedIrishOut++; }
        }
        


        while(itr.hasNext())
        {
           InData inData = (InData) itr.next();
           if (inData.matchPostCodes()) { matchedIrishIn++; }
           // search out data to find postcodes
           Iterator outItr = outDataFile.iterator();
           while(outItr.hasNext())
           {
              OutData outData = (OutData) outItr.next();

              if (outData.getPickTicket().equals(inData.getPickTicket()))
              {
                  if (outData.getShipToPostCode().equals(inData.getShipToPostCode()))
                  {
                      matchingPostCodes++;
                  }
                  else
                  {
                      this.print("Post codes for PT" + outData.getPickTicket()
                              + " do not match for in("
                              +inData.getShipToPostCode()
                              + ") & out("
                              +outData.getShipToPostCode()
                              + "), "
                              + " using postcode given for out.");
                      inData.setShipToPostCode(outData.getShipToPostCode());
                  }

              }
           }
           this.addInRow(inData.getarray());
        }

        if (matchedIrishIn>0)
        {
           this.print(matchedIrishIn + " Irish post codes for in matched sucessfully.");
        }
 
        if (matchedIrishOut>0)
        {
           this.print(matchedIrishOut + " Irish post codes for out matched sucessfully.");
        }

        if (matchingPostCodes>0)
        {
           this.print(matchingPostCodes + " post codes matched sucessfully from outs to ins.");
        }
                
        // display out data in table
        Iterator outItr3 = outDataFile.iterator();
        while(outItr3.hasNext())
        {
           OutData outData = (OutData) outItr3.next();
           this.addOutRow(outData.getarray());
        }
    }


    @Action
    public void saveData()
    {
        // save in
        String infilename = Settings.getSetting("CCM In File");
        SaveFile.SaveFile(inTableModel, infilename);
        this.print("In .csv saved to " + infilename);

        // save out
        String outfilename = Settings.getSetting("CCM Out File");
        SaveFile.SaveFile(outTableModel, outfilename);
        this.print("Out .csv saved to " + outfilename);

        // run the imports
        Runtime rt = Runtime.getRuntime();
        try
        {
            String inprogram = Settings.getSetting("CMM In Program");
            Process pr =rt.exec(inprogram);
            int exitVal = pr.waitFor();
            this.print("CCM In complete check CCM window for log.");
        }
        catch(Exception e)
        {
            this.print("Error with CCM In");
        }
        try
        {
            String outprogram = Settings.getSetting("CMM Out Program");
            Process pr =rt.exec(outprogram);
            int exitVal = pr.waitFor();
            this.print("CCM Out complete check CCM window for log.");
        }
        catch(Exception e)
        {
            this.print("Error with CCM Out");
        }
    }
    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = ImoprtConverterApp.getApplication().getMainFrame();
            aboutBox = new ImoprtConverterAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        ImoprtConverterApp.getApplication().show(aboutBox);
    }

    @Action
    public void showEditPostCodesBox() {
        JFrame mainFrame = ImoprtConverterApp.getApplication().getMainFrame();
        PostCodesEditor pcBox = new PostCodesEditor(mainFrame);
        pcBox.setLocationRelativeTo(mainFrame);
        ImoprtConverterApp.getApplication().show(pcBox);
        displayData();
    }
    @Action
    public void showEditSettingsBox() {
        JFrame mainFrame = ImoprtConverterApp.getApplication().getMainFrame();
        SettingsEditor setBox = new SettingsEditor(mainFrame);
        setBox.setLocationRelativeTo(mainFrame);
        ImoprtConverterApp.getApplication().show(setBox);
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        outputBox = new javax.swing.JTextArea();
        jScrollPane2 = new javax.swing.JScrollPane();
        inTable = new javax.swing.JTable();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator2 = new javax.swing.JSeparator();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem addInFileMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenuItem addOutFileMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenuItem importMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu optionsMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem exitMenuItem1 = new javax.swing.JMenuItem();
        javax.swing.JMenuItem settingsMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();

        mainPanel.setName("mainPanel"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        outputBox.setColumns(20);
        outputBox.setRows(5);
        outputBox.setName("outputBox"); // NOI18N
        jScrollPane1.setViewportView(outputBox);

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        inTable.setModel(inTableModel);
        inTable.setName("inTable"); // NOI18N
        jScrollPane2.setViewportView(inTable);

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        jTable1.setModel(outTableModel);
        jTable1.setName("jTable1"); // NOI18N
        jScrollPane3.setViewportView(jTable1);

        jSeparator1.setName("jSeparator1"); // NOI18N

        jSeparator2.setName("jSeparator2"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(imoprtconverter.ImoprtConverterApp.class).getContext().getActionMap(ImoprtConverterView.class, this);
        jButton1.setAction(actionMap.get("saveData")); // NOI18N
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(imoprtconverter.ImoprtConverterApp.class).getContext().getResourceMap(ImoprtConverterView.class);
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N

        jButton2.setAction(actionMap.get("addOutData")); // NOI18N
        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N

        jButton3.setAction(actionMap.get("addInData")); // NOI18N
        jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
        jButton3.setName("jButton3"); // NOI18N

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 746, Short.MAX_VALUE)
            .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 746, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                .addComponent(jButton3)
                .addGap(18, 18, 18)
                .addComponent(jButton2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 489, Short.MAX_VALUE)
                .addComponent(jButton1))
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 746, Short.MAX_VALUE)
            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 746, Short.MAX_VALUE)
            .addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 746, Short.MAX_VALUE)
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 242, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton1)
                    .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButton3)
                        .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        addInFileMenuItem.setAction(actionMap.get("addInData")); // NOI18N
        addInFileMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_I, java.awt.event.InputEvent.CTRL_MASK));
        addInFileMenuItem.setText(resourceMap.getString("addInFileMenuItem.text")); // NOI18N
        addInFileMenuItem.setName("addInFileMenuItem"); // NOI18N
        fileMenu.add(addInFileMenuItem);

        addOutFileMenuItem.setAction(actionMap.get("addOutData")); // NOI18N
        addOutFileMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        addOutFileMenuItem.setText(resourceMap.getString("addOutFileMenuItem.text")); // NOI18N
        addOutFileMenuItem.setName("addOutFileMenuItem"); // NOI18N
        fileMenu.add(addOutFileMenuItem);

        importMenuItem.setAction(actionMap.get("saveData")); // NOI18N
        importMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_G, java.awt.event.InputEvent.CTRL_MASK));
        importMenuItem.setText(resourceMap.getString("importMenuItem.text")); // NOI18N
        importMenuItem.setName("importMenuItem"); // NOI18N
        fileMenu.add(importMenuItem);

        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        optionsMenu.setText(resourceMap.getString("optionsMenu.text")); // NOI18N
        optionsMenu.setName("optionsMenu"); // NOI18N

        exitMenuItem1.setAction(actionMap.get("showEditPostCodesBox")); // NOI18N
        exitMenuItem1.setText(resourceMap.getString("exitMenuItem1.text")); // NOI18N
        exitMenuItem1.setName("exitMenuItem1"); // NOI18N
        optionsMenu.add(exitMenuItem1);

        settingsMenuItem.setAction(actionMap.get("showEditSettingsBox")); // NOI18N
        settingsMenuItem.setText(resourceMap.getString("settingsMenuItem.text")); // NOI18N
        settingsMenuItem.setName("settingsMenuItem"); // NOI18N
        optionsMenu.add(settingsMenuItem);

        menuBar.add(optionsMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 726, Short.MAX_VALUE)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
            .addComponent(progressBar, javax.swing.GroupLayout.DEFAULT_SIZE, 746, Short.MAX_VALUE)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 746, Short.MAX_VALUE)
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, statusPanelLayout.createSequentialGroup()
                .addGap(40, 40, 40)
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>                        

    // Variables declaration - do not modify                     
    private javax.swing.JTable inTable;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JTable jTable1;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JTextArea outputBox;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    // End of variables declaration                   

    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;
    private DefaultTableModel inTableModel;
    private DefaultTableModel outTableModel;
    private JDialog aboutBox;
}
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
/*
 * ImoprtConverterApp.java
 */

package imoprtconverter;

import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;

/**
 * The main class of the application.
 */
public class ImoprtConverterApp extends SingleFrameApplication {

    /**
     * At startup create and show the main frame of the application.
     */
    @Override protected void startup() {
        ImoprtConverterView view = new ImoprtConverterView(this);
        show(view);
        // open irish postcodes file
        PostCodes.setPostCodes();
        Settings.loadSettings();

        /* Prompt for files on startup
        File inFilename = FileChooserDialog.FileChooserDialog("Select the In import file");
        if (inFilename == null) {
            view.print("Error No in file Selected!");
            System.exit(0);
        }
        File outFilename = FileChooserDialog.FileChooserDialog("Select the out import file");
        if (outFilename == null) {
            view.print("Error No out file Selected!");
            System.exit(0);
        }



        Set<InData> inDataFile = InDataScanner.readFile(inFilename);
        view.print(inDataFile.size() + " lines in read successfully.");
        Set<OutData> outDataFile = OutDataScanner.readFile(outFilename);
        view.print(outDataFile.size() + " lines out read successfully.");





        // display in data in table
        Iterator itr = inDataFile.iterator();
        while(itr.hasNext())
        {
           InData inData = (InData) itr.next();
           // search out data to find postcodes
           Iterator outItr = outDataFile.iterator();
           int matchingPostCodes = 0;
           while(outItr.hasNext())      
           {
              OutData outData = (OutData) outItr.next();
              if (outData.getPickTicket().equals(inData.getPickTicket()))
              {
                  if (outData.getShipToPostCode().equals(inData.getShipToPostCode()))
                  {
                      matchingPostCodes++;
                  }
                  else
                  {
                      view.print("Post codes for PT" + outData.getPickTicket()
                              + " do not match for in & out, "
                              + "using postcode given in out.");
                      inData.setShipToPostCode(outData.getShipToPostCode());
                  }

              }
           }
           view.addInRow(inData.getarray());
        }
        view.print("Post codes for in matched sucessfully.");
        // display out data in table
        Iterator outItr = outDataFile.iterator();
        while(outItr.hasNext())
        {
           OutData outData = (OutData) outItr.next();
           view.addOutRow(outData.getarray());
        }
        view.print("Check all details and edit the lines if necessary then press the import button below.");
        */
    }






    /**
     * This method is to initialize the specified window by injecting resources.
     * Windows shown in our application come fully initialized from the GUI
     * builder, so this additional configuration is not needed.
     */
    @Override protected void configureWindow(java.awt.Window root) {
    }

    /**
     * A convenient static getter for the application instance.
     * @return the instance of ImoprtConverterApp
     */
    public static ImoprtConverterApp getApplication() {
        return Application.getInstance(ImoprtConverterApp.class);
    }

    /**
     * Main method launching the application.
     */
    public static void main(String[] args) {
        launch(ImoprtConverterApp.class, args);
    }


}
in20110307170937.csv (135 KB)
in data (text/plain)
out20110307171006.csv (28 KB)
out data (text/plain)

asked 07/18/2011 10:17

GracefBase's gravatar image

GracefBase ♦♦


11 Answers:
Well, that looks a reasonable task, but maybe we do not need to use all these codes.

So you have some input file where there is a column with post codes  and some
are either missing or not quite good and there is
another file where these postcodes can be looked up based on company name, correct?

Can you post the csv file (or maybe a portion of it) where we can see these issues and correspondiing
csv file through which it can be resolved- I can see the input file, but I don't see
any source form where we can get replacements.
Also please, indicate which columns contain post code and
what column is unique so that it could be used to match companies.



 
link
for_yan's gravatar image

for_yan

Hi For Yan,
Originally I thought we could use the sold to and ship to columns joined together to create a unique code, however that is only on the Out file, not the in file.
The company name is unique per postcode - please see attached csv file as an example - the first column is the company name on the data, the second column is the postcode on the data, and the third column is the unique code for the company on the database.

I've also realised that the input files I sent first time were the processed ones not the original ones - here attached are the some in original format.
 
example postcode file
 
 
In data original
 
 
Out data original
 
link
GracefBase's gravatar image

GracefBase

Well, it is still a little bit confusing.

Do I understand that you have input file with column zip code (like in CK-In-...  file above)
Then you have table like in Example-postcode-file.CSV above which has some post codes which need to be modified with one column with
the values as they are in the input file and another column with corresponding values as they need to be

So we should read input file check if the zip code on each line matches the one in the table which needs to be changed and
write output file with all those code modified which need to be modified and everything else being the same.
If we do such pre-processing then the rest of your program (all those codes above)  will do the job as required.

Is this correct formulation of the task?
link
for_yan's gravatar image

for_yan

Yes, exactly!
link
GracefBase's gravatar image

GracefBase

OK, so your CK-in-19.07.2011.csv is your input file (I am asking again as for some reason in the posting it says "out data")
and
Example-postcode-file.csv is your database-like file.
And I need to read the input and re-write it based on the zip code column of input file and the database?

Please, confirm and I'll write the appropriate program later today or by tomorrow.

link
for_yan's gravatar image

for_yan

Hi again,
Sorry I labelled them wrong - they are what it says in the file name.  There are two files one is for the In (see in data, in data scanner) and the other is for the out (out data, out data scanner).
Yes the postcode needs to be changed in the new CSV files for IN and OUT based on the 'database' to the third column (example-postcode-file.csv) but only if the postcode and company name match the other two columns.
Thanks so much
Grace
link
GracefBase's gravatar image

GracefBase

Thanks, so I basicall need only CK-In-19.07.2011.csv and example-postcode-file.csv as the inputs
to my program. I don't need your CK-out... file.
The out put will be analogous to CK-In... with zip code column modified in some cases.
link
for_yan's gravatar image

for_yan

Hi For Yan,
Actually yes you need the out file as well as it is different and is output to a different file.  There are two files generated by this program, the IN and the OUT csv files.  If you look at the code there are the following classes: INDATA, INDATA SCANNER, OUTDATA, OUTDATA SCANNER.
Hope this makes sense.
Cheers
G
link
GracefBase's gravatar image

GracefBase

Frankly, I didn't want to look at the code - I was suggesting to re-write the input file in a separate
applications. Then you'll feed it into your stuff and have it rewrite the way you need it.
link
for_yan's gravatar image

for_yan

I made the program the way I mentioned - as a stand-alone
pre-processing application.
To modify your code will take more time - maybe you'll find some clue
in this code and modify it yourself.

I used the openCSV library


download jar from here and make it available in your classpath:
http://mirrors.ibiblio.org/pub/mirrors/maven2/net/sf/opencsv/opencsv/1.7/opencsv-1.7.jar

see API here:
http://opencsv.sourceforge.net/apidocs/index.html

The output file produced by the program is attached below (please, check more extensively - I only checked a few lines).

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
import au.com.bytecode.opencsv.CSVReader;
import au.com.bytecode.opencsv.CSVWriter;

import java.io.*;
import java.util.HashMap;
import java.util.List;

public class ReplaceZIPCode {
    public ReplaceZIPCode(){
        try{
            HashMap <String, String>m = new HashMap <String, String>();
            
             DataInputStream in = new DataInputStream(new FileInputStream("Example-postcode-file.csv"));
          BufferedReader d
          = new BufferedReader(new InputStreamReader(in));
            CSVReader csv = new CSVReader(d);
            List<String[]> list = csv.readAll();
            for(int j=0; j<list.size(); j++){
                String [] codes = list.get(j);
                m.put(codes[1],codes[2]);

            }
            d.close();

           //   DataOutputStream out = new DataOutputStream(new FileOutputStream("CK-Out-19.07.2011.csv"));
            FileWriter w = new FileWriter(new File("CK-In_Mod-19.07.2011.csv"));
            DataInputStream in1 = new DataInputStream(new FileInputStream("CK-In-19.07.2011.csv"));
          BufferedReader d1
          = new BufferedReader(new InputStreamReader(in1));
            CSVReader csv1 = new CSVReader(d1);
            List<String[]> list1 = csv1.readAll();
            d1.close();

            CSVWriter ww = new CSVWriter(w);

                 for(int j=0; j<list1.size(); j++){
                String [] items = list1.get(j);
                     String zipCode = items[10];
                     if(m.get(zipCode) != null){
                         String newZipCode = m.get(zipCode);
                         items[10] = newZipCode;

                     }
                     ww.writeNext(items);
                 }

            
               ww.close();

            


        } catch(Exception ex){
            ex.printStackTrace();
        }

    }

    public static void main(String[] args) {
        new ReplaceZIPCode();
    }

}
link
for_yan's gravatar image

for_yan

Hiya,
Sorry for the delay in replying that was rude - but I just got caught up in another urgent project.
This is brilliant it does the job perfectly.
Thanks so much for your help For Jan
link
GracefBase's gravatar image

GracefBase

Your answer
[hide preview]

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

×141
×11

Asked: 07/18/2011 10:17

Seen: 424 times

Last updated: 08/24/2011 03:31