Anda di halaman 1dari 10

Nama : Arya Pramana

Kelas : KMA-R31/19
NPM : 19306045
UAS Praktikum Pemrograman Visual
Nama program : konter pulsa

1. Buatlah Codingan data seperti di bawah ini lalu imports data SQL Server Ke VbNet.

Imports System.Data.Odbc

Public Class PULSA


Dim Conn As OdbcConnection
Dim Cmd As OdbcCommand
Dim Ds As DataSet
Dim Da As OdbcDataAdapter
Dim Rd As OdbcDataReader
Dim MyDB As String
Dim biaya As Integer

'Connect Database'
Sub Koneksi()
MyDB = "Driver={MySQL ODBC 8.0 ANSI Driver};Database=pulsa;server=localhost;uid=root"
Conn = New OdbcConnection(MyDB)
If Conn.State = ConnectionState.Closed Then
Conn.Open()
End If
End Sub

'---------'
'Show Data'
'---------'
Sub dataprovider1()
Call Koneksi()
Da = New OdbcDataAdapter("SELECT * FROM provider ORDER BY nm_pr ASC", Conn)
Ds = New DataSet
Da.Fill(Ds, "provider")
dgprovider1.DataSource = Ds.Tables("provider")
With dgprovider1
.RowHeadersVisible = False
.Columns(0).Visible = False
.Columns(1).HeaderCell.Value = "Nama"
End With
End Sub

Sub dataprovider2()
Call Koneksi()
Da = New OdbcDataAdapter("SELECT * FROM provider ORDER BY nm_pr ASC", Conn)
Ds = New DataSet
Da.Fill(Ds, "provider")
dgprovider2.DataSource = Ds.Tables("provider")
With dgprovider2
.RowHeadersVisible = False
.Columns(0).Visible = False
.Columns(1).HeaderCell.Value = "Nama"
End With
End Sub

Sub datapulsa()
Call Koneksi()
Da = New OdbcDataAdapter("SELECT pulsa.id_pulsa, provider.nm_pr, pulsa.pembeli,
pulsa.notlp, pulsa.pulsa, pulsa.biaya FROM pulsa JOIN provider ON pulsa.kd_pr = provider.kd_pr
ORDER BY pulsa.pembeli ASC", Conn)
Ds = New DataSet
Da.Fill(Ds, "pulsa")
dgbeli.DataSource = Ds.Tables("pulsa")
With dgbeli
.RowHeadersVisible = False
.Columns(0).Visible = False
.Columns(1).HeaderCell.Value = "Provider"
.Columns(2).HeaderCell.Value = "Pembeli"
.Columns(3).HeaderCell.Value = "No. Tlp"
.Columns(4).HeaderCell.Value = "Pulsa"
.Columns(5).HeaderCell.Value = "Biaya"
.Columns(5).DefaultCellStyle.Format = "Rp #,#"
End With
End Sub

'-------------------------'
'Item DataGridView To Form'
'-------------------------'
Private Sub dgprovider1_CellClick(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs)
Handles dgprovider1.CellClick
Dim i As Integer
i = dgprovider1.SelectedCells(0).RowIndex
'DataGridView to TextBox'
txtkdpr1.Text = dgprovider1.Rows(i).Cells(0).Value.ToString()
txtnmpr.Text = dgprovider1.Rows(i).Cells(1).Value.ToString()
End Sub

Private Sub dgprovider2_CellClick(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs)


Handles dgprovider2.CellClick
Dim i As Integer
i = dgprovider2.SelectedCells(0).RowIndex
'DataGridView to TextBox'
txtkdpr2.Text = dgprovider2.Rows(i).Cells(0).Value.ToString()
End Sub
Private Sub dgbeli_CellClick(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs)
Handles dgbeli.CellClick
Dim i As Integer
i = dgbeli.SelectedCells(0).RowIndex
'DataGridView to TextBox'
txtkdpl.Text = dgbeli.Rows(i).Cells(0).Value.ToString()
End Sub

'--------------'
'Empty All Form'
'--------------'
Sub KosongTab1()
txtkdpr1.Text = ""
txtnmpr.Text = ""
End Sub

Sub KosongTab2()
txtkdpl.Text = ""
txtkdpr2.Text = ""
txtpembeli.Text = ""
txttlp.Text = ""
cbpulsa.SelectedIndex = -1
txtbiaya.Text = ""
End Sub

'------------'
'Button Input'
'------------'

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


btinp1.Click
If txtnmpr.Text = "" Then
MsgBox("Isi Semua Form.")
Else
Call Koneksi()
Dim simpan As String = "INSERT INTO provider(nm_pr) VALUES('" & txtnmpr.Text & "')"
Cmd = New OdbcCommand(simpan, Conn)
Cmd.ExecuteNonQuery()
MsgBox("Input Success")
Call datapulsa()
Call dataprovider1()
Call dataprovider2()
Call KosongTab1()
Call KosongTab2()
End If
End Sub

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


btinp2.Click
If txtkdpr2.Text = "" Or txtpembeli.Text = "" Or txttlp.Text = "" Or cbpulsa.SelectedIndex = -1
Then
MsgBox("Isi Semua Form.")
Else
Call Koneksi()
If cbpulsa.SelectedIndex = 0 Then
biaya = 10000
ElseIf cbpulsa.SelectedIndex = 1 Then
biaya = 15000
ElseIf cbpulsa.SelectedIndex = 2 Then
biaya = 20000
ElseIf cbpulsa.SelectedIndex = 3 Then
biaya = 25000
ElseIf cbpulsa.SelectedIndex = 4 Then
biaya = 30000
ElseIf cbpulsa.SelectedIndex = 5 Then
biaya = 35000
ElseIf cbpulsa.SelectedIndex = 6 Then
biaya = 40000
ElseIf cbpulsa.SelectedIndex = 7 Then
biaya = 45000
ElseIf cbpulsa.SelectedIndex = 8 Then
biaya = 50000
ElseIf cbpulsa.SelectedIndex = 9 Then
biaya = 55000
End If
Dim simpan As String = "INSERT INTO pulsa(kd_pr,pembeli,notlp,pulsa,biaya) VALUES('" &
txtkdpr2.Text & "','" &
txtpembeli.Text & "','" &
txttlp.Text & "','" &
cbpulsa.Text & "','" &
biaya & "')"
Cmd = New OdbcCommand(simpan, Conn)
Cmd.ExecuteNonQuery()
MsgBox("Input Success")
Call datapulsa()
Call dataprovider1()
Call dataprovider2()
Call KosongTab1()
Call KosongTab2()
End If
End Sub

'------------'
'Button Edit'
'------------'
Private Sub btedt1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
btedt1.Click
If txtkdpr1.Text = "" Or txtnmpr.Text = "" Then
MsgBox("Isi Semua Form")
Else
Call Koneksi()
Dim EditData As String = "UPDATE provider SET nm_pr='" &
txtnmpr.Text & "' WHERE kd_pr='" & txtkdpr1.Text & "'"
Cmd = New OdbcCommand(EditData, Conn)
Cmd.ExecuteNonQuery()
MsgBox("Update Success")
Call datapulsa()
Call dataprovider1()
Call dataprovider2()
Call KosongTab1()
Call KosongTab2()
End If
End Sub

'------------'
'Button Delete'
'------------'
Private Sub btdel1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
btdel1.Click
If txtkdpr1.Text = "" Then
MsgBox("Pilih Kode Terlebih Dahulu.")
Else
If MessageBox.Show("Yakin dihapus?", "", MessageBoxButtons.YesNo) =
Windows.Forms.DialogResult.Yes Then
Call Koneksi()
Dim hapus As String = "DELETE FROM provider WHERE kd_pr='" & txtkdpr1.Text & "'"
Cmd = New OdbcCommand(hapus, Conn)
Cmd.ExecuteNonQuery()
Call datapulsa()
Call dataprovider1()
Call dataprovider2()
Call KosongTab1()
Call KosongTab2()
End If
End If
End Sub

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


btdel2.Click
If txtkdpl.Text = "" Then
MsgBox("Pilih Kode Terlebih Dahulu.")
Else
If MessageBox.Show("Yakin dihapus?", "", MessageBoxButtons.YesNo) =
Windows.Forms.DialogResult.Yes Then
Call Koneksi()
Dim hapus As String = "DELETE FROM pulsa WHERE id_pulsa='" & txtkdpl.Text & "'"
Cmd = New OdbcCommand(hapus, Conn)
Cmd.ExecuteNonQuery()
End If
Call datapulsa()
Call dataprovider1()
Call dataprovider2()
Call KosongTab1()
Call KosongTab2()
End If
End Sub

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


MyBase.Load
Call datapulsa()
Call dataprovider1()
Call dataprovider2()
End Sub
Private Sub cbpulsa_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cbpulsa.SelectedIndexChanged
If cbpulsa.SelectedIndex = 0 Then
biaya = 10000
ElseIf cbpulsa.SelectedIndex = 1 Then
biaya = 15000
ElseIf cbpulsa.SelectedIndex = 2 Then
biaya = 20000
ElseIf cbpulsa.SelectedIndex = 3 Then
biaya = 25000
ElseIf cbpulsa.SelectedIndex = 4 Then
biaya = 30000
ElseIf cbpulsa.SelectedIndex = 5 Then
biaya = 35000
ElseIf cbpulsa.SelectedIndex = 6 Then
biaya = 40000
ElseIf cbpulsa.SelectedIndex = 7 Then
biaya = 45000
ElseIf cbpulsa.SelectedIndex = 8 Then
biaya = 50000
ElseIf cbpulsa.SelectedIndex = 9 Then
biaya = 55000
End If
txtbiaya.Text = Format(Val(biaya.ToString), "Rp #,#")
End Sub

End Class
2. inilah hasil yang sudah di running
Tampilan
 Form Pulsa

 Form Transaksi

Anda mungkin juga menyukai