Imports System.Data.Odbc Public Class Form1 Public Con As OdbcConnection Public Str As String Public cmd As OdbcCommand Public dr As OdbcDataReader Public da As OdbcDataAdapter Public ds As DataSet Public DGV As DataGridView Sub koneksi() Str = "dsn=futsal; server=localhost; uid = root;" Con = New OdbcConnection(Str) Con.Open() 'MsgBox("Koneksi Berhasil") End Sub Sub kosong() nokon.Text = "" kodetim.Text = "" namatim.Text = "" jammulai.Text = "" jammasuk.Text = "" lama.Text = "" besarsewa.Text = "" KodeAuto() End Sub Sub tampil() da = New OdbcDataAdapter("select * from biaya", Con) ds = New DataSet da.Fill(ds, "biaya") DataGridView1.DataSource = ds.Tables("biaya") End Sub Sub KodeAuto() cmd = New OdbcCommand("select * from biaya order by nokon desc", Con) dr = cmd.ExecuteReader dr.Read() If Not dr.HasRows Then nokon.Text = "NK001" Else nokon.Text = Val(Microsoft.VisualBasic.Mid(dr.Item("nokon").ToString , 4, 3)) + 1 If Len(nokon.Text) = 1 Then nokon.Text = "NK00" & nokon.Text & "" ElseIf Len(nokon.Text) = 2 Then nokon.Text = "NK0" ElseIf Len(nokon.Text) = 1 Then nokon.Text = "K" & nokon.Text & "" End If End If End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.Even tArgs) Handles MyBase.Load koneksi() tampil() kosong() KodeAuto()
End Sub Private Sub lama_TextChanged(ByVal sender As System.Object, ByVal e As Syste m.EventArgs) Handles lama.TextChanged End Sub Private Sub besarsewa_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles besarsewa.TextChanged End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.E ventArgs) Handles Button1.Click lama.Text = Val(jammasuk.Text) - Val(jammulai.Text) If lama.Text >= 3 Then besarsewa.Text = 70000 ElseIf lama.Text >= 2 Then besarsewa.Text = 50000 Else besarsewa.Text = 32000 End If End Sub Private Sub SIMPANToolStripMenuItem_Click(ByVal sender As System.Object, ByV al e As System.EventArgs) Handles SIMPANToolStripMenuItem.Click Str = "insert into biaya values (' " & nokon.Text & " ', ' " & kodetim.T ext & " ', ' " & namatim.Text & " ', ' " & jammulai.Text & " ',' " & jammasuk.Te xt & " ',' " & lama.Text & " ',' " & besarsewa.Text & " ')" cmd = New OdbcCommand(Str, Con) cmd.ExecuteNonQuery() MsgBox("Data Disimpan") kosong() tampil() KodeAuto() End Sub Private Sub KELUARToolStripMenuItem_Click(ByVal sender As System.Object, ByV al e As System.EventArgs) Handles KELUARToolStripMenuItem.Click Me.Dispose() End Sub Private Sub BATALToolStripMenuItem_Click(ByVal sender As System.Object, ByVa l e As System.EventArgs) Handles BATALToolStripMenuItem.Click kosong() End Sub Private Sub HAPUSToolStripMenuItem_Click(ByVal sender As System.Object, ByVa l e As System.EventArgs) Handles HAPUSToolStripMenuItem.Click Str = "delete from biaya where nokon='" & nokon.Text & "'" cmd = New OdbcCommand(Str, Con) cmd.ExecuteNonQuery() MsgBox("Anda Yakin Ingin Menghapus Data ?", MsgBoxStyle.YesNo, "Keluar") kosong() KodeAuto() tampil() End Sub
Private Sub KOREKSIToolStripMenuItem_Click(ByVal sender As System.Object, By Val e As System.EventArgs) Handles KOREKSIToolStripMenuItem.Click Str = "Update biaya set nokon='" & nokon.Text & _ "',kd_tim='" & kodetim.Text & _ "',nm_tim='" & namatim.Text & _ "', jm_mulai='" & jammulai.Text & _ "',jm_selesai='" & jammasuk.Text & _ "',lm_pemakaian='" & lama.Text & _ "',besar_sewa='" & besarsewa.Text & "' where nokon='" & nokon.Text & "'" cmd = New OdbcCommand(Str, Con) cmd.ExecuteNonQuery() MsgBox("Data Berhasil Diedit") kosong() tampil() KodeAuto() End Sub Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As Syste m.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick Dim i As Integer = Nothing i = DataGridView1.CurrentRow.Index With DataGridView1 On Error Resume Next nokon.Text = .Item(0, i).Value kodetim.Text = .Item(1, i).Value namatim.Text = .Item(2, i).Value jammulai.Text = .Item(3, i).Value jammasuk.Text = .Item(4, i).Value lama.Text = .Item(5, i).Value besarsewa.Text = .Item(6, i).Value End With End Sub Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, By Val e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.C ellContentClick Dim i As Integer = Nothing i = DataGridView1.CurrentRow.Index With DataGridView1 On Error Resume Next nokon.Text = .Item(0, i).Value kodetim.Text = .Item(1, i).Value namatim.Text = .Item(2, i).Value jammulai.Text = .Item(3, i).Value jammasuk.Text = .Item(4, i).Value lama.Text = .Item(5, i).Value besarsewa.Text = .Item(6, i).Value End With End Sub End Class