Beruflich Dokumente
Kultur Dokumente
1
Lain lain :
KODING
Imports System.Data.Odbc
Public Class frmbarang
Sub tampil()
Call koneksi()
da = New OdbcDataAdapter("select*from Barang order by Kodebrg", conn)
ds = New DataSet
ds.Clear()
da.Fill(ds, 0)
dgv.DataSource = ds.Tables(0)
conn.Close()
End Sub
Sub batal()
txtkode.Text = ""
txtnama.Text = ""
cbsatuan.Text = ""
txtstok.Text = ""
cmdubah.Enabled = False
cmdhapus.Enabled = False
cmdsimpan.Enabled = True
txtnama.Enabled = False
cbsatuan.Enabled = False
txtstok.Enabled = False
txtcari.Text = ""
txtkode.Focus()
End Sub
Sub kolom()
dgv.Columns(0).Width = 110
dgv.Columns(1).Width = 200
dgv.Columns(2).Width = 100
dgv.Columns(3).Width = 80
End Sub
Sub nama()
dgv.Columns(0).HeaderText = "Kode Barang"
dgv.Columns(1).HeaderText = "Nama Barang"
dgv.Columns(2).HeaderText = "Satuan"
dgv.Columns(3).HeaderText = "Stok"
End Sub
2
Sub item()
txttotal.ReadOnly = True
txttotal.Text = 0
End Sub
Sub ketemu()
Dim i As Integer
i = Me.dgv.CurrentRow.Index
With dgv.Rows.Item(i)
txtkode.Text = .Cells(0).Value
txtnama.Text = .Cells(1).Value
cbsatuan.Text = .Cells(2).Value
txtstok.Text = .Cells(3).Value
End With
End Sub
Sub totalitem()
Dim item As Integer = 0
item = dgv.RowCount - 1
txttotal.Text = item
End Sub
3
Private Sub txtkode_KeyDown(sender As Object, e As KeyEventArgs) Handles txtkode.KeyDown
If e.KeyCode = Keys.Enter Then
Call koneksi()
str = "select*from Barang where Kodebrg='" & txtkode.Text & "'"
cmd = New OdbcCommand(str, conn)
dr = cmd.ExecuteReader
dr.Read()
If dr.HasRows Then
Call ketemu()
If MsgBox("Barang dengan kode " & txtkode.Text & " sudah ada, apakah anda ingin
menghapus/mengubah data?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "Perhatian") = MsgBoxResult.Yes
Then
cmdsimpan.Enabled = False
cmdubah.Enabled = True
cmdhapus.Enabled = True
txtnama.Enabled = True
cbsatuan.Enabled = True
txtstok.Enabled = True
labelcari.Visible = False
txtkode.Focus()
Else
Call batal()
End If
Else
txtnama.Enabled = True
cbsatuan.Enabled = True
txtstok.Enabled = True
txtnama.Focus()
labelcari.Visible = False
End If
conn.Close()
End If
End Sub
4
Private Sub cmdsimpan_Click(sender As Object, e As EventArgs) Handles cmdsimpan.Click
Call koneksi()
If txtkode.Text = "" Or txtnama.Text = "" Or cbsatuan.Text = "" Or txtstok.Text = "" Then
MsgBox("Harap lengkapi data terlebih dahulu!", MsgBoxStyle.Exclamation, "Perhatian")
txtkode.Focus()
Else
str = "insert into barang values " & "('" & txtkode.Text & "','" & txtnama.Text & "','"
& cbsatuan.Text & "','" & txtstok.Text & "')"
cmd = New OdbcCommand(str, conn)
cmd.ExecuteNonQuery()
MsgBox("Data berhasil disimpan!", MsgBoxStyle.Information, "Input Barang")
Call tampil()
Call batal()
Call totalitem()
End If
conn.Close()
End Sub
5
Private Sub txtcari_TextChanged(sender As Object, e As EventArgs) Handles txtcari.TextChanged
Call koneksi()
str = "select*from barang where namabrg like '%" & txtcari.Text & "%'"
cmd = New OdbcCommand(str, conn)
dr = cmd.ExecuteReader
dr.Read()
If dr.HasRows Then
da = New OdbcDataAdapter(str, conn)
ds = New DataSet
da.Fill(ds, "barang")
dgv.DataSource = ds.Tables("barang")
dgv.ReadOnly = True
End If
conn.Close()
End Sub