You are on page 1of 5

CODDING PERTEMUAN 10

1. CODING
Imports MySql.Data.MySqlClient
Public Class Form1
Dim KONEKSI = New MySqlConnection
Dim PERINTAH As MySqlCommand
Dim dbDATASet As New DataTable

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles MyBase.Load
Call Refresh()
KONEKSI = New MySqlConnection
KONEKSI.ConnectionString =
"server=localhost;userid=root;password=;database=partikum5"
Dim BACA As MySqlDataReader
Try
KONEKSI.Open()
Dim query As String
query = "select * from partikum5.jual"
PERINTAH = New MySqlCommand(query, KONEKSI)
BACA = PERINTAH.ExecuteReader
While BACA.Read
Dim sNOFAK = BACA.GetString("nofaktur")
cboNOFAKTUR.Items.Add(sNOFAK)
End While
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
KONEKSI.Dispose()
End Try
End Sub
Private Sub cboNOFAKTUR_SelectedIndexChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles cboNOFAKTUR.SelectedIndexChanged
KONEKSI = New MySqlConnection
KONEKSI.ConnectionString =
"server=localhost;userid=root;password=;database=partikum5"
Dim BACA As MySqlDataReader
Try
KONEKSI.Open()
Dim query As String
query = "select * from jual where nofaktur='" & cboNOFAKTUR.Text & "' "
PERINTAH = New MySqlCommand(query, KONEKSI)
BACA = PERINTAH.ExecuteReader
While BACA.Read
txtNOFAK.Text = BACA.GetString("nofaktur")
txtNAPEL.Text = BACA.GetString("nm_pelanggan")
txtNABAR.Text = BACA.GetString("nm_barang")
txtHARGA.Text = BACA.GetInt32("harga")
txtQTY.Text = BACA.GetInt32("qty")
lblJLHARGA.Text = BACA.GetInt32("tot_harga")
txtDISKON.Text = BACA.GetInt32("diskon")
lblTOTBAYAR.Text = Format(BACA.GetInt32("tot_bayar"), "Rp ###,###,##")
End While
KONEKSI.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
KONEKSI.Dispose()
End Try
End Sub
Private Sub btnUPDATE_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUPDATE.Click
KONEKSI = New MySqlConnection
KONEKSI.ConnectionString =
"server=localhost;userid=root;password=;database=partikum5"
Dim BACA As MySqlDataReader
Try
KONEKSI.Open()
Dim QUERY As String
QUERY = "update jual set nm_pelanggan='" & txtNAPEL.Text & "',nm_barang='"
& txtNABAR.Text & "',harga='" & txtHARGA.Text & "',qty='" & txtQTY.Text &
"',tot_harga='" & lblJLHARGA.Text & "',diskon='" & txtDISKON.Text & "',tot_bayar='" &
lblTOTBAYAR.Text & "' where nofaktur='" & txtNOFAK.Text & "'"

PERINTAH = New MySqlCommand(QUERY, KONEKSI)


BACA = PERINTAH.ExecuteReader
MessageBox.Show("Data Telah Di Update")
KONEKSI.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
KONEKSI.Dispose()
End Try
Call Refresh()
End Sub

Private Sub txtQTY_TextChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles txtQTY.TextChanged
lblJLHARGA.Text = Val(txtHARGA.Text) * Val(txtQTY.Text)
lblTOTBAYAR.Text = "0"
End Sub

