8B -»
FPT POLYTECHNIC H th ng bai cu
=" Cacn idung dah ctrong baitr c
Trang 6FGDs Ki ntrucbat ng PPT POLYTECHNIC trong ngd ng ASP.NET m [ ngtrìnhb y: ®(€ m các trang ASPNET qu n lý giao di n ng d ng = [ ng trung gian ®Q m các Ì ptruycpd lí uqu nlýtruycpd lu ng d ng sCĩth ch acácdđd it ngnghi pv và các quy † c nghi pv
"Vid : Dit ngnghi pv : Cacl pbi udi nth cth khach
Trang 7Bia hy, ‘ot vriversity
FPT sD mm L ptruyc p CSDL
“"C©ungc pph ngth ctruy xutd li ut CSDL
®Ph ngth cchèn, c pnh t,xĩad li us d ngcacki
thu t truy c pCSDLnh ADO.NET
= Nén d t trong folder App Code
D it ng Data Source - Dong goi ng d ng - Các kĩthu tl p trình ASPNET nâng cao 7
Trang 98B -» FPT POLYTECHNIC Object Data Source = Gi ng v i SQL data source, Object data source cung cpph ng pháp: ® Truy xu thi nth d lut CSDLchong ¡dùng ®C pnh t CSDL =» Khac ® Object data source cho phép phat tri n ngd ng CSDL theo ki ntrucbat ng
® Object data source truyc pd li uqual ptruyc pd li u SQL data source truy c p CSDLtr cti p
=mV icác ngdngnh,s d ng SQL data source mang | inhi ul ¡ích, khơng ph ivi t code C#
“mV icác ngd ngÌ n, nên thi tk theo ki ntruc ba
t ng Do do, néns d ng ObjectDataSource
D it ng Data Source - Đĩng gĩi ng d ng - Các kĩthu tl p trình ASPNET nâng cao
Trang 11BGG Thi tk
PPT POLYTECHNIC ngd ngtheoki ntrucbat ng
=" T ch c ngd ng trên theo ki n trúc bat ng,s d ng di u khi n ObjectDataSource d thao tác v ¡ CSDL
® [ ng trình bày: Web Form Default.aspx
# Hai đi u khi n objectDatasource
"Hai di ukhi n bu cd_ l¡ u (drop-down list và datalist)
Trang 13Demo Bi - -¬ Xayd ng ngd ng ProductList FPT POLYTECHNIC tl ki =» N i dung demo ®T ochu ik tn i trong File web.config ® [hi tk † giao di n ® [ ol pnghi pv : Category ®[ ol ptruyc pCSDL: = T ol p CategoryDB ®Truy xutd li ut CSDL
= Them ObjectDataSource, ch dnh CategoryDB lal ptruyc p d li u cho ObjectDataSource nay
=" Lién k t ObjectDataSource v i cac di u khi n
® ihêm ch cnăng c pnh td li uchodi ukhin ® ki m sốt | ¡ thao tác v ¡ CSDL
“Vị tmãx lýs ki n cho cács ki n ltemlnserted
Trang 14
8b Fpt University FPT POLYTECHNIC Chu ik tn ji =" T ochu ik tn itrong file web.config <connectionStrings>
<add name="HalloweenConnectionString" connectionString="Data
Source=localhost\sqlexpress;Initial Catalog=Halloween; Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
D it ng Data Source - Đĩng gĩi ng d ng - Các kí thu tl p trình ASPNET nâng cao 14
Trang 168B -»
FPT POLYTECHNIC L pnghi pv Category
= Khai bao cacthu ctinht ng ngv icácc tÌ yt CSDL va cac ham get, set c acacthu ctinh nay
public class Category
{
private string categoryID; private string shortName; private string longName; public string CategoryID
{
get { return categoryID; }
set { categoryID = value; }
public string ShortName
{
get { return shortName; } set { shortName = value; }
}
public string LongName
{
get { return longName; }
set { longName = value; }
}
public Category()
D ii ng Data Source - Dong gĩi ng d ng - Các kĩthu tl p trình ASPNET nâng cao 16
Trang 17a8 , FptUniversity
FPT POLYTECHNIC L ptruy c p CSDL CategoryDB
“ Cungc pcácph ngth ctruy xu t, thêm, c pnh t, xoad li uvatr v ki ud it ng DataOblect cho đi u khi n ObjectDataSource
®D ch dnh CategoryDB la! p truy c p CSDL
=Thém dong [DataObject(true)] vaotr cddng khai bao
Ip
D it ng Data Source - Đĩng gĩi ng d ng - Các kĩthu tl p trình ASPNET nâng cao 17
Trang 18FPT POLYTECHNIC L p truy c p CSDL CategoryDB
=" Cacph ngth cc aCategoryDB
®*Lychuiktnid = cl u trong file web.config
Trang 208b Fpt University FPT POLYTECHNIC Ph ngth ctruy xu td lu = Truy c p CSDLtheo ki ntruck tn is d ngdata reader [DataObjectMethod(DataObjectMethodType Select) ] public static List<Category> GetCategories() t
List<Category> categoryList = new List<Category>();
SqlConnection con = new SqlConnection(GetConnectionString());
string sel = "SELECT CategoryID, ShortName, LongName " + “FROM Categories ORDER BY ShortName”" ;
Trang 21GD evry ———s Ph ngth cthémd li uvao CSDL [ DataObjectMethod(DataObjectMethodType Insert) | public static int InsertCategory(Category category) {
SqlConnection con = new SqlConnection(GetConnectionString()); string ins = "INSERT INTO Categories "
+ " (CategoryID, ShortName, LongName) "
Trang 228b Fpt University FPT POLYTECHNIC Ph ng th cc p nh t CSDL [ DataObjectMethod(DataObjectMethodType.Update) | public static int UpdateCategory( Category category) {
SqlConnection con = new SqlConnection(GetConnectionString()); string up = "UPDATE Categories "
Trang 238B -» FPT POLYTECHNIC Ph ng th c xĩa CSDL [DataObjectMethod(DataObjectMethodType.Delete) |] public static int DeleteCategory(Category category) {
SqlConnection con = new SqlConnection(GetConnectionString()); string del = "DELETE FROM Categories "
+ "WHERE CategoryID = @CategoryID " + "AND ShortName = @ShortName " + "AND LongName = @LongName ";
Trang 24GD FPT POLYTECHNIC Truy xu td li ut CSDL = Them ObjectDataSource ee BERR me dt bai sa skaakeiet Cubs vì Asp ude dirsaluny lus te appinalivn ————— (1) Le) mm 3np # C@:P'o:1.C:z~*LJ¿ cet€2)zf/.z2, 'ét.r^ 3 Jat3»et - -| ƒ” Show ely dzta com cenerts Dheawe a mesnces (ort neqonss runs Late ches 2F/> =| Ti Ch nl ptruy | ~ 3 | c pCSDL (2) Ch nph ngth ctruy
c p CSDL trong cac tab
SELECT, INSERT Previene | Nest» } | Tinh | | Carel |
D it ng Data Source - Đĩng gĩi ng d ng - Các kĩthu tl p trình ASPNET nâng cao 24
Trang 26ago Fpt University
FPT POLYTECHNIC Ma aspx c a Object data source
Trang 278B ‹ Them ch cnang PPE POLYTECHNIC c pnh td li uchodi ukhi n
= Thém cac button edit, delete cho GridView = Thém button Insert cho Details
=m) tch d m cdnhcho DetailsView la Insert (gan thu c tinh DefaultMode = Insert)
D it ng Data Source - Đĩng gĩi ng d ng - Các kĩthu tl p trình ASPNET nâng cao 27
Trang 28a8 ir Fpt University
FPT POLYTECHNIC Ki m soat! ithaotacv i
m ihêm s ki n RowUpdated, RowDeleted cho GridView = Thems_ ki nItemlnserted cho DetailsView
D it ng Data Source - Đĩng gĩi ng d ng - Các kĩthu tl p trình ASPNET nâng cao
hoclaptrinhweb.com
Trang 298b Fpt University
FPT POLYTECHNIC Ph ngth cx lýs ki nRowUpdated
protected void GridView1_RowUpdated(
Object sender, GridViewUpdatedEventArgs e)
= "A database error has occurred.<br /><br />" + e.Exception.Message; if (e.Exception.InnerException != null) lblError.Text += "<br />Message: + e.Exception.InnerException.Message; ndled = true; ode = true; edRows == @)
= "Another user may have updated that category.’
Trang 308b Fpt University
FPTPOLYTECHNC Ph ngth cx lýs ki nRowDeleted
protected void GridView1_RowDeleted(
object sender, GridViewDeletedEventArgs e) { if (e.Exception != null) { lblError.Text = "A database error has occurred.<br /><br />" + e.Exception.Message; if (e.Exception.InnerException != null) lblError.Text += "<br />Message: " + e.Exception.InnerException.Message; e.ExceptionHandled = true; } else if (e.AffectedRows == @)
lblError.Text = "Another user may have updated that category " + "<br />Please try again ;
}
D it ng Data Source - Đĩng gĩi ng d ng - Các kĩthu tl p trình ASPNET nâng cao 30
Trang 318b Fpt University
rrrrorrrrcmicPh ngth cx lýs ki nlteml nserted
protected void DetailsView1_ TtemTnserted(
Trang 33a8 i Fpt University
FPT POLYTECHNIC Tri nkhai ngd ng ASP.NET
= Tri n khai (Deploy) la qua trinh copy m t ng d ng web ASPNETt h th ng phattrin ngd ngt ¡server ch y
ng d ng
“mBaph ng pháp trí nkhai ng d ng:
® [ri n khai Xcopy
® [ri n khai t¡ n biên dch ® [ o Web Setup Project
D it ng Data Source - Đĩng gĩi ng d ng - Các kĩthu tl p trình ASPNET nâng cao
hoclaptrinhweb.com
Trang 34GD viv
FPT POLYTECHNIC Tri n khai XCo DY
= Copy toanb Filengu nc a ngd ngt | Server = Hai cach tri n khai Xcopy
®S dng! nh Xcopy
®S dng! nh Copy Web site trong Visual Studio
=" Ph ng pháp này th chi nkhad
Trang 35GD viv Demo
FPT POLYTECHNIC tri n khai XCo py
=" M website trong visual studio
= Ch n Copy Web Site trong menu Website
= Click vao Button Connectd m h ptho i Open Web site d ch nv tricopy filed n
=» Ch ncac File mu ncopy vas d ng button -> d copy file in: nt yp VA DaLz5 7 Peet b
` penne [aeons — mann arene F ế | cù Local Internet Information Server
E | Fite Select the Web site you want to opzn ba x
x - R System
VẬN Senne Wet nile [a] [x] a] Reermenle Wists site: [a F GH Luce! Web Servers 3 Anak AĐ sil S⁄i-lin ShiecflatsSnuersTo< = 4 #Ÿ Dris-lI Vách Site
2 Local IS sports tient
Trang 368B -» NN llll
FPT POLYTECHNIC Trị n khai ti n biên d ch
=» Biên dch các trang c a ngd ng, sau đĩ các file assembly ti n bien dch d c copy t† | server
= Hai cach tri n khai ti n bién dch
®S dng! nh Publish Web Site trong Visual Studio ®S dng! nh aspnet_compilert c as dong! nh
= Tri n khai ti n bién dch conhi u udi mh ntri n khai
Xcopy
® Tang hi unangc ang idungd utiéntruyc pd n site
*Bomth nvifilengu nkhéng d ccopyt i server
D it ng Data Source - Đĩng gĩi ng d ng - Các kĩthu tl p trình ASPNET nâng cao 36
Trang 37a8 a Fpt University Demo
FPT POLYTECHNIC Tri n khai ti n bien d ch
= Trong Visual Studio Ch n Publish Web Site trong menu
Build
Publish Web Site | 9 mnt
Target Location: (ftp:// , http:// or drive:\path)
g\Documents\Visual Studio 2010\Projects\ ObjectDataSourceT est\PrecompiledWeb\ ObjectDataSource est
Allow this precompiled site to be updatable
N uch ncheckbox, cac
- - - file ngu ns đ ctri n
EF Emit debug information khai cùng các file cĩ th
Use fixed naming and single page assemblies
Enable strong naming on precompiled assemblies th cthi
Trang 38GD viv
FPT POLYTECHNIC T o Web Setup Project
mPh ngphapnayt oram tb cài theo chu n
Windows,s d ngớ cài đt ngd ng Web lênm t I IS Server
=S d ngkhitri nkhaim t ngd ng trên nhi u server # Phién b n Visual Web Developer Express khong h tr
ph ng phap tri n khai nay
D it ng Data Source - Đĩng gĩi ng d ng - Các kĩthu tl p trình ASPNET nâng cao 38
Trang 398B -» Demo
FPT POLYTECHNIC T o Web Setu p Pro] ect
=" Ch n File -> Add -> New Project d hi nth h ptho |
Add New Project `
|] Installed Templates » Setup Project Setup and Deployment Type: ype: Setup uP anaweproymen and Deployment
| Visual C# Create a Windows Installer web projectto |
i Other Languages : which files can be added
4 Other Project Types Web Setup Project Setup and Deployment 4 Setup and Deployment
InstallShield LE 2 | Merge Module Project Setup and Deployment
Visual Studio Installer
Trang 408B - Demo
Ta T o Web Setup Project
Trang 41GD viv
FPT POLYTECHNIC T o Web Setup Project
m[ï och ngtrinh caid tb ng cach nh nchu t ph ¡ lên solution Explorer ch n Build
="B cait oran mtrongth m c Debug ho c Realease c a Web Setup Project, g m 2 file
® Setup.exe: File ch y
® Setup.msi: Ch at tc cacfiled ccaid t
“mÐĐ caid t ngd ng Web, Copy file Setup.exe va Setup.msi t i server vach y file setup.exe
D it ng Data Source - Đĩng gĩi ng d ng - Các kĩthu tl p trình ASPNET nâng cao 41
Trang 42GD viv
FPTPOLYTECHNIC Ƒ OVà€ uhinhth m c otrong lIIS
mU) Clientcĩth truyc pđ n server, các file ng d ng ph iđ ccopyd nth mcg cc a Web server
(C:\inetoub\wwwroot)
=D Client coth truyc pd nm t website khong n m trongth m cgc,tat om tth mec otrong lIS ở tr t ith m cch a các file c a website
D it ng Data Source - Đĩng gĩi ng d ng - Các kĩthu tl p trình ASPNET nâng cao 42
Trang 43ago Fpt University
D © mì O
FPTPOLYTECHNIC T OVäC€ uhìnhth m c otrong lIS7
=Cacb ct ovac uhinhth mc o
®*T oth moc _ o (Virtual Directory) trong IIS ®*Chuy nth mc othanh ngd ng
®C uhinh xacth c ® T o Application Pool
® Gan Applicaton Pool cho ng d ng ® Kich ho t directory browsing
eThi tl ptrang ch ym cdnh
D it ng Data Source - Đĩng gĩi ng d ng - Các kĩthu tl p trình ASPNET nâng cao 43
Trang 44a8 , Fpt University
De m O
FPT POLYTECHNIC Tovàc uhìnhth mc o trong IIS7
“m[ oth mec o trong lIS
ôđM IIS: Vao Run -> Inetmgr -> OK
Trang 458B -» Demo FPT POLYTECHNIC Tovàc uhìnhth mc o trong IIS7 “m Chuy nth m c othành ng d ng ®Nh n chu tph ivàoth m c o trén IIS GO see ee nes File View Help " " Connections #1 ® Ch n Convert to Application a i Application Pools « (9) Stes @ Default Wen Si (5 espnet_cii (D Test BP WedSetup2 > Ug) VirtualDirectoryTest| B *rnlnre Fdit Permiscors @ Convert to Application (Geld Application
nl Add Virtual Directory
Trang 468B -5 Demo
FPT POLYTECHNIC
=» C u hình xácth c
® Ch n Authentication trong vung giao di n chinh ® Thay d itr ng thai Enable/Disable ™ Authentication 4S)
Group ky: No Grouping
Narre Sratus Resnorse Tyn=
Anonymous Authenticatior Enakled
ASP.NET Impersoretion Cisab ed
Ligiore Furns Authernticelivn EisaÙb củ =TTP šC2 Loyin/Red reek
NT a Hire -2 Ege beak Mann
we 2N — |
y = > = = View Vein
pil ape Ằ << [4] le {af l= tơi MLanege Applic ation
pi can Mel HEL BRE Rew HE uel Apyinabion
rm c Datecer Completion taqee ohaliv atin Ferree on Biesexe: đun ai xe
c - lø] nđee.=+ 2 my
at a Leg & Le} Novarced Set rer
EeuliseSy Pagasuad Son San SMTPE su Rin
Sontrets Cniech
mr
; & @ jd a & & A
au ^.:n:zmhc Comensser L+f:.IE -€rtorv - EF'2*212q +inđ:r
Recumat inary Moy pings
_ es
<= 8 # AY | Bb
HII Logemy WIM Iyper Modak = Uulpul Regaai SSL Sdlinge