【第一次机房收费系统优化】-登录窗体

一、重点
这个窗体增加了判断用户的类别(操作员、一般用户、管理员)。
二、控件优化
label为空白:Label1.BackStyle = 0
command添加图片:(1)将Command控件的Style设置为1 - Graphical (2)在Command控件的Picture中,点浏览,选择一张图片。
在这里插入图片描述
三、优化区域
不能输入特殊符号

Select Case KeyAscii
  1. Case -20319 To -3652
  2. Case 48 To 57
  3. Case 65 To 90
  4. Case 97 To 122
  5. Case 8
  6. Case Else
  7. KeyAscii = 0
  8. End Select

四、代码

Private Sub cmdOk_Click()
'用来存放SQL语句
    Dim txtSQL As String
    Dim txtSQL1 As String
    Dim txtSQL2 As String
    
' 用来存放记录集对象
    Dim mrc As ADODB.Recordset
    Dim mrc1 As ADODB.Recordset
    Dim mrc2 As ADODB.Recordset
    
'用来存放返回信息
    Dim MsgText As String
    Dim msgText1 As String
    Dim Msgtext2 As String
    Dim ctrl As Control
    'ToDo: create test for correct password
    'check for correct password
    username = ""
  
    '判断输入用户名是否为空
    If Trim(txtUserName.Text = " ") Then
        MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
        txtUserName.SetFocus
        txtUserName.Text = ""
        txtPassword.Text = ""
        Exit Sub
        Else
    If Trim(txtPassword.Text = "") Then
        MsgBox "请输入密码!", vbOKOnly + vbExclamation, "提示"
        txtUserName.SetFocus
        txtPassword.Text = ""
        Exit Sub
        
    Else
       
            txtSQL = "select * from user_info where UserID='" & txtUserName.Text & "'"
            Set mrc = ExecuteSQL(txtSQL, MsgText) '执行查询语句
            
            txtSQL2 = "select * from worklog_info where UserID='" & txtUserName.Text & "'"
            Set mrc2 = ExecuteSQL(txtSQL2, Msgtext2)
            
            txtSQL1 = "select * from onwork_info where userid='" & txtUserName.Text & "'"
            Set mrc1 = ExecuteSQL(txtSQL1, msgText1)
            
                If mrc.EOF Then
                    MsgBox "无此用户,请重新输入!", vbOKOnly + vbExclamation, "提示"
                    txtUserName.Text = ""
                    txtUserName.SetFocus
                    Exit Sub
                    Else
                    
                    If mrc.Fields(0) = txtUserName.Text And mrc.Fields(1) = txtPassword.Text Then
                        End If
                        ok = True
                        
                        username = Trim(txtUserName.Text)
                        
                    If Trim(mrc.Fields(2)) = "管理员" Then
                    Else
                    If Trim(mrc.Fields(2)) = "操作员" Then
                        frmMain.cmucz.Enabled = False
                    Else
                        frmMain.manger.Enabled = False
                        frmMain.cmucz.Enabled = False
                        
            End If
        End If
    End If
    
    If mrc1.EOF = False Then
        MsgBox "此用户二次登陆", vbOKCancel + vbExclamation, "提示"
        mrc1.Delete
        mrc1.Update
        mrc1.Close
        
        Else
            
              mrc1.AddNew
                 mrc1.Fields(0) = Trim(txtUserName)
                 mrc1.Fields(1) = Trim(mrc.Fields(2))
                 mrc1.Fields(2) = Trim(Date)
                 mrc1.Fields(3) = Time
                 mrc1.Update
                 mrc1.Close

                 mrc2.AddNew        '添加记录到worklog_info表
                 mrc2.Fields(1) = Trim(txtUserName)
                 mrc2.Fields(2) = Trim(mrc.Fields(2))
                 mrc2.Fields(3) = Trim(Date)
                 mrc2.Fields(4) = Trim(Time)
                 mrc2.Fields(7) = VBA.Environ("computername")
                 mrc2.Fields(8) = True
                 mrc2.Update
                 mrc2.Close
            Me.Hide
            frmMain.Show

    '记载输入密码次数
    micount = micount + 1
    If micount = 3 Then
        Me.Hide
    End
'    Exit Sub
'        For Each ctrl In Me.Controls
'        If TypeOf ctrl Is textbox Then '是否为文本框textbox
'        ctrl.Text = ""
'        End If
'        Next
End If
End If
End If
End If
End Sub
``
展开阅读全文

没有更多推荐了,返回首页