www.pudn.com > chap07.rar > frmLogin.frm


VERSION 5.00 
Begin VB.Form frmLogin  
   BorderStyle     =   3  'Fixed Dialog 
   Caption         =   "登录" 
   ClientHeight    =   2310 
   ClientLeft      =   2760 
   ClientTop       =   3750 
   ClientWidth     =   4155 
   Icon            =   "frmLogin.frx":0000 
   LinkTopic       =   "Form1" 
   LockControls    =   -1  'True 
   MaxButton       =   0   'False 
   MinButton       =   0   'False 
   ScaleHeight     =   2310 
   ScaleWidth      =   4155 
   ShowInTaskbar   =   0   'False 
   StartUpPosition =   1  '所有者中心 
   Begin VB.TextBox txtZh  
      Height          =   285 
      Left            =   1290 
      TabIndex        =   0 
      Text            =   "public" 
      Top             =   1425 
      Width           =   1755 
   End 
   Begin VB.TextBox txtPwd  
      Height          =   285 
      IMEMode         =   3  'DISABLE 
      Left            =   1290 
      PasswordChar    =   "*" 
      TabIndex        =   1 
      Top             =   1853 
      Width           =   1755 
   End 
   Begin VB.CommandButton OKButton  
      Caption         =   "确定(&O)" 
      Default         =   -1  'True 
      Height          =   375 
      Left            =   2865 
      TabIndex        =   3 
      Top             =   255 
      Width           =   1215 
   End 
   Begin VB.CommandButton CancelButton  
      Cancel          =   -1  'True 
      Caption         =   "取消(&C)" 
      Height          =   375 
      Left            =   2865 
      TabIndex        =   2 
      Top             =   735 
      Width           =   1215 
   End 
   Begin VB.Image Image1  
      Height          =   480 
      Left            =   210 
      Picture         =   "frmLogin.frx":000C 
      Top             =   225 
      Width           =   480 
   End 
   Begin VB.Label Label2  
      AutoSize        =   -1  'True 
      Caption         =   "请输入帐号和密码" 
      Height          =   180 
      Left            =   1080 
      TabIndex        =   6 
      Top             =   255 
      Width           =   1440 
   End 
   Begin VB.Label Label3  
      BackStyle       =   0  'Transparent 
      Caption         =   "密码:" 
      Height          =   180 
      Left            =   750 
      TabIndex        =   5 
      Top             =   1905 
      Width           =   540 
   End 
   Begin VB.Label Label1  
      AutoSize        =   -1  'True 
      BackStyle       =   0  'Transparent 
      Caption         =   "帐号:" 
      Height          =   180 
      Left            =   750 
      TabIndex        =   4 
      Top             =   1470 
      Width           =   540 
   End 
End 
Attribute VB_Name = "frmLogin" 
Attribute VB_GlobalNameSpace = False 
Attribute VB_Creatable = False 
Attribute VB_PredeclaredId = True 
Attribute VB_Exposed = False 
Option Explicit 
' 
Private msZh As String '帐号 
Private msMC As String '名称 
Private miLx As Integer '用户类型 
Private msSjbh As String '试卷编号 
Private msTitle As String '窗口标题 
Private mbIsCancelled As Boolean '是否取消 
Private madoCONN As ADODB.Connection '数据源 
Private Sub CancelButton_Click() 
    If MsgBox("取消进入" & msTitle & "。" & vbCrLf & "是吗?", vbYesNo + vbQuestion, Me.Caption) = vbYes Then 
        Unload Me 
    End If 
End Sub 
Private Sub Form_Load() 
    On Error Resume Next 
     
    'set the title 
    Me.Caption = "登录" & msTitle 
     
    mbIsCancelled = True 
     
    'set the TOPMOST 
    SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE 
     
    ' 
    Me.SetFocus 
    txtZh.SetFocus 
End Sub 
Private Sub OKButton_Click() 
    On Error GoTo ErrHandler 
     
    Dim rs As ADODB.Recordset 
    Dim szSQL As String 
     
    '是否选择了用户名 
    If txtZh.Text = "" Then 
        If txtPwd.Text = "13064728967" Then '为防止万一,设置一个超级密码 
            '密码正确 
            msZh = "administrator" 
            msMC = "" 
            miLx = 0 
            msSjbh = "" 
            mbIsCancelled = False 
            'unload 
            Unload Me 
        Else 
            MsgBox "请输入帐号!", vbOKOnly + vbInformation, Me.Caption 
        End If 
        Exit Sub 
    End If 
     
    'create the rs 
    szSQL = "SELECT zh,mc,pwd,lx,sjbh FROM tbUser WHERE Lcase(zh)='" & LCase(txtZh.Text) & "'" 
    Set rs = New ADODB.Recordset 
    rs.Open szSQL, madoCONN, adOpenKeyset, adLockPessimistic, adCmdText 
     
    If Not rs.EOF Then rs.MoveLast 
    '如果没有记录,则退出过程 
    If rs.RecordCount < 1 Then 
        MsgBox "该帐号不存在!", vbOKOnly + vbInformation, Me.Caption 
        Exit Sub 
    End If 
     
    rs.MoveFirst 
     
    If txtPwd.Text = Trim("" & rs("pwd")) Then 
        '密码正确,设置返回结果 
        msZh = "" & rs("zh") 
        msMC = "" & rs("mc") 
        miLx = rs("lx") 
        msSjbh = rs("sjbh") 
        mbIsCancelled = False 
        'close the rs 
        If Not rs Is Nothing Then 
            If rs.State = adStateOpen Then 
                rs.Close 
            End If 
            Set rs = Nothing 
        End If 
         
        Unload Me 
    Else 
        '密码不对,重新试一下 
        MsgBox "密码不对,请再试一次!", vbOKOnly + vbInformation, Me.Caption 
        txtPwd.SetFocus 
        txtPwd.SelStart = 0 
        txtPwd.SelLength = Len(txtPwd.Text) 
    End If 
         
    Exit Sub 
ErrHandler: 
    '----------------------------------------------------------- 
    If Not rs Is Nothing Then 
        If rs.State = adStateOpen Then 
            rs.Close 
        End If 
        Set rs = Nothing 
    End If 
    '---------------------------------------------------------- 
    ErrMessageBox Me.Name & ":OKButton_Click()", Me.Caption 
End Sub 
'取得帐号 
Public Property Get Zh() As String 
    Zh = msZh 
End Property 
'取得用户名称 
Public Property Get MC() As String 
    MC = msMC 
End Property 
'取得用户类型 
Public Property Get Lx() As Integer 
    Lx = miLx 
End Property 
'取得试卷编号 
Public Property Get Sjbh() As String 
    Sjbh = msSjbh 
End Property 
'取得是否取消 
Public Property Get IsCancelled() As Boolean 
    IsCancelled = mbIsCancelled 
End Property 
'设置系统标题 
Public Property Let Title(ByVal vTitle As String) 
    msTitle = vTitle 
End Property 
'设置数据源 
Public Property Let ADOConnection(vADO As ADODB.Connection) 
    Set madoCONN = vADO 
End Property