CONTOH LISTING PROGRAM RELASI PHPTriad DENGAN VISUAL BASIC.2008
Listing Program
Imports MySql.Data.MySqlClient
Public Class Form1
Public db As New MySql.Data.MySqlClient.MySqlConnection
Public SQL As String
Public CMD As New MySqlCommand
Public rs As MySqlDataReader
Sub isitabel()
liv.Items.Clear()
SQL = "select a.kd_faktor,a.kd_barang,a.kd_konsumen,a.jumlah,a.total,b.nama_barang,b.harga,c.nama from pembelian as a,barang as b, kosumen as c where a.kd_barang =b.kd_barang and a.kd_konsumen=c.kd_konsumen"
CMD = New MySqlCommand(SQL, db)
rs = CMD.ExecuteReader
Try
While rs.Read
Dim lst As New ListViewItem
lst.Text = rs("kd_faktor")
lst.SubItems.Add(rs("kd_barang"))
lst.SubItems.Add(rs("kd_konsumen"))
lst.SubItems.Add(rs("nama_barang"))
lst.SubItems.Add(rs("harga"))
lst.SubItems.Add(rs("jumlah"))
lst.SubItems.Add(rs("total"))
lst.SubItems.Add(rs("nama"))
liv.Items.Add(lst)
End While
Catch ex As Exception
MsgBox(ex.Message)
End Try
rs.Close()
End Sub
Sub SIMPANDATA()
SQL = "insert into pembelian values ('" & kode_faktor.Text & _
"','" & kd_konsumen.Text & "','" & kode_barang.Text & _
"','" & jlh.Text & "','" & t_harga.Text & "')"
Try
CMD = New MySqlCommand(SQL, db)
CMD.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message)
End Try
isitabel()
kode_faktor.Clear()
kode_barang.Text = ""
nama_barang.Text = ""
harga.Text = ""
kd_konsumen.Text = ""
jlh.Text = ""
t_harga.Text = ""
nama.Text = ""
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SQL = "server=localhost;uid=root;database=penjualan_barang"
Try
db.ConnectionString = SQL
db.Open()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Call isitabel()
kdbarang()
kodekonsumen()
buattabel()
End Sub
Sub kdbarang()
SQL = "select * from barang"
CMD = New MySqlCommand(SQL, db)
rs = CMD.ExecuteReader
Try
While rs.Read
kode_barang.Items.Add(rs!kd_barang)
End While
Catch ex As Exception
MsgBox(ex.Message)
End Try
rs.Close()
End Sub
Private Sub kode_barang_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kode_barang.SelectedIndexChanged
SQL = "select * from barang where kd_barang='" & kode_barang.Text & "' "
CMD = New MySqlCommand(SQL, db)
rs = CMD.ExecuteReader
Try
rs.Read()
nama_barang.Text = rs!nama_barang
harga.Text = rs!harga
Catch ex As Exception
MsgBox(ex.Message)
End Try
rs.Close()
End Sub
Sub kodekonsumen()
SQL = "select * from kosumen"
CMD = New MySqlCommand(SQL, db)
rs = CMD.ExecuteReader
Try
While rs.Read
kd_konsumen.Items.Add(rs!kd_konsumen)
End While
Catch ex As Exception
MsgBox(ex.Message)
End Try
rs.Close()
End Sub
Private Sub kd_konsumen_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kd_konsumen.SelectedIndexChanged
SQL = "select * from kosumen where kd_konsumen='" & kd_konsumen.Text & "'"
CMD = New MySqlCommand(SQL, db)
rs = CMD.ExecuteReader
Try
rs.Read()
nama.Text = rs!nama
Catch ex As Exception
MsgBox(ex.Message)
End Try
rs.Close()
End Sub
Sub buattabel()
liv.Columns.Add("Kode Faktor", 100, HorizontalAlignment.Left)
liv.Columns.Add("Kode Barang", 100, HorizontalAlignment.Left)
liv.Columns.Add("Kode Konsumen", 100, HorizontalAlignment.Left)
liv.Columns.Add("Nama Barang", 100, HorizontalAlignment.Left)
liv.Columns.Add("Harga", 100, HorizontalAlignment.Left)
liv.Columns.Add("jumlah Beli", 80, HorizontalAlignment.Left)
liv.Columns.Add("Total Harga", 100, HorizontalAlignment.Left)
liv.Columns.Add("Nama ", 100, HorizontalAlignment.Left)
liv.GridLines = True
liv.FullRowSelect = True
liv.View = View.Details
End Sub
Sub editdata()
SQL = "update pembelian set kd_konsumen='" & kd_konsumen.Text & "'," & _
" kd_barang='" & kode_barang.Text & "'," & _
" jumlah='" & jlh.Text & "'," & _
" total='" & t_harga.Text & "' " & _
" where kd_faktor='" & kode_faktor.Text & "'"
Try
CMD = New MySqlCommand(SQL, db)
CMD.ExecuteNonQuery()
MsgBox("Data Telah Di Perbarui")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
isitabel()
End Sub
Sub HAPUSDATA()
SQL = "delete from pembelian where kd_faktor='" & kode_faktor.Text & "'"
Try
CMD = New MySqlCommand(SQL, db)
CMD.ExecuteNonQuery()
MsgBox("Data Telah Dihapus?")
Catch ex As Exception
End Try
isitabel()
kode_faktor.Clear()
End Sub
Private Sub simpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles simpan.Click
If simpan.Text = "Simpan" Then
SIMPANDATA()
Else
editdata()
End If
End Sub
Private Sub hapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hapus.Click
HAPUSDATA()
End Sub
Private Sub keluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles keluar.Click
End
End Sub
Dim x As String = ""
Private Sub kode_faktor_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles kode_faktor.KeyPress
Dim kbr As String = ""
Dim kks As String = ""
If Asc(e.KeyChar) = 13 Then
If kode_faktor.Text = "" Then
MsgBox("Nama Kosong")
Else
SQL = "select kd_barang,kd_konsumen,jumlah,total " & _
"from pembelian " & _
"where kd_faktor='" & kode_faktor.Text & "'"
CMD = New MySqlCommand(SQL, db)
rs = CMD.ExecuteReader
Try
rs.Read()
kbr = rs("kd_barang")
kks = rs("kd_konsumen")
jlh.Text = rs("jumlah")
t_harga.Text = rs("total")
simpan.Text = "Edit"
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
rs.Close()
End If
kode_barang.Text = kbr
kd_konsumen.Text = kks
End If
End Sub
Private Sub jlh_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles jlh.KeyPress
If Asc(e.KeyChar) = 13 Then
t_harga.Text = jlh.Text * harga.Text
End If
End Sub
Sub addkode()
SQL = "select*from pembelian order by kd_faktor desc"
cmd = New MySqlCommand(sql, db)
rs = cmd.ExecuteReader
Dim X As String
X = 0
If rs.HasRows = True Then
rs.Read()
X = Microsoft.VisualBasic.Right(rs!kd_faktor, 3)
kode_faktor.Text = "FAK" & Microsoft.VisualBasic.Right("00" & Val(X) + 1, 4)
Else
kode_faktor.Text = "FAK001"
End If
rs.Close()
End Sub
Private Sub Baru_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Baru.Click
addkode()
End Sub
End Class
Tidak ada komentar:
Posting Komentar