Form login:
Option Explicit
Public LoginSucceeded As Boolean
Private Sub cmdCancel_Click()
'set the global var to false
'to denote a failed login
LoginSucceeded = False
Me.Hide
End Sub
Private Sub cmdOK_Click()
'check for correct password
If txtPassword = "password" Then
'place code to here to pass the
'success to the calling sub
'setting a global var is the easiest
LoginSucceeded = True
Me.Hide
Else
MsgBox "Invalid Password, try again!", , "Login"
txtPassword.SetFocus
SendKeys "{Home}+{End}"
End If
End Sub
Private Sub Form_Load()
End Sub
Menu utama:
Private Sub f2_Click()
Frm_mobil.Show
End Sub
Private Sub f3_Click()
End
End Sub
Private Sub MDIForm_Load()
End Sub
Form Mobil:
Dim IPServer As String
Sub Hapus()
kode.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 Mobil(Kode,jenis, Warna)" & _
" values('" & kode.Text & _
"','" & jenis.Text & _
"','" & warna.Text & "')"
Case 1
SQL = "UPDATE Mobil SET jenis ='" & jenis.Text & "'," & _
" Warna = '" & warna.Text & "' " & _
" where Kode ='" & kode.Text & "'"
Case 2
SQL = "DELETE FROM Mobil WHERE KODE='" & kode.Text & "'"
End Select
MsgBox "Pemorosesan RECORD Database telah berhasil...!", vbInformation, "Data Mobil"
Db.Execute SQL, adCmdTable
Db.CommitTrans
Call Hapus
Adodc1.Refresh
kode.SetFocus
End Sub
Sub Tampilmobil()
On Error Resume Next
kode.Text = RS!kode
jenis.Text = RS!jenis
warna.Text = RS!warna
End Sub
Private Sub CmdProses_Click(Index As Integer)
Select Case Index
Case 0
Call Hapus
kode.SetFocus
Case 1
If Cmdproses(1).Caption = "&Simpan" Then
Call ProsesDB(0)
Else
Call ProsesDB(1)
End If
Case 2
X = MsgBox("Yakin RECORD MOBIL Akan Dihapus...!", vbQuestion + vbYesNo, "Mobil")
If X = vbYes Then ProsesDB 2
Call Hapus
kode.SetFocus
Case 3
Call Hapus
kode.SetFocus
Case 4
Unload Me
End Select
End Sub
Private Sub Kode_keyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If kode.Text = "" Then Exit Sub
WS.SendData "SEARCH-" & kode.Text
End If
End Sub
Sub MulaiKoneksi()
IPServer = "192.168.10.1"
IPClient = WS.LocalIP
WS.Connect IPServer, 1000
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
DoEvents
End
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 "NOTHING"
X = kode.Text
Call Hapus
kode.Text = X
Call RubahCMD(Me, False, True, False, True)
Cmdproses(1).Caption = "&Simpan"
jenis.SetFocus
Case "RECORD"
xData2 = Split(xData1(1), "/")
kode.Text = xData2(0)
jenis.Text = xData2(1)
warna.Text = xData2(2)
Call RubahCMD(Me, False, True, True, True)
Cmdproses(1).Caption = "&Edit"
kode.Enabled = False
jenis.SetFocus
Case "DEL"
MsgBox "Penghapusan Data Berhasil!"
Call Hapus
Case "Edit"
MsgBox "Pengeditan Record Berhasil!"
Call Hapus
Case "insert"
MsgBox "masukkan data berhasil!!"
Call Hapus
End Select
End Sub
Module:
Public SQL As String
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
Tidak ada komentar:
Posting Komentar