📄 frmlistemployee.frm
字号:
VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "Msflxgrd.ocx"
Begin VB.Form frmListEmployee
Caption = "员工情况"
ClientHeight = 4200
ClientLeft = 60
ClientTop = 345
ClientWidth = 8415
LinkTopic = "Form1"
ScaleHeight = 4200
ScaleWidth = 8415
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton cmdCancel
Caption = "返回(&N)"
Height = 375
Left = 4200
TabIndex = 11
Top = 1440
Width = 1335
End
Begin VB.CommandButton cmdOK
Caption = "查询(&Y)"
Height = 375
Left = 2400
TabIndex = 10
Top = 1440
Width = 1335
End
Begin VB.Frame Frame1
Caption = "查询方式"
Height = 1215
Left = 120
TabIndex = 2
Top = 120
Width = 8175
Begin VB.ComboBox cboTitle
Height = 315
Left = 5520
TabIndex = 9
Text = "Combo3"
Top = 720
Width = 2175
End
Begin VB.OptionButton optQuery
Caption = "按职称查询"
Height = 255
Index = 3
Left = 4080
TabIndex = 8
Top = 720
Width = 1335
End
Begin VB.ComboBox cboDegree
Height = 315
Left = 5520
TabIndex = 7
Text = "Combo2"
Top = 360
Width = 2175
End
Begin VB.OptionButton optQuery
Caption = "按学历查询"
Height = 255
Index = 2
Left = 4080
TabIndex = 6
Top = 360
Width = 1335
End
Begin VB.ComboBox cboDept
Height = 315
Left = 1680
TabIndex = 5
Text = "Combo1"
Top = 720
Width = 1695
End
Begin VB.OptionButton optQuery
Caption = "按部门查询"
Height = 255
Index = 1
Left = 360
TabIndex = 4
Top = 720
Width = 1335
End
Begin VB.OptionButton optQuery
Caption = "全部员工"
Height = 255
Index = 0
Left = 360
TabIndex = 3
Top = 360
Width = 1335
End
End
Begin MSFlexGridLib.MSFlexGrid fgEmployee
Height = 1695
Left = 120
TabIndex = 1
Top = 2400
Width = 8175
_ExtentX = 14420
_ExtentY = 2990
_Version = 393216
End
Begin VB.Line Line1
BorderColor = &H80000005&
X1 = 120
X2 = 8280
Y1 = 1920
Y2 = 1920
End
Begin VB.Label Label1
Caption = "员工基本情况查询结果:"
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 3000
TabIndex = 0
Top = 2040
Width = 2175
End
End
Attribute VB_Name = "frmListEmployee"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Public sqlStr As String
Public msgText As String
Sub queryAllEmployee()
Dim rs As ADODB.Recordset
Dim i As Integer
Dim j As Integer
If optQuery(0).Value = True Then
sqlStr = "select * from employeeBasic"
End If
If optQuery(1).Value = True Then
sqlStr = "select * from employeeBasic where department='" & cboDept.Text & "'"
End If
If optQuery(2).Value = True Then
sqlStr = "select * from employeeBasic where degree='" & cboDegree.Text & "'"
End If
If optQuery(3).Value = True Then
sqlStr = "select * from employeeBasic where title='" & cboTitle.Text & "'"
End If
Set rs = ExecuteSQL(sqlStr, msgText)
If rs.RecordCount = 0 Then
MsgBox "没有查找满足条件的数据!", vbExclamation, "提示"
fgEmployee.Rows = 1
Else
fgEmployee.Rows = rs.RecordCount + 1
fgEmployee.Cols = 10
'设定行高
For i = 0 To fgEmployee.Rows - 1
fgEmployee.RowHeight(i) = 280
Next i
'设定列的属性
fgEmployee.Row = 0
For i = 0 To fgEmployee.Cols - 1
fgEmployee.Col = i '指定当前列为第i列
fgEmployee.FixedAlignment(i) = 4 '每列内容居中显示
Select Case i
Case 0
fgEmployee.ColWidth(i) = 1000 '设定列宽
fgEmployee.Text = "编号"
Case 1
fgEmployee.ColWidth(i) = 720 '设定列宽
fgEmployee.Text = "姓名"
Case 2
fgEmployee.ColWidth(i) = 1000 '设定列宽
fgEmployee.Text = "性别"
Case 3
fgEmployee.ColWidth(i) = 1000 '设定列宽
fgEmployee.Text = "出生日期"
Case 4
fgEmployee.ColWidth(i) = 1000 '设定列宽
fgEmployee.Text = "职称"
Case 5
fgEmployee.ColWidth(i) = 1000 '设定列宽
fgEmployee.Text = "入职日期"
Case 6
fgEmployee.ColWidth(i) = 1000 '设定列宽
fgEmployee.Text = "所属部门"
Case 7
fgEmployee.ColWidth(i) = 1000 '设定列宽
fgEmployee.Text = "学历"
End Select
Next i
'rs.MoveFirst
i = 1
While (Not rs.EOF)
fgEmployee.Row = i
For j = 0 To fgEmployee.Cols - 1
fgEmployee.Col = j '设置当前为列为第j列
fgEmployee.CellAlignment = 4 '每列内容居中显示
Select Case j
Case 0
fgEmployee.Text = "" & rs.Fields("employeeNo")
Case 1
fgEmployee.Text = rs.Fields("name")
Case 2
fgEmployee.Text = rs.Fields("sex")
Case 3
fgEmployee.Text = rs.Fields("birthdate")
Case 4
fgEmployee.Text = rs.Fields("title")
Case 5
fgEmployee.Text = rs.Fields("dateStart")
Case 6
fgEmployee.Text = rs.Fields("department")
Case 7
fgEmployee.Text = rs.Fields("degree")
End Select
Next j
rs.MoveNext
i = i + 1
Wend
End If
rs.Close
End Sub
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub cmdOK_Click()
queryAllEmployee
End Sub
Private Sub Form_Load()
initDept
initDegree
initTitle
optQuery(0).Value = True
End Sub
Sub initDept()
Dim rstDept As ADODB.Recordset
'从数据库中读取所有部门名称并添加到组合列表框中
sqlStr = "select departName from department"
Set rstDept = ExecuteSQL(sqlStr, msgText)
cboDept.Clear
If Not rstDept.EOF Then
Do While Not rstDept.EOF
cboDept.AddItem Trim(rstDept.Fields(0))
rstDept.MoveNext
Loop
cboDept.ListIndex = 0
Else
MsgBox "没有部门信息,请添加门!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
rstDept.Close
End Sub
Sub initTitle()
Dim rstTitle As ADODB.Recordset
'从数据库中读取所有职称类型并添加到组合列表框中
sqlStr = "select DISTINCT title from employeeBasic"
Set rstTitle = ExecuteSQL(sqlStr, msgText)
cboTitle.Clear
If Not rstTitle.EOF Then
Do While Not rstTitle.EOF
cboTitle.AddItem Trim(rstTitle.Fields(0))
rstTitle.MoveNext
Loop
cboTitle.ListIndex = 0
Else
MsgBox "没有职称相关信息,请添加!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
rstTitle.Close
End Sub
Dim rstDegree As ADODB.Recordset
'从数据库中读取所有学历名称并添加到组合列表框中
sqlStr = "select DISTINCT degree from employeeBasic"
Set rstDegree = ExecuteSQL(sqlStr, msgText)
cboDegree.Clear
If Not rstDegree.EOF Then
Do While Not rstDegree.EOF
cboDegree.AddItem Trim(rstDegree.Fields(0))
rstDegree.MoveNext
Loop
cboDegree.ListIndex = 0
Else
MsgBox "没有学历相关信息,请添加!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
rstDegree.Close
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -