You are on page 1of 226

SUPERTRANS

NEW GENERATION CUSTOMER TRANSACTION SOLUTION

STATHIS POLYZOS
OBJECT ORIENTED SOFTWARE ENGINEERING
LARISSA ATEI UNIVERSITY OF STAFFORDSHIRE

TABLE OF CONTENTS
1. 2. INTRODUCTION REQUIREMENTS 2.1 2.2 2.3 3. FUNCTIONAL & NON-FUNCTIONAL REQUIREMENTS USE CASES & SEQUENCE DIAGRAM SYSTEM CLASSES 1 1 1 2 3 3 3
4 5

PROPOSED SYSTEM 3.1


3.1.1 3.1.2

COMMUNICATION: TRADETOKEN AND ITS CONTENTS


COMMON OBJECTS ENTITIES

3.2
3.2.1 3.2.2

THE SERVER
FRONT END DATABASE

7
7 8

3.3 3.4
3.4.1 3.4.2

SERVER-SIDE TASKS TOKEN HANDLING THE CLIENT


CUSTOMERS STAFF

8 9
10 11

3.5
3.5.1 3.5.2

UTILITIES
CLIENT UTILITIES DATABASE UTILITIES

14
14 15

4.

DEVELOPMENT ISSUES COMMENTS 4.1 4.2


4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7

15 15 17
17 17 17 17 17 17 17

THE DEVELOPMENT PROCESS TEST SCENARIOS


INVALID LOGON ATTEMPTS ATTEMPT LOGON WHEN SERVER IS DOWN DEPOSIT TO A NON-EXISTENT ACCOUNT USE OF INVALID AMOUNTS INVALID DATE RANGES FOR ACCOUNT TRANSACTIONS NEW USER ID TO AN INACTIVE EMPLOYEE ALPHABETICAL CHARACTERS IN PIN

4.3

SYSTEM CRITIQUE

18
i

5.

CONCLUSION USE CASE DIAGRAMS

18 21 21 22 23 23
23 23 23 23 24 24 24 24 24 25 25 25 25 26 26 26

APPENDIX A . A.1. A.2.

CUSTOMER USE CASES STAFF USE CASES USE CASE DESCRIPTIONS

APPENDIX B . B.1.

HIGH LEVEL

B.1.1. ACTIVATE/DEACTIVATE CARD B.1.2. ACTIVATE/DEACTIVATE USER B.1.3. ADD NEW EMPLOYEE B.1.4. CHANGE CARD PIN B.1.5. CHANGE PIN (CUSTOMER) B.1.6. CHECK ACCOUNTS B.1.7. CHECK SOURCE ACCOUNT BALANCE B.1.8. DEPOSIT CASH B.1.9. PAY CREDIT CARD BILL B.1.10. PAY TO CREDIT CARD B.1.11. PAY TO UTILITY B.1.12. PAY UTILITY BILL B.1.13. TRANSFER MONEY B.1.14. VERIFY OLD PIN B.1.15. VIEW TRANSACTIONS B.1.16. WITHDRAW CASH

B.2.

FULL DESCRIPTION

27
27 28

B.2.1. CHANGE PIN (CUSTOMER) B.2.2. TRANSFER MONEY

APPENDIX C . APPENDIX D . APPENDIX E . APPENDIX F . F.1.

CLASS DIAGRAM SEQUENCE DIAGRAM STATE MACHINE DIAGRAM SOURCE CODE

29 30 31 32 32
32 37 39 41 45 49 57 64 71

CLIENTPACK

F.1.1. CLIENTGUI.JAVA F.1.2. CSPACLIENT.JAVA F.1.3. F.1.4. F.1.5. F.1.6. F.1.7. F.1.8. F.1.9. ii
FRMACCOUNTSTATUS.JAVA FRMACTIVATESUSPEND.JAVA FRMCHANGEPIN.JAVA FRMCUSTOMERS.JAVA FRMEMPLOYEES.JAVA FRMLISTTRANSACTIONS.JAVA FRMNEWACCOUNT.JAVA

F.1.10. FRMNEWCREDITCARD.JAVA F.1.11. FRMNEWUSERID.JAVA F.1.12. FRMPAYCREDITCARD.JAVA F.1.13. FRMPAYUTILITY.JAVA F.1.14. FRMTRANSACTION.JAVA F.1.15. FRMTRANSFER.JAVA F.1.16. FRMTRANSFERCREDITCARD.JAVA F.1.17. FRMUTILITYTRANSACTION.JAVA F.1.18. MAINCUSMENU.JAVA F.1.19. MAINMENU.JAVA F.1.20. MAINMENUINT.JAVA

74 79 83 88 93 97 102 107 112 116 120

F.2.

COMMON OBJECTS

124
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141

F.2.1. ADDACCOUNT.JAVA F.2.2. ADDCREDITCARD.JAVA F.2.3. ADDUSER.JAVA F.2.4. CHANGEACTIVATIONSTATUS.JAVA F.2.5. CREDITCARDPAYMENT.JAVA F.2.6. CUSTOMERDATA.JAVA F.2.7. EMPLOYEEDATA.JAVA F.2.8. GETACCOUNT.JAVA F.2.9. LOGINSTATUS.JAVA F.2.10. LOGINUSER.JAVA F.2.11. MAKETRANSACTION.JAVA F.2.12. MAKETRANSFER.JAVA F.2.13. MAKETRANSFERTOCREDIT.JAVA F.2.14. REQUESTCUSTOMER.JAVA F.2.15. REQUESTEMPLOYEE.JAVA F.2.16. REQUESTPINCHANGE.JAVA F.2.17. REQUESTTRANSACTIONS.JAVA F.2.18. USERID.JAVA

F.3.

COMMON OBJECTS.ENTITIES

142
142 144 145 149 151 153 154 157 158 159 161

F.3.1. ACCOUNT.JAVA F.3.2. ADDRESS.JAVA F.3.3. CREDITCARD.JAVA F.3.4. CREDITCARDTRANSACTION.JAVA F.3.5. CUSTOMER.JAVA F.3.6. DATABASEOBJECT.JAVA F.3.7. EMPLOYEE.JAVA F.3.8. GENTRANSACTION.JAVA F.3.9. PERSON.JAVA F.3.10. TRANSACTION.JAVA F.3.11. USER.JAVA

F.4.

GLOBALPACK

164
164 iii

F.4.1. CLIENTUTILITIES.JAVA

F.4.2. DBUTILITIES.JAVA F.4.3. TRADETOKEN.JAVA

169 172

F.5.

SERVERPACK

173
173 177 179

F.5.1. CSPA.JAVA F.5.2. CSPAGUI.JAVA F.5.3. SERVERCSPA.JAVA

APPENDIX G . APPENDIX H . H.1. H.2.

TRADETOKEN CONTENTS & RETURN TYPES DATABASE SQL CODE

195 197 197 199 205 206 206 207 208 209 209 210 213 215 216 218 220

DATABASE TABLES & VIEWS DATABASE DIAGRAM REQUIRED DEMO SCREENSHOTS

APPENDIX I . APPENDIX J . J.1. J.2. J.3.

CASH DEPOSIT CASH WITHDRAWA INSUFFICIENT FUNDS ON CREDIT CARD PAYMENT APPLICATION SCREENSHOTS

APPENDIX K . K.1. K.2. K.3.

SERVER STAFF CUSTOMER VISUAL PARADIGM SCREENSHOTS JBUILDER SCREENSHOTS MS SQL SERVER 2005 SCREENSHOTS

APPENDIX L . APPENDIX M . APPENDIX N .

REFERENCES BIBLIOGRAPHY

iv

1. INTRODUCTION
Our aim in this paper is to present a system analysis and an implementation proposal for the SuperTrans system, a customer transaction system to be used by banks. In the first part of the paper, we will begin by briefly reviewing the system requirements proposed in the given scenario. We will then represent some of More these requirements in a more formal manner, using UML diagrams.

specifically, we will demonstrate a set of Use Cases for the system, we will see a class diagram of all classes our proposed application and we will also see some sequence and state machine diagrams. In the second part, we will describe the proposed implementation. Firstly, we examine the communication sequence between the server and client and we will analyse the way in which the server receives and handles client request. We will then describe the client side of the system and go through all front end forms as well as the code behind them. Moreover, we will take a look at some utility classes that we have designed to facilitate our work. we will identify the We will then discuss the issues that arose during the developed systems weaknesses and propose some development process and the ways in which we dealt with some of them. Finally, appropriate solutions. Concluding this paper, we will see that the resulting application is a system that focuses particularly on extendibility and scalability. the needs of a small bank. We have developed a solid system core that can be improved and expanded to easily fit

2. REQUIREMENTS
2.1 Functional & Non-Functional Requirements
The scenario requires the development of a Java application to cover the needs of a bank (DORBank in our proposed system). The requirements provided 1

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


are somewhat general and thus imply a system that will implement a long series of procedures and as well as a solid security mechanism, not unlike the professional systems of todays large financial institutions. The system must support the common tasks carried out by both bank staff and customers, such as cash deposits and withdrawals, utility bill payments, credit card payments etc, requesting a confirmation before each transaction. Staff options should also include adding customers, creating bank accounts, issuing and managing cards and creating new system credentials for customers. The banks management should also have access to employee records and must be able to handle employee access to the system. All the above should be implemented in a user friendly environment that facilitates the common tasks carried out by the staff or the customers, and that also implements a security mechanism that only allows access to those feature available to each user. The client application should not be different for staff and customers, but should rather disable the procedures that the user does not have access to. cards. On the server side, the application should be able to authenticate users, receive and appropriately process their requests and also provide a simple interface that will allow the staff to configure the server as needed. communication with the client part should be done via sockets. All Finally, as the The scenario states that a customer can only have one user ID and up to three credit

bank also uses some older types of devices, it is important that requests be processed on a separate service, so as to allow the handling of requests from these devices.

2.2 Use Cases & Sequence Diagram


Some sample use cases can be seen in Appendix A and while their descriptions are seen in Appendix B. These use cases essentially describe the interaction of actors (customers, staff or the system server) inside the two main interfaces of the system: the customer interface and the staff interface. The design of the use case was made in such a way so as to facilitate the analysis of the complex system into two main parts. too complex to read and understand. In fact, the manner in which the parts of the system and the end users interact is demonstrated in a much clearer fashion in the sequence diagram in Appendix D. The diagram depicts in detail the exact steps taken when a regular scenario of the Transfer Money use case is realised. It would have been impossible to depict the entire system inside on use case diagram without making

PROPOSED SYSTEM Stathis Polyzos

2.3 System Classes


The class diagram for the systems entities is shown in Appendix C. This system shows the required system classes, their attributes and their methods. Note that, in order to simplify the diagram, we have not included the get and set methods regarding the class attributes, but it goes without saying that these need to be implemented in the final system. However, the relationships between the classes are exhibited clearly and the resulting diagram can make an efficient guide to the programmer regarding the implementation of the system. Extending the Transaction object, we are requested to show a State Machine diagram for that object. This requirement is not clear (e.g. whether it refers to a bank transaction or a system transaction); hence the developed diagram shows the progress of a system transaction object from the client to the server until it ends up in a successful or failed state.

3. PROPOSED SYSTEM
The proposed application is a Java application that has been developed in Borlands JBuilder 2006 for Windows using the Java Development Kit (JDK) version 5 update 6 (v. 1.5.0_06-b05), which was the latest update at the time of development. The development environment, JBuilder 2006, is a cross-platform development solution and is generally accepted to be one of the best packages in the market today. The source code for all classes can be found in Appendix F, while screenshots of the GUI are shown in Appendix K. demo procedures are demonstrated in Appendix J. Finally, we have created two installation packages (one for the server and one for the client) that install the applications to the computer and create handy shortcuts. The programs can be started using a Windows executable application and include all the necessary libraries and class files that each part of the system requires. Additionally, the requested

3.1 Communication: TradeToken and its Contents


Our first point of analysis is the method of communication between the server and its clients. As we will see later, the server and client exchange objects using object data streams. TradeToken. The particular object that is exchanged is the TradeToken objects are serialisable and include only two data

members, the tokens data and an integer variable (objectType) that signals to the system how the token must be handled. The data contained in the token is 3

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


set to be of type object, since it can include an instance of any class, with the objectType providing additional information. 3.1.1 Common Objects The objects that the clients send to the server are all included in the CommonObjects package and are listed, along with the expected return information in Appendix G. These objects are also serialisable (so as to be included in the TradeToken without problems) and carry all the required information for some sort of action to take place. There are different objects to make a transfer from one account to another, or to make cash transactions. The use of these objects to carry the required information provided scalability to the application since it is easy to include new features by simply adding new objects and telling the server how to handle them. Since most of these objects carry one or two pieces of information, we will not describe all of them, but will rather explain the framework in which they where developed and analyse a few of them that are either important or more complicated. By far the most important token data object is the LoginStatus object. This is the only object that cannot be passed from the client to the server, but only vice versa, whilst this type of object is included in nearly all other types in the package, as well as all forms in the ClientPack. The client sends a login request (object LoginUser type 1) with the username and the password (as well as the hostname and the port, information that will later be returned to and used by the client). If the username and password match a set from the database, then a LoginStatus object is created, which included the server and port that the login information was successful (this will be used to route the other objects), a boolean variable (status) that signals a successful login and the user ID. As you will see from the constructor, the values of the status variable and of the user ID cannot be set to true when the object is initialised, but they can only be changed by calling the appropriate method with the correct integer value. In our proposed system, the value is a simple six-digit number, but in a more professional implementation this would be a longer number generated by an algorithm, possible requiring more data exchange*. This procedure implements a basic security mechanism, since all processing on the server side requires that the status variable be true on the object passed in each token. Another interesting object is the UserID object (type 3). This object

essentially sends the users ID to the server along with the users LoginStatus and an integer (actionType) that marks the corresponding action required from the server. In essence, this is an extension to the logic of the TradeToken and

* For example, the server could send a number to the client, the client would then process the number and return the result which should in turn match the result of the same process performed on the server side.

PROPOSED SYSTEM Stathis Polyzos this is portrayed by the nested switch statement for the case of that particular object in the token handling algorithm. Some action types actually use the user ID, to get for example the users accounts, credit cards or the access level, while others disregard it and just check the LoginStatus object. We will see this when we discuss token handling later. by the server. Some other token data objects are instantiated using string variables but actually use that information to instantiate other system entities like Account, or Transaction objects. Examples here include the MakeTransaction, the MakeTransfer, or the MakeTransferToCredit objects. The framework under which these common token data objects were built is fairly simple. Firstly, all objects (except for the UserID) must have a LoginStatus data member and must implement a GetStatus method that retrieves the status variable from that data member. Additionally, there are no default constructors, whilst overloading has been avoided, as a simple efficiency mechanism, since these objects serve a very particular cause and using them in various forms could create errors during token handling. Finally, for the same reason, there are no set methods while the gets return only the data of interest. We could have developed these classes using a parent class and having all of them extend it, but this practice created problems in token handling and was dropped (further discussion in section 4.1). 3.1.2 Entities Inside the CommonObjects package, we have included a sub-package called Entities, which essentially defines the classes for the records in the database tables. In fact, the class attributes in this package are identical to the field in the corresponding database tables. These classes are self-explanatory in general and have been designed in absolute accordance with the class diagram in Appendix C so we will only provide some general observations. Contrary to the token data objects, these objects include default constructors and implement get and set methods for all attributes. Additionally, in some of them, we have implemented particular constructors that instantiate the object by reading its attributes directly from the database using a Connection argument and the appropriate unique key. All the classes extend the DatabaseObject abstract class which includes the ID attribute, its get and set methods and the two required abstract methods to add and save the object to the database. All child classes implement the AddToDB method that adds a new object to the appropriate database table. Similarly, the SaveToDB method updates the database with the information that is 5 Action types are also used when exchanging Customer and Employee objects (types 14 and 15 respectively) for manipulation

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


stored in the particular instance of the class. Note here that a new object must have ID field equal to zero. A nifty trick added to the AddToDB method is that after the object has been added to the database, the method reads the last item in the appropriate table and stores its ID (primary key) to the ID variable of the given object, which was previously zero. Hence, when we call the AddToDB method on an object, its ID attribute is updated to match that stored in the database. The SaveToDB is not implemented on all objects since not all objects are directly accessible to the end user. An important note relates to the particular implementation of the Customer and Employee classes. These classes extend a parent abstract class (i.e. cannot be instantiated), namely Person, which in turn extends the DatabaseObject class. A Person object should always have a fullName and an address. class. The child classes inherit these attributes (and the corresponding get and set methods) and implement the attributes and methods particular to each Similar inheritance characteristics have been implemented in classes Transaction and CreditCardTransaction which extend the GenTransaction abstract class. Some classes implement methods that manipulate the data specifically for that class. For example, the CreditCard class includes the ChangePIN method to change the PIN of a credit card (and update the information in the database), including the necessary security procedures. Correspondingly, both the CreditCard and the User class include Activate and Deactivate methods that complete the corresponding actions, as requested in the specifications. A noteworthy observation at this point relates to how we have chosen to handle utility payments. Similarly to a real banking environment, a public utility company (PUC) is nothing but an instance of the Customer class. However, in that class (and, thus, in the customers table in that database), we have included a Boolean attribute that shows us whether a particular customer is a PUC. PUC customers are only allowed one account, to enable the system to locate their account by the customer name. customers name. Finally, it must be explained that the type variable in realisations of the GenTransaction class is set to 1 for deposits and 2 for withdrawals. This is also stored in the database and it allows the proper updating of the accounts balance in real time by the database. Consequently, the Account class includes an extra String attribute, which was not included in the design and which holds the

PROPOSED SYSTEM Stathis Polyzos

3.2 The Server


3.2.1 Front End We will continue this analysis by describing the server part of the GUI. When the banks system administrator starts the server (called CSPA) on the bank servers, the main application frame appears. The option that are required here are the name of the computer that hosts the application database, the name of the database itself and a valid username and password. By pressing the Up Server button, the server starts (actually a server thread starts) and incoming requests can be handled and processed. Note that screenshots of the proposed system are supplied in Appendix K. The database connector used is the latest version of Microsofts own SQL Server driver for JDBC that supports JDK 1.5*. The actual connection object is returned by calling on a method from the database utilities class (see section 3.5.2), and is passed as a parameter to the server class. Note that since the name of the computer that host the database server is given by the user, the application server and the database server computers need not be the same, thus allowing a three-tier architecture, so popular in todays enterprise systems. Now, the server class constructor accepts this parameter and starts a new server socket (a socket capable of accepting incoming connections) at port 5701, and starts a new thread where new connections can be handled. This thread runs while the allowRun variable is true (it becomes false when the server must be stopped) and sends incoming connections on a new thread class, ConnectedClient class. We have chosen to handle connections on a different

thread to enable the server to accept a connection from a new client even if the processing of request from the previous client has not been completed yet. The database connection is passed as an argument to the new thread. The type of stream selected to exchange information between server and client is the object stream, since objects will be exchanged between server and client, and more particularly instances of the TradeToken class which is described in section 3.1. Hence, an ObjectInputStream and ObjectOutputStream are created when a new client connection is accepted. We receive a TradeToken on the ObjectInputStream, handle it (HandleToken method, see below) and return another TradeToken on the ObjectOutputStream. closed. All connections are then

* The driver can be downloaded from Microsofts website at http://www.microsoft.com/downloads/details.aspx?FamilyID=e22bc83b-32ff-4474-a44a22b6ae2c4e17&DisplayLang=en (link valid on 28 January 2005) and is also included in the accompanying CD. The port number is hard-coded into the application for simplicity; it could alternatively be inputted in the server GUI frame, like in the client login form.

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


The above summarises the communication tasks carried out by the server. We have kept the data exchange functionality as simple as possible so as simplify communication testing, which in fact was the first issue in the development process. 3.2.2 Database The database behind the server was designed using the last version of MS SQL Server, namely the 2005 edition*, even though the server can also connect to SQL Server 2000 databases, since the connector works for all versions. It will not be described in great detail since it is a relatively simple model. A diagram of the tables and the relationships between them is shown in Appendix I, while the required SQL code for building the database is included in Appendix H. The fields of all tables are also attributes of the corresponding classes (see section 3.1.2 above) implemented in the application. The only exception here relates to the transaction date fields which are entered automatically by the server to prevent user errors or inconsistencies (e.g. a transaction is entered on a date after the current date). Additionally, the RegDate field in the tables that do not carry a transaction date is the date the record was inserted; it is also assigned by the database. Finally, a trigger has been implemented on the transactions table that updates an accounts balance when a related (tbl_Transactions)

transaction record is inserted, updated or deleted.

3.3 Server-Side Tasks Token Handling


Token handling, as well as all required processing, takes place on the server side. This automatically reduces the load off the client terminals and also allows older devices to send their requests to the server, as required in the system specifications. The server class is the ServerCPSA class, a class that extends Thread (to allow the front end to function while the server is running). While it runs, this class waits for connections and reads incoming object from the client. The server starts a new thread to process all incoming connections. This thread receives the TradeToken from the client, processes it and returns another TradeToken, with the requested information. The particular method that handles the tokens goes by the unimaginative name of HandleToken. The method starts by initialising the variables that will be required during the processing. The code for this method is

* We used MS SQL Server 2005 Workgroup Edition during development since it is the only version that runs on a 32-bit x86 workstation with Windows XP. For more advanced server systems, the Enterprise edition can be used instead, which also supports 64-bit systems. In a real banking environment, this may be permitted as most transactions carry a date value known, in Greece at least (and probably in France too!), as Valeur which signifies the date as of which the transaction is valid. However, we choose not to implement this feature for reasons of simplicity.

PROPOSED SYSTEM Stathis Polyzos quite large, but the actual processing time should be small, since a switch statement is used to do the required tasks for each token. For each case, comments mark the type of object that must have been received according to the TradeTokens data as well as the type of data that must be placed on the returning TradeToken. A list of the token data, their types and the returning data is shown in Appendix G. A popular returning data type is the confirmation token, which includes null data and either 1 (for success of the operation) or 0 (for failure) as the data type. As we can see, in all cases (except case 1, i.e. before login), the first action that takes place after reading the data from the incoming token (incToken) is the verification of the users login status. If the user has not successfully logged in, the operation stops returning a null TradeToken (null data and -1 as the data type). We can also see that when an error occurs, the returning token is again the null TradeToken. However, some procedures return particular error tokens. For example, in case 16, where a new account must be added to the database (object AddAccount), if the customer is a public utility company and already has an account (i.e. new account cannot be added), the error token returns the number of the existing account. Similar error token are returned for cases 17 (new user object AddUser) and 18 (new credit card object AddCreditCard). Another important note has to do with cases where the return data is an array. In these cases, we chose to include the arrays length in the returning TradeToken as its objectType, so as to facilitate the handling of the array on the client side. Finally, in cases where a double transaction must take place (e.g. a transfer from one account to another), if the second transaction in the set fails, we rollback the process by removing the first transaction from the database, not unlike professional banking information systems.

3.4 The Client


The client GUI is slightly more complicated than the server GUI, since we need to implement the security functionality proposed in the requirements. Before we start discussing the GUI, we must say that the singleton pattern has been implemented on all forms to prevent multiple instances of the same form. According to the singleton pattern, the forms constructor is private, the class includes a data member of its own type (unForm) to see if it has been instantiated and a public method (Instance in our implementation) is used to instantiate the form; the form is instantiated only if its instance data member (unForm) is null.

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


Additionally, all forms check if the user has successfully logged on, by using the GetStatus method in the status data member they all have. When the client application starts, the first frame that appears is the login frame (see Appendix K), which ask the user to input the server name and port and also provide a valid username and password. When pressing the Connect button, the first thing that must be done is to get the required arguments, namely the host name and port and the users name and password. The system corrects erroneous input either by filling in the blanks or by presenting the appropriate error messages. Once all information is successfully entered, a LoginUser object is prepared and sent to the server using the DispatchToken method (included in ClientUtilities see section 3.5.1). We receive the reply from the server and check the login status. error. If the user has failed to login, we inform them of the Four consecutive failed login attempts will end the application; a simple

security measure. If the user has successfully logged in, we present a message and then the main menu form appears. This menu is different for customers and for staff. 3.4.1 Customers The customer menu comes from the MainMenu class. It is a JFrame object that includes buttons that complete certain tasks for the customer. From the point of view of the customer, this application represents an electronic banking solution. Hence, no cash transactions can take place from this component. As requested in the system specifications, before any transaction is initiated, a confirmation dialogue box appears. The first option on the form is the account status form. The second button (Account Transactions) opens up This form a form

(frmAccountStatus) simply shows the customers accounts and their balance. (frmListTransactions) that allows the user to see the transactions that took place for a particular account in the given time period. Customers select the account of interest from a combo box and also provide the date period required. The parts of the dates are entered in different text boxes, so as to avoid the complications of using the Date or the Calendar class, and validated immediately through the ValidateField method. This method checks the validity of the data entered in the field according a maximum allowed value (e.g. 12 for months). Hence, when the user presses the View button, all data entered is valid. When the button is pressed, the application asks the transaction list from the server. The dates are passed in the format that the SQL query will use them (i.e. in the form yyyy-m-d). The incoming token carries a Transaction array and its length. If the arrays length is zero, the user gets the information; otherwise 10

PROPOSED SYSTEM Stathis Polyzos the transactions are displayed in the text area, with the minus sign leading the sums of outgoing transactions (type 2). The Transfer Money button is next in the main menu form. The button

opens up the frmTransfer form that allows customers to transfer money between their accounts. The form adds the customers accounts to two combo boxes so that the user can easily select them. The amount is entered in a text box and validated on input (also see the ToDouble method in ClientUtilities section 3.5.1). When the user presses the Transfer button, the system first checks that the request is a valid one (source and destination accounts are different, enough funds exist at the source account) and sends the request to the server. Appropriate messages appear according to the incoming confirmation. The next option is the Pay Utility option that opens the frmPayUtitlity form. This form is identical to the frmTransfer form, with two exceptions. In the target account combo box, the names of the public utility companies are entered and there is a field to add the customers number at the particular company where the payment is made. The number is added to the transactions comments so that the company can process the payment correctly. The fifth button on the main menu opens the frmTranferCreditCard, which performs a payment from an account to a credit card. It is essentially similar to the frmTransfer form with the only difference that the destination account is now credit card. The object carried in the sent TradeToken is now a MakeTransferToCredit object. The last button opens the form that allows a user to change the PIN to a card, the frmChangePin form. If the user is a customer, the credit cards allowed are only those of the particular user, otherwise the combo box lists all cards. The user must enter their old PIN and enter the new PIN twice. The two new PINs are must be equal. The old PIN is not verified here, as it is verified when the ChangePin method will be called on the CreditCard object on the server side. Appropriate message appear according the confirmation received from the server. 3.4.2 Staff The bank staff forms are more in number, since the tasks carried out by the bank staff are far more. The main menu (MainMenuInt) of an employee user includes the most common options inside the bank. transaction. The first two buttons on the form enable the employee to perform a single account transaction, i.e. a deposit or a withdrawal. These two buttons open the same form (frmTransaction) passing an integer parameter that holds the type of 11 Similarly to the options visible to the banks customer, the system requests confirmations before each

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


the transaction. The user enters the account number (by hand to avoid errors in selections, similarly to the transaction forms of real banking systems) and the amount and presses the Make Transaction button. The system firstly verifies user input, verifying the amount, the account number and the available balance, in case of a withdrawal. Note that account information is requested from the server after the amount is verified to avoid unnecessary traffic. The information is then passed on to the server who sends back a confirmation. The third button on the form opens the frmPayCreditCard that enables the user to perform a payment to a credit card. The process is similar to the transfer, with the system verifying user inputs, sending the request and informing the user of the reply. An interesting feature here is the automatic formatting of credit card numbers with a space every four digits, so as to improve readability. Similarly to the previous transaction processes, the frmUtilityTransaction form, which is the next in the main menu, performs a payment to public utility company account. The next option is only enabled if the user is a supervisor, i.e. has access level 1. A Boolean variable (supervisor) which is passed to the form during at user logon decided whether this button is enabled or not. This button opens the employees form (frmEmployees) which handles bank employee information. Similarly, the next button of the customer menu (which opens by the pressing the last button on the main menu) opens the frmCustomers form to handle customers. These forms include fields to enter all appropriate information and also include user friendly navigation buttons. They also include buttons to add a new record, to save changes to a record and to add related entities, namely a user ID and, for customers, a credit card or an account. Navigation is achieved by requesting employee or customer information from the server when needed. An integer array containing all employee or As the user This customer IDs is requested from the server on form initialisation.

presses the previous or next buttons, the appropriate ID is sent to the server requesting the corresponding entitys information from the database. procedure serves two important purposes. Firstly, it ensures that the user sees the most recent information on the form and, secondly, it minimises the entity data that must be stored in the memory of the client while the form is open. Imagine if the bank had a thousand employees and the system had to load all information to an array, or even a linked list. This would create a bigger problem in the case of customers (where navigation is the same), since they are expected to be much more. However, this procedure does not solve concurrency issues since once the object is sent to the client, the server will still allow changes to that object from other clients. This problem could also be solved by having the

12

PROPOSED SYSTEM Stathis Polyzos server keep a list of objects sent to clients and to send each object to other clients as read only while the first client is still viewing it. The forms are populated by a method called PopulateForm. This method reads the information from the server according to the current employee or customer ID and fills the forms fields with the received information. If the user wants to enter a new record, the form is cleared. This method is called at startup and also as the user navigates the available records. When the user wants to Save the data, the corresponding button pressed. The method saves the forms data into an Employee or Customer object and sends it to the server inside the appropriate token data object with the action type 1 to add or 2 to save an existing record. The server uses this information to call the appropriate method on the object. In case of success, the appropriate message pops up and if the object is a new (i.e. add), the form closes so the list of IDs can be updated*. When a new related entity (user ID, credit card or account) needs to be added, two important pieces of information are passed, along with the login status, which is, as mentioned earlier, present in every form. This information is the current entitys name and ID. The name is saved to the top of the insertion form for user-friendliness purposes, while the ID is used to link the related entity with the current one. In the case of the user ID, the forms also pass a Boolean variable indicating if the new ID will belong to an employee or a customer, as well as the permitted user levels. These insertion forms verify the data entered against objective rules (e.g. credit card number is sixteen digits long, a pin is four digits long) and send the request to the server. The servers handling of these insertion objects has been configured to output particular error results for cases where everything was done properly, but the record cannot be added because of a specifications limit. For example, as mentioned in section 2.1, a customer can only have up to three credit cards and only one user ID. We impose these limits from the front end, even though a database trigger would have been easier and possibly more efficient. The Customer menu includes common option regarding customer

management. The first option is, as mentioned earlier, the Customers form. The second and third options open the same form (frmActivateSuspend) that enables an employee to enable or suspend a credit card or a customer user ID. The form is informed of the required action by a Boolean variable (activate) that is passed as an argument. The form includes two check boxes that are programmed to be mutually exclusive (i.e. it is not possible for them to have the

This is, admittedly, not the most fitting solution, but it is a working one! The user levels are passed as arguments for scalability purposes; it may be required that the same form calls the new user ID form for different, but specific, access levels.

13

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


same value) and that signal if the suspend/activate operation will be performed on a card or a user ID. User IDs and credit cards are conveniently selected from a combo box. When the user presses the button (whose caption changes according to the required operation), the method sends the request to the server and processed the reply. The last option on the customer menu opens the frmChangePin form that enables a staff member to change the PIN of a customers card. personal and the bank staff can never have access to them. This process However, this would never occur in a real banking environment, since card PINs are strictly featured is mentioned in the requirements and thus we implement it here. The form and its functionality were described earlier when discussing the customers part of the application.

3.5 Utilities
To facilitate the programming work, we have implemented some common procedures as methods in utility classes. We have separated these utilities into two categories, namely the client and the database utilities, according to the functionality that they perform. Let us examine each of these two categories in turn. 3.5.1 Client Utilities The ClientUtilities class implements a series of methods whose purpose is to automate request and receive procedures that are required often at the client side. The first such method is the DispatchToken method. This method is the method used to send tokens to the server and receive the replies. It reads the TradeToken and LoginStatus objects passed as arguments, builds opens up a socket with the server (the host name and port are provided in the LoginStatus object), initialises the appropriate object streams (to send and accept serialised objects) and dispatches the token to the server. It receives and stores the reply and returns it as output after shutting down all connections. The next series of utilities retrieves specific information from the server. For example, the GetUserAccounts method returns an array that includes the Account objects associated with the customer who uses the particular user ID. Similarly, all methods return some form of information that either is particular to the active user or relates to more general information required by employee users (e.g. list of all credit card numbers). The last utility method, ToDouble, parses a string as a double. The reason that this method is used, as opposed the simple parseDouble of the Double 14

DEVELOPMENT ISSUES COMMENTS Stathis Polyzos class, is that it includes a few more functionalities. Firstly, it includes appropriate error handling procedures (with the try... catch syntax) so it shortens the code whenever we need to use it. Secondly, it does not allow the use of negative numbers since the method is used to parse currency amounts and third it tries to parse the string twice; once as is and once without any decimals or separators. If an error still occurs, or if the resulting value is negative, -1 is returned. 3.5.2 Database Utilities The DBUtilities class is particular to the server side, since the client does not have direct access to the database, and implements methods relating to database access, without however excluding database access by other means. The first method it includes is the method that builds a connection to an SQL Server database. The arguments passed are the servers name, the database name and a valid username and password. As mentioned earlier, the connector used is Microsofts own SQL Server connector for JDBC. The other two methods implemented retrieve information often required by the token handling algorithm, namely the users customer ID and the users access level. The former is used to locate other entities related to the customer who uses the given ID, whereas the latter is used to decide the allowed actions of a system user.

4. DEVELOPMENT ISSUES COMMENTS


4.1 The Development Process
The development of this extensive system was neither an easy nor a smooth process. A series of issues had to be addressed both during the design and during the implementation process. The first issue was the lack of any previous experience or practice on the requested CASE tool, namely Visual Paradigm. Even though the program is relatively easy to use, it did in fact require a lot of practice before the appropriate diagrams could be drawn. Naturally, all the interesting features of the product that aid the development process could not be effectively exploited exactly because of the lack of familiarity and of academic practice on the product. Additionally, the latest (5.1) version has some problems when requesting community keys and hence we had to be in contact with the Visual Paradigm support line to resolve the issue. The second issue relates to the given specifications. The fact that the

scenario given was quite general and did not propose particular functional 15

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


requirements forced the developer to implement probably more features than would be expected. This occurred because it had to be ensured that the resulting system answered to the idea of the system proposed in the scenario, even though that idea was not exactly clear. From this issue, a third issue occurred: data storage. The scenario

mentions nothing about the underlying database system. An immediate thought would be that no such system was required. However, this would make testing difficult because of the relationships between the entities: how would we be able to repeatedly test the process of a transaction insertion, when we would have to manually enter customer and account details before every test? The answer to the issue was MS SQL Server 2005. Even though seemingly a huge database system (for example MySQL could have been used instead), the authors familiarity with the particular product along with Microsofts handy connector made the process relatively easy and definitely of huge practical interest. Other than the specification issues, a dilemma faced in the development process related to the data carried in the tokens. At first, we had designed the system so that all data classes would inherit their common methods from a parent class. This would facilitate the development process and would also demonstrate the benefits of inheritance. However, there was an issue with the returning tokens; most returning tokens are not specially developed classes, but classes native to the Java class (or particular to some of its common libraries). They could not be carried in the same TradeToken object, unless the token included more data members that would be empty when travelling from client to server and would be filled only on the way back. dropped. This solution however would result on wasted data exchanged between the end points and was immediately Another choice would be to build a different class for the returning However it was deemed Hence the data objects tokens (e.g. ReturnToken), which was acceptable. particular object that would travel along the network.

preferable and more efficient to have a common method of communication, a placed in the tokens where developed as different classes. A final issue related to the development environment. Even though

noticeably better than its predecessor, JBuilder 2006 has certain issues when rendering forms if the developer chooses to implement any functionality out of the ordinary. For example, the fact that we used private constructors made it impossible for JBuilder to show the forms in the designer, if the designer had not rendered the form previously with a public constructor. Thus, we had to disable this functionality so as to design the form and re-enable it afterwards. dealt with. This somewhat impeded the development process, but it was a problem that had to be

16

DEVELOPMENT ISSUES COMMENTS Stathis Polyzos

4.2 Test Scenarios


4.2.1 Invalid logon attempts In the first test scenario, we will attempt to log in to the system using invalid credentials. We attempted to login using a blank password and the login process failed; we got a Login rejected message. attempt, the application was automatically terminated. 4.2.2 Attempt Logon when Server is down In this scenario, we attempted a logon when the server was down. The process did not complete with no error message at all. Additionally, if the attempted connection occurred after the server was put online and then offline again, the client application crashed and it was unavailable until we terminated the server application. 4.2.3 Deposit to a non-existent account In the test case, we tried to make a deposit to a non-existent account. The deposit did not complete and we received an appropriate Account does not exist error message. 4.2.4 Use of invalid amounts In this case, we tried to enter invalid amounts to the text boxes of forms. The system did not allow us to enter invalid or negative amounts and produced an informative error message. However, the error message appeared three times before we were allowed to re-edit the amount on the form. 4.2.5 Invalid date ranges for account transactions In this scenario, we requested the transactions of an account using invalid date ranges. Firstly, we requested the transactions from data 1 February 2006 to 1 January 2006. The result was a message saying An error occurred or no Additionally, we tried to transactions exist, which was not at all informative. After the fourth login

request transactions from 1 January to 31 February 2006 (an invalid date). In this case, the application crashed and would not be terminated until we shut down the server. 4.2.6 New user ID to an inactive employee In this test, we tried to add a new user ID to an inactive employee. The system allowed us this operation, when it should have rejected the request. 4.2.7 Alphabetical Characters in PIN In this scenario, we tried to use alphabetical characters in the PIN. This process was allowed by the system, even though it should not have been under normal conditions. 17

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


4.3 System Critique
Despite all the aforementioned issues, the resulting system is a solid, professional application that definitely covers requirements of the given scenario. However, fine tuning. Firstly, the developed application is not as object-oriented as it could be. In a better tuned end system, all objects would be loaded by the server and the client would call (invoke) methods on them remotely probably using the Javas Remote Method Invocation (RMI). This would greatly simplify the communication between the server and the client, but it would require a more thorough implementation of methods in all the entity objects. There would be no server process to directly handle incoming client requests and thus manipulate objects. Hence each object would have to include methods to manipulate each of its attributes. A possibility would also be to include database operations in the set methods of the attributes; as the attribute would be modified with the set method, the corresponding record could immediately be updated in the database. Another drawback relates to the systems GUI. Admittedly, the developed GUI, albeit practical, is not that original and does not include common options, like a menu bar or a toolbar. Of course, these options were neither requested in the specifications nor required in the form that the system was developed. But still, it would have made a good addition to include more visual stimulation in the delivered GUI, even though JBuilder is not particularly helpful in this process. Furthermore, some operations are not supported by the system. For example, the deletion of entities, or the settling of account was not implemented. However, these procedures are simple to develop and cannot be considered a serious drawback to the system, particularly since they were not present in the given requirements. Finally, we have located some bugs during our brief testing process in section 4.2 above. Obviously, a more thorough testing procedure would have to take place and all located bugs would have to be corrected if the system were to be released in a commercial form. like all professional applications, there is certainly room for improvement and we have in fact pinpointed some features that could use a little

5. CONCLUSION
Concluding this paper, we have firstly discussed the scenario given and deduced the necessary requirements. We have then formulated these requirements into UML diagrams, namely use case, class, sequence and state machine diagrams, and discussed a little about these diagrams. 18

CONCLUSION Stathis Polyzos We have then implemented these requirements into a complete Java database application using cutting edge tools, like JBuilder 2006 and MS SQL Server 2005. We provided a comprehensive analysis of all the systems features and discussed in detail how the final system achieves communication between its client and its server part. Subsequently, we discussed some of the issues that arose during the development process and the way in which we dealt with them. We then tested the system using some test scenarios and shown that even though the system does include error handling procedures that protect it from crashing or malfunctioning, there are a few bugs that need to be dealt with. Finally, we have recognised that the delivered application does have some weaknesses and proposed ways in which these could be corrected. Summing up, we can definitely say that, despite its bugs, the final system is a solid application that requires only a bit of fine tuning if it were to be released in a commercial form. and in terms of security. The tools used are state-of-the-art and the end result could cover all the operational needs of a small bank, both in terms of usability

19

USE CASE DIAGRAMS Stathis Polyzos

APPENDIX A. USE CASE DIAGRAMS


A.1. Customer Use Cases

21

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


A.2. Staff Use Cases

22

USE CASE DESCRIPTIONS Stathis Polyzos

APPENDIX B. USE CASE DESCRIPTIONS


B.1. High Level
B.1.1. Activate/Deactivate Card BASIC COURSE OF ACTION
1. 2. 3. 4. 5. Employee user requests to activate/deactivate card System displays all card numbers to user User selects card System asks for confirmation. If user gives negative reply, go back to 3 Transaction dispatched to server and system informs user of result; if failure go back to 3 else end use case.

B.1.2. Activate/Deactivate User BASIC COURSE OF ACTION


1. 2. 3. 4. 5. Employee user requests to activate/deactivate user System displays all customer usernames to user User selects username System asks for confirmation. If user gives negative reply, go back to 3 Transaction dispatched to server and system informs user of result; if failure go back to 3 else end use case.

B.1.3. Add New Employee BASIC COURSE OF ACTION


1. 2. 3. 4. 5. 6. Employee user selects the employees form If the user is a supervisor, open the form otherwise end use case User asks to add new employee User supplies all required information about the new employee and asks to save System asks for confirmation. If user gives negative reply, go back to 4 Transaction dispatched to server and system informs user of result; if failure go back to 4 else end use case.

B.1.4. Change Card PIN BASIC COURSE OF ACTION


1. 2. 3. 4. Employee user selects the change PIN form System displays all card numbers User selects card and provides old PIN one and new PIN twice. System asks for confirmation. If user gives negative reply, go back to 3

23

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


5. 6. Old PIN verification and new PIN must be 4 characters exactly. If error, go back to 3 Transaction dispatched to server and system informs user of result; if failure go back to 3 else end use case.

B.1.5. Change PIN (Customer) BASIC COURSE OF ACTION


1. 2. 3. 4. 5. 6. Customer user selects the change PIN form System displays customers card numbers User selects card and provides old PIN one and new PIN twice. System asks for confirmation. If user gives negative reply, go back to 3 Old PIN verification and new PIN must be 4 characters exactly. If error, go back to 3 Transaction dispatched to server and system informs user of result; if failure go back to 3 else end use case.

B.1.6. Check Accounts BASIC COURSE OF ACTION


1. 2. Customer user selects the check accounts form System displays customers accounts and balance

B.1.7. Check Source Account Balance BASIC COURSE OF ACTION


1. 2. 3. User requests withdrawal from account System verifies that amount is less than or equal to account balance System outputs whether transaction can take place

B.1.8. Deposit Cash BASIC COURSE OF ACTION


1. 2. 3. 4. 5. User asks to deposit money User supplies the account number and amount System asks for confirmation. If user gives negative reply, go back to 2 Account number is confirmed; if error go back to 2 Transaction dispatched to server and system informs user of result; if failure go back to 2 else end use case.

B.1.9. Pay Credit Card Bill BASIC COURSE OF ACTION


1. 2. Customer user requests to pay credit card bill System displays customer accounts and credit cards to customer user

24

.
3. 4. 5. 6.

USE CASE DESCRIPTIONS Stathis Polyzos


Customer user selects source account and target credit card and supplies the required amount. System asks for confirmation. If user gives negative reply, go back to 3 If amount greater than source balance go back to 3 Transaction dispatched to server and system informs user of result; if failure go back to 3 else end use case.

B.1.10. Pay To Credit Card BASIC COURSE OF ACTION


1. 2. 3. 4. 5. User requests to pay cash to credit card User provides credit card number and amount System asks for confirmation. If user gives negative reply, go back to 2 Credit card number is confirmed; if error go back to 2 Transaction dispatched to server and system informs user of result; if failure go back to 2 else end use case.

B.1.11. Pay To Utility BASIC COURSE OF ACTION


1. 2. 3. 4. 5. User requests to pay to utility company System displays PUC accounts to user User selects target PUC account and supplies the required amount as well as the customer number at the PUC System asks for confirmation. If user gives negative reply, go back to 3 Transaction dispatched to server and system informs user of result; if failure go back to 3 else end use case.

B.1.12. Pay Utility Bill BASIC COURSE OF ACTION


6. 7. 8. 9. Customer user requests to pay utility bill System displays customer and PUC accounts to customer user Customer user selects source and target account and supplies the required amount and their customer number at the PUC System asks for confirmation. If user gives negative reply, go back to 3 10. If amount greater than source balance go back to 3 11. Transaction dispatched to server and system informs user of result; if failure go back to 3 else end use case.

B.1.13. Transfer Money BASIC COURSE OF ACTION


1. Customer user requests money transfer

25

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


2. System displays accounts to customer user; if customer only has one account the use case ends 3. Customer user selects source and target account and the required amount 4. System asks for confirmation. If user gives negative reply, go back to 3 5. If source and target are the same or amount greater than source balance go back to 3 6. Transaction dispatched to server and system informs user of result; if failure go back to 3 else end use case.

B.1.14. Verify Old PIN BASIC COURSE OF ACTION


1. 2. 3. User suppliers old card PIN System verifies given PIN against card PIN System outputs whether PIN change can take place

B.1.15. View Transactions BASIC COURSE OF ACTION


1. 2. 3. 4. 5. Customer user requests to view account transactions System displays accounts to customer user Customer user selects account and supplies the date required System verifies dates as valid; if error go back to 3 System displays account transactions to the user

B.1.16. Withdraw Cash BASIC COURSE OF ACTION


1. 2. 3. 4. 5. User asks to withdraw money User supplies the account number and amount System asks for confirmation. If user gives negative reply, go back to 2 Account number is confirmed and its balance checked against amount; if error go back to 2 Transaction dispatched to server and system informs user of result; if failure go back to 2 else end use case.

26

USE CASE DESCRIPTIONS Stathis Polyzos

B.2.

Full Description

B.2.1. Change PIN (Customer) PRECONDITIONS


1. 2. 3. User has had online credentials issued User has successfully logged in to the System User has at least one credit card for which the PIN is known

POSTCONDITIONS
1. User can use new PIN for given card

BASIC COURSE OF ACTION


1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. Customer user selects the change PIN form Client application requests user card list from server Server sends back the users card number System displays card numbers in a combo box. User selects card and provides old PIN one and new PIN twice System asks for confirmation. If user gives negative reply, go back to 4 Old PIN verification and new PIN must be 4 characters exactly. If error, go back to 4 Transaction request dispatched to server Server verifies incoming information and performs transaction Server informs client of transaction result System informs user of result If failure go back to 4 else end use case.

27

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


B.2.2. Transfer Money PRECONDITIONS
1. 2. 3. User has had online credentials issued User has successfully logged in to the System User has at least two accounts with one having enough balance

POSTCONDITIONS
1. Money is available in target account

BASIC COURSE OF ACTION


1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. Customer user requests money transfer Client application requests users account from server Server replies with user account list System displays account numbers to user in a combo box (Alternate course A: User has only one account) Customer user selects source and target account and the required amount System asks for confirmation. If user gives negative reply, go back to 4 If source and target are the same go back to 4 If amount greater than source balance go back to 4 Transaction request is dispatched to server Server reads incoming information Server performs first transaction (withdrawal from source) If successful, perform second transaction (deposit to target) (Alternate course B: Withdrawal unsuccessful) If successful, return positive confirmation to client (Alternate course C: Deposit unsuccessful) System informs user of transaction result; use case ends

ALTERNATE COURSE A: USER HAS ONLY ONE ACCOUNT


A5. End use case

ALTERNATE COURSE B: WITHDRAWAL UNSUCCESSFUL


B12. Return negative confirmation B13. Go back to 4

ALTERNATE COURSE C: DEPOSIT UNSUCCESSFUL


C13. Rollback transaction Delete withdrawal C14. Return negative confirmation C15. Go back to 4

28

CLASS DIAGRAM Stathis Polyzos

APPENDIX C.

CLASS DIAGRAM

29

SUPERTRANS CUSTOMER TRANSACTION SYSTEM

APPENDIX D. SEQUENCE DIAGRAM

30

STATE MACHINE DIAGRAM Stathis Polyzos

APPENDIX E.

STATE MACHINE DIAGRAM

31

SUPERTRANS CUSTOMER TRANSACTION SYSTEM

APPENDIX F.
F.1.

SOURCE CODE

ClientPack

F.1.1. ClientGUI.java package ClientPack ; import import import import import import java.awt.* ; java.awt.event.ActionEvent ; java.awt.event.ActionListener ; java.io.ObjectInputStream ; java.io.ObjectOutputStream ; java.net.Socket ;

import javax.swing.* ; import import import import CommonObjects.LoginStatus ; CommonObjects.LoginUser ; GlobalPack.TradeToken ; GlobalPack.ClientUtilities ;

public class ClientGUI extends JFrame { private JPanel contentPane ; private JMenuBar jMenuBar1 = new JMenuBar () ; private JMenu jMenuFile = new JMenu () ; private JMenuItem jMenuFileExit = new JMenuItem () ; private JTextField txtServer = new JTextField () ; private JLabel lblServer = new JLabel () ; private JLabel lblPort = new JLabel () ; private JTextField txtPort = new JTextField () ; private JButton btnConnect = new JButton () ; private JLabel jLabel1 = new JLabel () ; private JLabel jLabel2 = new JLabel () ; private JTextField txtUsername = new JTextField () ; private JPasswordField txtPass = new JPasswordField () ; private int errorCnt = 0; public ClientGUI () { try { setDefaultCloseOperation (EXIT_ON_CLOSE) ; jbInit () ; } catch (Exception exception) { exception.printStackTrace () ; } } /** * Component initialization. * * @throws java.lang.Exception */ private void jbInit () throws Exception 32

SOURCE CODE Stathis Polyzos

{ contentPane = (JPanel) getContentPane () ; contentPane.setLayout (null) ; setSize (new Dimension (401, 189)) ; setTitle ("CSPA Client") ; jMenuFile.setText ("File") ; jMenuFileExit.setText ("Exit") ; jMenuFileExit.addActionListener (new ClientGUI_jMenuFileExit_ActionAdapter (this)) ; txtServer.setText ("localhost") ; txtServer.setBounds (new Rectangle (91, 19, 128, 19)) ; lblServer.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; lblServer.setToolTipText ("") ; lblServer.setText ("Server") ; lblServer.setBounds (new Rectangle (15, 24, 68, 14)) ; lblPort.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; lblPort.setToolTipText ("") ; lblPort.setText ("Port") ; lblPort.setBounds (new Rectangle (15, 50, 68, 14)) ; txtPort.setText ("5701") ; txtPort.setBounds (new Rectangle (91, 45, 57, 19)) ; btnConnect.setBounds (new Rectangle (253, 57, 115, 22)) ; btnConnect.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; btnConnect.setText ("Connect") ; btnConnect.addActionListener (new ClientGUI_btnConnect_actionAdapter (this)) ; jLabel1.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel1.setToolTipText ("") ; jLabel1.setText ("Password") ; jLabel1.setBounds (new Rectangle (15, 101, 68, 14)) ; jLabel2.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel2.setToolTipText ("") ; jLabel2.setText ("Username") ; jLabel2.setBounds (new Rectangle (15, 75, 68, 14)) ; txtUsername.setText ("GPapak") ; txtUsername.setBounds (new Rectangle (91, 70, 128, 19)) ; contentPane.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; txtPass.setText ("123456") ; txtPass.setBounds (new Rectangle (91, 96, 98, 19)) ; jMenuBar1.add (jMenuFile) ; jMenuFile.add (jMenuFileExit) ; setJMenuBar (jMenuBar1) ; contentPane.add (txtServer) ; contentPane.add (txtPort) ; contentPane.add (txtUsername) ; contentPane.add (txtPass) ; contentPane.add (jLabel2) ; contentPane.add (lblPort) ; contentPane.add (lblServer) ; contentPane.add (jLabel1) ; contentPane.add (btnConnect) ; } /** * * File | Exit action performed. * * @param actionEvent ActionEvent */ void jMenuFileExit_actionPerformed (ActionEvent actionEvent) { 33

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


System.exit (0) ; } /** * * Connect action performed, client attempts logon with the server and * if succesful, the appropriate menu appears. * * @param e ActionEvent */ public void btnConnect_actionPerformed (ActionEvent e) { String hostName = "", userName = "", stPass = "" ; int portNo = 0 ; char[] chPass ; //Server name if (txtServer.getText () == "") { txtServer.setText ("localhost") ; } hostName = txtServer.getText () ; //port try { portNo = Integer.parseInt (txtPort.getText ()) ; } catch (NumberFormatException nexp) { JOptionPane.showMessageDialog (null, "Invalid port...", "Error", JOptionPane.ERROR_MESSAGE) ; return ; } //User name if (txtUsername.getText () == "") { JOptionPane.showMessageDialog (null, "Please enter your user name...", "Error", JOptionPane.ERROR_MESSAGE, null) ; return ; } userName = txtUsername.getText () ; //Password chPass = txtPass.getPassword () ; for (int i = 0 ; i < chPass.length ; i++) { stPass += chPass[i] ; } //Attempt user login try { //Instantiate object LoginUser lg = new LoginUser (userName, stPass, hostName, portNo) ; //Send Token and receive reply TradeToken ret = ClientUtilities.DispatchToken ( new TradeToken (lg, 1), null, hostName, portNo) ;

34

SOURCE CODE Stathis Polyzos

//Check reply if (ret.getType () == 2) { LoginStatus lgSt = (LoginStatus) ret.getData () ; // If logged successfully, get the user level and open the // proper menu, else show error message if (lgSt.GetStatus ()) { JOptionPane.showMessageDialog (null, "Succesful login...", "Success", JOptionPane.INFORMATION_MESSAGE, null) ; //Get user level int usr = ClientUtilities.GetUserLevel (lgSt) ; switch (usr) { case 1: //Supervisor MainMenuInt mm1 = new MainMenuInt (lgSt, true) ; mm1.setVisible (true) ; this.setVisible (false) ; break ; case 2: //Staff MainMenuInt mm2 = new MainMenuInt (lgSt, false) ; mm2.setVisible (true) ; this.setVisible (false) ; break; case 3: //Customer MainMenu mm3 = new MainMenu (lgSt) ; mm3.setVisible (true) ; this.setVisible (false) ; break ; default: break ; } } else { errorCnt++ ; JOptionPane.showMessageDialog (null, "Login rejected..." + (errorCnt == 4? "\n\nApplication will exit..." : ""), "Error", JOptionPane.WARNING_MESSAGE) ; if (errorCnt == 4) System.exit(0); } } } catch (Exception uexp) { System.out.println ("Error " + uexp.getMessage ()) ; } } } class ClientGUI_btnConnect_actionAdapter implements ActionListener { private ClientGUI adaptee ; ClientGUI_btnConnect_actionAdapter (ClientGUI adaptee) { this.adaptee = adaptee ; } 35

SUPERTRANS CUSTOMER TRANSACTION SYSTEM

public void actionPerformed (ActionEvent e) { adaptee.btnConnect_actionPerformed (e) ; } } class ClientGUI_jMenuFileExit_ActionAdapter implements ActionListener { private ClientGUI adaptee ; ClientGUI_jMenuFileExit_ActionAdapter (ClientGUI adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent actionEvent) { adaptee.jMenuFileExit_actionPerformed (actionEvent) ; } }

36

SOURCE CODE Stathis Polyzos F.1.2. CSPAClient.java

package ClientPack ; import java.awt.Dimension ; import java.awt.Toolkit ; import javax.swing.SwingUtilities ; import javax.swing.UIManager ; public class CSPAClient { private boolean packFrame = false ; /** * Construct and show the application. */ public CSPAClient () { ClientGUI frame = new ClientGUI () ; // Validate frames that have preset sizes // Pack frames that have useful preferred size info, e.g. from their layout if (packFrame) { frame.pack () ; } else { frame.validate () ; } // Center the window Dimension screenSize = Toolkit.getDefaultToolkit ().getScreenSize () ; Dimension frameSize = frame.getSize () ; if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height ; } if (frameSize.width > screenSize.width) { frameSize.width = screenSize.width ; } frame.setLocation ((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2) ; frame.setVisible (true) ; } /** * Application entry point. * * @param args String[] */ public static void main (String[] args) { SwingUtilities.invokeLater (new Runnable () { public void run () { try { 37

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


UIManager.setLookAndFeel (UIManager.getSystemLookAndFeelClassName ()) ; } catch (Exception exception) { exception.printStackTrace () ; } new CSPAClient () ; } }) ; } }

38

SOURCE CODE Stathis Polyzos F.1.3. frmAccountStatus.java

package ClientPack ; import import import import java.awt.Font ; java.awt.Rectangle ; java.awt.event.* ; java.text.DecimalFormat ;

import javax.swing.* ; import CommonObjects.LoginStatus ; import CommonObjects.Entities.Account ; import GlobalPack.ClientUtilities ; public class frmAccountStatus extends JFrame { private LoginStatus status = null ; private Account[] cusAccounts ; private static frmAccountStatus unForm = null ; private JTextArea accStatus = new JTextArea () ; private JLabel jLabel1 = new JLabel () ; private frmAccountStatus (LoginStatus lgSt) { status = lgSt ; if (!status.GetStatus ()) { return ; } try { this.setSize (400, 350) ; jbInit () ; } catch (Exception exception) { exception.printStackTrace () ; } } public static frmAccountStatus Instance (LoginStatus lgSt) { if (unForm == null) { unForm = new frmAccountStatus (lgSt) ; unForm.setLocation (70, 50) ; } return unForm ; } private void jbInit () throws Exception { getContentPane ().setLayout (null) ; this.setResizable (false) ; this.setTitle ("Account Status") ; this.addComponentListener (new frmAccountStatus_this_componentAdapter (this)) ; accStatus.setFont (new java.awt.Font ("Dialog", Font.BOLD, 12)) ; accStatus.setVerifyInputWhenFocusTarget (false) ; 39

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


accStatus.setEditable (false) ; accStatus.setText ("") ; accStatus.setBounds (new Rectangle (28, 51, 339, 219)) ; jLabel1.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 12)) ; jLabel1.setHorizontalAlignment (SwingConstants.CENTER) ; jLabel1.setText (ClientUtilities.GetCustomerName (status)) ; jLabel1.setBounds (new Rectangle (17, 14, 356, 26)) ; this.getContentPane ().add (accStatus) ; this.getContentPane ().add (jLabel1) ; //Get customer's account list cusAccounts = ClientUtilities.GetUserAccounts (status) ; //Initialise text area accStatus.setText ("ID\tAccount Number\tBalance\n") ; //Append results for (int i = 0 ; i < cusAccounts.length ; i++) { accStatus.append (String.valueOf (i + 1) + "\t" + cusAccounts[i].GetAccountNumber () + "\t\t" + DecimalFormat.getCurrencyInstance ().format (cusAccounts[i].GetBalance ()) + "\n") ; } } public void this_componentHidden (ComponentEvent e) { unForm = null ; } } class frmAccountStatus_this_componentAdapter extends ComponentAdapter { private frmAccountStatus adaptee ; frmAccountStatus_this_componentAdapter (frmAccountStatus adaptee) { this.adaptee = adaptee ; } public void componentHidden (ComponentEvent e) { adaptee.this_componentHidden (e) ; } }

40

SOURCE CODE Stathis Polyzos F.1.4. frmActivateSuspend.java

