📄 frmqueryroom.frm
字号:
VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "Msflxgrd.ocx"
Begin VB.Form frmqueryRoom
Caption = "查询房间"
ClientHeight = 4815
ClientLeft = 60
ClientTop = 345
ClientWidth = 5130
LinkTopic = "Form1"
ScaleHeight = 4815
ScaleWidth = 5130
StartUpPosition = 3 'Windows Default
Begin MSFlexGridLib.MSFlexGrid fgRoom
Height = 1575
Left = 120
TabIndex = 8
Top = 3120
Width = 4815
_ExtentX = 8493
_ExtentY = 2778
_Version = 393216
End
Begin VB.CommandButton Command1
Caption = "取消(&C)"
Height = 375
Left = 2760
TabIndex = 6
Top = 2520
Width = 1095
End
Begin VB.CommandButton cmdQuery
Caption = "查询(&Q)"
Height = 375
Left = 1320
TabIndex = 5
Top = 2520
Width = 1095
End
Begin VB.Frame Frame2
Caption = "查询条件"
Height = 1215
Left = 240
TabIndex = 3
Top = 1080
Width = 4695
Begin VB.OptionButton optCondition
Caption = "按房间类型"
Height = 375
Index = 1
Left = 240
TabIndex = 11
Top = 720
Width = 1335
End
Begin VB.OptionButton optCondition
Caption = "按房间号"
Height = 375
Index = 0
Left = 240
TabIndex = 10
Top = 240
Width = 1335
End
Begin VB.ComboBox cboRoom
Height = 315
Left = 1680
TabIndex = 7
Text = "Combo1"
Top = 240
Width = 2655
End
Begin VB.ComboBox cboType
Height = 315
Left = 1680
TabIndex = 4
Text = "Combo1"
Top = 720
Width = 2655
End
End
Begin VB.Frame Frame1
Caption = "选择查询方式"
Height = 735
Left = 240
TabIndex = 0
Top = 240
Width = 4695
Begin VB.OptionButton optQueryType
Caption = "空闲房间"
Height = 375
Index = 2
Left = 1680
TabIndex = 9
Top = 240
Width = 1215
End
Begin VB.OptionButton optQueryType
Caption = "按指定条件查询"
Height = 375
Index = 1
Left = 3000
TabIndex = 2
Top = 240
Width = 1575
End
Begin VB.OptionButton optQueryType
Caption = "查询全部"
Height = 375
Index = 0
Left = 360
TabIndex = 1
Top = 240
Width = 1095
End
End
End
Attribute VB_Name = "frmqueryRoom"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public msgText As String
Public sqlStr As String
Private Sub cmdQuery_Click()
Dim rs As ADODB.Recordset
Dim i As Integer
Dim j As Integer
If optQueryType(0).Value = True Then
sqlStr = "select * from roomInfo"
End If
If optQueryType(2).Value = True Then
sqlStr = "select * from roomInfo where hasBooked='否'"
End If
If optQueryType(1).Value = True Then
If optCondition(0).Value Then
sqlStr = "SELECT * FROM roomInfo where roomno='" & cboRoom.Text & "'"
End If
If optCondition(1).Value Then
sqlStr = "SELECT * FROM roomInfo where roomtype='" & cboType.Text & "'"
End If
End If
Set rs = ExecuteSQL(sqlStr, msgText)
If rs.RecordCount = 0 Then
frmQueryBook.Height = 2800
MsgBox "没有查找满足条件的数据!", vbExclamation, "提示"
Else
fgRoom.Rows = rs.RecordCount + 1
fgRoom.Cols = 6
'Print fgRoom.Rows
'设定行高
For i = 0 To fgRoom.Rows - 1
fgRoom.RowHeight(i) = 280
Next i
'设定列的属性
fgRoom.Row = 0
For i = 0 To fgRoom.Cols - 1
fgRoom.Col = i '指定当前列为第i列
fgRoom.FixedAlignment(i) = 4 '每列内容居中显示
Select Case i
Case 0
fgRoom.ColWidth(i) = 620 '设定列宽
fgRoom.Text = "序号"
Case 1
fgRoom.ColWidth(i) = 920 '设定列宽
fgRoom.Text = "房间号"
Case 2
fgRoom.ColWidth(i) = 1000 '设定列宽
fgRoom.Text = "房间类型"
Case 3
fgRoom.ColWidth(i) = 700 '设定列宽
fgRoom.Text = "房间价格"
Case 4
fgRoom.ColWidth(i) = 700 '设定列宽
fgRoom.Text = "已入住"
Case 5
fgRoom.ColWidth(i) = 1000 '设定列宽
fgRoom.Text = "备注"
End Select
Next i
'rs.MoveFirst
i = 1
While (Not rs.EOF)
fgRoom.Row = i
For j = 0 To fgRoom.Cols - 1
fgRoom.Col = j '设置当前为列为第j列
fgRoom.CellAlignment = 4 '每列内容居中显示
Select Case j
Case 0
fgRoom.Text = "" & i
Case 1
fgRoom.Text = rs.Fields("roomNO")
Case 2
fgRoom.Text = rs.Fields("roomType")
Case 3
fgRoom.Text = rs.Fields("roomPrice")
Case 4
fgRoom.Text = rs.Fields("hasBooked")
Case 5
fgRoom.Text = rs.Fields("roomMemo")
End Select
Next j
'Print rs.Fields("bookid"), rs.Fields("bookname")
rs.MoveNext
i = i + 1
Wend
fgRoom.Visible = True
frmqueryRoom.Height = 5280
End If
rs.Close
End Sub
Private Sub Command1_Click()
Unload Me
End Sub
Private Sub Form_Load()
Dim rstType As ADODB.Recordset
Dim rstRoom As ADODB.Recordset
'窗体居中显示
Me.Top = (Screen.Height - Me.Height) \ 2
Me.Left = (Screen.Width - Me.Width) \ 2
'初始化房间信息
sqlStr = "select roomNo from roomInfo"
Set rstRoom = ExecuteSQL(sqlStr, msgText)
If Not rstRoom.EOF Then
Do While Not rstRoom.EOF
cboRoom.AddItem Trim(rstRoom.Fields(0))
rstRoom.MoveNext
Loop
cboRoom.ListIndex = 0
Else
MsgBox "没有任何房间信息!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
rstRoom.Close
'初始化房间类型
sqlStr = "select DISTINCT typename from roomtype"
Set rstType = ExecuteSQL(sqlStr, msgText)
If Not rstType.EOF Then
Do While Not rstType.EOF
cboType.AddItem Trim(rstType.Fields(0))
rstType.MoveNext
Loop
cboType.ListIndex = 0
Else
MsgBox "请添加客房类型!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
rstType.Close
'窗体居中显示
Me.Top = (Screen.Height - Me.Height) \ 2
Me.Left = (Screen.Width - Me.Width) \ 2
End Sub
Private Sub optQueryType_Click(Index As Integer)
If Index = 1 Then
Frame2.Enabled = True
optCondition(0).Enabled = True
optCondition(1).Enabled = True
cboRoom.Enabled = True
cboType.Enabled = True
Else
optCondition(0).Enabled = False
optCondition(1).Enabled = False
Frame2.Enabled = False
cboRoom.Enabled = False
cboType.Enabled = False
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -