📄 frmbus.vb
字号:
Public Class frmBus
Inherits System.Windows.Forms.Form
Private _frmMain As MainForm
Private _bTextBox1 As Boolean = True
Private _bTextBox2 As Boolean = True
#Region " Windows 窗体设计器生成的代码 "
Public Sub New(ByVal frmMain As MainForm)
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
_frmMain = frmMain
End Sub
'窗体重写处置以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意:以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents _label_end As System.Windows.Forms.Label
Friend WithEvents _label_start As System.Windows.Forms.Label
Friend WithEvents _listBox_end As System.Windows.Forms.ListBox
Friend WithEvents _listBox_start As System.Windows.Forms.ListBox
Friend WithEvents _button_search As System.Windows.Forms.Button
Friend WithEvents _textBox_end As System.Windows.Forms.TextBox
Friend WithEvents _textBox_start As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me._label_end = New System.Windows.Forms.Label()
Me._label_start = New System.Windows.Forms.Label()
Me._listBox_end = New System.Windows.Forms.ListBox()
Me._listBox_start = New System.Windows.Forms.ListBox()
Me._button_search = New System.Windows.Forms.Button()
Me._textBox_end = New System.Windows.Forms.TextBox()
Me._textBox_start = New System.Windows.Forms.TextBox()
Me.SuspendLayout()
'
'_label_end
'
Me._label_end.Font = New System.Drawing.Font("宋体", 10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me._label_end.Location = New System.Drawing.Point(152, 8)
Me._label_end.Name = "_label_end"
Me._label_end.Size = New System.Drawing.Size(80, 16)
Me._label_end.TabIndex = 21
Me._label_end.Text = "终点站:"
'
'_label_start
'
Me._label_start.Font = New System.Drawing.Font("宋体", 10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me._label_start.Location = New System.Drawing.Point(8, 8)
Me._label_start.Name = "_label_start"
Me._label_start.Size = New System.Drawing.Size(80, 16)
Me._label_start.TabIndex = 20
Me._label_start.Text = "起点站:"
'
'_listBox_end
'
Me._listBox_end.ItemHeight = 12
Me._listBox_end.Location = New System.Drawing.Point(152, 56)
Me._listBox_end.Name = "_listBox_end"
Me._listBox_end.Size = New System.Drawing.Size(128, 208)
Me._listBox_end.TabIndex = 19
'
'_listBox_start
'
Me._listBox_start.ItemHeight = 12
Me._listBox_start.Location = New System.Drawing.Point(8, 56)
Me._listBox_start.Name = "_listBox_start"
Me._listBox_start.Size = New System.Drawing.Size(128, 208)
Me._listBox_start.TabIndex = 18
'
'_button_search
'
Me._button_search.Location = New System.Drawing.Point(296, 24)
Me._button_search.Name = "_button_search"
Me._button_search.Size = New System.Drawing.Size(72, 24)
Me._button_search.TabIndex = 17
Me._button_search.Text = "查询"
'
'_textBox_end
'
Me._textBox_end.Location = New System.Drawing.Point(152, 24)
Me._textBox_end.Name = "_textBox_end"
Me._textBox_end.Size = New System.Drawing.Size(128, 21)
Me._textBox_end.TabIndex = 16
Me._textBox_end.Text = ""
'
'_textBox_start
'
Me._textBox_start.Location = New System.Drawing.Point(8, 24)
Me._textBox_start.Name = "_textBox_start"
Me._textBox_start.Size = New System.Drawing.Size(128, 21)
Me._textBox_start.TabIndex = 15
Me._textBox_start.Text = ""
'
'frmBus
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(376, 273)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me._label_end, Me._label_start, Me._listBox_end, Me._listBox_start, Me._button_search, Me._textBox_end, Me._textBox_start})
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow
Me.Name = "frmBus"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
Me.Text = "选择乘车路线"
Me.ResumeLayout(False)
End Sub
#End Region
'---------------------------------------------------------------------
Private Sub frmBus_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
LoadListBox()
End Sub
'---------------------------------------------------------------------
Private Sub LoadListBox()
_listBox_start.DataSource = _frmMain._environment.m_dataSet.Tables("公交车站")
_listBox_start.DisplayMember = "站名"
_listBox_end.DataSource = _frmMain._environment.m_dataSet.Tables("公交车站2")
_listBox_end.DisplayMember = "站名"
End Sub
'---------------------------------------------------------------------
Private Sub _listBox_start_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles _listBox_start.SelectedIndexChanged
If Not _bTextBox1 Then
_textBox_start.Text = _listBox_start.Text
End If
End Sub
'---------------------------------------------------------------------
Private Sub _listBox_end_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles _listBox_end.SelectedIndexChanged
If Not _bTextBox2 Then
_textBox_end.Text = _listBox_end.Text
End If
End Sub
'---------------------------------------------------------------------
Private Sub _listBox_start_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles _listBox_start.MouseDown
_bTextBox1 = False
End Sub
'---------------------------------------------------------------------
Private Sub _listBox_end_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles _listBox_end.MouseDown
_bTextBox2 = False
End Sub
'---------------------------------------------------------------------
Private Sub _textBox_start_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles _textBox_start.TextChanged
Dim nIndex As Integer = _listBox_start.FindString(_textBox_start.Text, -1)
If nIndex <> ListBox.NoMatches Then
_listBox_start.SelectedIndex = nIndex
End If
If _textBox_end.Text <> "" And _textBox_start.Text <> "" Then
_button_search.Enabled = True
Else
_button_search.Enabled = False
End If
_bTextBox1 = True
End Sub
'---------------------------------------------------------------------
Private Sub _textBox_end_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles _textBox_end.TextChanged
Dim nIndex As Integer = _listBox_end.FindString(_textBox_end.Text, -1)
If nIndex <> ListBox.NoMatches Then
_listBox_end.SelectedIndex = nIndex
End If
If _textBox_end.Text <> "" And _textBox_start.Text <> "" Then
_button_search.Enabled = True
Else
_button_search.Enabled = False
End If
_bTextBox2 = True
End Sub
'---------------------------------------------------------------------
Private Sub _button_search_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles _button_search.Click
' 判断站名的正确性
If Not IsValidStation(_textBox_start.Text) Then
MessageBox.Show("错误的起始站名。", "北京市地理信息公众查询系统", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
Return
End If
If Not IsValidStation(_textBox_end.Text) Then
MessageBox.Show("错误的终点站名。", "北京市地理信息公众查询系统", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
Return
End If
' 调用CPath类的Search方法公交乘车路线执行查询
Dim env As CEnvironment = _frmMain._environment
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
Dim array As New ArrayList()
env.m_path.Search(_textBox_start.Text, _textBox_end.Text, array)
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Arrow
If array.Count = 0 Then
MessageBox.Show("没有合适的乘车路线。", "北京市地理信息公众查询系统", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
Return
Else
' 如果有匹配的公交换乘方案,则新弹出一窗口,显示查询结果
Dim frm As New frmBusResult(_frmMain, array)
Visible = False
frm.ShowDialog(_frmMain)
Close()
End If
End Sub
'---------------------------------------------------------------------
Private Function IsValidStation(ByVal szStation As String) As Boolean
' 从“公交车站”表中查询是否有该站点名,如果有则返回true,否则返回false
Dim indexTbl As System.Data.DataTable
indexTbl = _frmMain._environment.m_dataSet.Tables("公交车站")
Dim rowsType As System.Data.DataRow() = indexTbl.Select("站名='" + szStation + "'")
If rowsType.Length > 0 Then
Return True
End If
Return False
End Function
'---------------------------------------------------------------------
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -