Design Jasa :
Codding Jasa:
Imports System.Data.Odbc
Public Class Jasa
Sub Kosongkan()
TKode.Text = ""
TNama.Text = ""
THarga.Text = ""
TKode.Focus()
End Sub
Sub DataBaru()
TNama.Text = ""
THarga.Text = ""
TKode.Focus()
End Sub
Sub Tampilkan()
da = New OdbcDataAdapter("Select * from jasa", Conn)
ds = New DataSet
ds.Clear()
da.Fill(ds, "Jasa")
DGV.DataSource = (ds.Tables("Jasa"))
DGV.ReadOnly = True
End Sub
Private Sub Jasa_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call Koneksi()
Call Tampilkan()
End Sub
Private Sub TKode_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TKode.KeyPress
If e.KeyChar = Chr(13) Then
cmd = New OdbcCommand("select * from jasa where Kode_Jasa='" & TKode.Text & "'", Conn)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows = True Then
TNama.Text = rd.GetString(1)
THarga.Text = rd.GetValue(2)
TNama.Focus()
Else
Call DataBaru()
TNama.Focus()
End If
End If
If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then e.Handled() = True
End Sub
Private Sub btnSimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSimpan.Click
If TKode.Text = "" Or TNama.Text = "" Or THarga.Text = "" Or TKode.Text = "" Then
MsgBox("Data Belum Lengkap")
Exit Sub
Else
cmd = New OdbcCommand("Select * from jasa where Kode_Jasa='" & TKode.Text & "'", Conn)
rd = cmd.ExecuteReader
rd.Read()
If Not rd.HasRows Then
Dim sqltambah As String = "Insert into jasa(Kode_Jasa,Nama_Jasa,Harga) values " & _
"('" & TKode.Text & "','" & TNama.Text & "','" & THarga.Text & "')"
cmd = New OdbcCommand(sqltambah, Conn)
cmd.ExecuteNonQuery()
Call Kosongkan()
Call Tampilkan()
Else
Dim sqledit As String = "UPDATE jasa SET " & _
"Nama_jasa='" & TNama.Text & "', " & _
"Harga='" & THarga.Text & "'" & _
"where Kode_jasa='" & TKode.Text & "'"
cmd = New OdbcCommand(sqledit, Conn)
cmd.ExecuteNonQuery()
Call Kosongkan()
Call Tampilkan()
End If
End If
End Sub
Private Sub btnTutup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTutup.Click
Me.Close()
End Sub
Private Sub btnHapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHapus.Click
If TKode.Text = "" Then
MsgBox("Isi kode Jasa terlebih dahulu")
TKode.Focus()
Exit Sub
Else
If MessageBox.Show("Yakin akan dihapus..?", "Konfirmasi", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
cmd = New OdbcCommand("Delete from jasa where Kode_Jasa='" & TKode.Text & "'", Conn)
cmd.ExecuteNonQuery()
Call Kosongkan()
Call Tampilkan()
Else
Call Kosongkan()
End If
End If
End Sub
Private Sub TKode_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles TKode.Validated
cmd = New OdbcCommand("select * from jasa where Kode_Jasa='" & TKode.Text & "'", Conn)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows = True Then
TNama.Text = rd.GetString(1)
THarga.Text = rd.GetValue(2)
TNama.Focus()
Else
Call DataBaru()
TNama.Focus()
End If
End Sub
Private Sub TNama_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TNama.KeyPress
If e.KeyChar = Chr(13) Then THarga.Focus()
End Sub
Private Sub THarga_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles THarga.KeyPress
If e.KeyChar = Chr(13) Then btnSimpan.Focus()
End Sub
Private Sub THarga_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles THarga.TextChanged
With Me.THarga ' mengatur format angka pada saat diinput
If (.Text >= "0" And .Text <= "9") Then .Text = FormatNumber(.Text, 0)
.SelectionStart = .Text.Length
End With
End Sub
Private Sub btnBatal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBatal.Click
Call Kosongkan()
End Sub
End Class
0 Post a Comment:
Post a Comment