1. 程式人生 > >【第一次機房收費系統優化】-登入窗體

【第一次機房收費系統優化】-登入窗體

一、重點
這個窗體增加了判斷使用者的類別(操作員、一般使用者、管理員)。
二、控制元件優化
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
``