package ClientPack ; import java.awt.* ; import java.awt.event.* ; import javax.swing.* ; import CommonObjects.* ; import GlobalPack.ClientUtilities ; import GlobalPack.TradeToken ; public class frmActivateSuspend extends JFrame { private static frmActivateSuspend unForm = null ; private LoginStatus status ; private boolean activate ; private String[] userIDs ; private String[] cards ; private JComboBox cmbCards = new JComboBox () ; private JComboBox cmbUsers = new JComboBox () ; private JLabel jLabel1 = new JLabel () ; private JLabel jLabel2 = new JLabel () ; private JCheckBox chkCard = new JCheckBox () ; private JCheckBox chkUser = new JCheckBox () ; private JButton btnExecute = new JButton () ; private frmActivateSuspend (LoginStatus lgSt, boolean activ) { status = lgSt ; activate = activ ; if (!status.GetStatus ()) return ; try { jbInit () ; } catch (Exception exception) { exception.printStackTrace () ; } } public static frmActivateSuspend Instance (LoginStatus lgSt, boolean activ) { if (unForm == null) { unForm = new frmActivateSuspend (lgSt, activ) ; unForm.setLocation (50, 50) ; } return unForm ; } private void jbInit () throws Exception { this.setSize (new Dimension (386, 200)) ; 41

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


this.setTitle (activate ? "Activation" : "Deactivation") ; this.addComponentListener (new frmActivateSuspend_this_componentAdapter (this)) ; getContentPane ().setLayout (null) ; cmbCards.setBounds (new Rectangle (111, 33, 193, 22)) ; jLabel2.setToolTipText ("") ; jLabel2.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel2.setText ("User ID") ; jLabel2.setBounds (new Rectangle (44, 66, 52, 14)) ; jLabel1.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel1.setText ("Card") ; jLabel1.setBounds (new Rectangle (44, 37, 52, 14)) ; chkUser.setText ("") ; chkUser.setBounds (new Rectangle (313, 62, 28, 23)) ; chkUser.addMouseListener (new frmActivateSuspend_chkUser_mouseAdapter (this)) ; chkCard.addMouseListener (new frmActivateSuspend_chkCard_mouseAdapter (this)) ; btnExecute.setBounds (new Rectangle (121, 111, 147, 37)) ; btnExecute.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; btnExecute.setText (activate ? "Activation" : "Deactivation") ; btnExecute.addActionListener (new frmActivateSuspend_btnExecute_actionAdapter (this)) ; chkCard.setSelected (true) ; this.getContentPane ().add (cmbCards) ; chkCard.setBounds (new Rectangle (313, 33, 28, 23)) ; this.getContentPane ().add (jLabel1) ; this.getContentPane ().add (cmbUsers) ; this.getContentPane ().add (jLabel2) ; this.getContentPane ().add (chkCard) ; this.getContentPane ().add (chkUser) ; this.getContentPane ().add (btnExecute) ; cmbUsers.setBounds (new Rectangle (111, 62, 193, 22)) ; UserID usr1 = new UserID (status.GetUser (), 8, status) ; UserID usr2 = new UserID (status.GetUser (), 9, status) ; //Request and receive information from the server userIDs = (String[]) ClientUtilities.DispatchToken (new TradeToken (usr2, 3), status, "", 0).getData () ; cards = (String[]) ClientUtilities.DispatchToken (new TradeToken (usr1, 3), status, "", 0).getData () ; //Check received information and store results //Users if (userIDs.length == 0) cmbUsers.setEnabled (false) ; else { for (int i = 0 ; i < userIDs.length ; i++) cmbUsers.addItem (userIDs[i]) ; cmbUsers.setSelectedIndex (0) ; } //Cards if (cards.length == 0) cmbCards.setEnabled (false) ; else { for (int i = 0 ; i < cards.length ; i++) cmbCards.addItem (cards[i]) ; cmbCards.setSelectedIndex (0) ; } } 42

SOURCE CODE Stathis Polyzos

/** * Makes sure only one check box is selected */ public void chkCard_mouseClicked (MouseEvent e) { chkUser.setSelected (!chkCard.isSelected ()) ; } /** * Makes sure only one check box is selected */ public void chkUser_mouseClicked (MouseEvent e) { chkCard.setSelected (!chkUser.isSelected ()) ; } /** * Performs the Activate or Suspend operation according to the user's * choice. * * @param e ActionEvent */ public void btnExecute_actionPerformed (ActionEvent e) { //Confirm if (JOptionPane.showConfirmDialog (null, "Confirm transaction...", "Confirmation", JOptionPane.YES_NO_OPTION) == 1) return ; //Read data according to selected options boolean card = chkCard.isSelected () ; String unique = (card ? cmbCards.getSelectedItem ().toString () : cmbUsers.getSelectedItem ().toString ()) ; //Send request and receive reply TradeToken ret = ClientUtilities.DispatchToken (new TradeToken (new ChangeActivationStatus (status, unique, activate, card), 10), status, "", 0) ; //Process results if (ret.getType () == 1) { JOptionPane.showMessageDialog (card ? "Card" : "User") + " " + "suspended") + "...", "Success", this.setVisible (false) ; } else JOptionPane.showMessageDialog JOptionPane.ERROR_MESSAGE) ; } public void this_componentHidden (ComponentEvent e) { unForm = null ; } } class frmActivateSuspend_this_componentAdapter 43

(null, (activate ? "activated" : JOptionPane.INFORMATION_MESSAGE) ;

(null, "Operation failed...", "Error",

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


extends ComponentAdapter { private frmActivateSuspend adaptee ; frmActivateSuspend_this_componentAdapter (frmActivateSuspend adaptee) { this.adaptee = adaptee ; } public void componentHidden (ComponentEvent e) { adaptee.this_componentHidden (e) ; } } class frmActivateSuspend_btnExecute_actionAdapter implements ActionListener { private frmActivateSuspend adaptee ; frmActivateSuspend_btnExecute_actionAdapter (frmActivateSuspend adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnExecute_actionPerformed (e) ; } } class frmActivateSuspend_chkUser_mouseAdapter extends MouseAdapter { private frmActivateSuspend adaptee ; frmActivateSuspend_chkUser_mouseAdapter (frmActivateSuspend adaptee) { this.adaptee = adaptee ; } public void mouseClicked (MouseEvent e) { adaptee.chkUser_mouseClicked (e) ; } } class frmActivateSuspend_chkCard_mouseAdapter extends MouseAdapter { private frmActivateSuspend adaptee ; frmActivateSuspend_chkCard_mouseAdapter (frmActivateSuspend adaptee) { this.adaptee = adaptee ; } public void mouseClicked (MouseEvent e) { adaptee.chkCard_mouseClicked (e) ; } }

44

SOURCE CODE Stathis Polyzos F.1.5. frmChangePin.java

package ClientPack ; import java.awt.* ; import java.awt.event.* ; import javax.swing.* ; import import import import CommonObjects.* ; CommonObjects.Entities.CreditCard ; GlobalPack.ClientUtilities ; GlobalPack.TradeToken ;

public class frmChangePin extends JFrame { private static frmChangePin unForm = null ; private LoginStatus status ; private String[] cards ; private JComboBox cmbCards = new JComboBox () ; private JLabel jLabel1 = new JLabel () ; private JLabel jLabel2 = new JLabel () ; private JButton btnChange = new JButton () ; private JPasswordField txtOldpin = new JPasswordField () ; private JPasswordField txtNewpin = new JPasswordField () ; private JLabel jLabel3 = new JLabel () ; private JPasswordField txtNewpin2 = new JPasswordField () ; private JLabel jLabel4 = new JLabel () ; private frmChangePin (LoginStatus lgSt) { status = lgSt ; if (!status.GetStatus ()) return ; try { jbInit () ; } catch (Exception exception) { exception.printStackTrace () ; } } public static frmChangePin Instance (LoginStatus lgSt) { if (unForm == null) { unForm = new frmChangePin (lgSt) ; unForm.setLocation (70, 50) ; } return unForm ; } private void jbInit () throws Exception { this.setSize (new Dimension (386, 223)) ; 45

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


this.setTitle ("Change PIN") ; this.addComponentListener (new frmChangePin_this_componentAdapter (this)) ; getContentPane ().setLayout (null) ; cmbCards.setBounds (new Rectangle (144, 26, 193, 22)) ; jLabel2.setToolTipText ("") ; jLabel2.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel2.setText ("Old PIN") ; jLabel2.setBounds (new Rectangle (41, 57, 52, 14)) ; jLabel1.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel1.setText ("Card") ; jLabel1.setBounds (new Rectangle (41, 30, 52, 14)) ; btnChange.setBounds (new Rectangle (129, 144, 147, 37)) ; btnChange.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; btnChange.setActionCommand ("Change") ; btnChange.setText ("Change PIN") ; btnChange.addActionListener (new frmChangePin_btnChange_actionAdapter (this)) ; txtOldpin.setText ("") ; txtOldpin.setBounds (new Rectangle (144, 53, 148, 22)) ; txtNewpin.setText ("") ; txtNewpin.setBounds (new Rectangle (144, 81, 148, 22)) ; jLabel3.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel3.setToolTipText ("") ; jLabel3.setText ("New PIN") ; jLabel3.setBounds (new Rectangle (41, 85, 52, 14)) ; txtNewpin2.setBounds (new Rectangle (144, 108, 148, 22)) ; jLabel4.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel4.setToolTipText ("") ; jLabel4.setText ("Reenter New PIN") ; jLabel4.setBounds (new Rectangle (41, 112, 100, 14)) ; this.getContentPane ().add (jLabel1) ; this.getContentPane ().add (jLabel2) ; this.getContentPane ().add (jLabel3) ; this.getContentPane ().add (jLabel4) ; this.getContentPane ().add (cmbCards) ; this.getContentPane ().add (txtOldpin) ; this.getContentPane ().add (txtNewpin) ; this.getContentPane ().add (txtNewpin2) ; this.getContentPane ().add (btnChange) ; this.getContentPane ().add (txtOldpin) ; //Get cards according to user level if (ClientUtilities.GetUserLevel (status) > 2) // Customer { TradeToken tk = ClientUtilities.DispatchToken (new TradeToken ( new UserID (status.GetUser (), 4, status), 3), status, "", 0) ; //Get customer credit card list CreditCard[] stCards = new CreditCard[tk.getType ()] ; stCards = (CreditCard[]) tk.getData () ; //Put the cards numbers in the array cards = new String[stCards.length] ; for (int i = 0 ; i < cards.length ; i++) cards[i] = stCards[i].GetCreditCardNumber () ; } else //Staff { //Get all credit card numbers cards = (String[]) ClientUtilities.DispatchToken (new TradeToken (new UserID (status.GetUser (), 8, status), 3), status, "", 0).getData () ; } //If no cards, disable button and combo box 46

SOURCE CODE Stathis Polyzos

if (cards.length == 0) { cmbCards.setEnabled (false) ; btnChange.setEnabled (false) ; } else { //Save the array in the combo box for (int i = 0 ; i < cards.length ; i++) cmbCards.addItem (cards[i]) ; cmbCards.setSelectedIndex (0) ; } } /** * Performs the Change Pin action. Old and new pins are read into strings, * and then sent to the server on Change Pin request. * A confirmation is returned and the user is informed appropriately * * @param e ActionEvent */ public void btnChange_actionPerformed (ActionEvent e) { //Confirm if (JOptionPane.showConfirmDialog (null, "Confirm transaction...", "Confirmation", JOptionPane.YES_NO_OPTION) == 1) return ; //Read data String newPin = "", newPin2 = "", oldPin = "" ; char[] newP = txtNewpin.getPassword (), newP2 = txtNewpin2.getPassword (), oldP = txtOldpin.getPassword () ; String unique = cmbCards.getSelectedItem ().toString () ; //Turn char arrays into strings for (int i = 0 ; i < newP.length ; i++) newPin += newP[i] ; for (int i = 0 ; i < newP.length ; i++) newPin2 += newP2[i] ; for (int i = 0 ; i < newP.length ; i++) oldPin += oldP[i] ; //Check that the new pins match if (!newPin.equals (newPin2)) { JOptionPane.showMessageDialog (null, "The new pins do not match...", "Error", JOptionPane.ERROR_MESSAGE) ; return ; } //Create pin change request RequestPinChange chPin = new RequestPinChange (status, unique, oldPin, newPin) ; //Send to the server and process reply if (ClientUtilities.DispatchToken (new TradeToken (chPin, 11), status, "", 0).getType () == 1) { JOptionPane.showMessageDialog (null, "PIN change complete...", "Success", JOptionPane.INFORMATION_MESSAGE) ; this.setVisible (false) ; 47

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


} else JOptionPane.showMessageDialog (null, "Operation failed...", "Error", JOptionPane.ERROR_MESSAGE) ; } public void this_componentHidden (ComponentEvent e) { unForm = null ; } } class frmChangePin_this_componentAdapter extends ComponentAdapter { private frmChangePin adaptee ; frmChangePin_this_componentAdapter (frmChangePin adaptee) { this.adaptee = adaptee ; } public void componentHidden (ComponentEvent e) { adaptee.this_componentHidden (e) ; } } class frmChangePin_btnChange_actionAdapter implements ActionListener { private frmChangePin adaptee ; frmChangePin_btnChange_actionAdapter (frmChangePin adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnChange_actionPerformed (e) ; } }

48

SOURCE CODE Stathis Polyzos F.1.6. frmCustomers.java

package ClientPack ; import java.awt.Rectangle ; import java.awt.event.* ; import javax.swing.* ; import import import import CommonObjects.* ; CommonObjects.Entities.Customer ; GlobalPack.ClientUtilities ; GlobalPack.TradeToken ;

public class frmCustomers extends JFrame { private LoginStatus status ; private static frmCustomers unForm ; private JTextField txtID = new JTextField () ; private JTextField txtCustomerName = new JTextField () ; private JTextField txtAddress = new JTextField () ; private JTextField txtCity = new JTextField () ; private JTextField txtZipCode = new JTextField () ; private JTextField txtPhoneNo = new JTextField () ; private JLabel jLabel1 = new JLabel () ; private JLabel jLabel3 = new JLabel () ; private JLabel jLabel5 = new JLabel () ; private JLabel jLabel6 = new JLabel () ; private JLabel jLabel7 = new JLabel () ; private JLabel jLabel8 = new JLabel () ; private JCheckBox chbPubUtilComp = new JCheckBox () ; private JLabel jLabel10 = new JLabel () ; private int[] customers ; private int curI ; private Customer curCust ; private private private private private private private JButton JButton JButton JButton JButton JButton JButton btnPrevious = new JButton () ; btnNext = new JButton () ; btnSave = new JButton () ; btnNew = new JButton () ; btnNewUser = new JButton () ; btnNewAccount = new JButton () ; btnNewCard = new JButton () ;

private frmCustomers (LoginStatus lgSt) { status = lgSt ; try { jbInit () ; } catch (Exception exception) { exception.printStackTrace () ; } } public static frmCustomers Instance (LoginStatus lgSt) 49

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


{ if (unForm == null) { unForm = new frmCustomers (lgSt) ; unForm.setLocation (80, 80) ; } return unForm ; } private void jbInit () throws Exception { this.setSize (450, 350) ; getContentPane ().setLayout (null) ; txtID.setEditable (false) ; txtID.setBounds (new Rectangle (110, 46, 64, 19)) ; txtCustomerName.setBounds (new Rectangle (110, 72, 301, 19)) ; this.addComponentListener (new frmCustomers_this_componentAdapter (this)) txtAddress.setBounds (new Rectangle (110, 95, 264, 19)) ; txtCity.setBounds (new Rectangle (110, 119, 91, 19)) ; txtZipCode.setBounds (new Rectangle (110, 143, 70, 19)) ; txtPhoneNo.setBounds (new Rectangle (110, 169, 139, 19)) ; jLabel1.setToolTipText ("LoginStatus lgSt") ; jLabel1.setText ("ID") ; jLabel1.setBounds (new Rectangle (29, 46, 70, 18)) ; jLabel3.setToolTipText ("LoginStatus lgSt") ; jLabel3.setText ("Full Name") ; jLabel3.setBounds (new Rectangle (29, 71, 70, 18)) ; jLabel5.setToolTipText ("LoginStatus lgSt") ; jLabel5.setText ("Address") ; jLabel5.setBounds (new Rectangle (29, 96, 70, 18)) ; jLabel6.setToolTipText ("LoginStatus lgSt") ; jLabel6.setText ("City") ; jLabel6.setBounds (new Rectangle (29, 120, 70, 18)) ; jLabel7.setToolTipText ("LoginStatus lgSt") ; jLabel7.setText ("ZipCode") ; jLabel7.setBounds (new Rectangle (29, 145, 70, 18)) ; jLabel8.setToolTipText ("LoginStatus lgSt") ; jLabel8.setText ("Phone No") ; jLabel8.setBounds (new Rectangle (29, 170, 70, 18)) ; chbPubUtilComp.setHorizontalTextPosition (SwingConstants.LEADING) ; chbPubUtilComp.setBounds (new Rectangle (147, 195, 22, 23)) ; jLabel10.setToolTipText ("LoginStatus lgSt") ; jLabel10.setText ("Public Utility Company") ; jLabel10.setBounds (new Rectangle (29, 197, 112, 18)) ; this.setTitle ("DORBank :: Customers") ; btnPrevious.setBounds (new Rectangle (60, 244, 73, 23)) ; btnPrevious.setText ("Previous") ; btnPrevious.addActionListener (new frmCustomers_btnPrevious_actionAdapter ; btnNext.setBounds (new Rectangle (142, 244, 73, 23)) ; btnNext.setText ("Next") ; btnNext.addActionListener (new frmCustomers_btnNext_actionAdapter (this)) btnSave.setBounds (new Rectangle (227, 245, 83, 22)) ; btnSave.setText ("Save") ; btnSave.addActionListener (new frmCustomers_btnSave_actionAdapter (this)) btnNew.setBounds (new Rectangle (320, 245, 83, 22)) ; btnNew.setText ("Add New") ; btnNew.addActionListener (new frmCustomers_btnNew_actionAdapter (this)) ; btnNewUser.setBounds (new Rectangle (299, 129, 112, 23)) ; btnNewUser.setText ("New User") ; 50

(this))

SOURCE CODE Stathis Polyzos

btnNewUser.addActionListener (new frmCustomers_btnNewUser_actionAdapter (this)) ; btnNewAccount.setBounds (new Rectangle (299, 158, 112, 23)) ; btnNewAccount.setText ("New Account") ; btnNewAccount.addActionListener (new frmCustomers_btnNewAccount_actionAdapter (this)) ; btnNewCard.setBounds (new Rectangle (299, 187, 112, 23)) ; btnNewCard.setText ("New Credit Card") ; btnNewCard.addActionListener (new frmCustomers_btnNewCard_actionAdapter (this)) ; this.getContentPane ().add (txtCustomerName) ; this.getContentPane ().add (txtID) ; this.getContentPane ().add (jLabel1) ; this.getContentPane ().add (jLabel3) ; this.getContentPane ().add (jLabel5) ; this.getContentPane ().add (jLabel6) ; this.getContentPane ().add (jLabel7) ; this.getContentPane ().add (txtAddress) ; this.getContentPane ().add (txtCity) ; this.getContentPane ().add (txtZipCode) ; this.getContentPane ().add (txtPhoneNo) ; this.getContentPane ().add (jLabel8) ; this.getContentPane ().add (jLabel10) ; this.getContentPane ().add (chbPubUtilComp) ; this.getContentPane ().add (btnPrevious) ; this.getContentPane ().add (btnNext) ; this.getContentPane ().add (btnSave) ; this.getContentPane ().add (btnNew) ; this.getContentPane ().add (btnNewUser) ; this.getContentPane ().add (btnNewAccount) ; this.getContentPane ().add (btnNewCard) ; //Request and receive customer IDs from server TradeToken tk = ClientUtilities.DispatchToken (new TradeToken (new UserID ( status.GetUser (), 6, status), 3), status, "", 0) ; //Process and store resutls if (tk.getType () > 0) { customers = new int[tk.getType ()] ; customers = (int[]) tk.getData () ; curI = 0 ; curCust = new Customer () ; PopulateForm () ; } } /** * Gets customer information from the server and populates the form's fields * according to that information * Also cleares the form for data entry */ private void PopulateForm () { //If not new record, request information if (curI != -1) curCust = (Customer) ClientUtilities.DispatchToken (new TradeToken (new RequestCustomer (status, customers[curI]), 12), status, "", 0).getData () ; else //if new record, instantiate new object curCust = new Customer () ; 51

SUPERTRANS CUSTOMER TRANSACTION SYSTEM

//Fill fields with customer data if (curCust.GetID () != 0) txtID.setText (String.valueOf (curCust.GetID ())) ; else txtID.setText ("") ; txtCustomerName.setText (curCust.GetFullName ()) ; txtAddress.setText (curCust.GetAddress ().GetAddressLine()) ; txtCity.setText (curCust.GetAddress ().GetCity ()) ; txtZipCode.setText (curCust.GetAddress ().GetZipCode ()) ; txtPhoneNo.setText (curCust.GetAddress ().GetPhoneNo ()) ; chbPubUtilComp.setSelected (curCust.GetPubUtil ()) ; //Enable navigation buttons according to position in list btnPrevious.setEnabled (curI > 0) ; btnNext.setEnabled (curI < (customers.length - 1)) ; } public void this_componentHidden (ComponentEvent e) { unForm = null ; } /** * Decreases the current index and calls the PopulateForm method * * @param e ActionEvent */ public void btnPrevious_actionPerformed (ActionEvent e) { curI-- ; PopulateForm () ; } /** * Increases the current index and calls the PopulateForm method * * @param e ActionEvent */ public void btnNext_actionPerformed (ActionEvent e) { curI++ ; PopulateForm () ; } /** * Sets the current index to -1 (new record) and calls the PopulateForm * method * * @param e ActionEvent */ public void btnNew_actionPerformed (ActionEvent e) { curI = -1 ; PopulateForm () ; } /** * Saves the record to the database * 52

SOURCE CODE Stathis Polyzos

* @param e ActionEvent */ public void btnSave_actionPerformed (ActionEvent e) { //Confirm if (JOptionPane.showConfirmDialog (null, "Confirm transaction...", "Confirmation", JOptionPane.YES_NO_OPTION) == 1) return ; //Save form data to object curCust.SetFullName (txtCustomerName.getText ()) ; curCust.GetAddress ().SetAddressLine (txtAddress.getText ()) ; curCust.GetAddress ().SetCity (txtCity.getText ()) ; curCust.GetAddress ().SetZipCode (txtZipCode.getText ()) ; curCust.GetAddress ().SetPhoneNo (txtPhoneNo.getText ()) ; curCust.SetPubUtil (chbPubUtilComp.isSelected ()) ; boolean isNew = (txtID.getText ().length () == 0) ; //Add if new record else save / Send data and receive reply TradeToken rec = ClientUtilities.DispatchToken (new TradeToken (new CustomerData (curCust, (isNew ? 1 : 2), status), 14), status, "", 0) ; //Inform user if (rec.getType () == 1) { JOptionPane.showMessageDialog (null, "Save successful...", "Message", JOptionPane.INFORMATION_MESSAGE) ; if (isNew) //close form so customer list can be updated this.setVisible (false) ; } else JOptionPane.showMessageDialog (null, "Save unsuccessful...", "Error", JOptionPane.ERROR_MESSAGE) ; } /** * Opens the New User form passing the allowed user level, the * customers's full name and ID as parameters. * * @param e ActionEvent */ public void btnNewUser_actionPerformed (ActionEvent e) { //If new record, save first if (curCust.GetID () == 0) { JOptionPane.showMessageDialog (null, "Please save the customer first...", "Error", JOptionPane.ERROR_MESSAGE) ; return ; } int[] lev = {3} ; //Allowed access level frmNewUserID nuid = frmNewUserID.Instance (status, curCust.GetFullName (), curCust.GetID (), lev, false) ; //False means the user ID is for a customer nuid.setVisible (true) ; } /** * Opens the New Card form passing the customer's full name and ID 53

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


* as parameters. * * @param e ActionEvent */ public void btnNewCard_actionPerformed (ActionEvent e) { //If new record, save first if (curCust.GetID () == 0) { JOptionPane.showMessageDialog (null, "Please save the customer first...", "Error", JOptionPane.ERROR_MESSAGE) ; return ; } frmNewCreditCard ncc = frmNewCreditCard.Instance (status, curCust.GetFullName (), curCust.GetID ()) ; ncc.setVisible (true) ; } /** * Opens the New Account form passing the customer's full name and ID * as parameters. * * @param e ActionEvent */ public void btnNewAccount_actionPerformed (ActionEvent e) { //If new record, save first if (curCust.GetID () == 0) { JOptionPane.showMessageDialog (null, "Please save the customer first...", "Error", JOptionPane.ERROR_MESSAGE) ; return ; } frmNewAccount nacc = frmNewAccount.Instance (status, curCust.GetFullName (), curCust.GetID ()) ; nacc.setVisible (true) ; } } class frmCustomers_btnNewAccount_actionAdapter implements ActionListener { private frmCustomers adaptee ; frmCustomers_btnNewAccount_actionAdapter (frmCustomers adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnNewAccount_actionPerformed (e) ; } } class frmCustomers_btnNewCard_actionAdapter implements ActionListener { 54

SOURCE CODE Stathis Polyzos

private frmCustomers adaptee ; frmCustomers_btnNewCard_actionAdapter (frmCustomers adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnNewCard_actionPerformed (e) ; } } class frmCustomers_btnNewUser_actionAdapter implements ActionListener { private frmCustomers adaptee ; frmCustomers_btnNewUser_actionAdapter (frmCustomers adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnNewUser_actionPerformed (e) ; } } class frmCustomers_btnNew_actionAdapter implements ActionListener { private frmCustomers adaptee ; frmCustomers_btnNew_actionAdapter (frmCustomers adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnNew_actionPerformed (e) ; } } class frmCustomers_btnSave_actionAdapter implements ActionListener { private frmCustomers adaptee ; frmCustomers_btnSave_actionAdapter (frmCustomers adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnSave_actionPerformed (e) ; } } class frmCustomers_btnNext_actionAdapter implements ActionListener { private frmCustomers adaptee ; 55

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


frmCustomers_btnNext_actionAdapter (frmCustomers adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnNext_actionPerformed (e) ; } } class frmCustomers_btnPrevious_actionAdapter implements ActionListener { private frmCustomers adaptee ; frmCustomers_btnPrevious_actionAdapter (frmCustomers adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnPrevious_actionPerformed (e) ; } } class frmCustomers_this_componentAdapter extends ComponentAdapter { private frmCustomers adaptee ; frmCustomers_this_componentAdapter (frmCustomers adaptee) { this.adaptee = adaptee ; } public void componentHidden (ComponentEvent e) { adaptee.this_componentHidden (e) ; } }

56

SOURCE CODE Stathis Polyzos F.1.7. frmEmployees.java

package ClientPack ; import java.awt.Rectangle ; import java.awt.event.* ; import javax.swing.* ; import import import import CommonObjects.* ; CommonObjects.Entities.Employee ; GlobalPack.ClientUtilities ; GlobalPack.TradeToken ;

public class frmEmployees extends JFrame { private LoginStatus status ; private static frmEmployees unForm ; private JTextField txtID = new JTextField () ; private JTextField txtIdentity = new JTextField () ; private JTextField txtFullName = new JTextField () ; private JTextField txtAddress = new JTextField () ; private JTextField txtCity = new JTextField () ; private JTextField txtZipCode = new JTextField () ; private JTextField txtPhoneNo = new JTextField () ; private JTextField txtTaxation = new JTextField () ; private JLabel jLabel1 = new JLabel () ; private JLabel jLabel2 = new JLabel () ; private JLabel jLabel3 = new JLabel () ; private JLabel jLabel5 = new JLabel () ; private JLabel jLabel6 = new JLabel () ; private JLabel jLabel7 = new JLabel () ; private JLabel jLabel8 = new JLabel () ; private JLabel jLabel9 = new JLabel () ; private JCheckBox chbActive = new JCheckBox () ; private JCheckBox chbMale = new JCheckBox () ; private JLabel jLabel10 = new JLabel () ; private JLabel jLabel11 = new JLabel () ; private int[] employees ; private int curI ; private Employee curEmpl ; private private private private private JButton JButton JButton JButton JButton btnSave = new JButton () ; btnPrevious = new JButton () ; btnNext = new JButton () ; btnNew = new JButton () ; btnAddUser = new JButton () ;

private frmEmployees (LoginStatus lgSt) { status = lgSt ; try { jbInit () ; } catch (Exception exception) { exception.printStackTrace () ; 57

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


} } public static frmEmployees Instance (LoginStatus lgSt) { if (unForm == null) { unForm = new frmEmployees (lgSt) ; unForm.setLocation (80, 80) ; } return unForm ; } private void jbInit () throws Exception { this.setSize (520, 340) ; getContentPane ().setLayout (null) ; txtID.setEditable (false) ; txtID.setBounds (new Rectangle (110, 46, 64, 19)) ; txtIdentity.setBounds (new Rectangle (110, 74, 77, 19)) ; txtFullName.setBounds (new Rectangle (110, 102, 170, 19)) ; this.addComponentListener (new frmEmployees_this_componentAdapter (this)) ; txtAddress.setBounds (new Rectangle (110, 131, 191, 19)) ; txtCity.setBounds (new Rectangle (110, 159, 91, 19)) ; txtZipCode.setBounds (new Rectangle (110, 187, 70, 19)) ; txtPhoneNo.setBounds (new Rectangle (110, 215, 139, 19)) ; txtTaxation.setBounds (new Rectangle (354, 47, 78, 19)) ; jLabel1.setToolTipText ("LoginStatus lgSt") ; jLabel1.setText ("ID") ; jLabel1.setBounds (new Rectangle (29, 46, 70, 18)) ; jLabel2.setToolTipText ("LoginStatus lgSt") ; jLabel2.setText ("Identity") ; jLabel2.setBounds (new Rectangle (29, 74, 70, 18)) ; jLabel3.setToolTipText ("") ; jLabel3.setText ("Full Name") ; jLabel3.setBounds (new Rectangle (29, 102, 70, 18)) ; jLabel5.setToolTipText ("LoginStatus lgSt") ; jLabel5.setText ("Address") ; jLabel5.setBounds (new Rectangle (29, 132, 70, 18)) ; jLabel6.setToolTipText ("LoginStatus lgSt") ; jLabel6.setText ("City") ; jLabel6.setBounds (new Rectangle (29, 160, 70, 18)) ; jLabel7.setToolTipText ("LoginStatus lgSt") ; jLabel7.setText ("ZipCode") ; jLabel7.setBounds (new Rectangle (29, 188, 70, 18)) ; jLabel8.setToolTipText ("LoginStatus lgSt") ; jLabel8.setText ("Phone No") ; jLabel8.setBounds (new Rectangle (29, 216, 70, 18)) ; jLabel9.setToolTipText ("LoginStatus lgSt") ; jLabel9.setText ("Taxation No") ; jLabel9.setBounds (new Rectangle (275, 48, 70, 18)) ; chbActive.setHorizontalTextPosition (SwingConstants.LEADING) ; chbActive.setBounds (new Rectangle (354, 73, 22, 23)) ; chbMale.setHorizontalTextPosition (SwingConstants.LEADING) ; chbMale.setBounds (new Rectangle (354, 93, 22, 23)) ; jLabel10.setToolTipText ("LoginStatus lgSt") ; jLabel10.setText ("Active") ; jLabel10.setBounds (new Rectangle (303, 75, 42, 18)) ; jLabel11.setToolTipText ("LoginStatus lgSt") ; jLabel11.setText ("Male") ; 58

SOURCE CODE Stathis Polyzos

jLabel11.setBounds (new Rectangle (303, 95, 42, 18)) ; btnSave.setBounds (new Rectangle (212, 256, 83, 22)) ; btnSave.setText ("Save") ; btnSave.addActionListener (new frmEmployees_btnSave_actionAdapter (this)) ; btnPrevious.setBounds (new Rectangle (45, 255, 73, 23)) ; btnPrevious.setText ("Previous") ; btnPrevious.addActionListener (new frmEmployees_btnPrevious_actionAdapter (this)) ; btnNext.setBounds (new Rectangle (127, 255, 73, 23)) ; btnNext.setText ("Next") ; btnNext.addActionListener (new frmEmployees_btnNext_actionAdapter (this)) ; btnNew.setBounds (new Rectangle (305, 256, 83, 22)) ; btnNew.setText ("Add New") ; btnNew.addActionListener (new frmEmployees_btnNew_actionAdapter (this)) ; this.setTitle ("DORBank :: Employees") ; btnAddUser.setBounds (new Rectangle (318, 174, 126, 34)) ; btnAddUser.setToolTipText ("") ; btnAddUser.setText ("Add User ID") ; btnAddUser.addActionListener (new frmEmployees_btnAddUser_actionAdapter (this)) ; this.getContentPane ().add (txtID) ; this.getContentPane ().add (txtIdentity) ; this.getContentPane ().add (txtFullName) ; this.getContentPane ().add (jLabel1) ; this.getContentPane ().add (jLabel2) ; this.getContentPane ().add (jLabel3) ; this.getContentPane ().add (txtAddress) ; this.getContentPane ().add (jLabel5) ; this.getContentPane ().add (txtCity) ; this.getContentPane ().add (txtZipCode) ; this.getContentPane ().add (txtPhoneNo) ; this.getContentPane ().add (jLabel6) ; this.getContentPane ().add (jLabel7) ; this.getContentPane ().add (jLabel8) ; this.getContentPane ().add (btnSave) ; this.getContentPane ().add (btnNext) ; this.getContentPane ().add (btnNew) ; this.getContentPane ().add (btnPrevious) ; this.getContentPane ().add (btnAddUser) ; this.getContentPane ().add (jLabel9) ; this.getContentPane ().add (txtTaxation) ; this.getContentPane ().add (chbActive) ; this.getContentPane ().add (jLabel10) ; this.getContentPane ().add (jLabel11) ; this.getContentPane ().add (chbMale) ; TradeToken tk = ClientUtilities.DispatchToken (new TradeToken (new UserID ( status.GetUser (), 7, status), 3), status, "", 0) ; //Process and store results if (tk.getType () > 0) { employees = new int[tk.getType ()] ; employees = (int[]) tk.getData () ; curI = 0 ; curEmpl = new Employee () ; PopulateForm () ; } } /** * Gets employee information from the server and populates the form's fields 59

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


* according to that information * Also cleares the form for data entry */ private void PopulateForm () { //If not new record, request information if (curI != -1) curEmpl = (Employee) ClientUtilities.DispatchToken (new TradeToken (new RequestEmployee (status, employees[curI]), 13), status, "", 0).getData () ; else //if new record, instantiate new object curEmpl = new Employee () ; //Fill fields with employee data if (curEmpl.GetID () != 0) txtID.setText (String.valueOf (curEmpl.GetID ())) ; else txtID.setText ("") ; txtIdentity.setText (curEmpl.GetIdentityNo ()) ; txtFullName.setText (curEmpl.GetFullName ()) ; txtAddress.setText (curEmpl.GetAddress ().GetAddressLine()) ; txtCity.setText (curEmpl.GetAddress ().GetCity ()) ; txtZipCode.setText (curEmpl.GetAddress ().GetZipCode ()) ; txtPhoneNo.setText (curEmpl.GetAddress ().GetPhoneNo ()) ; txtTaxation.setText (curEmpl.GetTaxationNo ()) ; chbMale.setSelected (curEmpl.GetSex ()) ; chbActive.setSelected (curEmpl.GetActive ()) ; //Enable navigation buttons according to position in list btnPrevious.setEnabled (curI > 0) ; btnNext.setEnabled (curI < (employees.length - 1)) ; } public void this_componentHidden (ComponentEvent e) { unForm = null ; } /** * Decreases the current index and calls the PopulateForm method * * @param e ActionEvent */ public void btnPrevious_actionPerformed (ActionEvent e) { curI-- ; PopulateForm () ; } /** * Increases the current index and calls the PopulateForm method * * @param e ActionEvent */ public void btnNext_actionPerformed (ActionEvent e) { curI++ ; PopulateForm () ; } 60

SOURCE CODE Stathis Polyzos

/** * Sets the current index to -1 (new record) and calls the PopulateForm * method * * @param e ActionEvent */ public void btnNew_actionPerformed (ActionEvent e) { curI = -1 ; PopulateForm () ; } /** * Saves the record to the database * * @param e ActionEvent */ public void btnSave_actionPerformed (ActionEvent e) { //Confirm if (JOptionPane.showConfirmDialog (null, "Confirm transaction...", "Confirmation", JOptionPane.YES_NO_OPTION) == 1) return ; //Save form data to object curEmpl.SetIdentityNo (txtIdentity.getText ()) ; curEmpl.SetFullName (txtFullName.getText ()) ; curEmpl.GetAddress().SetAddressLine (txtAddress.getText ()) ; curEmpl.GetAddress().SetCity( txtCity.getText ()) ; curEmpl.GetAddress().SetZipCode (txtZipCode.getText ()) ; curEmpl.GetAddress().SetPhoneNo (txtPhoneNo.getText ()) ; curEmpl.SetTaxationNo (txtTaxation.getText ()) ; curEmpl.SetActive (chbActive.isSelected ()) ; curEmpl.SetSex (chbMale.isSelected ()) ; boolean isNew = (txtID.getText ().length () == 0) ; //Add if new record else save / Send data and receive reply TradeToken rec = ClientUtilities.DispatchToken (new TradeToken (new EmployeeData (curEmpl, (isNew ? 1 : 2), status), 15), status, "", 0) ; //Inform user if (rec.getType () == 1) { JOptionPane.showMessageDialog (null, "Save successful...", "Message", JOptionPane.INFORMATION_MESSAGE) ; if (isNew) //close form so employee list can be updated this.setVisible (false) ; } else JOptionPane.showMessageDialog (null, "Save unsuccessful...", "Error", JOptionPane.ERROR_MESSAGE) ; } /** * Opens the New User form passing the allowed user levels, the * employee's full name and ID as parameters. * * @param e ActionEvent */ 61

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


public void btnAddUser_actionPerformed (ActionEvent e) { //If new record, save first if (curEmpl.GetID () == 0) { JOptionPane.showMessageDialog (null, "Please save the employee first...", "Error", JOptionPane.ERROR_MESSAGE) ; return ; } int[] lev = {1, 2} ; //Allowed access levels frmNewUserID nuid = frmNewUserID.Instance (status, curEmpl.GetFullName (), curEmpl.GetID (), lev, true) ; //True means the user ID is for an employee nuid.setVisible (true) ; } } class frmEmployees_btnAddUser_actionAdapter implements ActionListener { private frmEmployees adaptee ; frmEmployees_btnAddUser_actionAdapter (frmEmployees adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnAddUser_actionPerformed (e) ; } } class frmEmployees_btnSave_actionAdapter implements ActionListener { private frmEmployees adaptee ; frmEmployees_btnSave_actionAdapter (frmEmployees adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnSave_actionPerformed (e) ; } } class frmEmployees_btnNew_actionAdapter implements ActionListener { private frmEmployees adaptee ; frmEmployees_btnNew_actionAdapter (frmEmployees adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnNew_actionPerformed (e) ; } 62

SOURCE CODE Stathis Polyzos

} class frmEmployees_btnNext_actionAdapter implements ActionListener { private frmEmployees adaptee ; frmEmployees_btnNext_actionAdapter (frmEmployees adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnNext_actionPerformed (e) ; } } class frmEmployees_btnPrevious_actionAdapter implements ActionListener { private frmEmployees adaptee ; frmEmployees_btnPrevious_actionAdapter (frmEmployees adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnPrevious_actionPerformed (e) ; } } class frmEmployees_this_componentAdapter extends ComponentAdapter { private frmEmployees adaptee ; frmEmployees_this_componentAdapter (frmEmployees adaptee) { this.adaptee = adaptee ; } public void componentHidden (ComponentEvent e) { adaptee.this_componentHidden (e) ; } }

63

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


F.1.8. frmListTransactions.java package ClientPack ; import java.awt.* ; import java.awt.event.* ; import java.text.DecimalFormat ; import javax.swing.* ; import import import import import import CommonObjects.LoginStatus ; CommonObjects.RequestTransactions ; CommonObjects.Entities.Account ; CommonObjects.Entities.Transaction ; GlobalPack.ClientUtilities ; GlobalPack.TradeToken ;

public class frmListTransactions extends JFrame { private LoginStatus status = null ; private Account[] cusAccounts ; private static frmListTransactions unForm = null ; private JTextArea accTransactions = new JTextArea () ; private JLabel jLabel1 = new JLabel () ; private JComboBox cmbFromAccount = new JComboBox () ; private JTextField txtFromDay = new JTextField () ; private JTextField txtFromMonth = new JTextField () ; private JTextField txtFromYear = new JTextField () ; private JTextField txtToMonth = new JTextField () ; private JTextField txtToYear = new JTextField () ; private JTextField txtToDay = new JTextField () ; private JLabel jLabel2 = new JLabel () ; private JLabel jLabel3 = new JLabel () ; private JButton btnView = new JButton () ; private JLabel errorBar = new JLabel () ; private Transaction[] transTbl ; private frmListTransactions (LoginStatus lgSt) { status = lgSt ; if (!status.GetStatus ()) return ; try { jbInit () ; } catch (Exception exception) { exception.printStackTrace () ; } } public static frmListTransactions Instance (LoginStatus lgSt) { if (unForm == null) { unForm = new frmListTransactions (lgSt) ; unForm.setLocation (70, 50) ; } 64

SOURCE CODE Stathis Polyzos

return unForm ; } private void jbInit () throws Exception { this.setSize (460, 450) ; getContentPane ().setLayout (null) ; this.setResizable (false) ; this.setTitle ("Account Status") ; this.addComponentListener (new frmListTransactions_this_componentAdapter (this)) ; accTransactions.setFont (new java.awt.Font ("Dialog", Font.BOLD, 12)) ; accTransactions.setToolTipText ("") ; accTransactions.setVerifyInputWhenFocusTarget (false) ; accTransactions.setEditable (false) ; accTransactions.setText ("") ; accTransactions.setBounds (new Rectangle (20, 117, 421, 249)) ; jLabel1.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel1.setText ("Account") ; jLabel1.setBounds (new Rectangle (52, 23, 63, 22)) ; cmbFromAccount.setNextFocusableComponent (txtFromDay) ; cmbFromAccount.setBounds (new Rectangle (123, 23, 184, 22)) ; txtFromDay.setNextFocusableComponent (txtFromMonth) ; txtFromDay.setText ("") ; txtFromDay.setBounds (new Rectangle (123, 49, 30, 22)) ; txtFromDay.addFocusListener (new frmListTransactions_txtFromDay_focusAdapter (this)) ; txtToDay.setNextFocusableComponent (txtToMonth) ; txtToDay.setText ("") ; txtToDay.setBounds (new Rectangle (123, 75, 30, 22)) ; txtToDay.addFocusListener (new frmListTransactions_txtToDay_focusAdapter (this)) ; jLabel2.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel2.setText ("From") ; jLabel3.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel2.setBounds (new Rectangle (52, 49, 63, 22)) ; jLabel3.setText ("To") ; jLabel3.setBounds (new Rectangle (52, 75, 63, 22)) ; btnView.setBounds (new Rectangle (246, 60, 124, 29)) ; btnView.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; btnView.setText ("View") ; btnView.addActionListener (new frmListTransactions_btnView_actionAdapter (this)) ; txtFromYear.setNextFocusableComponent (txtToDay) ; txtFromYear.setText ("") ; txtFromYear.setBounds (new Rectangle (192, 49, 47, 22)) ; txtFromYear.addFocusListener (new frmListTransactions_txtFromYear_focusAdapter (this)) ; txtToYear.setNextFocusableComponent (btnView) ; txtToYear.setText ("") ; txtToYear.setBounds (new Rectangle (192, 75, 47, 22)) ; txtToYear.addFocusListener (new frmListTransactions_txtToYear_focusAdapter (this)) ; txtToMonth.setNextFocusableComponent (txtToYear) ; txtToMonth.setText ("") ; txtToMonth.setBounds (new Rectangle (158, 75, 30, 22)) ; txtToMonth.addFocusListener (new frmListTransactions_txtToMonth_focusAdapter (this)) ; txtFromMonth.setNextFocusableComponent (txtFromYear) ; txtFromMonth.setBounds (new Rectangle (158, 49, 30, 22)) ; 65

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


txtFromMonth.addFocusListener (new frmListTransactions_txtFromMonth_focusAdapter (this)) ; errorBar.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; errorBar.setForeground (Color.red) ; errorBar.setToolTipText ("") ; errorBar.setText ("") ; errorBar.setBounds (new Rectangle (1, 387, 322, 14)) ; this.getContentPane ().add (cmbFromAccount) ; this.getContentPane ().add (txtFromDay) ; this.getContentPane ().add (accTransactions) ; this.getContentPane ().add (jLabel2) ; this.getContentPane ().add (jLabel3) ; this.getContentPane ().add (txtToDay) ; this.getContentPane ().add (jLabel1) ; this.getContentPane ().add (btnView) ; this.getContentPane ().add (errorBar) ; this.getContentPane ().add (txtFromYear) ; this.getContentPane ().add (txtToYear) ; this.getContentPane ().add (txtFromMonth) ; this.getContentPane ().add (txtToMonth) ; //Get customer's account and add them to the combo box cusAccounts = ClientUtilities.GetUserAccounts (status) ; for (int i = 0 ; i < cusAccounts.length ; i++) cmbFromAccount.addItem (cusAccounts[i].GetAccountNumber ()) ; cmbFromAccount.setSelectedIndex (0) ; //Select the first account } /** * Looks through the cusAccounts array for an account object that matches * the given account number. * * @param accNumber String * @return Account */ private Account GetAccountByNo (String accNumber) { for (int i = 0 ; i < cusAccounts.length ; i++) if (cusAccounts[i].GetAccountNumber ().equals (accNumber)) return cusAccounts[i] ; return null ; } /** * Validates the data entered in the parameted Text field according to the * maximum value also passed a paremeter. * * If validation fails, the focus is kept in the particular text field * which will also become red. * * @param fld JTextField * @param maxNo int */ public void ValidateField (JTextField fld, int maxNo) { boolean error = false ; int retNo = -1 ; //Try to parse input as number 66

SOURCE CODE Stathis Polyzos

try { retNo = Integer.parseInt (fld.getText ()) ; } catch (NumberFormatException nexp) { error = true ; } //If no error, check if the input is valid if (!error) if (retNo < 0 || retNo > maxNo) error = true ; //Set the background and the status bar text fld.setBackground (error ? Color.red : Color.white) ; errorBar.setText (error ? "Invalid input" : "") ; //If error, grab the focus if (error) { fld.grabFocus () ; fld.selectAll () ; } } public void this_componentHidden (ComponentEvent e) { unForm = null ; } public void txtFromDay_focusLost (FocusEvent e) { ValidateField (txtFromDay, 31) ; } public void txtFromMonth_focusLost (FocusEvent e) { ValidateField (txtFromMonth, 12) ; } public void txtFromYear_focusLost (FocusEvent e) { ValidateField (txtFromYear, 9999) ; } public void txtToDay_focusLost (FocusEvent e) { ValidateField (txtToDay, 31) ; } public void txtToMonth_focusLost (FocusEvent e) { ValidateField (txtToMonth, 12) ; } public void txtToYear_focusLost (FocusEvent e) { ValidateField (txtToYear, 9999) ; }

67

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


/** * The View action is performed. The method requests a transaction list * from the server and when the list is received, it is displayed in * a simple text box. * * @param e ActionEvent */ public void btnView_actionPerformed (ActionEvent e) { //Build object RequestTransactions rqTrans = new RequestTransactions (status, GetAccountByNo (cmbFromAccount.getSelectedItem ().toString ()), txtFromYear.getText () + "-" + txtFromMonth.getText () + "-" + txtFromDay.getText (), txtToYear.getText () + "-" + txtToMonth.getText () + "-" + txtToDay.getText ()) ; //Send token and get reply TradeToken rec = ClientUtilities.DispatchToken (new TradeToken (rqTrans, 6), status, "", 0) ; //Check results int trLng = rec.getType () ; if (trLng > 0) { //Initialise text box accTransactions.setText ("Date\tAmount\tComment\n") ; //Initialise table and copy data transTbl = new Transaction[trLng] ; transTbl = (Transaction[]) rec.getData () ; //Show data in text box for (int i = 0 ; i < trLng ; i++) accTransactions.append (transTbl[i].GetTransDate () + "\t" + DecimalFormat.getCurrencyInstance ().format ( transTbl[i].GetAmount () * ( transTbl[i].GetType () == 2 ? -1 : 1)) + "\t" + transTbl[i].GetComments () + "\n") ; } else accTransactions.setText ("An error occured or no transactions exist...") ; } } class frmListTransactions_btnView_actionAdapter implements ActionListener { private frmListTransactions adaptee ; frmListTransactions_btnView_actionAdapter (frmListTransactions adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnView_actionPerformed (e) ; } } 68

SOURCE CODE Stathis Polyzos

class frmListTransactions_txtToYear_focusAdapter extends FocusAdapter { private frmListTransactions adaptee ; frmListTransactions_txtToYear_focusAdapter (frmListTransactions adaptee) { this.adaptee = adaptee ; } public void focusLost (FocusEvent e) { adaptee.txtToYear_focusLost (e) ; } } class frmListTransactions_txtToMonth_focusAdapter extends FocusAdapter { private frmListTransactions adaptee ; frmListTransactions_txtToMonth_focusAdapter (frmListTransactions adaptee) { this.adaptee = adaptee ; } public void focusLost (FocusEvent e) { adaptee.txtToMonth_focusLost (e) ; } } class frmListTransactions_txtToDay_focusAdapter extends FocusAdapter { private frmListTransactions adaptee ; frmListTransactions_txtToDay_focusAdapter (frmListTransactions adaptee) { this.adaptee = adaptee ; } public void focusLost (FocusEvent e) { adaptee.txtToDay_focusLost (e) ; } } class frmListTransactions_txtFromYear_focusAdapter extends FocusAdapter { private frmListTransactions adaptee ; frmListTransactions_txtFromYear_focusAdapter (frmListTransactions adaptee) { this.adaptee = adaptee ; } public void focusLost (FocusEvent e) { adaptee.txtFromYear_focusLost (e) ; } }

69

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


class frmListTransactions_txtFromMonth_focusAdapter extends FocusAdapter { private frmListTransactions adaptee ; frmListTransactions_txtFromMonth_focusAdapter (frmListTransactions adaptee) { this.adaptee = adaptee ; } public void focusLost (FocusEvent e) { adaptee.txtFromMonth_focusLost (e) ; } } class frmListTransactions_txtFromDay_focusAdapter extends FocusAdapter { private frmListTransactions adaptee ; frmListTransactions_txtFromDay_focusAdapter (frmListTransactions adaptee) { this.adaptee = adaptee ; } public void focusLost (FocusEvent e) { adaptee.txtFromDay_focusLost (e) ; } } class frmListTransactions_this_componentAdapter extends ComponentAdapter { private frmListTransactions adaptee ; frmListTransactions_this_componentAdapter (frmListTransactions adaptee) { this.adaptee = adaptee ; } public void componentHidden (ComponentEvent e) { adaptee.this_componentHidden (e) ; } }

70

SOURCE CODE Stathis Polyzos F.1.9. frmNewAccount.java

package ClientPack ; import java.awt.Font ; import java.awt.Rectangle ; import java.awt.event.* ; import javax.swing.* ; import import import import import CommonObjects.AddAccount ; CommonObjects.LoginStatus ; CommonObjects.Entities.Account ; GlobalPack.ClientUtilities ; GlobalPack.TradeToken ;

public class frmNewAccount extends JFrame { private LoginStatus status = null ; private static frmNewAccount unForm = null ; private int entityID ; private JLabel jLabel1 = new JLabel () ; private JLabel jLabel2 = new JLabel () ; private JTextField txtRealName = new JTextField () ; private JTextField txtAccountNo = new JTextField () ; private JButton btnAdd = new JButton () ; public frmNewAccount (LoginStatus lgSt, String rlName, int ID) { status = lgSt ; entityID = ID ; if (!status.GetStatus ()) return ; try { jbInit (rlName) ; } catch (Exception exception) { exception.printStackTrace () ; } } public static frmNewAccount Instance (LoginStatus lgSt, String rlName, int ID) { if (unForm == null) { unForm = new frmNewAccount (lgSt, rlName, ID) ; unForm.setLocation (70, 80) ; } return unForm ; } private void jbInit (String rlName) throws Exception { this.setSize (400, 180) ; getContentPane ().setLayout (null) ; this.setResizable (false) ; 71

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


this.setAlwaysOnTop (true) ; this.setTitle ("New Account") ; this.addComponentListener (new frmNewAccount_this_componentAdapter (this)) ; jLabel1.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel1.setText ("Real Name") ; jLabel1.setBounds (new Rectangle (22, 38, 110, 22)) ; jLabel2.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel2.setText ("Account No") ; jLabel2.setBounds (new Rectangle (22, 62, 110, 22)) ; txtRealName.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; txtRealName.setEditable (false) ; txtRealName.setBounds (new Rectangle (157, 41, 181, 19)) ; txtAccountNo.setBounds (new Rectangle (157, 65, 121, 19)) ; btnAdd.setBounds (new Rectangle (128, 107, 120, 23)) ; btnAdd.setText ("Add") ; btnAdd.addActionListener (new frmNewAccount_btnAdd_actionAdapter (this)) ; this.getContentPane ().add (jLabel1) ; this.getContentPane ().add (jLabel2) ; this.getContentPane ().add (txtAccountNo) ; this.getContentPane ().add (txtRealName) ; this.getContentPane ().add (btnAdd) ; //Read arguments and set options txtRealName.setText (rlName) ; } public void this_componentHidden (ComponentEvent e) { unForm = null ; } /** * Performs the add event. Verifies user inputs, sends request to server * and processes results * * @param e ActionEvent */ public void btnAdd_actionPerformed (ActionEvent e) { //Confirm if (JOptionPane.showConfirmDialog (null, "Confirm transaction...", "Confirmation", JOptionPane.YES_NO_OPTION) == 1) return ; //Verify input if (txtAccountNo.getText ().length () == 0) { JOptionPane.showMessageDialog (null, "No account number entered...\n", "Error", JOptionPane.ERROR_MESSAGE) ; return ; } //Build Account object Account acc = new Account () ; acc.SetAccountNumber (txtAccountNo.getText ()) ; acc.SetCustomer (entityID) ; //Send request and get reply TradeToken ret = ClientUtilities.DispatchToken (new TradeToken (new AddAccount (status, acc), 16), status, "", 0) ;

72

SOURCE CODE Stathis Polyzos

//Process reply and inform user of process results switch (ret.getType ()) { case 0: //Account not added JOptionPane.showMessageDialog (null, "A database error occured..\n\n" + "Please contact support immediately...\n\n", "Error", JOptionPane.ERROR_MESSAGE) ; break ; case 1: //Account added JOptionPane.showMessageDialog (null, "Account added successfully...\n", "Message", JOptionPane.INFORMATION_MESSAGE) ; this.setVisible (false) ; break ; case 2: //PUC customer has account JOptionPane.showMessageDialog (null, "Customer is a Public Utility " + "Company and already\nhas an account...\n\n" + "Your request was NOT completed...\n\n", "Error", JOptionPane.ERROR_MESSAGE) ; break ; default: //Unknown error JOptionPane.showMessageDialog (null, "An error occured..\n\n" + "Please contact support immediately...\n\n", "Error", JOptionPane.ERROR_MESSAGE) ; break ; } } } class frmNewAccount_btnAdd_actionAdapter implements ActionListener { private frmNewAccount adaptee ; frmNewAccount_btnAdd_actionAdapter (frmNewAccount adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnAdd_actionPerformed (e) ; } } class frmNewAccount_this_componentAdapter extends ComponentAdapter { private frmNewAccount adaptee ; frmNewAccount_this_componentAdapter (frmNewAccount adaptee) { this.adaptee = adaptee ; } public void componentHidden (ComponentEvent e) { adaptee.this_componentHidden (e) ; } }

73

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


F.1.10. frmNewCreditCard.java package ClientPack ; import import import import java.awt.Font ; java.awt.Rectangle ; java.awt.event.* ; java.text.DecimalFormat ;

import javax.swing.* ; import import import import import CommonObjects.AddCreditCard ; CommonObjects.LoginStatus ; CommonObjects.Entities.CreditCard ; GlobalPack.ClientUtilities ; GlobalPack.TradeToken ;

public class frmNewCreditCard extends JFrame { private LoginStatus status = null ; private static frmNewCreditCard unForm = null ; private int entityID ; private private private private private private private private private private private private JLabel jLabel1 = new JLabel () ; JLabel jLabel2 = new JLabel () ; JLabel jLabel3 = new JLabel () ; JLabel jLabel4 = new JLabel () ; JTextField txtCustomerName = new JTextField () ; JTextField txtCreditCardNo = new JTextField () ; JPasswordField pswPin = new JPasswordField () ; JPasswordField pswPin2 = new JPasswordField () ; JButton btnAdd = new JButton () ; DecimalFormat twoDigits = new DecimalFormat ("#,##0.00") ; JTextField txtMoney = new JTextField () ; JLabel jLabel5 = new JLabel () ;

private frmNewCreditCard (LoginStatus lgSt, String rlName, int ID) { status = lgSt ; entityID = ID ; if (!status.GetStatus ()) return ; try { jbInit (rlName) ; } catch (Exception exception) { exception.printStackTrace () ; } } public static frmNewCreditCard Instance (LoginStatus lgSt, String rlName, int ID) { if (unForm == null) { unForm = new frmNewCreditCard (lgSt, rlName, ID) ; unForm.setLocation (70, 80) ; 74

SOURCE CODE Stathis Polyzos

} return unForm ; } private void jbInit (String rlName) throws Exception { this.setSize (400, 240) ; getContentPane ().setLayout (null) ; this.setResizable (false) ; this.setAlwaysOnTop (true) ; this.setTitle ("New Credit Card") ; this.addComponentListener (new frmNewCreditCard_this_componentAdapter (this)) ; jLabel1.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel1.setText ("Real Name") ; jLabel1.setBounds (new Rectangle (22, 38, 110, 22)) ; jLabel2.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel2.setText ("Credit Card Number") ; jLabel2.setBounds (new Rectangle (22, 62, 110, 22)) ; jLabel3.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel3.setText ("PIN") ; jLabel3.setBounds (new Rectangle (22, 85, 110, 22)) ; jLabel4.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel4.setText ("Confirm PIN") ; jLabel4.setBounds (new Rectangle (22, 109, 110, 22)) ; txtCustomerName.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; txtCustomerName.setEditable (false) ; txtCustomerName.setBounds (new Rectangle (157, 41, 181, 19)) ; txtCreditCardNo.setBounds (new Rectangle (157, 65, 121, 19)) ; pswPin.setBounds (new Rectangle (157, 88, 100, 19)) ; pswPin2.setBounds (new Rectangle (157, 112, 100, 19)) ; btnAdd.setBounds (new Rectangle (123, 172, 120, 23)) ; btnAdd.setText ("Add") ; btnAdd.addActionListener (new frmNewCreditCard_btnAdd_actionAdapter (this)) ; txtMoney.setText (twoDigits.format (0)) ; txtMoney.setHorizontalAlignment (SwingConstants.TRAILING) ; txtMoney.setBounds (new Rectangle (157, 135, 89, 19)) ; txtMoney.addFocusListener (new frmNewCreditCard_txtMoney_focusAdapter (this)) ; jLabel5.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel5.setText ("Credit Limit") ; jLabel5.setBounds (new Rectangle (22, 135, 110, 22)) ; this.getContentPane ().add (jLabel1) ; this.getContentPane ().add (jLabel2) ; this.getContentPane ().add (jLabel3) ; this.getContentPane ().add (jLabel4) ; this.getContentPane ().add (txtCreditCardNo) ; this.getContentPane ().add (txtCustomerName) ; this.getContentPane ().add (pswPin) ; this.getContentPane ().add (pswPin2) ; this.getContentPane ().add (btnAdd) ; this.getContentPane ().add (jLabel5) ; this.getContentPane ().add (txtMoney) ; //Read arguments and set options txtCustomerName.setText (rlName) ; } public void this_componentHidden (ComponentEvent e) { unForm = null ; } 75

SUPERTRANS CUSTOMER TRANSACTION SYSTEM

/** * Performs the add event. Verifies user inputs, sends request to server * and processes results * * @param e ActionEvent */ public void btnAdd_actionPerformed (ActionEvent e) { //Confirm if (JOptionPane.showConfirmDialog (null, "Confirm transaction...", "Confirmation", JOptionPane.YES_NO_OPTION) == 1) return ; String String char[] char[] errMsgs = "" ; bullet = " - " ; chPin = pswPin.getPassword () ; chPin2 = pswPin2.getPassword () ;

//Read passwords String pin = "" ; String pin2 = "" ; for (int i = 0 ; i < chPin.length ; i++) pin += chPin[i] ; for (int i = 0 ; i < chPin2.length ; i++) pin2 += chPin2[i] ; //Verify inputs if (txtCreditCardNo.getText ().length () != 16) errMsgs += bullet + "Invalid Card Number\n" ; if (!pin.equals (pin2)) errMsgs += bullet + "PINs do not match\n" ; if (pin.length () != 4) errMsgs += bullet + "PIN must be exactly four digits\n" ; if (ClientUtilities.ToDouble (txtMoney.getText ()) < 0.01) errMsgs += bullet + "Invalid credit card limit\n" ; if (!errMsgs.equals ("")) { JOptionPane.showMessageDialog (null, "Please collect the following errors:\n\n" + errMsgs + "\n", "Error", JOptionPane.ERROR_MESSAGE) ; return ; } //Build CreditCard object CreditCard cc = new CreditCard () ; cc.SetCreditCardNumber (txtCreditCardNo.getText ()) ; cc.SetCustomer (entityID) ; cc.SetLimit (ClientUtilities.ToDouble (txtMoney.getText ())) ; cc.SetPIN (pin) ; //Send request and get reply TradeToken ret = ClientUtilities.DispatchToken (new TradeToken (new AddCreditCard (status, cc), 18), status, "", 0) ; //Process reply and inform user of process results switch (ret.getType ()) { case 0: //Card not added JOptionPane.showMessageDialog (null, 76

SOURCE CODE Stathis Polyzos

"A database error occured..\n\n" + "Please contact support immediately...\n\n", "Error", JOptionPane.ERROR_MESSAGE) ; break ; case 1: //Card added JOptionPane.showMessageDialog (null, "Card added successfully...\n", "Message", JOptionPane.INFORMATION_MESSAGE) ; this.setVisible (false) ; break ; case 2: //Customer has 3 cards JOptionPane.showMessageDialog (null, "Customer already has three " + "cards...\n\n" + "Your request was NOT completed...\n\n", "Error", JOptionPane.ERROR_MESSAGE) ; break ; default: //Unknown error JOptionPane.showMessageDialog (null, "An error occured..\n\n" + "Please contact support immediately...\n\n", "Error", JOptionPane.ERROR_MESSAGE) ; break ; } } /** * Verifies the money text field and also formats it as a decimal with two * decimal places, also using the thousands separator * * @param focusEvent FocusEvent */ public void txtMoney_focusLost (FocusEvent focusEvent) { //Try to parse the number as a double double val = ClientUtilities.ToDouble (txtMoney.getText ()) ; //If it cannot be parsed show error message if (val == -1) { JOptionPane.showMessageDialog (null, "Not a valid amount...\n\n" + "Only positive amounts are allowed...", "Error", JOptionPane.ERROR_MESSAGE) ; txtMoney.grabFocus () ; txtMoney.selectAll () ; return ; } //Format the number and put it in the text box txtMoney.setText (twoDigits.format (val)) ; } } class frmNewCreditCard_txtMoney_focusAdapter extends FocusAdapter { private frmNewCreditCard adaptee ; frmNewCreditCard_txtMoney_focusAdapter (frmNewCreditCard adaptee) { this.adaptee = adaptee ; } public void focusLost (FocusEvent e) { 77

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


adaptee.txtMoney_focusLost (e) ; } } class frmNewCreditCard_btnAdd_actionAdapter implements ActionListener { private frmNewCreditCard adaptee ; frmNewCreditCard_btnAdd_actionAdapter (frmNewCreditCard adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnAdd_actionPerformed (e) ; } } class frmNewCreditCard_this_componentAdapter extends ComponentAdapter { private frmNewCreditCard adaptee ; frmNewCreditCard_this_componentAdapter (frmNewCreditCard adaptee) { this.adaptee = adaptee ; } public void componentHidden (ComponentEvent e) { adaptee.this_componentHidden (e) ; } }

78

SOURCE CODE Stathis Polyzos F.1.11. frmNewUserID.java

package ClientPack ; import java.awt.Font ; import java.awt.Rectangle ; import java.awt.event.* ; import javax.swing.* ; import import import import import CommonObjects.AddUser ; CommonObjects.LoginStatus ; CommonObjects.Entities.User ; GlobalPack.ClientUtilities ; GlobalPack.TradeToken ;

public class frmNewUserID extends JFrame { private LoginStatus status = null ; private static frmNewUserID unForm = null ; private int entityID ; private boolean isEmpl ; private JLabel jLabel1 = new JLabel () ; private JLabel jLabel2 = new JLabel () ; private JLabel jLabel3 = new JLabel () ; private JLabel jLabel4 = new JLabel () ; private JLabel jLabel5 = new JLabel () ; private JTextField txtRealName = new JTextField () ; private JTextField txtUserName = new JTextField () ; private JPasswordField pswPass = new JPasswordField () ; private JPasswordField pswPass2 = new JPasswordField () ; private JComboBox cmbLevel = new JComboBox () ; private JButton btnAdd = new JButton () ; private frmNewUserID (LoginStatus lgSt, String rlName, int ID, int[] levels, boolean empl) { status = lgSt ; entityID = ID ; isEmpl = empl ; if (!status.GetStatus ()) return ; try { jbInit (rlName, levels) ; } catch (Exception exception) { exception.printStackTrace () ; } } public static frmNewUserID Instance (LoginStatus lgSt, String rlName, int ID, int[] levels, boolean empl) { if (unForm == null) { unForm = new frmNewUserID (lgSt, rlName, ID, levels, empl) ; unForm.setLocation (70, 80) ; 79

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


} return unForm ; } private void jbInit (String rlName, int[] levels) throws Exception { this.setSize (400, 240) ; getContentPane ().setLayout (null) ; this.setResizable (false) ; this.setAlwaysOnTop (true) ; this.setTitle ("New User") ; this.addComponentListener (new frmNewUserID_this_componentAdapter (this)) ; jLabel1.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel1.setText ("Real Name") ; jLabel1.setBounds (new Rectangle (22, 38, 110, 22)) ; jLabel2.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel2.setText ("User Name") ; jLabel2.setBounds (new Rectangle (22, 62, 110, 22)) ; jLabel3.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel3.setText ("Password") ; jLabel3.setBounds (new Rectangle (22, 85, 110, 22)) ; jLabel4.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel4.setText ("Confirm Password") ; jLabel4.setBounds (new Rectangle (22, 109, 110, 22)) ; jLabel5.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel5.setText ("Access Level") ; jLabel5.setBounds (new Rectangle (22, 132, 110, 22)) ; txtRealName.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; txtRealName.setEditable (false) ; txtRealName.setBounds (new Rectangle (157, 41, 181, 19)) ; txtUserName.setBounds (new Rectangle (157, 65, 121, 19)) ; pswPass.setBounds (new Rectangle (157, 88, 100, 19)) ; pswPass2.setBounds (new Rectangle (157, 112, 100, 19)) ; cmbLevel.setBounds (new Rectangle (157, 135, 53, 19)) ; btnAdd.setBounds (new Rectangle (123, 172, 120, 23)) ; btnAdd.setText ("Add") ; btnAdd.addActionListener (new frmNewUserID_btnAdd_actionAdapter (this)) ; this.getContentPane ().add (jLabel1) ; this.getContentPane ().add (jLabel2) ; this.getContentPane ().add (jLabel3) ; this.getContentPane ().add (jLabel4) ; this.getContentPane ().add (jLabel5) ; this.getContentPane ().add (txtUserName) ; this.getContentPane ().add (txtRealName) ; this.getContentPane ().add (pswPass) ; this.getContentPane ().add (pswPass2) ; this.getContentPane ().add (cmbLevel) ; this.getContentPane ().add (btnAdd) ; //Read arguments and set options txtRealName.setText (rlName) ; for (int i = 0 ; i < levels.length ; i++) cmbLevel.addItem (String.valueOf (levels[i])) ; cmbLevel.setSelectedIndex (0) ; } public void this_componentHidden (ComponentEvent e) { unForm = null ; } 80

SOURCE CODE Stathis Polyzos

/** * Performs the add event. Verifies user inputs, sends request to server * and processes results * * @param e ActionEvent */ public void btnAdd_actionPerformed (ActionEvent e) { //Confirm if (JOptionPane.showConfirmDialog (null, "Confirm transaction...", "Confirmation", JOptionPane.YES_NO_OPTION) == 1) return ; String String char[] char[] errMsgs = "" ; bullet = " - " ; chPass = pswPass.getPassword () ; chPass2 = pswPass2.getPassword () ;

//Read passwords String pass = "" ; String pass2 = "" ; for (int i = 0 ; i < chPass.length ; i++) pass += chPass[i] ; for (int i = 0 ; i < chPass2.length ; i++) pass2 += chPass2[i] ; //Verify inputs if (txtUserName.getText ().length () == 0) errMsgs += bullet + "No user name selected\n" ; if (!pass.equals (pass2)) errMsgs += bullet + "Passwords do not match\n" ; if (!errMsgs.equals ("")) { JOptionPane.showMessageDialog (null, "Please collect the following errors:\n\n" + errMsgs + "\n", "Error", JOptionPane.ERROR_MESSAGE) ; return ; } //Build user object User usr = new User () ; usr.SetUserName (txtUserName.getText ()) ; usr.SetPass (pass) ; if (isEmpl) usr.SetEmployeeID (entityID) ; else usr.SetCustomerID (entityID) ; usr.SetAccessLevel (Integer.parseInt (cmbLevel.getSelectedItem ().toString ())) ; //Send request and get reply TradeToken ret = ClientUtilities.DispatchToken (new TradeToken (new AddUser ( status, usr), 17), status, "", 0) ; //Process reply and inform user of process results switch (ret.getType ()) { case 0: //User not added JOptionPane.showMessageDialog (null, 81

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


"A database error occured..\n\n" + "Please contact support immediately...\n\n", "Error", JOptionPane.ERROR_MESSAGE) ; break ; case 1: //User added JOptionPane.showMessageDialog (null, "User added successfully...\n", "Message", JOptionPane.INFORMATION_MESSAGE) ; this.setVisible (false) ; break ; case 2: //User exists JOptionPane.showMessageDialog (null, (isEmpl ? "Employee" : "Customer") + " already has user credentials...\n\n" + "Your request was NOT completed...\n\n", "Error", JOptionPane.ERROR_MESSAGE) ; break ; default: //Unknown error JOptionPane.showMessageDialog (null, "An error occured..\n\n" + "Please contact support immediately...\n\n", "Error", JOptionPane.ERROR_MESSAGE) ; break ; } } } class frmNewUserID_btnAdd_actionAdapter implements ActionListener { private frmNewUserID adaptee ; frmNewUserID_btnAdd_actionAdapter (frmNewUserID adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnAdd_actionPerformed (e) ; } } class frmNewUserID_this_componentAdapter extends ComponentAdapter { private frmNewUserID adaptee ; frmNewUserID_this_componentAdapter (frmNewUserID adaptee) { this.adaptee = adaptee ; } public void componentHidden (ComponentEvent e) { adaptee.this_componentHidden (e) ; } }

82

SOURCE CODE Stathis Polyzos F.1.12. frmPayCreditCard.java

package ClientPack ; import import import import java.awt.Font ; java.awt.Rectangle ; java.awt.event.* ; java.text.DecimalFormat ;

import javax.swing.* ; import import import import CommonObjects.CreditCardPayment ; CommonObjects.LoginStatus ; GlobalPack.ClientUtilities ; GlobalPack.TradeToken ;

public class frmPayCreditCard extends JFrame { private LoginStatus status = null ; private JTextField cmbToCreditCard = new JTextField () ; private JLabel jLabel2 = new JLabel () ; private JTextField txtMoney = new JTextField () ; private JLabel jLabel3 = new JLabel () ; private JButton btnTransfer = new JButton () ; DecimalFormat twoDigits = new DecimalFormat ("#,##0.00") ; private static frmPayCreditCard unForm = null ; private frmPayCreditCard (LoginStatus lgSt) { status = lgSt ; if (!status.GetStatus ()) return ; try { jbInit () ; } catch (Exception exception) { exception.printStackTrace () ; } } public static frmPayCreditCard Instance (LoginStatus lgSt) { if (unForm == null) { unForm = new frmPayCreditCard (lgSt) ; unForm.setLocation (70, 80) ; } return unForm ; } private void jbInit () throws Exception { this.setSize (400, 240) ; getContentPane ().setLayout (null) ; cmbToCreditCard.setBounds (new Rectangle (116, 33, 221, 22)) ; cmbToCreditCard.addFocusListener (new 83

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


frmPayCreditCard_cmbToCreditCard_focusAdapter (this)) ; jLabel2.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel2.setToolTipText ("") ; jLabel2.setText ("Credit Card") ; jLabel2.setBounds (new Rectangle (22, 33, 85, 22)) ; this.setResizable (false) ; this.setTitle ("Pay Credit Card") ; this.addComponentListener (new frmPayCreditCard_this_componentAdapter (this)) ; txtMoney.setText (twoDigits.format (0)) ; txtMoney.setHorizontalAlignment (SwingConstants.TRAILING) ; txtMoney.setBounds (new Rectangle (116, 60, 111, 22)) ; txtMoney.addFocusListener (new frmPayCreditCard_txtMoney_focusAdapter (this)) ; jLabel3.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel3.setText ("Amount") ; jLabel3.setBounds (new Rectangle (22, 60, 85, 22)) ; btnTransfer.setBounds (new Rectangle (95, 103, 195, 36)) ; btnTransfer.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; btnTransfer.setText ("Transfer") ; btnTransfer.addActionListener (new frmPayCreditCard_btnTransfer_actionAdapter (this)) ; this.getContentPane ().add (cmbToCreditCard) ; this.getContentPane ().add (jLabel2) ; this.getContentPane ().add (txtMoney) ; this.getContentPane ().add (jLabel3) ; this.getContentPane ().add (btnTransfer) ; } /** * Verifies the money text field and also formats it as a decimal with two * decimal places, also using the thousands separator * * @param focusEvent FocusEvent */ public void txtMoney_focusLost (FocusEvent focusEvent) { //Try to parse the number as a double double val = ClientUtilities.ToDouble (txtMoney.getText ()) ; //If it cannot be parsed show error message if (val == -1) { JOptionPane.showMessageDialog (null, "Not a valid amount...\n\n" + "Only positive amounts are allowed...", "Error", JOptionPane.ERROR_MESSAGE) ; txtMoney.grabFocus () ; txtMoney.selectAll () ; return ; } //Format the number and put it in the text box txtMoney.setText (twoDigits.format (val)) ; } /** * Performs * verifies * added to * * @param e */ public void { 84

the transaction. Reads card information from the server, user inputs and sends to transaction to the server to be the database ActionEvent btnTransfer_actionPerformed (ActionEvent e)

SOURCE CODE Stathis Polyzos

//Confirm if (JOptionPane.showConfirmDialog (null, "Confirm transaction...", "Confirmation", JOptionPane.YES_NO_OPTION) == 1) return ; String ccNoTo = cmbToCreditCard.getText ().replace (" ", "") ; Double amt = ClientUtilities.ToDouble (txtMoney.getText ()) ; //Check amount if (amt <= 0) { JOptionPane.showMessageDialog (null, "Please enter a valid amount...", "Error", JOptionPane.ERROR_MESSAGE) ; return ; } //Send information to server and get reply TradeToken rec = ClientUtilities.DispatchToken (new TradeToken (new CreditCardPayment (status, ccNoTo, amt), 9), status, "", 0) ; //Check completion of transaction and inform user if (rec.getType () != 1) { JOptionPane.showMessageDialog (null, "Transaction was not added...\n\n" + "Please contact the DORbank support line...\n\n", "Error", JOptionPane.ERROR_MESSAGE) ; return ; } JOptionPane.showMessageDialog (null, "Your payment was successful...", "Information", JOptionPane.INFORMATION_MESSAGE) ; this.setVisible (false) ; } public void this_componentHidden (ComponentEvent e) { unForm = null ; } /** * Verifies and formats the credit cards number. This method does NOT * verify that a card by that number exists, but rather checks that * the number is a possible one (i.e. has 16 digits) * * @param e FocusEvent */ public void cmbToCreditCard_focusLost (FocusEvent e) { //Check length if (cmbToCreditCard.getText ().replace (" ", "").length () != 16) { JOptionPane.showMessageDialog (null, "Invalid card number...", "Error", JOptionPane.ERROR_MESSAGE) ; cmbToCreditCard.grabFocus () ; cmbToCreditCard.selectAll () ; return ; } //Format string adding a space every 4 digits String gtStr = cmbToCreditCard.getText () ; String rtStr = "" ; 85

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


for (int i = 0 ; i < gtStr.length () ; i++) { rtStr += gtStr.substring (i, i + 1) ; if ((i + 1) % 4 == 0) rtStr += " " ; } cmbToCreditCard.setText (rtStr) ; } } class frmPayCreditCard_cmbToCreditCard_focusAdapter extends FocusAdapter { private frmPayCreditCard adaptee ; frmPayCreditCard_cmbToCreditCard_focusAdapter (frmPayCreditCard adaptee) { this.adaptee = adaptee ; } public void focusLost (FocusEvent e) { adaptee.cmbToCreditCard_focusLost (e) ; } } class frmPayCreditCard_this_componentAdapter extends ComponentAdapter { private frmPayCreditCard adaptee ; frmPayCreditCard_this_componentAdapter (frmPayCreditCard adaptee) { this.adaptee = adaptee ; } public void componentHidden (ComponentEvent e) { adaptee.this_componentHidden (e) ; } } class frmPayCreditCard_btnTransfer_actionAdapter implements ActionListener { private frmPayCreditCard adaptee ; frmPayCreditCard_btnTransfer_actionAdapter (frmPayCreditCard adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnTransfer_actionPerformed (e) ; } } class frmPayCreditCard_txtMoney_focusAdapter extends FocusAdapter { private frmPayCreditCard adaptee ; frmPayCreditCard_txtMoney_focusAdapter (frmPayCreditCard adaptee) 86

SOURCE CODE Stathis Polyzos

{ this.adaptee = adaptee ; } public void focusLost (FocusEvent focusEvent) { adaptee.txtMoney_focusLost (focusEvent) ; } }

87

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


F.1.13. frmPayUtility.java package ClientPack ; import import import import java.awt.Font ; java.awt.Rectangle ; java.awt.event.* ; java.text.DecimalFormat ;

import javax.swing.* ; import import import import import CommonObjects.LoginStatus ; CommonObjects.MakeTransfer ; CommonObjects.Entities.Account ; GlobalPack.ClientUtilities ; GlobalPack.TradeToken ;

public class frmPayUtility extends JFrame { private LoginStatus status = null ; private JComboBox cmbFromAccount = new JComboBox () ; private JComboBox cmbToAccount = new JComboBox () ; private Account[] cusAccounts ; private Account[] pubAccounts ; private JLabel jLabel1 = new JLabel () ; private JLabel jLabel2 = new JLabel () ; private JTextField txtMoney = new JTextField () ; private JLabel jLabel3 = new JLabel () ; DecimalFormat twoDigits = new DecimalFormat ("#,##0.00") ; private static frmPayUtility unForm = null ; private JTextField txtCusNumber = new JTextField () ; private JLabel jLabel4 = new JLabel () ; private JButton btnTransfer = new JButton () ; private frmPayUtility (LoginStatus lgSt) { status = lgSt ; if (!status.GetStatus ()) return ; try { jbInit () ; } catch (Exception exception) { exception.printStackTrace () ; } } public static frmPayUtility Instance (LoginStatus lgSt) { if (unForm == null) { unForm = new frmPayUtility (lgSt) ; unForm.setLocation (70, 110) ; } return unForm ; } 88

SOURCE CODE Stathis Polyzos

private void jbInit () throws Exception { this.setSize (400, 240) ; getContentPane ().setLayout (null) ; cmbFromAccount.setBounds (new Rectangle (154, 34, 184, 22)) ; cmbToAccount.setBounds (new Rectangle (154, 62, 184, 22)) ; jLabel1.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel1.setText ("From Account") ; jLabel1.setBounds (new Rectangle (36, 34, 85, 22)) ; jLabel2.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel2.setText ("To Utility") ; jLabel2.setBounds (new Rectangle (36, 62, 85, 22)) ; this.setResizable (false) ; this.setTitle ("Pay Utility") ; this.addComponentListener (new frmPayUtility_this_componentAdapter (this)) ; txtMoney.setText (twoDigits.format (0)) ; txtMoney.setHorizontalAlignment (SwingConstants.TRAILING) ; txtMoney.setBounds (new Rectangle (154, 89, 111, 22)) ; txtMoney.addFocusListener (new frmPayUtility_txtMoney_focusAdapter (this)) ; jLabel3.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel3.setText ("Amount") ; jLabel3.setBounds (new Rectangle (36, 89, 85, 22)) ; txtCusNumber.setText ("") ; txtCusNumber.setBounds (new Rectangle (154, 117, 197, 22)) ; jLabel4.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel4.setText ("Utility Cus. Number") ; jLabel4.setBounds (new Rectangle (36, 117, 113, 22)) ; btnTransfer.setBounds (new Rectangle (93, 157, 195, 36)) ; btnTransfer.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; btnTransfer.setText ("Transfer") ; btnTransfer.addActionListener (new frmPayUtility_btnTransfer_actionAdapter (this)) ; this.getContentPane ().add (cmbToAccount) ; this.getContentPane ().add (txtMoney) ; this.getContentPane ().add (txtCusNumber) ; this.getContentPane ().add (jLabel4) ; this.getContentPane ().add (cmbFromAccount) ; this.getContentPane ().add (jLabel1) ; this.getContentPane ().add (jLabel3) ; this.getContentPane ().add (jLabel2) ; this.getContentPane ().add (btnTransfer) ; //Get user and PUC accounts and fill combo boxes cusAccounts = ClientUtilities.GetUserAccounts (status) ; pubAccounts = ClientUtilities.GetPubUtilAccounts (status) ; for (int i = 0 ; i < cusAccounts.length ; i++) cmbFromAccount.addItem (cusAccounts[i].GetAccountNumber ()) ; for (int i = 0 ; i < pubAccounts.length ; i++) cmbToAccount.addItem (pubAccounts[i].GetCustomerName ()) ; cmbFromAccount.setSelectedIndex (0) ; cmbToAccount.setSelectedIndex (0) ; } /** * Looks through the cusAccounts array for an account object that matches * the given account number. * * @param accNumber String * @return Account 89

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


*/ private Account GetAccountByNo (String accNumber) { for (int i = 0 ; i < cusAccounts.length ; i++) if (cusAccounts[i].GetAccountNumber ().equals (accNumber)) return cusAccounts[i] ; return null ; } /** * Looks through the pubAccount array for an account object where the customer * name matches the given argument. * * @param cusName String * @return Account */ private Account GetAccountByName (String cusName) { for (int i = 0 ; i < pubAccounts.length ; i++) if (pubAccounts[i].GetCustomerName ().equals (cusName)) return pubAccounts[i] ; return null ; } /** * Verifies the money text field and also formats it as a decimal with two * decimal places, also using the thousands separator * * @param focusEvent FocusEvent */ public void txtMoney_focusLost (FocusEvent focusEvent) { double val = ClientUtilities.ToDouble (txtMoney.getText ()) ; if (val == -1) { JOptionPane.showMessageDialog (null, "Not a valid amount...\n\n" + "Only positive amounts are allowed...", "Error", JOptionPane.ERROR_MESSAGE) ; this.txtMoney.grabFocus () ; this.txtMoney.selectAll () ; return ; } txtMoney.setText (twoDigits.format (val)) ; } /** * Performs the Transfer action. Sends a request to the server to transfer * money between the two accounts * * @param e ActionEvent */ public void btnTransfer_actionPerformed (ActionEvent e) { //Confirm if (JOptionPane.showConfirmDialog (null, "Confirm transaction...", "Confirmation", JOptionPane.YES_NO_OPTION) == 1) return ;

90

SOURCE CODE Stathis Polyzos

//Read String accNoTo = Double

data accNoFrom = cmbFromAccount.getSelectedItem ().toString (), cmbToAccount.getSelectedItem ().toString () ; amt = ClientUtilities.ToDouble (txtMoney.getText ()) ;

//Verify that a customer number has been entered if (txtCusNumber.getText ().length () == 0) { JOptionPane.showMessageDialog (null, "Please enter your customer number " + "for the selected\npublic utility company...\n", "Error", JOptionPane.ERROR_MESSAGE) ; return ; } //Check that the amount is a positive number if (amt <= 0) { JOptionPane.showMessageDialog (null, "Please enter a valid amount...", "Error", JOptionPane.ERROR_MESSAGE) ; return ; } //Check that there are enough funds at the source account if (amt > GetAccountByNo (accNoFrom).GetBalance ()) { JOptionPane.showMessageDialog (null, "Insufficient funds at source" + " account...", "Error", JOptionPane.ERROR_MESSAGE) ; return ; } //Send token and get reply TradeToken rec = ClientUtilities.DispatchToken (new TradeToken ( new MakeTransfer (status, GetAccountByNo (accNoFrom), GetAccountByName (accNoTo), amt, txtCusNumber.getText ()), 4), status, "", 0) ; //Check for confirmation and show messages if (rec.getType () != 1) { JOptionPane.showMessageDialog (null, "Transaction was not added...\n\n" + "Please contact the DORbank support line...\n\n", "Error", JOptionPane.ERROR_MESSAGE) ; return ; } JOptionPane.showMessageDialog (null, "Your payment was successful...", "Information", JOptionPane.INFORMATION_MESSAGE) ; this.setVisible (false) ; } public void this_componentHidden (ComponentEvent e) { unForm = null ; } } class frmPayUtility_btnTransfer_actionAdapter implements ActionListener { 91

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


private frmPayUtility adaptee ; frmPayUtility_btnTransfer_actionAdapter (frmPayUtility adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnTransfer_actionPerformed (e) ; } } class frmPayUtility_this_componentAdapter extends ComponentAdapter { private frmPayUtility adaptee ; frmPayUtility_this_componentAdapter (frmPayUtility adaptee) { this.adaptee = adaptee ; } public void componentHidden (ComponentEvent e) { adaptee.this_componentHidden (e) ; } } class frmPayUtility_txtMoney_focusAdapter extends FocusAdapter { private frmPayUtility adaptee ; frmPayUtility_txtMoney_focusAdapter (frmPayUtility adaptee) { this.adaptee = adaptee ; } public void focusLost (FocusEvent focusEvent) { adaptee.txtMoney_focusLost (focusEvent) ; } }

92

SOURCE CODE Stathis Polyzos F.1.14. frmTransaction.java

package ClientPack ; import import import import java.awt.Font ; java.awt.Rectangle ; java.awt.event.* ; java.text.DecimalFormat ;

import javax.swing.* ; import import import import CommonObjects.* ; CommonObjects.Entities.Account ; GlobalPack.ClientUtilities ; GlobalPack.TradeToken ;

public class frmTransaction extends JFrame { private LoginStatus status = null ; private int type ; private JTextField txtAccount = new JTextField () ; private JLabel jLabel1 = new JLabel () ; private JTextField txtMoney = new JTextField () ; private JLabel jLabel3 = new JLabel () ; private JButton btnGo = new JButton () ; DecimalFormat twoDigits = new DecimalFormat ("#,##0.00") ; private static frmTransaction unForm = null ; private JTextField txtComments = new JTextField () ; private JLabel jLabel2 = new JLabel () ; private frmTransaction (LoginStatus lgSt, int tp) { status = lgSt ; type = tp ; if (!status.GetStatus ()) { return ; } try { this.setSize (400, 240) ; jbInit () ; } catch (Exception exception) { exception.printStackTrace () ; } } public static frmTransaction Instance (LoginStatus lgSt, int tp) { if (unForm == null) { unForm = new frmTransaction (lgSt, tp) ; unForm.setLocation (70, 80) ; } return unForm ; } 93

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


private void jbInit () throws Exception { getContentPane ().setLayout (null) ; txtAccount.setBounds (new Rectangle (116, 34, 184, 22)) ; jLabel1.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel1.setToolTipText ("") ; jLabel1.setText ("Account") ; jLabel1.setBounds (new Rectangle (22, 34, 85, 22)) ; this.setResizable (false) ; this.setTitle ("Make " + (type == 1 ? "Withdrawal" : "Deposit")) ; this.addComponentListener (new frmTransaction_this_componentAdapter (this)) ; txtMoney.setText (twoDigits.format (0)) ; txtMoney.setHorizontalAlignment (SwingConstants.TRAILING) ; txtMoney.setBounds (new Rectangle (115, 63, 111, 22)) ; txtMoney.addFocusListener (new frmTransaction_txtMoney_focusAdapter (this)) ; jLabel3.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel3.setText ("Amount") ; jLabel3.setBounds (new Rectangle (22, 63, 85, 22)) ; btnGo.setBounds (new Rectangle (103, 129, 195, 36)) ; btnGo.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; btnGo.setText (type == 1 ? "Withdraw" : "Deposit") ; btnGo.addActionListener (new frmTransaction_btnGo_actionAdapter (this)) ; txtComments.setText ("") ; txtComments.setBounds (new Rectangle (115, 90, 163, 24)) ; jLabel2.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel2.setText ("Comments") ; jLabel2.setBounds (new Rectangle (22, 92, 85, 22)) ; this.getContentPane ().add (txtAccount) ; this.getContentPane ().add (jLabel1) ; this.getContentPane ().add (txtMoney) ; this.getContentPane ().add (jLabel3) ; this.getContentPane ().add (txtComments) ; this.getContentPane ().add (jLabel2) ; this.getContentPane ().add (btnGo) ; } /** * Verifies the money text field and also formats it as a decimal with two * decimal places, also using the thousands separator * * @param focusEvent FocusEvent */ public void txtMoney_focusLost (FocusEvent focusEvent) { //Try to parse the number as a double double val = ClientUtilities.ToDouble (txtMoney.getText ()) ; //If it cannot be parsed show error message if (val == -1) { JOptionPane.showMessageDialog (null, "Not a valid amount...\n\n" + "Only positive amounts are allowed...", "Error", JOptionPane.ERROR_MESSAGE) ; txtMoney.grabFocus () ; txtMoney.selectAll () ; return ; } //Format the number and put it in the text box txtMoney.setText (twoDigits.format (val)) ; } 94

SOURCE CODE Stathis Polyzos

/** * Performs the transaction. Reads account information from the server, * verifies user inputs and sends to transaction to the server to be * added to the database * * @param e ActionEvent */ public void btnGo_actionPerformed (ActionEvent e) { //Confirm if (JOptionPane.showConfirmDialog (null, "Confirm transaction...", "Confirmation", JOptionPane.YES_NO_OPTION) == 1) return ; String accNo = txtAccount.getText () ; String comment = txtComments.getText () ; Double amt = ClientUtilities.ToDouble (txtMoney.getText ()) ; //Check for negative amounts if (amt <= 0) { JOptionPane.showMessageDialog (null, "Please enter a valid amount...", "Error", JOptionPane.ERROR_MESSAGE) ; return ; } //Read account information from server Account acc = (Account) ClientUtilities.DispatchToken (new TradeToken ( new GetAccount (accNo, status), 7), status, "", 0).getData () ; //If account does not exist if (acc.GetID () == 0) { JOptionPane.showMessageDialog (null, "Account does not exist...", "Error", JOptionPane.ERROR_MESSAGE) ; return ; } //Check balance if (amt > acc.GetBalance () && type == 1) { JOptionPane.showMessageDialog (null, "Insufficient funds at source" + " account...", "Error", JOptionPane.ERROR_MESSAGE) ; return ; } //Send transaction and get reply TradeToken rec = ClientUtilities.DispatchToken (new TradeToken ( new MakeTransaction (status, acc, type, amt, comment), 8), status, "", 0) ; //Check completion of transaction and inform user if (rec.getType () != 1) { JOptionPane.showMessageDialog (null, "Transaction was not added...\n\n" + "Please contact the DORbank support line...\n\n", "Error", JOptionPane.ERROR_MESSAGE) ; return ; 95

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


} JOptionPane.showMessageDialog (null, "Your transfer was successful...", "Information", JOptionPane.INFORMATION_MESSAGE) ; this.setVisible (false) ; } public void this_componentHidden (ComponentEvent e) { unForm = null ; } } class frmTransaction_this_componentAdapter extends ComponentAdapter { private frmTransaction adaptee ; frmTransaction_this_componentAdapter (frmTransaction adaptee) { this.adaptee = adaptee ; } public void componentHidden (ComponentEvent e) { adaptee.this_componentHidden (e) ; } } class frmTransaction_btnGo_actionAdapter implements ActionListener { private frmTransaction adaptee ; frmTransaction_btnGo_actionAdapter (frmTransaction adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnGo_actionPerformed (e) ; } } class frmTransaction_txtMoney_focusAdapter extends FocusAdapter { private frmTransaction adaptee ; frmTransaction_txtMoney_focusAdapter (frmTransaction adaptee) { this.adaptee = adaptee ; } public void focusLost (FocusEvent focusEvent) { adaptee.txtMoney_focusLost (focusEvent) ; } }

96

SOURCE CODE Stathis Polyzos F.1.15. frmTransfer.java

package ClientPack ; import import import import java.awt.Font ; java.awt.Rectangle ; java.awt.event.* ; java.text.DecimalFormat ;

import javax.swing.* ; import import import import import CommonObjects.LoginStatus ; CommonObjects.MakeTransfer ; CommonObjects.Entities.Account ; GlobalPack.ClientUtilities ; GlobalPack.TradeToken ;

public class frmTransfer extends JFrame { private LoginStatus status = null ; private JComboBox cmbFromAccount = new JComboBox () ; private JComboBox cmbToAccount = new JComboBox () ; private Account[] cusAccounts ; private JLabel jLabel1 = new JLabel () ; private JLabel jLabel2 = new JLabel () ; private JTextField txtMoney = new JTextField () ; private JLabel jLabel3 = new JLabel () ; private JButton btnTransfer = new JButton () ; private DecimalFormat twoDigits = new DecimalFormat ("#,##0.00") ; private static frmTransfer unForm = null ; private frmTransfer (LoginStatus lgSt) { status = lgSt ; if (!status.GetStatus ()) return ; try { jbInit () ; } catch (Exception exception) { exception.printStackTrace () ; } } public static frmTransfer Instance (LoginStatus lgSt) { if (unForm == null) { unForm = new frmTransfer (lgSt) ; unForm.setLocation (70, 80) ; } return unForm ; } private void jbInit () throws Exception { 97

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


this.setSize (400, 240) ; getContentPane ().setLayout (null) ; cmbFromAccount.setBounds (new Rectangle (116, 34, 184, 22)) ; cmbToAccount.setBounds (new Rectangle (116, 62, 184, 22)) ; jLabel1.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel1.setText ("From Account") ; jLabel1.setBounds (new Rectangle (22, 34, 85, 22)) ; jLabel2.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel2.setText ("To Account") ; jLabel2.setBounds (new Rectangle (22, 62, 85, 22)) ; this.setResizable (false) ; this.setTitle ("Transfer Money") ; this.addComponentListener (new frmTransfer_this_componentAdapter (this)) ; txtMoney.setText (twoDigits.format (0)) ; txtMoney.setHorizontalAlignment (SwingConstants.TRAILING) ; txtMoney.setBounds (new Rectangle (116, 89, 111, 22)) ; txtMoney.addFocusListener (new frm_Transfer_txtMoney_focusAdapter (this)) ; jLabel3.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel3.setText ("Amount") ; jLabel3.setBounds (new Rectangle (22, 89, 85, 22)) ; btnTransfer.setBounds (new Rectangle (93, 132, 195, 36)) ; btnTransfer.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; btnTransfer.setText ("Transfer") ; btnTransfer.addActionListener (new frm_Transfer_btnTransfer_actionAdapter (this)) ; this.getContentPane ().add (cmbFromAccount) ; this.getContentPane ().add (jLabel2) ; this.getContentPane ().add (cmbToAccount) ; this.getContentPane ().add (jLabel1) ; this.getContentPane ().add (txtMoney) ; this.getContentPane ().add (jLabel3) ; this.getContentPane ().add (btnTransfer) ; //Get user accounts cusAccounts = ClientUtilities.GetUserAccounts (status) ; //Verify number of customer accounts if (cusAccounts.length < 2) { JOptionPane.showMessageDialog(null, "Need more than two accounts...", "Error", JOptionPane.ERROR_MESSAGE); this.setVisible(false); return; } //Fill combo boxes for (int i = 0 ; i < cusAccounts.length ; i++) { cmbFromAccount.addItem (cusAccounts[i].GetAccountNumber ()) ; cmbToAccount.addItem (cusAccounts[i].GetAccountNumber ()) ; } cmbFromAccount.setSelectedIndex (0) ; cmbToAccount.setSelectedIndex (1) ; } /** * Looks through the cusAccounts array for an account object that matches * the given account number. * * @param accNumber String 98

SOURCE CODE Stathis Polyzos

* @return Account */ private Account GetAccountByNo (String accNumber) { for (int i = 0 ; i < cusAccounts.length ; i++) if (cusAccounts[i].GetAccountNumber ().equals (accNumber)) return cusAccounts[i] ; return null ; } /** * Verifies the money text field and also formats it as a decimal with two * decimal places, also using the thousands separator * * @param focusEvent FocusEvent */ public void txtMoney_focusLost (FocusEvent focusEvent) { //Try to parse the number as a double double val = ClientUtilities.ToDouble (txtMoney.getText ()) ; //If it cannot be parsed show error message if (val == -1) { JOptionPane.showMessageDialog (null, "Not a valid amount...\n\n" + "Only positive amounts are allowed...", "Error", JOptionPane.ERROR_MESSAGE) ; txtMoney.grabFocus () ; txtMoney.selectAll () ; return ; } //Format the number and put it in the text box txtMoney.setText (twoDigits.format (val)) ; } /** * Performs the Transfer action. Sends a request to the server to transfer * money between the two accounts * * @param e ActionEvent */ public void btnTransfer_actionPerformed (ActionEvent e) { //Confirm if (JOptionPane.showConfirmDialog (null, "Confirm transaction...", "Confirmation", JOptionPane.YES_NO_OPTION) == 1) return ; //Read String accNoTo = Double data accNoFrom = cmbFromAccount.getSelectedItem ().toString (), cmbToAccount.getSelectedItem ().toString () ; amt = ClientUtilities.ToDouble (txtMoney.getText ()) ;

//Check that the account are not the same if (accNoFrom.equals (accNoTo)) { JOptionPane.showMessageDialog (null, "Please select different accounts...", "Error", JOptionPane.ERROR_MESSAGE) ; return ; 99

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


} //Check that the amount is a positive number if (amt <= 0) { JOptionPane.showMessageDialog (null, "Please enter a valid amount...", "Error", JOptionPane.ERROR_MESSAGE) ; return ; } //Check that there are enough funds at the source account if (amt > GetAccountByNo (accNoFrom).GetBalance ()) { JOptionPane.showMessageDialog (null, "Insufficient funds at source" + " account...", "Error", JOptionPane.ERROR_MESSAGE) ; return ; } //Send the object and get the reply TradeToken rec = ClientUtilities.DispatchToken (new TradeToken ( new MakeTransfer (status, GetAccountByNo (accNoFrom), GetAccountByNo (accNoTo), amt, ""), 4), status, "", 0) ; //Check for confirmation and show messages if (rec.getType () != 1) { JOptionPane.showMessageDialog (null, "Transaction was not added...\n\n" + "Please contact the DORbank support line...\n\n", "Error", JOptionPane.ERROR_MESSAGE) ; return ; } JOptionPane.showMessageDialog (null, "Your transfer was successful...", "Information", JOptionPane.INFORMATION_MESSAGE) ; this.setVisible (false) ; } public void this_componentHidden (ComponentEvent e) { unForm = null ; } } class frmTransfer_this_componentAdapter extends ComponentAdapter { private frmTransfer adaptee ; frmTransfer_this_componentAdapter (frmTransfer adaptee) { this.adaptee = adaptee ; } public void componentHidden (ComponentEvent e) { adaptee.this_componentHidden (e) ; } } class frm_Transfer_btnTransfer_actionAdapter implements ActionListener 100

SOURCE CODE Stathis Polyzos

{ private frmTransfer adaptee ; frm_Transfer_btnTransfer_actionAdapter (frmTransfer adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnTransfer_actionPerformed (e) ; } } class frm_Transfer_txtMoney_focusAdapter extends FocusAdapter { private frmTransfer adaptee ; frm_Transfer_txtMoney_focusAdapter (frmTransfer adaptee) { this.adaptee = adaptee ; } public void focusLost (FocusEvent focusEvent) { adaptee.txtMoney_focusLost (focusEvent) ; } }

101

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


F.1.16. frmTransferCreditCard.java package ClientPack ; import import import import java.awt.Font ; java.awt.Rectangle ; java.awt.event.* ; java.text.DecimalFormat ;

import javax.swing.* ; import import import import import import CommonObjects.LoginStatus ; CommonObjects.MakeTransferToCredit ; CommonObjects.Entities.Account ; CommonObjects.Entities.CreditCard ; GlobalPack.ClientUtilities ; GlobalPack.TradeToken ;

public class frmTransferCreditCard extends JFrame { private LoginStatus status = null ; private JComboBox cmbFromAccount = new JComboBox () ; private JComboBox cmbToCreditCard = new JComboBox () ; private Account[] cusAccounts ; private CreditCard[] cusCrCards ; private JLabel jLabel1 = new JLabel () ; private JLabel jLabel2 = new JLabel () ; private JTextField txtMoney = new JTextField () ; private JLabel jLabel3 = new JLabel () ; private JButton btnTransfer = new JButton () ; DecimalFormat twoDigits = new DecimalFormat ("#,##0.00") ; private static frmTransferCreditCard unForm = null ; private frmTransferCreditCard (LoginStatus lgSt) { status = lgSt ; if (!status.GetStatus ()) return ; try { jbInit () ; } catch (Exception exception) { exception.printStackTrace () ; } } public static frmTransferCreditCard Instance (LoginStatus lgSt) { if (unForm == null) { unForm = new frmTransferCreditCard (lgSt) ; unForm.setLocation (70, 80) ; } return unForm ; } private void jbInit () 102

SOURCE CODE Stathis Polyzos

throws Exception { this.setSize (400, 240) ; getContentPane ().setLayout (null) ; cmbFromAccount.setBounds (new Rectangle (116, 34, 184, 22)) ; cmbToCreditCard.setBounds (new Rectangle (116, 62, 184, 22)) ; jLabel1.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel1.setText ("From Account") ; jLabel1.setBounds (new Rectangle (22, 34, 85, 22)) ; jLabel2.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel2.setText ("To Credit Card") ; jLabel2.setBounds (new Rectangle (22, 62, 85, 22)) ; this.setResizable (false) ; this.setTitle ("Pay Credit Card") ; this.addComponentListener (new frmTransferCreditCard_this_componentAdapter (this)) ; txtMoney.setText (twoDigits.format (0)) ; txtMoney.setHorizontalAlignment (SwingConstants.TRAILING) ; txtMoney.setBounds (new Rectangle (116, 89, 111, 22)) ; txtMoney.addFocusListener (new frmTransferCreditCard_txtMoney_focusAdapter (this)) ; jLabel3.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel3.setText ("Amount") ; jLabel3.setBounds (new Rectangle (22, 89, 85, 22)) ; btnTransfer.setBounds (new Rectangle (93, 132, 195, 36)) ; btnTransfer.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; btnTransfer.setText ("Transfer") ; btnTransfer.addActionListener (new frmTransferCreditCard_btnTransfer_actionAdapter (this)) ; this.getContentPane ().add (cmbFromAccount) ; this.getContentPane ().add (jLabel2) ; this.getContentPane ().add (cmbToCreditCard) ; this.getContentPane ().add (jLabel1) ; this.getContentPane ().add (txtMoney) ; this.getContentPane ().add (jLabel3) ; this.getContentPane ().add (btnTransfer) ; //Get user accounts and credit cards and fill combo boxes cusAccounts = ClientUtilities.GetUserAccounts (status) ; cusCrCards = ClientUtilities.GetUserCreditCards (status) ; for (int i = 0 ; i < cusAccounts.length ; i++) cmbFromAccount.addItem (cusAccounts[i].GetAccountNumber ()) ; for (int i = 0 ; i < cusCrCards.length ; i++) cmbToCreditCard.addItem (cusCrCards[i].GetCreditCardNumberFormatted ()) ; cmbFromAccount.setSelectedIndex (0) ; cmbToCreditCard.setSelectedIndex (0) ; } /** * Looks through the cusAccounts array for an account object that matches * the given account number. * * @param accNumber String * @return Account */ private Account GetAccountByNo (String accNumber) { for (int i = 0 ; i < cusAccounts.length ; i++) if (cusAccounts[i].GetAccountNumber ().equals (accNumber)) return cusAccounts[i] ; 103

SUPERTRANS CUSTOMER TRANSACTION SYSTEM

return null ; } /** * Looks through the cusCrCards array for a Credit Card object that matches * the given card number. * * @param ccNumber String * @return CreditCard */ private CreditCard GetCreditCardByNo (String ccNumber) { for (int i = 0 ; i < cusCrCards.length ; i++) if (cusCrCards[i].GetCreditCardNumberFormatted ().equals (ccNumber)) return cusCrCards[i] ; return null ; } /** * Verifies the money text field and also formats it as a decimal with two * decimal places, also using the thousands separator * * @param focusEvent FocusEvent */ public void txtMoney_focusLost (FocusEvent focusEvent) { double val = ClientUtilities.ToDouble (txtMoney.getText ()) ; if (val == -1) { JOptionPane.showMessageDialog (null, "Not a valid amount...\n\n" + "Only positive amounts are allowed...", "Error", JOptionPane.ERROR_MESSAGE) ; this.txtMoney.grabFocus () ; this.txtMoney.selectAll () ; return ; } txtMoney.setText (twoDigits.format (val)) ; } /** * Performs the Transfer action. Sends a request to the server to transfer * money between the two accounts * * @param e ActionEvent */ public void btnTransfer_actionPerformed (ActionEvent e) { //Confirm if (JOptionPane.showConfirmDialog (null, "Confirm transaction...", "Confirmation", JOptionPane.YES_NO_OPTION) == 1) return ; //Read data String accNoFrom = cmbFromAccount.getSelectedItem ().toString (), ccNoTo = cmbToCreditCard.getSelectedItem ().toString () ; Double amt = ClientUtilities.ToDouble (txtMoney.getText ()) ; //Check that the amount is a positive number 104

SOURCE CODE Stathis Polyzos

if (amt <= 0) { JOptionPane.showMessageDialog (null, "Please enter a valid amount...", "Error", JOptionPane.ERROR_MESSAGE) ; return ; } //Check that there are enough funds at the source account if (amt > GetAccountByNo (accNoFrom).GetBalance ()) { JOptionPane.showMessageDialog (null, "Insufficient funds at source" + " account...", "Error", JOptionPane.ERROR_MESSAGE) ; return ; } //Send token and get reply TradeToken rec = ClientUtilities.DispatchToken (new TradeToken ( new MakeTransferToCredit ( status, GetAccountByNo (accNoFrom), GetCreditCardByNo (ccNoTo), amt), 5), status, "", 0) ; //Check for confirmation and show messages if (rec.getType () != 1) { JOptionPane.showMessageDialog (null, "Transaction was not added...\n\n" + "Please contact the DORbank support line...\n\n", "Error", JOptionPane.ERROR_MESSAGE) ; return ; } JOptionPane.showMessageDialog (null, "Your payment was successful...", "Information", JOptionPane.INFORMATION_MESSAGE) ; this.setVisible (false) ; } public void this_componentHidden (ComponentEvent e) { unForm = null ; } } class frmTransferCreditCard_this_componentAdapter extends ComponentAdapter { private frmTransferCreditCard adaptee ; frmTransferCreditCard_this_componentAdapter (frmTransferCreditCard adaptee) { this.adaptee = adaptee ; } public void componentHidden (ComponentEvent e) { adaptee.this_componentHidden (e) ; } } class frmTransferCreditCard_btnTransfer_actionAdapter implements ActionListener { private frmTransferCreditCard adaptee ; 105

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


frmTransferCreditCard_btnTransfer_actionAdapter (frmTransferCreditCard adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnTransfer_actionPerformed (e) ; } } class frmTransferCreditCard_txtMoney_focusAdapter extends FocusAdapter { private frmTransferCreditCard adaptee ; frmTransferCreditCard_txtMoney_focusAdapter (frmTransferCreditCard adaptee) { this.adaptee = adaptee ; } public void focusLost (FocusEvent focusEvent) { adaptee.txtMoney_focusLost (focusEvent) ; } }

106

SOURCE CODE Stathis Polyzos F.1.17. frmUtilityTransaction.java

package ClientPack ; import import import import java.awt.Font ; java.awt.Rectangle ; java.awt.event.* ; java.text.DecimalFormat ;

import javax.swing.* ; import import import import import CommonObjects.LoginStatus ; CommonObjects.MakeTransaction ; CommonObjects.Entities.Account ; GlobalPack.ClientUtilities ; GlobalPack.TradeToken ;

public class frmUtilityTransaction extends JFrame { private LoginStatus status = null ; private JComboBox cmbToAccount = new JComboBox () ; private Account[] pubAccounts ; private JLabel jLabel2 = new JLabel () ; private JTextField txtMoney = new JTextField () ; private JLabel jLabel3 = new JLabel () ; DecimalFormat twoDigits = new DecimalFormat ("#,##0.00") ; private static frmUtilityTransaction unForm = null ; private JTextField txtCusNumber = new JTextField () ; private JLabel jLabel4 = new JLabel () ; private JButton btnTransfer = new JButton () ; private frmUtilityTransaction (LoginStatus lgSt) { status = lgSt ; if (!status.GetStatus ()) return ; try { this.setSize (400, 240) ; jbInit () ; } catch (Exception exception) { exception.printStackTrace () ; } } public static frmUtilityTransaction Instance (LoginStatus lgSt) { if (unForm == null) { unForm = new frmUtilityTransaction (lgSt) ; unForm.setLocation (70, 110) ; } return unForm ; } private void jbInit () throws Exception 107

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


{ getContentPane ().setLayout (null) ; cmbToAccount.setBounds (new Rectangle (154, 33, 184, 22)) ; jLabel2.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel2.setText ("To Utility") ; jLabel2.setBounds (new Rectangle (36, 33, 85, 22)) ; this.setResizable (false) ; this.setTitle ("Pay Utility") ; this.addComponentListener (new frmUtilityTransaction_this_componentAdapter (this)) ; txtMoney.setText (twoDigits.format (0)) ; txtMoney.setHorizontalAlignment (SwingConstants.TRAILING) ; txtMoney.setBounds (new Rectangle (154, 60, 111, 22)) ; txtMoney.addFocusListener (new frmUtilityTransaction_txtMoney_focusAdapter (this)) ; jLabel3.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel3.setText ("Amount") ; jLabel3.setBounds (new Rectangle (36, 60, 85, 22)) ; txtCusNumber.setText ("") ; txtCusNumber.setBounds (new Rectangle (154, 88, 197, 22)) ; jLabel4.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; jLabel4.setText ("Utility Cus. Number") ; jLabel4.setBounds (new Rectangle (36, 88, 113, 22)) ; btnTransfer.setBounds (new Rectangle (101, 129, 195, 36)) ; btnTransfer.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; btnTransfer.setText ("Transfer") ; btnTransfer.addActionListener (new frmUtilityTransaction_btnTransfer_actionAdapter (this)) ; this.getContentPane ().add (cmbToAccount) ; this.getContentPane ().add (txtMoney) ; this.getContentPane ().add (txtCusNumber) ; this.getContentPane ().add (jLabel4) ; this.getContentPane ().add (jLabel3) ; this.getContentPane ().add (jLabel2) ; this.getContentPane ().add (btnTransfer) ; pubAccounts = ClientUtilities.GetPubUtilAccounts (status) ; for (int i = 0 ; i < pubAccounts.length ; i++) cmbToAccount.addItem (pubAccounts[i].GetCustomerName ()) ; cmbToAccount.setSelectedIndex (0) ; } /** * Looks through the pubAccount array for an account object where the customer * name matches the given argument. * * @param cusName String * @return Account */ private Account GetAccountByName (String cusName) { for (int i = 0 ; i < pubAccounts.length ; i++) if (pubAccounts[i].GetCustomerName ().equals (cusName)) return pubAccounts[i] ; return null ; } /** * Verifies the money text field and also formats it as a decimal with two * decimal places, also using the thousands separator * 108

SOURCE CODE Stathis Polyzos

* @param focusEvent FocusEvent */ public void txtMoney_focusLost (FocusEvent focusEvent) { //Try to parse the number as a double double val = ClientUtilities.ToDouble (txtMoney.getText ()) ; //If it cannot be parsed show error message if (val == -1) { JOptionPane.showMessageDialog (null, "Not a valid amount...\n\n" + "Only positive amounts are allowed...", "Error", JOptionPane.ERROR_MESSAGE) ; txtMoney.grabFocus () ; txtMoney.selectAll () ; return ; } //Format the number and put it in the text box txtMoney.setText (twoDigits.format (val)) ; } /** * Performs the transaction. Reads account information from the server, * verifies user inputs and sends to transaction to the server to be * added to the database * * @param e ActionEvent */ public void btnTransfer_actionPerformed (ActionEvent e) { //Confirm if (JOptionPane.showConfirmDialog (null, "Confirm transaction...", "Confirmation", JOptionPane.YES_NO_OPTION) == 1) return ; String accNoTo = cmbToAccount.getSelectedItem ().toString () ; Double amt = ClientUtilities.ToDouble (txtMoney.getText ()) ; //Check customers's PUC number if (txtCusNumber.getText ().length () == 0) { JOptionPane.showMessageDialog (null, "Please enter customer's PUC number " + "for the selected\npublic utility company...\n", "Error", JOptionPane.ERROR_MESSAGE) ; return ; } //Check amount if (amt <= 0) { JOptionPane.showMessageDialog (null, "Please enter a valid amount...", "Error", JOptionPane.ERROR_MESSAGE) ; return ; } //Send information to server and get reply TradeToken rec = ClientUtilities.DispatchToken (new TradeToken (new MakeTransaction (status, GetAccountByName (accNoTo), (byte) 1, amt, "Customer Number: " + txtCusNumber.getText ()), 8), status, "", 0) ; //Check completion of transaction and inform user if (rec.getType () != 1) 109

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


{ JOptionPane.showMessageDialog (null, "Transaction was not added...\n\n" + "Please contact the DORbank support line...\n\n", "Error", JOptionPane.ERROR_MESSAGE) ; return ; } JOptionPane.showMessageDialog (null, "Your payment was successful...", "Information", JOptionPane.INFORMATION_MESSAGE) ; this.setVisible (false) ; } public void this_componentHidden (ComponentEvent e) { unForm = null ; } } class frmUtilityTransaction_btnTransfer_actionAdapter implements ActionListener { private frmUtilityTransaction adaptee ; frmUtilityTransaction_btnTransfer_actionAdapter (frmUtilityTransaction adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnTransfer_actionPerformed (e) ; } } class frmUtilityTransaction_this_componentAdapter extends ComponentAdapter { private frmUtilityTransaction adaptee ; frmUtilityTransaction_this_componentAdapter (frmUtilityTransaction adaptee) { this.adaptee = adaptee ; } public void componentHidden (ComponentEvent e) { adaptee.this_componentHidden (e) ; } } class frmUtilityTransaction_txtMoney_focusAdapter extends FocusAdapter { private frmUtilityTransaction adaptee ; frmUtilityTransaction_txtMoney_focusAdapter (frmUtilityTransaction adaptee) { this.adaptee = adaptee ; } public void focusLost (FocusEvent focusEvent) { 110

SOURCE CODE Stathis Polyzos

adaptee.txtMoney_focusLost (focusEvent) ; } }

111

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


F.1.18. MainCusMenu.java package ClientPack ; import java.awt.* ; import java.awt.event.ActionEvent ; import java.awt.event.ActionListener ; import javax.swing.JButton ; import javax.swing.JFrame ; import import import import import import import import import CommonObjects.LoginStatus ; GlobalPack.ClientUtilities; java.awt.Rectangle ; java.awt.Font ; javax.swing.JLabel ; javax.swing.* ; java.awt.Dimension ; java.awt.event.ComponentEvent ; java.awt.event.ComponentAdapter ;

public class MainCusMenu extends JFrame { private LoginStatus status = null ; private static MainCusMenu unForm = null ; private JButton btnCustomers = new JButton () ; private JButton btnSuspend = new JButton () ; private JButton btnActivate = new JButton () ; private JButton btnChangePIN = new JButton () ; private MainCusMenu (LoginStatus lgSt) { status = lgSt ; if (!status.GetStatus ()) return ; try { jbInit () ; } catch (Exception exception) { exception.printStackTrace () ; } } public static MainCusMenu Instance (LoginStatus lgSt) { if (unForm == null) { unForm = new MainCusMenu (lgSt) ; unForm.setLocation (70, 80) ; } return unForm ; }

private void jbInit () throws Exception { 112

SOURCE CODE Stathis Polyzos

this.setSize (215, 250) ; this.setLocation (40, 40) ; getContentPane ().setLayout (null) ; this.setDefaultCloseOperation (JFrame.HIDE_ON_CLOSE) ; this.setResizable (false) ; this.setTitle ("SuperTrans Client :: Customers") ; this.addComponentListener (new MainCusMenu_this_componentAdapter (this)) ; btnCustomers.setBounds (new Rectangle (32, 29, 149, 35)) ; btnCustomers.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; btnCustomers.setText ("Customers") ; btnCustomers.addActionListener (new MainCusMenu_btnCustomers_actionAdapter (this)) ; btnSuspend.setBounds (new Rectangle (32, 116, 149, 35)) ; btnSuspend.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; btnSuspend.setToolTipText ("") ; btnSuspend.setText ("Suspend Card/User") ; btnSuspend.addActionListener (new MainCusMenu_btnSuspend_actionAdapter (this)) ; btnActivate.setBounds (new Rectangle (32, 72, 149, 35)) ; btnActivate.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; btnActivate.setToolTipText ("") ; btnActivate.setText ("Activate Card/User") ; btnActivate.addActionListener (new MainCusMenu_btnActivate_actionAdapter (this)) ; btnChangePIN.setBounds (new Rectangle (32, 159, 149, 35)) ; btnChangePIN.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; btnChangePIN.setToolTipText ("") ; btnChangePIN.setText ("Change Card PIN") ; btnChangePIN.addActionListener (new MainCusMenu_btnChangePIN_actionAdapter (this)) ; this.getContentPane ().add (btnCustomers) ; this.getContentPane ().add (btnActivate) ; this.getContentPane ().add (btnSuspend) ; this.getContentPane ().add (btnChangePIN) ; } public void this_componentHidden (ComponentEvent e) { unForm = null; } public void btnActivate_actionPerformed (ActionEvent e) { frmActivateSuspend frmact = frmActivateSuspend.Instance(status, true); frmact.setVisible(true); } public void btnSuspend_actionPerformed (ActionEvent e) { frmActivateSuspend frmact = frmActivateSuspend.Instance(status, false); frmact.setVisible(true); } public void btnChangePIN_actionPerformed (ActionEvent e) { frmChangePin chPin = frmChangePin.Instance(status); chPin.setVisible(true); } public void btnCustomers_actionPerformed (ActionEvent e) { 113

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


frmCustomers frC = frmCustomers.Instance(status); frC.setVisible(true); } } class MainCusMenu_btnCustomers_actionAdapter implements ActionListener { private MainCusMenu adaptee ; MainCusMenu_btnCustomers_actionAdapter (MainCusMenu adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnCustomers_actionPerformed (e) ; } } class MainCusMenu_btnChangePIN_actionAdapter implements ActionListener { private MainCusMenu adaptee ; MainCusMenu_btnChangePIN_actionAdapter (MainCusMenu adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnChangePIN_actionPerformed (e) ; } } class MainCusMenu_btnSuspend_actionAdapter implements ActionListener { private MainCusMenu adaptee ; MainCusMenu_btnSuspend_actionAdapter (MainCusMenu adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnSuspend_actionPerformed (e) ; } } class MainCusMenu_btnActivate_actionAdapter implements ActionListener { private MainCusMenu adaptee ; MainCusMenu_btnActivate_actionAdapter (MainCusMenu adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { 114

SOURCE CODE Stathis Polyzos

adaptee.btnActivate_actionPerformed (e) ; } } class MainCusMenu_this_componentAdapter extends ComponentAdapter { private MainCusMenu adaptee ; MainCusMenu_this_componentAdapter (MainCusMenu adaptee) { this.adaptee = adaptee ; } public void componentHidden (ComponentEvent e) { adaptee.this_componentHidden (e) ; } }

115

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


F.1.19. MainMenu.java package ClientPack ; import java.awt.* ; import java.awt.event.ActionEvent ; import java.awt.event.ActionListener ; import javax.swing.JButton ; import javax.swing.JFrame ; import import import import import import CommonObjects.LoginStatus ; GlobalPack.ClientUtilities ; java.awt.Rectangle ; java.awt.Font ; javax.swing.JLabel ; javax.swing.* ;

public class MainMenu extends JFrame { private LoginStatus status = null ; private JButton btnTransfer = new JButton () ; private JButton btnPayUtil = new JButton () ; private JButton btnAccStatus = new JButton () ; private JLabel jLabel1 = new JLabel () ; private JButton btnPayCreditCard = new JButton () ; private JButton btnViewTrans = new JButton () ; private JButton btnChngPin = new JButton () ; public MainMenu (LoginStatus lgSt) { status = lgSt ; if (!status.GetStatus ()) return ; try { jbInit () ; } catch (Exception exception) { exception.printStackTrace () ; } } private void jbInit () throws Exception { this.setSize (245, 350) ; this.setLocation (20, 20) ; getContentPane ().setLayout (null) ; btnTransfer.setBounds (new Rectangle (40, 133, 163, 35)) ; btnTransfer.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; btnTransfer.setText ("Transfer Money") ; btnTransfer.addActionListener (new MainMenu_btnTransfer_actionAdapter (this)) ; this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE) ; this.setResizable (false) ; this.setTitle ("SuperTrans Client :: Main") ; btnPayUtil.setBounds (new Rectangle (40, 175, 163, 35)) ; btnPayUtil.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; btnPayUtil.setActionCommand ("Pay Utility") ; 116

SOURCE CODE Stathis Polyzos

btnPayUtil.setText ("Pay Utility") ; btnPayUtil.addActionListener (new MainMenu_btnPayUtil_actionAdapter (this)) ; btnAccStatus.setBounds (new Rectangle (40, 48, 163, 35)) ; btnAccStatus.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; btnAccStatus.setText ("Account Status") ; btnAccStatus.addActionListener (new MainMenu_btnAccStatus_actionAdapter (this)) ; jLabel1.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 12)) ; jLabel1.setHorizontalAlignment (SwingConstants.CENTER) ; jLabel1.setText (ClientUtilities.GetCustomerName (status)) ; jLabel1.setBounds (new Rectangle (17, 14, 208, 20)) ; btnPayCreditCard.setBounds (new Rectangle (40, 218, 163, 35)) ; btnPayCreditCard.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; btnPayCreditCard.setText ("Pay Credit Card Bill") ; btnPayCreditCard.addActionListener (new MainMenu_btnPayCreditCard_actionAdapter (this)) ; btnViewTrans.setBounds (new Rectangle (40, 89, 163, 35)) ; btnViewTrans.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; btnViewTrans.setHorizontalTextPosition (SwingConstants.CENTER) ; btnViewTrans.setText ("Account Transactions") ; btnViewTrans.addActionListener (new MainMenu_btnViewTrans_actionAdapter (this)) ; btnChngPin.setBounds (new Rectangle (40, 261, 163, 35)) ; btnChngPin.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; btnChngPin.setText ("Change PIN") ; btnChngPin.addActionListener (new MainMenu_btnChngPin_actionAdapter (this)) ; this.getContentPane ().add (jLabel1) ; this.getContentPane ().add (btnAccStatus) ; this.getContentPane ().add (btnTransfer, null) ; this.getContentPane ().add (btnChngPin) ; this.getContentPane ().add (btnPayUtil) ; this.getContentPane ().add (btnPayCreditCard) ; this.getContentPane ().add (btnViewTrans) ; } public void btnTransfer_actionPerformed (ActionEvent e) { frmTransfer transf = frmTransfer.Instance (status) ; transf.setVisible (true) ; } public void btnPayUtil_actionPerformed (ActionEvent e) { frmPayUtility util = frmPayUtility.Instance (status) ; util.setVisible (true) ; } public void btnAccStatus_actionPerformed (ActionEvent e) { frmAccountStatus accStat = frmAccountStatus.Instance (status) ; accStat.setVisible (true) ; } public void btnPayCreditCard_actionPerformed (ActionEvent e) { frmTransferCreditCard payCC = frmTransferCreditCard.Instance (status) ; payCC.setVisible (true) ; } public void btnViewTrans_actionPerformed (ActionEvent e) { 117

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


frmListTransactions list = frmListTransactions.Instance (status) ; list.setVisible (true) ; } public void btnChngPin_actionPerformed (ActionEvent e) { frmChangePin chp = frmChangePin.Instance (status) ; chp.setVisible (true) ; } } class MainMenu_btnChngPin_actionAdapter implements ActionListener { private MainMenu adaptee ; MainMenu_btnChngPin_actionAdapter (MainMenu adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnChngPin_actionPerformed (e) ; } } class MainMenu_btnViewTrans_actionAdapter implements ActionListener { private MainMenu adaptee ; MainMenu_btnViewTrans_actionAdapter (MainMenu adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnViewTrans_actionPerformed (e) ; } } class MainMenu_btnPayCreditCard_actionAdapter implements ActionListener { private MainMenu adaptee ; MainMenu_btnPayCreditCard_actionAdapter (MainMenu adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnPayCreditCard_actionPerformed (e) ; } } class MainMenu_btnAccStatus_actionAdapter implements ActionListener { private MainMenu adaptee ; MainMenu_btnAccStatus_actionAdapter (MainMenu adaptee) 118

SOURCE CODE Stathis Polyzos

{ this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnAccStatus_actionPerformed (e) ; } } class MainMenu_btnPayUtil_actionAdapter implements ActionListener { private MainMenu adaptee ; MainMenu_btnPayUtil_actionAdapter (MainMenu adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnPayUtil_actionPerformed (e) ; } } class MainMenu_btnTransfer_actionAdapter implements ActionListener { private MainMenu adaptee ; MainMenu_btnTransfer_actionAdapter (MainMenu adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent actionEvent) { adaptee.btnTransfer_actionPerformed (actionEvent) ; } }

119

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


F.1.20. MainMenuInt.java package ClientPack ; import import import import java.awt.Font ; java.awt.Rectangle ; java.awt.event.ActionEvent ; java.awt.event.ActionListener ;

import javax.swing.* ; import CommonObjects.LoginStatus ; import GlobalPack.ClientUtilities ; public class MainMenuInt extends JFrame { private LoginStatus status = null ; private boolean supervisor = false ; private JLabel jLabel1 = new JLabel () ; private JButton btnDeposit = new JButton () ; private JButton btnWithdraw = new JButton () ; private JButton btnCC = new JButton () ; private JButton btnUtility = new JButton () ; private JButton btnEmployes = new JButton () ; private JButton btnCusMenu = new JButton () ; public MainMenuInt (LoginStatus lgSt, boolean superV) { status = lgSt ; supervisor = superV ; if (!status.GetStatus ()) return ; try { jbInit () ; } catch (Exception exception) { exception.printStackTrace () ; } } private void jbInit () throws Exception { this.setSize (245, 367) ; this.setLocation (20, 20) ; getContentPane ().setLayout (null) ; this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE) ; this.setResizable (false) ; this.setTitle ("SuperTrans Client :: Main") ; jLabel1.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 12)) ; jLabel1.setHorizontalAlignment (SwingConstants.CENTER) ; jLabel1.setText (ClientUtilities.GetCustomerName (status)) ; jLabel1.setBounds (new Rectangle (22, 13, 203, 24)) ; btnDeposit.setBounds (new Rectangle (42, 47, 163, 35)) ; btnDeposit.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; btnDeposit.setText ("Deposit") ; btnDeposit.addActionListener (new MainMenuInt_btnDeposit_actionAdapter (this)) 120

SOURCE CODE Stathis Polyzos

; btnWithdraw.setBounds (new Rectangle (42, 93, 163, 35)) ; btnWithdraw.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; btnWithdraw.setText ("Withdrawal") ; btnWithdraw.addActionListener (new MainMenuInt_btnWithdraw_actionAdapter (this)) ; btnCC.setBounds (new Rectangle (42, 138, 163, 35)) ; btnCC.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; btnCC.setText ("Pay Credit Card") ; btnCC.addActionListener (new MainMenuInt_btnCC_actionAdapter (this)) ; btnUtility.setBounds (new Rectangle (42, 184, 163, 35)) ; btnUtility.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; btnUtility.setText ("Pay Utility") ; btnUtility.addActionListener (new MainMenuInt_btnUtility_actionAdapter (this)) ; btnEmployes.setBounds (new Rectangle (42, 229, 163, 35)) ; btnEmployes.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; btnEmployes.setText ("Employees") ; btnEmployes.addActionListener (new MainMenuInt_btnEmployes_actionAdapter (this)) ; btnEmployes.setEnabled (supervisor) ; btnCusMenu.setBounds (new Rectangle (42, 275, 163, 35)) ; btnCusMenu.setFont (new java.awt.Font ("Tahoma", Font.BOLD, 11)) ; btnCusMenu.setText ("Customer Menu") ; btnCusMenu.addActionListener (new MainMenuInt_btnCusMenu_actionAdapter (this)) ; this.getContentPane ().add (jLabel1) ; this.getContentPane ().add (btnDeposit) ; this.getContentPane ().add (btnWithdraw) ; this.getContentPane ().add (btnCC) ; this.getContentPane ().add (btnUtility) ; this.getContentPane ().add (btnEmployes) ; this.getContentPane ().add (btnCusMenu) ; } public void btnDeposit_actionPerformed (ActionEvent e) { frmTransaction transact = frmTransaction.Instance (status, 2) ; transact.setVisible (true) ; } public void btnWithdraw_actionPerformed (ActionEvent e) { frmTransaction transact = frmTransaction.Instance (status, 1) ; transact.setVisible (true) ; } public void btnCC_actionPerformed (ActionEvent e) { frmPayCreditCard crPay = frmPayCreditCard.Instance (status) ; crPay.setVisible (true) ; } public void btnUtility_actionPerformed (ActionEvent e) { frmUtilityTransaction util = frmUtilityTransaction.Instance (status) ; util.setVisible (true) ; } public void btnCusMenu_actionPerformed (ActionEvent e) { 121

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


MainCusMenu mm = MainCusMenu.Instance (status) ; mm.setVisible (true) ; } public void btnEmployes_actionPerformed (ActionEvent e) { frmEmployees frmEm = frmEmployees.Instance (status) ; frmEm.setVisible (true) ; } } class MainMenuInt_btnEmployes_actionAdapter implements ActionListener { private MainMenuInt adaptee ; MainMenuInt_btnEmployes_actionAdapter (MainMenuInt adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnEmployes_actionPerformed (e) ; } } class MainMenuInt_btnCusMenu_actionAdapter implements ActionListener { private MainMenuInt adaptee ; MainMenuInt_btnCusMenu_actionAdapter (MainMenuInt adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnCusMenu_actionPerformed (e) ; } } class MainMenuInt_btnUtility_actionAdapter implements ActionListener { private MainMenuInt adaptee ; MainMenuInt_btnUtility_actionAdapter (MainMenuInt adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnUtility_actionPerformed (e) ; } } class MainMenuInt_btnCC_actionAdapter implements ActionListener { private MainMenuInt adaptee ; MainMenuInt_btnCC_actionAdapter (MainMenuInt adaptee) 122

SOURCE CODE Stathis Polyzos

{ this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnCC_actionPerformed (e) ; } } class MainMenuInt_btnWithdraw_actionAdapter implements ActionListener { private MainMenuInt adaptee ; MainMenuInt_btnWithdraw_actionAdapter (MainMenuInt adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnWithdraw_actionPerformed (e) ; } } class MainMenuInt_btnDeposit_actionAdapter implements ActionListener { private MainMenuInt adaptee ; MainMenuInt_btnDeposit_actionAdapter (MainMenuInt adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnDeposit_actionPerformed (e) ; } }

123

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


F.2. Common Objects

F.2.1. AddAccount.java package CommonObjects ; import java.io.Serializable; import CommonObjects.Entities.Account; public class AddAccount implements Serializable { LoginStatus status; Account acc; public AddAccount (LoginStatus lgSt, Account cpAcc) { status = lgSt; acc = cpAcc; } public Account GetAccount() {return acc;} public boolean GetStatus () {return status.GetStatus();} }

124

SOURCE CODE Stathis Polyzos F.2.2. AddCreditCard.java

package CommonObjects ; import java.io.Serializable; import CommonObjects.Entities.CreditCard; public class AddCreditCard implements Serializable { LoginStatus status; CreditCard cc; public AddCreditCard (LoginStatus lgSt, CreditCard cpCC) { status = lgSt; cc = cpCC; } public CreditCard GetCreditCard() {return cc;} public boolean GetStatus () {return status.GetStatus();} }

125

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


F.2.3. AddUser.java package CommonObjects ; import java.io.Serializable; import CommonObjects.Entities.User; public class AddUser implements Serializable { LoginStatus status; User usr; public AddUser (LoginStatus lgSt, User cpUsr) { status = lgSt; usr = cpUsr; } public User GetUser() {return usr;} public boolean GetStatus () {return status.GetStatus();} }

126

SOURCE CODE Stathis Polyzos F.2.4. ChangeActivationStatus.java

package CommonObjects ; import java.io.Serializable; public class ChangeActivationStatus implements Serializable { LoginStatus status; String unique; boolean activate; boolean card; public ChangeActivationStatus (LoginStatus lgSt, String un, boolean activ, boolean crd) { status = lgSt; unique = un; activate = activ; card = crd; } public public public public } String GetUnique() { return unique; } boolean Activate() { return activate; } boolean Card() { return card; } boolean GetStatus() { return status.GetStatus();}

127

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


F.2.5. CreditCardPayment.java package CommonObjects ; import java.io.Serializable; import CommonObjects.Entities.CreditCardTransaction; public class CreditCardPayment implements Serializable { LoginStatus status; CreditCardTransaction crTrans; String ccNo; public CreditCardPayment (LoginStatus lgSt, String creditCardNo, Double amt) { ccNo = creditCardNo; status = lgSt; crTrans = new CreditCardTransaction(0, 0, (byte) 1, amt); } public String GetCreditCardNo() {return ccNo;} public CreditCardTransaction GetCrTransaction() {return crTrans;} public boolean GetStatus(){return status.GetStatus();} }

128

SOURCE CODE Stathis Polyzos F.2.6. CustomerData.java

package CommonObjects ; import java.io.Serializable; import CommonObjects.Entities.Customer; public class CustomerData implements Serializable { LoginStatus status; int actionType; Customer cus; public CustomerData (Customer cpCus, int cpAct, LoginStatus lgSt) { cus = cpCus; actionType = cpAct; status = lgSt; } public Customer GetCustomer() {return cus;} public int GetActionType() {return actionType;} public boolean GetStatus() {return status.GetStatus();} }

129

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


F.2.7. EmployeeData.java package CommonObjects ; import java.io.Serializable; import CommonObjects.Entities.Employee; public class EmployeeData implements Serializable { LoginStatus status; int actionType; Employee empl; public EmployeeData (Employee cpEmpl, int cpAct, LoginStatus lgSt) { empl = cpEmpl; actionType = cpAct; status = lgSt; } public Employee GetEmployee() {return empl;} public int GetActionType() {return actionType;} public boolean GetStatus() {return status.GetStatus();} }

130

SOURCE CODE Stathis Polyzos F.2.8. GetAccount.java

package CommonObjects ; import java.io.Serializable; public class GetAccount implements Serializable { String accountNo; LoginStatus status; public GetAccount (String acc, LoginStatus lgSt) { accountNo = acc; status = lgSt; } public String GetAccountNo() {return accountNo;} public boolean GetStatus (){return status.GetStatus();} }

131

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


F.2.9. LoginStatus.java package CommonObjects; import java.io.Serializable; public class LoginStatus implements Serializable { boolean status ; String host; int port, userID; public LoginStatus (String cpHost, int cpPort) { host = cpHost ; port = cpPort ; status = false ; } public void TrueLogin(int checkme, int usrID) { if (checkme == 270278) { status = true ; userID = usrID; } } public boolean GetStatus() { return status; } public String GetHost() { return host; } public int GetPort() { return port; } public int GetUser() { return userID; } }

132

SOURCE CODE Stathis Polyzos F.2.10. LoginUser.java

package CommonObjects; import java.io.Serializable; public class LoginUser implements Serializable { String username, pass, host; int port; public LoginUser(String usr, String pwd, String hst, int prt) { username = usr; pass = pwd; host = hst; port = prt; } public String Username() { return username; } public String Password() { return pass; } public String Host () { return host ; } public int Port () { return port ; } }

133

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


F.2.11. MakeTransaction.java package CommonObjects ; import java.io.Serializable; import CommonObjects.Entities.*; public class MakeTransaction implements Serializable { LoginStatus status; Transaction trans; public MakeTransaction ( LoginStatus lgSt, Account cpAcc, int cpType, double cpAmt, String cpComments) { status = lgSt; trans = new Transaction (0, "", cpAcc.GetID (), (byte) cpType, cpAmt, cpComments) ; } public Transaction GetTransaction() {return trans;} public boolean GetStatus() {return status.GetStatus();} }

134

SOURCE CODE Stathis Polyzos F.2.12. MakeTransfer.java

package CommonObjects ; import java.io.Serializable; import CommonObjects.Entities.Transaction; import CommonObjects.Entities.Account; public class MakeTransfer implements Serializable { LoginStatus status; Transaction transOut; Transaction transIn; public MakeTransfer ( LoginStatus lgSt, Account accFrom, Account accTo, double amount, String cusNo) { status = lgSt ; transOut = new Transaction(); transIn = new Transaction(); transOut.SetAccount (accFrom.GetID ()) ; transIn.SetAccount (accTo.GetID ()) ; transOut.SetType ((byte) 2) ; transIn.SetType ((byte) 1) ; transOut.SetAmount (amount) ; transIn.SetAmount (amount) ; if (!cusNo.equals("")) { transOut.SetComments(accTo.GetCustomerName() + " (Payment)"); transIn.SetComments("Customer Number: " + cusNo); } } public Transaction GetTransOut() {return transOut;} public Transaction GetTransIn() {return transIn;} public boolean GetStatus() {return status.GetStatus();} }

135

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


F.2.13. MakeTransferToCredit.java package CommonObjects ; import java.io.Serializable; import CommonObjects.Entities.*; public class MakeTransferToCredit implements Serializable { LoginStatus status; Transaction transOut; CreditCardTransaction transIn; public MakeTransferToCredit ( LoginStatus lgSt, Account accFrom, CreditCard ccTo, double amount) { status = lgSt ; transOut = new Transaction(); transOut.SetAccount (accFrom.GetID ()) ; transOut.SetType ((byte) 2) ; transOut.SetAmount (amount) ; transOut.SetComments("Credit Card Payment: " + ccTo.GetCreditCardNumberFormatted()); transIn = new CreditCardTransaction(); transIn.SetCreditCard(ccTo.GetID()); transIn.SetType ((byte) 1) ; transIn.SetAmount (amount) ; } public Transaction GetTransOut() {return transOut;} public CreditCardTransaction GetCreditIn() {return transIn;} public boolean GetStatus() {return status.GetStatus();} }

136

SOURCE CODE Stathis Polyzos F.2.14. RequestCustomer.java

package CommonObjects ; import java.io.Serializable; public class RequestCustomer implements Serializable { LoginStatus status; int cusID; public RequestCustomer (LoginStatus lgSt, int ID) { status = lgSt; cusID = ID; } public int GetID() {return cusID;} public boolean GetStatus() {return status.GetStatus();} }

137

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


F.2.15. RequestEmployee.java package CommonObjects ; import java.io.Serializable; public class RequestEmployee implements Serializable { LoginStatus status; int emplID; public RequestEmployee (LoginStatus lgSt, int ID) { status = lgSt; emplID = ID; } public int GetID() {return emplID;} public boolean GetStatus() {return status.GetStatus();} }

138

SOURCE CODE Stathis Polyzos F.2.16. RequestPinChange.java

package CommonObjects ; import java.io.Serializable; public class RequestPinChange implements Serializable { LoginStatus status; String cardNo, oldPin, newPin; public RequestPinChange ( LoginStatus lgSt, String crNo, String oldp, String newp ) { status = lgSt; cardNo = crNo; oldPin = oldp; newPin = newp; } public public public public } String GetCardNo() {return cardNo;} String GetOldPin() {return oldPin;} String GetNewPin() {return newPin;} boolean GetStatus() {return status.GetStatus();}

139

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


F.2.17. RequestTransactions.java package CommonObjects ; import CommonObjects.Entities.Account; import java.io.Serializable; public class RequestTransactions implements Serializable { LoginStatus status; Account account; String dateFrom, dateTo; public RequestTransactions ( LoginStatus lgSt, Account acc, String dtFrom, String dtTo) { status = lgSt; account = acc; dateFrom = dtFrom; dateTo = dtTo; } public boolean GetStatus () { return status.GetStatus () ; } public String GetFromDate () { return dateFrom + " 00:00:00" ; } public String GetToDate () { return dateTo + " 23:59:59" ; } public int GetAccount() { return account.GetID(); } public int GetCustomer() { return account.GetCustomer(); } public int GetUser() { return status.GetUser(); } }

140

SOURCE CODE Stathis Polyzos F.2.18. UserID.java

package CommonObjects ; import java.io.Serializable; public class UserID implements Serializable { int userID, actionType; LoginStatus status; public UserID () { userID = 0; actionType = 0; status = null; } public UserID(int usr, int actTp, LoginStatus lgSt) { userID = usr; actionType = actTp; status = lgSt; } public boolean GetStatus() {return status.GetStatus();} public int GetUserID () {return userID;} public int GetActionType() {return actionType;} }

141

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


F.3. Common Objects.Entities

F.3.1. Account.java package CommonObjects.Entities ; import java.sql.*; public class Account extends DatabaseObject { private String accountNumber; private int customer; private double balance; private String customerName; public Account () { ID = 0; accountNumber = ""; customer = 0; balance = 0; customerName = ""; } public Account ( int cpAccountID, String cpAccountNumber, int cpCustomer, double cpBalance ) { ID = cpAccountID; accountNumber = cpAccountNumber; customer = cpCustomer; balance = cpBalance; customerName = ""; } public Account ( int cpAccountID, String cpAccountNumber, int cpCustomer, double cpBalance, String cpCustomerName ) { ID = cpAccountID ; accountNumber = cpAccountNumber ; customer = cpCustomer ; balance = cpBalance ; customerName = cpCustomerName ; } public boolean AddToDB(Connection dbCon) { if (ID != 0) return false; int added = 0; 142

SOURCE CODE Stathis Polyzos

try { Statement stmt = dbCon.createStatement () ; added = stmt.executeUpdate ("INSERT INTO tbl_Accounts " + "(AccountNumber, Customer) " + "VALUES ('" + accountNumber + "', " + customer + ")") ; ResultSet rs = stmt.executeQuery ("SELECT AccountID FROM " + "tbl_Accounts WHERE AccountNumber = '" + accountNumber + "'") ; if (rs.next()) ID = Integer.parseInt (rs.getString (1)) ; return (added == 1) ; } catch (Exception e) { return false ; } } public boolean SaveToDB(Connection dbCon) { //Is not implemented return false; } public String GetAccountNumber() {return accountNumber;} public void SetAccountNumber(String num) {accountNumber = num;} public int GetCustomer() {return customer;} public void SetCustomer(int cus) {customer = cus;} public double GetBalance() {return balance;} public void SetBalance(double bal) {balance = bal;} public String GetCustomerName() {return customerName;} public void SetCustomerName(String cnm) {customerName }

= cnm;}

143

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


F.3.2. Address.java package CommonObjects.Entities ; import java.io.Serializable; public class Address implements Serializable { private String addressLine, phoneNo, city, zipCode; public Address () { addressLine = "" ; phoneNo = "" ; city = "" ; zipCode = "" ; } public String GetAddressLine () {return addressLine;} public void SetAddressLine(String addr) {addressLine = addr;} public String GetPhoneNo () {return phoneNo;} public void SetPhoneNo(String ph) {phoneNo = ph;} public String GetCity () {return city;} public void SetCity(String cit) {city = cit;} public String GetZipCode () {return zipCode;} public void SetZipCode(String zip) {zipCode = zip;} }

144

SOURCE CODE Stathis Polyzos F.3.3. CreditCard.java

package CommonObjects.Entities ; import java.sql.* ; public class CreditCard extends DatabaseObject { private int customer ; private String creditCardNumber ; private String PIN ; private double creditLimit ; public CreditCard () { ID = 0 ; customer = 0 ; creditCardNumber = "" ; PIN = "" ; creditLimit = 0 ; } public CreditCard ( int cpCrCardID, int cpCustomer, String cpCrCardNumber, String cpPIN, double cpCreditLimit ) { ID = cpCrCardID ; customer = cpCustomer ; creditCardNumber = cpCrCardNumber ; PIN = cpPIN ; creditLimit = cpCreditLimit ; } public CreditCard (Connection dbCon, String number) { creditCardNumber = number ; try { Statement stmt = dbCon.createStatement () ; ResultSet rs = stmt.executeQuery ("SELECT * FROM tbl_CreditCards " + "WHERE CreditCardNo = '" + creditCardNumber + "'") ; rs.next () ; ID = Integer.parseInt (rs.getString (1)) ; customer = Integer.parseInt (rs.getString (2)) ; PIN = rs.getString (4) ; creditLimit = Double.parseDouble (rs.getString (5)) ; rs.close () ; stmt.close () ; } catch (Exception exp) { System.out.println (exp.getMessage ()) ; } } 145

SUPERTRANS CUSTOMER TRANSACTION SYSTEM

public boolean AddToDB (Connection dbCon) { if (ID != 0) return false ; int added = 0 ; try { Statement stmt = dbCon.createStatement () ; added = stmt.executeUpdate ("INSERT INTO tbl_CreditCards " + "(Customer, CreditCardNo, PIN, CreditLimit) " + "VALUES (" + customer + ", '" + creditCardNumber + "', '" + PIN + "', " + creditLimit + ")") ; ResultSet rs = stmt.executeQuery ("SELECT CreditCardID FROM " + "tbl_CreditCards WHERE CreditCardNo = '" + creditCardNumber + "'") ; if (rs.next ()) ID = Integer.parseInt (rs.getString (1)) ; return (added == 1) ; } catch (Exception e) { return false ; } } public boolean SaveToDB(Connection dbCon) { //Is not implemented return false; } public boolean ChangePIN (Connection dbCon, String oldPin, String newPin) { if (!oldPin.equals (PIN) || ID == 0 || newPin.length () != 4 || newPin.equals (oldPin)) return false ; int updated = 0 ; try { Statement stmt = dbCon.createStatement () ; updated = stmt.executeUpdate ("UPDATE tbl_CreditCards " + "SET PIN = '" + newPin + "' WHERE CreditCardID = " + ID) ; PIN = newPin ; return (updated == 1) ; } catch (Exception e) { System.out.println (e.getMessage ()) ; return false ; } } public boolean Deactivate (Connection dbCon) { if (ID == 0) return false ; 146

SOURCE CODE Stathis Polyzos

int updated = 0 ; try { Statement stmt = dbCon.createStatement () ; updated = stmt.executeUpdate ("UPDATE tbl_CreditCards " + "SET Active = 0 WHERE CreditCardID = " + ID) ; return (updated == 1) ; } catch (Exception e) { return false ; } } public boolean Activate (Connection dbCon) { if (ID == 0) return false ; int updated = 0 ; try { Statement stmt = dbCon.createStatement () ; updated = stmt.executeUpdate ("UPDATE tbl_CreditCards " + "SET Active = 1 WHERE CreditCardID = " + ID) ; return (updated == 1) ; } catch (Exception e) { return false ; } } public int GetCustomer () { return customer ;} public void SetCustomer (int cus){ customer = cus ;} public String GetCreditCardNumber () { return creditCardNumber ; } public void SetCreditCardNumber (String num) { if (num.length () == 16) creditCardNumber = num ; } public String GetCreditCardNumberFormatted () { String retString = "" ; for (int i = 0 ; i < creditCardNumber.length () ; i++) { retString += creditCardNumber.substring (i, i + 1) ; if ((i + 1) % 4 == 0) retString += " " ; } return retString ; } public String GetPIN () { return PIN ; } public void SetPIN (String pin) { 147

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


if (pin.length () == 4) PIN = pin ; } public double GetLimit () { return creditLimit ; } public void SetLimit (double bal) { creditLimit = bal ; } }

148

SOURCE CODE Stathis Polyzos F.3.4. CreditCardTransaction.java

package CommonObjects.Entities ; import java.sql.*; public class CreditCardTransaction extends GenTransaction { private int creditCard; public CreditCardTransaction () { ID = 0 ; creditCard = 0 ; type = 0 ; amount = 0 ; comments = "" ; } public CreditCardTransaction ( int cpTransID, int cpAccount, byte cpType, double cpAmount ) { ID = cpTransID; creditCard = cpAccount; type = cpType; amount = cpAmount; comments = "" ; } public CreditCardTransaction (CreditCardTransaction cpTrans) { ID = cpTrans.GetID() ; creditCard = cpTrans.GetCreditCard () ; type = cpTrans.GetType () ; amount = cpTrans.GetAmount () ; comments = cpTrans.GetComments () ; } public boolean AddToDB(Connection dbCon) { if (ID != 0) return false ; int added = 0 ; try { Statement stmt = dbCon.createStatement () ; added = stmt.executeUpdate ("INSERT INTO tbl_CreditCardTransactions " + "(CreditCard, Type, Amount, Comments) " + "VALUES (" + creditCard + ", " + type + ", " + amount + ", '" + comments + "' )") ; ResultSet rs = stmt.executeQuery("SELECT TOP 1 CCTrID FROM " + "tbl_CreditCardTransactions ORDER BY CCTrID DESC"); if (rs.next ()) ID = Integer.parseInt (rs.getString (1)) ; 149

SUPERTRANS CUSTOMER TRANSACTION SYSTEM

return (added == 1) ; } catch (Exception e) { System.out.println( e.getMessage()); return false ; } } public boolean SaveToDB (Connection dbCon) { //Is not implemented return false ; } public int GetCreditCard() { return creditCard;} public void SetCreditCard(int cc) {creditCard = cc;} }

150

SOURCE CODE Stathis Polyzos F.3.5. Customer.java

package CommonObjects.Entities ; import java.sql.*; public class Customer extends Person { private boolean pubUtil ; public Customer () { ID = 0 ; fullName = "" ; address = new Address(); pubUtil = false ; } public Customer (Connection dbCon, int id) { ID = id ; address = new Address(); try { Statement stmt = dbCon.createStatement () ; ResultSet rs = stmt.executeQuery ("SELECT * FROM tbl_Customers " + "WHERE CusID = " + ID) ; rs.next(); fullName = rs.getString (2) ; address.SetAddressLine (rs.getString (3)) ; address.SetCity (rs.getString (4)) ; address.SetZipCode (rs.getString (5)) ; address.SetPhoneNo (rs.getString (6)) ; pubUtil = (rs.getString (7).equals ("1") ? true : false) ; rs.close () ; stmt.close () ; } catch (Exception exp) { System.out.println (exp.getMessage ()) ; } } public boolean AddToDB (Connection dbCon) { if (ID != 0) return false ; try { int added = 0 ; Statement stmt = dbCon.createStatement () ; added = stmt.executeUpdate ("INSERT INTO tbl_Customers " + "(CustomerName, Address, City, ZipCode, PhoneNo, IsPubUtilComp) " + "VALUES ('" + fullName + "', '" + address.GetAddressLine () + "', '" + address.GetCity () + "', '" + address.GetZipCode () + "', '" + address.GetPhoneNo () + "', " + (pubUtil ? "1" : "0") + " )") ; 151

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


ResultSet rs = stmt.executeQuery ("SELECT TOP 1 CusID FROM " + "tbl_Customers ORDER BY CusID DESC") ; if (rs.next ()) ID = Integer.parseInt (rs.getString (1)) ; return (added == 1) ; } catch (Exception e) { System.out.println (e.getMessage ()) ; return false ; } } public boolean SaveToDB (Connection dbCon) { if (ID == 0) return false ; try { int added = 0 ; Statement stmt = dbCon.createStatement () ; added = stmt.executeUpdate ("UPDATE tbl_Customers SET " + "CustomerName = '" + fullName + "', Address = '" + address.GetAddressLine() +"', City = '" + address.GetCity() + "', ZipCode = '" + address.GetZipCode() + "', PhoneNo = '" + address.GetPhoneNo() + "', IsPubUtilComp = " + (pubUtil ? "1" : "0") + "WHERE CusID = " + ID) ; return (added == 1) ; } catch (Exception e) { System.out.println (e.getMessage ()) ; return false ; } } public boolean GetPubUtil () {return pubUtil;} public void SetPubUtil(boolean ut) {pubUtil = ut;} }

152

SOURCE CODE Stathis Polyzos F.3.6. DatabaseObject.java

package CommonObjects.Entities ; import java.io.Serializable; import java.sql.*; public abstract class DatabaseObject implements Serializable { int ID; public int GetID () {return ID;} public void SetID(int id) {ID = id;} public abstract boolean AddToDB(Connection dbCon); public abstract boolean SaveToDB(Connection dbCon); }

153

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


F.3.7. Employee.java package CommonObjects.Entities ; import java.sql.* ; public class Employee extends Person { private String identityNo, taxationNo ; private boolean sex, active ; public Employee () { ID = 0 ; identityNo = "" ; fullName = "" ; address = new Address(); taxationNo = "" ; sex = false ; active = false ; } public Employee (Connection dbCon, int id) { ID = id ; address = new Address(); try { Statement stmt = dbCon.createStatement () ; ResultSet rs = stmt.executeQuery ("SELECT * FROM tbl_Employees " + "WHERE EmplID = " + ID) ; rs.next () ; identityNo = rs.getString (2) ; fullName = rs.getString (3) ; address.SetAddressLine(rs.getString (4) ); address.SetPhoneNo( rs.getString (5) ); address.SetCity( rs.getString (6) ); address.SetZipCode( rs.getString (7) ); taxationNo = rs.getString (12) ; sex = (rs.getString (8).equals ("1") ? true : false) ; active = (rs.getString (9).equals ("1") ? true : false) ; rs.close () ; stmt.close () ; } catch (Exception exp) { System.out.println (exp.getMessage ()) ; } } public boolean AddToDB (Connection dbCon) { if (ID != 0) return false ; 154

SOURCE CODE Stathis Polyzos

try { int added = 0 ; Statement stmt = dbCon.createStatement () ; added = stmt.executeUpdate ("INSERT INTO tbl_Employees " + "(IdentityNo, LastName, FirstName, Address, PhoneNo, City, " + "ZipCode, Sex, Active, TaxationNo) " + "VALUES ('" + identityNo + "', '" + fullName + "', '" + address.GetAddressLine () + "', '" + address.GetPhoneNo () + "', '" + address.GetCity () + "', '" + address.GetZipCode () + "', " + (sex ? "1" : "0") + ", " + (active ? "1" : "0") + ", '" + taxationNo + "' )") ; ResultSet rs = stmt.executeQuery ("SELECT TOP 1 EmplID FROM " + "tbl_Employees ORDER BY EmplID DESC") ; if (rs.next ()) ID = Integer.parseInt (rs.getString (1)) ; return (added == 1) ; } catch (Exception e) { System.out.println (e.getMessage ()) ; return false ; } } public boolean SaveToDB (Connection dbCon) { if (ID == 0) return false ; try { int added = 0 ; Statement stmt = dbCon.createStatement () ; added = stmt.executeUpdate ("UPDATE tbl_Employees SET " + "IdentityNo = '" + identityNo + "', FullName = '" + fullName + "', Address = '" + address.GetAddressLine() + "', PhoneNo = '" + address.GetPhoneNo() + "', City = '" + address.GetCity() + "', ZipCode = '" + address.GetZipCode() + "', Sex = " + (sex ? "1" : "0") + ", Active = " + (active ? "1" : "0") + ", TaxationNo = '" + taxationNo + "' WHERE EmplID = " + ID) ; return (added == 1) ; } catch (Exception e) { System.out.println (e.getMessage ()) ; return false ; } } public String GetIdentityNo () {return identityNo;} public void SetIdentityNo(String iden) {identityNo = iden;} public boolean GetSex () {return sex;} public void SetSex(boolean sx) {sex = sx;} public boolean GetActive () {return active;} public void SetActive(boolean act) {active = act;}

155

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


public String GetTaxationNo () {return taxationNo;} public void SetTaxationNo(String tx) {taxationNo = tx;} }

156

SOURCE CODE Stathis Polyzos F.3.8. GenTransaction.java

package CommonObjects.Entities ; public abstract class GenTransaction extends DatabaseObject { byte type ; double amount ; String comments ; public byte GetType() { return type;} public void SetType(byte typ) {type = typ;} public double GetAmount () {return amount;} public void SetAmount(double amt) {amount = amt;} public String GetComments() { return comments;} public void SetComments(String comm) {comments = comm;} }

157

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


F.3.9. Person.java package CommonObjects.Entities ; public abstract class Person extends DatabaseObject { String fullName; Address address; public String GetFullName () {return fullName;} public void SetFullName(String fname) {fullName = fname;} public Address GetAddress() {return address;} public void SetAddress(Address add) {address = add;} }

158

SOURCE CODE Stathis Polyzos F.3.10. Transaction.java

package CommonObjects.Entities ; import java.sql.* ; public class Transaction extends GenTransaction { private String transDate ; private int account ; public Transaction () { ID = 0 ; transDate = "" ; account = 0 ; type = 0 ; amount = 0 ; comments = "" ; } public Transaction ( int cpTransID, String cpTransDate, int cpAccount, byte cpType, double cpAmount, String cpComments ) { ID = cpTransID ; transDate = cpTransDate ; account = cpAccount ; type = cpType ; amount = cpAmount ; comments = cpComments ; } public Transaction (Transaction cpTrans) { ID = cpTrans.GetID () ; transDate = cpTrans.GetTransDate () ; account = cpTrans.GetAccount () ; type = cpTrans.GetType () ; amount = cpTrans.GetAmount () ; comments = cpTrans.GetComments () ; } public boolean AddToDB(Connection dbCon) { if (ID != 0) return false ; int added = 0 ; try { Statement stmt = dbCon.createStatement () ; added = stmt.executeUpdate ("INSERT INTO tbl_Transactions " + "(Account, Type, Amount, Comments) " + 159

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


"VALUES (" + account + ", " + type + ", " + amount + ", '" + comments + "' )") ; ResultSet rs = stmt.executeQuery("SELECT TOP 1 TransID FROM " + "tbl_Transactions ORDER BY TransID DESC"); if (rs.next ()) ID = Integer.parseInt (rs.getString (1)) ; return (added == 1) ; } catch (Exception e) { System.out.println( e.getMessage()); return false ; } } public boolean SaveToDB (Connection dbCon) { //Is not implemented return false ; } public String GetTransDate() { return transDate;} public void SetTransDate(String trdt) {transDate = trdt;} public int GetAccount() { return account;} public void SetAccount(int acc) {account = acc;} }

160

SOURCE CODE Stathis Polyzos F.3.11. User.java

package CommonObjects.Entities ; import java.sql.*; public class User extends DatabaseObject { private String userName; private String password; private int accessLevel; private int emplID; private int custID; public User () { ID = 0 ; userName = "" ; password = "" ; accessLevel = 0 ; custID = 0 ; emplID = 0 ; } public User ( int cpUserID, String cpUserName, String cpPass, int cpAccLev, int cpID, String type ) { ID = cpUserID; userName = cpUserName; password = cpPass ; accessLevel = cpAccLev ; if (type.equals("empl")) emplID = cpID ; else custID = cpID ; } public User (Connection dbCon, String userN) { userName = userN ; try { Statement stmt = dbCon.createStatement () ; ResultSet rs = stmt.executeQuery ("SELECT * FROM tbl_UserAccess " + "WHERE UserName = '" + userName + "'") ; rs.next () ; ID = Integer.parseInt (rs.getString (1)) ; password = rs.getString (3) ; accessLevel = Integer.parseInt (rs.getString (4)) ; emplID = Integer.parseInt (rs.getString (5)) ; custID = Integer.parseInt (rs.getString (6)) ; 161

SUPERTRANS CUSTOMER TRANSACTION SYSTEM

rs.close () ; stmt.close () ; } catch (Exception exp) { System.out.println (exp.getMessage ()) ; } } public boolean AddToDB (Connection dbCon) { if (ID != 0) return false ; int added = 0 ; try { Statement stmt = dbCon.createStatement () ; added = stmt.executeUpdate ("INSERT INTO tbl_UserAccess " + "(UserName, Password, AccessLevel, EmployeeID, CustomerID) " + "VALUES ('" + userName + "', '" + password + "', " + accessLevel + ", " + emplID + ", " + custID + ")") ; ResultSet rs = stmt.executeQuery ("SELECT UserID FROM " + "tbl_UserAccess WHERE UserName = '" + userName + "'") ; if (rs.next ()) ID = Integer.parseInt (rs.getString (1)) ; return (added == 1) ; } catch (Exception e) { return false ; } } public boolean SaveToDB(Connection dbCon) { //Is not implemented return false; } public boolean DeactivateUser (Connection dbCon) { if (ID == 0) return false ; int updated = 0 ; try { Statement stmt = dbCon.createStatement () ; updated = stmt.executeUpdate ("UPDATE tbl_UserAccess SET [Active] = 0 " + "WHERE UserID = " + ID) ; return (updated == 1) ; } catch (Exception e) 162

SOURCE CODE Stathis Polyzos { return false ; } } public boolean ActivateUser (Connection dbCon) { if (ID == 0) return false ; int updated = 0 ; try {

Statement stmt = dbCon.createStatement () ; updated = stmt.executeUpdate ("UPDATE tbl_UserAccess SET [Active] = 1 " + "WHERE UserID = " + ID) ; return (updated == 1) ; } catch (Exception e) { return false ; } } public String GetUserName() {return userName;} public void SetUserName(String nam) {userName = nam;} public String GetPass() {return password;} public void SetPass(String ps) {password = ps;} public int GetAccessLevel() {return accessLevel;} public void SetAccessLevel(int lev) {accessLevel = lev;} public int GetEmployeeID() {return emplID;} public void SetEmployeeID(int empl) {emplID= empl;} public int GetCustomerID() {return custID;} public void SetCustomerID(int cnm) {custID = cnm;} }

163

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


F.4. GlobalPack

F.4.1. ClientUtilities.java package GlobalPack ; import java.io.ObjectInputStream ; import java.io.ObjectOutputStream ; import java.net.Socket ; import import import import CommonObjects.LoginStatus ; CommonObjects.UserID ; CommonObjects.Entities.Account ; CommonObjects.Entities.CreditCard ;

public abstract class ClientUtilities { /** * Dispatches the TradeToken to the server specified in the LoginStatus * object or to the particular host and server pass explicitly as arguments. * * Returns the server's reply token * * @param snd TradeToken * @param status LoginStatus * @param host String * @param port int * @return TradeToken */ public static TradeToken DispatchToken (TradeToken tok, LoginStatus status, String host, int port) { TradeToken ret ; //If port not specified, use values from status object if (port == 0) { host = status.GetHost () ; port = status.GetPort () ; } try { //Initiate connection and objects Socket s = new Socket (host, port) ; ObjectOutputStream oos = new ObjectOutputStream (s.getOutputStream ()) ; ObjectInputStream ois = new ObjectInputStream (s.getInputStream ()) ; //Send TradeToken oos.writeObject (tok) ; oos.flush () ; //Read reply ret = (TradeToken) ois.readObject () ; //Close connection oos.close () ; ois.close () ; s.close () ; } catch (Exception exp) 164

SOURCE CODE Stathis Polyzos

{ System.out.println (exp.getMessage ()) ; ret = new TradeToken () ; } return ret ; } /** * Reads the user's accounts from the server. * * @param status LoginStatus * @return Account[] */ public static Account[] GetUserAccounts (LoginStatus status) { Account[] retArray ; TradeToken rcvTok = DispatchToken (new TradeToken (new UserID (status. GetUser (), 1, status), 3), status, "", 0) ; retArray = new Account[rcvTok.getType ()] ; retArray = (Account[]) rcvTok.getData () ; return retArray ; } /** * Reads the public utility company accounts from the server. * * @param status LoginStatus * @return Account[] */ public static Account[] GetPubUtilAccounts (LoginStatus status) { Account[] retArray ; TradeToken rcvTok = DispatchToken (new TradeToken (new UserID (status. GetUser (), 2, status), 3), status, "", 0) ; retArray = new Account[rcvTok.getType ()] ; retArray = (Account[]) rcvTok.getData () ; return retArray ; } /** * Reads the user's real name from the server. * * @param status LoginStatus * @return String */ public static String GetCustomerName (LoginStatus status) { String retString ; TradeToken rcvTok = DispatchToken (new TradeToken (new UserID (status. GetUser (), 3, status), 3), status, "", 0) ; retString = (String) rcvTok.getData () ; return retString ; } 165

SUPERTRANS CUSTOMER TRANSACTION SYSTEM

/** * Reads the user's Credit Cards from the server * * @param status LoginStatus * @return CreditCard[] */ public static CreditCard[] GetUserCreditCards (LoginStatus status) { CreditCard[] retArray ; TradeToken rcvTok = DispatchToken (new TradeToken (new UserID (status. GetUser (), 4, status), 3), status, "", 0) ; retArray = new CreditCard[rcvTok.getType ()] ; retArray = (CreditCard[]) rcvTok.getData () ; return retArray ; } /** * Reads the user's access level from the server. * * @param status LoginStatus * @return int */ public static int GetUserLevel (LoginStatus status) { TradeToken rcvTok = DispatchToken (new TradeToken (new UserID (status. GetUser (), 5, status), 3), status, "", 0) ; return rcvTok.getType () ; } /** * Reads the IDs of all customers from the server * * @param status LoginStatus * @return int[] */ public static int[] GetCustomerIDList (LoginStatus status) { int[] retArray ; TradeToken rcvTok = DispatchToken (new TradeToken (new UserID (status. GetUser (), 6, status), 3), status, "", 0) ; retArray = new int[rcvTok.getType ()] ; retArray = (int[]) rcvTok.getData () ; return retArray ; } /** * Reads the IDs of all employees from the server * * @param status LoginStatus * @return int[] */ public static int[] GetEmployeeIDList (LoginStatus status) { int[] retArray ; 166

SOURCE CODE Stathis Polyzos

TradeToken rcvTok = DispatchToken (new TradeToken (new UserID (status. GetUser (), 7, status), 3), status, "", 0) ; retArray = new int[rcvTok.getType ()] ; retArray = (int[]) rcvTok.getData () ; return retArray ; } /** * Reads the credit card numbers of all cards from the server * * @param status LoginStatus * @return String[] */ public static String[] GetAllCreditCards (LoginStatus status) { String[] retArray ; TradeToken rcvTok = DispatchToken (new TradeToken (new UserID (status. GetUser (), 8, status), 3), status, "", 0) ; retArray = new String[rcvTok.getType ()] ; retArray = (String[]) rcvTok.getData () ; return retArray ; } /** * Reads the user names of all customer users from the server * * @param status LoginStatus * @return String[] */ public static String[] AllUserIDs (LoginStatus status) { String[] retArray ; TradeToken rcvTok = DispatchToken (new TradeToken (new UserID (status. GetUser (), 9, status), 3), status, "", 0) ; retArray = new String[rcvTok.getType ()] ; retArray = (String[]) rcvTok.getData () ; return retArray ; } /** * Tries to parse a string as double and returns -1 if the string cannot * be parsed, or the double if it is valid.Only allows positive numbers, so * if the string represents a negative number, an error (-1) will be * returned. * * @param amt String * @return Double */ public static Double ToDouble (String amt) { double retVal = -1 ; try 167

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


{ retVal = Double.parseDouble (amt) ; } catch (NumberFormatException nfe) { //If not a clean number, try again removing decimals and separators try { retVal = Double.parseDouble (amt.replace (".", "").replace (",", ".")) ; } catch (NumberFormatException nfe2) {} ; } if (retVal < 0) retVal = -1 ; return retVal ; } }

168

SOURCE CODE Stathis Polyzos F.4.2. DBUtilities.java

package GlobalPack ; import java.sql.* ; public abstract class DBUtilities { /** * Attempts a connection to an SQL server specified by the server parameter, * for the specific database, using the given user name and password. * * Uses the Microsoft SQL connector for JDBC. * * Returns the connection object or null in case of an error * * @param server String * @param database String * @param user String * @param pass String * @return Connection */ public static Connection MakeConnection (String server, String database, String user, String pass) { Connection retCon ; try { //Import class Class.forName ("com.microsoft.sqlserver.jdbc.SQLServerDriver") ; //Build connection string String connString = "jdbc:sqlserver://" ; connString += server ; connString += ";databaseName=" + database ; connString += ";user=" + user ; connString += ";password=" + pass ; //Attempt connection retCon = DriverManager.getConnection (connString) ; } catch (ClassNotFoundException e) { System.out.println ("Could not find driver...") ; return null ; } catch (SQLException e) { System.out.println ("SQL Exception while connecting to SQL Server :\n" + e.getMessage ()) ; return null ; } return retCon ; } /** * Gets the customer ID from a given user ID. If the user is an employee. 169

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


* zero is returned. * * @param userID int * @param dbCon Connection * @return int */ public static int GetCustomer (int userID, Connection dbCon) { int retCust = 0 ; try { //Get query results Statement stmt = dbCon.createStatement () ; ResultSet rs = stmt.executeQuery ("SELECT CustomerID FROM tbl_UserAccess" + " WHERE UserID = " + userID) ; //Store reponse if (rs.next ()) retCust = Integer.parseInt (rs.getString (1)) ; } catch (Exception e) { System.out.println (e.getMessage ()) ; return -1 ; } return retCust ; } /** * Gets the user level of the specified user ID * * @param userID int * @param dbCon Connection * @return int */ public static int GetLevel (int userID, Connection dbCon) { int retLevl = 0 ; try { //Get query results Statement stmt = dbCon.createStatement () ; ResultSet rst = stmt.executeQuery ( "SELECT AccessLevel FROM tbl_UserAccess " + "WHERE UserID = " + userID) ; //Store reponse if (rst.next ()) retLevl = Integer.parseInt (rst.getString (1)) ; } catch (Exception e) { System.out.println (e.getMessage ()) ; return -1 ; } return retLevl ; } 170

SOURCE CODE Stathis Polyzos

171

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


F.4.3. TradeToken.java package GlobalPack ; import java.io.Serializable ; public class TradeToken implements Serializable { private Object carryData ; private int objectType ; public TradeToken () { carryData = null ; objectType = -1 ; } public TradeToken (Object seData, int seType) { carryData = seData ; objectType = seType ; } public Object getData () { return carryData ; } public int getType () { return objectType ; } }

172

SOURCE CODE Stathis Polyzos

F.5.

ServerPack

F.5.1. CSPA.java package ServerPack ; import import import import java.awt.* ; java.awt.event.ActionEvent ; java.awt.event.ActionListener ; java.sql.Connection ;

import javax.swing.* ; import GlobalPack.DBUtilities ; import java.awt.Rectangle ; import java.awt.Dimension ; public class CSPA extends JFrame { private JPanel contentPane ; private JMenuBar jMenuBar1 = new JMenuBar () ; private JMenu jMenuFile = new JMenu () ; private JMenuItem jMenuFileExit = new JMenuItem () ; private JButton btnStart = new JButton () ; private JButton btnStop = new JButton () ; private JTextArea resArea = new JTextArea () ; private ServerCSPA cs ; private JTextField txtServer = new JTextField () ; private JPasswordField txtPass = new JPasswordField () ; private JTextField txtDB = new JTextField () ; private JTextField txtUserName = new JTextField () ; private JLabel jLabel1 = new JLabel () ; private JLabel jLabel2 = new JLabel () ; private JLabel jLabel3 = new JLabel () ; private JLabel jLabel4 = new JLabel () ; private Connection con ; public CSPA () { try { setDefaultCloseOperation (EXIT_ON_CLOSE) ; jbInit () ; } catch (Exception exception) { exception.printStackTrace () ; } } /** * Component initialization. * * @throws java.lang.Exception */ private void jbInit () throws Exception { contentPane = (JPanel) getContentPane () ; contentPane.setLayout (null) ; 173

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


this.setJMenuBar (jMenuBar1) ; setSize (new Dimension (490, 320)) ; setTitle ("SuperTrans :: CSPA") ; jMenuFile.setText ("File") ; jMenuFileExit.setText ("Exit") ; jMenuFileExit.addActionListener (new CSPA_jMenuFileExit_ActionAdapter (this)) ; btnStart.setBounds (new Rectangle (129, 83, 105, 23)) ; btnStart.setText ("Up Server") ; btnStart.addActionListener (new CSPA_btnStart_actionAdapter (this)) ; btnStop.setBounds (new Rectangle (281, 83, 105, 23)) ; btnStop.setEnabled (false) ; btnStop.setText ("Down Server") ; btnStop.addActionListener (new CSPA_btnStop_actionAdapter (this)) ; resArea.setBounds (new Rectangle (20, 119, 448, 119)) ; txtServer.setText ("localhost") ; txtServer.setBounds (new Rectangle (123, 25, 106, 19)) ; txtPass.setText ("bankpass") ; txtPass.setBounds (new Rectangle (323, 49, 114, 17)) ; txtDB.setText ("DORBank") ; txtDB.setBounds (new Rectangle (123, 48, 104, 19)) ; txtUserName.setText ("bankAdmin") ; txtUserName.setBounds (new Rectangle (323, 25, 116, 19)) ; jLabel1.setText ("User") ; jLabel1.setBounds (new Rectangle (260, 27, 58, 14)) ; jLabel2.setText ("Database") ; jLabel2.setBounds (new Rectangle (30, 50, 88, 14)) ; jLabel3.setText ("Password") ; jLabel3.setBounds (new Rectangle (260, 50, 60, 14)) ; jLabel4.setText ("Database Server") ; jLabel4.setBounds (new Rectangle (30, 27, 88, 14)) ; jMenuBar1.add (jMenuFile) ; jMenuFile.add (jMenuFileExit) ; contentPane.add (txtUserName) ; contentPane.add (txtServer) ; contentPane.add (txtPass) ; contentPane.add (jLabel1) ; contentPane.add (jLabel3) ; contentPane.add (resArea) ; contentPane.add (btnStop) ; contentPane.add (btnStart) ; contentPane.add (txtDB) ; contentPane.add (jLabel4) ; contentPane.add (jLabel2) ; } /** * File | Exit action performed. * * @param actionEvent ActionEvent */ void jMenuFileExit_actionPerformed (ActionEvent actionEvent) { System.exit (0) ; } public void btnStart_actionPerformed (ActionEvent e) { char[] password ; try { 174

SOURCE CODE Stathis Polyzos

password = txtPass.getPassword () ; String pass = "" ; for (int i = 0 ; i < password.length ; i++) { pass += password[i] ; } con = DBUtilities.MakeConnection (txtServer.getText (), txtDB.getText (), txtUserName.getText (), pass) ; if (con.equals (null)) { this.resArea.append ("Error connecting to database...\n") ; } else { this.resArea.append ("Connected to database...\n") ; cs = new ServerCSPA (con) ; this.resArea.append ("Server up...\n") ; this.btnStop.setEnabled (true) ; this.btnStart.setEnabled (false) ; } } catch (Exception exp) { this.resArea.append (exp.getMessage () + "\n") ; } } public void btnStop_actionPerformed (ActionEvent e) { cs.StopServer () ; this.resArea.append ("Server down...\n") ; try { con.close () ; } catch (Exception clExp) {} this.resArea.append ("Connection to database closed...\n") ; this.btnStop.setEnabled (false) ; this.btnStart.setEnabled (true) ; } } class CSPA_btnStop_actionAdapter implements ActionListener { private CSPA adaptee ; CSPA_btnStop_actionAdapter (CSPA adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnStop_actionPerformed (e) ; } } class CSPA_btnStart_actionAdapter implements ActionListener 175

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


{ private CSPA adaptee ; CSPA_btnStart_actionAdapter (CSPA adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent e) { adaptee.btnStart_actionPerformed (e) ; } } class CSPA_jMenuFileExit_ActionAdapter implements ActionListener { private CSPA adaptee ; CSPA_jMenuFileExit_ActionAdapter (CSPA adaptee) { this.adaptee = adaptee ; } public void actionPerformed (ActionEvent actionEvent) { adaptee.jMenuFileExit_actionPerformed (actionEvent) ; } }

176

SOURCE CODE Stathis Polyzos F.5.2. CSPAGUI.java

package ServerPack ; import java.awt.Dimension ; import java.awt.Toolkit ; import javax.swing.SwingUtilities ; import javax.swing.UIManager ; public class CSPAGUI { private boolean packFrame = false ; public static CSPAGUI serverGUI ; public CSPA frame ; /** * Construct and show the application. */ public CSPAGUI () { CSPA frame = new CSPA () ; // Validate frames that have preset sizes // Pack frames that have useful preferred size info, e.g. from their layout if (packFrame) { frame.pack () ; } else { frame.validate () ; } // Center the window Dimension screenSize = Toolkit.getDefaultToolkit ().getScreenSize () ; Dimension frameSize = frame.getSize () ; if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height ; } if (frameSize.width > screenSize.width) { frameSize.width = screenSize.width ; } frame.setLocation ((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2) ; frame.setVisible (true) ; } /** * Application entry point. * * @param args String[] */ public static void main (String[] args) { SwingUtilities.invokeLater (new Runnable () { public void run () { try 177

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


{ UIManager.setLookAndFeel (UIManager.getSystemLookAndFeelClassName ()) ; } catch (Exception exception) { exception.printStackTrace () ; } serverGUI = new CSPAGUI () ; } }) ; } }

178

SOURCE CODE Stathis Polyzos F.5.3. ServerCSPA.java

package ServerPack ; import import import import import java.io.ObjectInputStream ; java.io.ObjectOutputStream ; java.net.ServerSocket ; java.net.Socket ; java.sql.* ;

import CommonObjects.* ; import CommonObjects.Entities.* ; import GlobalPack.* ; public class ServerCSPA extends Thread { private ServerSocket hostServer ; private int portNumber ; public boolean allowRun = true ; private Connection dbCon ; public ServerCSPA (Connection cpCon) throws Exception { portNumber = 5701 ; hostServer = new ServerSocket (portNumber) ; System.out.println ("Server up on port " + portNumber + ".") ; dbCon = cpCon ; this.start () ; } public void run () { while (allowRun) { try { System.out.println ("Awaiting...") ; Socket client = hostServer.accept () ; System.out.println ("New connection from IP: " + client.getInetAddress ()) ; ClientConnection c = new ClientConnection (client, dbCon) ; } catch (Exception e) {} } try { hostServer.close () ; hostServer.setReuseAddress (true) ; } catch (Exception exc) {} } public void StopServer () { allowRun = false ; System.out.println ("Server down...") ; 179

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


} } class ClientConnection extends Thread { private Socket client = null ; private Connection dbCon ; private ObjectInputStream ois = null ; private ObjectOutputStream oos = null ; public ClientConnection (Socket clientSocket, Connection con) { dbCon = con ; client = clientSocket ; try { ois = new ObjectInputStream (client.getInputStream ()) ; oos = new ObjectOutputStream (client.getOutputStream ()) ; } catch (Exception e1) { try { client.close () ; } catch (Exception e) { System.out.println (e.getMessage ()) ; } return ; } this.start () ; } public void run () { TradeToken recToken = null ; try { recToken = (TradeToken) ois.readObject () ; TradeToken output = this.HandleToken (recToken) ; oos.writeObject (output) ; oos.flush () ; ois.close () ; oos.close () ; client.close () ; } catch (Exception e) { System.out.println (e.getMessage ()) ; } } /* * * Gets the received token from the client and processes it accordingly * returning the appropriate reply token. 180

SOURCE CODE Stathis Polyzos

* Will normally throw an exception only when an error occurs in the * communication with the database * */ private TradeToken HandleToken (TradeToken incToken) throws Exception { TradeToken retToken = new TradeToken () ; //Return token Statement stmt = dbCon.createStatement () ; //Statement object ResultSet rst ; //Resultset int retLng = 0 ; //Return array length switch (incToken.getType ()) { case 1: //LoginUser (returns LoginStatus) //Read object LoginUser recObj = (LoginUser) incToken.getData () ; LoginStatus retStat = new LoginStatus ( recObj.Host (), recObj.Port ()) ; String usr = recObj.Username () ; String pass = recObj.Password () ; int userID1 = 0 ; //Match username and password in the database rst = stmt.executeQuery ("SELECT UserID " + "FROM tbl_UserAccess WHERE ( UserName = '" + usr + "' ) AND ( Password = '" + pass + "' ) AND ( Active = 1 )") ; //Check for results if (rst.next ()) userID1 = Integer.parseInt (rst.getString (1)) ; //If there exists a username, change the status in LoginStatus if (userID1 != 0) retStat.TrueLogin (270278, userID1) ; //Save results retToken = new TradeToken (retStat, 2) ; break ; case 3: //User ID, return object vary according to action type //Read object UserID usrID = (UserID) incToken.getData () ; //Authenticate if (!usrID.GetStatus ()) return new TradeToken () ; switch (usrID.GetActionType ()) { case 1: //Get Customer Accounts //Get customer ID int cus = DBUtilities.GetCustomer (usrID.GetUserID (), dbCon) ; if (cus == 0) return new TradeToken () ; 181

SUPERTRANS CUSTOMER TRANSACTION SYSTEM

//Count customer accounts rst = stmt.executeQuery ("SELECT Count(*) FROM tbl_Accounts " + "WHERE Customer = " + cus) ; if (rst.next ()) retLng = Integer.parseInt (rst.getString (1)) ; //If no accounts exist, return null if (retLng == 0) return new TradeToken () ; //Instantiate return array with known length Account[] retAccArray = new Account[retLng] ; //Get resultset rst = stmt.executeQuery ("SELECT * FROM tbl_Accounts " + "WHERE Customer = " + cus + " ORDER BY AccountNumber") ; rst.next () ; //Save accounts to account array for (int i = 0 ; i < retLng ; i++) { Account tmpAcc = new Account ( Integer.parseInt (rst.getString (1)), rst.getString (2), Integer.parseInt (rst.getString (3)), Double.parseDouble (rst.getString (4))) ; retAccArray[i] = tmpAcc ; rst.next () ; } //Save result retToken = new TradeToken (retAccArray, retLng) ; break ; case 2: //Get Public Utility Company (PUC) Accounts //Get customer ID int cus2 = DBUtilities.GetCustomer (usrID.GetUserID (), dbCon) ; //Count PUC accounts rst = stmt.executeQuery ( "SELECT Count(*) FROM qry_PublicUtilityAccounts" + " WHERE Customer <> " + cus2) ; if (rst.next ()) retLng = Integer.parseInt (rst.getString (1)) ; //If no accounts exist, return null if (retLng == 0) return new TradeToken () ; //Initialise return array with known length Account[] retAccArray2 = new Account[retLng] ; rst = stmt.executeQuery ( "SELECT * FROM qry_PublicUtilityAccounts " + " WHERE Customer <> " + cus2 + " ORDER BY CustomerName") ; rst.next () ; //Save account objects to array for (int i = 0 ; i < retLng ; i++) 182

SOURCE CODE Stathis Polyzos

{ Account tmpAcc = new Account ( Integer.parseInt (rst.getString (1)), rst.getString (2), Integer.parseInt (rst.getString (4)), Double.parseDouble (rst.getString (5)), rst.getString (3)) ; retAccArray2[i] = tmpAcc ; rst.next () ; } //Save results retToken = new TradeToken (retAccArray2, retLng) ; break ; case 3: //Get User's real Name //Get access level and IDs String sql = "SELECT AccessLevel, EmployeeID, CustomerID " + "FROM tbl_UserAccess " + "WHERE UserID = " + usrID.GetUserID () ; rst = stmt.executeQuery (sql) ; int retLevel = 0, //Access Level retEmpl = 0, //Employee ID retCus = 0 ; //Customer ID if (rst.next ()) { retLevel = Integer.parseInt (rst.getString (1)) ; retEmpl = Integer.parseInt (rst.getString (2)) ; retCus = Integer.parseInt (rst.getString (3)) ; } if (retLevel > 2) //User is customer sql = "SELECT CustomerName FROM tbl_Customers" + " WHERE CusID = " + retCus ; else //User is employee sql = "SELECT FullName FROM tbl_Employees " + "WHERE EmplID = " + retEmpl ; rst = stmt.executeQuery (sql) ; String retString = "" ; //Get name from resultset if (rst.next ()) retString = rst.getString (1) ; //Save results retToken = new TradeToken (retString, 0) ; break ; case 4: //Get Customer's Credit Cards //Get customer ID int cus4 = DBUtilities.GetCustomer (usrID.GetUserID (), dbCon) ; if (cus4 == 0) return new TradeToken () ; //Count credit cards rst = stmt.executeQuery ("SELECT Count(*) FROM tbl_CreditCards " + "WHERE Active = 1 AND Customer = " + cus4) ; 183

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


if (rst.next ()) retLng = Integer.parseInt (rst.getString (1)) ; //If no cards return null if (retLng == 0) return new TradeToken () ; //Initialise array with known length CreditCard[] retArray4 = new CreditCard[retLng] ; rst = stmt.executeQuery ("SELECT * FROM tbl_CreditCards " + "WHERE Active = 1 AND Customer = " + cus4 + " ORDER BY CreditCardNo") ; rst.next () ; //Save credit cards to list for (int i = 0 ; i < retLng ; i++) { CreditCard tmpCC = new CreditCard ( Integer.parseInt (rst.getString (1)), Integer.parseInt (rst.getString (2)), rst.getString (3), rst.getString (4), Double.parseDouble (rst.getString (5))) ; retArray4[i] = tmpCC ; rst.next () ; } //Save results retToken = new TradeToken (retArray4, retLng) ; break ; case 5: //Get user level //Get level int retLevl = DBUtilities.GetLevel (usrID.GetUserID (), dbCon) ; //Return error or save results if (retLevl == 0) return new TradeToken () ; else retToken = new TradeToken (null, retLevl) ; break ; case 6: //Customer ID List //Get level int lev6 = DBUtilities.GetLevel (usrID.GetUserID (), dbCon) ; //If customer, return error if (lev6 > 2) return new TradeToken () ; int[] retArray6 ; //Count customers and check if any exists rst = stmt.executeQuery ("SELECT COUNT(*) FROM tbl_Customers") ; if (rst.next ()) retLng = Integer.parseInt (rst.getString (1)) ; if (retLng == 0) return new TradeToken (null, 0) ;

184

SOURCE CODE Stathis Polyzos

//Initialise return array with known length retArray6 = new int[retLng] ; rst = stmt.executeQuery ( "SELECT CusID FROM tbl_Customers") ; rst.next () ; //Save IDs to list for (int i = 0 ; i < retLng ; i++) { retArray6[i] = Integer.parseInt (rst.getString (1)) ; rst.next () ; } //Save results retToken = new TradeToken (retArray6, retLng) ; break ; case 7: //Employee ID List //Get user level int lev7 = DBUtilities.GetLevel (usrID.GetUserID (), dbCon) ; //If not management return error if (lev7 > 1) return new TradeToken () ; int[] retArray7 ; //Count employees and check if any exist rst = stmt.executeQuery ("SELECT COUNT(*) FROM tbl_Employees") ; if (rst.next ()) retLng = Integer.parseInt (rst.getString (1)) ; if (retLng == 0) return new TradeToken (null, 0) ; //Initialise array with known length retArray7 = new int[retLng] ; rst = stmt.executeQuery ( "SELECT EmplID FROM tbl_Employees ORDER BY EmplID") ; rst.next () ; //Save IDs to list for (int i = 0 ; i < retLng ; i++) { retArray7[i] = Integer.parseInt (rst.getString (1)) ; rst.next () ; } //Save results retToken = new TradeToken (retArray7, retLng) ; break ; case 8: //Credit Card No List (All Credit Cards) //Get level int lev8 = DBUtilities.GetLevel (usrID.GetUserID (), dbCon) ; //If customer return error if (lev8 > 2) return new TradeToken () ;

185

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


String[] retArray8 ; //Count credit cards and check if any exist rst = stmt.executeQuery ( "SELECT COUNT(*) FROM tbl_CreditCards") ; if (rst.next ()) retLng = Integer.parseInt (rst.getString (1)) ; if (retLng == 0) return new TradeToken (null, 0) ; //Initialise array with known length retArray8 = new String[retLng] ; rst = stmt.executeQuery ( "SELECT CreditCardNo FROM tbl_CreditCards" + " ORDER BY CreditCardNo") ; rst.next () ; //Save credit card numbers to list for (int i = 0 ; i < retLng ; i++) { retArray8[i] = rst.getString (1) ; rst.next () ; } //Save results retToken = new TradeToken (retArray8, retLng) ; break ; case 9: //UserID List (Customers) //Get User level int lev9 = DBUtilities.GetLevel (usrID.GetUserID (), dbCon) ; //if customer return error if (lev9 > 2) return new TradeToken () ; String[] retArray9 ; //Count customer users and check if any exist rst = stmt.executeQuery ("SELECT COUNT(*) FROM tbl_UserAccess " + "WHERE AccessLevel = 3") ; if (rst.next ()) retLng = Integer.parseInt (rst.getString (1)) ; if (retLng == 0) return new TradeToken (null, 0) ; //Initialise array with known length retArray9 = new String[retLng] ; rst = stmt.executeQuery ("SELECT UserName FROM tbl_UserAccess " + "WHERE AccessLevel = 3 ORDER BY UserName") ; rst.next () ; //Save user names to list for (int i = 0 ; i < retLng ; i++) { retArray9[i] = rst.getString (1) ; rst.next () ; } //Save results 186

SOURCE CODE Stathis Polyzos

retToken = new TradeToken (retArray9, retLng) ; break ; default: break ; } break ; case 4: //Make Transfer - Returns confirmation //Read data MakeTransfer mkTrans = (MakeTransfer) incToken.getData () ; //Authenticate if (!mkTrans.GetStatus ()) return new TradeToken () ; //Read transactions Transaction trOut4 = new Transaction (mkTrans.GetTransOut ()) ; Transaction trIn4 = new Transaction (mkTrans.GetTransIn ()) ; boolean success4 = false ; //Add withdrawal (trOut) success4 = trOut4.AddToDB (dbCon) ; //if fail, return error if (!success4) return new TradeToken (null, 0) ; //Add deposit (trIn) success4 = trIn4.AddToDB (dbCon) ; //If fail, rollback previous transaction and return error if (!success4) { int del4 = stmt.executeUpdate ("DELETE FROM tbl_Transactions " + "WHERE ( TransID = " + trOut4.GetID () + " )") ; return new TradeToken (null, 0) ; } //Save results retToken = new TradeToken (null, 1) ; break ; case 5: //Make Transfer To CreditCard - Returns confirmation //Read object MakeTransferToCredit mkTransCr = (MakeTransferToCredit) incToken.getData () ; //Authenticate if (!mkTransCr.GetStatus ()) return new TradeToken () ; //Read transactions Transaction trOut5 = new Transaction (mkTransCr.GetTransOut ()) ; CreditCardTransaction trIn5 = new CreditCardTransaction ( mkTransCr.GetCreditIn ()) ; boolean success5 = false ;

187

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


//Add cash withdrawal success5 = trOut5.AddToDB (dbCon) ; //If fail return error if (!success5) return new TradeToken (null, 0) ; //Add credit card payment success5 = trIn5.AddToDB (dbCon) ; //If fail, rollback withdrawal and return error if (!success5) { int del = stmt.executeUpdate ("DELETE FROM tbl_Transactions " + "WHERE ( TransID = " + trOut5.GetID () + " )") ; return new TradeToken (null, 0) ; } //Save results retToken = new TradeToken (null, 1) ; break ; case 6: //Request Account Transactions - Returns Transaction array //Read object RequestTransactions rqTs = (RequestTransactions) incToken.getData () ; //Authenticate if (!rqTs.GetStatus ()) return new TradeToken () ; //Check if user (customer) is account holder if (rqTs.GetCustomer () != DBUtilities.GetCustomer ( rqTs.GetUser (), dbCon)) return new TradeToken () ; //Count Transactions in time window and check if any exist String outst = "SELECT COUNT(*) FROM tbl_Transactions " + "WHERE (TransDate > CONVERT(DATETIME, '" + rqTs.GetFromDate () + "', 102) AND TransDate < CONVERT(DATETIME, '" + rqTs.GetToDate () + "', 102)) AND ( Account = " + rqTs.GetAccount () + " )" ; rst = stmt.executeQuery (outst) ; if (rst.next ()) retLng = Integer.parseInt (rst.getString (1)) ; if (retLng == 0) return new TradeToken (null, 0) ; //Initialise array with known length Transaction[] trans = new Transaction[retLng] ; rst = stmt.executeQuery ("SELECT * FROM qry_Transactions " + "WHERE (TransDate > CONVERT(DATETIME, '" + rqTs.GetFromDate () + "', 102) AND TransDate < CONVERT(DATETIME, '" + rqTs.GetToDate () + "', 102)) AND ( Account = " + rqTs.GetAccount () + " )") ; rst.next () ; //Save Transactions to array for (int i = 0 ; i < retLng ; i++) { 188

SOURCE CODE Stathis Polyzos

Transaction tmpTrans = new Transaction () ; tmpTrans.SetID (Integer.parseInt (rst.getString (1))) ; tmpTrans.SetTransDate (rst.getString (2)) ; tmpTrans.SetAccount (rqTs.GetAccount ()) ; tmpTrans.SetType (Byte.parseByte (rst.getString (4))) ; tmpTrans.SetAmount (Double.parseDouble (rst.getString (5))) ; tmpTrans.SetComments (rst.getString (6)) ; trans[i] = tmpTrans ; rst.next () ; } //Save results retToken = new TradeToken (trans, retLng) ; break ; case 7: //GetAccount by number - Returns Account object //Read data GetAccount gtAcc = (GetAccount) incToken.getData () ; //Authenticate if (!gtAcc.GetStatus ()) return new TradeToken () ; Account acc = new Account () ; //Get resultset rst = stmt.executeQuery ("SELECT * FROM tbl_Accounts " + "WHERE ( AccountNumber = '" + gtAcc.GetAccountNo () + "' )") ; //Save object attributes if (rst.next ()) { acc.SetID (Integer.parseInt (rst.getString (1))) ; acc.SetAccountNumber (rst.getString (2)) ; acc.SetCustomer (Integer.parseInt (rst.getString (3))) ; acc.SetBalance (Double.parseDouble (rst.getString (4))) ; } else return new TradeToken (new Account (), -1) ; //Save resutls retToken = new TradeToken (acc, 0) ; break ; case 8: //Make Transaction - Returns Confirmation //Read data MakeTransaction mkTransc = (MakeTransaction) incToken.getData () ; //Authenticate if (!mkTransc.GetStatus ()) return new TradeToken () ; //Get Transaction Transaction trans8 = new Transaction (mkTransc.GetTransaction ()) ; boolean success8 = false ; 189

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


success8 = trans8.AddToDB (dbCon) ; //Add //If fail return error if (!success8) return new TradeToken (null, 0) ; //Save confirmation retToken = new TradeToken (null, 1) ; break ; case 9: //Make credit card payment - Returns Confirmation //Read data CreditCardPayment pCrCd = (CreditCardPayment) incToken.getData () ; //Authenticate if (!pCrCd.GetStatus ()) return new TradeToken () ; //Get Credit Card ID rst = stmt.executeQuery ("SELECT CreditCardID FROM " + "tbl_CreditCards WHERE Active = 1 AND CreditCardNo = '" + pCrCd.GetCreditCardNo () + "'") ; if (!rst.next ()) return new TradeToken (null, 0) ; int crID = Integer.parseInt (rst.getString (1)) ; //Read transaction and store credit card ID CreditCardTransaction cr = pCrCd.GetCrTransaction () ; cr.SetCreditCard (crID) ; //Add transaction boolean success9 = false ; success9 = cr.AddToDB (dbCon) ; //If fail return error if (!success9) return new TradeToken (null, 0) ; //Save confirmation retToken = new TradeToken (null, 1) ; break ; case 10: //Change Activation Status - return confirmation //Read data ChangeActivationStatus chActSt = (ChangeActivationStatus) incToken.getData () ; //Authenticate if (!chActSt.GetStatus ()) return new TradeToken () ; boolean success10 = false ; //If object is card if (chActSt.Card ()) { //Read card from database CreditCard cred = new CreditCard (dbCon, chActSt.GetUnique ()) ;

190

SOURCE CODE Stathis Polyzos

//Activate or suspend (deactivate) if (chActSt.Activate ()) success10 = cred.Activate (dbCon) ; else success10 = cred.Deactivate (dbCon) ; } else //Object is user { //Read user from database User usrL = new User (dbCon, chActSt.GetUnique ()) ; //Activate or suspend (deactivate) if (chActSt.Activate ()) success10 = usrL.ActivateUser (dbCon) ; else success10 = usrL.DeactivateUser (dbCon) ; } //Save results retToken = new TradeToken (null, (success10 ? 1 : 0)) ; break ; case 11: //Request Pin Change - returns confirmation //Read data RequestPinChange pinch = (RequestPinChange) incToken.getData () ; //Authenticate if (!pinch.GetStatus ()) return new TradeToken () ; //Read credit card object CreditCard cred = new CreditCard (dbCon, pinch.GetCardNo ()) ; //Change pin boolean success11 = cred.ChangePIN (dbCon, pinch.GetOldPin (), pinch.GetNewPin ()) ; //Save results retToken = new TradeToken (null, (success11 ? 1 : 0)) ; break ; case 12: //Request Customer - Returns Customer object //Read data RequestCustomer gtCus = (RequestCustomer) incToken.getData () ; //Authenticate if (!gtCus.GetStatus ()) return new TradeToken () ; //Read customer object and return it Customer cus = new Customer (dbCon, gtCus.GetID ()) ; retToken = new TradeToken (cus, 0) ; break ; case 13: //Request Employee - Returns Employee object //Read data RequestEmployee gtEmpl = (RequestEmployee) incToken.getData () ; 191

SUPERTRANS CUSTOMER TRANSACTION SYSTEM

//Authenticate if (!gtEmpl.GetStatus ()) return new TradeToken () ; //Read Employee object and return it Employee empl = new Employee (dbCon, gtEmpl.GetID ()) ; retToken = new TradeToken (empl, 0) ; break ; case 14: //Customer Data (Save or add Customer) - return confirmation //Read data CustomerData cd = (CustomerData) incToken.getData () ; //Authenticate if (!cd.GetStatus ()) return new TradeToken () ; //Get Customer object Customer cus14 = cd.GetCustomer () ; boolean success14 = false ; if (cd.GetActionType () == 1) //Add success14 = cus14.AddToDB (dbCon) ; else //Save success14 = cus14.SaveToDB (dbCon) ; //Save results retToken = new TradeToken (null, (success14 ? 1 : 0)) ; break ; case 15: //Employee Data (Save or add Employee) - return confirmation //Read data EmployeeData emp = (EmployeeData) incToken.getData () ; //Authenticate if (!emp.GetStatus ()) return new TradeToken () ; //Get Employee object Employee emp15 = emp.GetEmployee () ; boolean success15 = false ; if (emp.GetActionType () == 1) //Add success15 = emp15.AddToDB (dbCon) ; else //Save success15 = emp15.SaveToDB (dbCon) ; //Save results retToken = new TradeToken (null, (success15 ? 1 : 0)) ; break ; case 16: //Add Account - return confirmation or existing PUC account number //Read data AddAccount addAcc = (AddAccount) incToken.getData(); //Authenticate if (!addAcc.GetStatus()) 192

SOURCE CODE Stathis Polyzos

return new TradeToken(); //Get Account Account acc16 = addAcc.GetAccount(); //See if customer is PUC and has account String accNo16 = ""; rst = stmt.executeQuery ("SELECT AccountNumber FROM tbl_Customers " + "INNER JOIN tbl_Accounts ON CusID = Customer " + "WHERE (IsPubUtilComp = 1) AND (Customer = " + acc16.GetCustomer() + ")"); if (rst.next ()) accNo16 = rst.getString (1) ; //If PUC customer has account return account number with error code 2 if (!accNo16.equals("")) return new TradeToken (accNo16, 2) ; //Add to DB boolean success16 = acc16.AddToDB(dbCon); //Save results retToken = new TradeToken (null, (success16 ? 1 : 0)) ; break ; case 17: //Add User - return confirmation or existing username //Read data AddUser addUsr = (AddUser) incToken.getData () ; //Authenticate if (!addUsr.GetStatus ()) return new TradeToken () ; //Get User User usr17 = addUsr.GetUser () ; //See if employee or customer has user name and, if so, get that name String usrName = ""; String whereCond = (usr17.GetEmployeeID () == 0 ? "WHERE CustomerID = " + usr17.GetCustomerID () : "WHERE EmployeeID = " + usr17.GetEmployeeID ()) ; rst = stmt.executeQuery ("SELECT UserID FROM tbl_UserAccess " + whereCond) ; if (rst.next()) usrName = rst.getString(1); //If username exists, return it with error code 2 if (!usrName.equals("")) return new TradeToken(usrName, 2); //Add to DB boolean success17 = usr17.AddToDB (dbCon) ; //Save results retToken = new TradeToken (null, (success17 ? 1 : 0)) ; break; case 18: //Add Credit Card - return confirmation or No of Credit Cards //Read data 193

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


AddCreditCard addCC = (AddCreditCard) incToken.getData () ; //Authenticate if (!addCC.GetStatus ()) return new TradeToken () ; //Get User CreditCard cc18 = addCC.GetCreditCard () ; //See if customer has three credit cards rst = stmt.executeQuery("SELECT Count(*) FROM tbl_CreditCards " + "WHERE Customer = " + cc18.GetCustomer()); if (rst.next()) retLng = Integer.parseInt(rst.getString(1)); //If customer already has more than 2 cards, return error with code 2 if (retLng > 2) return new TradeToken(retLng, 2); //Add to DB boolean success18 = cc18.AddToDB (dbCon) ; //Save results retToken = new TradeToken (null, (success18 ? 1 : 0)) ; break; default: break ; } //Return new object with results return retToken ; } }

194

TRADETOKEN CONTENTS & RETURN TYPES Stathis Polyzos

APPENDIX G. TRADETOKEN CONTENTS & RETURN TYPES


Returns
object (type)

Switch
-1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

Object Class
Empty Token LoginUser LoginStatus UserID MakeTransfer MakeTransferToCredit RequestTransactions GetAccount MakeTransaction CreditCardPayment ChangeActivationStatus RequestPinChange RequestCustomer RequestEmployee CustomerData EmployeeData AddAccount AddUser AddCreditCard

ActionTypes 1 2

LoginStatus

See separate table null (Confirmation) null (Confirmation) Transaction[] (length) Account (0) null (Confirmation) null (Confirmation) null (Confirmation) null (Confirmation) Customer (0) Employee (0) Add null (Confirmation) Add null (Confirmation) null (Confirmation) null (Confirmation) null (Confirmation) Save null (Confirmation) Save null (Confirmation)

195

SUPERTRANS CUSTOMER TRANSACTION SYSTEM

UserID Objects Action Type


1 2 3 4 5 6 7 8 9

Returns
object (type)

User's Accounts Account[] (length) PUC Accounts, Account[] (length) Customer Name String (0) User's Credit Cards CreditCard[] (length) User Level null (level) Customer ID List int[] (length) Employee ID List int[] (length) All CreditCard Numbers String[] (length) All Customer UserNames String[] (length)

196

DATABASE SQL CODE Stathis Polyzos

APPENDIX H. DATABASE SQL CODE


H.1. Database

USE [master] GO CREATE DATABASE [DORBank] ON PRIMARY ( NAME = N'StathisBank_Data', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL\Data\StathisBank_Data.MDF' , SIZE = 2432KB , MAXSIZE = UNLIMITED, FILEGROWTH = 10%) LOG ON ( NAME = N'StathisBank_Log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL\Data\StathisBank_Log.LDF' , SIZE = 4224KB , MAXSIZE = UNLIMITED, FILEGROWTH = 10%) COLLATE Greek_CI_AS GO EXEC dbo.sp_dbcmptlevel @dbname=N'DORBank', @new_cmptlevel=80 GO IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled')) begin EXEC [DORBank].[dbo].[sp_fulltext_database] @action = 'disable' end GO ALTER DATABASE [DORBank] SET ANSI_NULL_DEFAULT OFF GO ALTER DATABASE [DORBank] SET ANSI_NULLS OFF GO ALTER DATABASE [DORBank] SET ANSI_PADDING OFF GO ALTER DATABASE [DORBank] SET ANSI_WARNINGS OFF GO ALTER DATABASE [DORBank] SET ARITHABORT OFF GO ALTER DATABASE [DORBank] SET AUTO_CLOSE OFF GO ALTER DATABASE [DORBank] SET AUTO_CREATE_STATISTICS ON GO ALTER DATABASE [DORBank] SET AUTO_SHRINK ON GO ALTER DATABASE [DORBank] SET AUTO_UPDATE_STATISTICS ON GO ALTER DATABASE [DORBank] SET CURSOR_CLOSE_ON_COMMIT OFF GO ALTER DATABASE [DORBank] SET CURSOR_DEFAULT GLOBAL GO ALTER DATABASE [DORBank] SET CONCAT_NULL_YIELDS_NULL OFF GO ALTER DATABASE [DORBank] SET NUMERIC_ROUNDABORT OFF GO ALTER DATABASE [DORBank] SET QUOTED_IDENTIFIER OFF GO ALTER DATABASE [DORBank] SET RECURSIVE_TRIGGERS OFF GO ALTER DATABASE [DORBank] SET ENABLE_BROKER GO ALTER DATABASE [DORBank] SET AUTO_UPDATE_STATISTICS_ASYNC OFF GO ALTER DATABASE [DORBank] SET DATE_CORRELATION_OPTIMIZATION OFF GO ALTER DATABASE [DORBank] SET TRUSTWORTHY OFF 197

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


GO ALTER GO ALTER GO ALTER GO ALTER GO ALTER GO ALTER GO ALTER

DATABASE [DORBank] SET ALLOW_SNAPSHOT_ISOLATION OFF DATABASE [DORBank] SET PARAMETERIZATION SIMPLE DATABASE [DORBank] SET READ_WRITE

DATABASE [DORBank] SET RECOVERY SIMPLE DATABASE [DORBank] SET MULTI_USER

DATABASE [DORBank] SET PAGE_VERIFY TORN_PAGE_DETECTION DATABASE [DORBank] SET DB_CHAINING OFF

USE [DORBank] GO CREATE USER [bankAdmin] FOR LOGIN [bankAdmin] WITH DEFAULT_SCHEMA=[bankAdmin]

198

DATABASE SQL CODE Stathis Polyzos

H.2.

Tables & Views

USE [DORBank] GO /****** Object: Table [dbo].[tbl_Accounts] Script Date: 02/05/2006 19:50:23 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[tbl_Accounts]( [AccountID] [int] IDENTITY(1,1) NOT NULL, [AccountNumber] [char](8) COLLATE Greek_CI_AS NOT NULL, [Customer] [int] NOT NULL, [Balance] [float] NOT NULL CONSTRAINT [DF_tbl_Accounts_Balance] DEFAULT (0), [RegDate] [smalldatetime] NOT NULL CONSTRAINT [DF_tbl_Accounts_RegDate] DEFAULT (getdate()), CONSTRAINT [PK_tbl_Accounts] PRIMARY KEY CLUSTERED ( [AccountID] ASC )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO /****** Object: Table [dbo].[tbl_CreditCards] Script Date: 02/05/2006 19:50:24 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[tbl_CreditCards]( [CreditCardID] [int] IDENTITY(1,1) NOT NULL, [Customer] [int] NOT NULL, [CreditCardNo] [char](16) COLLATE Greek_CI_AS NOT NULL, [PIN] [char](4) COLLATE Greek_CI_AS NOT NULL, [CreditLimit] [float] NOT NULL CONSTRAINT [DF_tbl_CreditCards_CreditLimit] DEFAULT (0), [Active] [bit] NOT NULL CONSTRAINT [DF_tbl_CreditCards_Active] DEFAULT (1), [RegDate] [smalldatetime] NOT NULL CONSTRAINT [DF_tbl_CreditCards_RegDate] DEFAULT (getdate()), CONSTRAINT [PK_tbl_CreditCards] PRIMARY KEY CLUSTERED ( [CreditCardID] ASC )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY], CONSTRAINT [IX_tbl_CreditCards] UNIQUE NONCLUSTERED ( [CreditCardNo] ASC )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO /****** Object: Table [dbo].[tbl_CreditCardTransactions] 02/05/2006 19:50:24 ******/

Script Date:

199

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[tbl_CreditCardTransactions]( [CCTrID] [int] IDENTITY(1,1) NOT NULL, [TransDate] [smalldatetime] NOT NULL CONSTRAINT [DF_tbl_CreditCardTransactions_TransDate] DEFAULT (getdate()), [CreditCard] [int] NOT NULL, [Type] [smallint] NOT NULL, [Amount] [float] NOT NULL, [Comments] [nvarchar](150) COLLATE Greek_CI_AS NULL, CONSTRAINT [PK_tbl_CreditCardTransactions] PRIMARY KEY CLUSTERED ( [CCTrID] ASC )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[tbl_Customers] Script Date: 02/05/2006 19:50:24 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[tbl_Customers]( [CusID] [int] IDENTITY(1,1) NOT NULL, [CustomerName] [nvarchar](150) COLLATE Greek_CI_AS NOT NULL, [Address] [nvarchar](100) COLLATE Greek_CI_AS NULL, [City] [nvarchar](50) COLLATE Greek_CI_AS NULL, [ZipCode] [nvarchar](50) COLLATE Greek_CI_AS NULL, [PhoneNo] [nvarchar](50) COLLATE Greek_CI_AS NULL, [IsPubUtilComp] [bit] NOT NULL CONSTRAINT [DF_tbl_Customers_IsPubUtilComp] DEFAULT (0), [RegDate] [smalldatetime] NOT NULL CONSTRAINT [DF_tbl_Customers_RegDate] DEFAULT (getdate()), CONSTRAINT [PK_tbl_Customers] PRIMARY KEY CLUSTERED ( [CusID] ASC )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[tbl_Employees] Script Date: 02/05/2006 19:50:24 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[tbl_Employees]( [EmplID] [int] IDENTITY(1,1) NOT NULL, [IdentityNo] [nvarchar](15) COLLATE Greek_CI_AS NOT NULL, [FullName] [nvarchar](150) COLLATE Greek_CI_AS NOT NULL, [Address] [nvarchar](100) COLLATE Greek_CI_AS NULL, [PhoneNo] [nvarchar](50) COLLATE Greek_CI_AS NULL, [City] [nvarchar](50) COLLATE Greek_CI_AS NULL, [ZipCode] [nvarchar](10) COLLATE Greek_CI_AS NULL, [Sex] [bit] NOT NULL CONSTRAINT [DF_tbl_Employees_Sex] DEFAULT (1), [Active] [bit] NOT NULL CONSTRAINT [DF_tbl_Employees_Active] DEFAULT (0), [DateHired] [smalldatetime] NULL, [DelDate] [smalldatetime] NULL, 200

DATABASE SQL CODE Stathis Polyzos

[TaxationNo] [nvarchar](10) COLLATE Greek_CI_AS NOT NULL, [RegDate] [smalldatetime] NOT NULL CONSTRAINT [DF_tbl_Employees_RegDate] (getdate()), CONSTRAINT [PK_tbl_Employees] PRIMARY KEY CLUSTERED ( [EmplID] ASC )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY], CONSTRAINT [IX_tbl_Employees] UNIQUE NONCLUSTERED ( [IdentityNo] ASC )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY], CONSTRAINT [IX_tbl_Employees_1] UNIQUE NONCLUSTERED ( [TaxationNo] ASC )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY]

DEFAULT

GO /****** Object: Table [dbo].[tbl_Transactions] Script Date: 02/05/2006 19:50:24 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[tbl_Transactions]( [TransID] [int] IDENTITY(1,1) NOT NULL, [TransDate] [smalldatetime] NOT NULL CONSTRAINT [DF_tbl_Transactions_TransDate] DEFAULT (getdate()), [Account] [int] NOT NULL, [Type] [smallint] NOT NULL, [Amount] [float] NOT NULL, [Comments] [nvarchar](200) COLLATE Greek_CI_AS NULL, CONSTRAINT [PK_tbl_Transactions] PRIMARY KEY CLUSTERED ( [TransID] ASC )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[tbl_UserAccess] Script Date: 02/05/2006 19:50:24 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[tbl_UserAccess]( [UserID] [int] IDENTITY(1,1) NOT NULL, [UserName] [char](20) COLLATE Greek_CI_AS NOT NULL, [Password] [char](20) COLLATE Greek_CI_AS NULL, [AccessLevel] [int] NOT NULL CONSTRAINT [DF_tbl_UserAccess_CentralConsole] DEFAULT (0), [EmployeeID] [int] NOT NULL CONSTRAINT [DF_tbl_UserAccess_EmployeeID] DEFAULT (0), [CustomerID] [int] NOT NULL CONSTRAINT [DF_tbl_UserAccess_CustomerID] DEFAULT (0), [Active] [bit] NOT NULL CONSTRAINT [DF_tbl_UserAccess_Active] DEFAULT (1), [RegDate] [smalldatetime] NOT NULL CONSTRAINT [DF_tbl_UserAccess_RegDate] DEFAULT (getdate()), CONSTRAINT [PK_tbl_UserAccess] PRIMARY KEY CLUSTERED ( [UserID] ASC 201

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY], CONSTRAINT [IX_tbl_UserAccess_1] UNIQUE NONCLUSTERED ( [UserName] ASC )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO USE [DORBank] GO USE [DORBank] GO USE [DORBank] GO USE [DORBank] GO USE [DORBank] GO ALTER TABLE [dbo].[tbl_Accounts] WITH NOCHECK ADD CONSTRAINT [FK_tbl_Accounts_tbl_Customers] FOREIGN KEY([Customer]) REFERENCES [dbo].[tbl_Customers] ([CusID]) ON UPDATE CASCADE ON DELETE CASCADE GO ALTER TABLE [dbo].[tbl_Accounts] CHECK CONSTRAINT [FK_tbl_Accounts_tbl_Customers] GO ALTER TABLE [dbo].[tbl_CreditCards] WITH NOCHECK ADD CONSTRAINT [FK_tbl_CreditCards_tbl_Customers] FOREIGN KEY([Customer]) REFERENCES [dbo].[tbl_Customers] ([CusID]) ON UPDATE CASCADE ON DELETE CASCADE GO ALTER TABLE [dbo].[tbl_CreditCards] CHECK CONSTRAINT [FK_tbl_CreditCards_tbl_Customers] GO ALTER TABLE [dbo].[tbl_CreditCards] WITH NOCHECK ADD CONSTRAINT [CK_tbl_CreditCardsLimit] CHECK (([CreditLimit] >= 0)) GO ALTER TABLE [dbo].[tbl_CreditCards] CHECK CONSTRAINT [CK_tbl_CreditCardsLimit] GO ALTER TABLE [dbo].[tbl_CreditCardTransactions] WITH NOCHECK ADD CONSTRAINT [FK_tbl_CreditCardTransactions_tbl_CreditCards] FOREIGN KEY([CreditCard]) REFERENCES [dbo].[tbl_CreditCards] ([CreditCardID]) ON UPDATE CASCADE ON DELETE CASCADE GO ALTER TABLE [dbo].[tbl_CreditCardTransactions] CHECK CONSTRAINT [FK_tbl_CreditCardTransactions_tbl_CreditCards] GO ALTER TABLE [dbo].[tbl_CreditCardTransactions] WITH CHECK ADD CONSTRAINT [CK_tbl_CreditCardTransactionsAmt] CHECK (([Amount] > 0)) GO ALTER TABLE [dbo].[tbl_CreditCardTransactions] WITH CHECK ADD CONSTRAINT [CK_tbl_CreditCardTransactionsType] CHECK (([Type] = 1 or [Type] = 2)) GO ALTER TABLE [dbo].[tbl_Transactions] WITH NOCHECK ADD CONSTRAINT [FK_tbl_Transactions_tbl_Accounts] FOREIGN KEY([Account]) REFERENCES [dbo].[tbl_Accounts] ([AccountID]) ON UPDATE CASCADE 202

DATABASE SQL CODE Stathis Polyzos

ON DELETE CASCADE GO ALTER TABLE [dbo].[tbl_Transactions] CHECK CONSTRAINT [FK_tbl_Transactions_tbl_Accounts] GO ALTER TABLE [dbo].[tbl_Transactions] WITH NOCHECK ADD CONSTRAINT [CK_tbl_TransactionsAmount] CHECK (([Amount] > 0)) GO ALTER TABLE [dbo].[tbl_Transactions] CHECK CONSTRAINT [CK_tbl_TransactionsAmount] GO ALTER TABLE [dbo].[tbl_Transactions] WITH NOCHECK ADD CONSTRAINT [CK_tbl_TransactionsType] CHECK (([Type] = 1 or [Type] = 2)) GO ALTER TABLE [dbo].[tbl_Transactions] CHECK CONSTRAINT [CK_tbl_TransactionsType] GO ALTER TABLE [dbo].[tbl_UserAccess] WITH NOCHECK ADD CONSTRAINT [FK_tbl_UserAccess_tbl_Customers] FOREIGN KEY([CustomerID]) REFERENCES [dbo].[tbl_Customers] ([CusID]) GO ALTER TABLE [dbo].[tbl_UserAccess] WITH NOCHECK ADD CONSTRAINT [FK_tbl_UserAccess_tbl_Employees] FOREIGN KEY([EmployeeID]) REFERENCES [dbo].[tbl_Employees] ([EmplID]) GO ALTER TABLE [dbo].[tbl_UserAccess] WITH NOCHECK ADD CONSTRAINT [CK_tbl_UserAccessCustomer] CHECK ((((not(isnull([CustomerID],0) = 0 and [AccessLevel] = 3))))) GO ALTER TABLE [dbo].[tbl_UserAccess] CHECK CONSTRAINT [CK_tbl_UserAccessCustomer] GO ALTER TABLE [dbo].[tbl_UserAccess] WITH NOCHECK ADD CONSTRAINT [CK_tbl_UserAccessEmpl] CHECK ((((not(isnull([EmployeeID],0) = 0 and ([AccessLevel] = 1 or [AccessLevel] = 2)))))) GO ALTER TABLE [dbo].[tbl_UserAccess] CHECK CONSTRAINT [CK_tbl_UserAccessEmpl] GO ALTER TABLE [dbo].[tbl_UserAccess] WITH NOCHECK ADD CONSTRAINT [CK_tbl_UserAccessGenLevel] CHECK (([AccessLevel] > 0 and [AccessLevel] < 4)) GO ALTER TABLE [dbo].[tbl_UserAccess] CHECK CONSTRAINT [CK_tbl_UserAccessGenLevel] GO ALTER TABLE [dbo].[tbl_UserAccess] WITH NOCHECK ADD CONSTRAINT [CK_tbl_UserAccessUser] CHECK ((((not(isnull([EmployeeID],0) = 0 and isnull([CustomerID],0) = 0))))) GO ALTER TABLE [dbo].[tbl_UserAccess] CHECK CONSTRAINT [CK_tbl_UserAccessUser] USE [DORBank] GO /****** Object: View [dbo].[qry_AccountBalances] Script Date: 02/05/2006 19:51:01 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE VIEW [dbo].[qry_AccountBalances] AS SELECT dbo.tbl_Accounts.AccountID AS Account, SUM(ISNULL(CAST((CASE WHEN Type = 2 THEN Amount ELSE (Amount * (- 1)) END) AS float), 0)) AS Balance FROM dbo.tbl_Transactions RIGHT OUTER JOIN 203

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


dbo.tbl_Accounts ON dbo.tbl_Transactions.Account = dbo.tbl_Accounts.AccountID GROUP BY dbo.tbl_Accounts.AccountID GO /****** Object: View [dbo].[qry_CreditCardBalances] Script Date: 02/05/2006 19:51:01 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE VIEW [dbo].[qry_CreditCardBalances] AS SELECT dbo.tbl_CreditCards.CreditCardID, dbo.tbl_CreditCards.CreditLimit, SUM(CAST(ISNULL((CASE WHEN Type = 1 THEN Amount ELSE (Amount * (- 1)) END), 0) AS float)) AS Balance, dbo.tbl_CreditCards.CreditLimit + SUM(CAST(ISNULL((CASE WHEN Type = 1 THEN Amount ELSE (Amount * (- 1)) END), 0) AS float)) AS Remaining FROM dbo.tbl_CreditCards LEFT OUTER JOIN dbo.tbl_CreditCardTransactions ON dbo.tbl_CreditCards.CreditCardID = dbo.tbl_CreditCardTransactions.CreditCard GROUP BY dbo.tbl_CreditCards.CreditCardID, dbo.tbl_CreditCards.CreditLimit GO /****** Object: View [dbo].[qry_PublicUtilityAccounts] Script Date: 02/05/2006 19:51:01 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE VIEW [dbo].[qry_PublicUtilityAccounts] AS SELECT dbo.tbl_Accounts.AccountID, dbo.tbl_Accounts.AccountNumber, dbo.tbl_Customers.CustomerName, dbo.tbl_Accounts.Customer, dbo.tbl_Accounts.Balance, dbo.tbl_Accounts.RegDate FROM dbo.tbl_Accounts INNER JOIN dbo.tbl_Customers ON dbo.tbl_Accounts.Customer = dbo.tbl_Customers.CusID WHERE (dbo.tbl_Customers.IsPubUtilComp = 1) GO /****** Object: View [dbo].[qry_Transactions] Script Date: 02/05/2006 19:51:01 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE VIEW [dbo].[qry_Transactions] AS SELECT TransID, CAST(DAY(TransDate) AS nvarchar(2)) + '/' + CAST(MONTH(TransDate) AS nvarchar(2)) + '/' + CAST(YEAR(TransDate) AS nvarchar(4)) AS [Date], Account, Type, Amount, Comments, TransDate FROM dbo.tbl_Transactions GO

204

DATABASE DIAGRAM Stathis Polyzos

APPENDIX I.

DATABASE DIAGRAM

205

SUPERTRANS CUSTOMER TRANSACTION SYSTEM

APPENDIX J.
J.1.

REQUIRED DEMO SCREENSHOTS

Cash Deposit

206

REQUIRED DEMO SCREENSHOTS Stathis Polyzos

J.2.

Cash Withdrawa

207

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


J.3. Insufficient Funds on Credit Card Payment

208

APPLICATION SCREENSHOTS Stathis Polyzos

APPENDIX K. APPLICATION SCREENSHOTS


K.1. Server

209

SUPERTRANS CUSTOMER TRANSACTION SYSTEM


K.2. Staff

210

APPLICATION SCREENSHOTS Stathis Polyzos

211

SUPERTRANS CUSTOMER TRANSACTION SYSTEM

212

APPLICATION SCREENSHOTS Stathis Polyzos

K.3.

Customer

213

SUPERTRANS CUSTOMER TRANSACTION SYSTEM

214

VISUAL PARADIGM SCREENSHOTS Stathis Polyzos

APPENDIX L.

VISUAL PARADIGM SCREENSHOTS

215

SUPERTRANS CUSTOMER TRANSACTION SYSTEM

APPENDIX M. JBUILDER SCREENSHOTS

216

JBUILDER SCREENSHOTS Stathis Polyzos

217

SUPERTRANS CUSTOMER TRANSACTION SYSTEM

APPENDIX N. MS SQL SERVER 2005 SCREENSHOTS

218

MS SQL SERVER 2005 SCREENSHOTS Stathis Polyzos

219

SUPERTRANS CUSTOMER TRANSACTION SYSTEM

REFERENCES BIBLIOGRAPHY
Google Search Engine http://www.google.com Agile Modeling http://www.agilemodeling.com/artifacts/systemUseCase.htm Accessed on 5 February 2006 Borland JBuilder 2006 Local Help Coulouris G., et al, Distributed Systems: Concepts & Design, 4th Edition, Addison Wesley, 2005 Deitel, et al, Java How To Program, Electronic Version Fowler M, UML Distilled, 3rd Edition, Addison Wesley, 2003 Singleton Pattern from CodeProject.com http://www.codeproject.com/csharp/SingletonForms.asp Accessed on 9 December 2005

220