Implementing SCORM at Kids Training Team - Witchita State ...

treescattleΛογισμικό & κατασκευή λογ/κού

2 Νοε 2013 (πριν από 4 χρόνια και 7 μέρες)

117 εμφανίσεις






Implementation of a 3


Tier Web Application

f
or
Mobile Devices using Microsoft .NET platform









Rahil Kidwai

Department of Computer Science

Wichita State University













CS898T


Mobile

& Wireless

Networks

Dr. Chin
-
Chih Chang



1

Table of Co
ntents

1.0

Introduction

................................
................................
................................
........
2

2.0

Application Overview

................................
................................
........................
2

2.2.1

The Data Layer
................................
................................
............................

4

2.2.2

Application Layer

................................
................................
.......................

4

2.2.3

Presentation Layer
................................
................................
.......................

4

2.3.1

Microsoft .NET Framework
................................
................................
........

4

2.3.2

C# (CSharp)

................................
................................
................................

5

2.3.3

ASP.NET
................................
................................
................................
.....

5

2.3.4

SQLServer 2000 DBMS

................................
................................
.............

6

3.0

Implementation

................................
................................
................................
..
6

3.1.1

Database Schema

................................
................................
........................

6

3.1.2

Stored Procedures

................................
................................
.......................

7

3.1.3

‘dlStockTrade’ Class
................................
................................
...................

9

3.2.1

Class ‘Order’

................................
................................
.............................

12

3.2.2

Class ‘Portfolio’

................................
................................
........................

13

3.2.3

Class ‘Ticker’

................................
................................
............................

15

3.2.4

Class ‘blStockTrade’
................................
................................
.................

16

3.3.1

Login web page (code behind file)

................................
...........................

17

3.3.2

logout web page (code behind file)
................................
...........................

18

3.3.3

Main web page (code behind file)
................................
.............................

19

3.3.4

Portfolio web page (code behind file)
................................
.......................

19

3.3.5

Search web page (code behind file)

................................
..........................

20

3.3.6

Buysell web page (code behind file)
................................
.........................

21

3.3.7

‘Menu’ user control (code beh
ind file)

................................
.....................

22

3.4.1

‘Login’ web Page

................................
................................
......................

23

3.4.2

‘Main’ web Page

................................
................................
.......................

25

3.4.3

‘Search’ web Page
................................
................................
.....................

27

3.4.4

‘Buysell’ web Page

................................
................................
...................

28

3.4.5

Portfolio web Page

................................
................................
....................

31

4.0

References

................................
................................
................................
.........
32


List of Figures

F
igure 1

3


Tier Application Architecture

………………………………………
… 3

F
igure 2

Schema of the database

……………………………………………………..6

2.1

StockTrade
-

an MM
IT Application

................................
................................
...

2

2.2

Application Architecture
................................
................................
.....................

3

2.3

Technologies Used

................................
................................
..............................

4

3.1

Implementation of Data Layer

................................
................................
............

6

3.2

Implementation of Business Logic Layer

................................
.........................

12

3.3

Presentation Layer

(of website for normal users)

................................
.............

17

3.4

Presentation Layer Implementation (for mobile devices)
................................
.

23



2

1.0

Introduction

Over the past few years, the world has seen an explosion of new wireless devices, such as
cell phones, pagers, and personal digital assistants (PDAs), which enable users to browse
W
eb sites at any time from any location. Developing web applications for these devices is
challenging for the following reasons:



Different markup languages are necessary, including HTML for PDAs, wireless
markup language (WML) for wireless application prot
ocol (WAP) cell phones, and
compact HTML (cHTML) for Japanese i
-
mode phones.



Devices have different form factors. For example, devices have varying numbers of
display lines, horizontal or vertical screen orientation, and color or black and white
displays.




Devices have different network connectivity, ranging from 9.6 KB cellular
connections to 11 MB Wireless LANs.



Devices have different capabilities. Some devices can display images, some can make
phone calls, and some can receive notification messages.

T
he Microsoft Mobile Internet Toolkit addresses these challenges by isolating them from
the details of wireless development. Thus, developers can quickly and easily build a
single, mobile Web application that delivers appropriate markup for a wide variety o
f
mobile devices.

It has been very interesting and challenging project. I want to thank Dr
.

Chang for his
support for the completion of my project.


2.0

Application

Overview

2.1

StockTrade
-

an MMIT Application

This project is a real world application, a web sit
e which can be efficiently accessed
though mobile devices as well. Using this web site people will be able to monitor and
trade stocks from any where any time using their mobile devices provided their devices
have access to the internet.

StockTrade is a we
b application through which its users can
:



Login to their accounts,



T
rade stocks,



V
iew their portfolio,



Search for specific information, and



V
iew financial news.



3


2.2

Application Architecture

This web application is a 3
-
tier application. A 3
-
tier applicatio
n is an application program
that is organized into three major parts or layers, each of which is distributed to a
different place or places in a network. The three parts or layers are:



Client Layer or Presentation Layer



Application Layer



Data Layer or Dat
abase Layer




Figure 1 : 3


Tier Application Architecture



4

2.2.1

The Data Layer

The data layer consists of two separate layers. The first consists of

the set of stored
procedures implemented directly within the database. These stored procedures run on the
server and provide only basic data. Using stored procedures instead of embedding queries
directly in the web pages greatly improves performance as th
ey are pre
-
compiled, pre
-
optimized and separately tested.


The next layer consists of a set of classes which calls and handle the stored procedures.
These classes handle all requests to or from the actual database and provide a shield to
the application da
ta ensuring data integrity. Also this provides the only way to modify
data and no other source can modify data in the database in any way.

2.2.2

Application Layer

This layer is implemented in order to encapsulate business rules. Here I have
implemented some cla
sses to encapsulate the business functionality. They neither access
data (except through the data layer) nor do they bother with the display or presentation of
this data to the user. They only deal with the complexities of the business itself.

2.2.3

Presentatio
n Layer

This layer handles everything to do with the presentation of the system and includes all
the web pages of this application. This layer only interacts with the business layer.

The advantages of building application using 3
-
Tier Architecture are:

-

Ea
sy maintenance

-

Simplifies future enhancements

-

Code reuse

I have developed two versions of this application, one is for users connecting through
their desktop PCs or laptop systems and the other is for users connecting through their
mobile devices. The main

advantage is that I just have to change the presentation layer of
my application to allow for mobile devices. Both applications are using the same data and
application layer code.


2.3

Technologies Used

2.3.1

Microsoft .NET Framework

.NET (dot
-
net) is the name Micr
osoft gives to its general vision of the future of
computing, the view being of a world in which many applications run in a distributed
manner across the Internet. We can identify a number of different motivations driving
this vision.



5

Distributed computing

is rather like object oriented programming, in that it encourages
specialized code to be collected in one place, rather than copied redundantly in lots of
places. There are thus potential efficiency gains to be made in moving to the distributed
model.

By
collecting specialized code in one place and opening up a generally accessible
interface to it, different types of machines (phones, handhelds, desktops, etc.) can all be
supported with the same code. Hence Microsoft's 'run
-
anywhere' aspiration.

By control
ling real
-
time access to some of the distributed nodes (especially those
concerning authentication) companies like Microsoft can control more easily the running
of its applications. It moves applications further into the area of 'services provided' rather
than 'objects owned'.

Since Microsoft sees its future as providing software services in distributed applications,
the .NET framework has been written so that applications on other platforms will be able
to access these services. For example, .NET has been
built upon open standard
technologies like XML and SOAP.

At the development end of the .NET vision is the .NET Framework. This contains the
Common Language Runtime, the .NET Framework Classes, and higher
-
level features
like ASP.NET and WinForms.

The Common

Language Runtime (CLR) manages the execution of code compiled for the
.NET platform. The CLR has two interesting features. Firstly, its specification has been
opened up so that it can be ported to non
-
Windows platforms. Secondly, any number of
different l
anguages can be used to manipulate the .NET framework classes, and the CLR
will support them.

2.3.2

C# (CSharp)

Not all of the supported languages fit entirely neatly into the .NET framework, but one
language that is guaranteed to fit in perfectly is C#. This ne
w language, a successor to
C++, has been released in conjunction with the .NET framework, and is likely to be the
language of choice for many developers working on .NET applications.

2.3.3

ASP.NET

ASP.NET is a programming framework built on the common language r
untime that can
be used on a server to build powerful Web applications.
ASP.NET is compiled common
language runtime code running on the server. ASP.NET take advantage of early binding,
just
-
in
-
time compilation, native optimization, and caching services rig
ht out of the box.

The ASP.NET framework is complemented by a rich toolbox and designer in the Visual
Studio IDE. WYSIWYG editing, drag
-
and
-
drop server controls, and automatic
deployment are some features this powerful tool provides.



6

Because ASP.NET is ba
sed on the common language runtime, the power and flexibility
of that entire platform is available to Web application developers. Further, common
language runtime interoperability guarantees that your existing investment in COM
-
based
development is preserv
ed when migrating to ASP.NET.

ASP.NET makes it easy to perform common tasks, from simple form submission and
client authentication to deployment and site configuration. Additionally, the common
language runtime simplifies development, with managed code ser
vices such as automatic
reference counting and garbage collection.

2.3.4

SQLServer 2000 DBMS

SQL

Server™ 2000 has been used as the DBMS for this application.

SQL Server™ 2000

is a powerful Database Management System by Microsoft.



3.0

Implementation

3.1

Implementation of
Data Layer

3.1.1

Database Schema

Following is the schema of the database:



Figure 2 : Schem
a of the database



7


Following are the main points of this schema:



There can be several orders of an account, but each order belongs to only one
account.



Each account can have several portfolios.



Each portfolio belongs to a particular Ticker.


3.1.2

Stored Proced
ures

3.1.2.1

STCheckFunds

This procedure determines if there are enough funds available to place a specific order.


CREATE PROCEDURE [STCheckFunds]

(@account int, @amount float)

AS

DECLARE

@available

float,

@retValue

bit

BEGIN

SELECT @available = AccountBalance
FROM STAccounts


WHERE AccountId =



@account


IF @available < @amount



SET @retValue = 0


ELSE



SET @retValue = 1


RETURN @retValue

END


3.1.2.2

STCheckStocks

This procedure determines if the quantity entered against a sell order is valid or not.


CREATE PRO
CEDURE [STCheckStocks]

(@account int, @symbol varchar(50), @quantity int)

AS

DECLARE

@tid
int,

@total

int,

@count int,

@retValue

int

BEGIN


SELECT @count = COUNT(*) FROM STTickers WHERE Symbol = @symbol


IF @count = 0



SET @retValue = 0


ELSE


BEGIN



S
ELECT @tid = TickerId FROM STTickers WHERE Symbol =




@symbol



SELECT @total = SUM(Quantity) FROM STPortfolioS WHERE




AccountId

= @account AND TickerId = @tid



IF @total >= @quantity




SET @retValue = 1



ELSE




SET @retValue = 0


END



RETURN @re
tValue

END




8


3.1.2.3

STPlaceOrder

This procedure
enters a new order into the database
.


CREATE PROCEDURE [STPlaceOrder]

(@account int, @symbol varchar(50), @buysell bit, @quantity int,
@price float)

AS

DECLARE

@value int,

@count int,

@tid

int

BEGIN


SELECT @coun
t = COUNT(*) FROM STTickers WHERE Symbol =




@symbol


IF @count = 1



BEGIN



SELECT @tid = TickerId FROM STTickers WHERE Symbol=




@symbol



INSERT INTO STOrders (AccountId, TickerId, BuySell,




Quantity, PricePlaced) VALUES (@account, @tid,





@buysell,

@quantity, @price)



SET @value = @@Identity



END


ELSE



SET @value =
-
1


RETURN @value

END


3.1.2.4

STPortfolio

This procedure
returns all the portfolios of a given account.


CREATE PROCEDURE [STPortfolio]

(@accountId int)

AS

BEGIN


SELECT T.Name,

T.Symbol, P.Quantity, T.LastPrice


FROM STPortfolios P, STTickers T


WHERE T.TickerId = P.TickerId AND P.AccountId= @accountId

END


3.1.2.5

STTickerDetails

This procedure returns the details of a particular Ticker symbol.


CREATE PROCEDURE [STTickerDetails]

(@t
icker varchar(100))

AS

BEGIN


SELECT TickerId, Symbol, Name, LastPrice


FROM STTickers


WHERE Symbol = @ticker


END


3.1.2.6

STVerifyLogin

This procedure
is used to verify the given login information.




9

CREATE PROCEDURE [STVerifyLogin]

(@username varchar(50), @pa
ssword varchar(50))

AS

DECLARE

@valid int,

@count int

BEGIN


SELECT @count = COUNT(*) FROM STAccounts WHERE login =




@username AND password = @password


IF @count = 1



SELECT @valid = AccountId FROM STAccounts WHERE login =




@username AND passwo
rd = @password


ELSE



SET @valid = 0


RETURN @valid

END


3.1.3

‘dlStockTrade’ Class

Below is the code of the class used to implement the data layer.


using

System;

using

System.Data;

using

System.Data.SqlClient;

using

System.Configuration;

namespace

StockTrade.
Components.DLL

