现方法如下所示:
DimoAsAdodc
Seto=DataGrid1.datasource
o.Recordset.Delete
o.Recordset.Update
这里主要是用到了ado对像的方法。用这个方法得到数据源。
下面是整个工具栏运行时代码:
SelectCaseButton.Index
Case1
sel.Show1
Case3
add.Show1
Case5
GoTonext2
DimsAsAdodc
Sets=DataGrid1.datasource
Ifs.RecordSource="users"Then
edit.Show1
EndIf
next2:
Case7
ResumeNext
DimoAsAdodc
Seto=DataGrid1.datasource
o.Recordset.Delete
o.Recordset.Update
Case9
back.Show1
Case11
WithAdodc1
.Mode=adModeReadWrite
.ConnectionString=provider&";"&datasource
.CommandType=adCmdTable
.RecordSource="users"'
.Refresh
EndWith
SetDataGrid1.datasource=Adodc1
DataGrid1.Refresh
Calldx
Case13
UnloadMe
EndSelect
状态栏分四个部分。第一个为固定显示当前所用软件名称及作者。其中第二个和第三部分为动态显示的,它会显示出每次用户登录名称及其管理模式。由上图可以看出,lf为本软件管理员。第四部分为日期与时间的显示。其中第三部分的代码实现如下:
main.Text1.Text=Adodc1.Recordset.Fields("级别")
main.Text2.Text=Adodc1.Recordset.Fields("用户")
StatusBar1.Panels(2).Text="当前用户:"&Text2.Text
StatusBar1.Panels(3).Text="用户模式:"&Text1.Text
StatusBar1.Panels(4).Text=Date&""&Time
'设置普通用户模式
IfText1.Text="普通用户"Then
yhgl.Visible=False
g1.Visible=False
jlsc.Visible=False
gysz.Visible=False
Toolbar1.Buttons(5).Visible=False
Toolbar1.Buttons(6).Visible=False
Toolbar1.Buttons(7).Visible=False
Toolbar1.Buttons(8).Visible=False
EndIf
主窗体在程序运行中会遇到不断改变其大小,最小化,最大化,以及用鼠标来改变,这里需要在窗体的Resize事件中添加代码,让程序中用到的各个控件随时可以适应窗体改变后的大小,在这里改变的控件主要有DataGrid、TreeView系列及Frame控件、StatusBar。下面就是设置它们大小的程序代码:
DataGrid1.Width=main.Width-SSTab1.Width
DataGrid1.Height=main.Height-StatusBar1.Height-CoolBar1.Height-750
SSTab1.Height=main.Height-StatusBar1.Height-CoolBar1.Height-750
Frame1.Height=main.Height-StatusBar1.Height-CoolBar1.Height-1200
Frame2.Height=main.Height-StatusBar1.Height-CoolBar1.Height-1200
Frame3.Height=main.Height-StatusBar1.Height-CoolBar1.Height-1200
TreeView1.Height=main.Height-StatusBar1.Height-CoolBar1.Height-1500
TreeView2.Height=main.Height-StatusBar1.Height-CoolBar1.Height-1500
TreeView3.Height=main.Height-StatusBar1.Height-CoolBar1.Height-1500
Y=main.Width
x=(Y-z)/4
StatusBar1.Panels(1).Width=u+x
StatusBar1.Panels(2).Width=v+x
StatusBar1.Panels(3).Width=w+x
StatusBar1.Panels(4).Width=m+x
这个软件的主要部分都在这里运行、查看,所以在主窗体的load事件里要把所用的到的东西都要加载进来,例如所在程序运行时所用到的表,左侧treeview部分树形显示的初始化。在这里几乎用到了所有的表,如下所示:
provider="provider=Microsoft.jet.oledb.4.0"
datasource="datasource="&App.Path&"\DB.mdb"
WithAdodc1
.Mode=adModeReadWrite
.ConnectionString=provider&";"&datasource
.CommandType=adCmdTable
.RecordSource="users"'
.Refresh
EndWith
WithAdodc2
.Mode=adModeReadWrite
.ConnectionString=provider&";"&datasource
.CommandType=adCmdTable
.RecordSource="gongyu"
.Refresh
EndWith
WithAdodc3
.Mode=adModeReadWrite
.ConnectionString=provider&";"&datasource
.CommandType=adCmdTable
.RecordSource="class"
.Refresh
EndWith
WithAdodc4
.Mode=adModeReadWrite
.ConnectionString=provider&";"&datasource
.CommandType=adCmdTable
.RecordSource="weisheng"
.Refresh
EndWith
WithAdodc5
.Mode=adModeReadWrite
.ConnectionString=provider&";"&datasource
EndWith
WithAdodc6
.Mode=adModeReadWrite
.ConnectionString=provider&";"&datasource
.CommandType=adCmdTable
.RecordSource="dengji"
.Refresh
EndWith
WithAdodc7
.Mode=adModeReadWrite
.ConnectionString=provider&";"&datasource
.CommandType=adCmdTable
.RecordSource="qinshi"
.Refresh
EndWith
WithAdodc9
.Mode=adModeReadWrite
.ConnectionString=provider&";"&datasource
.CommandType=adCmdTable
.RecordSource="zichan"
.Refresh
EndWith
treeview部分树形显示的初始化在这里已经做了几个过程,调用即可。
4.3系统设置
4.3.1用户管理
①界面效果图
图4.3用户管理
②界面制作与实现方法
这个界面总体来说各个控件比较简单,但是作为一个添加删除管理员的操作,它已经连接到了数据库,与数据库的yonghu表相联。各个控件也与数据库中表的字段绑定。
在窗体初始化的时候要判断当前数据库表中是否有记录,如果没有记录那么有些按钮将会被设置成为失效状态,否则会出现错误。设置代码如下:
DimproviderAsString
DimdatasourceAsString
provider="provider=Microsoft.jet.oledb.4.0"
datasource="datasource="&App.Path&"\DB.mdb"
WithAdodc1
.Mode=adModeReadWrite
.ConnectionString=provider&";"&datasource
.CommandType=adCmdTable
.RecordSource="yonghu"
.Refresh
EndWith
Option1.Enabled=False
Option2.Enabled=False
IfAdodc1.Recordset.RecordCount=0Then
Command2.Enabled=False
Command3.Enabled=False
Command5.Enabled=False
Command6.Enabled=False
EndIf
Text2.Text=Text3.Text
上一条与下一条的功能一目了然,它们可以对当前表进行上一条记录或下一条记录依次查看。当找到记录后,可以对其进行相对的删除、修改等操作。上一条记录与下一条的记录在查看时有一个判断。当表中记录移到最前面(BOF)或最后面(EOF)时,会把上一条或下一条其中的一个按钮的enable属性设置为true。即不可以前查看或向后查看。
上一条与下一条主要代码如下:
Adodc1.Recordset.MovePrevious'移动记录
Command6.Enabled=True
IfAdodc1.Recordset.BOFThen
Adodc1.Recordset.MoveFirst
Command5.Enabled=False
EndIf
Adodc1.Recordset.MoveNext'移动记录
Command5.Enabled=True
IfAdodc1.Recordset.EOFThen
Adodc1.Recordset.MoveLast
Command6.Enabled=False
EndIf
添加用户可以添加使用该管理软件的用户。添加的时候可以选择所添加人物的级别。软件默认为两个级别:管理员、普通用户。管理员拥有对此软件管理操作等一切的权力。普通用户,只有普通的查看、查询、备份、添加等权力。没有对记录删除等权力。在添加用户时你可以选择一个且必须选择一个。然后输入此用户的用户名和密码即可!
添加用户主要代码:
IfCommand1.Caption="添加"Then
Command2.Enabled=False
Command5.Enabled=False
Command6.Enabled=False
Command1.Caption="确定"
Command3.Caption="取消"
Adod
上一篇:
餐饮酒店管理系统(论文和程序)
下一篇:
试析影响公路路面平整度的因素及应采取的施工措施