操作流程:
在窗体加载时直接显示数据。
使用数据库表:
worklog_info(存放用户上下机记录)
具体代码如下:
Option Explicit
Dim H As Single '定义窗体高的变量 '定义窗体高的变量
Dim W As Single '定义窗体高的变量 '定义窗体宽的变量
Private Sub cmdOFF_Click()
Unload frmDutyTeacher
End Sub
Private Sub Form_Load()
H = Me.Height
W = Me.Width
With MSHFlexGrid
.Rows = 1
.TextMatrix(0, 0) = "记录号"
.TextMatrix(0, 1) = "教师"
.TextMatrix(0, 2) = "级别"
.TextMatrix(0, 3) = "登录日期"
.TextMatrix(0, 4) = "登录时间"
.TextMatrix(0, 5) = "机器名"
End With
End Sub
Private Sub Form_Resize()
'对worklog_info表操作
Dim mrcworklog As ADODB.Recordset '用于存放记录集
Dim worklogSQL As String '用于存放SQL语句
Dim worklogMsgText As String '用于存放返回信息
worklogSQL = "select * from worklog_info where status='True'"
Set mrcworklog = ExecuteSQL(worklogSQL, worklogMsgText)
'查看是否存在WORKLOG的记录
If mrcworklog.EOF = True Then
MsgBox "没有值班教师!", vbOKOnly + vbInformation, "提示"
Else
With MSHFlexGrid
Do While mrcworklog.EOF = False
.Rows = .Rows + 1
.CellAlignment = 4
.TextMatrix(.Rows - 1, 0) = Trim(mrcworklog.Fields(0))
.TextMatrix(.Rows - 1, 1) = Trim(mrcworklog.Fields(1))
.TextMatrix(.Rows - 1, 2) = Trim(mrcworklog.Fields(2))
.TextMatrix(.Rows - 1, 3) = Trim(mrcworklog.Fields(3))
.TextMatrix(.Rows - 1, 4) = Trim(mrcworklog.Fields(4))
.TextMatrix(.Rows - 1, 5) = Trim(mrcworklog.Fields(7))
mrcworklog.MoveNext
Loop
End With
mrcworklog.Close
End If
Me.Height = H
Me.Width = W
Me.PaintPicture Me.Picture, 0, 0, Me.ScaleWidth, Me.ScaleHeight '实现背景图随窗体变大而改变
End Sub
优化方面:
Dim H As Single '定义窗体高的变量 '定义窗体高的变量
Dim W As Single '定义窗体高的变量 '定义窗体宽的变量
Private Sub Form_Load()
H = Me.Height
W = Me.Width
End Sub
Private Sub Form_Resize()
Me.Height = H
Me.Width = W
Me.PaintPicture Me.Picture, 0, 0, Me.ScaleWidth, Me.ScaleHeight '实现背景图随窗体变大而改变
End Sub