VB+Access学生公寓管理系统 第5页

可。

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single)

Line1.Visible = False

Line2.Visible = False

Line3.Visible = False

Line4.Visible = False

Line5.Visible = False

Line6.Visible = False

Line7.Visible = False

Line8.Visible = False

End Sub

    鼠标按下的时候设置线条的颜色如下:

Private Sub Label3_MouseDown(Button As Integer, Shift As Integer, x As Single, Y As Single)

Line1.BorderColor = &H808080

Line2.BorderColor = &H808080

Line3.BorderColor = &HE0E0E0

Line4.BorderColor = &HE0E0E0

End Sub

    鼠标移动到标签的时候设置线条的颜色如下:

Private Sub Label3_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single)

Line1.BorderColor = &HE0E0E0

Line2.BorderColor = &HE0E0E0

Line3.BorderColor = &H808080

Line4.BorderColor = &H808080

Line1.Visible = True

Line2.Visible = True

Line3.Visible = True

Line4.Visible = True

End Sub

(2) 用户类型判断

    在数据库中建了一人yonghu表。在添加管理人员时有两种默认级别。管理员、普通用户。管理员拥有对数据库操作的一切权限。普通用户只有普通的查看,数据转换等。没有删除等操作功能。前用户成功登录后,会在主窗体的状态栏中显示出当前用户及其用户类型。

主要代码如下:

设置当前控件连接的数据库

Dim provider As String

Dim datasource As String

provider = "provider=Microsoft.jet.oledb.4.0"

datasource = "data source=" & App.Path & "\DB.mdb"

With Adodc1

.Mode = adModeReadWrite

.ConnectionString = provider & ";" & datasource

.CommandType = adCmdTable

.RecordSource = "yonghu"

.Refresh

.Recordset.MoveFirst

End With

对用户进行判断

If Text1.Text = "" Then

MsgBox "请输入用户名!", 48, "提示"

Exit Sub

End If

Adodc1.Recordset.Find "用户='" & Text1.Text & "'"

If Adodc1.Recordset.EOF = False And Text2.Text = Trim(Adodc1.Recordset.Fields("pass")) Then

main.Text1.Text = Adodc1.Recordset.Fields("级别")

main.Text2.Text = Adodc1.Recordset.Fields("用户")

main.Show

Unload Me

Else

Text1.Text = ""

Text2.Text = ""

MsgBox "登录不成功,请重新登录!", 48, "提示"

End If

4.2  程序主界面

程序主界面为本软件的显示的核心部分。一切主要操作及显示都通过这里完成。整个界面主要由五部分组成。菜单部分、工具栏、左侧操作栏、右侧显示栏以及状态栏。

界面效果图如下:

4.2程序主界面

菜单栏的详见附录内容,这里就不提了。左侧操作栏和右侧显示栏会在下面的内容中做介绍,现在只简单介绍一下工具栏和状态栏,以及主窗体的各个事件。

工具栏主要是由coolbar制作而成。由它制做的工具栏的显示效果会更有立体感一些。这里只列出了几个常用的按钮。其中的添加按钮是用来对公寓住宿人员进行添加,修改也是对所住宿人员进行修改,想要进行修改时必须显示所有记录时才可以进行。在这里值得一提的是删除DataGrid的操作,由于不知道它的当前数据源是哪个,所以在删除前要确定它的数据源,也就是它所链接的adodc1的数据源,或者是其它ado控件对它的数据源进行重新绑定后的数据库表,也有可能是经过一个查询后得到的记录。

②它的实现方法如下所示:

Dim o As Adodc

Set o = DataGrid1.datasource

    o.Recordset.Delete

    o.Recordset.Update

这里主要是用到了ado对像的方法。用这个方法得到数据源。

    下面是整个工具栏运行时代码:

Select Case Button.Index

Case 1

sel.Show 1

Case 3

add.Show 1

Case 5

On Error GoTo next2

Dim s As Adodc

Set s = DataGrid1.datasource

If s.RecordSource = "users" Then

edit.Show 1

End If

next2:

Case 7

On Error Resume Next

Dim o As Adodc

Set o = DataGrid1.datasource

    o.Recordset.Delete

    o.Recordset.Update

Case 9

back.Show 1

Case 11

With Adodc1

.Mode = adModeReadWrite

.ConnectionString = provider & ";" & datasource

.CommandType = adCmdTable

.RecordSource = "users" '

.Refresh

End With

Set DataGrid1.datasource = Adodc1

DataGrid1.Refresh

Call dx

Case 13

Unload Me

End Select

状态栏分四个部分。第一个为固定显示当前所用软件名称及作者。其中第二个和第三部分为动态显示的,它会显示出每次用户登录名称及其管理模式。由上图可以看出,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

'设置普通用户模式

If Text1.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

End If

主窗体在程序运行中会遇到不断改变其大小,最小化,最大化,以及用鼠标来改变,这里需要在窗体的Resize事件中添加代码,让程序中用到的各个控件随时可以适应窗体改变后的大小,在这里改变的控件主要有DataGridTreeView系列及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 = "data source=" & App.Path & "\DB.mdb"

With Adodc1

.Mode = adModeReadWrite

.ConnectionString = provider & ";" & datasource

.CommandType = adCmdTable

.RecordSource = "users" '

.Refresh

End With

 

With Adodc2

.Mode = adModeReadWrite

.ConnectionString = provider & ";" & datasource

.CommandType = adCmdTable

.RecordSource = "gongyu"

.Refresh

End With

 

With Adodc3

.Mode = adModeReadWrite

.ConnectionString = provider & ";" & datasource

.CommandType = adCmdTable

.RecordSource = "class"

.Refresh

End With

 

With Adodc4

.Mode = adModeReadWrite

.ConnectionString = provider & ";" & datasource

.CommandType = adCmdTable

.RecordSource = "weisheng"

.Refresh

End With

 

With Adodc5

.Mode = adModeReadWrite

.ConnectionString = provider & ";" & datasource

End With

 

With Adodc6

.Mode = adModeReadWrite

.ConnectionString = provider & ";" & datasource

.CommandType = adCmdTable

.RecordSource = "dengji"

.Refresh

End With

 

With Adodc7

.Mode = adModeReadWrite

.ConnectionString = provider & ";" & datasource

.CommandType = adCmdTable

.RecordSource = "qinshi"

.Refresh

End With

 

With Adodc9

.Mode = adModeReadWrite

.ConnectionString = provider & ";" & datasource

.CommandType = adCmdTable

.RecordSource = "zichan"

.Refresh

End With

treeview部分树形显示的初始化在这里已经做了几个过程,调用即可。

4.3系统设置

4.3.1用户管理

①界面效果图

上一页  [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]  ... 下一页  >> 

Copyright © 2007-2012 www.chuibin.com 六维论文网 版权所有