Halo semuanya kini kita masuk pada tahap selanjutnya dari posting "Tutorial-01" di bulan desember'10 lalu.
silahkan buat Form seperti dibawah ini, namakan dengan USER
buka View Code pada Vb.Net anda dan tambahkan pada awal code ketikan
**********************************
Imports System.Data
Imports System.Data.OleDb
**********************************
double click pada form
**********************************
Call MyKoneksi.KONEKSI_DBMS()
Call FIELD_LOCK()
Call CAPITAL()
CmbLEVEL.Items.Clear()
CmbLEVEL.Items.Add("ADMINISTRATOR")
CmbLEVEL.Items.Add("SYSADMIN")
CmbLEVEL.Items.Add("USER")
*************************************
pada Class Form USER buat beberapa Private Sub
***************************************
Private Sub SEGER()
RSKODE = New OleDb.OleDbDataAdapter("SELECT IDUSER FROM TABEL_USER_SISTEM ORDER BY IDUSER DESC", MyKoneksi.KONEKSI_DBMS)
Try
DATASET_ID.Tables.Clear()
Catch ex As Exception
RSKODE.Fill(DATASET_ID)
End Try
End Sub
************************************************************************
Private Sub ID_USER()
Dim URUTAN As String = ""
Dim HITUNG As String
Dim intHITUNG As Integer
RSKODE = New OleDb.OleDbDataAdapter("SELECT IDUSER, USERNAME, PASSWORD, AUTHENTIFIKASI FROM TABEL_USER_SISTEM ORDER BY IDUSER DESC", MyKoneksi.KONEKSI_DBMS)
RSKODE.Fill(DATASET_ID)
If DATASET_ID.Tables(0).Rows.Count = 0 Then
URUTAN = "USR0001"
Else
'klo sortir record ASC
'HITUNG = "2" & Mid(DATASET_ID.Tables(0).Rows(DATASET_ID.Tables(0).Rows.Count - 1).Item(0), 4, 4)
'klo sortir record DESC
HITUNG = "2" & Mid(DATASET_ID.Tables(0).Rows(0).Item(0), 4, 4)
intHITUNG = CInt(HITUNG) + 1
If intHITUNG > 29999 Then
MsgBox("OVER LOAD DATA", MsgBoxStyle.Information, "SISTEM")
Else
URUTAN = "USR" & Mid(CStr(intHITUNG), 2, 4)
End If
End If
TxtIDUSER.Text = URUTAN
End Sub
*****************************************************************
Dim DATASET_ID As New DataSet
Dim RSKODE As OleDb.OleDbDataAdapter
******************************************************************
Private Sub CAPITAL()
TxtIDUSER.CharacterCasing = CharacterCasing.Upper
TxtUSERNAME.CharacterCasing = CharacterCasing.Upper
TxtPASSWORD.CharacterCasing = CharacterCasing.Upper
End Sub
**********************************************************************
Private Sub FIELD_EMPTY()
TxtIDUSER.Text = ""
TxtUSERNAME.Text = ""
TxtPASSWORD.Text = ""
CmbLEVEL.Text = ""
End Sub
**********************************************************************
Private Sub FIELD_UNLOCK()
TxtUSERNAME.Enabled = True
TxtPASSWORD.Enabled = True
CmbLEVEL.Enabled = True
End Sub
**********************************************************************
Private Sub FIELD_LOCK()
TxtIDUSER.Enabled = False
TxtUSERNAME.Enabled = False
TxtPASSWORD.Enabled = False
CmbLEVEL.Enabled = False
End Sub
*******************************************
Private Sub BTN_INPUT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_INPUT.Click
If BTN_INPUT.Text = "&INPUT" Then
Call FIELD_EMPTY()
Call FIELD_UNLOCK()
Call ID_USER()
TxtUSERNAME.Focus()
BTN_EDIT.Enabled = False
BTN_DELETE.Enabled = False
BTN_INPUT.Text = "&SIMPAN"
BTN_EXIT.Text = "&BATAL"
ElseIf BTN_INPUT.Text = "&SIMPAN" Then
Call SAVE_DATA()
End If
End Sub
***********************************************
Private Sub SAVE_DATA()
Try
Call MyKoneksi.KONEKSI_DBMS()
CONN.Open()
Dim SQLINPUT As String = "INSERT INTO TABEL_USER_SISTEM VALUES ('" & TxtIDUSER.Text & "','" & TxtUSERNAME.Text & "','" & TxtPASSWORD.Text & "','" & CmbLEVEL.Text & "')"
Dim INPUT As OleDbCommand = New OleDbCommand(SQLINPUT, CONN)
INPUT.ExecuteNonQuery()
CONN.Close()
Call FIELD_EMPTY()
Call FIELD_LOCK()
Call BTN_READY()
MsgBox("DATA TELAH TERSIMPAN", MsgBoxStyle.Information, "WIRATMOJO")
Call SEGER()
Catch ex As Exception
MsgBox("KONEKSI DATABASE BERMASALAH", MsgBoxStyle.Exclamation, "WIRATMOJO")
Call FIELD_EMPTY()
Call FIELD_LOCK()
Call BTN_READY()
End Try
End Sub
******************************************************
Private Sub BTN_EDIT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_EDIT.Click
If BTN_EDIT.Text = "&EDIT" Then
BTN_EDIT.Text = "&OK"
BTN_EXIT.Text = "&BATAL"
BTN_INPUT.Enabled = False
BTN_DELETE.Enabled = False
Call FIELD_UNLOCK()
TxtUSERNAME.Focus()
ElseIf BTN_EDIT.Text = "&OK" Then
Call UPDATE_DATA()
End If
End Sub
*******************************************
Private Sub UPDATE_DATA()
Try
Call MyKoneksi.KONEKSI_DBMS()
CONN.Open()
Dim SQLUPDATE As String = "UPDATE TABEL_USER_SISTEM " & _
"SET[USERNAME] ='" & TxtUSERNAME.Text & "', " & _
"[PASSWORD] ='" & TxtPASSWORD.Text & "', " & _
"[AUTHENTIFIKASI] ='" & CmbLEVEL.Text & "' " & _
"WHERE [IDUSER] = '" & TxtIDUSER.Text & "'"
Dim UPDATE As OleDbCommand = New OleDbCommand(SQLUPDATE, CONN)
UPDATE.ExecuteNonQuery()
CONN.Close()
Call FIELD_EMPTY()
Call FIELD_LOCK()
Call BTN_READY()
MsgBox("DATA TELAH DIUBAH !!!", MsgBoxStyle.Information, "WIRATMOJO")
Call SEGER()
Catch ex As Exception
MsgBox("KONEKSI DATABASE BERMASALAH", MsgBoxStyle.Exclamation, "WIRATMOJO")
Call FIELD_EMPTY()
Call FIELD_LOCK()
Call BTN_READY()
End Try
End Sub
*********************************************************************
Private Sub BTN_DELETE_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_DELETE.Click
Call DELETE_DATA()
End Sub
*********************************************************************
Private Sub DELETE_DATA()
Try
Call MyKoneksi.KONEKSI_DBMS()
CONN.Open()
Dim SQLDELETE As String = "DELETE FROM TABEL_USER_SISTEM WHERE IDUSER='" & TxtIDUSER.Text & "'"
Dim DELETE As OleDbCommand = New OleDbCommand(SQLDELETE, CONN)
DELETE.ExecuteNonQuery()
CONN.close()
Call FIELD_EMPTY()
Call FIELD_LOCK()
Call BTN_READY()
MsgBox("DATA TELAH DIHAPUS !!!", MsgBoxStyle.Information, "WIRATMOJO")
Call SEGER()
Catch ex As Exception
MsgBox("KONEKSI DATABASE BERMASALAH", MsgBoxStyle.Exclamation, "WIRATMOJO")
Call FIELD_EMPTY()
Call FIELD_LOCK()
Call BTN_READY()
End Try
End Sub
********************************************************
Private Sub BTN_EXIT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_EXIT.Click
If BTN_EXIT.Text = "&EXIT" Then
Me.Close()
ElseIf BTN_EXIT.Text = "&BATAL" Then
Call FIELD_EMPTY()
Call FIELD_LOCK()
Call BTN_READY()
End If
End Sub
***********************************************
Private Sub TxtUSERNAME_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtUSERNAME.KeyPress
If e.KeyChar = Chr(13) Then TxtPASSWORD.Focus()
End Sub
***************************************************************************
Private Sub TxtPASSWORD_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtPASSWORD.KeyPress
If e.KeyChar = Chr(13) Then CmbLEVEL.Focus()
End Sub
****************************************************************************
Private Sub CmbLEVEL_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles CmbLEVEL.KeyPress
If e.KeyChar = Chr(13) Then
If BTN_INPUT.Enabled = True Then
BTN_INPUT.Focus()
ElseIf BTN_INPUT.Enabled = False Then
BTN_EDIT.Focus()
End If
End If
End Sub
****************************************************
Private Sub BTN_LIST_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_LIST.Click
Me.Hide()
APLIKASI.Show()
End Sub
******************************************************
Comments
Post a Comment