. Hariyadi

Senin, 04 Juli 2011

Sub hapus()
    kd_produk.Enabled = True
    ClearFORM Me
    Call RubahCMD(Me, True, False, False, False)
    cmdproses(1).Caption = "&baru"
End Sub

Sub prosesDB(Log As Byte)
   Select Case Log
        Case 0
            SQL = "INSERT INTO produk(kd_produk, nama, satuan, jumlah)" & _
                " values('" & kd_produk.Text & _
                "','" & nama.Text & _
                "','" & satuan.Text & _
                "','" & jumlah.Text & "')"
        Case 1
           
            SQL = "UPDATE produk SET Nama ='" & nama.Text & "'," & _
                  " satuan = '" & satuan.Text & "'," & _
                  " jumlah = '" & jumlah.Text & "'," & _
                  " where kd_produk ='" & kd_produk.Text & "'"
        Case 2
            SQL = "DELETE FROM produk WHERE kd_produk='" & kd_produk.Text & "'"
    End Select
    MsgBox "Pemorosesan RECORD Database telah berhasil...!", vbInformation, "Data produk"
    Db.Execute SQL, adCmdTable
    Call hapus
    Adodc1.Refresh
    kd_produk.SetFocus
End Sub

Sub Tampilproduk()
    On Error Resume Next
    kd_produk.Text = RS!kd_produk
    nama.Text = RS!nama
    satuan.Text = RS!satuan
    jumlah.Text = RS!jumlah
   
End Sub

Private Sub Cmdproses_Click(Index As Integer)
Select Case Index
    Case 0
        Call hapus
        kd_produk.SetFocus
    Case 1
        If cmdproses(1).Caption = "&baru" Then
            Call prosesDB(0)
        Else
            Call prosesDB(1)
        End If
    Case 2
        x = MsgBox("Yakin RECORD produk Akan Dihapus...!", vbQuestion + vbYesNo, "produk")
        If x = vbYes Then prosesDB 2
        Call hapus
        kd_produk.SetFocus
    Case 3
        Call hapus
        kd_produk.SetFocus
    Case 4
        Unload Me
    End Select
End Sub

Private Sub Form_Load()
    Call OPENDB
    Call hapus
   
   
End Sub

Private Sub kd_produk_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        If kd_produk.Text = "" Then
            MsgBox "Masukkan kd_produk produk !", vbInformation, "produk"
            kd_produk.SetFocus
            Exit Sub
        End If
        SQL = "SELECT * FROM produk WHERE kd_produk='" & kd_produk.Text & "'"
        If RS.State = adStateOpen Then RS.Close
        RS.Open SQL, Db, adOpenDynamic, adLockOptimistic
        If RS.RecordCount <> 0 Then
            Tampilproduk
            Call RubahCMD(Me, False, True, True, True)
            cmdproses(1).Caption = "&Edit"
            kd_produk.Enabled = False
        Else
            x = kd_produk.Text
            Call hapus
            kd_produk.Text = x
            Call RubahCMD(Me, False, True, False, True)
            cmdproses(1).Caption = "&baru"
        End If
        nama.SetFocus
    End If
End Sub

Tidak ada komentar:

Posting Komentar