5.4.13 系统用户设置业务
系统用户设置业务仅有管理员可操作,位于系统菜单“参数设置”中。该菜单由登录功能控制,仅有以管理员身份登录的时候菜单才可用。系统菜单“参数设置”的其余两项功能代码由“frmMain”主窗体实现。系统用户设置实际上就是维护数据库中的“Users”表。实现方法与“图书基本信息管理”功能类似。
窗体设计与代码介绍如下:
图5-30 系统用户信息管理子窗体设计1
图5-31 系统用户信息管理子窗体设计2
代码5-16 系统用户设置功能代码
′****************************************************************************
Dim addnewflag As Boolean
′窗体加载
Private Sub Form_Load()
′设置窗体中各控件位置等信息
lblInfo.Left=Me.ScaleLeft
lblInfo.Top=Me.ScaleTop
lblInfo.Width=Screen.Width
sstabUserInfo.Top=lblInfo.Top+450
sstabUserInfo.Left=70
sstabUserInfo.Width=Screen.Width-200
sstabUserInfo.Height=Screen.Height-2650
DataGrid1.Top=lblInfo.Top+500
DataGrid1.Left=100
DataGrid1.Width=Screen.Width-550
DataGrid1.Height=Screen.Height-3300
DataGrid1.Visible=False
Set DataGrid1.DataSource=rsUserInfo ′配置数据源
DataGrid1.ReBind
Frame2.Left=(Screen.Width-Frame2.Width)/2
Call display
End Sub
Private Sub cmdFirst_Click()
On Error Resume Next
rsUserInfo.MoveFirst
Call display
End Sub
Private Sub cmdLast_Click()
On Error Resume Next
rsUserInfo.MoveLast
Call display
End Sub
Private Sub cmdNext_Click()
On Error Resume Next
rsUserInfo.MoveNext
If rsUserInfo.EOF Then
rsUserInfo.MoveLast
MsgBox″最后一条记录″,vbInformation,″最后一条记录″
Else
Call display
End If
End Sub
Private Sub cmdPrevious_Click()
On Error Resume Next
rsUserInfo.MovePrevious
If rsUserInfo.BOF Then
rsUserInfo.MoveFirst
MsgBox″已是第一条记录″,vbInformation,″已是第一条记录″
Else
Call display
End If
End Sub
′“取消”按钮
Private Sub cmdCancel_Click()
cmdAddNew.Enabled=True
cmdDel.Enabled=True
cmdFirst.Enabled=True
cmdLast.Enabled=True
cmdPrevious.Enabled=True
cmdNext.Enabled=True
cmdCancel.Enabled=False
rsUserInfo.CancelUpdate
rsUserInfo.MoveFirst
Call display
End Sub
′添加记录
Private Sub cmdAddNew_Click()
On Error Resume Next
Call clear
Dim i As Integer
addnewflag=True
cmdAddNew.Enabled=False
cmdCancel.Enabled=True
cmdDel.Enabled=False
cmdFirst.Enabled=False
cmdLast.Enabled=False
cmdPrevious.Enabled=False
cmdNext.Enabled=False
rsUserInfo.AddNew
txtUserId.SetFocus
End Sub
′删除记录
Private Sub cmdDel_click()
On Error Resume Next
If MsgBox(″确认删除么?″,vbOKCancel+vbExclamation,″删除记录″)=vbOK Then
rsUserInfo.Delete
rsUserInfo.MoveNext
If rsUserInfo.EOF Then
rsUserInfo.MoveLast
MsgBox″最后一条记录″
End If
Call display
End If
End Sub
′保存记录
Private Sub cmdsave_click()
On Error Resume Next
If txtUserId.Text=″″Or txtUserName.Text=″″Then
MsgBox″保存错误!!!数据添加失败!″,vbCritical,″添加全部数据″
txtUserId.SetFocus
Exit Sub
End If
Call assign
rsUserInfo.Save
MsgBox″保存成功″,vbInformation,″已保存成功″
cmdDel.Enabled=True
cmdFirst.Enabled=True
cmdLast.Enabled=True
cmdPrevious.Enabled=True
cmdNext.Enabled=True
cmdAddNew.Enabled=True
cmdCancel.Enabled=False
Exit Sub
End Sub
′clear函数定义
Private Sub clear()
txtUserId.Text=″″
txtUserName.Text=″″
End Sub
′Display函数定义
Private Sub display()
cmdCancel.Enabled=False
txtUserId.Text=rsUserInfo(0)&″″
txtUserName.Text=rsUserInfo(1)&″″
End Sub
′将控件中的数据添加到记录集对应的列
Private Sub assign()
If addnewflag=True Then
rsUserInfo(0)=Trim$(txtUserId.Text)
rsUserInfo(1)=Trim$(txtUserName.Text)
addnewflag=False
Else
rsUserInfo(0)=Trim$(txtUserId.Text)
rsUserInfo(1)=Trim$(txtUserName.Text)
End If
End Sub
′选项卡点击使数据表在对应的选项卡中显示
′注意将选项卡控件的名字修改与本事件匹配
Private Sub sstabUserInfo_Click(PreviousTab As Integer)I
If PreviousTab=0Then
DataGrid1.Visible=True
Else
DataGrid1.Visible=False
End If
End Sub
免责声明:以上内容源自网络,版权归原作者所有,如有侵犯您的原创版权请告知,我们将尽快删除相关内容。