第一次机房收费系统---登陆窗体

前言

不管是学生还是机房,敲的第一个窗体都是登录,这两个学习项目有很大的相同点,学生有源码,机房却没有,需要搞清楚里边的逻辑,问题也就迎刃而解了。
下面是我画的机房的流程图:

第一次机房收费系统---登陆窗体_第1张图片

代码如下:

Option Explicit
Private Declare Function GetUserName Lib "advapi32.d11" Alias "GetUserNameA" (ByVal lpbuffer As String, nSize As Long) As Long
Public OK As Boolean
Dim miCount As Integer

Private Sub cmdexit_Click()
    OK = False
    Me.Hide
End Sub

Private Sub cmdOK_Click()
Dim txtSQL As String             '用来存放SQL语句
Dim mrc As ADODB.Recordset       '用来存放记录及对象
Dim msgtext As String            '用来存放返回信息
txtUserName = ""                    '判断输入用户名是否为空

If Trim(txtUserName.Text) = "" Then '判断用户名是否存在
    MsgBox "没有这个用户,请重新输入!", vbOKOnly + vbExclamation, "警告"
    txtUserName.SetFocus
Else
    txtSQL = "select * from user_Info where user_ID='" & txtUserName.Text & "'"  '查询指定用户名的记录
    Set mrc = executeSQL(txtSQL, msgtext)
    If mrc.EOF Then            '判断数据库中是否有记录
        MsgBox "没有这个用户,请重新输入!", vbOKOnly + vbExclamation, "警告"
        txtUserName.SetFocus
    Else
        If Trim(mrc.Fields(1)) = Trim(txtPassword.Text) Then
            OK = False
            mrc.Close
            Me.Hide
            frmmain.Show
            
            username = Trim(txtUserName.Text)
        Else
            MsgBox "输入密码不正确,请重新输入!", vbOKOnly + vbExclamation, "警告"
            txtPassword.SetFocus
            txtPassword.Text = ""
        End If
        
    End If
End If
miCount = miCount + 1               '限制输入密码次数
If miCount = 1 Then
        MsgBox "密码输入错误,您还有两次机会!", vbOKOnly + vbExclamation, "警告"
        txtPassword.SetFocus
        txtPassword.Text = ""
        Exit Sub
    ElseIf miCount = 2 Then
        MsgBox "密码输入错误,您还有一次机会!", vbOKOnly + vbExclamation, "警告"
        txtPassword.SetFocus
        txtPassword.Text = ""
        Exit Sub
    ElseIf miCount = 3 Then
        MsgBox "密码输入错误,程序即将关闭!", vbOKOnly + vbExclamation, "警告"
        txtPassword.SetFocus
        txtPassword.Text = ""
        Me.Hide
        Exit Sub
    End If
    End If

End If
Exit Sub
End Sub

'查询条件    用户输入信息不能为空
    If Trim(txtUserName.Text = "") Then
        MsgBox "用户名称不能为空,请重新输入!", vbOKOnly + vbExclamation, "警告"
        txtUserName.SetFocus
    ElseIf Trim(txtPassword.Text = "") Then
        MsgBox "用户密码不能为空,请重新输入!", vbOKOnly + vbExclamation, "警告"
        txtUserName.SetFocus
    End If
End Sub
    


Private Sub Form_Load()

End Sub

Private Sub txtUserName_KeyPress(KeyAscii As Integer)            '限制用户名只能有数字和字母组成
If (KeyAscii >= 48 And KeyAscii <= 57) Or (KeyAscii >= 65 And KeyAscii <= 90) Or (KeyAscii >= 97 And KeyAscii <= 122) Or (KeyAscii = 8) Then
  Else
  MsgBox "用户名由字母和数字组成", vbOKOnly + vbExclamation, "警告"
  KeyAscii = 0
  End If
End Sub

好好学习,天天向上

你可能感兴趣的:(第一次机房收费系统---登陆窗体)