Penambahan Coding dalam Form Input Guru :
Option Explicit
Dim st As Boolean
Dim rs As ADODB.Recordset
Private Sub enbTombol(TAMBAH As Boolean, SIMPAN As Boolean, EDIT As Boolean, HAPUS As Boolean, KELUAR As Boolean, BATAL As Boolean, CARI As Boolean)
Command(0).Enabled = TAMBAH
Command(1).Enabled = SIMPAN
Command(2).Enabled = EDIT
Command(3).Enabled = HAPUS
Command(6).Enabled = CARI
Command(4).Visible = KELUAR
Command(5).Visible = BATAL
Command(6).Enabled = CARI
End Sub
Private Sub aktif()
Text(0).Enabled = True
Text(1).Enabled = True
Text(2).Enabled = True
Text(3).Enabled = True
DTPicker1.Enabled = True
Combo(0).Enabled = True
Combo(1).Enabled = True
Text(4).Enabled = True
TextCari(5).Enabled = True
End Sub
Private Sub pasif()
Text(0).Enabled = False
Text(1).Enabled = False
Text(2).Enabled = False
Text(3).Enabled = False
DTPicker1.Enabled = False
Combo(0).Enabled = False
Combo(1).Enabled = False
Text(4).Enabled = False
TextCari(5).Enabled = False
End Sub
Private Sub kosong(Optional enb As Boolean = False)
Dim I As Integer
For I = 0 To Text.Count - 1
Text(I) = ""
Text(I).Enabled = enb
Next I
Text(1).SetFocus
End Sub
Private Function cKosong() As Boolean
Dim I As Integer
For I = 0 To Text.Count - 1
If Text(I) = "" Then cKosong = True: Exit Function
Next I
cKosong = False
End Function
Private Function cek() As Boolean
Dim I As Integer
For I = 0 To Text.Count - 1
If Text(I) = "" Then cek = True: Exit Function
Next I
'cek False
End Function
Private Sub Command_Click(Index As Integer)
Select Case Index
Case 0 ' TAMBAH
kosong True
Text(0) = AutoNum("G", 5, "guru", "kde_guru")
Text(0).Enabled = True
st = True
Text(0).SetFocus
Call aktif
enbTombol False, True, False, False, True, False, True
Command(4).Visible = True
Case 1 'SIMPAN
If cek = True Then
MsgBox "Isikan Data Dengan Benar!", vbInformation, "Kosong"
Exit Sub
End If
ya = MsgBox("Apakah Anda yakin data ini akan Anda simpan?", vbQuestion + vbYesNo, "Simpan")
If ya = vbYes Then
Set rs = ConnAPP.Execute("SELECT * FROM Guru WHERE Kde_Guru = '" & Text(0).Text & "'")
If Not rs.EOF Then
rs.Close
Set rs = ConnAPP.Execute("UPDATE Guru set NIP='" & Text(1).Text & "',Nma_Guru='" & Text(2).Text & "',Tempat='" & Text(3).Text & "',TL='" & DTPicker1 & "',Alamat='" & Text(4).Text & "',Sex='" & Combo(0) & "',Agama='" & Combo(1) & "' WHERE Kde_Guru = '" & Text(0).Text & "'")
MsgBox "Berhasil Disimpan", vbInformation + vbOKOnly, "Simpan"
enbTombol False, True, True, True, False, True, True
guru.Enabled = True
Private Sub tampil()
siswa.ListItems.Clear
Set rs = ConnAPP.Execute("SELECT * FROM Siswa")
While Not rs.EOF
Set isi = siswa.ListItems.Add(, , rs!Kde_Siswa)
isi.SubItems(1) = rs!NIS
isi.SubItems(2) = rs!Nama
isi.SubItems(3) = rs!Sex
isi.SubItems(4) = rs!Tmpt
isi.SubItems(5) = rs!TL
isi.SubItems(6) = rs!Agama
isi.SubItems(7) = rs!Alamat
isi.SubItems(8) = rs!Masuk
isi.SubItems(9) = rs!KELUAR
rs.MoveNext
Wend
End Sub
Private Sub siswa_Click()
Set rs = ConnAPP.Execute(" SELECT * FROM Siswa WHERE Kde_Siswa='" & siswa.SelectedItem & "'")
If Not rs.EOF Then
Text(0) = rs!Kde_Siswa
Text(1) = rs!NIS
Text(2) = rs!Nama
Text(3) = rs!Tmpt
DTPicker1 = rs!TL
Combo(0) = rs!Sex
Combo(1) = rs!Agama
Text(4) = rs!Alamat
Text(5) = rs!Masuk
Text(6) = rs!KELUAR
End If
enbTombol False, False, True, True, True, False, True
Call pasif
End Sub
Else
rs.Close
Set rs = ConnAPP.Execute("insert into Guru(Kde_Guru,NIP,Nma_Guru,Tempat,TL,Sex, Agama,Alamat)values('" & Text(0) & "','" & Text(1) & "','" & Text(2) & "','" & Text(3) & "','" & DTPicker1 & "','" & Combo(0) & "','" & Combo(1) & "','" & Text(4) & "')")
MsgBox "Berhasil Disimpan", vbInformation + vbOKOnly, "Simpan"
End If
Call tampil
enbTombol True, False, False, False, False, True, True
Command(6).Enabled = True
End If
Case 2 ' EDIT
Call aktif
enbTombol False, True, True, True, True, False, True
Case 3 ' HAPUS
If MsgBox("Apakah Data Ini Akan Dihapus !", vbQuestion + vbYesNo, "warning") = vbYes Then
strsql = "DELETE FROM Guru WHERE Kde_Guru='" & Text(0) & "'"
ConnAPP.Execute (strsql)
MsgBox "Data Berhasil Dihapus !"
guru.ListItems.Remove guru.SelectedItem.Index
kosong True
Call pasif
enbTombol True, False, False, False, False, True, True
End If
Case 6 ' CARI
guru.ListItems.Clear
Set rs = ConnAPP.Execute("SELECT * FROM guru where Kde_Guru='" & Text(5) & "'")
While Not rs.EOF
Set isi = guru.ListItems.Add(, , rs!Kde_Guru)
isi.SubItems(1) = rs!NIS
isi.SubItems(2) = rs!Nama
isi.SubItems(3) = rs!Sex
isi.SubItems(4) = rs!Tmpt
isi.SubItems(5) = rs!TL
isi.SubItems(6) = rs!Agama
isi.SubItems(7) = rs!Alamat
isi.SubItems(8) = rs!Masuk
isi.SubItems(9) = rs!KELUAR
rs.MoveNext
MsgBox "Data Ditemukan...!!!"
Wend
Text(5) = ""
Case 4 'KELUAR
Unload Me
Case 5 'BATAL
Unload Me
End Select
End Sub
Private Sub Form_Load()
Combo(0).AddItem "LAKI-LAKI"
Combo(0).AddItem "PEREMPUAN"
Combo(1).AddItem "ISLAM"
Combo(1).AddItem "KRSTEN"
Combo(1).AddItem "KHATOLIK"
Combo(1).AddItem "BUDHA"
Combo(1).AddItem "HINDU"
Call tampil
'" & DTPicker1 & "''" & DTPicker1 & "''" & DTPicker1 & "'
End Sub
Private Sub tampil()
guru.ListItems.Clear
Set rs = ConnAPP.Execute("SELECT * FROM Guru")
While Not rs.EOF
Set isi = guru.ListItems.Add(, , rs!Kde_Guru)
isi.SubItems(1) = rs!NIP
isi.SubItems(2) = rs!Nma_Guru
isi.SubItems(3) = rs!Tempat
isi.SubItems(4) = rs!TL
isi.SubItems(5) = rs!Sex
isi.SubItems(6) = rs!Agama
isi.SubItems(7) = rs!Alamat
rs.MoveNext
Wend
End Sub
Private Sub guru_Click()
Set rs = ConnAPP.Execute(" SELECT * FROM guru WHERE Kde_guru='" & guru.SelectedItem & "'")
If Not rs.EOF Then
Text(0) = rs!Kde_Guru
Text(1) = rs!NIP
Text(2) = rs!Nma_Guru
Text(3) = rs!Tempat
DTPicker1 = rs!TL
Combo(0) = rs!Sex
Combo(1) = rs!Agama
Text(4) = rs!Alamat
End If
enbTombol False, False, True, True, True, False, True
Call pasif
End Sub
Tidak ada komentar:
Posting Komentar