Beruflich Dokumente
Kultur Dokumente
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
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
8 9
10 11
3.5
3.5.1 3.5.2
UTILITIES
CLIENT UTILITIES DATABASE UTILITIES
14
14 15
4.
15 15 17
17 17 17 17 17 17 17
4.3
SYSTEM CRITIQUE
18
i
5.
18 21 21 22 23 23
23 23 23 23 24 24 24 24 24 25 25 25 25 26 26 26
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
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
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
169 172
F.5.
SERVERPACK
173
173 177 179
195 197 197 199 205 206 206 207 208 209 209 210 213 215 216 218 220
CASH DEPOSIT CASH WITHDRAWA INSUFFICIENT FUNDS ON CREDIT CARD PAYMENT APPLICATION SCREENSHOTS
SERVER STAFF CUSTOMER VISUAL PARADIGM SCREENSHOTS JBUILDER SCREENSHOTS MS SQL SERVER 2005 SCREENSHOTS
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
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.
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
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
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
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.
* 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.
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
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
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.
scenario given was quite general and did not propose particular functional 15
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
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
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
21
22
23
24
.
3. 4. 5. 6.
25
26
B.2.
Full Description
POSTCONDITIONS
1. User can use new PIN for given card
27
POSTCONDITIONS
1. Money is available in target account
28
APPENDIX C.
CLASS DIAGRAM
29
30
APPENDIX E.
31
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
{ 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
34
//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
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
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
38
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
40
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
/** * 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
44
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
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
48
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
(this))
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
//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
* @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
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
56
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
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
/** * 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
} 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
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
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
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
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
70
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
72
//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
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
} 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
/** * 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
"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
78
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
/** * 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
82
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
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)
//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
87
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
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
90
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
92
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
/** * 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
96
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
* @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
{ 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
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
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
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
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
106
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
* @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
adaptee.txtMoney_focusLost (focusEvent) ; } }
111
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 ; }
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
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
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
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
{ 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
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
; 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
{ 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
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
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
126
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
128
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
130
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
132
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
134
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
136
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
138
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
140
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
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
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
144
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
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
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
148
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
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
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
152
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
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
156
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
158
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
160
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
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
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
{ 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
/** * 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
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
168
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
171
172
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
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
176
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
178
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
* 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
//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
{ 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
184
//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
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
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
190
//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
//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
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
194
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
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
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
DATABASE [DORBank] SET ALLOW_SNAPSHOT_ISOLATION OFF DATABASE [DORBank] SET PARAMETERIZATION SIMPLE DATABASE [DORBank] SET READ_WRITE
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
H.2.
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
[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
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
204
APPENDIX I.
DATABASE DIAGRAM
205
APPENDIX J.
J.1.
Cash Deposit
206
J.2.
Cash Withdrawa
207
208
209
210
211
212
K.3.
Customer
213
214
APPENDIX L.
215
216
217
218
219
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