📄 roomstate.frm
字号:
Caption = "当前房间:"
Height = 255
Left = 1080
TabIndex = 4
Top = 360
Width = 975
End
End
End
Attribute VB_Name = "RoomState"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private iMaxRoomNumber As Integer
'初始表数据表的结构
Private Sub InitDataTable()
'查询各楼层的房间数
OpenTable Adodc1, "select count(*) as total from 客房信息 group by 楼层编号"
If Adodc1.Recordset.RecordCount <> 0 Then
'获得房间最多的那一层的房间数
For i = 0 To Adodc1.Recordset.RecordCount - 1
If iMaxRoomNumber < Int(Adodc1.Recordset(0)) Then
iMaxRoomNumber = Int(Adodc1.Recordset(0))
End If
Adodc1.Recordset.MoveNext
Next
End If
fgDataGrid.Rows = Adodc1.Recordset.RecordCount + 1
fgDataGrid.Cols = iMaxRoomNumber + 1
For i = 0 To iMaxRoomNumber
fgDataGrid.ColWidth(i) = 500 '设置宽度
fgDataGrid.TextMatrix(0, i) = i '设置编号
Next i
fgDataGrid.TextMatrix(0, 0) = "楼层"
'将楼层编号添加到数据行中
OpenTable Adodc1, "select distinct 楼层编号 from 客房信息"
For i = 1 To Adodc1.Recordset.RecordCount
Dim strFloor As String
strFloor = Adodc1.Recordset(0)
fgDataGrid.TextMatrix(i, 0) = strFloor
Adodc1.Recordset.MoveNext
Next i
End Sub
Private Sub LoadData()
Dim m As String
OpenTable Adodc1, "select distinct 楼层编号 from 客房信息"
For i = 1 To Adodc1.Recordset.RecordCount
m = Adodc1.Recordset.Fields(0)
OpenTable Adodc2, "select 客房类型,楼层编号,状态 from 客房信息 " + " where 楼层编号 = '" + m + "'"
'查询出每个楼层的房间信息
For j = 1 To iMaxRoomNumber
'设置房间的状态信息
If j < Adodc2.Recordset.RecordCount + 1 Then
If Not fla Then
fgDataGrid.TextMatrix(i, j) = Adodc2.Recordset.Fields(2)
Adodc2.Recordset.MoveNext
Else
If Adodc2.Recordset.Fields(0) <> strRoomState Then
fgDataGrid.TextMatrix(i, j) = ""
Adodc2.Recordset.MoveNext
ElseIf Adodc2.Recordset.Fields(2) = "空房" Then
fgDataGrid.TextMatrix(i, j) = Adodc2.Recordset.Fields(2)
Adodc2.Recordset.MoveNext
Else
fgDataGrid.TextMatrix(i, j) = ""
Adodc2.Recordset.MoveNext
End If
End If
Else
fgDataGrid.TextMatrix(i, j) = ""
End If
Next
If Not Adodc1.Recordset.BOF And Not Adodc1.Recordset.EOF Then
Adodc1.Recordset.MoveNext
End If
Next
fla = False
End Sub
Private Function GetStateNumber(ByVal State As String) As String
Select Case Trim(State)
Case "将到"
GetStateNumber = "0"
Case "将离"
GetStateNumber = "1"
Case "空房"
GetStateNumber = "2"
Case "维修"
GetStateNumber = "3"
Case "住房"
GetStateNumber = "4"
Case "自用"
GetStateNumber = "5"
End Select
End Function
Private Function GetStateText(ByVal State As String) As String
Select Case Trim(State)
Case "0"
GetStateText = "将到"
Case "1"
GetStateText = "将离"
Case "2"
GetStateText = "空房"
Case "3"
GetStateText = "维修"
Case "4"
GetStateText = "住房"
Case "5"
GetStateText = "自用"
End Select
End Function
Private Sub fgDataGrid_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim iRow, iCol As Integer
iRow = fgDataGrid.Row
iCol = fgDataGrid.Col
If iCol = 0 Then
Exit Sub
End If
If Trim(fgDataGrid.Text) = "" Then
Me.Arrive.Value = False
Me.Leave.Value = False
Me.Empty.Value = False
Me.Repair.Value = False
Me.Full.Value = False
Me.Self.Value = False
CurrentRoom.Caption = ""
Exit Sub
End If
If iCol <> 0 Then
If strFilterRoomState = "" Then
OpenTable Adodc1, "select * from 客房信息 " + " where 楼层编号 = '" + fgDataGrid.TextMatrix(iRow, 0) + "'"
Else
OpenTable Adodc1, "select 楼层编号,状态 from 客房信息 " + " where 状态 = '空房'" + " and 楼层编号 = ' " + fgDataGrid.TextMatrix(iRow, 0) + "'"
End If
For i = 1 To iCol - 1
If Not Adodc1.Recordset.BOF And Not Adodc1.Recordset.EOF Then
Adodc1.Recordset.MoveNext
End If
Next
CurrentRoom.Caption = Adodc1.Recordset("客房编号")
'根据选择的房间设置RadioButton
Select Case fgDataGrid.TextMatrix(iRow, iCol)
Case "将到"
Me.Arrive.Value = True
Case "将离"
Me.Leave.Value = True
Case "空房"
Me.Empty.Value = True
Case "维修"
Me.Repair.Value = True
Case "住房"
Me.Full.Value = True
Case "自用"
Me.Self.Value = True
End Select
End If
End Sub
Private Sub SelectReserve_Click()
Reserve.RoomCode.Text = Me.CurrentRoom.Caption
Unload Me
End Sub
Private Sub SelectReside_Click()
Reside.RoomCode.Text = Me.CurrentRoom.Caption
Unload Me
End Sub
Private Sub Set_Click()
Dim iRow, iCol As Integer
Dim strTmpState As String
Dim strState As String
strState = fgDataGrid.Text
iRow = fgDataGrid.Row
iCol = fgDataGrid.Col
If iCol = 0 Then
Exit Sub
End If
If Trim(fgDataGrid.Text) = "" Then
Me.Arrive.Value = False
Me.Leave.Value = False
Me.Empty.Value = False
Me.Repair.Value = False
Me.Full.Value = False
Me.Self.Value = False
CurrentRoom.Caption = ""
Exit Sub
End If
If iCol <> 0 Then
If strFilterRoomState = "" Then
OpenTable Adodc2, "select * from 客房信息 " + " where 楼层编号 = '" + fgDataGrid.TextMatrix(iRow, 0) + "'"
Else
OpenTable Adodc2, "select 楼层编号,状态 from 客房信息 " + " where 状态 = '空房'" + " and 楼层编号 = ' " + fgDataGrid.TextMatrix(iRow, 0) + "'"
End If
For i = 1 To iCol - 1
Adodc2.Recordset.MoveNext
Next
If Me.Arrive.Value = True Then
strTmpState = "将到"
ElseIf Me.Empty.Value = True Then
strTmpState = "空房"
ElseIf Me.Full.Value = True Then
strTmpState = "住房"
ElseIf Me.Leave.Value = True Then
strTmpState = "将离"
ElseIf Me.Repair.Value = True Then
strTmpState = "维修"
ElseIf Me.Self.Value = True Then
strTmpState = "自用"
End If
'如果状态已经更新
If strTmpState <> strState Then
Adodc2.Recordset("状态") = strTmpState
Adodc2.Recordset.UpdateBatch adAffectCurrent
LoadData
End If
Else
Exit Sub
End If
End Sub
Private Sub UpRoom_Click()
LoadData
End Sub
Private Sub Form_Load()
iMaxRoomNumber = 0
InitDataTable
LoadData
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -