Listing Program FrmMatakuliah
Sub Hapus()
KODE.Enabled = True
KODE.Text = ""
NAMA.Text = ""
SKS.Text = ""
SEMESTER.Text = ""
Call RubahCMD(True, False, False, False)
CmdProses(1).Caption = "&Simpan"
End Sub
Sub ProsesDB(Log As Byte)
Select Case Log
Case 0
SQL = "INSERT INTO MataKuliah(KODE, Nama, SKS, SEMESTER)" & _
" values('" & KODE.Text & _
"','" & NAMA.Text & _
"','" & SKS.Text & _
"','" & SEMESTER.Text & "')"
Case 1
SQL = "UPDATE MataKuliah SET Nama ='" & NAMA.Text & "'," & _
" SKS = '" & SKS.Text & "'," & _
" SEMESTER = '" & SEMESTER.Text & "' " & _
" where KODE ='" & KODE.Text & "'"
Case 2
SQL = "DELETE FROM MataKuliah WHERE KODE='" & KODE.Text & "'"
End Select
MsgBox "Pemorosesan RECORD Database telah berhasil...!", vbInformation, "Data MataKuliah"
Db.Execute SQL, adCmdTable
Call Hapus
Adodc1.Refresh
KODE.SetFocus
End Sub
Sub TampilMataKuliah()
On Error Resume Next
KODE.Text = RS!KODE
NAMA.Text = RS!NAMA
SKS.Text = RS!SKS
SEMESTER.Text = RS!SEMESTER
Call RubahCMD(False, True, True, True)
CmdProses(1).Caption = "&Edit"
KODE.Enabled = False
End Sub
Private Sub CmdProses_Click(Index As Integer)
Select Case Index
Case 0
Call Hapus
KODE.SetFocus
Case 1
If CmdProses(1).Caption = "&Simpan" Then
Call ProsesDB(0)
Else
Call ProsesDB(1)
End If
Case 2
x = MsgBox("Yakin RECORD MataKuliah Akan Dihapus...!", vbQuestion + vbYesNo, "MataKuliah")
If x = vbYes Then ProsesDB 2
Case 3
Call Hapus
KODE.SetFocus
Case 4
Unload Me
End Select
End Sub
Private Sub Form_Load()
Call OPENDB
Call Hapus
SEMESTER.AddItem "I"
SEMESTER.AddItem "II"
SEMESTER.AddItem "III"
SEMESTER.AddItem "IV"
SEMESTER.AddItem "V"
SEMESTER.AddItem "VI"
SKS.AddItem "2"
SKS.AddItem "3"
SKS.AddItem "4"
End Sub
Private Sub KODE_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If KODE.Text = "" Then
MsgBox "Masukkan KODE MataKuliah !", vbInformation, "MataKuliah"
KODE.SetFocus
Exit Sub
End If
SQL = "SELECT * FROM MataKuliah WHERE KODE='" & KODE.Text & "'"
If RS.State = adStateOpen Then RS.Close
RS.Open SQL, Db, adOpenDynamic, adLockOptimistic
If RS.RecordCount <> 0 Then
TampilMataKuliah
Else
x = KODE.Text
Call Hapus
KODE.Text = x
Call RubahCMD(False, True, False, True)
CmdProses(1).Caption = "&Simpan"
End If
NAMA.SetFocus
End If
End Sub
Sub RubahCMD(L0 As Boolean, L1 As Boolean, L2 As Boolean, L3 As Boolean)
CmdProses(0).Enabled = L0
CmdProses(1).Enabled = L1
CmdProses(2).Enabled = L2
CmdProses(3).Enabled = L3
End Sub
Tidak ada komentar:
Posting Komentar