End Sub
Private Sub munReadRegist_Click()
CheckConnect 'Reference function to make objcon break if connection is open Load frmReadRegist frmReadRegist.Show End Sub
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button) Select Case Button.Key Case \
CheckConnect 'Reference function to make objcon break if connection is open Load frmAdmin frmAdmin.Show Case \
CheckConnect 'Reference function to make objcon break if connection is open Load frmVipReg frmVipReg.Show Case \
CheckConnect 'Reference function to make objcon break if connection is open Load frmVipQuery frmVipQuery.Show Case \
CheckConnect 'Reference function to make objcon break if connection is open Load frmBookReg frmBookReg.Show Case \
CheckConnect 'Reference function to make objcon break if connection is open Load frmBookQuery frmBookQuery.Show Case \
CheckConnect 'Reference function to make objcon break if connection is open Load frmReadRegist frmReadRegist.Show Case \
CheckConnect 'Reference function to make objcon break if connection is open Load frmReadQuery frmReadQuery.Show End Select End Sub
操作员管理界面如图5.3所示。
23
图5.3 操作员管理界面
代码如下:
Option Explicit Sub SetTextEmpty()
'This function is set all text to empty txtOpID.Text = \ txtOpName.Text = \ txtOpPwd.Text = \ cboOpGrade.Text = \ txtOpAddTime.Text = \End Sub
Sub RefreshOperator()
'This function is to Refresh text
txtOpID.Text = objRs.Fields(0).Value txtOpName.Text = objRs.Fields(1).Value txtOpPwd.Text = objRs.Fields(2).Value cboOpGrade.Text = objRs.Fields(3).Value ' txtOpAddTime.Text = objRs.Fields(4).Value End Sub
Private Sub cmdAdd_Click()
24
txtOpID.Enabled = True 'You don't change datagrid untill you add data finish dgdOp.Enabled = False
If cmdAdd.Caption = \添加\ cmdAdd.Caption = \确定\
SetTextEmpty ' reference settextempty founction to set empty cmdDel.Enabled = False cmdModify.Enabled = False cmdRefresh.Enabled = False txtOpID.SetFocus Else
If Trim(txtOpName.Text) = \
MsgBox \name must not null ,please input operator name !\vbInformation + vbOKOnly
txtOpName.SetFocus Exit Sub
ElseIf Trim(txtOpID.Text) = \
MsgBox \ID must not null ,please input operator ID !\vbInformation + vbOKOnly
txtOpID.SetFocus Exit Sub
ElseIf Trim(txtOpPwd.Text) = \
MsgBox \password must not null ,please input operator password !\vbInformation + vbOKOnly
txtOpPwd.SetFocus Exit Sub Else
With objRs
checkAddNew = True
.Filter = \ If .RecordCount > 0 Then
MsgBox \ txtOpID.Text = \ txtOpID.SetFocus
.Filter = \
cmdRefresh.Value = True 'To executer refresh once checkAddNew = False cmdDel.Enabled = True cmdModify.Enabled = True cmdAdd.Caption = \添加(&A)\ txtOpID.Enabled = False cmdRefresh.Enabled = True dgdOp.Enabled = True
25
checkAddNew = False Exit Sub End If
checkAddNew = True .AddNew
.Fields(0).Value = Trim(txtOpID.Text) .Fields(1).Value = Trim(txtOpName.Text) .Fields(2).Value = Trim(txtOpPwd.Text) .Fields(3).Value = Trim(cboOpGrade.Text) .Fields(4).Value = Trim(txtOpAddTime.Text) .Update
MsgBox \ .Filter = \
cmdRefresh.Value = True 'To executer refresh once End With
checkAddNew = False
'----There will reference a founction to set empty txtOpID.Enabled = False cmdDel.Enabled = True cmdModify.Enabled = True cmdRefresh.Enabled = True cmdAdd.Caption = \添加\
dgdOp.Enabled = True 'You can use datagrid after add finish End If End If End Sub
Private Sub cmdDel_Click()
If Empty_Check = True Then Exit Sub 'Reference function to check if your database is null If Not objRs.EOF And objRs.RecordCount > 0 Then
If MsgBox(\= vbYes Then
objRs.Delete End If End If End Sub
Private Sub cmdModify_Click()
If Empty_Check = True Then Exit Sub 'Reference function to check if your database is null dgdOp.Enabled = False
If txtOpID.Text <> objRs.Fields(0).Value Then Exit Sub 'To check operator ID If cmdModify.Caption = \修改\ cmdModify.Caption = \确定\ cmdDel.Enabled = False
26
cmdAdd.Enabled = False Else
With objRs
.Fields(0).Value = Trim(txtOpID.Text) .Fields(1).Value = Trim(txtOpName.Text) .Fields(2).Value = Trim(txtOpPwd.Text) .Fields(3).Value = Trim(cboOpGrade.Text) .Update End With
cmdModify.Caption = \修改\ cmdDel.Enabled = True cmdAdd.Enabled = True dgdOp.Enabled = True End If End Sub
Private Sub cmdExit_Click() Unload Me End Sub
Private Sub cmdRefresh_Click()
RefreshOperator 'Reference function is to Refresh text End Sub
Private Sub dgdOp_RowColChange(LastRow As Variant, ByVal LastCol As Integer) If checkAddNew = True Then Exit Sub cmdRefresh.Value = True End Sub
Private Sub Form_Activate()
FormMiddle frmAdmin 'Reference function to make form in MDIForm'mddile cboOpGrade.ListIndex = 1
If ConnectToServer = True Then
Set objRs = New ADODB.Recordset StrSql = \
GetData StrSql 'Reference function to get data Set dgdOp.DataSource = objRs cmdRefresh.Value = True End If End Sub
Private Sub txtOpAddTime_KeyPress(KeyAscii As Integer) 'CheckInputNum 'Reference function to check input
If Not (KeyAscii >= vbKey0 And KeyAscii <= vbKey9 _ Or KeyAscii = vbKeyBack _ Or KeyAscii = Asc(\
27