📄 frmupdate.frm
字号:
VERSION 5.00
Begin VB.Form frmUpdate
Caption = "修改/删除房间"
ClientHeight = 3150
ClientLeft = 60
ClientTop = 345
ClientWidth = 7500
LinkTopic = "Form1"
ScaleHeight = 3150
ScaleWidth = 7500
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton cmdDelete
Caption = "删除(&D)"
Height = 375
Left = 5320
TabIndex = 18
Top = 2640
Width = 975
End
Begin VB.CommandButton cmdMove
Caption = "末记录(&L)"
Height = 375
Index = 3
Left = 3240
TabIndex = 15
Top = 2640
Width = 855
End
Begin VB.CommandButton cmdMove
Caption = "后移(&N)"
Height = 375
Index = 2
Left = 2200
TabIndex = 14
Top = 2640
Width = 855
End
Begin VB.CommandButton cmdMove
Caption = "前移(&P)"
Height = 375
Index = 1
Left = 1160
TabIndex = 13
Top = 2640
Width = 855
End
Begin VB.CommandButton cmdMove
Caption = "首记录(&F)"
Height = 375
Index = 0
Left = 120
TabIndex = 12
Top = 2640
Width = 855
End
Begin VB.Frame Frame1
Caption = "客房信息"
Height = 2295
Left = 120
TabIndex = 2
Top = 240
Width = 7215
Begin VB.ComboBox cboBooked
Height = 315
Left = 1200
TabIndex = 17
Text = "Combo1"
Top = 1800
Width = 2175
End
Begin VB.TextBox txtPrice
Enabled = 0 'False
Height = 270
Left = 1200
MaxLength = 10
TabIndex = 6
Top = 1440
Width = 1455
End
Begin VB.TextBox txtName
Height = 270
Left = 1200
MaxLength = 5
TabIndex = 5
Top = 480
Width = 2175
End
Begin VB.ComboBox cboType
Height = 315
Left = 1200
Style = 2 'Dropdown List
TabIndex = 4
Top = 960
Width = 2175
End
Begin VB.TextBox txtMemo
Height = 1560
Left = 4440
MaxLength = 5
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 3
Top = 480
Width = 2535
End
Begin VB.Label Label3
Caption = "是否入住:"
Height = 255
Left = 240
TabIndex = 16
Top = 1920
Width = 975
End
Begin VB.Label Label2
Caption = "房间价格:"
Height = 255
Index = 3
Left = 240
TabIndex = 11
Top = 1440
Width = 975
End
Begin VB.Label Label2
Caption = "房 间 号:"
Height = 255
Index = 0
Left = 240
TabIndex = 10
Top = 480
Width = 975
End
Begin VB.Label Label2
Caption = "房间类型:"
Height = 255
Index = 1
Left = 240
TabIndex = 9
Top = 960
Width = 975
End
Begin VB.Label Label2
Caption = "元/每天"
Height = 255
Index = 4
Left = 2760
TabIndex = 8
Top = 1440
Width = 615
End
Begin VB.Label Label1
Caption = "备 注:"
Height = 255
Left = 3600
TabIndex = 7
Top = 480
Width = 855
End
End
Begin VB.CommandButton cmdExit
Caption = "取消 (&X)"
Height = 375
Left = 6480
TabIndex = 1
Top = 2640
Width = 855
End
Begin VB.CommandButton cmdUpdate
Caption = "修改(&U)"
Height = 375
Left = 4280
TabIndex = 0
Top = 2640
Width = 855
End
End
Attribute VB_Name = "frmUpdate"
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
Public rstRoom As ADODB.Recordset
Private Sub cboType_Click()
Dim rstType As ADODB.Recordset
sqlStr = "select typename,price from roomtype where typename='" & Trim(cboType) & "'"
Set rstType = ExecuteSQL(sqlStr, msgText)
If Not rstType.EOF Then
txtPrice = rstType!price
Else
MsgBox "请先添加客房类型!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
rstType.Close
End Sub
Private Sub cmdDelete_Click()
Dim sel As Integer
sel = MsgBox("确定要删除吗?", vbOKCancel, "确认")
If sel = vbOK Then
rstRoom.Delete
cmdMove_Click (2)
MsgBox "成功删除一条记录", vbInformation, "提示"
End If
End Sub
Private Sub cmdExit_Click()
Unload Me
End Sub
Private Sub cmdMove_Click(Index As Integer)
Select Case Index
'移动到第一条记录
Case 0: rstRoom.MoveFirst
showRec
'向前移动一条记录
Case 1:
rstRoom.MovePrevious
If rstRoom.BOF Then
rstRoom.MoveFirst
End If
showRec
'向后移动一条记录
Case 2:
rstRoom.MoveNext
If rstRoom.EOF Then
rstRoom.MoveLast
End If
showRec
'移动到最后一条记录
Case 3: rstRoom.MoveLast
showRec
End Select
End Sub
Private Sub cmdUpdate_Click()
rstRoom.Fields("roomNO") = txtName.Text
rstRoom.Fields("roomType") = cboType.Text
rstRoom.Fields("roomPrice") = txtPrice.Text
rstRoom.Fields("hasBooked") = cboBooked.Text
rstRoom.Fields("roomMemo") = txtMemo.Text
rstRoom.Update
cmdMove_Click (2)
MsgBox "已成功修改数据!!", vbInformation, "提示"
End Sub
Private Sub Form_Load()
Dim rstType As ADODB.Recordset
'窗体居中显示
Me.Top = (Screen.Height - Me.Height) \ 2
Me.Left = (Screen.Width - Me.Width) \ 2
txtName = ""
txtPrice = ""
txtMemo = ""
cboType.Clear
'初始化房间类型
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
'获取房间表的记录集
sqlStr = "select * from roomInfo"
Set rstRoom = ExecuteSQL(sqlStr, msgText)
showRec
End Sub
Public Sub showRec()
If Not rstRoom.EOF Then
txtName.Text = Trim(rstRoom.Fields("roomNO"))
txtPrice.Text = Trim(rstRoom.Fields("roomPrice"))
txtMemo.Text = Trim(rstRoom.Fields("roomMemo"))
cboType.Text = Trim(rstRoom.Fields("roomType"))
cboBooked.Text = Trim(rstRoom.Fields("hasBooked"))
Else
MsgBox "没有任何房间信息!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -