The first step in designing the components of this application is to look at the way that the permanent data for the application will be stored. For this example, our data will be stored in a SQL Server database. There will be three tables in this database. In a real banking application, the data would be much more complex. Since the example application is solving only one part of the problem, we will use a considerably less complex database.
The first table is the
table. This table will have information about each customer, including their name, address, and phone number. Each customer will have a unique customer CUSTOMER
, which will be used to identify all of the customer's information stored throughout the system. The structure of the ID
table is:CUSTOMER
Field Name | Type | Size |
CustomerID | Int | |
Name | Char | 50 |
StreetAddr | Char | 50 |
City | Char | 40 |
State | Char | 20 |
PostalCode | Char | 20 |
PhoneNumber | Char | 30 |
The next table that will be used in our example is the
table. This table will have information about each account that the bank has. This account information will be the account number, which will serve as the primary key of the table. The table will also have a field for the customer that owns the account. This field will have a foreign key from the ACCOUNT
table. The table will also have the current balance of the account, as well as the date and time of the last transaction. The structure of the CUSTOMER
table is:ACCOUNT
Field Name | Type | Size |
AccountNumber | Int | |
CustomerID | Int | |
Balance | Money | |
LastTransaction | Datetime |
The third table in the bank's database will be the
table. This table will contain a record of all transactions that occur at the bank. There will be a unique TRANSREC
field that will serve as the primary key for the table. The value of this field will be automatically generated when the record is created. There will be a field that identifies the transaction type. In the case that the example is covering, there is only one transaction type, account transfer. This will be indicated by a value of ID
in this field. There will be fields that identify the detail data of the transaction, which includes the account numbers of the source and destination accounts, as well as the amount transferred. The record will also have a field that indicates the date and time that the transaction took place. The structure of the TRANS
table is:TRANSREC
Field Name | Type | Size |
TransactionID | Int | |
TransactionType | Char | 5 |
SourceAccount | Int | |
DestinationAccount | Int | |
Amount | Money | |
TransTime | Datetime |
Now that we have designed the database tables that will hold the information, we need to create a set of application components that will have methods that let the application process the information to support the problem. If we review the steps that the application will follow to perform the transfer, we can begin to identify methods that will need to be created. Remember, in this example, the user has already been identified and verified.
TRANSREC
table.By examining these steps, we can begin to identify the types of methods that our application components will need to perform.
There will need to be a component that allows the user to select an account. We can divide our application logic between ASP script and the COM components that will run on the server. To allow the user to select an account, we need to present a list of all possible accounts. This implies that there is a method that returns a list of accounts for a given customer. The next method that we need will ensure that the source account has sufficient funds to transfer. This method will accept as input the source account number and the amount and return true if there is sufficient funds to transfer.
Next, we will need a method to withdraw money from an account. This method should take an account number and amount as parameters. Since this part of the application will be running inside of a transaction, the method should abort the transaction if it is unable to remove the money from the account. Once the money is withdrawn, we will need a method to deposit money into an account. This method will also take the account number and amount as parameters. As with the withdrawal method, this method should abort the transaction if it is unable to deposit the amount.
The final method that we will need is to log the transaction into the
table. This method should accept as parameters all of the fields of the transaction table, except the timestamp, which it can generate internally. This method should return a true or false, depending on if it is able to successful update the database tableTRANSREC