{


public

class

dlStockTrade


{



private

const

string

strConnection =









"Server=newton;UID=rpuser;PWD=rpuser;







database=ResourceScheduler;";



// default constructor



private

dlStockTrade() { }



/
/*****************************
*******************



// Returns '0' for invalid login information



// otherwise returns AccountId of the account



/
/************************************************



public

static

int

verifyLogin(
string

user,
string

pwd)



{




SqlConnection connectio
n = getConnection();




SqlCommand command =
new

SqlCommand("STVerifyLogin",









connection);




command.CommandType = CommandType.StoredProcedure;




command.Parameters.Add("@username",user);




command.Parameters.Add("@password", pwd);



S
qlParameter retValue = command.Parameters.Add(






"ReturnValue",SqlDbType.Int);




retValue.Direction = ParameterDirection.ReturnValue;




connection.Open();




command.ExecuteNonQuery();




int

result = Convert.ToInt32(






command.Parameters["Ret
urnValue"].Value);




connection.Close();




return

result;



}



/
/************************************************



10



// Retrieves whole portfolio of a particular account



/
/************************************************



public

static

DataSet getPort
folio (
int

accountId)



{




SqlConnection connection = getConnection();




SqlCommand command =
new

SqlCommand(







"STPortfolio", connection);




command.CommandType = CommandType.StoredProcedure;




command.Parameters.Add("@accountId",accountId);




S
qlDataAdapter da =
new

SqlDataAdapter(command);




DataSet ds =
new

DataSet();




da.Fill(ds);




return

ds;






}



/
/************************************************



// Retrieves details of a ticker symbol



/
/*****************************************
*******



public

static

DataSet getTickerDetails(
string

symbol)



{




SqlConnection connection = getConnection();




SqlCommand command =
new

SqlCommand(






"STTickerDetails", connection);




command.CommandType = CommandType.StoredProcedure;




com
mand.Parameters.Add("@ticker",symbol);




SqlDataAdapter da =
new

SqlDataAdapter(command);




DataSet ds =
new

DataSet();




da.Fill(ds);




return

ds;





}



/
/************************************************



// Places a Order



// returns orderId,
-
1
for invalid ticker,



// 0 for other invalid data



/
/************************************************



public

static

int

PlaceOrder (
int

acct,
string

sym,






bool

bs,
int

qty,
double

placed)



{




SqlConnection connection = getConnection();




SqlCo
mmand command =
new

SqlCommand(





"STPlaceOrder", connection);




command.CommandType = CommandType.StoredProcedure;




byte

b = bs ? (
byte
)1 : (
byte
)0;




command.Parameters.Add("@account",acct);




command.Parameters.Add("@symbol",sym);




command.Para
meters.Add("@buysell",b);





command.Parameters.Add("@quantity",qty);




command.Parameters.Add("@price",placed);




SqlParameter retValue = command.Parameters.Add(






"ReturnValue",SqlDbType.Int);




retValue.Direction = ParameterDirection.ReturnVa
lue;




connection.Open();




command.ExecuteNonQuery();




int

result = Convert.ToInt32(






command.Parameters["ReturnValue"].Value);




connection.Close();




return

result;





}



11



/
/************************************************



// Checks fo
r funds before placing a Order



// returns 1 if sufficient funds are available



// to order else 0



/
/************************************************



public

static

bool

CheckFunds (
int

acct,
double

val)



{




SqlConnection connection = getConnectio
n();




SqlCommand command =
new

SqlCommand(






"STCheckFunds", connection);




command.CommandType = CommandType.StoredProcedure;




command.Parameters.Add("@account",acct);




command.Parameters.Add("@amount",val);




SqlParameter retValue = command.Pa
rameters.Add(






"ReturnValue",SqlDbType.Bit);




retValue.Direction = ParameterDirection.ReturnValue;




connection.Open();




command.ExecuteNonQuery();



sbyte

result = Convert.ToSByte(






command.Parameters["ReturnValue"].Value);




conn
ection.Close();




if
(result == 0)
return

false
;




else

return

true
;





}



/
/************************************************



// Checks for stock quantity before placing a sell Order



// returns 1 if sufficient stocks are available to order



// els
e 0



/
/************************************************



public

static

bool

CheckStocks (
int

acct,
string

sym,









int

qty)



{




SqlConnection connection = getConnection();




SqlCommand command =
new

SqlCommand(






"STCheckStocks", connection);




command.CommandType = CommandType.StoredProcedure;




command.Parameters.Add("@account",acct);




command.Parameters.Add("@symbol",sym);




command.Parameters.Add("@quantity",qty);




SqlParameter retValue = command.Parameters.Add(






"ReturnValue",S
qlDbType.Bit);




retValue.Direction = ParameterDirection.ReturnValue;




connection.Open();




command.ExecuteNonQuery();



sbyte

result = Convert.ToSByte(






command.Parameters["ReturnValue"].Value);




connection.Close();





if
(result == 0
)

return

false
;




else



return

true
;







}



private

static

SqlConnection getConnection()



{




return

new

SqlConnection(dlStockTrade.strConnection);



}


}

}



12

3.2

Implementation of
Business Logic Layer

Below are the definitions of all the classes used in

implementation of the business logic.

3.2.1

Class ‘Order’

using

System;

using

System.Data;

using

System.Configuration;

using

System.Text;

using

System.Data.SqlClient;

using

System.Collections;

using

StockTrade.Components.DLL;

namespace

StockTrade.Components.BLL

{


/
/************************************************


// Order Class used to represent an Order


/
/************************************************


public

class

Order


{



private

int


accountId;



private

string


symbol;



private

bool


buyOrSell;



pr
ivate

int


quantity;



private

double


pricePlaced;



private

double


priceExecuted;



/
/default constructor



public

Order() { }





public

Order (
int

acct,
string

ticker,
bool

bs,
int

qty,







double

placed,
double

exec)



{




accountId = acct;




sym
bol = ticker;







buyOrSell = bs;




quantity = qty;




pricePlaced = placed;




priceExecuted = exec;



}



/
/************************************************





// set and get Properties



/
/************************************************





public

int

AccountId



{




get
{
return

accountId; }




set
{ accountId =
value
; }



}



public

string

Symbol



{




get
{
return

symbol; }




set
{ symbol =
value
; }



}



public

int

Quantity



{




get
{
return

quantity; }




set
{ quantity =
value
; }



}



public

b
ool

BuyOrSell



13



{




get
{
return

BuyOrSell; }




set
{ BuyOrSell =
value
; }



}



public

double

PricePlaced



{




get
{
return

pricePlaced; }




set
{ pricePlaced =
value
; }



}



public

double

PriceExecuted



{




get
{
return

priceExecuted; }




set
{ priceE
xecuted =
value
; }



}


/
/************************************************



// Places a Order
,

returns orderId,
-
1 for invalid


//

ticker, 0 for other invalid data


/
/************************************************




public

static

int

PlaceOrder (
int

ac
ct,
string

sym,





bool

bs,
int

qty,
double

placed)



{




return

dlStockTrade.PlaceOrder(acct, sym, bs,






qty, placed);



}


/
/************************************************




// Checks for funds before placing a Order


// returns 1 if sufficient

funds are available


// to order else returns 0


/
/************************************************




public

static

bool

CheckFunds (
int

acct,
double

val)


{



return

dlStockTrade.CheckFunds(acct, val);


}


/
/*********************************************
***




// Checks for stock quantity before placing a sell Order


// returns 1 if sufficient stocks are available


// to order else 0


/
/************************************************




public

static

bool

CheckStocks (
int

acct,
string

sym,
int

qty)



{




return

dlStockTrade.CheckStocks(acct, sym, qty);



}


}

}

3.2.2

Class ‘Portfolio’

using

System;

using

System.Data;

using

System.Configuration;

using

System.Text;

using

System.Data.SqlClient;

using

System.Collections;

using

StockTrade.Components.DLL;

namespace

StockTrade.Components.BLL

{


/
/************************************************



// Portfolio Class Represents a Portfolio



14


/
/************************************************


public

class

Portfolio


{



private

int


accountId;



private

string


ticker;



private

string


description;



private

int


quantity;



private

double


currValue;



private

double


total;



// default constructor



public

Portfolio() { }



public

Portfolio (
int

acctId,
string

ticker,
string

desc,







int

qty,
double

val)



{




accountId = acctId;




ticker = ticker;







description = desc;




quantity = qty;




currValue = val;



}


/
/************************************************



// set and get Properties


/
/************************************************




public

int

AccountId



{




get
{
return

accountId; }




set
{ accountId =
value
; }



}





public

string

Item



{




get
{
return

ticker; }




set
{ ticker =
value
; }



}



public

string

Ticker



{




get
{
return

ticker; }




set
{ ticker =
value
; }



}



public

stri
ng

Description



{




get
{
return

description; }




set
{ description =
value
; }



}



public

int

Quantity



{




get
{
return

quantity; }




set
{ quantity =
value
; }



}



public

double

CurrentValue



{




get
{
return

currValue; }




set
{ currValue =
value
;

}



}



public

double

Total



{




get
{
return

total; }




set
{ total =
value
; }



15



}




/
/************************************************


// Retrieves whole portfolio of a particular account


/
/************************************************




public

static

ArrayList getPortfolio(
int

acctId)



{




ArrayList portfolio =
new

ArrayList ();




DataSet ds = dlStockTrade.getPortfolio(acctId);




// Copy data into a Collection of portfolio objects




foreach
(DataRow r
in

ds.Tables[0].Rows)




{





Portfolio

p =
new

Portfolio();





p.Description = r["Name"].ToString();





p.Ticker = r["Symbol"].ToString();





p.Quantity = Convert.ToInt32(r["Quantity"]);





p.CurrentValue = Convert.ToDouble(r["LastPrice"]);





p.AccountId = acctId;





p.Total = p.Quantit
y * p.CurrentValue;





portfolio.Add(p);




}




return

portfolio;



}


}

}

3.2.3

Class ‘Ticker’

using

System;

using

System.Data;

using

System.Configuration;

using

System.Text;

using

System.Data.SqlClient;

using

System.Collections;

using

StockTrade.Components.D
LL;


namespace

StockTrade.Components.BLL

{


/
/************************************************


// Ticker Class


// Used to represent a Portfolio


/
/************************************************


public

class

Ticker


{



private

int



id;



private

stri
ng


symbol;



private

string


name;



private

double


lastPrice;



// default constructor



public

Ticker() { }



public

Ticker (
int

id,
string

ticker,
string

desc,
double

val)



{




id = id;




symbol = ticker;







name = desc;




lastPrice = val;



}



/
/************************************************



// set and get Properties



16



/
/************************************************



public

int

Id



{




get
{
return

id; }




set
{ id =
value
; }



}



public

string

Symbol



{




get
{
return

symbol; }




s
et
{ symbol =
value
; }



}



public

string

Name



{




get
{
return

name; }




set
{ name =
value
; }



}



public

double

LastPrice



{




get
{
return

lastPrice; }




set
{ lastPrice =
value
; }



}



/
/************************************************



// Retri
eves last price of a particular ticker



/
/************************************************



public

static

ArrayList getTickerDetails (
string

symbol)



{




ArrayList ticker =
new

ArrayList ();




DataSet ds = dlStockTrade.getTickerDetails (







symbol.
Trim());




// copy Data into a Collection of portfolio objects




foreach
(DataRow r
in

ds.Tables[0].Rows)




{





Ticker t =
new

Ticker();





t.Id = Convert.ToInt32(r["TickerId"]);





t.Symbol = r["Symbol"].ToString();





t.Name = r["Name"].ToString()
;





t.LastPrice = Convert.ToDouble(r["LastPrice"]);





ticker.Add(t);




}




return

ticker;



}


}

}

3.2.4

Class ‘blStockTrade’

using

System;

using

System.Web.UI.WebControls;

using

StockTrade.Components.DLL;

namespace

StockTrade.Components.BLL

{



public

cl
ass

blStockTrade



{



//default constructor



private

blStockTrade() { }



/
/************************************************



// Returns '0' for invalid login information



// otherwise returns AccountId of the account





17



/
/***************************
*********************



public

static

int

verifyLogin(
string

user,
string

pwd)



{




return

dlStockTrade.verifyLogin(user, pwd);



}



/
/************************************************



// populate the menu



/
/******************************************
******



public

static

void

Menu(Table tbl)



{




for
(
int

i = 0; i<3; i++) {





menuItem(tbl, "&nbsp;", "");




}




menuItem(tbl, "My Portfolio", "myportfolio.aspx");




menuItem(tbl, "&nbsp;", "");




menuItem(tbl, "Buy / Sell", "buysell.aspx");




me
nuItem(tbl, "&nbsp;", "");




menuItem(tbl, "Search", "search.aspx");




menuItem(tbl, "&nbsp;", "");




menuItem(tbl, "Logout", "logout.aspx");




for
(
int

i = 0; i<15; i++) {





menuItem(tbl, "&nbsp;", "");




}



}



private

static

void

menuItem(Table t
bl,
string

txt,
string
link)



{




TableRow tr;




TableCell tc;




tr =
new

TableRow();




tc =
new

TableCell();




if
(link.Equals(""))





tc.Text = "&nbsp";




else





tc.Text = "<a href='"+link+"'>"+txt+"</a>";




tr.Cells.Add(tc);




tbl.Rows.Add(tr)
;



}


}

}


3.3

Presentation Layer (of website for normal users)

3.3.1

Login web page (code behind file)

using

System;

using

System.Collections;

using

System.ComponentModel;

using

System.Data;

using

System.Drawing;

using

System.Web;

using

System.Web.SessionState;

using

System.Web.UI;

using

System.Web.UI.WebControls;

using

System.Web.UI.HtmlControls;

using

StockTrade.Components.BLL;

namespace

StockTrade



18

{


public

class

login : System.Web.UI.Page


{



protected

System.Web.UI.WebControls.Label lblMessage;



protected

System.Web.UI.WebControls.TextBox txtLogin;



protected

System.Web.UI.WebControls.TextBox txtPassword;



protected

System.Web.UI.WebControls.RequiredFieldValidator







rfvUserName;



protected

System.Web.UI.WebControls.RequiredFieldValidator







rfvPa
ssword;



protected

System.Web.UI.WebControls.Button btnSubmit;



protected

System.Web.UI.WebControls.Table tblMenu;



protected

System.Web.UI.WebControls.Button btnCancel;



public

void

Page_Load(
object

sender, System.EventArgs e)



{




if

(Request.Brows
er["IsMobileDevice"] == "true" ) {





Response.Redirect("/StockTradeMobile/login.aspx");




}




TableRow tr;




TableCell tc;







for
(
int

i = 0; i<25; i++){





tr =
new

TableRow();





tc =
new

TableCell();





tc.Text = "&nbsp;";





tr.Cells.Add(tc
);





tblMenu.Rows.Add(tr);








}



}




public

void

btnCancel_Click(
object

sender,System.EventArgs

e)



{




txtLogin.Text = "";




txtPassword.Text = "";



}




public

void

btnSubmit_Click(
object

sender,System.EventArgs e)



{




int

acctId

= blStockTrade.verifyLogin(










txtLogin.Text.Trim(),

txtPassword.Text.Trim());





if
(acctId == 0){





lblMessage.Text = "Invalid login information entered,







please try again";





lblMessage.Visible =
true
;




}




else

{





Session["Accoun
tId"] = acctId;





Session["LoggedIn"] = 1;





Response.Redirect("main.aspx");




}







}


}

}

3.3.2

logout web page (code behind file)

using

System;

using

System.Collections;

using

System.ComponentModel;



19

using

System.Data;

using

System.Drawing;

using

Syste
m.Web;

using

System.Web.SessionState;

using

System.Web.UI;

using

System.Web.UI.WebControls;

using

System.Web.UI.HtmlControls;

namespace

StockTrade

{


public

class

logout : System.Web.UI.Page


{





public

void

Page_Load(
object

sender, System.EventArgs e)



{




Session.Abandon();




Response.Redirect("login.aspx");



}


}

}

3.3.3

Main web page (code behind file)

using

System;

using

System.Collections;

using

System.ComponentModel;

using

System.Data;

using

System.Drawing;

using

System.Web;

using

System.Web.Session
State;

using

System.Web.UI;

using

System.Web.UI.WebControls;

using

System.Web.UI.HtmlControls;

using

StockTrade.Components.BLL;

namespace

StockTrade

{


public

class

main : System.Web.UI.Page


{



public

void

Page_Load(
object

sender, System.EventArgs e)



{




//nothing



}


}

}


3.3.4

Portfolio web page (code behind file)


using

System;

using

System.Collections;

using

System.ComponentModel;

using

System.Data;

using

System.Drawing;

using

System.Web;

using

System.Web.SessionState;

using

System.Web.UI;

using

System
.Web.UI.WebControls;

using

System.Web.UI.HtmlControls;

using

StockTrade.Components.BLL;



20

namespace

StockTrade

{


public

class

portfolio : System.Web.UI.Page


{



protected

System.Web.UI.WebControls.DataGrid dgPortfolio;





public

void

Page_Load(
object

s
ender, System.EventArgs e)



{




dgPortfolio.DataSource = Portfolio.getPortfolio(






Convert.ToInt32(Session["AccountId"]));




dgPortfolio.DataBind();



}


}

}

3.3.5

Search web page (code behind file)

using

System;

using

System.Collections;

using

System.Com
ponentModel;

using

System.Data;

using

System.Drawing;

using

System.Web;

using

System.Web.SessionState;

using

System.Web.UI;

using

System.Web.UI.WebControls;

using

System.Web.UI.HtmlControls;

using

StockTrade.Components.BLL;


namespace

StockTrade

{


public

class

search : System.Web.UI.Page


{



protected

System.Web.UI.WebControls.TextBox txtTicker;



protected

System.Web.UI.WebControls.Label lblTicker;



protected

System.Web.UI.WebControls.Label lblPrice;



protected

System.Web.UI.WebControls.Button btnSubmi
t;



protected

System.Web.UI.WebControls.RequiredFieldValidator












rfvTicker;



protected

System.Web.UI.WebControls.RequiredFieldValidator












rfvUserName;



public

void

Page_Load(
object

sender, System.EventArgs e)



{




lblTicker.Visible

=
false
;




lblPrice.Visible =
false
;



}



public

void

btnSubmit_Click(
object

sender,System.EventArgs e)



{




ArrayList arr = Ticker.getTickerDetails(











txtTicker.Text.Trim());




if
(arr.Count == 0)

{





lblTicker.Text = "No such symbol found"
;





lblTicker.Visible =
true
;




}




else

if
(arr.Count > 1)

{





lblTicker.Text = "Multiple entries found";





lblTicker.Visible =
true
;




}



21




else
{






Ticker t = (Ticker)arr[0];





lblTicker.Text = "Company: " + t.Name;





lblTicker.Visible =
t
rue
;





lblPrice.Text = "Last Price: " +






Convert.ToString(t.LastPrice);





lblPrice.Visible =
true
;




}



}


}

}

3.3.6

Buysell web page (code behind file)

using

System;

using

System.Collections;

using

System.ComponentModel;

using

System.Data;

using

Sy
stem.Drawing;

using

System.Web;

using

System.Web.SessionState;

using

System.Web.UI;

using

System.Web.UI.WebControls;

using

System.Web.UI.HtmlControls;

using

StockTrade.Components.BLL;

namespace

StockTrade

{


public

class

buysell : System.Web.UI.Page


{



p
rotected

System.Web.UI.WebControls.RadioButton radBuy;



protected

System.Web.UI.WebControls.RadioButton radSell;



protected

System.Web.UI.WebControls.Label lblMessage;



protected

System.Web.UI.WebControls.TextBox txtQuantity;



protected

System.Web.UI.W
ebControls.TextBox txtPrice;



protected

System.Web.UI.WebControls.TextBox txtTicker;



protected

System.Web.UI.WebControls.Button btnSubmit;



protected

System.Web.UI.WebControls.Button btnCancel;



protected

System.Web.UI.WebControls.RequiredFieldValidat
or













rfvPrice;



protected

System.Web.UI.WebControls.RequiredFieldValidator












rfvQuantity;



protected

System.Web.UI.WebControls.RequiredFieldValidator












rfvTicker;



public

void

Page_Load(
object

sender, System.EventArgs e)



{




//nothing



}




public

void

btnCancel_Click(
object

sender, System.EventArgs e)



{




Response.Redirect("main.aspx");



}




public

void

btnSubmit_Click(
object

sender, System.EventArgs e)



{




if
(radBuy.Checked ==
false

&& radSell.Checked ==
false
)
{





lblMessage.Text = "Please select buy or sell";





lblMessage.Visible =
true
;



22





return
;




}




int

qty;


double

price;


bool

bs;




if
(radBuy.Checked)





bs =
true
;
// buy order




else





bs =
false
;
// sell order




try

{





qty = Convert.ToI
nt32(txtQuantity.Text.Trim());





price = Convert.ToDouble(txtPrice.Text.Trim());





if
(qty <= 0 || price <= 0) {






lblMessage.Text = "Quantity / price should be










greater than 0";






lblMessage.Visible =
true
;






return
;





}




}




cat
ch
(Exception data){





string

x = data.Message;





lblMessage.Text = "Invalid data for qty
/

p
rice.";





lblMessage.Visible =
true
;





return
;




}




if
(radBuy.Checked)



{





if
(!Order.CheckFunds(Convert.ToInt32(







Session["AccountId"]),qty*pric
e))
{






lblMessage.Text = "Insufficient funds ";






lblMessage.Visible =
true
;






return
;





}




}




if
(radSell.Checked){





if
(!Order.CheckStocks(Convert.ToInt32(Session["AccountId"]





),txtTicker.Text.Trim().ToUpper(), qty)){






lblMessage
.Text = "Invalid data specified";






lblMessage.Visible =
true
;






return
;





}




}





int

oid = Order.PlaceOrder(Convert.ToInt32








(Session["AccountId"]),






txtTicker.

Text.Trim().ToUpper(),

bs,qty,price);




if
(oid <= 0)





lblMessage.Tex
t = "Order submission failure";




else





lblMessage.Text = "Order placed. Order No: " + oid;




lblMessage.Visible =
true
;



}


}

}

3.3.7

‘Menu’ user control (code behind file)

namespace

StockTrade

{


using

System;



23


using

System.Data;


using

System.Drawing;


using

System.Web;


using

System.Web.UI.WebControls;


using

System.Web.UI.HtmlControls;


public

class

ucMenu : System.Web.UI.UserControl


{



protected

System.Web.UI.WebControls.Table tblMenu;



private

void

Page_Load(
object

sender, System.EventArgs e)



{




for
(
int

i = 0; i<2; i++){





menuItem(tblMenu, "&nbsp;", "");




}




menuItem(tblMenu, "My Portfolio", "portfolio.aspx");




menuItem(tblMenu, "&nbsp;", "");




menuItem(tblMenu, "Buy / Sell", "buysell.aspx");




menuItem(tblMenu, "&nbsp;", "");




m
enuItem(tblMenu, "Search", "search.aspx");




menuItem(tblMenu, "&nbsp;", "");




menuItem(tblMenu, "Main", "main.aspx");




menuItem(tblMenu, "&nbsp;", "");




menuItem(tblMenu, "Logout", "logout.aspx");




for
(
int

i = 0; i<15; i++){





menuItem(tblMenu,

"&nbsp;", "");




}



}



private

static

void

menuItem(Table tbl,
string

txt,
string

link)



{




TableRow tr;




TableCell tc;




tr =
new

TableRow();




tc =
new

TableCell();




if
(link.Equals(""))





tc.Text = "&nbsp";




else





tc.Text = "<a href='"
+ link + "'>" + txt + "</a>";




tr.Cells.Add(tc);




tbl.Rows.Add(tr);



}




}

}

3.4

Presentation Layer

Implementation

(for mobile devices)

3.4.1


Login


web Page

3.4.1.1

Html Code

(login.aspx)

<%@ Page language="c#" Codebehind="login.aspx.cs" Inherits=

"StockTradeMobil
e.MobileLogin" AutoEventWireup="false" %>

<%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls"

Assembly="System.Web.Mobile" %>

<HEAD></HEAD>

<body>

<mobile:stylesheet id="Stylesheet1" ReferencePath="Styles.ascx"




runat="server"></mo
bile:stylesheet>

<mobile:form id="frmLogin" EnableViewState="False" runat="server"



StyleReference="Form">



24

<mobile:Label id="lblSignin" StyleReference="Title" Runat="server">



Sign
-
In</mobile:Label>

<mobile:Label id="lblUser" runat="server">User name:<
/mobile:Label>

<mobile:TextBox id="txtUser" runat="server"></mobile:TextBox>

<mobile:RequiredFieldValidator id="rfvUser" Runat="server"





ControlToValidate="txtUser" Err
orMessage="Enter user name">
</mobile:RequiredFieldValidator>

<mobile:Label id="lblP
assword" runat="server">Password:</mobile:Label>

<mobile:TextBox id="txtPassword" runat="server" Password="True">




</mobile:TextBox>

<mobile:RequiredFieldValidator id="rfvPassword" Runat="server"




ControlToValidate="txtPassword" Er
rorMessage="Enter p
assword">


</mobile:RequiredFieldValidator>

<mobile:Command id="cmdSubmit" runat="server">Login</mobile:Command>

<mobile:Command id="cmdCancel" runat="server">Reset</mobile:Command>

<mobile:Label id="lblMessage" runat="server" StyleReference="Error">


</
mobile:Label>

</mobile:form>

</body>

3.4.1.2

Code behind (login.aspx.cs)

using

System;

using

System.Collections;

using

System.ComponentModel;

using

System.Data;

using

System.Drawing;

using

System.Web;

using

System.Web.Mobile;

using

System.Web.SessionState;

using

S
ystem.Web.UI;

using

System.Web.UI.MobileControls;

using

System.Web.UI.WebControls;

using

System.Web.UI.HtmlControls;

using

StockTrade.Components.BLL;

namespace

StockTradeMobile

{


public

class

MobileLogin : System.Web.UI.MobileControls.MobilePage


{



prot
ected

System.Web.UI.MobileControls.Label lblUser;



protected

System.Web.UI.MobileControls.Label lblPassword;



protected

System.Web.UI.MobileControls.TextBox txtUser;





protected

System.Web.UI.MobileControls.TextBox txtPassword;



protected

System.Web.U
I.MobileControls.RequiredFieldValidator












rfvUser;



protected

System.Web.UI.MobileControls.RequiredFieldValidator












rfvPassword;



protected

System.Web.UI.MobileControls.Command cmdSubmit;



protected

System.Web.UI.MobileControls.Label

lblMessage;



protected

System.Web.UI.MobileControls.Form frmError;



protected

System.Web.UI.MobileControls.Form frmLogin;



protected

System.Web.UI.MobileControls.StyleSheet Stylesheet1;



protected

System.Web.UI.MobileControls.Label lblSignin;



protec
ted

System.Web.UI.MobileControls.Command cmdCancel;



private

void

Page_Load(
object

sender, System.EventArgs e)



{




if

(Request.Browser["IsMobileDevice"] == "false" )

{





Response.Redirect("/StockTrade/login.aspx");



25




}



}




private

void

cm
dCancel_Click(
object

sender,System.EventArgs e)



{




txtUser.Text = "";




txtPassword.Text = "";



}




private

void

cmdSubmit_Click(
object

sender,System.EventArgs e)



{




if
(txtUser.Text.Trim()== ""||txtPassword.Text.Trim()=="")





return
;




int

ac
ctId = lStockTrade.verifyLogin(txtUser.Text.Trim(),








txtPassword.Text.Trim());







if
(acctId == 0){





lblMessage.Text = "Invalid login information ntered”;





lblMessage.Visible =
true
;




}




else

{





Session["AccountId"] = acctId;





Sessi
on["LoggedIn"] = 1;





RedirectToMobilePage("main.aspx");




}



}


}

}


3.4.2


Main


web Page

3.4.2.1

Html Code

(main.aspx)

<%@ Page language="c#" Codebehind="main.aspx.cs" Inherits=

"StockTradeMobile.MobileMain" AutoEventWireup="false" %>

<%@ Register TagPrefix="mobi
le" Namespace="System.Web.UI.MobileControls"

Assembly="System.Web.Mobile" %>

<HEAD></HEAD>

<body>

<mobile:stylesheet id="Stylesheet1" ReferencePath="Styles.ascx"



runat="server"></mobile:stylesheet>

<mobile:Form id="Login" runat="server" StyleReference=
"Form"



EnableViewState="False">

<mobile:Label id="lblHead" runat="server" StyleReference="Title">



Stock Trade</mobile:Label>Select Item from the list:

<
mobile:Command id="cmdPortfolio" Runat="server" Format="Link">





Portfolio</mobile:Command>

<
mob
ile:Command id="cmdOrder" Runat="server" Format="Link">



New Order</mobile:Command>

<mobile:Command id="cmdSearch" Runat="server" Format="Link">






Search</mobile:Command>

<
mobile:Command id="cmdLogout" Runat="server" Format="Link">





Logout</mobile:C
ommand>

</mobile:Form>

</body>

3.4.2.2

Code behind
(
main
.aspx.cs)

using

System;

using

System.Collections;



26

using

System.ComponentModel;

using

System.Data;

using

System.Drawing;

using

System.Web;

using

System.Web.Mobile;

using

System.Web.SessionState;

using

System.W
eb.UI;

using

System.Web.UI.MobileControls;

using

System.Web.UI.WebControls;

using

System.Web.UI.HtmlControls;

using

StockTrade.Components.BLL;

namespace

StockTradeMobile

{


public

class

MobileMain : System.Web.UI.MobileControls.MobilePage


{



protected

Sy
stem.Web.UI.MobileControls.Label lblUser;



protected

System.Web.UI.MobileControls.TextBox txtUser;



protected

System.Web.UI.MobileControls.RequiredFieldValidator











rfvUser;



protected

System.Web.UI.MobileControls.TextBox txtPassword;



protecte
d

System.Web.UI.MobileControls.RequiredFieldValidator












rfvPassword;



protected

System.Web.UI.MobileControls.Command cmdSubmit;



protected

System.Web.UI.MobileControls.Command cmdCancel;



protected

System.Web.UI.MobileControls.Form Login;



pr
otected

System.Web.UI.MobileControls.Label lblMessage;



protected

System.Web.UI.MobileControls.StyleSheet Stylesheet1;



protected

System.Web.UI.MobileControls.Label lblHead;



protected

System.Web.UI.MobileControls.Form frmPortfolio;



protected

System.W
eb.UI.MobileControls.List lstPortfolio;



protected

System.Web.UI.MobileControls.Command cmdPortfolio;



protected

System.Web.UI.MobileControls.Label lblPortfolio;



protected

System.Web.UI.MobileControls.Command cmdOrder;



protected

System.Web.UI.MobileC
ontrols.Command cmdSearch;



protected

System.Web.UI.MobileControls.Command cmdLogout;



protected

System.Web.UI.MobileControls.Form frmError;



private

void

Page_Load(
object

sender, System.EventArgs e)



{




//nothing



}



public

void

cmdPortfolio_Click
(
object

sender,System.EventArgs)



{




RedirectToMobilePage("portfolio.aspx");



}



public

void

cmdLogout_Click(
object

sender, System.EventArgs e)



{




Session.Abandon();




RedirectToMobilePage("login.aspx");



}



public

void

cmdOrder_Click(
object

se
nder, System.EventArgs e)



{




RedirectToMobilePage("buysell.aspx");



}



public

void

cmdSearch_Click(
object

sender, System.EventArgs e)



{




RedirectToMobilePage("search.aspx");



}



27


}

}

3.4.3


Search


web Page

3.4.3.1

Html Code

(search.aspx)

<%@ Register TagPrefi
x="mobile" Namespace="System.Web.UI.MobileControls"

Assembly="System.Web.Mobile" %>

<%@ Page language="c#" Codebehind="search.aspx.cs"

Inherits="StockTradeMobile.search" AutoEventWireup="false" %>

<HEAD></HEAD>

<body
>

<mobile:stylesheet id="Stylesheet1"
ReferencePath="Styles.ascx"


runat="server"></mobile:stylesheet>

<mobile:Form ID="frmSearch" Runat="server" StyleReference="Form"


EnableViewState="False">

<mobile:Label id="lblSearch" runat="server"


StyleReference="Title">Search</mobile:Label>

<mobile
:Label id="lblTicker" runat="server">Ticker:</mobile:Label>

<mobile:TextBox id="txtTicker" runat="server"></mobile:TextBox>

<mobile:RequiredFieldValidator id="rfvTicker" Runat="server"


ErrorMessage="Enter ticker symbol"








ControlToValidate="txtTicke
r"

></mobile:RequiredFieldValidator>

<mobile:Command id="cmdSubmit" runat="server">Search</mobile:Command>

<mobile:Label id="lblMessage" runat="server"></mobile:Label>

<mobile:Label id="lblResult" runat="server"></mobile:Label>



</mobile:Form>

</body>

3.4.3.2

Cod
e behind (
search
.aspx.cs)

using

System;

using

System.Collections;

using

System.ComponentModel;

using

System.Data;

using

System.Drawing;

using

System.Web;

using

System.Web.Mobile;

using

System.Web.SessionState;

using

System.Web.UI;

using

System.Web.UI.Mobil
eControls;

using

System.Web.UI.WebControls;

using

System.Web.UI.HtmlControls;

using

StockTrade.Components.BLL;

namespace

StockTradeMobile

{


public

class

search : System.Web.UI.MobileControls.MobilePage


{



protected

System.Web.UI.MobileControls.StyleShee
t Stylesheet1;



protected

System.Web.UI.MobileControls.Label lblSearch;



protected

System.Web.UI.MobileControls.Label lblTicker;



protected

System.Web.UI.MobileControls.TextBox txtTicker;



protected

System.Web.UI.MobileControls.RequiredFieldValidator












rfvTicker;



protected

System.Web.UI.MobileControls.Command cmdSubmit;



protected

System.Web.UI.MobileControls.Form frmSearch;



protected

System.Web.UI.MobileControls.Label lblResult;



protected

System.Web.UI.MobileControls.Label lblMessage;



private

void

Page_Load(
object

sender, System.EventArgs e)



28



{



}



private

void

cmdSubmit_Click(
object

sender, System.EventArgs)



{




if
(txtTicker.Text.Trim() == "")





return
;







ArrayList arr = Ticker.getTickerDetails(









txtTicker.Text.Tri
m());




if
(arr.Count == 0)

{





lblMessage.Text = "No such symbol found";





lblMessage.Visible =
true
;




}




else

if
(arr.Count > 1)

{





lblMessage.Text = "Multiple entries found";





lblMessage.Visible =
true
;




}




else

{





Ticker t = (Ticker
)arr[0];





lblMessage.Text = "Company: " + t.Name;





lblResult.Text = "Last Price:" +









Convert.ToString(t.LastPrice);





lblMessage.Visible =
true
;





lblResult.Visible =
true
;








}



}


}

}


3.4.4


Buysell


web Page

3.4.4.1

Html Code

(buysell.aspx)

<
%@ Page language="c#" Codebehind="buysell.aspx.cs" Inherits=


"StockTradeMobile.buysell" AutoEventWireup="false" %>

<%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls"


Assembly="System.Web.Mobile" %>

<HEAD></HEAD>

<body>

<mobile:sty
lesheet id="Stylesheet1" ReferencePath="Styles.ascx"


runat="server"></mobile:stylesheet>

<mobile:form id="frmOrder" EnableViewState="False" runat="server"


StyleReference="Form">

<mobile:Label id="lblOrder" StyleReference="Title" Runat="server">


New Or
der</mobile:Label>

<mobile:SelectionList id="selOrder" Runat="server" Rows="2"



SelectType="Radio">


<Item Value="Buy" Text="Buy" Selected="True"></Item>


<Item Value="Sell" Text="Sell"></Item>

</mobile:SelectionList>

<mobile:Label id="lblTicker" runat="
server">Ticker:</mobile:Label>

<mobile:TextBox id="txtTicker" runat="server"></mobile:TextBox>

<mobile:RequiredFieldValidator id="rfvTicker" Runat="server"


ErrorMessage="Enter ticker symbol" ControlToValidate=




"txtTicker">

</mobile:RequiredFieldValid
ator>

<mobile:Label id="lblQuantity" runat="server">Quantity:</mobile:Label>

<mobile:TextBox id="txtQuantity" runat="server"></mobile:TextBox>

<mobile:RequiredFieldValidator id="rfvQuantity" Runat="server"



29


ErrorMessage="Enter quantity" ControlToValidate=
"txtQuantity">

</mobile:RequiredFieldValidator>

<mobile:Label id="lblPrice" runat="server">Price:</mobile:Label>

<mobile:TextBox id="txtPrice" runat="server"></mobile:TextBox>

<mobile:RequiredFieldValidator id="rfvPrice" Runat="server"


ErrorMessage="Ent
er price" ControlToValidate="txtPrice">


</mobile:RequiredFieldValidator>

<mobile:Command id="cmdSubmit" runat="server">Submit</mobile:Command>

<mobile:Command id="cmdCancel" runat="server">Cancel</mobile:Command>

<mobile:Label id="lblMessage" runat="serv
er" StyleReference="Error">


</mobile:Label>

</mobile:form>



<mobile:form id="frmConfirm" EnableViewState="False" runat="server"


StyleReference="Form">

<mobile:Label id="lblConfirm" StyleReference="Title" Runat="server">


Order Confirmation</mobile:La
bel>

<mobile:Label id="lblCOrder" runat="server"></mobile:Label>

<mobile:Label id="lblCTicker" runat="server">Ticker:</mobile:Label>

<mobile:Label id="lblCQuantity" runat="server">Quantity:





</mobile:Label>

<mobile:Label id="lblCPrice" runat="server">Pr
ice:</mobile:Label>

<mobile:Command id="cmdMain" Runat="server" Format="Link">Main



</mobile:Command>

</mobile:form>

</body>

3.4.4.2

Code behind (
buysell
.aspx.cs)

using

System;

using

System.Collections;

using

System.ComponentModel;

using

System.Data;

using

Syste
m.Drawing;

using

System.Web;

using

System.Web.Mobile;

using

System.Web.SessionState;

using

System.Web.UI;

using

System.Web.UI.MobileControls;

using

System.Web.UI.WebControls;

using

System.Web.UI.HtmlControls;

using

StockTrade.Components.BLL;

namespace

Stoc
kTradeMobile

{


public

class

buysell : System.Web.UI.MobileControls.MobilePage


{



protected

System.Web.UI.MobileControls.Command cmdSubmit;



protected

System.Web.UI.MobileControls.Command cmdCancel;



protected

System.Web.UI.MobileControls.Label lblMess
age;



protected

System.Web.UI.MobileControls.Form frmOrder;



protected

System.Web.UI.MobileControls.SelectionList selOrder;



protected

System.Web.UI.MobileControls.Label lblTicker;



protected

System.Web.UI.MobileControls.TextBox txtTicker;



protected

System.Web.UI.MobileControls.RequiredFieldValidator












rfvTicker;



protected

System.Web.UI.MobileControls.Label lblQuantity;



protected

System.Web.UI.MobileControls.TextBox txtQuantity;



30



protected

System.Web.UI.MobileControls.RequiredFieldValida
tor











rfvQuantity;



protected

System.Web.UI.MobileControls.Label lblPrice;



protected

System.Web.UI.MobileControls.TextBox txtPrice;



protected

System.Web.UI.MobileControls.RequiredFieldValidator











rfvPrice;



protected

System.Web.UI.M
obileControls.Label lblOrder;



protected

System.Web.UI.MobileControls.Label lblConfirm;



protected

System.Web.UI.MobileControls.Label lblCOrder;



protected

System.Web.UI.MobileControls.Label lblCTicker;



protected

System.Web.UI.MobileControls.Label lbl
CQuantity;



protected

System.Web.UI.MobileControls.Label lblCPrice;



protected

System.Web.UI.MobileControls.Form frmConfirm;



protected

System.Web.UI.MobileControls.Command cmdMain;



protected

System.Web.UI.MobileControls.StyleSheet Stylesheet1;



priv
ate

void

Page_Load(
object

sender, System.EventArgs e)



{



}




private

void

cmdCancel_Click(
object

sender, System.EventArgs )



{




RedirectToMobilePage("main.aspx");



}



private

void

cmdSubmit_Click(
object

sender, System.EventArgs )



{




if
(txtTick
er.Text.Trim()

==

""

|| txtQuantity.Text.Trim()




== "" || txtPrice.Text.Trim() == "")





return
;




int

qty;



double

price;



bool

bs;




if
(selOrder.SelectedIndex == 0)





bs =
true
;
// buy order




else





bs =
false
;
// sell order




try

{





qt
y = Convert.ToInt32(txtQuantity.Text.Trim());





price = Convert.ToDouble(txtPrice.Text.Trim());





if
(qty <= 0 || price <= 0)

{






lblMessage.Text = "Quantity / price should be












greater than 0";






lblMessage.Visible =
true
;






return
;





}




}




catch
(Exception data)

{





string

x = data.Message;





lblMessage.Text = "Invalid data entered”;





lblMessage.Visible =
true
;





return
;




}




if
(bs ==
true
)
// buy order

{





if
(!Order.CheckFunds(Convert.ToInt32(








Session["Acco
untId"]),qty*price))
{






lblMessage.Text = "Insufficient funds ";






lblMessage.Visible =
true
;






return
;





}




}



31




if
(bs ==
false
)
// sell order
{





if
(!Order.CheckStocks(Convert.ToInt32(Session[





"AccountId"]),txtTicker.Text.Trim().ToUppe
r(), qty)){






lblMessage.Text = "Invalid data specified";






lblMessage.Visible =
true
;






return
;





}




}




int

oid = Order.PlaceOrder(Convert.ToInt32








(Session["AccountId"])











,txtTicker.Text.Trim().ToUpper(),bs,qty,price);




if
(oid <= 0){





lblMessage.Text = "Order submission failure";





lblMessage.Visible =
true
;




}




else

{





lblCOrder.Text = "Order No: " + oid;





lblCTicker.Text = "Ticker: " +









txtTicker.Text.Trim().ToUpper();





lblCQuantity.Text = "Quant
ity: " +








txtQuantity.Text.Trim();





lblCPrice.Text = "Price: " + txtPrice.Text.Trim();





ActiveForm = frmConfirm;








}



}



private

void

cmdMain_Click(
object

sender, System.EventArgs e)



{




RedirectToMobilePage("main.aspx");



}


}

}

3.4.5

Po
rtfolio

web Page

3.4.5.1

Html Code

(portfolio.aspx)

<%@ Page language="c#" Codebehind="portfolio.aspx.cs"

Inherits="StockTradeMobile.portfolio" AutoEventWireup="false" %>

<%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls"

Assembly="System.W
eb.Mobile" %>

<HEAD></HEAD>

<body>

<mobile:stylesheet id="Stylesheet1" ReferencePath="Styles.ascx"



runat="server"></mobile:stylesheet>

<mobile:Form id="frmPortfolio" StyleReference="Form" runat="server">

<mobile:ObjectList id="lstPortfolio" runat="serve
r"





LabelField="ticker"></mobile:ObjectList>

<mobile:Command id="cmdMain" Format="Link" Runat="server">



Back to Main</mobile:Command>

</mobile:Form>

</body>

3.4.5.2

Code behind (
portfolio
.aspx.cs)

using

System;

using

System.Collections;

using

System.Componen
tModel;

using

System.Data;

using

System.Drawing;

using

System.Web;



32

using

System.Web.Mobile;

using

System.Web.SessionState;

using

System.Web.UI;

using

System.Web.UI.MobileControls;

using

System.Web.UI.WebControls;

using

System.Web.UI.HtmlControls;

using

Sto
ckTrade.Components.BLL;

namespace

StockTradeMobile

{


public

class

portfolio : System.Web.UI.MobileControls.MobilePage


{



protected

System.Web.UI.MobileControls.ObjectList

lstPortfolio;



protected

System.Web.UI.MobileControls.StyleSheet Stylesheet1;



protected

System.Web.UI.MobileControls.Command cmdMain;



protected

System.Web.UI.MobileControls.Form frmPortfolio;



private

void

Page_Load(
object

sender, System.EventArgs e)



{







if

(!IsPostBack)

{





ArrayList arr =
new

ArrayList();





lstPortf
olio.DataSource =Portfolio.getPortfolio








(
Convert.toInt32(Session[“AccountId”])
);





lstPortfolio.DataBind ();




}



}



private

void

cmdMain_Click(
object

sender, System.EventArgs e)



{




RedirectToMobilePage("main.aspx");



}


}

}



4.0

References

[
1] Duthie, ASP.NET Programming with Micsrosoft Visual C# .NET Step By Step,

Redmond: Microsoft Press, 2003.

[2] Jones, Freeman, C# For Java Developers, Redmond: Microsoft Press, 2003.

[3] Walther, ASP.NET Unleashed (2nd Edition), Indianapolis: Sams Publis
hing, 2004.

[4] Onion, Essential ASP.NET with Examples in C#, Boston: Addison Wesley, 2003.


[5] Dietel, Deitel, Listfield, Neito, Yaeger, Zlatkina, C# How to program, New Jersey:

Prentice Hall, 2002.

[6] www.msdn.microsoft.com, Microsoft Devel
oper Network (MSDN).