📄 frmqueryproduct.frm
字号:
VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "Msflxgrd.ocx"
Begin VB.Form frmQueryProduct
Caption = "产品查询"
ClientHeight = 2865
ClientLeft = 60
ClientTop = 345
ClientWidth = 5040
LinkTopic = "Form1"
ScaleHeight = 2865
ScaleWidth = 5040
StartUpPosition = 3 'Windows Default
Begin MSFlexGridLib.MSFlexGrid fgProducts
Height = 1215
Left = 120
TabIndex = 7
Top = 1560
Width = 4815
_ExtentX = 8493
_ExtentY = 2143
_Version = 393216
End
Begin VB.Frame Frame1
Caption = "查询方式"
Height = 1335
Left = 120
TabIndex = 0
Top = 120
Width = 4815
Begin VB.ComboBox cboCondition
Height = 315
Left = 1200
TabIndex = 4
Top = 360
Width = 1695
End
Begin VB.CommandButton cmdCancel
Caption = "返回(&C)"
Height = 375
Left = 3360
TabIndex = 3
Top = 840
Width = 1095
End
Begin VB.CommandButton cmdQuery
Caption = "查询(&Q)"
Height = 375
Left = 3360
TabIndex = 2
Top = 360
Width = 1095
End
Begin VB.TextBox txtKey
Height = 285
Left = 1200
TabIndex = 1
Top = 840
Width = 1695
End
Begin VB.Label Label2
Caption = "条件取值:"
Height = 255
Left = 240
TabIndex = 6
Top = 840
Width = 975
End
Begin VB.Label Label1
Caption = "查询条件:"
Height = 375
Left = 240
TabIndex = 5
Top = 360
Width = 975
End
End
End
Attribute VB_Name = "frmQueryProduct"
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 cboCondition_Click()
If cboCondition.Text = "全部" Then
txtKey.Enabled = False
Else
txtKey.Enabled = True
End If
End Sub
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub cmdQuery_Click()
queryClients
End Sub
Private Sub Form_Load()
initQueryType
End Sub
Sub queryClients()
Dim rs As ADODB.Recordset
Dim i As Integer
Dim j As Integer
If cboCondition.Text = "全部" Then
If txtKey.Text = "" Then
MsgBox "请输入查询条件!!"
End If
sqlStr = "select * from products"
End If
If cboCondition.Text = "产品编号" Then
If txtKey.Text = "" Then
MsgBox "请输入查询条件!!"
End If
sqlStr = "select * from products where productID='" & txtKey.Text & "'"
End If
If cboCondition.Text = "产品名称" Then
If txtKey.Text = "" Then
MsgBox "请输入查询条件!!"
End If
sqlStr = "select * from products where productName LIKE '%" & txtKey.Text & "%'"
End If
Set rs = ExecuteSQL(sqlStr, msgText)
If rs.RecordCount = 0 Then
MsgBox "没有查找满足条件的数据!", vbExclamation, "提示"
fgProducts.Rows = 1
Else
fgProducts.Rows = rs.RecordCount + 1
fgProducts.Cols = 6
'设定行高
For i = 0 To fgProducts.Rows - 1
fgProducts.RowHeight(i) = 280
Next i
'设定列的属性
fgProducts.Row = 0
For i = 0 To fgProducts.Cols - 1
fgProducts.Col = i '指定当前列为第i列
fgProducts.FixedAlignment(i) = 4 '每列内容居中显示
Select Case i
Case 0
fgProducts.ColWidth(i) = 600 '设定列宽
fgProducts.Text = "编号"
Case 1
fgProducts.ColWidth(i) = 2000 '设定列宽
fgProducts.Text = "产品名称"
Case 2
fgProducts.ColWidth(i) = 1000 '设定列宽
fgProducts.Text = "产品价格"
Case 3
fgProducts.ColWidth(i) = 1000 '设定列宽
fgProducts.Text = "产品成本"
Case 4
fgProducts.ColWidth(i) = 1000 '设定列宽
fgProducts.Text = "已售数量"
Case 5
fgProducts.ColWidth(i) = 1000 '设定列宽
fgProducts.Text = "库存"
End Select
Next i
'rs.MoveFirst
i = 1
While (Not rs.EOF)
fgProducts.Row = i
For j = 0 To fgProducts.Cols - 1
fgProducts.Col = j '设置当前为列为第j列
fgProducts.CellAlignment = 4 '每列内容居中显示
Select Case j
Case 0
fgProducts.Text = rs.Fields("productID")
Case 1
fgProducts.Text = rs.Fields("productName")
Case 2
fgProducts.Text = rs.Fields("price")
Case 3
fgProducts.Text = rs.Fields("cost")
Case 4
fgProducts.Text = rs.Fields("saled")
Case 5
fgProducts.Text = rs.Fields("stored")
End Select
Next j
rs.MoveNext
i = i + 1
Wend
End If
rs.Close
End Sub
Sub initQueryType()
cboCondition.Clear
cboCondition.AddItem "全部"
cboCondition.AddItem "产品编号"
cboCondition.AddItem "产品名称"
cboCondition.ListIndex = 0
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -