Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Microsoft Visual C++ .NET Professional Projects - Premier Press

.pdf
Скачиваний:
168
Добавлен:
24.05.2014
Размер:
25.78 Mб
Скачать

180Project 1 DATABASE PROGRAMMING USING VC++.NET

Transfer. Users have to click on this button to handle transactions involving transfer of amounts both within and outside the branch. When you click on this button, the Transfer Account screen, shown in Figure 8-4, appears.

 

 

Y

 

L

 

F

 

M

 

E

 

T

 

 

FIGURE 8-4 The ransfer AccountAscreen

 

Commit. Users can click on this button to commit all pending transactions. This is typically used to handle all check-based transactions.

Figure 8-5 displays the menu designed for this application.

FIGURE 8-5 The main menu

The Reports menu is designed to hold the options for various kinds of reports that the branch generates, such as the Day-end Transactions report. The More option is provided to enable the addition of more reports to this menu.

Low-Level Design

During the low-level design phase, a detailed design of the various software modules is prepared using the high-level design. The team decides on the various standards, such as naming conventions for variables, controls, and forms for a project.

Team-Fly®

IMPLEMENTING DATA ACCESS TECHNOLOGIES

Chapter 8

181

 

 

 

All of these specifications are documented so that a consistency can be maintained among the various modules for an application. I will next discuss some of these specifications.

The Database Schema

As mentioned previously, Microsoft SQL Server 2000 is used as the back-end database for this project. The development team has decided upon the following database schema, shown in Figure 8-6. The name of the database designed is

Banking.

FIGURE 8-6 The schema for the Banking database

The database contains the following four tables:

Account_Detail. Stores all account-related details, such as account number, customer’s first and last name, date of birth, address, account type, and balance. Figure 8-7 displays the structure of the

Account_Detail table.

Transaction_Detail. Stores all transaction-related details, such as the transaction type, mode, date, amount, and status. Figure 8-8 displays the structure of the Transaction_Detail table.

182 Project 1 DATABASE PROGRAMMING USING VC++.NET

FIGURE 8-7 Structure of the Account_Detail table

FIGURE 8-8 Structure of the Transaction_Detail table

Check_Book. Stores details regarding the check books issued to the customers, such as the account number to which the check book is issued, the number of checks in the book, and the starting and ending check numbers. Figure 8-9 displays the structure of the Check_Book table.

FIGURE 8-9 Structure of the Check_Book table

IMPLEMENTING DATA ACCESS TECHNOLOGIES

Chapter 8

183

 

 

 

BankLogin. Stores the usernames and corresponding passwords. This table is used to validate the user who is trying to access the application. Figure 8-10 displays the structure of the BankLogin table.

FIGURE 8-10 Structure of the BankLogin table

The tables Account_Detail, Transaction_Detail, and Check_Book are related to

each other based on the field Account_Number. The Account_Number field is a primary key in the Account_Detail table and a foreign key in the Transac-

tion_Detail and Check_Book tables.

The BankLogin table is a stand-alone table because it is used to store the usernames and passwords of the users, and this information is not related to the information stored in other tables of the database.

Construction

During the construction phase, various components of the application are coded. The various specifications identified during the low-level design are used to accomplish this. In this project, you will code the banking application.

Integration and Testing

In the testing phase, various tests and validations are carried out on the various modules and their integration functionality is checked. In the SaveMyMoney Bank application, a single project will contain all the required classes that will handle the stated functionality. The code integrates all of these forms. Therefore, in this phase, all you need to do is to test whether the application is working fine. You will check out all validation checks that you have implemented and find the loopholes in the application and fix them. Typically, in this stage, you will try out all given options and check whether all the requirements collated initially are met.

184 Project 1 DATABASE PROGRAMMING USING VC++.NET

User Acceptance Test

In the acceptance phase, various tests are carried out based on the predefined acceptance criteria as given by the client. In addition, system support is provided to troubleshoot any issues or bugs identified in this phase. The SaveMyMoney Bank application is designed as a beta application; hence, it must be tested by the bankers in the New York office. Based on their feedback and suggestions, the application can be enhanced.

By now, you have a fair idea of the project requirements and are geared up to start building the application.

The Banking Application

Before you start coding the project, let me quickly list the steps that you need to perform to create this application:

1.Design the database in Microsoft SQL Server 2000.

2.Configure the ODBC data source for your database.

3.Create an SDI application with ODBC support.

4.Design the various screens of the application: main application screen, Login screen, Deposit/Withdrawal screen, and Transfer screen.

5.Design the main menu for the application’s main screen.

6.Add the required classes and code to provide the required functionality.

Creating the Banking Database

In this section, you will learn the steps to create the database and the required tables. To create a database, you need to perform the following steps:

1. Choose, Start, Programs, Microsoft SQL Server, Query Analyzer.

TIP

Alternatively, you can choose Start, Run, and type isqlw to invoke the SQL Query Analyzer.

IMPLEMENTING DATA ACCESS TECHNOLOGIES

Chapter 8

185

 

 

 

2.Log in to the server using the sa login. The SQL Query Analyzer window appears, as shown in Figure 8-11.

FIGURE 8-11 The SQL Query Analyzer window

3.The default database that is active is the “master” database. Type the following in the Query window (in the right pane):

create database Banking

4.Press F5 to execute the script. This will create a database named Banking in the server to which you are connected.

TIP

Alternatively, you can click on the Execute Query button on the toolbar.

5.On the toolbar, from the list, select Banking as the current database, as shown in Figure 8-12.

186 Project 1 DATABASE PROGRAMMING USING VC++.NET

FIGURE 8-12 The list of databases

Next, you will create the tables within the database. The following is the code for creating the required tables. You can type the complete listing in the query window and execute it as a single script file.

TIP

When you save the code in the Query window, a script is created. The extension of the file created is .sql.

create table BankLogin

(

UserNm varchar(5) not null,

Pwd varchar(15) not null

)

— Inserting values into the BankLogin table insert BankLogin

values(‘S103’,’password’)

create table Account_Detail

(

Account_Number int IDENTITY (10000,1) not null primary key,

First_Name varchar(30) not null,

Last_Name varchar(30) not null, date_birth varchar(10) not null, Permanent_Addr varchar(50) not null, Mailing_Addr varchar(50) not null, Phone_Number varchar(15) not null,

IMPLEMENTING DATA ACCESS TECHNOLOGIES

Chapter 8

187

 

 

 

eMailID varchar(30) null, Type_account char(1) not null, Balance float not null, Valid_Acc char(2) not null, Ref_Acc_No int not null

)

— Inserting values into the Account_Detail table

insert Account_Detail

values(‘Masine’,’Philip’,’09/09/72’,’Street V Opp. Great Circle’,’Bldg-11, Avenue 2’,’91-20392012’,’mph@pinc.com’,’S’,800,’VA’,0)

create table Check_Book

(

Tran_No int Identity(100,1) primary key,

Account_Number int not null constraint fk_AcctNumb foreign key references Account_Detail(Account_Number),

Number_of_Checks int not null,

Date_of_Issue char(10) not null,

Start_Check_Number int not null,

End_Check_Number int not null,

Hand_Over char(1) not null

)

— Inserting values into the Check_Book table insert Check_Book values(10000,20,’30/09/01’,1,20,’C’)

create table Transaction_Detail

(

TranId int identity(100,1) primary key,

Account_Number int not null constraint fk_AcctNum foreign key references Account_Detail(Account_Number),

Transaction_Mode char(3) not null,

Transaction_Type char(3) not null,

Transaction_Date char(10) not null,

Transaction_Amount float not null,

Check_Draft_Number int null,

To_Account int null,

188 Project 1 DATABASE PROGRAMMING USING VC++.NET

Creditor_Name varchar(30) null,

Creditor_BankName varchar(30) null,

Creditor_BankAddr varchar(50) null,

Transaction_Status char(1) not null

— You will enter values into this table through the front-end

)

TIP

You can use SQL Server Enterprise Manager, which provides an MMC (Microsoft Management Console) based interface, to graphically design the databases and tables.

After entering the preceding code, press F5 to execute it. You can click on the Messages tab to check whether the commands were executed successfully. Any error message will appear in this view.

You are now ready with the back-end database. For your front-end application to interact with this database, you need to create a data source that will provide the required ODBC support.

Configuring an ODBC Data Source

To configure an ODBC data source, you need to perform the following steps:

1.Choose Start, Settings, Control Panel.

2.Double-click Administrative Tools.

3.Double-click Data Sources (ODBC) to open the ODBC Data Source Administrator dialog box, shown in Figure 8-13.

4.Click on the Add button. The Create New Data Source dialog box, shown in Figure 8-14, appears.

5.Scroll down the list of drivers and select SQL Server.

6.Click on the Finish button. The Create a New Data Source to SQL Server dialog box appears, shown in Figure 8-15.

7.In the dialog box, specify the name and description of the data source to be created, and select the server that you are connecting to. Figure 8-15 shows the values to be specified.

IMPLEMENTING DATA ACCESS TECHNOLOGIES

Chapter 8

189

 

 

 

FIGURE 8-13 The ODBC Data Source Administrator dialog box

FIGURE 8-14 The Create New Data Source dialog box

CAUTION

Remember that your application will establish a connection with the Banking database by using the data source that you are creating here. The data source name that you specify here acts as the identifier of the database. While creating your application, you need to specify this name to connect with the required back-end database.