A. SERVER
1. FORM KARYAWAN
Sub hapus()
nik.Enabled = True
ClearFORM Me
Call RubahCMD(Me, True, False, False, False)
cmdproses(1).Caption = "&Simpan"
End Sub
Sub ProsesDB(Log As Byte)
Select Case Log
Case 0
sql = "insert into Karyawan(nik,nama,jabatan,golongan,bagian)" & _
"values('" & nik.Text & _
"','" & nama.Text & _
"','" & jabatan.Text & _
"','" & golongan.Text & _
"','" & bagian.Text & "')"
Case 1
sql = "update Karyawan set nama='" & nama.Text & "'," & _
"jabatan='" & jabatan.Text & "'," & _
"golongan='" & golongan.Text & "'," & _
"bagian= '" & bagian.Text & "'" & _
"where nik='" & nik.Text & "'"
Case 2
sql = "delete from Karyawan where nik='" & nik.Text & "'"
End Select
MsgBox "Pemrosesan record database telah berhasil...!", vbInformation, "data Karyawan"
Db.BeginTrans
Db.Execute sql, adCmdTable
Db.CommitTrans
Call hapus
Adodc1.Refresh
nik.SetFocus
End Sub
Sub TampilKaryawan()
On Error Resume Next
nik.Text = rs!nik
nama.Text = rs!nama
jabatan.Text = rs!jabatan
golongan.Text = rs!golongan
bagian.Text = rs!bagian
End Sub
Private Sub cmdproses_Click(Index As Integer)
Select Case Index
Case 0
Call hapus
nik.SetFocus
Case 1
If cmdproses(1).Caption = "&Simpan" Then
Call ProsesDB(0)
Else
Call ProsesDB(1)
End If
Case 2
X = MsgBox("Yakin RECORD Karyawan akan dihapus...!", vbQuestion + vbYesNo, "Karyawan")
If X = vbYes Then ProsesDB 2
Call hapus
nik.SetFocus
Case 3
Call hapus
nik.SetFocus
Case 4
Unload Me
End Select
End Sub
Private Sub Form_Load()
Call OPENDB
Call hapus
MulaiServer
End Sub
Private Sub nik_keypress(keyascii As Integer)
If keyascii = 13 Then
If nik.Text = "" Then
MsgBox "Masukkan NIK Karyawan! ", vbInformation, "Karyawan"
nik.SetFocus
Exit Sub
End If
sql = "SELECT * FROM Karyawan WHERE nik='" & nik.Text & "' "
If rs.State = adStateOpen Then rs.Close
rs.Open sql, Db, adOpenDynamic, adLockOptimistic
If rs.RecordCount <> 0 Then
TampilKaryawan
Call RubahCMD(Me, False, True, True, True)
cmdproses(1).Caption = "&Edit"
nik.Enabled = False
Else
X = nik.Text
Call hapus
nik.Text = X
Call RubahCMD(Me, False, True, False, True)
cmdproses(1).Caption = "&Simpan"
End If
nama.SetFocus
End If
End Sub
Sub MulaiServer()
WS.LocalPort = 1000
WS.Listen
End Sub
Private Sub WS_connectionrequest(ByVal requestid As Long)
WS.Close
WS.Accept requestid
Me.Caption = "server-client" & WS.RemoteHostIP & "connect"
End Sub
Private Sub ws_dataarrival(ByVal bytestotal As Long)
Dim xKirim As String
Dim xData1() As String
Dim xData2() As String
WS.GetData xKirim, vbString, bytestotal
xData1 = Split(xKirim, "-")
Select Case xData1(0)
Case "SEARCH"
sql = "SELECT * FROM Karyawan WHERE nik='" & xData1(1) & "' "
If rs.State = adStateOpen Then rs.Close
rs.Open sql, Db, adOpenDynamic, adLockOptimistic
If rs.RecordCount <> 0 Then
WS.SendData "RECORD-" & rs!nama & "/" & rs!jabatan & "/" & rs!golongan & "/" & rs!bagian
Else
WS.SendData "NOTHING-DATA"
End If
Case "INSERT"
Db.BeginTrans
Db.Execute xData1(1), adCmdTable
Db.CommitTrans
WS.SendData " INSERT-xxx"
Adodc1.Refresh
Case "DELETE"
sql = " Delete * from Karyawan " & _
" where Kode = '" & xData1(1) & "' "
Db.BeginTrans
Db.Execute sql, adCmdTable
Db.CommitTrans
Adodc1.Refresh
WS.SendData "DEL-xxx"
Case "UPDATE"
Db.BeginTrans
Db.Execute xData1(1), adCmdTable
Db.CommitTrans
WS.SendData "EDIT-xxx"
Adodc1.Refresh
End Select
End Sub
MODUL FORM KARYAWAN
Public Db As New ADODB.Connection
Public rs As New ADODB.Recordset
Public rs2 As New ADODB.Recordset
Public sql As String
Sub OPENDB()
If Db.State = adStateOpen Then Db.Close
Db.CursorLocation = adUseClient
Db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & App.Path & _
"\db1.mdb;Persist Security Info=False "
End Sub
Sub ClearFORM(f As Form)
Dim ctl As Control
For Each ctl In f
If TypeOf ctl Is TextBox Then ctl.Text = ""
If TypeOf ctl Is ComboBox Then ctl.Text = ""
Next
End Sub
Sub Center(f As Form)
f.Move (Screen.Width - f.Width) / 2, (Screen.Height - f.Height) / 4
End Sub
Sub RubahCMD(f As Form, L0 As Boolean, L1 As Boolean, L2 As Boolean, L3 As Boolean)
f.cmdproses(0).Enabled = L0
f.cmdproses(1).Enabled = L1
f.cmdproses(2).Enabled = L2
f.cmdproses(3).Enabled = L3
End Sub
2. FORM LOGIN
Unload Me
End Sub
Private Sub ok_Click()
If username.Text = "siti" And pass.Text = "1234" Then
Me.Hide
MenuUtama.Show
Else
MsgBox "Maaf! Username dan Password yang anda masukkan salah", vbInformation, "pemakai"
End If
End Sub
3. FORM MENU UTAMA
FrmKaryawan.Show
End Sub
Private Sub Keluar_Click()
Unload Me
End Sub
HASIL DARI LISTING PROGRAM
"Nama='" & Nama.Text & _
"',Golongan='" & golongan.Text & _
"',Jabatan='" & jabatan.Text & _
"',Bagian='" & bagian.Text & _
"'Where Nik='" & Nik.Text & "'"
Tidak ada komentar:
Posting Komentar