Design Kasir:
Kodding Kasir :
Imports System.Data.Odbc
Public Class Kasir
Sub Kosongkan()
TKode.Text = ""
TNama.Text = ""
TPass.Text = ""
TStatus.Text = ""
TKode.Focus()
End Sub
Sub DataBaru()
TNama.Text = ""
TPass.Text = ""
TStatus.Text = ""
TKode.Focus()
End Sub
Sub Tampilkan()
da = New OdbcDataAdapter("Select * from kasir", Conn)
ds = New DataSet
ds.Clear()
da.Fill(ds, "Kasir")
DGV.DataSource = (ds.Tables("Kasir"))
DGV.ReadOnly = True
End Sub
Private Sub Kasir_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 kasir where Kode_Kasir='" & TKode.Text & "'", Conn)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows = True Then
TNama.Text = rd.GetString(1)
TPass.Text = rd.GetString(2)
TStatus.Text = rd.GetString(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 btnSimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSimpan.Click
If TKode.Text = "" Or TNama.Text = "" Or TPass.Text = "" Or TStatus.Text = "" Or TKode.Text = "" Then
MsgBox("Data Belum Lengkap")
Exit Sub
Else
cmd = New OdbcCommand("Select * from kasir where Kode_Kasir='" & TKode.Text & "'", Conn)
rd = cmd.ExecuteReader
rd.Read()
If Not rd.HasRows Then
Dim sqltambah As String = "Insert into kasir(Kode_Kasir,Nama_Kasir,Pass_Kasir,Status_Kasir) values " & _
"('" & TKode.Text & "','" & TNama.Text & "','" & TPass.Text & "','" & TStatus.Text & "')"
cmd = New OdbcCommand(sqltambah, Conn)
cmd.ExecuteNonQuery()
Call Kosongkan()
Call Tampilkan()
Else
Dim sqledit As String = "Update kasir set " & _
"Nama_Kasir='" & TNama.Text & "', " & _
"Pass_Kasir='" & TPass.Text & "', " & _
"Status_Kasir='" & TStatus.Text & "'" & _
"where Kode_Kasir='" & 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 Kasir 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 kasir where Kode_Kasi r='" & 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 kasir where Kode_Kasir='" & TKode.Text & "'", Conn)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows = True Then
TNama.Text = rd.GetString(1)
TPass.Text = rd.GetString(2)
TStatus.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 TPass.Focus()
End Sub
Private Sub TPass_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TPass.KeyPress
If e.KeyChar = Chr(13) Then TStatus.Focus()
End Sub
Private Sub TStatus_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TStatus.KeyPress
If e.KeyChar = Chr(13) Then btnSimpan.Focus()
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