📄 frmquerydevice.frm
字号:
VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "msflxgrd.ocx"
Begin VB.Form frmQueryDevice
Caption = "设备查询"
ClientHeight = 4680
ClientLeft = 60
ClientTop = 345
ClientWidth = 7080
LinkTopic = "Form1"
ScaleHeight = 4680
ScaleWidth = 7080
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton cmdCancel
Caption = "返回(&C)"
Height = 375
Left = 3480
TabIndex = 10
Top = 1560
Width = 1455
End
Begin VB.CommandButton cmdQuery
Caption = "查询(&Q)"
Height = 375
Left = 1680
TabIndex = 9
Top = 1560
Width = 1455
End
Begin MSFlexGridLib.MSFlexGrid fgDevices
Height = 2535
Left = 120
TabIndex = 1
Top = 2040
Width = 6855
_ExtentX = 12091
_ExtentY = 4471
_Version = 393216
End
Begin VB.Frame Frame1
Caption = "查询方式"
Height = 1335
Left = 120
TabIndex = 0
Top = 120
Width = 6855
Begin VB.ComboBox cboStatus
Height = 315
Left = 5040
TabIndex = 8
Text = "Combo2"
Top = 360
Width = 1575
End
Begin VB.OptionButton optDeviceQuery
Caption = "按报废状态"
Height = 375
Index = 2
Left = 3720
TabIndex = 7
Top = 360
Width = 1335
End
Begin VB.OptionButton optDeviceQuery
Caption = "查询全部设备"
Height = 255
Index = 3
Left = 3720
TabIndex = 6
Top = 840
Width = 1455
End
Begin VB.TextBox txtName
Height = 375
Left = 1560
TabIndex = 5
Text = "Text1"
Top = 360
Width = 1575
End
Begin VB.ComboBox cboProducer
Height = 315
Left = 1560
TabIndex = 4
Text = "Combo1"
Top = 840
Width = 1575
End
Begin VB.OptionButton optDeviceQuery
Caption = "按生产厂家"
Height = 255
Index = 1
Left = 240
TabIndex = 3
Top = 840
Width = 1575
End
Begin VB.OptionButton optDeviceQuery
Caption = "按设备名称"
Height = 375
Index = 0
Left = 240
TabIndex = 2
Top = 360
Width = 1695
End
End
End
Attribute VB_Name = "frmQueryDevice"
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
Private Sub cboProducer_Click()
optDeviceQuery(1).Value = True
End Sub
Private Sub cboStatus_Click()
optDeviceQuery(2).Value = True
End Sub
Private Sub cmdCancel_Click()
Unload Me
End Sub
Sub initProducer()
'方法的作用:将设备表中的所有厂商名称显示到列表框中
Dim rstProducer As ADODB.Recordset
'从数据库中读取所有厂商名称并添加到组合列表框中
sqlStr = "select distinct producer from devices"
Set rstProducer = ExecuteSQL(sqlStr, msgText)
cboProducer.Clear
If Not rstProducer.EOF Then
Do While Not rstProducer.EOF
cboProducer.AddItem Trim(rstProducer.Fields(0))
rstProducer.MoveNext
Loop
cboProducer.ListIndex = 0
Else
MsgBox "没有找到相关信息,请添加!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
rstProducer.Close
End Sub
Sub initStatus()
cboStatus.Clear
cboStatus.AddItem "现已报废"
cboStatus.AddItem "工作正常"
End Sub
Private Sub cmdQuery_Click()
queryDevices
End Sub
Private Sub Form_Load()
'窗体居中显示
Me.Top = (Screen.Height - Me.Height) \ 2
Me.Left = (Screen.Width - Me.Width) \ 2
initProducer
initStatus
txtName = ""
optDeviceQuery(0).Value = True
End Sub
Private Sub txtName_GotFocus()
optDeviceQuery(0).Value = True
End Sub
Sub queryDevices()
Dim rs As ADODB.Recordset
Dim i As Integer
Dim j As Integer
If optDeviceQuery(0).Value = True Then
If txtName = "" Then
MsgBox "设备名称不能为空,请输入查询条件!!"
Exit Sub
End If
sqlStr = "select * from devices where" _
& " deviceName LIKE '%" & txtName.Text & "%'"
End If
If optDeviceQuery(1).Value = True Then
sqlStr = "select * from devices where" _
& " producer='" & cboProducer.Text & "'"
End If
If optDeviceQuery(2).Value = True Then
If cboStatus.Text = "工作正常" Then
sqlStr = "select * from devices where deserted=false"
Else
sqlStr = "select * from devices where deserted=true"
End If
End If
If optDeviceQuery(3).Value = True Then
sqlStr = "select * from devices"
End If
Set rs = ExecuteSQL(sqlStr, msgText)
If rs.RecordCount = 0 Then
MsgBox "没有查找满足条件的数据!", vbExclamation, "提示"
fgDevices.Rows = 1
Else
fgDevices.Rows = rs.RecordCount + 1
fgDevices.Cols = 7
'设定行高
For i = 0 To fgDevices.Rows - 1
fgDevices.RowHeight(i) = 280
Next i
'设定列的属性
fgDevices.Row = 0
For i = 0 To fgDevices.Cols - 1
fgDevices.Col = i '指定当前列为第i列
fgDevices.FixedAlignment(i) = 4 '每列内容居中显示
Select Case i
Case 0
fgDevices.ColWidth(i) = 600 '设定列宽
fgDevices.Text = "序号"
Case 1
fgDevices.ColWidth(i) = 1000 '设定列宽
fgDevices.Text = "设备编号"
Case 2
fgDevices.ColWidth(i) = 1500 '设定列宽
fgDevices.Text = "设备名称"
Case 3
fgDevices.ColWidth(i) = 1500 '设定列宽
fgDevices.Text = "生产厂家"
Case 4
fgDevices.ColWidth(i) = 1000 '设定列宽
fgDevices.Text = "购买日期"
Case 5
fgDevices.ColWidth(i) = 600 '设定列宽
fgDevices.Text = "价格"
Case 6
fgDevices.ColWidth(i) = 800 '设定列宽
fgDevices.Text = "设备状态"
End Select
Next i
'rs.MoveFirst
i = 1
While (Not rs.EOF)
fgDevices.Row = i
For j = 0 To fgDevices.Cols - 1
fgDevices.Col = j '设置当前为列为第j列
fgDevices.CellAlignment = 4 '每列内容居中显示
Select Case j
Case 0
fgDevices.Text = "" & i
Case 1
fgDevices.Text = rs.Fields("deviceNo")
Case 2
fgDevices.Text = rs.Fields("deviceName")
Case 3
fgDevices.Text = rs.Fields("producer")
Case 4
fgDevices.Text = rs.Fields("buydate")
Case 5
fgDevices.Text = rs.Fields("price")
Case 6
If rs.Fields("deserted") = False Then
fgDevices.Text = "工作正常"
Else
fgDevices.Text = "已报废"
End If
End Select
Next j
rs.MoveNext
i = i + 1
Wend
End If
rs.Close
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -