📄 form1.frm
字号:
VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Begin VB.Form frmJDXX
Caption = "酒店信息管理"
ClientHeight = 6000
ClientLeft = 48
ClientTop = 336
ClientWidth = 8076
LinkTopic = "Form1"
MDIChild = -1 'True
ScaleHeight = 6000
ScaleWidth = 8076
WindowState = 2 'Maximized
Begin VB.Frame Frame1
Height = 1452
Left = 360
TabIndex = 1
Top = 120
Width = 7335
Begin VB.ComboBox Combo1
Height = 300
Left = 5520
TabIndex = 11
Top = 180
Width = 1695
End
Begin VB.TextBox Text2
Height = 300
Left = 960
TabIndex = 7
Top = 540
Width = 6252
End
Begin VB.TextBox Text1
Height = 300
Left = 960
TabIndex = 6
Top = 180
Width = 3792
End
Begin VB.CommandButton Command4
Caption = "保存"
Height = 345
Left = 2400
TabIndex = 5
Top = 960
Width = 1230
End
Begin VB.CommandButton Command3
Caption = "删除"
Height = 345
Left = 5040
TabIndex = 4
Top = 960
Width = 1230
End
Begin VB.CommandButton Command2
Caption = "修改"
Height = 345
Left = 3720
TabIndex = 3
Top = 960
Width = 1230
End
Begin VB.CommandButton Command1
Caption = "添加"
Height = 345
Left = 1080
TabIndex = 2
Top = 960
Width = 1230
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "星级"
Height = 180
Left = 5040
TabIndex = 10
Top = 240
Width = 360
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "酒店地址"
Height = 180
Left = 120
TabIndex = 9
Top = 600
Width = 720
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "酒店名称"
Height = 180
Left = 120
TabIndex = 8
Top = 240
Width = 720
End
End
Begin MSDataGridLib.DataGrid DataGrid1
Align = 2 'Align Bottom
Height = 3948
Left = 0
TabIndex = 0
Top = 1716
Width = 8076
_ExtentX = 14245
_ExtentY = 6964
_Version = 393216
AllowUpdate = -1 'True
ForeColor = 0
HeadLines = 2
RowHeight = 15
BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Caption = "酒店信息一览表"
ColumnCount = 2
BeginProperty Column00
DataField = ""
Caption = ""
BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED}
Type = 0
Format = ""
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 2052
SubFormatType = 0
EndProperty
EndProperty
BeginProperty Column01
DataField = ""
Caption = ""
BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED}
Type = 0
Format = ""
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 2052
SubFormatType = 0
EndProperty
EndProperty
SplitCount = 1
BeginProperty Split0
MarqueeStyle = 3
AllowFocus = 0 'False
AllowRowSizing = 0 'False
BeginProperty Column00
EndProperty
BeginProperty Column01
EndProperty
EndProperty
End
Begin MSAdodcLib.Adodc Adodc1
Align = 2 'Align Bottom
Height = 336
Left = 0
Top = 5664
Visible = 0 'False
Width = 8076
_ExtentX = 14245
_ExtentY = 593
ConnectMode = 0
CursorLocation = 3
IsolationLevel = -1
ConnectionTimeout= 15
CommandTimeout = 30
CursorType = 3
LockType = 3
CommandType = 8
CursorOptions = 0
CacheSize = 50
MaxRecords = 0
BOFAction = 0
EOFAction = 0
ConnectStringType= 1
Appearance = 1
BackColor = -2147483643
ForeColor = -2147483640
Orientation = 0
Enabled = -1
Connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\hua\桌面\tour\tour.mdb;Persist Security Info=False"
OLEDBString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\hua\桌面\tour\tour.mdb;Persist Security Info=False"
OLEDBFile = ""
DataSourceName = ""
OtherAttributes = ""
UserName = ""
Password = ""
RecordSource = ""
Caption = "Adodc1"
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
_Version = 393216
End
End
Attribute VB_Name = "frmJDXX"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim editing As Boolean
Private Sub Command1_Click()
'添加记录
If editing = False Then '添加记录
editing = True
Text1.Text = ""
Text2.Text = ""
Combo1.ListIndex = 0
Command1.Caption = "放弃"
Command1.Enabled = True
Command2.Enabled = False
Command3.Enabled = False
Command4.Enabled = True
Else '取消添加
If MsgBox("确定取消添加新记录?", vbQuestion + vbYesNo, "取消?") = vbYes Then
editing = False
Call DataGrid1_Click
End If
End If
End Sub
Private Sub Command2_Click()
'修改记录
If editing = False Then '修改记录
editing = True
Command2.Caption = "放弃"
Command1.Enabled = False
Command2.Enabled = True
Command3.Enabled = False
Command4.Enabled = True
Else '取消修改
If MsgBox("确定取消修改当前记录?", vbQuestion + vbYesNo, "取消?") = vbYes Then
editing = False
Adodc1.Recordset.CancelBatch adAffectAllChapters '取消修改
Call DataGrid1_Click
End If
End If
End Sub
Private Sub Command3_Click()
'删除记录
If MsgBox("确定删除当前记录?", vbQuestion + vbYesNo, "删除?") = vbYes Then
Adodc1.Recordset.Delete '删除记录
Adodc1.Recordset.MoveNext '移动记录
If Adodc1.Recordset.EOF Then
If Adodc1.Recordset.RecordCount <> 0 Then
Adodc1.Recordset.MoveLast
End If
End If
Call DataGrid1_Click '刷新记录
End If
End Sub
Private Sub Command4_Click() '保存按钮
'检查输入
If Text1.Text = "" Then
MsgBox "请输入酒店名称!"
Text1.SetFocus
Exit Sub
End If
If Text2.Text = "" Then
MsgBox "请输入酒店地址!"
Text2.SetFocus
Exit Sub
End If
'保存记录
If Command1.Enabled = True Then '新增记录
If Adodc1.Recordset.RecordCount <> 0 Then '记录不为零
'查找是否存在相同记录
Adodc1.Recordset.MoveFirst '移动记录
Adodc1.Recordset.Find "名称 = '" & Text1.Text & "'" '查找记录
If Not Adodc1.Recordset.EOF Then '找到了记录
MsgBox "该酒店的记录已经存在!将取消添加。", vbInformation + vbOKCancel, "错误"
'取消添加
editing = False
Call DataGrid1_Click
Exit Sub
End If
End If
'保存记录
Adodc1.Recordset.AddNew '调用AddNew方法增加记录
Adodc1.Recordset(1) = Text1.Text '设定字段值
Adodc1.Recordset(2) = Combo1.ListIndex + 1
Adodc1.Recordset(3) = Text2.Text
Adodc1.Recordset.UpdateBatch adAffectAllChapters '保存记录
Else '修改按钮
'保存记录
Adodc1.Recordset(1) = Text1.Text
Adodc1.Recordset(2) = Combo1.ListIndex + 1
Adodc1.Recordset(3) = Text2.Text
Adodc1.Recordset.UpdateBatch adAffectAllChapters '保存记录
End If
'其他设定
editing = False
Call DataGrid1_Click
End Sub
Private Sub DataGrid1_Click()
'本段的代码主要用于刷新当前数据和设定按钮状态
If editing = False Then '没有修改或添加记录
Command1.Caption = "添加"
Command1.Enabled = True
If Adodc1.Recordset.RecordCount <> 0 Then '有记录
Command2.Caption = "修改"
Command2.Enabled = True
Command3.Enabled = True
Command4.Enabled = False
Text1.Text = DataGrid1.Columns(1).Text '更新文本框中的内容
Text2.Text = DataGrid1.Columns(3).Text '更新文本框中的内容
Combo1.ListIndex = DataGrid1.Columns(2).Text - 1 '更新组合框中的内容
Else '没有记录
Command2.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
End If
End If
End Sub
Private Sub Form_Load()
'设定窗体的数据源
Adodc1.ConnectionString = constr ' 设定ADO数据控件的连接字符串
Adodc1.CommandType = adCmdTable '设定ADO数据控件的命令类型
Adodc1.RecordSource = "酒店信息" '设定数据源为数据表
Set DataGrid1.DataSource = Adodc1 '设定DataGrid控件的数据源
Adodc1.Refresh '刷新数据控件
DataGrid1.ReBind '重新绑定控件
'向组合框中添加条目
Combo1.Clear
Combo1.AddItem "★"
Combo1.AddItem "★★"
Combo1.AddItem "★★★"
Combo1.AddItem "★★★★"
Combo1.AddItem "★★★★★"
'其他设定
editing = False
Call DataGrid1_Click
End Sub
Private Sub Form_Resize()
If Me.WindowState = 1 Then '最小化窗体时
Exit Sub '退出过程
End If
With Frame1 '设定框架的位置
.Left = (Me.Width - Frame1.Width) / 2
.Top = 120
End With
'设定DataGrid控件的高度
DataGrid1.Height = Me.Height - Frame1.Height - Adodc1.Height - 200
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -