📄 frmuser.frm
字号:
VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Begin VB.Form FrmUser
BackColor = &H00EFF2EC&
BorderStyle = 1 'Fixed Single
Caption = "Pendaftaran Operator"
ClientHeight = 7110
ClientLeft = 45
ClientTop = 390
ClientWidth = 5415
FillColor = &H00FFFFFF&
ForeColor = &H00FFFFFF&
Icon = "FrmUser.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 7110
ScaleWidth = 5415
StartUpPosition = 2 'CenterScreen
Begin VB.OptionButton TxtLoginAdmin
Caption = "Admin"
Height = 375
Left = 2520
TabIndex = 5
Top = 2880
Width = 1335
End
Begin VB.OptionButton TxtLoginUser
Caption = "Guest"
Height = 375
Left = 1440
TabIndex = 4
Top = 2880
Width = 855
End
Begin VB.TextBox TxtTelpon
Height = 375
Left = 1440
MaxLength = 15
TabIndex = 18
Top = 2400
Width = 2175
End
Begin VB.TextBox TxtAlamat
Height = 375
Left = 1440
MaxLength = 25
TabIndex = 3
Top = 1920
Width = 3135
End
Begin VB.TextBox TxtNama
Height = 375
Left = 1440
MaxLength = 20
TabIndex = 2
Top = 1440
Width = 2535
End
Begin VB.TextBox TxtPassword
Height = 375
IMEMode = 3 'DISABLE
Left = 1440
MaxLength = 15
PasswordChar = "*"
TabIndex = 1
Top = 960
Width = 1815
End
Begin VB.TextBox TxtUser
Height = 375
Left = 1440
MaxLength = 15
TabIndex = 0
Top = 480
Width = 1815
End
Begin VB.CommandButton CmdSimpan
Caption = "Simpan"
Height = 375
Left = 240
TabIndex = 6
Top = 6240
Width = 975
End
Begin VB.CommandButton CmdUbah
Caption = "Ubah"
Height = 375
Left = 1560
TabIndex = 7
Top = 6240
Width = 975
End
Begin VB.CommandButton CmdHapus
Caption = "Hapus"
Height = 375
Left = 2880
TabIndex = 8
Top = 6240
Width = 975
End
Begin VB.CommandButton CmdTutup
Caption = "Tutup"
Height = 375
Left = 4080
TabIndex = 9
Top = 6240
Width = 975
End
Begin VB.Frame Frame2
Height = 855
Left = 120
TabIndex = 17
Top = 6000
Width = 5175
End
Begin VB.Frame Frame1
Height = 3375
Left = 120
TabIndex = 10
Top = 240
Width = 5175
Begin VB.Label Label2
BackStyle = 0 'Transparent
Caption = "Nama User"
Height = 255
Left = 360
TabIndex = 16
Top = 360
Width = 1455
End
Begin VB.Label Label3
BackStyle = 0 'Transparent
Caption = "Password"
Height = 255
Left = 360
TabIndex = 15
Top = 840
Width = 1455
End
Begin VB.Label Label4
BackStyle = 0 'Transparent
Caption = "Nama Asli"
Height = 255
Left = 360
TabIndex = 14
Top = 1320
Width = 1455
End
Begin VB.Label Label5
BackStyle = 0 'Transparent
Caption = "Alamat"
Height = 255
Left = 360
TabIndex = 13
Top = 1800
Width = 1455
End
Begin VB.Label Label6
BackStyle = 0 'Transparent
Caption = "No. Telpon"
Height = 255
Left = 360
TabIndex = 12
Top = 2280
Width = 1455
End
Begin VB.Label Label7
BackStyle = 0 'Transparent
Caption = "Jenis User"
Height = 255
Left = 360
TabIndex = 11
Top = 2760
Width = 1455
End
End
Begin MSFlexGridLib.MSFlexGrid GridOp
Height = 2295
Left = 120
TabIndex = 19
Top = 3720
Width = 5175
_ExtentX = 9128
_ExtentY = 4048
_Version = 393216
Cols = 3
FixedCols = 0
End
End
Attribute VB_Name = "FrmUser"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub cl2_Click()
End Sub
Private Sub cmdhapus_Click()
cn.Open
cmd.ActiveConnection = cn
cmd.CommandType = adCmdText
cmd.CommandText = "SELECT account.* FROM account WHERE account.user = '" & TxtUser.Text & "'"
cmd.Execute
rs.ActiveConnection = cn
rs.Open "SELECT account.* FROM account WHERE account.user = '" & TxtUser.Text & "'", cn, adOpenStatic, adLockOptimistic
If Not rs.RecordCount = 0 Then
If rs(2) = "root" Then
MsgBox "root : Nama user ini tidak bisa dihapus"
Else
rs.Delete
End If
End If
cn.Close
Bersih
CmdSimpan.Enabled = False
CmdUbah.Enabled = False
CmdHapus.Enabled = False
TxtUser.Text = ""
TxtUser.SetFocus
End Sub
Private Sub cmdsimpan_Click()
Dim passwd As String
passwd = EncryptText(TxtPassword.Text, "password")
cn.Open
cmd.ActiveConnection = cn
cmd.CommandType = adCmdText
cmd.CommandText = "SELECT account.* FROM account WHERE account.user = '" & TxtUser.Text & "'"
cmd.Execute
rs.ActiveConnection = cn
rs.Open "SELECT account.* FROM account WHERE account.user = '" & TxtUser.Text & "'", cn, adOpenStatic, adLockOptimistic
If Not rs.RecordCount = 0 Then
If rs(2) = "root" Then
rs(0) = TxtUser.Text
rs(5) = passwd
rs(1) = TxtNama.Text
rs(3) = TxtAlamat.Text
rs(4) = TxtTelpon.Text
rs(2) = "root"
rs.Update
Else
rs(0) = TxtUser.Text
rs(5) = passwd
rs(1) = TxtNama.Text
rs(3) = TxtAlamat.Text
rs(4) = TxtTelpon.Text
If TxtLoginAdmin.value = True Then
rs(2) = "admin"
Else
rs(2) = "user"
End If
rs.Update
End If
Else
rs.AddNew
rs(0) = TxtUser.Text
rs(5) = passwd
rs(1) = TxtNama.Text
rs(3) = TxtAlamat.Text
rs(4) = TxtTelpon.Text
If TxtLoginAdmin.value = True Then
rs(2) = "admin"
Else
rs(2) = "user"
End If
rs.Update
End If
cn.Close
Bersih
CmdSimpan.Enabled = False
CmdUbah.Enabled = False
CmdHapus.Enabled = False
TxtUser.Text = ""
TxtUser.SetFocus
End Sub
Private Sub CmdTutup_Click()
Unload Me
End Sub
Private Sub CmdUbah_Click()
CmdUbah.Enabled = False
CmdHapus.Enabled = False
CmdSimpan.Enabled = True
TxtPassword.SetFocus
End Sub
Private Sub Image1_Click()
End Sub
Private Sub Form_Load()
Call loadgrid
End Sub
Private Sub TxtAlamat_GotFocus()
TxtAlamat.Backcolor = &HFFFF00
End Sub
Private Sub TxtAlamat_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
TxtTelpon.SetFocus
End If
End Sub
Private Sub TxtAlamat_LostFocus()
TxtAlamat.Backcolor = &H80000005
End Sub
Private Sub TxtNama_GotFocus()
TxtNama.Backcolor = &HFFFF00
End Sub
Private Sub TxtNama_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
TxtAlamat.SetFocus
End If
End Sub
Private Sub TxtNama_LostFocus()
TxtNama.Backcolor = &H80000005
End Sub
Private Sub TxtPassword_GotFocus()
TxtPassword.Backcolor = &HFFFF00
End Sub
Private Sub TxtPassword_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
TxtNama.SetFocus
End If
End Sub
Private Sub TxtPassword_LostFocus()
TxtPassword.Backcolor = &H80000005
End Sub
Private Sub TxtTelpon_GotFocus()
TxtTelpon.Backcolor = &HFFFF00
End Sub
Private Sub TxtTelpon_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
TxtLoginUser.SetFocus
End If
End Sub
Private Sub TxtTelpon_LostFocus()
TxtTelpon.Backcolor = &H80000005
End Sub
Private Sub TxtUser_GotFocus()
TxtUser.Backcolor = &HFFFF00
End Sub
Private Sub TxtUser_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If Not TxtUser.Text = "" Then
CekUser
End If
End If
End Sub
Private Sub TxtUser_LostFocus()
TxtUser.Backcolor = &H80000005
End Sub
Private Sub CekUser()
cn.Open
cmd.ActiveConnection = cn
cmd.CommandType = adCmdText
cmd.CommandText = "SELECT account.* FROM account WHERE account.user = '" & TxtUser.Text & "'"
cmd.Execute
rs.ActiveConnection = cn
rs.Open "SELECT account.* FROM account WHERE account.user = '" & TxtUser.Text & "'", cn, adOpenStatic, adLockOptimistic
If rs.RecordCount = 0 Then
Baru
Else
TxtPassword.Text = DecryptText(rs(5), "password")
TxtNama.Text = rs(1)
TxtAlamat.Text = rs(3)
TxtTelpon.Text = rs(4)
If rs(2) = "root" Then
TxtLoginAdmin.value = True
TxtLoginUser.value = False
ElseIf rs(2) = "admin" Then
TxtLoginAdmin.value = True
TxtLoginUser.value = False
Else
TxtLoginUser.value = True
TxtLoginAdmin.value = False
End If
CmdUbah.Enabled = True
CmdHapus.Enabled = True
CmdSimpan.Enabled = False
End If
cn.Close
End Sub
Private Sub Bersih()
TxtPassword.Text = ""
TxtNama.Text = ""
TxtAlamat.Text = ""
TxtTelpon.Text = ""
TxtLoginUser.value = False
TxtLoginAdmin.value = False
End Sub
Private Sub Baru()
Bersih
TxtPassword.SetFocus
CmdSimpan.Enabled = True
CmdUbah.Enabled = False
CmdHapus.Enabled = False
End Sub
Private Sub loadgrid()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim cmd As New ADODB.Command
Dim sql As String
GridOp.TextMatrix(0, 0) = "Nama User"
GridOp.TextMatrix(0, 1) = "Nama Asli"
GridOp.TextMatrix(0, 2) = "Level"
GridOp.ColWidth(0) = 1200
GridOp.ColWidth(1) = 1600
GridOp.ColWidth(2) = 2250
sql = "SELECT account.* FROM account"
cn.Open con1
rs.ActiveConnection = cn
rs.Open sql, cn, adOpenStatic, adLockOptimistic
If Not rs.RecordCount = 0 Then
GridOp.Rows = rs.RecordCount + 1
rs.MoveFirst
For i = 1 To rs.RecordCount
GridOp.TextMatrix(i, 0) = rs(0)
GridOp.TextMatrix(i, 1) = rs(1)
GridOp.TextMatrix(i, 2) = rs(2)
rs.MoveNext
Next i
Else
GridOp.Rows = 1
End If
cn.Close
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -