5.管理员信息表(tOperators),其字段列表如表4-5所示。
表4-5 管理员信息表的结构
序号 1 2 3 4
字段名称 cOperatorID cOperatorName cOperatorPassword cOperatorAddTime 字段说明 管理员编号 管理员姓名 密码 管理员加入时间 类型 文本 文本 文本 时间日期 位数 5 10 6 10 属性 必须非空 必须非空 必须非空 必须非空 备注 18
第五章 编码实现
5.1 程序编码
登陆界面如图5.1所示。
图5.1 登陆界面
程序代码如下:
Function Check_Password(ByVal UserName As String, ByVal UserPassword As String) As Integer On Error GoTo ER2:
If ConnectToServer = True Then Set objRs = New Recordset
StrSql = \cOperatorPassword from tOperators where cOperatorName='\Trim(cboName.Text) & \
GetData StrSql 'Reference function to get data If objRs.EOF Then
Check_Password = 0 'This Operator not exist Else
If txtPassword.Text <> Trim(objRs.Fields(\ Check_Password = 1 ' password error Else
Check_Password = 2 'password ok
CurrentOpname = Trim(cboName.Text)
CurrentOppassword = objRs.Fields(\ 'Here can save a operator grade for expand End If End If
objCon.Close Exit Function ER2:
19
& MsgBox Err.Description Check_Password = 255 End If End Function
Private Sub cmdCancel_Click() Unload Me End End Sub
Private Sub cmdOK_Click() Dim intCheck As Integer
'Static intLogTimes to save user login times Static intLogTimes As Integer
intLogTimes = intLogTimes + 1 'Save login times If intLogTimes > MaxLogTimes Then
'Over allowed login times then list information
MsgBox \ Unload Me Else
intCheck = Check_Password(Trim(txtPassword), Trim(cboName)) Select Case intCheck Case 0
MsgBox \ Case 1
MsgBox \error ,please check your password !\vbInformation + vbOKOnly, \ Case 2
Unload Me
If CurrentOpname = \ MainWin.mnuOp.Visible = True Else
MainWin.mnuOp.Visible = False End If
Load MainWin MainWin.Show End Select
End If End Sub
主界面如图5.2所示。
20
图5.2 程序主界面
程序代码如下:
Option Explicit
Private Sub MDIForm_Activate()
If CurrentOpname = \
StatusBar2.Panels(1).Text = \管理员:\ Toolbar1.Buttons(1).Visible = True Toolbar1.Buttons(2).Visible = True Else
StatusBar2.Panels(1).Text = \操作员:\ Toolbar1.Buttons(1).Visible = False Toolbar1.Buttons(2).Visible = False End If End Sub
Private Sub MDIForm_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbRightButton Then
PopupMenu mnuOperation 'Design popup menu End If End Sub
Private Sub MDIForm_Unload(Cancel As Integer)
CheckConnect 'Reference function to make objcon break if connection is open End Sub
21
Private Sub mnuAbout_Click() frmAbout.Show End Sub
Private Sub mnuBookQuery_Click()
CheckConnect 'Reference function to make objcon break if connection is open Load frmBookQuery frmBookQuery.Show End Sub
Private Sub mnuBookRegist_Click()
CheckConnect 'Reference function to make objcon break if connection is open Load frmBookReg frmBookReg.Show End Sub
Private Sub mnuBorrowQuery_Click()
CheckConnect 'Reference function to make objcon break if connection is open Load frmReadQuery frmReadQuery.Show End Sub
Private Sub mnuExit_Click()
CheckConnect 'Reference function to make objcon break if connection is open Unload Me End End Sub
Private Sub mnuReLogin_Click()
CheckConnect 'Reference function to make objcon break if connection is open Unload Me Load frmLogin frmLogin.Show End Sub
Private Sub mnuVipQuery_Click()
CheckConnect 'Reference function to make objcon break if connection is open Load frmVipQuery frmVipQuery.Show End Sub
Private Sub mnuVipRegist_Click()
CheckConnect 'Reference function to make objcon break if connection is open Load frmVipReg frmVipReg.Show
22