Wednesday, October 12, 2011

Membuat Sebuah Aplikasi pada Visual Foxpro

Latihan : Kartu Hasil Studi Mahasisw
1. Buatlah Project dengan nama : khs.pjx
2. Buatlah Database didalam project : datakhs.dbc
3. Buatlah Tabel-tabel dibawah ini.
Tabel : mhs.dbf
Name                     type                 Width               Index
Nim                        Character         8                      Primary/Descending(↓)
Nama                     Character         30
Jur                          Character         2
Jnskel                     Character         10
alamat                    Memo              4
telp                         Character         13
foto                        General            4
4. Buatlah form dengan tampilan sebagai berikut : frm_mhs.scx

Properties
Object Name Lain-lain
Form1 Form1 Caption=FORM MAHASISWA
Text1 Txtnim
Text2 Txtnama
Combo1 Cjur Row Source=KA,MI,TK  Row Source Type=1-Value
Optiongroup1 Ojns
Option1 Opl Caption=Laki-laki
Option2 Opp Caption=Perempuan
Edit1 Ealmt
Text3 Txttelp Input Mask=999-9999999999
Command1 Cmdadd
Command2 Cmdcancel
Command3 Cmdsave
Command4 Cmdedit
Command5 Cmddelete
Command6 Cmdexit
Text3 Txtcari
Command7 Cmdfind
Timer1 Timer1 Interval=100
Text4 Txtdatetime Alignment=2-Center
Command7 Cmdupload Caption=\<UPLOAD
Image2 Image_foto Visible=false
Olebondcontrol1 Olefoto Visible=false
#        Buatlah methode : aktif, nonaktif, bersih, simpan, tampil, urut

#        Listing Program frm_mhs.scx
Form1                                                                         activate
thisform.nonaktif
thisform.bersih
thisform.txtnim.Enabled= .F.
thisform.cmdsave.Enabled= .F.
thisform.cmdcancel.Enabled= .F.
thisform.cmdedit.Enabled= .F.
thisform.cmddelete.Enabled= .F.
thisform.cmdadd.Enabled= .T.
thisform.AutoCenter= .T.
thisform.Caption=”FORM MAHASISWA”+SPACE(100)
Form1                                                                         load
SET DEFAULT TO c:\pagi\kelas\nim\khs&&mengaktifkan path folder
USE mhs &&mengaktifkan table mhs.dbf
SET ORDER TO tag nim &&menggunakan key nim
PUBLIC no &&PUBLIC berfungsi untuk membuat variabel secara global
PUBLIC isi,lcgambar
SET DATE ITALIAN
Form1                                                                         aktif
thisform.txtnama.Enabled= .T.
thisform.cjur.Enabled= .T.
thisform.ojns.Enabled= .T.
thisform.ealmt.Enabled= .T.
thisform.txttelp.Enabled= .T.
thisform.olefoto.Enabled= .T.
thisform.cmdupload.Enabled= .T.
Form1                                                                         nonaktif
thisform.txtnama.Enabled= .F.
thisform.cjur.Enabled= .F.
thisform.ojns.Enabled= .F.
thisform.ealmt.Enabled= .F.
thisform.txttelp.Enabled= .F.
thisform.olefoto.Enabled= .F.
thisform.cmdupload.Enabled= .F.
Form1                                                                         bersih
thisform.txtnim.Value=”"
thisform.txtnama.Value=”"
thisform.cjur.Value=”"
thisform.ojns.Value=0
thisform.ealmt.Value=”"
thisform.txttelp.Value=”"
thisform.olefoto.Visible= .F.
thisform.image_foto.Visible= .F.
Form1                                                                         tampil
thisform.txtnim.Value=mhs.nim
thisform.txtnama.Value=mhs.nama
thisform.cjur.Value=mhs.jur
IF mhs.jnskel=”Laki-laki” then
thisform.ojns.opl.Value=1
thisform.ojns.opp.Value=0
ELSE
IF mhs.jnskel=”Perempuan” then
thisform.ojns.opl.Value=0
thisform.ojns.opp.Value=1
ENDIF
ENDIF
thisform.ealmt.Value=mhs.alamat
thisform.txttelp.Value=mhs.telp
thisform.olefoto.ControlSource=”mhs.foto”
thisform.olefoto.Visible= .T.
Form1                                                                         urut
no=INT(VAL(RIGHT(mhs.nim,4))+1)
no=REPLICATE(“0″,+4-LEN(LTRIM(STR(no))))+LTRIM(STR(no))

Form1                                                                         simpan
replace nim WITH thisform.txtnim.Value
replace nama WITH thisform.txtnama.Value
replace jur WITH thisform.cjur.Value
IF thisform.ojns.opl.Value=1 then
thisform.ojns.opp.Value=0
replace jnskel WITH thisform.ojns.opl.Caption
ELSE
IF thisform.ojns.opp.Value=1 then
thisform.ojns.opl.Value=0
replace jnskel WITH thisform.ojns.opp.Caption
ENDIF
ENDIF
replace alamat WITH thisform.ealmt.Value
replace telp WITH thisform.txttelp.Value
APPEND GENERAL foto FROM ALLTRIM(lcgambar)

cmdadd                                                                       click
isi=.t.
thisform.aktif
thisform.bersih
thisform.cmdcancel.Enabled= .T.
thisform.cmdsave.Enabled= .T.
thisform.cmdedit.Enabled= .F.
thisform.cmddelete.Enabled= .F.
thisform.cmdadd.Enabled= .F.
thisform.txtnama.SetFocus
cmdcancel                                                                   click
thisform.bersih
thisform.nonaktif
thisform.cmdsave.Enabled= .F.
thisform.cmdcancel.Enabled= .F.
thisform.cmdedit.Enabled= .F.
thisform.cmddelete.Enabled= .F.
thisform.cmdadd.Enabled= .T.
thisform.Refresh

cmdedit                                                                       click
isi=.f.
thisform.aktif
thisform.cjur.Enabled= .F.
thisform.cmddelete.Enabled= .F.
thisform.cmdsave.Enabled= .T.
thisform.cmdcancel.Enabled= .T.

cmdexit                                                                       click
quit

cmdsave                                                                      click
IF EMPTY(thisform.txtnim.Value) OR;
EMPTY(thisform.txtnama.Value) OR;
EMPTY(thisform.cjur.Value) OR;
thisform.ojns.Value=0 OR;
EMPTY(thisform.ealmt.Value) OR;
EMPTY(thisform.txttelp.Value) OR;
EMPTY(lcgambar) then
MESSAGEBOX(“DATA HARUS DI ISI LENGKAP”,48,”WARNING”)
RETURN
ENDIF
IF isi=.t. THEN &&penyimpanan awal sebelum di edit
APPEND BLANK &&membuat record kosong
thisform.simpan
MESSAGEBOX(“DATA TELAH TERSIMPAN”,64,”INFO”)
ELSE
IF isi=.f. THEN &&penyimpanan data setelah di edit
thisform.simpan
MESSAGEBOX(“DATA TELAH TERUPDATE”,64,”INFO”)
ENDIF
thisform.nonaktif
thisform.bersih
thisform.cmdsave.Enabled= .F.
thisform.cmdcancel.Enabled= .F.
thisform.cmdedit.Enabled= .F.
thisform.cmddelete.Enabled= .F.
thisform.cmdadd.Enabled= .T.
thisform.Refresh

cmddelete                                                                   click
hapus=MESSAGEBOX(“Data Mahasiswa dengan NIM “+thisform.txtnim.Value+;
” ingin dihapus?”,36,”INFO”)
IF hapus=6 then
DELETE
PACK
ENDIF
thisform.bersih
thisform.cmddelete.Enabled= .F.
thisform.cmdedit.Enabled= .F.
thisform.cmdadd.Enabled= .T.
cmduplad                                                                    click
lcgambar=”"
lcgambar=GETFILE(“BMP”)
thisform.image_foto.Stretch= 2
thisform.image_foto.Picture=ALLTRIM(lcgambar)
thisform.image_foto.Visible= .T.

Timer1                                                            timer
thisform.txtdatetime.Value=DATETIME()
teks=thisform.caption
thisform.caption=right(teks,len(teks)-1)+left(teks,1)

cjur                                                                              click
IF thisform.cjur.Value=”KA” then
SEEK ALLTRIM(“11″)
thisform.urut
thisform.txtnim.Value=”11″+RIGHT(DTOC(DATE()),2)+no
ELSE
IF thisform.cjur.Value=”MI” then
SEEK ALLTRIM(“12″)
thisform.urut
thisform.txtnim.Value=”12″+RIGHT(DTOC(DATE()),2)+no
ELSE
IF thisform.cjur.Value=”TK” then
SEEK ALLTRIM(“13″)
thisform.urut
thisform.txtnim.Value=”13″+RIGHT(DTOC(DATE()),2)+no
ENDIF
ENDIF
ENDIF
cmdfind                                                           click
SET ORDER TO tag nim
IF SEEK(ALLTRIM(thisform.txtcari.Value))
thisform.tampil
thisform.cmdedit.Enabled= .T.
thisform.cmddelete.Enabled= .T.
thisform.cmdsave.Enabled= .F.
thisform.cmdcancel.Enabled= .F.
thisform.cmdadd.Enabled= .F.
ELSE
MESSAGEBOX(“Data tidak ada!!”,64,”INFO”)
thisform.txtcari.SetFocus
ENDIF
thisform.txtcari.Value=”"
thisform.Refresh

No comments:

Post a Comment