我对我的代码有一些疑问,我正在使用 VB6.0 我有一个使用TimerControl的问题...用户将首先登录[ frmLogin ]然后 UserID 和密码必须识别是管理员还是访客。一旦被识别为管理员,用户将被重定向到 frmAdmin ,如果没有,他将被重定向到[strong> frmEmployee 后定时器[ tmLogin ] /进度条[ pgLogin ] 达到100%。我只是感到困惑,因为我使用的数据库有两个表[ tblEmployee &的 tblPosition ]。每个表都有一个索引: tblEmployee 的 idxid 和 tblPosition 的 idxpost ...我不知道在哪里插入条件语句...请帮帮我,一旦解决了,我可能会遇到进一步问题的规则...提前谢谢。这是我的代码
Private Sub cmdContinue_Click()
Dim boolLogedIn As Boolean
If Me.txtUserID.Text = "" And Me.txtPassword.Text = "" Then
Me.lblWarning.Caption = "*User ID and Password must not be a null."
Me.tmLoginformSize.Enabled = True
Me.txtUserID.SetFocus
Beep
ElseIf Me.txtUserID.Text = "" Then
Me.lblWarning.Caption = "*User ID must not be a null."
Me.tmLoginformSize.Enabled = True
Me.txtUserID.SetFocus
Beep
ElseIf Me.txtPassword.Text = "" Then
Me.lblWarning.Caption = "*Password must not be a null."
Me.tmLoginformSize.Enabled = True
Me.txtPassword.SetFocus
Beep
Else
Do Until datLogin.Recordset.EOF
With datLogin.Recordset
If Me.txtUserID.Text = !empid And Me.txtPassword.Text = !Password Then
boolLogedIn = True
Exit Do
Else
datLogin.Recordset.MoveNext
End If
End With
Loop
If boolLogedIn = True Then
Me.tmLogin.Enabled = True
Me.lblConnecting.Visible = True
Me.lblLoginPercent.Visible = True
Me.pbLogin.Visible = True
Else
Me.lblWarning.Caption = "*User ID and Password did not match."
Me.datLogin.Recordset.MoveFirst
Me.tmLoginformSize.Enabled = True
Beep
End If
End If
End Sub
Private Sub tmLogin_Timer()
With Me.pbLogin
Me.pbLogin.Value = Me.pbLogin.Value + 1
Me.lblLoginPercent.Caption = Str(Me.pbLogin.Value) + "%"
If Me.pbLogin.Value >= 1 And Me.pbLogin.Value < 50 Then
Me.lblConnecting.Caption = "Connecting..."
ElseIf Me.pbLogin.Value >= 50 And Me.pbLogin.Value < 100 Then
Me.lblConnecting.Caption = "Logging in..."
Else
Me.lblConnecting.Caption = "Done..."
frmLogin.Hide
frmEmployee.Show
Me.tmLogin.Enabled = False
End If
End With
End Sub
...这是我的截图
答案 0 :(得分:1)
你的问题不够明确。如果您想根据管理员或其他方式加载表单,可以像这样使用
dim r as new adodb.recordset
r.open "select postid from tblemployee",db,adopendynamic,adlockoptimistic,adcmdtext
'db is your adodb.connection
if r.eof then
msgbox "name/pass not matched"
exit sub
else
'do whatever you like with your postid in r.fields(0)
end if
答案 1 :(得分:0)
以下是我将如何通过最少的更改来实现您所寻找的目标 你的代码:
'Add this declaration
Dim m_intLoggedInUserType As Integer
Private Sub cmdContinue_Click()
'Unchanged code
Do Until datLogin.Recordset.EOF
With datLogin.Recordset
If Me.txtUserID.Text = !empid And Me.txtPassword.Text = !Password Then
boolLogedIn = True
m_intLoggedInUserType = !postId
Exit Do
Else
datLogin.Recordset.MoveNext
End If
End With
Loop
'More unchanged code
End Sub
Private Sub tmLogin_Timer()
With Me.pbLogin
'Unchanged code
Me.lblConnecting.Caption = "Done..."
frmLogin.Hide
if m_intLoggendInUserType = 1 Then
frmAdmin.Show
Else
frmEmployee.Show
End If
Me.tmLogin.Enabled = False
End If
End With
End Sub
你也应该注意Rasel的答案,因为直接使用连接和记录集对象比datacontrol更好。