📄 frmbus1.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 frmbus1
Caption = "公交信息录入"
ClientHeight = 3000
ClientLeft = 1110
ClientTop = 345
ClientWidth = 5745
KeyPreview = -1 'True
LinkTopic = "Form4"
ScaleHeight = 11115
ScaleWidth = 15240
Begin VB.PictureBox picButtons
Align = 2 'Align Bottom
Appearance = 0 'Flat
BorderStyle = 0 'None
ForeColor = &H80000008&
Height = 300
Left = 0
ScaleHeight = 300
ScaleWidth = 15240
TabIndex = 7
Top = 10485
Width = 15240
Begin VB.CommandButton cmdClose
Caption = "关闭(&C)"
Height = 300
Left = 4675
TabIndex = 12
Top = 0
Width = 1095
End
Begin VB.CommandButton cmdRefresh
Caption = "刷新(&R)"
Height = 300
Left = 3521
TabIndex = 11
Top = 0
Width = 1095
End
Begin VB.CommandButton cmdDelete
Caption = "删除(&D)"
Height = 300
Left = 2367
TabIndex = 10
Top = 0
Width = 1095
End
Begin VB.CommandButton cmdUpdate
Caption = "更新(&U)"
Height = 300
Left = 1213
TabIndex = 9
Top = 0
Width = 1095
End
Begin VB.CommandButton cmdAdd
Caption = "添加(&A)"
Height = 300
Left = 59
TabIndex = 8
Top = 0
Width = 1095
End
End
Begin MSDataGridLib.DataGrid DataGrid1
Height = 1300
Left = 0
TabIndex = 6
Top = 1020
Width = 5765
_ExtentX = 10160
_ExtentY = 2302
_Version = 393216
AllowUpdate = 0 'False
HeadLines = 1
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
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
BeginProperty Column00
EndProperty
BeginProperty Column01
EndProperty
EndProperty
End
Begin VB.TextBox txtFields
DataField = "index"
DataSource = "datPrimaryRS"
Height = 285
Index = 2
Left = 2040
TabIndex = 5
Top = 700
Width = 3375
End
Begin VB.TextBox txtFields
DataField = "busstation"
DataSource = "datPrimaryRS"
Height = 285
Index = 1
Left = 2040
TabIndex = 3
Top = 380
Width = 3375
End
Begin VB.TextBox txtFields
DataField = "busid"
DataSource = "datPrimaryRS"
Height = 285
Index = 0
Left = 2040
TabIndex = 1
Top = 60
Width = 3375
End
Begin MSAdodcLib.Adodc datPrimaryRS
Align = 2 'Align Bottom
Height = 330
Left = 0
Top = 10785
Width = 15240
_ExtentX = 26882
_ExtentY = 582
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=MSDataShape;Data PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=d:\My Documents\新建文件夹\db1.mdb;"
OLEDBString = "PROVIDER=MSDataShape;Data PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=d:\My Documents\新建文件夹\db1.mdb;"
OLEDBFile = ""
DataSourceName = ""
OtherAttributes = ""
UserName = ""
Password = ""
RecordSource = $"frmbus1.frx":0000
Caption = " "
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
Begin VB.Label lblLabels
Caption = "站号"
Height = 255
Index = 2
Left = 120
TabIndex = 4
Top = 700
Width = 1815
End
Begin VB.Label lblLabels
Caption = "站点"
Height = 255
Index = 1
Left = 120
TabIndex = 2
Top = 380
Width = 1815
End
Begin VB.Label lblLabels
Caption = "线路"
Height = 255
Index = 0
Left = 120
TabIndex = 0
Top = 60
Width = 1815
End
End
Attribute VB_Name = "frmbus1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public Function connectstring() As String
ConnectionString = "provider=microsoft.jet.oledb.4.0;data source=db1.mdb"
End Function
Public Function runsql(ByVal sql As String, msgs As String)
Dim cn As Connection
On Error GoTo runsql_error
Set cn = New Connection
cn.Open ConnectionString()
cn.Execute sql
msgs = sql & "successful."
Set cn = Nothing
End Function
Public Function runselect(ByVal sql As String, msgs As String) As ADODB.Recordset
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
On Error GoTo runselect_error
Set cn = New ADODB.Connection
cn.Open connectstring()
Set rs = New ADODB.Recordset
rs.Open Trim$(sql), cn, adOpenKeyset
Set runselect = rs
msgs = "查询到" & rs.RecordCount & "条记录"
runselct_exit:
Set rs = Nothing
Set rs = Nothing
Exit Function
runselect_error:
msgs = "查询错误:" & Err.Description
Resume runselect_exit
End Function
Private Sub Form_Load()
Dim cn As New ADODB.Connection
Dim mrc As ADODB.Recordset, mrc2 As ADODB.Recordset
Dim txtsql As String
Set mrc = runselect("select * from bus", msgtext)
Set DataGrid1.DataSource = mrc
If mrc.RecordCount >= 1 Then
Call DataGrid1_Click
End If
Set grdDataGrid.DataSource = datPrimaryRS.Recordset("ChildCMD").UnderlyingValue
txtFields(0).Text = ""
txtFields(1).Text = ""
txtFields(2).Text = ""
End Sub
Private Sub Form_Resize()
On Error Resume Next
'当窗体调整时会调整网格
grdDataGrid.Width = Me.ScaleWidth
grdDataGrid.Height = Me.ScaleHeight - grdDataGrid.Top - datPrimaryRS.Height - 30 - picButtons.Height
End Sub
Private Sub Form_Unload(Cancel As Integer)
Screen.MousePointer = vbDefault
End Sub
Private Sub datPrimaryRS_Error(ByVal ErrorNumber As Long, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, fCancelDisplay As Boolean)
'错误处理程序代码置于此处
'想要忽略错误,注释掉下一行
'想要捕获它们,在此添加代码以处理它们
MsgBox "Data error event hit err:" & Description
End Sub
' Private Sub datPrimaryRS_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
'为这个 recordset 显示当前记录位置
datPrimaryRS.Caption = "Record: " & CStr(datPrimaryRS.Recordset.AbsolutePosition)
End Sub
'验证代码置于此处
'下列动作发生时该事件被调用
Dim bCancel As Boolean
Select Case adReason
Case adRsnAddNew
Case adRsnClose
Case adRsnDelete
Case adRsnFirstChange
Case adRsnMove
Case adRsnRequery
Case adRsnResynch
Case adRsnUndoAddNew
Case adRsnUndoDelete
Case adRsnUndoUpdate
Case adRsnUpdate
End Select
If bCancel Then adStatus = adStatusCancel
End Sub
Private Sub cmdAdd_Click()
Dim mrc3 As ADODB.Recordset
Set mrc3 = runselect("select * from bus where busid=" & Trim(txtFields(1)) & "and index=" & Trim(CInt(txtFields(2))), msgtext)
If mrc3.RecordCount >= 1 Then
MsgBox ("站号一存在,不能输入一样的站号")
End If
On Error GoTo AddErr
Text1.Text
datPrimaryRS.Recordset.AddNew
Exit Sub
AddErr:
MsgBox Err.Description
End Sub
Private Sub cmdDelete_Click()
On Error GoTo DeleteErr
With datPrimaryRS.Recordset
.Delete
.MoveNext
If .EOF Then .MoveLast
End With
Exit Sub
DeleteErr:
MsgBox Err.Description
End Sub
Private Sub cmdRefresh_Click()
'只有多用户应用程序需要
On Error GoTo RefreshErr
datPrimaryRS.Refresh
Set grdDataGrid.DataSource = datPrimaryRS.Recordset("ChildCMD").UnderlyingValue
Exit Sub
RefreshErr:
MsgBox Err.Description
txtFields(0).Text = ""
txtFields(1).Text = ""
txtFields(2).Text = ""
End Sub
Private Sub cmdUpdate_Click()
On Error GoTo UpdateErr
datPrimaryRS.Recordset.UpdateBatch adAffectAll
Exit Sub
UpdateErr:
MsgBox Err.Description
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -