Tuesday, 30 April 2013

Membuat Form Kasir Atau Admin Pada Project VB 6

Sebelum anda mengikuti Sesi ini, anda harus mengikuti Postingan kami sebelumnya Yaitu :
Membuat Form Menu Utama
Membuat Database
membuat Koneksi Database
Membuat Form Login
Menambahakan Components ADODC dan Datagrid

karena tanpa anda meilhat postingan diatas, dipastikan anda tersesat * hehhehehe....
Baiklah untuk membuat Form Kasir atau Admin berikut langkah - langkahnya :

Klik Add Form
Ubah name : FormMasterAdmin
Caption: Form Admin

Buat layout Form seperti dibawah ini :


Dan Berikut adalah Koding untuk Form Admin diatas :


Dim mvBookMark As Variant

Private Sub CmdEdit_Click()
    If CmdEdit.Caption = "&Edit" Then
        CmdInput.Enabled = False
        CmdEdit.Caption = "&Simpan"
        CmdHapus.Enabled = False
        CmdTutup.Caption = "&Batal"
        SiapIsi
        Text1.SetFocus
    Else
        If Text2 = "" Or Text3 = "" Or Combo1 = "" Then
            MsgBox "Masih Ada Data Yang Kosong", vbInformation, "Pemberitahuan"
        Else
            Dim SQLEdit As String
            SQLEdit = "Update Admin Set NamaAdmin= '" & Text2 & "', PasswordAdmin='" & Text3 & "', LevelAdmin='" & Combo1 & "' where KodeAdmin='" & Text1 & "'"
            koneksi.Execute SQLEdit
           
            MsgBox "Data Berhasil Diedit", vbInformation, "Pemberitahuan"
           
            Form_Activate
        End If
    End If
End Sub

Private Sub Combo1_keypress(KeyAscii As Integer)
If KeyAscii = 13 Then
Text3.SetFocus
End If
End Sub
Private Sub Form_Activate()
Call BukaDB
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & App.Path & "\DBtemplate.mdb"
Adodc1.RecordSource = "select KodeAdmin as [Kode],NamaAdmin as [Nama], LevelAdmin as [Level] from Admin"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
DataGrid1.Refresh
Call kondisiawal
CmdInput.SetFocus
End Sub

Private Sub AutoNomor()
Call BukaDB
RSAdmin.Open ("select * from Admin Where KodeAdmin In(Select Max(KodeAdmin)From Admin)Order By kodeAdmin Desc"), koneksi
RSAdmin.Requery
    Dim Urutan As String * 6
    Dim Hitung As Long
    With RSAdmin
        If .EOF Then
            Urutan = "ADM" + "001"
            Text1 = Urutan
        Else
            Hitung = Right(!KodeAdmin, 3) + 1
            Urutan = "ADM" + Right("000" & Hitung, 3)
        End If
        Text1 = Urutan
    End With
End Sub

Sub Form_Load()
Text1.MaxLength = 6
Text2.MaxLength = 20
Text3.MaxLength = 10
Text3.PasswordChar = "X"
kondisiawal
End Sub
Private Sub kosongkantext()
    Text1 = ""
    Text2 = ""
    Text3 = ""
    Combo1 = ""
End Sub

Private Sub SiapIsi()
    Text1.Enabled = True
    Text2.Enabled = True
    Text3.Enabled = True
    Combo1.Enabled = True
    Combo1.AddItem "USER"
    Combo1.AddItem "ADMIN"
End Sub

Private Sub TidakSiapIsi()
    Text1.Enabled = False
    Text2.Enabled = False
    Text3.Enabled = False
    Combo1.Enabled = False
End Sub

Private Sub kondisiawal()
    kosongkantext
    TidakSiapIsi
    CmdInput.Caption = "&Input"
    CmdEdit.Caption = "&Edit"
    CmdHapus.Caption = "&Hapus"
    CmdTutup.Caption = "&Tutup"
    CmdInput.Enabled = True
    CmdEdit.Enabled = True
    CmdHapus.Enabled = True
End Sub

Private Sub TampilkanData()
    With RSAdmin
        If Not RSAdmin.EOF Then
            Text2 = RSAdmin!NamaAdmin
            Combo1 = RSAdmin!levelAdmin
            Text3 = RSAdmin!passwordAdmin
        End If
    End With
End Sub


Private Sub CmdInput_Click()
    If CmdInput.Caption = "&Input" Then
        CmdInput.Caption = "&Simpan"
        CmdEdit.Enabled = False
        CmdHapus.Enabled = False
        CmdTutup.Caption = "&Batal"
        SiapIsi
        kosongkantext
        Call AutoNomor
        Text1.Enabled = False
        Text2.SetFocus
    Else
        If Text1 = "" Or Text2 = "" Or Text3 = "" Or Combo1 = "" Then
            MsgBox "Data Belum Lengkap...!", vbInformation, "Pemberitahuan"
           
        Else
            Dim SQLTambah As String
            SQLTambah = "Insert Into Admin (KodeAdmin,NamaAdmin,passwordAdmin,levelAdmin) values ('" & Text1 & "','" & Text2 & "','" & Text3 & "','" & Combo1 & "')"
            koneksi.Execute SQLTambah
           
            MsgBox "Data Berhasil Ditambah", vbInformation, "Pemberitahuan"
           
            Form_Activate
            Call kondisiawal
        End If
    End If
End Sub


Private Sub CmdHapus_Click()
    If CmdHapus.Caption = "&Hapus" Then
        CmdInput.Enabled = False
        CmdEdit.Enabled = False
        CmdTutup.Caption = "&Batal"
        kosongkantext
        SiapIsi
        Text1.SetFocus
    End If
End Sub

Private Sub CmdTutup_Click()
    Select Case CmdTutup.Caption
        Case "&Tutup"
            Unload Me
        Case "&Batal"
            TidakSiapIsi
            kondisiawal
    End Select
End Sub

Function CariData()
    Call BukaDB
    RSAdmin.Open "Select * From Admin where KodeAdmin='" & Text1 & "'", koneksi
End Function

Private Sub Text1_KeyPress(KeyAscii As Integer)
KeyAscii = Asc(UCase(Chr(KeyAscii)))
If KeyAscii = 13 Then
    If Len(Text1) < 6 Then
        MsgBox "Kode Harus 6 Digit", vbInformation, "Pemberitahuan"
        Text1.SetFocus
        Exit Sub
    Else
        Text2.SetFocus
    End If

    If CmdInput.Caption = "&Simpan" Then
        Call CariData
        If Not RSAdmin.EOF Then
            TampilkanData
            MsgBox "Kode Admin Sudah Ada", vbInformation, "Pemberitahuan"
            kosongkantext
            Text1.SetFocus
        Else
            Text2.SetFocus
        End If
    End If
   
    If CmdEdit.Caption = "&Simpan" Then
        Call CariData
        If Not RSAdmin.EOF Then
            TampilkanData
            Text1.Enabled = False
            Text2.SetFocus
        Else
            MsgBox "Kode Admin Tidak Ada", vbInformation, "Pemberitahuan"
            Text1 = ""
            Text1.SetFocus
        End If
    End If
   
    If CmdHapus.Enabled = True Then
        Call CariData
        If Not RSAdmin.EOF Then
            TampilkanData
            Pesan = MsgBox("Yakin akan dihapus", vbYesNo)
            If Pesan = vbYes Then
                Dim SQLHapus As String
                SQLHapus = "Delete From Admin where kodeAdmin= '" & Text1 & "'"
                koneksi.Execute SQLHapus
               
                MsgBox "Data Berhasil Dihapus", vbInformation, "Pemberitahuan"
               
                kondisiawal
                Form_Activate
            Else
                kondisiawal
                CmdHapus.SetFocus
            End If
        Else
            MsgBox "Data Tidak Ditemukan", vbInformation, "Pemberitahuan"
            Text1.SetFocus
        End If
    End If
End If
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)
    KeyAscii = Asc(UCase(Chr(KeyAscii)))
    If KeyAscii = 13 Then Combo1.SetFocus
End Sub
Private Sub Text3_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        If CmdInput.Enabled = True Then
            CmdInput.SetFocus
        ElseIf CmdEdit.Enabled = True Then
            CmdEdit.SetFocus
        End If
    End If
End Sub



Catatan :
Pada MenuUtama anda tambahkan pada MenuEditor, Master Admin. dan ketika di Klik pastikan Form Admin yang anda buat seperti diatas FormMasterAdmin.Show




No comments:

Post a Comment