Private Sub txtDISKON_TextChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles txtDISKON.TextChanged
lblTOTBAYAR.Text = Format((Val(txtHARGA.Text) * Val(txtQTY.Text)) -
((Val(txtHARGA.Text) * Val(txtQTY.Text)) * (Val(txtDISKON.Text) / 100)), "Rp
###,###,##")
End Sub
Private Sub btnREFRESH_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnREFRESH.Click
KONEKSI = New MySqlConnection
KONEKSI.ConnectionString =
"server=localhost;userid=root;password=;database=partikum5"
Dim SDA As New MySqlDataAdapter

Dim bSource As New BindingSource


Try
KONEKSI.Open()
Dim query As String
query = "select * from partikum5.jual"
PERINTAH = New MySqlCommand(query, KONEKSI)
SDA.SelectCommand = PERINTAH
SDA.Fill(dbDataSet)
bSource.DataSource = dbDataSet
dgvJUAL.DataSource = bSource
SDA.Update(dbDataSet)

KONEKSI.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
KONEKSI.Dispose()
End Try
End Sub
Private Sub segar()
KONEKSI = New MySqlConnection
KONEKSI.ConnectionString =
"server=localhost;userid=root;password=;database=partikum5"
Dim SDA As New MySqlDataAdapter

Dim bSource As New BindingSource

Try
KONEKSI.Open()

Dim query As String


query = "select * from partikum5.jual"
PERINTAH = New MySqlCommand(query, KONEKSI)
SDA.SelectCommand = PERINTAH
SDA.Fill(dbDataSet)
bSource.DataSource = dbDataSet
dgvJUAL.DataSource = bSource
SDA.Update(dbDataSet)

KONEKSI.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
KONEKSI.Dispose()
End Try
End Sub

Private Sub btnTAMBAH_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnTAMBAH.Click
KONEKSI = New MySqlConnection
KONEKSI.ConnectionString =
"server=localhost;userid=root;password=;database=partikum5"
Dim BACA As MySqlDataReader

Try
KONEKSI.Open()
Dim query As String
query = "insert into partikum5.jual (nofaktur,
nm_pelanggan,nm_barang,harga,qty,tot_harga,diskon,tot_bayar) values ('" &
txtNOFAK.Text & "','" & txtNAPEL.Text & "','" & txtNABAR.Text & "','" & txtHARGA.Text
& "','" & txtQTY.Text & "','" & lblJLHARGA.Text & "','" & txtDISKON.Text & "','" &
lblTOTBAYAR.Text & "')"

PERINTAH = New MySqlCommand(query, KONEKSI)


BACA = PERINTAH.ExecuteReader

MessageBox.Show("Data Telah Disimpan")


KONEKSI.Close()

Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
KONEKSI.Dispose()
End Try
Call Refresh()
End Sub
Private Sub btnHAPUS_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnHAPUS.Click
KONEKSI = New MySqlConnection
KONEKSI.ConnectionString =
"server=localhost;userid=root;password=;database=partikum5"
Dim BACA As MySqlDataReader
Try
KONEKSI.Open()
Dim QUERY As String
QUERY = "delete from partikum5.jual where nofaktur='" & txtNOFAK.Text &
"'"

PERINTAH = New MySqlCommand(QUERY, KONEKSI)


BACA = PERINTAH.ExecuteReader
MessageBox.Show("Data Telah Di Delete")
KONEKSI.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
KONEKSI.Dispose()
End Try
Call Refresh()
End Sub
Private Sub dgvJUAL_CellContentClick(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvJUAL.CellContentClick
If e.RowIndex >= 0 Then
Dim row As DataGridViewRow
row = Me.dgvJUAL.Rows(e.RowIndex)

txtNOFAK.Text = row.Cells("nofaktur").Value.ToString
txtNAPEL.Text = row.Cells("nm_pelanggan").Value.ToString
txtNABAR.Text = row.Cells("nm_barang").Value.ToString
txtHARGA.Text = row.Cells("harga").Value.ToString
txtQTY.Text = row.Cells("qty").Value.ToString
lblJLHARGA.Text = row.Cells("tot_harga").Value.ToString
txtDISKON.Text = row.Cells("diskon").Value.ToString
lblTOTBAYAR.Text = row.Cells("tot_bayar").Value.ToString

End If
End Sub
Private Sub btnKELUAR_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnKELUAR.Click
Me.Close()
End Sub

Private Sub txtCARI_TextChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles txtCARI.TextChanged
Dim DV As New DataView(dbDataSet)
DV.RowFilter = String.Format("nm_pelanggan like '%{0}%'", txtCARI.Text)
dgvJUAL.DataSource = DV

End Sub

End Class

2. GAMBAR

You might also like