You are on page 1of 70

GIO TRNH

QUN TR CSDL VISUAL FOXPRO

Mc lc

CHNG 1: GII THIU V H QUN TR CSDL VISUAL FOXPRO CHNG 2: THAO TC VI BNG D LIU CHNG 3: SP XP-TM KIM-THNG K CHNG 4: LP TRNH TRN VISUAL FOXRO CHNG 5: FORMS CHNG 6: REPORTS CHNG 7: TO MENU V QUN L N

www.Updatesofts.com 2006

Chng 1: GII THIU V H QUN TR CSDL VISUAL FOXPRO


1.1 Tng quan v FoxPro v Visual FoxPro 1.1.1 Gii thiu Foxpro l h qun tr c s d liu dng gii quyt cc bi ton trong cc lnh vc qun l. FoxPro c tha k v pht trin trn phn mm DBASE III PLUS v DBASE IV, nhng sn phm ni ting ca hng ASTON-TATE. Khi cc cng c lp trnh v cc ng dng trn mi trng Windows ngy nhiu th Microsoft cho ra i cc phin bn FoxPro 2.6, chy c trn hai mi trng DOS v Windows. Visual Foxpro l sn phm ca hng Microsoft, n c k tha t Foxpro for Windows, l mt trong nhng cng c tin li gii quyt cc bi ton trong lnh vc qun l cho nhng ngi chuyn nghip v khng chuyn nghip. T khi pht trin n nay, Hng Microsoft cho ra i nhiu phin bn Visual Foxpro 3.0, 4.0, 5.0, 6.0. 1.1.2 Khi ng Visual Foxpro. Sau khi ci t Visual FoxPro, ta c th khi ng n bng cch thc hin file FoxProw.exe hoc file vfp.exe i vi Visual Foxpro theo cc cch sau: + Kch chut vo biu tng ca FoxPro hoc Visual Foxpro trn Desktop + Chn menu Start/Program, chn Microsoft Visual Foxpro v kch chut vo . Mn hnh Visual Foxpro sau khi khi ng:

Thanh tiu

Thanh Menu

Thanh cng Ca s lnh

Mn hnh Visual FoxPro sau khi khi ng: 1.1.3 Cc ch lm vic

Visual FoxPro c 2 ch lm vic; ch tng tc (interactive) v ch chng trnh (program). Ch tng tc: L ch tr li tng cu lnh mt ca ngi s dng, trong ch ny c 2 hnh thc a cu lnh: * a cu lnh qua menu h thng (system menu). * a cu lnh t ca s lnh (command window). Ch chng trnh: Cc cu lnh trong ca s lnh c th tp trung thnh mt file v lu trn a (gi l file chng trnh ngun). Khi mun thc hin cc lnh trong chng trnh ny, ti ca s lnh a vo cc cu lnh: DO < tn chng trnh > thot khi Visual FoxPro, ti ca s lnh s dng lnh QUIT 1.2 Cc khi nim c bn 1.2.1 Kiu d liu i tng x l ca V. FOXPRO l d liu, qun l v khai thc tt cc d liu ny, tu theo tnh cht, V.FOXPRO phi chia d liu thnh nhiu kiu d liu khc nhau: kiu s (numberic), kiu chui (character), kiu ngy thng (date), kiu l lun (logical), kiu b nh (memo), kiu hnh nh (picture). a. Kiu s - Numeric (N): dng biu din cc s liu mang gi tr s hc v c nhu cu tnh ton nh trong k ton, qun l, .... Mi d liu kiu s chim ti a 20 ch s gm c phn nguyn, phn thp phn v du chm thp phn. b. Kiu s - Float (F): Dng biu din s l cc s c du chm ng nh: 2.03e5 (2.03 x 105), thng c s dng trong cc chng trnh thuc lnh vc khoa hc k thut, ... c. Kiu chui - Charater (C): Cha cc s liu l t hp mt s bt k cc k t ASCII nh tn, h hoc l s nhng khng c nhu cu tnh ton nh s chng minh, a ch, s phng, ... Mi d liu kiu chui c di ti a 255 k t (mi k t chim 1 byte trong b nh). d. Kiu ngy thng - Data (D): Dng cho nhng s liu dng ngy thng nh ngy sinh, ngy n,.... l nhng s nguyn dng "yyyymmdd" khi hin th ra bn ngoi s c chuyn thnh dng ngy thng bnh thng nh mm-dd-yy, dd-mm-yyyy,... tu theo yu cu ca ngi

lp trnh. di c nh ca d liu kiu ngy l 8 k t. e. Kiu logic - Logical (L): Dng cho nhng d liu ch c mt trong hai trng hp hoc ng (T) hoc sai (F) nh gii tnh, i tng u tin, ... di c nh ca d liu kiu l lun l 1 k t. f. Kiu ghi nh - Memo (M): D liu kiu ghi nh l mt on vn bn c di ln hn 255 k t, nh khen thng, l kch, qu trnh cng tc,... di khai bo l 10 nhng ni dung thc s ca kiu ghi nh l tu , chng c lu tr trong mt tp tin khc c cng tn nhng phn m rng l .FPT (FoxPro Text). g. Kiu tng qut - General (G): Dng cha d liu nh bng tnh, m thanh,... h. Kiu hnh nh - Ficture (P): D liu lu di dng hnh nh .BMP, thng c dng trong cc chng trnh "qun l nh s", "nhn dng",... 1.2.2 Cc php ton a. Php ton s hc: c thc hin trn cc d liu kiu s, gm cc php ton: Php ton -, + ** hay ^ ,/ % +, ngha du m v dng lu tha nhn, chia phn d (modulo) cng, tr V d +5, -7 5**2,5^2 25, 5/7 25%5 10-2, 45+4

u tin cc php ton theo th t nu trn, c th thay i th t tnh ton bng cch t chng trong 2 du ngoc n ( ) nh cc quy tc tnh ton s hc thng thng. b. Php ton chui: Dng x l cc d liu kiu chui. Php ton ghp ni (+): dng ghp 2 chui cnh nhau, kt qu ca php ton l mt d liu kiu chui. V d: Trung tm' + 'Tin hc' -----> 'Trung tm Tin hc'

Php ton ghp ni (-): dng ghp 2 chui cnh nhau v di chuyn cc du cch chui th nht (nu c) ra cui chui to thnh. V d: 'Trung tm ' - ' Tin hc' -----> 'Trung tm Tin hc '

Php ton $: kim tra chui bn tri c nm trong chui bn phi khng. Kt qu ca php ton c kiu logic. V d: 'ab' $ "ABab" cho gi tr .T. nhng 'ab $ "AaBb" cho gi tr .F. c. Php ton ngy: Hai d liu kiu ngy c th tr (-) cho nhau cho khong cch i s gia 2 ngy. V d: {01/08/2003} - {05/09/2003} -------> - 35 {01/08/2003} - {05/07/2003} -------> 25 Mt d liu kiu ngy c th cng (+) hay tr (-) mt s nguyn cho kt qu l mt d liu kiu ngy. V d: {01/08/2003}+ 10 -------> {11/08/2003} {01/08/2003}- 20 -------> {12/07/2003} Ch : Hai d liu kiu ngy khng th cng (+) cho nhau. Mt s khng th tr (-) vi mt d liu kiu ngy. Vic din t th t ngy (D), thng (M), nm (Y) trong mt d liu kiu ngy cn ph thuc vo thi im hin ti ang theo h thng ngy thng no. (1) Lnh SET DATE FRENCH |AMERICAN| JAPAN: Cho php thit lp d liu dng ngy theo kiu Php|M|Nht. (2) SET CENTURY ON|OFF: Quy c nm c mt d liu dng ngy c biu din theo dng hai s (mc nh) hay dng bn s. Nu SET CENTURY ON th nm c biu din theo dng bn con s, nu SET CENTURY OFF (dng mc nh) th nm c biu din theo dng hai con s. (3) Lnh SET MARK TO <bthc C>: n nh k t phn cch ngy thng, nm l <bthc C>. Dng lnh SET MARK TO tr v k t phn cch ngy thng mc nh.

d. Php ton quan h: dng so snh hai gi tr ca hai biu thc cng kiu Php ton < > = == ngha nh hn ln hn bng bng chnh xc Php ton <>, ! <= => khc nh hn hay bng ln hn hay bng ngha

Hai d liu kiu s c so snh da theo biu din ca chng trn trc s. Hai d liu kiu ngy c so snh da theo biu din ca chng theo chiu ca thi gian. Trong kiu logic, Visual FoxPro quy c: .T.<.F. Hai d liu kiu chui c di bng nhau c so snh da theo nguyn tc sau: u tin so snh 2 m ASCII ca 2 k t u ca hai chui, nu bng nhau th so snh tip. V d: 'ABCD' < 'ABCE' -----------> .T. 'a' < 'A' ------------> .F.

Trng hp hai chui c di khc nhau, th vic so snh da vo vic thit lp mi trng SET EXACT ON/OFF, ngha l: Nu SET EXACT ON th 'AB' = 'AB ' -----------> .F.

Nu SET EXACT OFF th 'ABCD' = 'AB' -----------> .T. e. Php ton logic: Visual FoxPro c 3 php ton logic: NOT; AND; OR NOT hay ! AND OR 1.2.3 Ton hng Ton hng l cc d liu tham gia vo cc php ton. V d: del=b^2 - 4*a*c th b,2,4,a,c l cc ton hng. 1.2.4 Hng : ph nh ca ton hng theo sau. : cho gi tr .T. nu c hai ton hng u .T. : cho gi tr .F. nu c hai ton hng u .F.

L i lng c gi tr khng i trong thi gian chng trnh thc hin. Tr kiu d liu memo th mi kiu d liu u c hng ca n. Hng kiu s: nh -2.5, 100, 4.14 Hng kiu chui: hng loi ny phi trong hai du "..." hoc '...' hoc [...], c di ti a khng qu 253 k t. V d: "abc"; tng hp', '123',....... Hng kiu ngy: phi c t trong cp du {...} V d: {01/01/96}; {}: ngy rng. Hng logic: ch c 2 gi tr .T. v .F. 1.2.5 Bin Bin l i lng dng lu tr d liu trong qu trnh tnh ton. Bin c hai c trng chnh: tn bin v gi tr ca bin. Tn bin c t theo nguyn tc: di khng qu 10 k t, bt u phi l ch ci hoc du _ phn cn li l t hp ca bt k cc ch ci, ch s hoc du _. Tn bin khng nn t trng tn cc t kho ca Visual FoxPro, tn bin c th vit bng ch in hoa hay ch thng. Visual FoxPro hiu kiu ca bin l kiu ca gi tr m n ang mang. S lng ti a ca bin c php s dng l 2048 bin. Visual FoxPro chia bin lm 3 loi: a. Bin b nh: Gi chung l bin, do ngi s dng to ra trong b nh, khi khng s dng na c th gii phng tit kim b nh. V d: hsl = 3.12 ngaysinh = {01/01/88} b. Bin h thng: c to ra ngay t khi khi ng Visual FoxPro. C tn bt u bng du gch ni ( _ ) thng c s dng trong vn in n, ngi s dng khng th gii phng bin loi ny. c. Bin trng: Tn cc trng trong tp tin CSDL , n ch c ngha khi tp tin cha n c m ra s dng.

Nu c mt bin t trng vi mt bin trng th bin trng c u tin thc hin trc. Nu tn hi hai bin trng v bin b nh trng tn nhau, truy nhp n chng m khng s nhm ln, bn s dng quy cch sau cho bin b nh: M.<tn trng> hay M -> <tn trng> 1.2.6 Hm Hm l nhng on chng trnh c vit sn nhm thc hin mt cng vic no . Cc hm ny thng cho ra mt gi tr, nhng cng c hm ch thi hnh mt vic no m khng cho ra mt tr no c. V hnh thc hm c c trng bi tn hm v theo sau l cp du ( ) dng bao cc i s, cc i s ny t cch nhau bi du phy. Mt hm c th c nhiu i s hoc khng c i s no c nhng phi c ( ) theo sau. V d: Date ( ): cho bit ngy thng nm h thng. Sqrt(x): cn bc 2 ca x. C 2 loi hm: Hm c sn ca Visual FoxPro v hm t to do ngi s dng to ra. Chng ta s nghin cu vn ny k hn chng sau. 1.2.7 Biu thc Biu thc l tp hp ca mt hay nhiu thnh phn nh hng, hm, bin, php ton, du ngoc trn. Sau khi tnh ton biu thc s cho mt tr duy nht. Tr ca biu thc thuc v mt trong 4 kiu: N, C, D, L. Mt biu thc c th rt phc tp, tr ca biu thc c tnh theo nguyn tc sau: * Trong ( ) tnh trc, ngoi ( ) tnh sau, * Php ton u tin cao tnh trc. * Bn tri tnh trc, bn phi tnh sau. 1.2.8 T kho T kho l nhng t c Visual FoxPro s dng vo mt mc ch ring, ngi s dng khng c t tn trng vi cc t kho ny. Thng thng t kho l nhng ng t ng t ca lnh thc hin. Nu t kho c nhiu hn 4 k t th khi s dng ch cn ghi 4 k t u. V d: Cu lnh MODIFY COMMAND LUONG.PRG c 2 t kho l MODIFY v COMMAND c th vit gn l: MODI COMM LUONG.PRG 1.2.9 Lnh v chng trnh

Lnh l nhng yu cu thc hin mt nhim v no . Lnh trong Visual FoxPro thng l mt ng t, cng c trng hp l mt k hiu nh: !. ?, ... Tp hp cc lnh nhm t c mt mc tiu ra gi l chng trnh. Trong Visual FoxPro c 3 cch ban hnh lnh: a. Dng ca s lnh: Lnh c a vo ca s lnh, sau khi n Enter lnh c thi hnh ngay. Thi hnh xong mt lnh th lnh c c lu li trn ca s lnh c th s dng cho ln sau. Cch ny thng dng trong nhng tnh ton n gin kim tra kt qu ca lnh. b. Dng menu: Lnh c ban hnh bng cch kch hot menu tng ng, sau khi thi hnh xong cu lnh cng c lu li trn ca s lnh. Cch ny ch hn ch trong mt s lnh thng thng trn tp tin CSDL. c. Dng chng trnh: Son tho trc mt chng trnh gm nhiu lnh thch hp. Chng trnh c lu trn a di tn mt tp tin c phn m rng PRG. thc hin chng trnh ny, ti ca s lnh a cu lnh DO <tn file.PRG>. Sau khi n Enter chng trnh c np vo b nh v tng lnh c thc hin theo th t.

Bi thc hnh chng 1


1. Gi s c tp tin HSNV.DBF (c cu trc nh m t bi 1, thc hnh hai) trong c t nht 15 mu tin. a. Dng lnh SORT sp xp li tp tin HSNV.DBF sang mt tp tin mi HSNVSX.DBF theo ch tiu: Cc mu tin c sp xp theo tng n v (gim dn), trong mi n v th t tn, h c sp xp tng dn. b. M tp tin HSNVSX.DBF S dng lnh LIST lit k cc trng HOLOT, TEN, NGSINH, M_LUONG, MADV. S dng lnh USE ng tp tin li.

c. Lp 3 tp tin ch mc: FMASO.IDX theo trng MASONV, FDONVI.IDX theo trng MADV, FLUONG.IDX theo trng M_LUONG gim dn. - Bng cch thay th tp tin ch mc ch, hy lit k cc mu tin theo MASONV tng dn, theo MADV tng dn, theo M_LUONG gim dn. 2. Trong tp tin HSNV.DBF a. Dng lnh LOCATE: - Tm ngi c h tn l LE VAN NAM (gi s c h tn ny trong tp tin HSNV.DBF). Dng lnh DISPLAY cho hin ni dung ca mu tin ny, ri dng lnh EDIT sa li. - Tm nhng ngi phng Hnh chnh (MADV=HC), cho hin y thng tin ca nhng ngi ny. - Tm nhng ngi c mc lng > 310. b. Dng lnh SEEK tm kim ngi c MASONV=TCH01 (gi s m ny c trong tp tin HSNV.DBF). Cho hin ni dung ca mu tin ny. c. Cho bit a ch ca ngi c H tn l HO VAN HAO, sinh ngy 10/11/58 (bng hai cch: LOCATE v SEEK).

--------------------------------------------------------------------------

1.

CHNG 2:

THAO TC VI BNG D LIU

1.1. 2.1. KHI NIM

Bng d liu cha d liu theo dng dng v ct, mi dng c gi l mt mu tin (record), mi ct c gi l mt trng (field) ca bng. Mi bng d liu c lu tr trn a vi tn file c phn m rng mc nh l DBF, mi bng d liu c hai phn: cu trc v ni dung ca bng. V d: bng nhn vin (nhanvien.dbf) c cu trc sau:

Fieldname Hoten Gioitinh Ngaysinh NamLV Lylich

Type Character Logic Date Numberic Memo

Width 30 1 8 4 10

Decimal

Ni dung ca NHANVIEN.DBF Hoten Nguyen van A Le thi Nhan ................ Gioitinh .T. .F. ........ Ngaysinh 10/15/75 06/15/70 .......... NamLV 1999 1995 ......... Lylich Memo Memo .........

1.2. 2.2 FILE V KIU FILE TRONG VISUAL FOXPRO

2.2.1 Cc kiu file chnh ca Foxpro FoxPro c cc kiu file sau: *.dbf: *.idx: *.prg: *.dbc: *.dll: *.pjx: *.scx: *.vcx: File d liu File ch mc File chng trnh File c s d liu File th vin lin kt ng File d n File Form File th vin

2.2.2. Cch t chc mt file d liu

a. File d liu: L tp hp d liu phn nh v mt tp hp cc i tng qun l thng qua cc thuc tnh ca n. b. Bn ghi (Record): L mt b gi tr cc thuc tnh phn nh v mt i tng qun l. c. Trng (Field): L mt thuc tnh trong file d liu, mi trng c xc nh bi tn trng, kiu trng v kch thc trng. + Tn trng (Field name): Tn trng di ti a 10 k t bao gm ch ci, ch s, k t gch di, k t u tin ca tn trng phi l ch ci. + Kiu trng (Field type): Kiu trng c cc dng sau: C: Charater D:Date ....................... + Kch thc trng (Field Width): L khong b nh cn thit lu tr cc gi tr ca trng, kch thc ca trng ph thuc vo kiu trng: Kiu C: Kiu N: Kiu L: Kiu D: Kiu M: Currency: Ti a 254 Byte Ti a 20 Byte k c du thp phn Chim 1 Byte Chim 8 Byte di tu , chim 10 Byte khi khai bo Chim 8 byte N:Numberic M:Memo L:Logic G:General

+ Cu trc file: Mi t hp trng sp xp theo th t nht nh gi l cu trc ca file d liu, mi file d liu ch c mt cu trc c th. 2.2.3. Nguyn tc hot ng Chng ta ch c th truy nhp n cc phn t ca mt file DBF nu file c m bng lnh USE <tn file DBF>. mi thi im bt k, mi file DBF ang m s c mt mu tin hin thi, mu tin hin thi

l mu tin c th truy nhp vo thi im . Mu tin hin thi c tr n b con tr mu tin (record pointer). Mi mu tin ang m c 2 v tr c bit ch : u file v cui file. bit c con tr mu tin u hay cui file ta dng cc hm logic sau: . Hm BOF( ) (begin of file) cho gi tr .T. nu con tr mu tin cui file DBF ang m, ngc li hm cho gi tr .F. . Hm BOF( ) (end of file) cho gi tr .T. nu con tr mu tin cui file DBF ang m, ngc li hm cho gi tr .F. . S th t ca mu tin (record number - recno): m t s th t vt l ca mu tin trong tp tin c s d liu DBF. S th t ny do FoxPro qui nh mt cch tun t, c nh s t 1 n mu tin cui cng. Trong khi lm vic, nu xo mt mu tin th s th t ny cng t ng c cp nht theo cho ph hp. . Hm RECOUNT( ) dng bit s mu tin ca mt tp tin DBF ang m. . Hm RECSIZE( ) dng bit c kch thc ca mt mu tin. . Hm RECNO( ) cho bit s th t ca mu tin hin thi. . Kch thc ca cc mu tin ca mt file DBF u bng nhau.
1.3. 2.3. CC LNH C BN TRN FILE DBF 1.4. 2.3.1 Dng lnh tng qut

Lnh l mt ch th cho my thc hin mt thao tc c th. Mt lnh trong Foxpro ni chung c c php tng qut nh sau: Lnh [phm vi] [FIELDS <dsch trng>] [FOR <btL1>] [WHILE <btL2>] [FROM <tn file> / ARRAY <tn mng>] [TO print/tn file/dsch bin] Trong , Lnh: mt t kho, cho bit mc ch ca cng vic, phi vit u tin v c th vit 4 k t u nu lnh c nhiu hn 4 k t. V d: DISPLAY FIELDS HOTEN, HSLUONG DISP FIEL HOTEN, HSLUONG

Phm vi (Scope): ch nh phm vi cc mu tin chu s tc ng ca lnh, phm vi c th l: ALL: tt c cc mu tin trong file d liu u b tc ng ca lnh (nu c s

dng FOR th phm vi c hiu l ALL). NEXT <n>: n mu tin tip theo tnh t mu tin hin thi b tc ng ca lnh. RECORD <n> REST Lnh ch tc ng n mu tin th n Lnh s tc ng t mu tin hin thi cho n ht.

FIELDS <dsch trng>: lnh ch c tc dng trn nhng trng c tn c nu trong <dsch trng>. FOR <btL1>: mu tin no tho mn <btL1> mi b tc ng bi lnh. WHILE <btL2>: chng no <btL2> cn ng th lnh cn hiu lc. Ngha l, lnh s tc ng ln cc bn ghi tho mn biu thc logic i km (c gi tr l .T.) cho n khi gp mt bn ghi khng tho mn biu thc logic (c gi tr .F.) hoc n ht file d liu. Nu iu kin sai th lnh c dng ngay. Trong lnh nu va c FOR va c WHILE th mnh WHILE u tin thc hin trc. FROM <tn file>: tn ca file m t lnh ly s liu s dng cho file DBF ang m. TO PRINT/tn file/dsch bin: chuyn kt qu sau khi thc hin lnh n my in/file/bin. Cc mnh theo sau lnh c mt hay khng tu trng hp v khng cn phi vit theo th t nh nu.
1.5. 2.3.2 To bng d liu

C php:

Create <tn file DBF>

hoc

Chn File/New/<chn loi file d liu DBF> V d: create nhanvien && to bng nhanvien

Lc ny, mn hnh s xut hin hp thoi ta to cu trc bng Chn thm trng

Xa trng

Trong :

Name: Type: Width: Decimal:

Tn trng Kiu trng rng ca trng S ch s l sau phn du chm thp phn, phn ny ch s

dng cho d liu kiu s. Ch : - Cc tn trng khng c trng nhau, khng c trng vi t kho. - i vi d liu kiu s nu c phn thp phn th rng ca phn thp phn phi nh hn rng ca trng t nht l 2 n v. kt thc vic nhp cu trc ta n ng thi Ctrl+W, lc ny s nhn c hp thoi Lc ny: tr li <No> th s quay li ca s d liu. Khi kt thc vic nhp d liu, nhn t hp <Ctrl+W> lu file d liu ln a. Khi file d liu s c dng <tn file>.DBF Ch : nhp d liu cho trng MEMO, ta a con tr n hp memo ri nhn t hp phm Ctrl_PgUp, lc s xut hin ca s nhp d liu cho trng ny. Sau khi kt thc vic nhp d liu cho n, ta n t hp Ctrl+W ghi li.
1.6. 2.3.3 nh v con tr n mt bn ghi

phm

lnh, tr

li <Yes> tin hnh nhp cc bn ghi. Khi chn Yes s tip tc xut hin hp thoi nhp

a. nh v tuyt i C php: GO <N>|[TOP]|[BOTTOM] Tc dng: Dng chuyn con tr bn ghi n bn ghi c s hiu <n> c chi nh trong cu

lnh. + GO TOP: Dng chuyn con tr bn ghi v u file d liu. + GO BOTTOM: Dng chuyn con tr bn ghi v cui file d liu. b.nh v tng i C php: Skip [+|-] [<n>] Tc dng: Di chuyn con tr bn ghi v trc (-) hay sau (+) so vi bn ghi hin thi. Ch : Khi ch g lnh Skip th con tr bn ghi s c di chuyn v sau bn ghi hin thi mt n v.
1.7. 2.3.4 Ly d liu t bng

a. Lnh Display C php: display [<phm vi>] [fields<danh sch trng>] [For<bthc logic>] [While<bthc logic>] [on|off] Tc dng: Hin th ni dung ca cc bn ghi trong <phm vi> c ch nh v tho mn iu kin ca cc biu thc logic i sau FOR v WHILE nu c. Theo mc nh th tt c cc trng trong bng d liu s c hin th, nu c [field<danh sch trng>] th nhng trng c ch ra trong danh sch ny mi c hin th ln mn hnh. <phm vi> mc nh l bn ghi hin thi. V d: 1. Hin th tt c cc bn ghi ca bng d liu nhanvien: Use nhanvien Display all 2. Hin th tt c nhng ngi c nm lm vic (namlv) trc 1980 Display for namlv <1980 Ch : Trong cu lnh ca Fox, nu c mnh FOR th phm vi mc nh l ALL. b. Lnh LIST

C php:

List [<phm vi>] [fields<danh sch trng>] [For<bthc logic>] [While<bthc

logic>] [on|off] Tc dng: Hin th ni dung ca cc bn ghi nh lnh Display nhng mc nh ca lnh ny l ALL V d:1. Hin th tt c cc bn ghi ca bng d liu nhanvien: Use nhanvien List 2. Hin th tt c nhng ngi c nm lm vic (namlv) trc 1980 List for namlv <1980 c. Lnh ?|?? C php: ?|?? <danh sch biu thc>

Tc dng: Lnh ny tnh ton v cho hin th kt qu ca danh sch biu thc ln mn hnh. Ch : lnh ? trc khi in d liu th xung di 1 dng, cn lnh ?? th khng. V d: Cho hin th h tn ca ngi c s hiu l 5 ln mn hnh: Go 5 ? ho ten, hoten Ch : danh sch biu thc trong Fox c vit cch nhau bi du phy ,. V d: cho bit h tn, nm lm vic ca ngi c s hiu l 2: Go 2 ?ho ten:,hoten,nam lam viec:,namlv
1.8. 2.3.5 Chn, b sung bn ghi

a. Chn bn ghi C php: INSERT [BEFORE][BLANK] Tc dng: Chn mt bn ghi ngay sau bn ghi hin thi (nu c [Before]) vi ni dung c nhp vo. Nu c [BLANK] th s chn mt bn ghi trng.

V d: chn mt bn ghi vo sau bn ghi th 3: Go 3 Insert b. B sung bn ghi C php: APPEND [BLANK] Tc dng: chn 1 bn ghi vo cui bng d liu (gi tr c nhp vo), nu c tham s [BLANK] th s b sung mt bn ghi trng. 2.3.6 Sa cha ni dung bn ghi a. Lnh BROWSE: C PHP: BROWSE [FIELD<DSCH TRNG>] [FREEZE<DSCH TRNG>][NODELETE] [NOEDIT] [FOR<BTHC LOGIC>] TC DNG: HIN TH NI DUNG CA BNG D LIU, MI BN GHI C TH HIN TRONG MT HNG (DNG), TA C TH XEM V DI CHUYN HP SNG T TRNG NY QUA TRNG KHC, BN GHI NY SANG BN GHI KHC V C TH SA I NI DUNG CA TNG MU TIN TRONG BN GHI. V D: USE NHANVIEN BROWSE [FIELD<DSCH TRNG>]: CHO PHP CC TRNG TRONG DANH SCH NY C HIN TH TRN MN HNH, NU KHNG C THAM S NY TH TT C CC TRNG TRONG BNG D LIU S C HIN TH. [FREEZE<DSCH TRNG>]: CHO PHP CC TRNG TRONG DANH SCH NY LUN C HIN TH TRN MN HNH. [NODELETE]: KHNG CHO PHP XO [NOEDIT]: KHNG CHO PHP SA I.

V D: HIN TH NI DUNG CA CC TRNG HOTEN, NAMLV TIN HNH SA I. BROWSE FIELD HOTEN,NAMLV FREEZE NAMLV [FOR<BTHC LOGIC>]: CH CHO PHP NHNG BIU THC THO MN IU KIN CA BIU THC LOGIC MI C HIN TH. b. Lnh Edit C PHP: EDIT [<PHM VI>] [FIELD<DSCHTRNG>][ NOAPPEND][NODELETE] [NOEDIT] [FOR<BTHC LOGIC>] [WHILE<BTHC LOGIC>] TC DNG: TNG T NH LNH BROWSE NHNG CC BN GHI C XUT HIN NH LNH APPEND. c. Lnh REPLACE C PHP: REPLACE [<PHMVI>]<TRNG 1>WITH<BTHC 1>[ADDITIVE] [,<TRNG 2> WITH <BTHC 2> [ADDITIVE]...][FOR<BTHC LOGIC>] [WHILE<BTHC LOGIC>] TC DNG: DNG THAY TH NI DUNG CC TRNG C CH RA CA CC BN GHI NM TRONG <PHM VI> V THA MN IU KIN CA <BIU THC LOGIC> I SAU FOR HOC WHILE BI CC BIU THC TNG NG. PHM VI MC NH L BN GHI HIN THI. CH : KIU D LIU CA <BIU THC> V CA <TRNG> TNG NG PHI TNG NG NHAU, NU KHNG TH FOX S THNG BO LI KIU D LIU "DATA TYPE MISMATCH". V D: 1. THAY TH H TN CA NHN VIN TRONG FILE NHANVIEN BNG CH IN

REPLACE ALL HOTEN WITH UPPER(HOTEN) 2. NNG LNG CA NHNG NHN VIN N LNH THM 50000 NG REPLACE LUONG WITH LUONG+50000 FOR !GIOITINH
1.9. 2.3.7 Xo bn ghi

VIC XO MT BN GHI TRONG BNG D LIU C THC HIN THEO HAI BC: BC 1: NH DU BN GHI MUN XO: C PHP: DELETE [<PHM VI>] [FOR<BTHC LOGIC>] [WHILE<BTHC LOGIC>] TC DNG: LNH NY NH DU TT C CC BN GHI THO MN IU KIN C NU, MC NH L BN GHI HIN THI. KHI THC HIN LNH NY CC BN GHI C CH NH NH DU XO S XUT HIN DU * TRC CC BN GHI. LC NY TA C TH PHC HI LI CC BN GHI C. V D: NH DU XO NHNG NHN VIN C NM LM VIC TRC 1951. DELETE FOR NAMLV <1950 BC 2. XO CC BN GHI. CC BN GHI SAU KHI C NH DU XO NU QUYT NH THT S MUN XO N TH THC HIN LNH PACK, NGC LI NU KHNG MUN XO N TH THC HIN LNH RECALL. A. LNH XO CC BN GHI B NH DU XA (PACK) C PHP: PACK TC DNG: XO CC BN GHI TRONG BNG D LIU C NH DU XO BNG LNH DELETE. B. LNH PHC HI CC BN GHI C NH DU XO (RECALL):

C PHP: RECALL [<PHM VI>] [FOR<BTHC LOGIC>] [WHILE<BTHC LOGIC>] TC DNG: PHC HI LI CC BN GHI M TRC C NH DU XO BI LNH DELETE. PHM VI MC NH CA LNH NY L BN GHI HIN THI. C. LNH XA D LIU TRN FILE DBF. C PHP: ZAP TC DNG: XA TT C CC BN GHI TRONG MT FILE DBF ANG M.
1.10. 2.3.8 Lc d liu

HN CH S LNG CC BN GHI THAM GIA VO QU TRNH X L, TA C TH LC CC BN GHI TRONG BNG D LIU THO MN IU KIN CHO TRC. C PHP: SET FILTER TO <BTHC LOGIC> SAU KHI THC HIN LNH LC TH CC LNH TIP THEO SAU LNH NY CH C TC DNG I VI CC BN GHI THO MN IU KIN LC. MUN HU B VIC LC D LIU TA THC HIN LNH: SET FILTER TO V D: 1. CH HIN TH NHNG NHN VIN N: SET FILTER TO !GIOITINH LIST ..... 2. CH XT NHNG NHN VIN C QU QUN L HU SET FILTER TO QUEQUAN=="HUE" LIST .........
1.11. 2.3.9 THAO TC VI CU TRC BNG:

a. Xem cu trc bng (List|Display structure) C PHP: LIST | DISPLAY STRUCTURE TC DNG: HIN TH CU TRC CA BNG D LIU ANG C M, BAO GM: TN TRNG, KIU V RNG CA TRNG. V D: USE NHANVIEN LIST STRUCTURE b. Sa i cu trc bng d liu C PHP: MODIFY STRUCTURE TC DNG: HIN TH V CHO PHP SA I CU TRC BNG D LIU, KT THC LNH NY NHN T HP PHM CTRL+W. V D: USE NHANVIEN MODIFY STRUCTURE c. Sao lu cu trc bng d liu C PHP: COPY STRUCTURE TO <TEN FILE.DBF> [FIELDS<DANH SCH TRNG>] TC DNG: SAO CHP CU TRC CA BNG D LIU ANG C M SANG MT BNG MI C TN C CH RA TRONG <TEN FILE.DBF> VI CC TRNG C CH RA TRONG MC [FIELD<DANH SCH TRNG>]. MC NH CA LNH NY L TT C CC TRNG C TRONG BNG D LIU ANG C M. V D: SAO LU CU TRC CA NHANVIEN THNH FILE C TN L LUU.DBF NHNG CH GM CC TRNG: HOTE, GIOITINH, NMLV. USE NHANVIEN COPY STRUCTURE TO LUU FIELDS HOTEN, GIOITINH, NAMLV CH : BNG MI C TO RA CH C CU TRC, KHNG C NI DUNG.

1.12. 2.3.10 Sao chp bng

C PHP: COPY TO <TN BNG CH> [<PHM VI>] [FIELDS <DANH SCH TRNG>] [FOR<BTHC LOGIC>] [WHILE<BTHC LOGIC>] TC DNG: LNH DNG TO BNG MI C TN C CH RA <TN BNG CH> VI NI DUNG C LY T BNG D LIU ANG C M. MC NH LNH NY L TT C CC BN GHI U C SAO CHP, NU C PHM VI V CC BIU THC LOGIC TH NHNG BN GHI THO MN IU KIN MI WOCJ SAO CHP. DANG SCH TRNG CH NH CC TRNG C SAO CHP. V D: TO BNG D LIU C TN L NU.DBF T FILE NHANVIEN.DBF GM CC TRNG HOTEN, NGAYSINH, NAMLV. USE NHANVIEN COPY TO NU FIELDS HOTEN, NGAYSINH, NAMLV FOR !GIOITINH USE NU LIST
1.13. 2.4. MT S HM THNG DNG

&&M XEM KT QU

2.4.1. Cc hm v ngy thng A. HM DATE(): CHO NGY, THNG, NM HIN TI CA H THNG. TH T NGY, THNG, NM CA LNH NY PH THUC VO LNH SET DATE. V D: NU TA THC HIN LNH: SET DATE FRENCH RI THC HIN LNH DATE() TH NGY HIN HNH CA H THNG S C HIN RA THEO TH T L NGY, THNG, NM. B. HM YEAR(<BTHC DATE>): CHO NM (C 4 CH S) CA <BTHC DATE>. V D: YEAR(DATE()) CHO NM HIN TI CA NGY H THNG. C. HM MONTH(<BTHC DATE>): CHO THNG HIN TI CA BIU THC NGY V D: MONTH(DATE()) CHO THNG CA NGY H THNG.

D. HM DAY(<BTHC DATE>): CHO NGY CA BIU THC NGY. V D: DAY(DATE()) CHO NGY HIN TI. 2.4.2. Cc hm v chui A. HM LEN(<BTHC C>): CHO CHIU DI CA BIU THC, TNH BNG BYTE CA <BTHC C>, CHUI RNG C CHIU DI L 1. B. HM LEFT(<BTHC C>, <N>): TRCH RA MT CHUI T <BTHC C> GM <N> K T TNH T BN TRI SANG. V D: ?LEFT("NGUYEN VAN AN", 6) CHO KT QU L "NGUYEN". C. HM RIGHT(<BTHC C>, <N>): TRCH RA MT CHUI T <BTHC C> GM <N> K T TNH T BN PHI SANG. D. HM SUBSTR (<BTHC C>, <N1>, <N2>):TRCH RA MT CHUI CON CA <BTHC C> T V TR <N1> V GM <N2>) K T. V D: ? SUBSTR ("NGUYEN VAN AN", 8, 3" KT QU CHO CHUI "VAN". E. HM ALLTRIM (<BTHC C>): CHO KT QU L MT CHUI SAU KHI LOI B CC K T TRNG HAI BN (NU C) CA<BTHC C>. V D: ?ALLTRIM("NGUYEN VAN AN ") "NGUYEN VAN AN" F. HM UPPER(<BTHCC>): CHO KT QU L CHUI IN HOA CA <BTHC C>. V D: ?UPPER ("NGUYEN VAN AN") "NGUYEN VAN AN" G. HM LOWER <BTHC C>: NGC LI CA HM UPPER. 2.4.3. Cc hm s hc A. ASB(X): CHO GI TR TUYT I CA X. B. INT(X): CHO PHN NGUYN CA X. C. ROUND(X,<N>): LM TRN X VI N S L. E. SIN(X): CHO GI TR SIN X F. COS (X): CHO GI TR COS X.

Bi thc hnh chng 2 1. To tp tin DBF. Dng lnh Create t ca s lnh to cu trc cho tp tin HSNV.DBF nh sau: (Ch to cu trc, khng nhp d liu).
2. Field

Name

Field Type Character Character Character Logic Character Date Numeric Numeric Date

Width 5 20 7 1 30 8 2 3 8

Dec

Phn ghi ch M s nhn vin H lt Tn Phi (Nam, N) a ch Ngy sinh Trnh vn ho Mc lng Ngy ln lng

MASONV HOLOT TEN PHAI DIACHI NGSINH TDVH M_LUONG NGAYLL

Ghi ch: Trnh vn ho c nh gi qua cc m sau: 0: M ch, 1-12: Ph thng, 13: i hc, 14, Cao hc, 15: Tin s b. Cho bit cng dng ca phm F5 v F6 c. Thm vo tp tin va to ra hai trng mi.
3. Field

Name

Field Type Character Memo

Width 2 10

Dec

Phn ghi ch M n v H hng

MADV HOHANG

d. trng PHAI sa li tn l NU c kiu Logic. e. Nhp s liu 10 nhn vin vo tp tin HSNV.BDF ny. Ghi ch: nhp d liu vo vng HOHANG (kiu Memo) dng phm Ctrl_Home v kt thc bng Ctrl_W.

2. Dng menu h thng to cu trc tp tin HOCVIEN.DBF sau y:


4. Field

Name

Field Type Character Character Character Logic Date Character Character Character Character Numeric Numeric Logic Date

Width 4 20 7 1 8 2 20 4 3 5 5 1 10

Dec

Phn ghi ch M s nhn vin H lt Tn Nam: .T., N: .F. Ngy sinh

MASONV HO TEN NAM NGSINH NOISINH DIACHI MALOP MAGV DIEMLT DIEMTH UUTIEN GHICHU

Ni sinh a ch M lp M gio vin

2 2

im l thuyt im thc hnh u tin Ghi ch

Nhp s liu 10 hc vin u tin b. Dng lnh DIR ca s lnh xem tp tin c trn a hay khng, s mu tin va nhp v dung lng a cn trng? c. G lnh: Use ng tp tin HOCVIEN.DBF ri thot khi FoxPro.

C p nh t d
1. M tp tin HOCVIEN.DBF

li u

- Dng lnh LIST hay DISPLAY ALL xem ni dung cc mu tin ca tp tin HOCVIEN.DBF v ch xem cc vng tin MAHV, HO, TEN, NAM, MALOP, MAGV, DIEMLT, DIEMTH, nu c sai st hy iu chnh cho ng. 2. G lnh SET STATUS ON xem thanh trng thi. - Nu thanh trng thi b che khut bi ca s lnh th n Ctrl_F7 di chuyn ca s n v tr khc. - Nu bng m di ca s lnh che lp thanh trng thi th g SET SHADOW OFF tt i.

3. Dng lnh APPEND thm hai mu tin mi ri n Ctrl_W ghi li. 4. Dng hm RECNO() cho bit s hiu ca mu tin hin hnh di con tr n u tp tin. 5. S dng lnh EDIT sa ni dung cc mu tin tu thch ca bn, sa xong n Ctrl_W ghi li. 6. G lnh: BROWSE. Quan st mn hnh ri th cc ng tc sau: a. a vt sng n mu tin th nht ti vng ghi ch, ri n Ctrl_Home xem phn ghi ch c nhng ni dung g? G thm mt ghi ch tu ri n Ctrl_W ghi li. b. n Alt+B gi MENU ca BROWSE, sau gi APPEND, nhp thm 1 mu tin ri n Ctrl_W ghi li. c. G li lnh BROWSE ln na, n Ctrl_N, FoxPro s thm mu tin trng cui, nhp s liu cho mu tin ny. d. a vt sng n vng DIEMLT, n Alt+B gi MENU ph, sau chn Move ri chuyn vt sng n vng DIEMTH, n Enter. Kt qu hai ct DIEMLT v DIEMTH s c chuyn cho nhau. e. a vt sng n vng NOISINH, n Alt+B gi menu SIZE, dng mi tn tri thu hp ct ny cn 10 Bytes thi, sau g: Vnh li-Hu vo mu tin th t. 7. G lnh DELETE ALL FOR DIEMTH < 7 ri xem c bao nhiu mu tin b nh du xo? 8. G lnh BROWSE quan st, sau a vt sng n mt mu tin b nh du xo ri n Ctrl_T xem du xo c cn hay khng, n li Ctrl_T ln na xem iu g xy ra, sau n Ctrl_W thot ra. 9. G lnh RECALL ALL phc hi cc mu tin b nh du xo ri ng tp tin HOCVIEN.DBF li. 10. M tp tin HSNV.DBF a. Dng lnh REPLACE tng lng gp i cho tt c nhn vin, sau tng thm ring cho cc n nhn vin 10% na. b. Thm vo cu trc tin HSNV.DBF mt trng LOAIBC (loi bin ch: BC/HD) v dng BROWSE nhp d liu cho vng tin ny, n Ctrl_B thot khi BROWSE. c. G lnh DISPLAY STRUCTURE (hay F5) xem li cu trc. d. nh du xo cc nhn vin m ch v trnh ph thng cho lit k trn mn hnh nhng mu tin khng b nh du xo.

e. Nhp thm hai mu tin vo gia tp tin HSNV.DBF. - Mt mu tin sau mu tin c STT=5 - Mt mu tin trc mu tin c STT=3 f. G lnh RECALL ALL phc hi cc mu tin b nh du xo. g. Lit k danh sch cc nhn vin theo dng. MNV HOLOT TEN NU NGSINH HSL TDVH

h. Lit k theo ng cu g nhng nhn vin nam. i. Lit k theo dng cu g nhng nhn vin nam t 18 n 30 tui. j. Lit k theo dng cu g nhng nhn vin n c trnh i hc. k. Lit k theo dng cu g nhng nhn vin c tn bt u bng vn H l. G lnh Use ng tp tin HXNV.DBF ri thot khi FoxPro.

5.

CHNG 3: SP XP-TM KIM-THNG K

5.1. 3.1. SP XP

3.1.1. Khi nim

Trong m t b ng d li u, chng ta c th s p x p cc m u tin theo m t tiu chu n n o tu theo yu c u c a vi c khai thc thng tin.
3.1.2. Sp xp theo ch mc a. Khi nim v ch mc Ta bit mi bng d liu cha cc bn ghi v mi bn ghi u c nh s hiu theo s th t t 1 n n. V d: bng NHANVIEN.DBF c dang sau: Record# 1 2 3 4 HOTEN NGUYN VN A L th nhn Nguyn An Trn Hnh S hiu cc bn ghi Khi x b n ghi. V d: use NHANVIEN list Kt qu in ra s nh sau: Record# 1 2 3 4 HOTEN NGUYN VN A L th nhn Nguyn An Trn Hnh NGAYSINH 02/10/75 05/23/75 10/26/80 09/25/70 GIOITINH .T. .F. .T. .T. NAMLV 1985 1980 1982 1981 l thng tin trong b ng d li u, ta truy xu t chng theo tr t t c as hi u NGAYSINH 02/10/75 05/23/75 10/26/80 09/25/70 GIOITINH .T. .F. .T. .T. NAMLV 1985 1980 1982 1981

Sp xp bng d liu theo ch mc l to ra mt file mi (c phn m rng mc nh l .IDX) ch c hai trng: trng kho sp xp v trng s hiu bn ghi. Th t ca bn ghi y l th t sp xp.

V d : file ch m c c a b ng nhanvien theo th vi c nh sau:


Namlv file ch mc theo namlv 1980 1981 1982 1985 trong file ch mc ny. Record# 2 4 3 1

t ng d n c a n m lm

Lc ny, khi truy xut d liu ca bng, th t ca cc bn ghi l th t c quy nh

V d : Trong b ng nhanvien, s th t truy xu t:


Record# 2 4 3 1 Hoten L th nhn Trn Hnh Nguyn An Nguyn vn A

d ng ch

m c theo tr

ng namlv.idx ta c
namlv 1980 1981 1982 1985

ngaysinh 05/23/75 09/25/70 10/26/80 02/10/75

gioitinh .F. .T. .T. .T.

b. Lp ch mc IDX cho bng d liu C php: INDEX ON <bthc kho> TO <tn file idx> [FOR<bthc logic>] [UNIQUE] Tc dng: Lnh sp xp file d liu theo chiu tng dn ca <Bthc kho> ca cc bn ghi tho mn <Bthc logic> sau FOR, mc nh l tt c cc bn ghi. Nu c t kho [UNIQUE] th cc bn ghi no c <Bthc kho> trng nhau s b b qua trn file ch mc. V d 1: Hin th theo th t tng dn ca namlv ca cc nhn vin. use NHANVIEN index on NAMLV to CMNAMLV list

V d 2: Hin th theo th t tng dn ca hoten index on HOTEN to CMHOTEN list Ch : Lnh lun sp xp theo th t tng dn ca <bthc kho>, do vy khi la chn <bthc kho> th phi chn cho ph hp. V d 1: Hin th theo th t gim dn ca namlv ca cc nhn vin. use NHANVIEN index on -NAMLV to CMNAMLVG list V d 2: Hin th theo th t gim dn ca ngaysinh. use NHANVIEN index on date()-NGAYSINH to CMNSINHG list c. Mt s lnh lin quan + SET INDEX TO <file ch mc>: Dng m file ch mc sau khi m mt bng d liu. + SET INDEX TO: Dng ng file ch mc. + REINDEX: Dng d li u.
5.2. 3.2. TM KIM

c p nh t l i file ch

m c sau khi c s

s a

i trn b ng

3.2.1. Tm kim tun t a. Lnh Locate: C php: LOCATE [<phm vi>] FOR<bthc logic> [WHILE<bthc logic>]

Tc dng: Lnh s duyt tun t cc bn ghi trong bng d liu v tm n bn ghi u tin trong <phm vi> tho mn iu kin ca <bthc logic>. Nu tm c, hm FOUND() s cho gi tr .T., hm EOF() c gi tr .F. V d: Tm nhn vin u tin trong bng d liu sinh nm 1970 trong bng nhanvien use NHANVIEN Locate for year(NGAYSINH) = 1970 Display b. Lnh continue C php : CONTINUE Chc nng : Theo sau lnh LOCATE, dng tm bng ghi k tip sau tha mn iu kin nu. V d : Tm 2 nhn vin u tin sinh nm 1970 use NHANVIEN locate for year ( NGAY SINH) = 1970 display continue display 3.2.2. Tm kim sau khi lp ch mc C php : SEEK <biu thc> Chc nng : sau khi lp ch mc theo <bthc kha> tm bn ghi no tha mn mt iu kin da vo <bthc kha> Ta s dng lnh SEEK theo sau l <gi tr> ca biu iu kin cn tm. nu tm thy th hm FOUND() c gi tr .T. v hm EOF () c gi tr .F. V d: 1. Sp xp theo th t tng dn ca H Tn, tm nhn vin c tn Nguyen Van AN.

use NHANVIEN index on upper(HOTEN) to CMHOTEN seek Nguyen Van An disp 2. Sp xp theo th t gim dn ca NAMLV, tm nhn vin c nm lm vic 1981. use NHANVIEN index on - NAMLV to CMNAMLVG list seek -1981 disp 3.3. THNG K 3.3.1. m s lng bn ghi C php COUNT [<phm vi>][FOR<btlogic>] [WHILE<btlogic>] [TO<bin nh>] Chc nng :lnh dng m s mu tin trong bng d liu hin hnh tha mn iu kin cc <bthc logic> nm trong phm vi c ch ra. Kt qu c a ra mn hnh hay a vo <bin nh> nu c TO. V d: Cho bit c bao nhiu nhn vin c NAMLV l 1980 use NHANVIEN count for NAMLV = 1980 to songuoi ? c songuoi: , songuoi, lm vic nm 1980 3.3.2. Tnh tng gi tr cc trng kiu s C php: SUM [<phm vi>] [<dsch bt>] [TO <ds bin>] [FOR <bt logic>] [WHILE <btlogic>]

Chc nng : Lnh s ly tng theo cc biu thc c xy dng da trn cc trng kiu s, ca cc bn ghi trong bng d liu; nm trong <phm vi> v tha mn iu kin ca cc <bthc logic>. Nu khng c <ds biu thc> th cc trng kiu s u c ly tng. Mc nh, kt qu c a ra mn hnh; nu c TO <dsbin> th kt qu ca cc <biu thc> s c a vo cc <bin> tng ng. Ch : Phi tng ng 1-1 gia <ds biu thc> v <ds bin>. V d: Da vo bng NHANVIEN, cho bit tng LUONG phi tr v tng PHUCAP l bao nhiu. use NHANVIEN sum LUONG, PHUCAP to tongluong, tongpc ? tong luong la: , tong luong ? tong phu cap la: , tongpc 3.3.3. Tnh trung bnh cng cc trng kiu s C php: AVERAGE [<phm vi>] [<ds biu thc>] [TO <ds bin >] [FOR <bt logic>] [WHILE <bt logic>] Chc nng : ging nh lnh SUM trn nhng sau khi ly tng, lnh s ly gi tr em chia cho tng s bn ghi tham gia vo cu lnh. V d: da vo bng NHANVIEN, cho bit trung bnh mi nhn vin nhn c bao nhiu LUONG, PHU CAP. use NHANVIEN average LUONG, PHUCAP to tbluong, tbphucap ? trung binh luong: , tbluong ? trung bnh phu cap: , tbphucap 3.3.4. Tnh tng cc trng s theo nhm C PHP: TOTAL ON <BT KHA> TO <TN BNG MI.DBF>[<PHM VI>]

[FIELD <dstrng>][FOR <bi thc L>][WHILE < bi thc L>] Chc nng: Lnh s cng dn cc trng kiu s theo tng nhm bn ghi c <bt kha> ging nhau v a vo bng mi c tn c ch ra <tn bng .DBF>. Mc nh th tt c cc trng kiu s u c cng dn, nu c FIELDS <danh sch trng> th ch c cc trng lit k mi c cng. Lnh ch tc ng n cc bn ghi nm trong (phm vi) v tho mn iu kin i sau cc mnh FOR, WHILE. Ch : Trc khi dng lnh ny, bng d liu phi nh sp xp theo kho. V d: Da vo bng VATTV, hy thng k xem mi mt hng xut hay nhp mt s lng l bao nhiu. use VATTV

index on MAXN + MAVT to CMTK total on MAXN + MAVT to THONGKE fields SOLUONG use THONGKE ? chi tiet la : list MAXN, MAVT, SOLUONG, DONGIA Gi s bng VATTU sau khi sp xp l: MAXN N N N N N 9 4 1 2 10 SOCT MAVTU A01 A01 F01 F01 F01 SOLUONG 145 203 123 345 654 5 500 200 200 180 DONGIA

Kt qu ca bng THONGKE.DBF l: MAXN N SOCT 9 MAVTU A01 SOLUONG 348 DONGIA 500

N N

1 10

F01 F01

469 654

200 180

6.

CHNG 4:

LP TRNH TRN VISUAL FOXRO

6.1. 4.1. CHNG TRNH

4.1.1 Khi nim L mt dy lnh lin tip c t chc vo 1 file chng trnh, file chng trnh mc nh c phn m rng l *. PRG. Trong mt chng trnh, mi lnh c vit trn mt hng v mi hng ch cha mt lnh ti mt ct bt k. 4.1.2. Son tho chng trnh son tho chng trnh, t ca s lnh a vo lnh; MODIFY COMAND < tn file ch ng trnh >

Lc ny xut hin ca s chng trnh ta c th a cc lnh vo cho n. Mt chng trnh foxpro thng c 3 phn. a) To mi trng lm vic : thng cha cc lnh sau: SET DATE FRENCH: t ngy thng nm theo dng DD-MM-YY SET CURENCY ON : t nm c 4 ch s SET TALK OFF/ON : n hin cc kt qu thc hin lnh SET DEFAULT TO <ng dn> : t ng dn hin thi CLEAR: xo mn hnh hin th kt qu CLOSE ALL: ng cc bng d liu, cc file c s d liu,... b) Phn thn chng trnh:

Thc hin cc cng vic m chng trnh yu cu nh : + Cp nhp d liu + x l, tnh ton + Kt xut thng tin c) Kt thc chng trnh + ng cc tp tin CSDL, cc bng d liu ang s dng + Gii phng bin nh + Tr li cc ch cho h thng. d) Ch thch trong chng trnh L cc gii thch c thm vo lm r cho chng trnh, phi c bt u bi du * hay && * : Bt u mt dng && : Vit sau mt lnh
6.2. 4.2. BIN NH

4.2.1. Khai bo bin a) Lnh gn = C php: V d: <bin> = <bin thc> a= 5 ngay = Date() b) Lnh STORE C php: STORE <bthc> to <ds bin>

Cng dng: Gn gi tr <bthc> cho <ds bin> ; nu <bin> cha tn ti n s khai bo, nu c th thay th bi gi tr mi. V d: STORE 0 To a, b, c

4.2.2. Nhp gi tr cho bin t bn phm a) Lnh ACCEPT C php ACCEPT <bthc chui> to <bin chui>

Chc nng : Dng nhp mt chui t bn phm, kt thc bi phm , gi tr nhn c s a cho <bin>. V d: ACCEPT nhap ho ten to bhoten ? Ho ten vua nhap', bhoten <Bthc chui> l mt cu nhc nh ngi s dng. b. Lnh INPUT C php: INPUT <Bthc chui> to <bin> Tc dng: Tng t lnh trn nhng c th nhn d liu theo tng kiu: Kiu Charater: Phi c t trong cp du ' ... ' hay "... ". Kiu Numberic: Nhp d liu kiu s. Kiu Date: Phi c trong du {}. Kiu Logic: Nhp gi tr .T. hay .F. V d: INPUT 'Nhap ngay sinh' TO bngaysinh INPUT 'Nhap diem" TO bdiem Ch : Trong hai lnh trn, nu bin cha c th n s t khai bo, nu c th n s thay gi tr ca bin bi gi tr va nhp.

4.3. CC CU TRUC IU KHIN CHNG TRNH 4.3.1. Cu trc tun t

Quy c: Chng trnh c thc hin t trn xung di. 4.3.2. C u trc r nhnh Cn g i l c u trc ch n l a. C u trc r y : Bthc L .T. Cc lnh nhnh c hai .F.

d ng: d ng khuy t v d ng a. Dng khuyt: C php: IF <Bthc L> <cc lnh> ENDIF

Tc dng: Khi gp cu trc ny, <Bthc L> s c tnh, nu c gi tr .T. th <cc lnh> s c thc hin, ngc li thc hin cc lnh tip theo sau. V d : Vi t ch set talk off clear Input :Nhap so thu nhat' to so1 Input :Nhap so thu hai' to so2 max=so1 If max < so2 max=so2 Endif ? "So lon nhat la:', max set talk on return b. Dng y : .T. Bthc L .F. ng trnh nh p v o hai s , cho bi t s l n nh t

Cc lnh

Cc lnh

C php: IF <Bthc L> <cc lnh 1> ELSE <cc lnh 2> ENDIF Tc dng: Khi gp cu trc ny, <Bthc L> s c tnh. Nu c gi tr .T. th <cc lnh 1> s c thc hin, ngc li (c gi tr .F.) th s thc hin <cc lnh 2>. Sau tip tc thc hin cc lnh tip theo trong chng trnh. V d: Da vo bng nhanvien, hy nhp vo mt h tn nhn vin, tm xem c ng l nhn vin ca cng ty hay khng, nu ng th thng bo nm sinh v nm lm vic, ngc li th thng bo l khng phi nhn vin ca cng ty. set talk off clear close all use NHANVIEN accept 'nhap ho ten nhan vien:' to bhoten locate for HOTEN =bhoten if found() ? ' ngay sinh l:', ngaysinh' ?'nam lam viec:', namlv else ?'khong phai la nhan vien cua cong ty' endif set talk on return

4.3.2.1. La chn mt trong nhiu trng hp C php DO CASE

CASE <Bthc L1> <cc lnh 1> CASE <Bthc L2> <cc lnh 2> ...................... CASE <Bthc Ln> <cc lnh n> [OTHERWISE <Cc lnh n+1>] ENDCASE Tc dng: Khi gp cu trc DO CASE, cc <Bthc L> iu kin s c tnh. Nu <Bthc L> iu kin no c gi tr .T. th nhm lnh tng ng s c thc hin v kt thc cu trc ny, ri tip tc thc hin cc lnh sau ENDCASE. Trong trng hp khng c <bthc L> no t 1 n n c gi tr .T. th <nhm lnh n+1> (nu c) s c thc hin. V d: Vit chng trnh nhp vo mt nm (c 4 ch s), sau nhp thm mt thng, cho bit thng ny c bao nhiu ngy. set takl off clear input 'nhap vao mot nam' to bnam input 'nhap vao mot thang' to bthang do case case bthang=4 or bthang = 6 or bthang = 9 or bthang=11 songay=30 case bthang=12 if (mod(bnam, 4)=0 and (mod(bnam, 100)<>0) songay=29 else songay=28 endif otherwise songay=31

endcase ? 'thang', bthang, 'nam', bnam, 'co', so ngay, 'ngay' set talk on return 4.3.3. Cu trc lp 4.3.3.1. Cu trc DO WHILE C php: DO WHILE <Bthc L> <cc lnh> [LOOP] [EXIT] ENDDO Tc dng: Khi gp cu trc ny th <Bthc L> s c tnh, nu c gi tr .F. th s dng v thc hin cc lnh sau ENDDO. Nu c gi tr .T. th cc lnh trong thn vng lp s c thc hin v li quay v kim tra iu kin trong <bthc L> v c th tip tc. [LOOP]: Khi gp lnh ny, Foxpro s quay v kim tra iu kin logic m b qua cc lnh pha sau [LOOP]. [EXIT]: Khi gp lnh ny th s thot ra khi chng trnh. V d: Cho bit dang schh tn ca cc nhn vin trong cng ty. set takl off clear close all use NHANVIEN ? 'danh sach ho ten hoc vien la:' do while !eof() ?HOTEN skip enddo set talk on return

Ch : Khi s dng cu trc ny, cc lnh trong thn vng lp phi thay i c gi tr ca <Bthc L> m bo tnh kt thc. V d: Nhp vo mt nm, hy thng bo danh sch h tn, ngy sinh ca nhng nhn vin lm vic trong nm , nu khng c th thng bo l khng c. set takl off set date french clear close all use NHANVIEN input 'nhap nam lam viec" to bnam set filter to NAMLV = bnam count to dem if dem = 0 ? ' khong co nhan vien nao' else go top ? 'danh sach nhan vien lam viec nm', bnam ? "HO TEN do while !eof() ?HOTEN, NGAYSINH skip enddo endif set filter to set talk on return 4.3.3.2. Cu trc SCAN C php SCAN [<phm vi>] [FOR<Bthc L>] [WHILE<bthc L>] NGAY SINH'

<cc lnh> [LOOP] [EXIT] END SCAN Tc dng: Dng duyt ln lt cc bn ghi trong bng d liu hin hnh nm trong <phm vi> c ch ra v tho mn iu kin ca cc <Bthc L> sau FOR hoc WHILE. Tng ng vi mt bn ghi tm c. <cc lnh> s c thc hin. Cu trc SCAN s dng khi no duyt n bn ghi cui cng ca bng d liu ang xt.

V d : Vi t ch ng trnh nh p n m (b n ch vin sinh n m .


set takl off set date french clear close all use NHANVIEN input 'nhap nam lam viec" to bnam input 'nhap nam:' to bnam

s ), hi n th

nh ng n

nhn

? 'DANH SACH CAC NU NHAN VIEN, SINH NAM', bnam scan for !GIOITINH and year(NGAYSINH)=bnam ?HOTEN, NGAYSINH endscan set talk on return -------------------------------------------------------------------

Bi thc hnh chng 4


7. Field

Name

Field Type Character Character Character

Width 5 20 7

Dec

Phn ghi ch M s nhn vin H lt Tn

MASV HOLOT TEN

NGSINH QUEQUAN DOS VRES FOX DTB XEPLOAI

Date Character Numeric Numeric Numeric Numeric Character

8 20 2 2 2 4 4 2

Ngy sinh Qu qun im mn Dos im VRER im FoxPro im trung bnh Xp loi

Nhp vo 10 mu tin cho cc vng: MASV, HOLOT, TEM, NGSINH, QQUAN, DOS, VRES, FOR theo mu di y. Cc vng tin cn li s tnh sau: MASV CK001 NT001 NT002 CK002 KT001 KT002 CK003 CK004 NT003 NT004 HOLOT Le Van Ho Thi Tran Van Le Ng. Thi Le Van Vo Ho Duc Vo Thi Le Van TEN Hung Lan Long Tung Hoa Chau Anh Tuan Lan Huy NGSINH 12-04-1972 10-05-1969 06-12-1968 05-06-1967 10-10-1967 05-04-1968 02-10-1969 10-02-1968 02-01-1969 05-06-1968 QQUAN Da Nang Hue Da Lat TP.HCM TP.HCM Da Nang Hue Da Nang Hue Da Nang DOS 8 7 5 7 8 7 9 7 8 8 VRES FOR 9 6 4 7 4 6 9 6 9 5 10 9 5 6 7 9 10 9 9 2

2. Dng lnh COPY FILE chp tp tin KETQUA1.DBF thnh KQ1.DBF. Sau c th dng lnh USE KQ1 m tp tin KQ1 khng? ti sao? 3. M tp tin KETQUA1.DBF a. Tnh (im trung bnh), bit rng DOS c h s hai, VRES c h s 1, FOX c h s 3. b. Xp loi, bit rng: DTB>=9 : Xp loi GIOI

7<=DTB<9 : Xp loi KHA

5<=DTB<7 : Xp loi TB DTB<5 : Xp loi YEU

c. Sp xp gim dn theo DTB v ghi vo tp tin SX_DTB.DBF. M tp tin SX_DTB.DBF ri dng lnh BROWSE xem. d. i d liu ca trng QQUAN thnh ch hoa. e. Tnh trung bnh cng ca cc mn hc cho ton b cc mu tin, cho tng nhm c MASV bt u bng CK, NT, KT. f. Cho bit s sinh vin c t nht hai mn c im >=8. Bi tp chng 5

1. To tp tin NHAPVT.DBF c cu trc nh sau:


8. Field

Name

Field Type Charater Date Charater Numeric Numeric Numeric

Width 5 8 1 6 8 9

Dec

Phn ghi ch M s vt t Ngy nhp Nhp: N, xut: X S lng n gi Thnh tin

MAVT NGAYNHAP MANX SL DONGIA THANHTIEN

Nhp vo 10 mu tin theo mu di y: MAVT TV01 TL01 ML01 BU01 QB01 MG01 ND01 NGAYNHAP 01-01-1998 04-01-1998 08-01-1998 04-05-1998 05-01-1998 05-06-1998 06-06-1998 MANX N N X N N X N SL 12 10 40 30 28 12 20
8.1. DONGIA

3850000 4700000 5100000 220000 350000 4000000 650000

HD02 HD02 XD01

10-10-1998 01-01-1998 01-01-1998

N N X

12 10 30

13000000 16000000 1200000

2. Tp tin TONKHO98.DBF c cu trc nh sau:

9. Field

Name

Field Type Charater Numeric Numeric Numeric Numeric

Width 5 10 10 10 10

Dec

Phn ghi ch M s vt t Tn u k S lng nhp S lng xut Tn cui k

MAVT TONDAU SLN SLX TONCUOI

Nhp vo cc mu tin sau: MAVT TV01 TL01 ML01 BU01 QB01 MG01 ND01 HD02 HD02 XD01 TONDAU 12 30 50 40 50 55 100 50 45 100

3. To tp tin DMVTU.DBF c cu trc sau:


10. Field

Name

Field Type Charater 5

Width

Dec

MAVT

TENVT

Charater

20

- Ly MAVT trong tp tin TONKH98.DBF thay th vo trng MAVT - Nhp vo trng TENVT cc d liu sau:

MAVT TV01 TL01 ML01 BU01 QB01 MG01 ND01 HD02 XD01

NGAYNHAP Tivi mau SHAP 14 Tu lanh TOSHIBA 1401 May lanh 1.5 HP Ban ui Philip Quat ban Hitachi May giat SANYO 40 Noi com dien SANYO Xe cub 86 Xe dap NHAT

4. Tnh gi tr trng THANHTIEN ca tp tin NHAPVT.DBF 5. Tnh tng s tin nhp ca mi loi vt t c ch ci u tin bn tri ging nhau. 6. Tnh SLN, SLX, TONCUOI, sau thi gian nhp xut trn. 7. To tp tin TONKHO99.DBF c cu trc ging nh TONKHO98.DBF. Ly TONCUOI ca tp tin TONKHO94.DBF b vo TONDAU ca TONKHO99.DBF 8. Lit k danh sch Nhp vt t gm cc mc sau: MAVT TENVT NGAYNHAP MANX SL

9. Lit k danh sch TONKHO gm cc mc sau: MAVT TENVT TONDAU TONCUOI

11.

CHNG 5: FORMS

11.1. 5.1. KHI NIM V LP TRNH HNG I TNG:

Thit k v lp trnh hng i tng l mt s thay i i vi phong cch lp trnh c, lp trnh hng th tc. y thay v ngh n cc chc nng ca chng trnh ta ch cn ngh n cc i tng ang to: l cc thnh phn c lp ca mt ng dng ci chc nng ring ca n. Mi mt i tung u c mt b thuc tnh m t i tng; cc phng thc l nhng on trnh cha trong iu khin, cho iu khin bit cch thc thc hin mt on cng vic no ; v tp hp nhng s kin l nhng phn ng ca i tng. Trong Visual Foxpro, cc form v control l cc i tng c dng xy dng cc ng dng 5.1.1. Thuc tnh ca i tng (Properties) ch n mt thuc tnh ca i tng no ta dng c php sau: <tn i tng>.<thuc tnh> V d: Myform.caption= Chng trnh ng dng Cc thuc tnh thng dng: - Left: V tr cnh tri ca i tng so vi vt cha n. - Top: V tr trn ca i tng so vi vt cha n. - Height: Chiu cao ca i tng. - Width: Chiu rng ca i tng. - Name: Tn ch i tng. - Enable: Gi tr logic: True: c quyn lm vic. False: Khng c quyn lm vic. - Visible: Gi tr logic: True: Thy c i tng;

False: Khng thy c i tng. 5.1.2. Phng thc ca i tng (Methods) gi n phng thc ca mt i tng, ta dng c php: <tn i tng>.<phng thc> V d: Myform.show Mt s phng thc thng dng: - Refresh: Lm ti li i tng. - Show: Hin i tng. - Hide: n i tng. - Release: Gii phng i tng. - SetFocus: Thit lp tm ngm cho i tng. 5.1.3. S kin ca i tng ch n s kin ca i tng, ta dng c php sau: <tn i tng>.<s kin> Mt s s kin thng dng: - Click: c gi khi kch chut vo i tng. - DbClick: c gi khi kch p chut vo i tng. - MouseMove: c gi khi di chuyn chut trn b mt ca i tng. - KeyPress: c gi khi nhn mt phm kch chut vo i tng. - Got focus: c gi khi a i tng vo tm ngm. - Lostfocus: c gi khi a i tng ra khi tm ngm - Change: c gi khi c s thay i ni dung d liu kiu chui ca i tng.

11.2. 5.2. FORM

5.2.1. Gii thiu Form c dng lm giao din nhp, hin th thng tin, n cung cp mt tp hp cc i tng p li nhng thao tc ca ngi dng lm cho ng dng ra dng chuyn nghip. V d: Giao din ca mt Form nhp d liu 5.2.2. To form thng qua Wizard T menu Tools, chn wizard, chn form, xut hin giao din wizard selection, ri thng qua hng dn. 5.2.3. To form thng qua thit k to form thng qua thit k, t ca s lnh ta thc hin lnh sau:
CREATE FORM <tn form>

Khi ta c mn hnh thit k form nh sau: a. Qun l form Lu Form: T menu file, chn save lu vo <tn form>, mc nh phn m rng l scx. Chy form: T ca s lnh, thc hin lnh sau: DO FORM <tn form> ng form (gii phng khi b nh) RELEASE <tn form>

b. Tuy cp n cc i tng trn form + Mun ch n mt i tng no trn form, ta dng: <tn form>. <i tng>: nu <i tng> khng cng vi form ang thao tc. <this form>.<i tng>: nu i tng nm trn form ang thao tc. + Mun thay i gi tr cc thuc tnh trn form, ta <tn form>.<thuc tnh>= <gi tr>: nu mun thay thuc tnh ca form khng phi l form hin hnh. <This form>.<thuc tnh>=<gi tr>: nu mun thay cc thuc tnh ca form hin hnh. c. Cc thuc tnh, phng thc, s kin thng trn form. Thuc tnh: - BackColor: Mu nn - BorderStyle: Dng ng vin - Caption: Tiu ca form - FillColor: Mu t i tng - Fontname: Font ch cho cc i tng cha vn bn - Fontsize: Knh thc fontname - Moveable: Cho php di chuyn hay khng ................. Tnh hung - MoveMouse: p ng khi di chuyn chut trn b mt form - Destroy: p ng khi gii phng form - Load: p ng khi np form vo b nh dng i dng: i

5.3. Thanh cng c Control Toolbar Mun a i tng trn thanh Control vo form: 4 bc - Kch chut vo i tng cn a - V n trn form xc nh v tr - Thit lp cc thuc tnh thch hp - Vit m lnh cho cc tnh hung tng ng Quy c t tn cho cc i tng Loi i tng Form Command Edit box Grid Image Label Textbox Timer 5.3.2. Mt s i tng trn Controls a. Label : Dng th hin cc chui trn form. Cc thuc tnh thng dng: - Caption: Chui th hin - Autosize: Gi tr logic, cho php kch thc ca Label c t ng chnh sa theo di ca caption hay khng. b. Command Bottom: Dng th hin cc nt lnh trn form. Tn Bt u bi Frm Bt u bi cmd Bt u bi Edb Bt u bi Grd Bt u bi Img Bt u bi Lbl Bt u bi Txt Bt u bi Tmr

Cc thuc tnh thng dng: - Caption: tn xut hin trn nt lnh - Picture: Hnh xut hin trn nt lnh - Enable: gi tr Logic, cho php chn nt lnh hay khng Cc S kin thng dng: - Click: Khi kch chut vo nt lnh th s kin ny c gi. c. TextBox: Dng xem, chnh sa d liu t cc trng trong bng d liu khng phi kiu memo. Cc thuc tnh thng dng. - ControlSource: Tn ca trng hay bin m gi tr ca n c hin trong textbox - Value: Gi tr hin thi ca textbox. S kin thng dng: - Change: Khi c s thay i ca thuc tnh value - KeyPress: Khi c phm bt k c n. d. Editbox: Tng t nh textbox, c dng chnh sa d liu t cc trng memo. Cc thuc tnh thng dng. - Control Source: Tn ca trng m gi tr ca n c th hin trong editbox. - ScrollBars: C hin thanh cun trong khung editbox hay khng. - ReadOnly: Cho php c c chnh sa ni dung hay khng S kin thng dng: - Change: Khi c s thay i ca thuc tnh value. - Keypress: Khi c phm bt k c n. e. Images: Dng a cc hnh nh trn form.

Cc thuc tnh thng dng. - Picture: Xc nh file hnh nh - Stretch: Xc nh cch thc th hin hnh nh (phng to, thu nh, nguyn mu). f. Timer: Dng thit lp cc cng vic thc hin u n sau mt khong thi gian. Cc thuc tnh thng dng. - Enabled: Xc nh xem Timer c hiu lc hay khng - Interval: Quy nh khong thi gian xc nh cho tnh hung timer. S kin thng dng: - Timer: c kch hot u n sau mt khong thi gian xc nh thuc tnh Interval. g. Grid: Dng th hin d liu theo dng bng. Cc thuc tnh thng dng. - Row Source: Xc nh bng d liu cn th hin. - ColumnCount: Xc nh s ct ca Grid. Ch : Nu Row Source khng c ch ra th ly bng d liu hin hnh. Nu Column count khng ch ra th mc nh l tt c cc trng trong bng d liu (Column count=-1). Control Source: c xc nh cho tng ct, dng khai bo ngun d liu cho ct . - Allow Addnew: Cho php thm cc bn ghi mi hay khng. Ch : Mun thay i cc thuc tnh trn Grid th chuyn Grid sang dng edit bng cch nhn phm phi chut ln Rrid, chn Properties. Grid ang ch Edit c mt ng vin bao quanh.
12. 5.4.

V d

Gi s c bng d liu vi cu trc: MANV HOTEN C C 5 30 FrmXem

Hy thit k form xem bng d liu trn.

Ta thit k form nh sau

TxtMAN V TxtHOTE N

CmdDa

CmdTruo

CmdSau

CmdCuoi

CmdThoa t

13. 14.

Cc thuc tnh chnh : + TxtMANV cc thuc tnh ControlSource l MANV


15.

+ TxtHOTEN cc thuc tnh ControlSource l HOTEN

16. M

lnh ca cc i tng trn Form l: + FrmXem.load use hoso + CmdDau.Click go top

thisform.refresh + CmdCuoi.Click go bottom thisform.refresh + CmdTruoc.Click if not bof() skip -1 endif thisform.refresh + CmdSau.Click if not eof() skip endif thisform.refresh + CmdThoat.Click use thisform.release

17.

CHNG 6

REPORTS

17.1. 6.1. KHI NIM

Reports l cng c trnh by v tm tt d liu trong mt vn bn khi in. Report c hai thnh phn c bn cu thnh: d liu ngun, thng thng l cc bng d liu v hnh thc trnh by l dng thc ca report s nh dng cch kt xut d liu. Mn hnh thit k Report

17.2. 6.2. CC BC TO REPORT

Ta c th thit k report th hin d liu nhiu dng thc khc nhau trn giy khi in. Qu trnh thit k gm 4 bc chnh nh sau: 1. Xc nh loi Report cn to: Tc l quyt nh chn dng thc m report hin th kt qu. 2. To Report layout: C th s dng report wizard hay report designer. Report layout c lu trn a vi phn m rng ca file l FRX: Lu tr chi tit ca report. 3. Sa i layout ca report. 4. Xem v in report.
17.3. 6.3. TO REPORT BNG WIZARD.

T menu Tools, chn Wizard, chn Report sau lm theo cc bc hng dn. Bc 1: Chn bng d liu v cc trng cn th hin

Bc 2: To nhm d liu kt xut

Bc 3: Chn kiu Report th hin Bc 4: Chn cch trnh by trn giy in

Bc 5: Chn trng Sp xp

Bc 6: t ta , kt thc
17.4. 6.4. TO REPORT BNG REPORT DESIGNER

6.4.1. Qun l Report To mi Report: CREATE REPORT <tn Report> V d: create report THU Lc ny mn hnh xut hin hp thoi report

M mt report sn c: MODIFY <tn report>

Xem trc khi in: REPORT FORM <tn report> PREVIEW Xem trc khi in c iu kin: REPORT FORM <tn report> PREVIEW <iu kin> In report: REPORT FORM <tn report> TO PRINTER

6.4.2. Cc thnh phn trn Report

Title: Dng in trn mi report: T menu report, chn title summary Page Header: in trn mi header ca mi trang in. Column header: in tn header ca mi ct. chn, t menu file chn page setup, chn gi tr cho column number ln hn 1. Group header: Xut hin mi khi bt u nhm mi. chn, t menu report chn data grouping. Detail: phn chi tit trn mi record (ng vi tng record trn bng d liu). Group footer: In phn Footer ca mi nhm. chn, t menu report chn data grouping.

Column footer: In phn Footer ca mi ct. chn, t menu file, chn page setup, chn gi tr cho column nimber ln hn 1. Page Footer: In phn Footer ca mi trang. Sumary: Phn tm tt ca mi report. 6.4.3. Cc control trn Report Thanh cng c Report Control Chc nng ca cc control: Field trong bng d liu, bin v cc biuthc ton Text thun tu ng k Hp v ng khung Hnh trn, elip Hnh nh hoc field General 6.4.4. a cc control vo report Thc hin cc bc sau: + Chn control thch hp + Ko r chut trn report xc nh v tr ca n trn report + Hiu chnh cc control a. a field vo report: + Kch chut vo + Trong hp report Expression, chn nt lnh sau hp Expression. + Trong hp field, hcn tn trng hay bin thch hp. + Chn OK. Field Label Line Rectangle Rounded Rectangle Picture

abl

b. a label vo report: + Chn + G ni dung ca label c. a Picture bound control vo report: + Chn picture bound control + Xut hin hp hi thoi report picture, chn file, nu mun chn hnh nh t file, chn field nu mun chn trng General. + Chn Ok 6.5. V d Thit k Report nh sau (da vo Bng CANBO.DBF bi tp 2):

iif(GIOI TINH=".T.", "nam"

iif(COGIADINH=".F.",

18.

CHNG 7.

TO MENU V QUN L N

18.1. 7.1. TO MENU 18.2. 7.1.1. GII THIU

Menu cung cp mt phng thc c cu trc v giao din vi ngi dng tc ng ln nhng cu lnh trong ng dng. Vic sp xp v thit k menu thch hp s gip cho ngi dng c thun li khi s dng h thng menu ca bn.
18.3. 7.1.2. CC BC TI MT MENU H THNG

1. Sp xp v thit k: Quyt nh menu no bn cn chng xut hin v tr no trn mn hnh, cn nhng menu con no? 2. S dng menu designer, to menu v cc Submenu. 3. Gn cc cu lnh tng ng vi cng vic. 4. Bin dch menu 5. Tin hnh chy th, kim tra.
18.4. 7.1.3. TO MENU H THNG

7.1.3.1. Qun l menu h thng Menu h thng c lu tr tn a vi file c phn m rng l *.MNX To menu bng cng c Designer Menu: Thc hin lnh: CREATE MENU <tn menu> M menu c: MODIFY MENU <tn menu> Dch file Menu: dch file menu, t mn hnh Menu Designer chn lnh Generate. File menu sau khi dch s c phn m rng l MPR. 7.1.3.2. To menu h thng thng qua Menu Designer Sau khi thc hin lnh Create menu, ta c mn hnh giao din Menu: Designer nh

sau:

+ Trong hp Prompt, ta a vo tn cn hin th trn giao din. + Trong hp Result, chn: - Submenu nu mun to menu con. - Procedure nu mun thi hnh th tc - Command n u mu n th c hi n m t l nh.
+ Kt thc, n Ctrl_W.

18.5. 7.2.QUN L N 18.6. 7.2.1. KHI NIM N

n l tn gi ch n ng dng m bn ang xy dng. Thng thng cc thnh phn ca mt n bao gm: + Cc bng d liu (table). + Cc file c s d liu (database) + Cc form + Cc report + Cc query + Cc file khc nh m thanh, hnh nh, ti liu, hnh nh con tr,...

18.7. 7.2.2. QUN L N

Mt n trong Visual Foxpro c lu tr trn file c phn m rng mc nh l *.PRJ. 7.2.2.1. To mi cc n Thc hin lnh: CREATE PROJECT <tn n> Lc ny xut hin ca s qun l n Project Manager nh trn. +

Database: Bao gm cc: Table: Cc bng d liu c lin kt vi nhau hay cc bng t do.

Query: L cu trc ly thng tin t cc bng table. View: L cc Query chuyn dng m ta c th truy xut d liu cc b v t xa cho php cp nht cc ngun d liu bng cch lm thay Report bi quyre. + Documents: Cha cc ti liu s dng cho n; bao gm cc form v report.

+ Class: Lit k cc th vin c s dng. + Code: v nhng file khc: Lit k cc file chng trnh v cc file khc c s dng trong chng trnh. chnh sa bt k mt thnh phn no trong n ta chn n ri chn nt Modify. thm bt k mt file no cho n ta kch nt add (nu chn file c) hoc nt new (nu to mi). Mun loi b bt k mt thnh phn no ca n ta chn n ri chn nt remove. 7.2.2.2. M mt n c Thc hin lnh: MODIFY PROJECT <tn n> 7.2.2.3. Dch n + Dch sang APP: Khi ny, chn n phi c mt bn sao ca Visual Foxpro. Dng lnh BUILD <tn n> + Dch sang file c phn m rng l exe: Khi ny, ngi dng khng cn c Visual Foxpro nhng phi cung cp hai file: vfp6r.dll v vfp6renu.dll c ci t trong ng dn hoc trong cng th mc vi ng dng. Dng lnh: BUILD EXE <tn n> 7.2.2.4. Chy n Sau khi dch, ta c th chy n thng qua lnh: DO <tn ng dng>
18.8. 7.2.3. T STARTING POINT CHO N

Khi ng dng c thi hnh, c mt im bt u, l Starting point. chn mt thnh phn ca d n l Starting point: + Chn thnh phn c t l Starting point. + T Menu Project, chn Set main. Thng thng, Starting point l mt chng trnh khi ng cha cc thnh phn: Do setup.prg

Do mainmenu.mpr Read Events Do cleanup.prg a. Do Setup.prg: L th c hi n ch ng trnh thi t l p mi tr ng cho h th ng.

b. Do mainmenu.mpr: Chy file menu chnh thit lp giao din cho h thng. c. Read Events: Bt u thc hin vng lp thc hin cng vic. d. Do cleanup.prg: Chy chng trnh dn dp mi trng, tr li mi trng cho h thng v thot khi h thng. y, phi c lnh Clear Events thot khi vng lp c thit lp bi lnh Read Events.