Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Communica/on
in
Visual
Studio/C#
using
3-/er
Arcitecture
The
examples
uses
ADO.NET
3-/er/layer
Architecture
Presenta/on
Tier
PL
BL
Logic
Tier
Data
Source
DAL
Data Tier - DL
Modularized
h=p://en.wikipedia.org/wiki/Mul//er_architecture
3-/er/layer
Architecture
Presenta4on
Tier
This
is
the
topmost
level
of
the
applica/on.
The
presenta/on
/er
displays
informa/on
related
to
such
services
as
browsing
merchandise,
purchasing
and
shopping
cart
contents.
It
communicates
with
other
/ers
by
which
it
puts
out
the
results
to
the
browser/client
/er
and
all
other
/ers
in
the
network.
In
simple
terms
it
is
a
layer
which
users
can
access
directly
such
as
a
web
page,
or
an
opera/ng
systems
GUI
Applica4on
4er
(business
logic,
logic
4er,
data
access
4er,
or
middle
4er)
The
logical
/er
is
pulled
out
from
the
presenta/on
/er
and,
as
its
own
layer.
It
controls
an
applica/ons
func/onality
by
performing
detailed
processing.
Data
4er
This
/er
consists
of
database
servers.
Here
informa/on
is
stored
and
retrieved.
This
/er
keeps
data
neutral
and
independent
from
applica/on
servers
or
business
logic.
Giving
data
its
own
/er
also
improves
scalability
and
performance.
h=p://en.wikipedia.org/wiki/Mul//er_architecture
3-/er Architecture
Presenta/on Tier
Presenta/on Tier
Presenta/on Tier
Logic
Tier
Data
Access
Tier
Stored
Procedures
Database
Data Tier
Web
Web
Server
Services
Business/
Data
Logic
Tier
Stored
Procedures
Data
Source
Data
Tier
TFS
Cient
Presenta/on
Tier
Client
Client
Client
Internet
Presenta/on Layer
Firewall
Presenta/on Layer
Presenta/on Layer
Client
Client
Web Service
Presenta/on Layer
Presenta/on Layer
Presenta/on Layer
Web
Server
Server
Stored
Database
Procedures
Server
Business
Logic
Data
Tier
We
are
going
to
create
the
Database
/
Data
Layer/Tier,
including:
1. Tables
2. Views
Note!
Install
them
in
this
order
3. Stored
Procedures
4. Triggers
5. Script
for
some
Dummy
Data
Download
Zip
Files
with
Tables,
Views,
Stored
Procedures
and
Triggerse
in
order
to
create
the
Data
Tier
in
SQL
Server
(The
ZIP
File
is
located
on
the
same
place
as
this
File)
11
Data
Tier
Triggers
Stored
Procedures
Views
Tables
Data Tier
SQL Server
12
Database Tables
13
14
15
Logic
Tier
ASP.NET
Web
Forms
Presenta/on
Tier
WinForms
Presenta/on Tier
Presenta/on Tier
Logic Tier
Data Tier
Purpose:
All
the
Apps
should/could
share
the
same
Logic
Tier
To
make
your
Apps
easier
to
maintain
and
extend
etc.
Database
17
18
LogicTier
19
StudentData.cs
20
21
22
Code
(StudentData.cs):
using
System.Data.SqlClient;
using
System.Data.SqlTypes;
using
System.Data;
namespace
Tuc.School.LogicTier
{
public
class
StudentData
{
public
DataSet
GetStudentDB(string
connectionString)
{
string
selectSQL
=
"select
StudentName,
StudentNumber,
SchoolName,
ClassName,
Grade
from
StudentData
order
by
StudentName";
//
Define
the
ADO.NET
objects.
SqlConnection
con
=
new
SqlConnection(connectionString);
SqlDataAdapter
da
=
new
SqlDataAdapter(selectSQL,
con);
DataSet
ds
=
new
DataSet();
da.Fill(ds);
return
ds;
}
}
}
23
25
Presenta/on
Layer
Desktop
App:
WinForms
We
assume
the
App
will
be
used
only
in
the
local
LAN
(or
local
on
the
same
computer
where
the
database
is
located)
and
that
we
have
direct
access
to
the
Database)
Label
DataGridView
27
28
29
30
Create Form
Label
DataGridView
32
33
WinForm
Code
using
System.Configuration;
using
Tuc.School.WinFormApp;
namespace
WinFormApp
{
public
partial
class
Form1
:
Form
{
private
string
connectionString
=
ConfigurationManager.ConnectionStrings["SCHOOLConnectionString"].ConnectionString;
public
Form1()
{
InitializeComponent();
}
private
void
Form1_Load(object
sender,
EventArgs
e)
{
FillStudentGrid();
}
private
void
FillStudentGrid()
{
DataSet
ds
=
new
DataSet();
StudentWinForm
studentList
=
new
StudentWinForm();
ds
=
studentList.GetStudent(connectionString);
dataGridViewStudentInformation.DataSource
=
ds.Tables[0];
}
}
}
Note!
Connec/onString
is
stored
in
App.cong
34
35
36
Test it
It works!!!
37
38
Recommended
Li=erature
Tutorial:
Introduc/on
to
Database
Systems
h=p://home.hit.no/~hansha/?tutorial=database
Tutorial:
Structured
Query
Language
(SQL)
h=p://home.hit.no/~hansha/?tutorial=sql
Tutorial:
Using
SQL
Server
in
C#
Tutorial:
Introduc/on
to
Visual
Studio
and
C#
h=p://home.hit.no/~hansha/?tutorial=csharp
39
E-mail:
hans.p.halvorsen@hit.no
Blog:
hUp://home.hit.no/~hansha/
40