Welcome To ViniCeca's World

Delete this widget from your Dashboard and add your own words. This is just an example!

FORM DATA SUPPLIER

Jumat, 13 Mei 2011



Coding Entry Data Supplier


Imports System.Data.OleDb
Imports System.Data
Public Class FrmMasterSupplier
Dim cnn As OleDbConnection
Dim cmmd As OleDbCommand
Dim dReader As OleDbDataReader
Private Sub FrmMasterSupplier_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Buka koneksi
cnn = New OleDbConnection(strConn)
If cnn.State <> ConnectionState.Closed Then cnn.Close()
cnn.Open()

'Buat AutoNumber u kode barang
Dim strTemp As String = ""
Dim strValue As String = ""
Dim sql As String

sql = "SELECT * FROM SUPPLIER ORDER BY KDSUP DESC"
cmmd = New OleDbCommand(sql, cnn)
dReader = cmmd.ExecuteReader
If dReader.Read Then
strTemp = Mid(dReader.Item("KDSUP"), 3, 5) + 1
Else
txtkdSup.Text = "SU00001"
Exit Sub
End If
'MsgBox(strTemp)
strValue = Val(strTemp) + 1
txtkdSup.Text = "SU" & Mid("00000", 1, 5 - strValue.Length) & strValue
End Sub

Private Sub cmdKeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdKeluar.Click
Me.Dispose()
End Sub

Private Sub txtkdSup_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtkdSup.KeyPress
If Asc(e.KeyChar) = 13 Then
cmmd = New OleDbCommand("SELECT * FROM SUPPLIER WHERE KDSUP='" & txtkdSup.Text & "'", cnn)
dReader = cmmd.ExecuteReader
If dReader.Read Then
''jika data ditemukan
cmdSimpan.Enabled = False
cmdUbah.Enabled = True
cmdHapus.Enabled = True

txtNmSup.Text = dReader.Item("NMSUP")
txtalamat.Text = dReader.Item("ALAMAT")

txtNmSup.Focus()

Else
txtNmSup.Focus()
txtNmSup.Text = ""
txtalamat.Text = ""

End If
End If
End Sub


Private Sub cmdSimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSimpan.Click
Dim sql As String
Dim strTemp As String = ""
Dim strValue As String = ""

sql = "INSERT INTO SUPPLIER (KDSUP, NMSUP, ALAMAT) " & "VALUES('" & txtkdSup.Text & "','" & txtNmSup.Text & "','" & txtalamat.Text & "')"

cmmd = New OleDbCommand(sql, cnn)

Dim x As Integer = cmmd.ExecuteNonQuery

If x = 1 Then
MessageBox.Show("DATA BERHASIL DISIMPAN")

sql = "SELECT * FROM SUPPLIER ORDER BY KDSUP DESC"
cmmd = New OleDbCommand(sql, cnn)
dReader = cmmd.ExecuteReader
If dReader.Read Then
strTemp = Mid(dReader.Item("KDSUP"), 3, 5)
'caraChris
'strChris = Mid(dReader.Item("KDSUP"), 3, 5) + 1

Else
txtkdSup.Text = "SU0000!"
Exit Sub
End If

'MsgBox(strTemp)
strValue = Val(strTemp) + 1
txtkdSup.Text = "SU" & Mid("00000", 1, 5 - strValue.Length) & strValue

txtNmSup.Text = ""
txtalamat.Text = ""
txtNmSup.Focus()
Else
MessageBox.Show("GAGAL MENYIMPAN DATA")
End If
End Sub

Private Sub cmdUbah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUbah.Click
Dim sql As String
sql = "UPDATE SUPPLIER SET NMSUP='" & txtNmSup.Text & "'," & "ALAMAT='" & txtalamat.Text & "' " & "WHERE KDSUP='" & txtkdSup.Text & "'"

cmmd = New OleDbCommand(sql, cnn)

Dim x As Integer = cmmd.ExecuteNonQuery

If x = 1 Then
MessageBox.Show("DATA BERHASIL DIUPDATE")
txtkdSup.Text = ""
txtNmSup.Text = ""
txtalamat.Text = ""
txtkdSup.Enabled = True
txtkdSup.Focus()
Else
MessageBox.Show("GAGAL UPDATE DATA")
End If
End Sub

Private Sub cmdHapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdHapus.Click
Dim sql As String
sql = "DELETE FROM SUPPLIER WHERE KDSUP='" & txtkdSup.Text & "'"

cmmd = New OleDbCommand(sql, cnn)

Dim x As Integer = cmmd.ExecuteNonQuery

If x = 1 Then
MessageBox.Show("DATA BERHASIL DIHAPUS")
txtkdSup.Text = ""
txtNmSup.Text = ""
txtalamat.Text = ""
txtkdSup.Enabled = True
txtkdSup.Focus()
Else
MessageBox.Show("GAGAL HAPUS DATA")
End If
End Sub

Private Sub cmdBatal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBatal.Click
txtNmSup.Text = ""
txtalamat.Text = ""
End Sub

Private Sub BtnCariSup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCariSup.Click
Dim popupsup As New PopSup
popupsup.ShowDialog()
If popupsup.retKdSup <> "" Then
txtkdSup.Text = popupsup.retKdSup
txtNmSup.Text = popupsup.retNmSup
txtalamat.Text = popupsup.retAlmtSup
txtkdSup.Enabled = False
txtNmSup.Focus()
End If
End Sub

End Class

Free Template Blogger collection template Hot Deals BERITA_wongANteng SEO theproperty-developer

0 komentar:

Posting Komentar