?? 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 + -