Form Master Produk Part 5

Selamat Siang coder berikut lanjutan dari tutorial sebelumnya dan masih di applikasi sederhana Minimarket dan bisa di cek >>>>> Disini ...

Step 1 :
Copikan coding berikut dibawah public class
Sub tampil(ByVal sql As String)
        kon.Open()
        perintah.Connection = kon
        perintah.CommandType = CommandType.Text
        perintah.CommandText = sql
        mda.SelectCommand = perintah
        ds.Tables.Clear()
        mda.Fill(ds, "data")
        dg.DataSource = ds.Tables("data")
        kon.Close()
    End Sub

    Sub proses(ByVal sql As String)
        kon.Open()
        perintah.Connection = kon
        perintah.CommandType = CommandType.Text
        perintah.CommandText = sql
        perintah.ExecuteNonQuery()
        kon.Close()
    End Sub
    Sub setdg()
        dg.Columns(0).HeaderText = "Kode Produk"
        dg.Columns(1).HeaderText = "Produk Group"
        dg.Columns(2).HeaderText = "Nama Produk"

        dg.Columns(0).Width = 220
        dg.Columns(1).Width = 200
        dg.Columns(2).Width = 250

    End Sub

    Sub tidakaktif()
        txtprodukid.Enabled = False
        txtproduknama.Enabled = False
        cmbprodukgrup.Enabled = False

        txtprodukid.BackColor = Color.Gray
        txtproduknama.BackColor = Color.Gray
        cmbprodukgrup.BackColor = Color.Gray
        cmdsave.Enabled = False
        cmddelete.Enabled = False
        cmdupdate.Enabled = False
    End Sub

    Sub aktif()
        txtprodukid.Enabled = True
        txtproduknama.Enabled = True
        cmbprodukgrup.Enabled = True

        txtprodukid.BackColor = Color.White
        txtproduknama.BackColor = Color.White
        cmbprodukgrup.BackColor = Color.White
        cmdsave.Enabled = True
        cmddelete.Enabled = True
        cmdupdate.Enabled = True
    End Sub
    Sub bersih()
        txtprodukid.Text = ""
        txtproduknama.Text = ""
        cmbprodukgrup.Text = ""
    End Sub

    Sub cekkode()
        kon.Open()
        perintah.Connection = kon
        perintah.CommandType = CommandType.Text
        perintah.CommandText = "SELECT * from produk where produkid='" & txtprodukid.Text & "'"
        cek = perintah.ExecuteReader
        cek.Read()
        If cek.HasRows Then
            txtprodukid.Enabled = False
            cmbprodukgrup.Text = cek.Item("produkgrup")
            txtproduknama.Text = cek.Item("produknama")
        End If
        cek.Close()
        Call aktif()
        txtprodukid.Focus()
        kon.Close()
    End Sub
    Sub getgrup()
        kon.Open()
        perintah.Connection = kon
        perintah.CommandType = CommandType.Text
        perintah.CommandText = "SELECT * FROM grup ORDER BY grupid"
        cek = perintah.ExecuteReader
        While cek.Read
            cmbprodukgrup.Items.Add(cek.Item("grupid") & " - " & cek.Item("grupnama"))
        End While
        kon.Close()

    End Sub
Step 2 :
klik 2 kali di form maka akan menghasilkan form load dan copikan coding berikut
Call tampil("SELECT produkid,grupid,produknama FROM produk JOIN grup ON produk.produkgrup=grup.grupid")
        Call setdg()
Step 3 :
Lanjutan dari form load tadi maka ganti event di sebelah kanan dan ganti event nya menjadi form activated dan copikan coding berikut :
cmbprodukgrup.Items.Clear()
        Call getgrup()
        Call tidakaktif()
Step 4 :
Klik 2 kali di tombol save dan copikan koding berikut :
Try
            Call proses("INSERT INTO produk VALUES('" & txtprodukid.Text & "','" & cmbprodukgrup.Text.Substring(0, 5) & "','" & txtproduknama.Text & "')")
            Call tampil("SELECT produkid,grupid,produknama FROM produk JOIN grup ON produk.produkgrup=grup.grupid")
            Call bersih()
            Call setdg()
        Catch ex As Exception
            MsgBox("Data Tidak Bisa Disimpan", MsgBoxStyle.Information, "Informasi")
        End Try
Step 5 :
klik 2 kali di tombol delete dan kopikan coding berikut :
Try
            Call proses("DELETE FROM produk where produkid='" & txtprodukid.Text & "'")
            Call tampil("SELECT produkid,grupid,produknama FROM produk JOIN grup ON produk.produkgrup=grup.grupid")
            Call bersih()
            Call setdg()
        Catch ex As Exception
            MsgBox("Data Tidak Bisa Dihapus", MsgBoxStyle.Information, "Informasi")
        End Try
Step 6 :
Klik 2 kali di tombol update dan copikan coding berikut : 
Try
            Call proses("update produk set produkgrup='" & cmbprodukgrup.Text.Substring(0, 5) & "',produknama='" & txtproduknama.Text & "' where produkid='" & txtprodukid.Text & "'")
            Call tampil("SELECT produkid,grupid,produknama FROM produk JOIN grup ON produk.produkgrup=grup.grupid")
            Call bersih()
            Call setdg()
        Catch ex As Exception
            MsgBox("Data Tidak Bisa Diupdate", MsgBoxStyle.Information, "Informasi")
        End Try
Step 7 :
Klik 2 kali di datagrid view dan ganti eventnya di sebelah kanan atas menjadi datagridview cellclick dan copikan coding berikut :
Dim i As Integer
        i = dg.CurrentRow.Index
        txtprodukid.Text = dg.Rows.Item(i).Cells(0).Value
        Call cekkode()
Step 8 :
copikan coding berikut pada tombol add untuk mengaktifkan form yang sedang tidak aktif..
Call aktif()
Sekian dan terima kasih >>> HappyCoding

Form Master Grup Part 4

Ini adalah tutorial lanjutan dari perancangan sistem informasi minimarket yang saya buat untuk lebih lanjut mari kita liat designya :
Untuk melihat Tutorial Sebelumnya bisa dilihat Disini


Step 1 : 
copi kan coding berikut dibawah public class
Sub tampil(ByVal sql As String)
        kon.Open()
        perintah.Connection = kon
        perintah.CommandType = CommandType.Text
        perintah.CommandText = sql
        mda.SelectCommand = perintah
        ds.Tables.Clear()
        mda.Fill(ds, "data")
        dg.DataSource = ds.Tables("data")
        kon.Close()
    End Sub

    Sub proses(ByVal sql As String)
        kon.Open()
        perintah.Connection = kon
        perintah.CommandType = CommandType.Text
        perintah.CommandText = sql
        perintah.ExecuteNonQuery()
        kon.Close()
    End Sub
    Sub setdg()
        dg.Columns(0).HeaderText = "Kode Group"
        dg.Columns(1).HeaderText = "Nama Group"
        
        dg.Columns(0).Width = 220
        dg.Columns(1).Width = 440
        
    End Sub

    Sub tidakaktif()
        txtgrupid.Enabled = False
        txtgrupnama.Enabled = False

        txtgrupid.BackColor = Color.Gray
        txtgrupnama.BackColor = Color.Gray
        cmdsave.Enabled = False
        cmddelete.Enabled = False
        cmdupdate.Enabled = False
    End Sub

    Sub aktif()
        txtgrupid.Enabled = True
        txtgrupnama.Enabled = True

        txtgrupid.BackColor = Color.White
        txtgrupnama.BackColor = Color.White
        cmdsave.Enabled = True
        cmddelete.Enabled = True
        cmdupdate.Enabled = True
    End Sub
    Sub bersih()
        txtgrupid.Text = ""
        txtgrupnama.Text = ""
    End Sub

    Sub cekkode()
        kon.Open()
        perintah.Connection = kon
        perintah.CommandType = CommandType.Text
        perintah.CommandText = "SELECT * FROM grup where grupid='" & txtgrupid.Text & "'"
        cek = perintah.ExecuteReader
        cek.Read()
        If cek.HasRows Then
            txtgrupid.Enabled = False
            txtgrupnama.Text = cek.Item("grupnama")
        End If
        cek.Close()
        Call aktif()
        txtgrupid.Focus()
        kon.Close()
    End Sub
Step 2 :
klik 2 kali di form maka akan menghasilkan form load dan copikan coding berikut :
Call tampil("SELECT * FROM grup ORDER BY grupid ASC")
        Call setdg()
Step 3 :
Klik 2 kali di tombol save dan copikan coding berikut :
Try
            Call proses("INSERT INTO grup VALUES('" & txtgrupid.Text & "','" & txtgrupnama.Text & "')")
            Call tampil("SELECT * FROM grup ORDER BY grupid ASC")
            Call bersih()
            Call setdg()
        Catch ex As Exception
            MsgBox("Data Tidak Bisa Disimpan", MsgBoxStyle.Information, "Informasi")
        End Try
Step 4 :
Klik 2 kali di tombol delete dan copikan koding berikut :
Try
            Call proses("DELETE FROM grup where grupid='" & txtgrupid.Text & "'")
            Call tampil("SELECT * FROM grup ORDER BY grupid ASC")
            Call bersih()
            Call setdg()
        Catch ex As Exception
            MsgBox("Data Tidak Bisa Dihapus", MsgBoxStyle.Information, "Informasi")
        End Try
Step 5:
klik 2 kali di tombol update dan copikan coding berikut :
Try
            Call proses("update grup set grupnama='" & txtgrupnama.Text & "' where grupid='" & txtgrupid.Text & "'")
            Call tampil("SELECT * FROM grup ORDER BY grupid ASC")
            Call bersih()
            Call setdg()
        Catch ex As Exception
            MsgBox("Data Tidak Bisa Diupdate", MsgBoxStyle.Information, "Informasi")
        End Try
Step 6 :
klik 2 kali di datagridview dan pilih event yang disebelah kanan atas dan ganti menjadi datagridview cellclik dan copikan coding berikut :
Dim i As Integer
        i = dg.CurrentRow.Index
        txtgrupid.Text = dg.Rows.Item(i).Cells(0).Value
        Call cekkode()
koding diatas ini berfungsi untuk cek data dan melakukan proses update dan delete..
Sekian dan Terima Kasih..

Kategori

Kategori