bankFiles.class
package com; import java.io.*; import java.sql.*; import java.util.*; public class bankFiles { String accountData =""; String companyName; EmployeeObject4 employeeObject; GregorianCalendar today; String companyAccount; String companySort; public bankFiles() { } public void prepareCompanyData(String c) { //The company name from the session object has been passed from PayRolllAxis //as the session object cannot be accessed from with a java class. companyName = c; //new instance of the GregorianCalendar created. today = new GregorianCalendar(); try { Connection connection = ConnectionPool2.getConnection(); Statement statement; String query = "Select AccountNumber, SortCode From CompanyData WHERE companyName = '"+companyName+"'"; statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery( query ); resultSet.next(); companyAccount = resultSet.getString(1); companySort = resultSet.getString(2); } catch(SQLException sqle) { } } //adds the data for the individual employee public String addEmployee(EmployeeObject4 e) { employeeObject = e; String recordType = "3"; String sortCode = employeeObject.getSortCode(); String accountNumber = employeeObject.getAccountNumber(); String PaymentAmount = String.valueOf(employeeObject.getNetPay()); accountData = accountData +"#"+ recordType+"#"+companyAccount+"#"+companySort +"#"+accountNumber+"#"+sortCode; return accountData; } //Header placed on the begining of the string. public String addHeader() { String recordType = "1"; //Values are taken from the instance of the gregorian calendar. String year = String.valueOf(today.get(today.YEAR)); String month = String.valueOf(today.get(today.MONTH)); String date = String.valueOf(today.get(today.DATE)); String hr = String.valueOf(today.get(today.HOUR)); String min = String.valueOf(today.get(today.MINUTE)); String sec = String.valueOf(today.get(today.SECOND)); String filler = "000000000100000000010000000001000000000100000000010000000001000000000100000000010000000001000000000100000000010000000001000000000100000000010000000001000000"; String Record = recordType + year + month + date + hr + min + sec + filler; return Record; } public String addFooter(double totalPayment, int NoOfPayements) { String a = "1"; String aa = companyAccount; String aaa = companySort; String s = String.valueOf(totalPayment); String ss = String.valueOf(NoOfPayements); String sss = "0000000001000000000100000000010000000001000000000100000000010000000001000000000100000000010000000001000"; String st = a + aa + aaa + s + ss + sss; return st; } public void createFile(double totalPayment, int NoOfPayements)//combines header with { String f = addFooter(totalPayment, NoOfPayements);//gets footer data String s = addHeader();//header is placed on string s = s + accountData;// account data is placed on String s = s + f; try { saveString(s); } catch(IOException io) { } } public void saveString(String s)throws IOException { File file = new File("c:/bankfile.txt"); FileOutputStream fw = new FileOutputStream(file); fw.write(s.getBytes()); fw.close(); accountData =""; } //This method takes a string as an argument and integer and adds the charecter specified // in its argument to its left side untill it is the length specified by the int argument //Sections of the transaction String are required to be of a specified length.the string //and the length it needs to be and the charecters it is to be filled with are passed // the method and the filled string returned not implemented due to time limitaions. public String StringFiller(String s, int n, char t) { //finds the number of space filling charecters needed to fill the string int c = n - s.length(); String i = ""; // adds charecters to the filler string until the length is correct. while(i.length() < c) { i = i + t; } //Adds the filler to the original string. s = i + s; return s; } }