lap trinh theo kien truc 3 lop

Download Lap Trinh Theo Kien Truc 3 Lop

Post on 26-Sep-2015

223 views

Category:

Documents

4 download

Embed Size (px)

DESCRIPTION

fuck thay`

TRANSCRIPT

  • LP TRNH THEO KIN TRC 3 LP/TNG

    (3-TIERS ARCHITECHTURE)

    Xy dng phn mm theo kin trc 3 lp:

    Trc y, i vi cc phn mm c s dng lin quan n dliu, thng khi lm ngi lp trnh

    thng tch hp vic giao tip vi ngi s dng , x l ri ghi xung d liu trn cng mt form (y l m

    hnh mt lp). Nhng trong kin trc 3 lp (m hnh 3 lp), phi c vic phn bit rch ri gia cc lp ny.

    M hnh 3 lp c th c m t nh sau :

    Lp Presentation: Lp giao din (giao tip vi ngi s dng) : ch thun x l vic giao tip vi ngi

    s dng, nhp xut, m khng thc hin vic tnh ton, kim tra, x l, hay cc thao tc lin quan

    n c s d liu.

    Lp Business Logic: Lp x l nghip v, lp ny chuyn thc hin cc x l , kim tra cc rng buc,

    cc qui tc ng x ca phn mm , cc chc nng ch yu, Vic thc hin ny c lp vi cch thit

    k cng nh ci t giao din. Thng tin cho lp ny thc hin cc x l ca mnh c ly t lp giao

    din.

    Lp Data Access: Lp d liu, lp ny chuyn thc hin cc cng vic lin quan n lu tr v truy

    xut d liu ca ng dng. D liu c th ly t c s d liu (Access, SQL Server ) hoc tp tin

    (text, binary, XML ). Lp ny thc hin kt ni trc tip vi c s d liu v thc hin tt c cc

    thao tc lin quan n c s d liu m phn mm cn.

  • Li ch ca lp trnh theo kin trc 3 lp:

    Vi m hnh ny, cc cng vic ca tng lp l c lp vi nhau, gim s gn kt gia cc thc th ca

    phn mm. Vic thay i mt lp khng lm thay i cc lp cn li, thun tin hn cho qu trnh ti pht

    trin v bo tr phn mm.

    Minh ha lp trnh theo kin trc 3 lp:

    Bc 1: To project mi trong Visual Studio t tn l project DTO (Data Transfer Object)

    Bc 2: Xy dng cc lp DanhMuc v lp SanPham.

    Danh mc l tn mt nhm cc sn phm gm 2 thuc tnh (m danh mc v tn danh mc). Mt danh mc

    s bao gm nhiu sn phm. Lp SanPham cha thng tin ca sn phm.

  • Lp DanhMuc.cs

    Lp SanPham.cs

    Bc 3: Build project DTO

    Bc 4: To thm mt project mi t tn l DataAcessTier

  • Bc 5: B sung reference cho project ny bng cch nhp chut phi vo tn project trong ca s Solution

    Explorer v chn Add Reference.

    Trong hp thoi xut hin chn DTO.

  • Bc 6: Xy dng lp DBConnection cho vic kt ni c s d liu ( y l Microsoft Access)

    Bc 7: Xy dng cc lp DAO

    Ch : Cc lp ny k tha t lp DBConnection, v khai bo using DTO.

    Lp DanhMucDAO

  • Lp SanPhamDAO

  • Bc 8: Build project DataAccessTier

    Bc 9: To mt project mi t tn l BusinessLogicTier

  • Bc 10: Tng t add reference DTO v DataAccessTier

    Bc 11: Thm cc lp BUS.

    Lp DanhMucBUS.cs

  • Lp SanPhamBUS.cs

    Build project.

    Bc 12: Thm mt project t tn PresentaionTier v Add Reference: DTO v BusinessLogicTier

  • Bc 13: To form MainForm

    Bc 14: Vit code cho MainForm nh sau:

  • Ch : phi khai bo cc s kin ca Form.

    Bc 15: To mt from mi t tn l SanPhamForm

    DataGridView

  • Bc 16: Vit code cho form

  • Bc 17: Copy file c s d liu mu dbSanPham.mdb vo th mc Debug ca poject ny.

    Bc 18: Chy v kim tra chng trnh.

    Bi tp: Vit thm chc nng cp nht v kim tra cc iu kin thm/xa/cp nht (nu c) ca chng

    trnh.