Design Mekanik :
Codding Mekanik :
Imports System.Data.Odbc
Public Class Mekanik
Sub Kosongkan()
TKode.Text = ""
TNama.Text = ""
TAlamat.Text = ""
TTelp.Text = ""
TKode.Focus()
End Sub
Sub DataBaru()
TNama.Text = ""
TAlamat.Text = ""
TTelp.Text = ""
TKode.Focus()
End Sub
Sub Tampilkan()
da = New OdbcDataAdapter("Select * from mekanik", Conn)
ds = New DataSet
ds.Clear()
da.Fill(ds, "Mekanik")
DGV.DataSource = (ds.Tables("Mekanik"))
DGV.ReadOnly = True
End Sub
Private Sub Mekanik_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 mekanik where Kode_Mekanik='" & TKode.Text & "'", Conn)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows = True Then
TNama.Text = rd.GetString(1)
TAlamat.Text = rd.GetString(2)
TTelp.Text = rd.GetValue(3)
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 TKode_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles TKode.Validated
cmd = New OdbcCommand("select * from mekanik where Kode_Mekanik='" & TKode.Text & "'", Conn)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows = True Then
TNama.Text = rd.GetString(1)
TAlamat.Text = rd.GetString(2)
TTelp.Text = rd.GetString(3)
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 TAlamat.Focus()
End Sub
Private Sub TAlamat_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TAlamat.KeyPress
If e.KeyChar = Chr(13) Then TTelp.Focus()
End Sub
Private Sub TTelp_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TTelp.KeyPress
If e.KeyChar = Chr(13) Then btnSimpan.Focus()
End Sub
Private Sub btnTutup_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTutup.Click
Me.Close()
End Sub
Private Sub btnBatal_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBatal.Click
Call Kosongkan()
End Sub
Private Sub btnHapus_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHapus.Click
If TKode.Text = "" Then
MsgBox("Isi kode Mekanik 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 mekanik where Kode_Mekanik='" & TKode.Text & "'", Conn)
cmd.ExecuteNonQuery()
Call Kosongkan()
Call Tampilkan()
Else
Call Kosongkan()
End If
End If
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 TAlamat.Text = "" Or TTelp.Text = "" Or TKode.Text = "" Then
MsgBox("Data Belum Lengkap")
Exit Sub
Else
cmd = New OdbcCommand("Select * from mekanik where Kode_Mekanik='" & TKode.Text & "'", Conn)
rd = cmd.ExecuteReader
rd.Read()
If Not rd.HasRows Then
Dim sqltambah As String = "Insert into mekanik(Kode_Mekanik,Nama_Mekanik,Alamat_Mekanik,Telepon_Mekanik) values " & "('" & TKode.Text & "','" & TNama.Text & "','" & TAlamat.Text & "','" & TTelp.Text & "')"
cmd = New OdbcCommand(sqltambah, Conn)
cmd.ExecuteNonQuery()
Call Kosongkan()
Call Tampilkan()
Else
Dim sqledit As String = "Update mekanik set " & _
"Nama_Mekanik='" & TNama.Text & "', " & _
"Alamat_Mekanik='" & TAlamat.Text & "', " & _
"Telepon_Mekanik='" & TTelp.Text & "'" & _
"where Kode_Mekanik='" & TKode.Text & "'"
cmd = New OdbcCommand(sqledit, Conn)
cmd.ExecuteNonQuery()
Call Kosongkan()
Call Tampilkan()
End If
End If
End Sub
End Class
Design Pendaftaran :
0 Post a Comment:
Post a Comment