Component-Oriented
Design and Process Solutions
www.componentware.net
.NET Enterprise Services Transactions
This project contains existing server and client projects, simulation bank accounts transactions. To use it, you need to create the bank database.
Create a SQL Server Database
Create a database, which will contain a table of Bank Accounts. Bring up the SQL server explorer: Start | Programs | Microsoft SQL Server | Enterprise Manager:
Expand Microsoft SQL Servers and the server group to see the databases:
Right-click on Databases, select “New Database…”
Name: Bank Account System
Press OK
Next, create the accounts table:
Right-click on the Tables folder in the bank DB, and select New Table…
Add the Number, Balance and Name columns, of types int, money and varchar.
Make the Number column the key, and disallow Nulls for it. Name the table “BankAccounts”.
Adding Accounts
In the SQL Enterprise Manager verify the table is there (may have to refresh - F5):
Open the table, and return all rows, by selecting in the BankAccounts table context menu Open Table | Return all rows
You should get an empty table, like this:
Add two new accounts, numbered 123 and 456. Set initial balance of 500 in each, and name them after yourself and your spouse (or pet):
Using the Bank Application
Open up the BankAccountServer.sln solution file. Build both the server and the client to make sure all is well. The server contains the Account and AccountMgr components. The Account component implements the IAccount interface, used to credit or debit an account.
The Account component uses ADO.NET to credit or debit an account. The only business logic applied is in rejecting debiting an account with insufficient balance (throwing an exception).
The AccountMgr component implements the IAccountMgr interface, used to transfer money between accounts.
AccountMgr creates one account object to represent the credit account, a second account object to represent the debit account, and calls IAccount.Creadit() and IAccount.Debit() on them respectively.
Here is the architecture of the bank application and the client:
Use the client to invoke the transfer, and pass 100 from account 123 to account 456. The client contains a data grid reflecting your transfer actions:
Experiments
Try performing a transfer when one of the two accounts doesn't exist: For example, suppose only the destination account number is valid.
Similarly, try a transfer, with an amount greater than the source account balance. Note, that the destination account is credited.
IDesign Inc. www.componentware.net October 2001
- 8 -
©2001 IDesign Inc. All rights reserved