Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Imports MySql.Data.

MySqlClient
Public Class Form1
Dim strkon As String = "server=localhost; user id=root; database=dbservis"
Dim kon As New MySqlConnection(strkon)
Dim perintah As New MySqlCommand
Dim mda As New MySqlDataAdapter
Dim cek As MySqlDataReader
Dim ds As New DataSet

Sub bersih()
txtidservice.Text = ""
txtnamakonsumen.Text = ""
cmbjenisservice.Text = " - Pilih - "
txtbiayaservice.Text = ""
txtbiayasparepart.Text = ""
txttotalbiaya.Text = ""
End Sub
Sub tampil()
kon.Open()
perintah.Connection = kon
perintah.CommandType = CommandType.Text
perintah.CommandText = "select * from tbservice"
mda.SelectCommand = perintah
ds.Tables.Clear()
mda.Fill(ds, "Data")
DataGridView1.DataSource = ds.Tables("Data")
kon.Close()
End Sub

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


Handles MyBase.Load
Call tampil()
Call bersih()
End Sub

Private Sub cmbjenisservice_SelectedIndexChanged(ByVal sender As System.Object, ByVal


e As System.EventArgs) Handles cmbjenisservice.SelectedIndexChanged
If cmbjenisservice.Text = "PC" Then
txtbiayaservice.Text = 100000
ElseIf cmbjenisservice.Text = "Laptop" Then
txtbiayaservice.Text = 200000
Else
txtbiayaservice.Text = 150000
End If
End Sub

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


System.EventArgs) Handles txtbiayasparepart.TextChanged
txttotalbiaya.Text = Val(txtbiayaservice.Text) + Val(txtbiayasparepart.Text)
End Sub

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


System.EventArgs) Handles cmdsimpan.Click
kon.Open()
perintah.Connection = kon
perintah.CommandType = CommandType.Text
perintah.CommandText = "insert into tbtransaksi value('" & txtidservice.Text &
"'," & _
"'" & txtnamakonsumen.Text & "','" & cmbjenisservice.Text & "','" &
txtbiayaservice.Text & "'," & _
"'" & txtbiayasparepart.Text & "','" & txttotalbiaya.Text & "')"
perintah.ExecuteNonQuery()
kon.Close()

Call tampil()
Call bersih()
End Sub
Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
Dim I As String
I = DataGridView1.CurrentRow.Index
txtidservice.Text = DataGridView1.Rows.Item(I).Cells(0).Value
txtnamakonsumen.Text = DataGridView1.Rows.Item(I).Cells(1).Value
cmbjenisservice.Text = DataGridView1.Rows.Item(I).Cells(2).Value
txtbiayaservice.Text = DataGridView1.Rows.Item(I).Cells(3).Value
txtbiayasparepart.Text = DataGridView1.Rows.Item(I).Cells(4).Value
txttotalbiaya.Text = DataGridView1.Rows.Item(I).Cells(5).Value
End Sub

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


System.EventArgs) Handles cmdhapus.Click
kon.Open()
perintah.Connection = kon
perintah.CommandType = CommandType.Text
perintah.CommandText = "delete from tbtransaksi where idservice = '" &
txtidservice.Text & "'"
perintah.ExecuteNonQuery()
kon.Close()

Call tampil()
Call bersih()
End Sub

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


Handles cmdedit.Click
kon.Open()
perintah.Connection = kon
perintah.CommandType = CommandType.Text
perintah.CommandText = "update tbservice set namakonsumen = '" &
txtnamakonsumen.Text & "'," & _
"jenisservice = '" & cmbjenisservice.Text & "',biayaservice = '" &
txtbiayaservice.Text & "'," & _
"biayasparepart = '" & txtbiayasparepart.Text & "',totalbiaya = '" &
txttotalbiaya.Text & "' " & _
"where idservice = '" & txtidservice.Text & "'"
perintah.ExecuteNonQuery()
kon.Close()

Call tampil()
Call bersih()
End Sub

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


System.EventArgs) Handles cmdkeluar.Click
Me.Close()
End Sub
End Class

You might also like