⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmstation.vb

📁 地理信息系统二次开发实例教程VB.NET及源代码
💻 VB
字号:
Public Class frmStation
    Inherits System.Windows.Forms.Form

    Private _frmMain As MainForm
    Private _szStaName As String

#Region " Windows 窗体设计器生成的代码 "

    Public Sub New(ByVal frmMain As MainForm, ByVal stationName As String)
        MyBase.New()

        '该调用是 Windows 窗体设计器所必需的
        InitializeComponent()

        '在 InitializeComponent() 调用之后添加任何初始化
        _frmMain = frmMain
        _szStaName = stationName
    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 button1 As System.Windows.Forms.Button
    Friend WithEvents _label2 As System.Windows.Forms.Label
    Friend WithEvents _label_Statation As System.Windows.Forms.Label
    Friend WithEvents _listBox As System.Windows.Forms.ListBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.button1 = New System.Windows.Forms.Button()
        Me._label2 = New System.Windows.Forms.Label()
        Me._label_Statation = New System.Windows.Forms.Label()
        Me._listBox = New System.Windows.Forms.ListBox()
        Me.SuspendLayout()
        '
        'button1
        '
        Me.button1.Enabled = False
        Me.button1.Location = New System.Drawing.Point(190, 2)
        Me.button1.Name = "button1"
        Me.button1.Size = New System.Drawing.Size(56, 24)
        Me.button1.TabIndex = 11
        Me.button1.Text = "定位"
        '
        '_label2
        '
        Me._label2.Anchor = ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right)
        Me._label2.Font = New System.Drawing.Font("宋体", 10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
        Me._label2.Location = New System.Drawing.Point(24, 32)
        Me._label2.Name = "_label2"
        Me._label2.Size = New System.Drawing.Size(164, 24)
        Me._label2.TabIndex = 10
        '
        '_label_Statation
        '
        Me._label_Statation.Anchor = ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right)
        Me._label_Statation.Font = New System.Drawing.Font("宋体", 10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
        Me._label_Statation.Location = New System.Drawing.Point(24, 8)
        Me._label_Statation.Name = "_label_Statation"
        Me._label_Statation.Size = New System.Drawing.Size(164, 24)
        Me._label_Statation.TabIndex = 9
        '
        '_listBox
        '
        Me._listBox.Anchor = (((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right)
        Me._listBox.ItemHeight = 12
        Me._listBox.Location = New System.Drawing.Point(24, 64)
        Me._listBox.Name = "_listBox"
        Me._listBox.Size = New System.Drawing.Size(168, 172)
        Me._listBox.TabIndex = 8
        '
        'frmStation
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(256, 245)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.button1, Me._label2, Me._label_Statation, Me._listBox})
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frmStation"
        Me.Text = "车站信息"
        Me.TopMost = True
        Me.ResumeLayout(False)

    End Sub

#End Region

    '---------------------------------------------------------------------
    Private Sub frmStation_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        _label_Statation.Text = " 车站名称:" + _szStaName
        _label2.Text = "经过" + _szStaName + "的公交线路:"
        LoadListBox()
    End Sub
    '---------------------------------------------------------------------
    Private Sub LoadListBox()
        _listBox.Items.Clear()
        If "" = _szStaName Then
            Return
        End If

        Dim typeTbl As System.Data.DataTable
        typeTbl = _frmMain._environment.m_dataSet.Tables("公交车站路线")
        Dim szFilter As String = "站名='" + _szStaName + "'"
        If _frmMain._environment.m_szBusFilter <> "" Then
            szFilter += " And "
            szFilter += _frmMain._environment.m_szBusFilter
        End If

        Dim rowstypes As System.Data.DataRow() = typeTbl.Select(szFilter)
        Dim myRow As System.Data.DataRow
        For Each myRow In rowstypes
            _listBox.Items.Add(myRow("线路名"))
        Next
    End Sub
    '---------------------------------------------------------------------
    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
        Dim szName As String = _listBox.Text ' 公交路线名称
        Dim szLayer As String = CEnvironment.BUSLINE_LAYERNAME '公交路线所在图层名称

        Dim ly As MapObjects2.MapLayer = _frmMain.Map.Layers.Item(szLayer)
        If ly Is Nothing Then
            Return
        End If

        Dim rs As MapObjects2.Recordset = ly.SearchExpression("名称 like '" + szName + "'")
        If rs Is Nothing Then
            MessageBox.Show("地图上没有这条公交线路!", _
                            "北京市地理信息公众查询系统", _
                            MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return
        End If

        rs.MoveFirst()
        If rs.EOF Then
            MessageBox.Show("地图上没有这条公交线路!", _
                            "北京市地理信息公众查询系统", _
                            MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return
        End If

        ' 在地图找到了这条线路,画出来
        ' 首先定位
        Dim pt As MapObjects2.Point
        Dim line As MapObjects2.Line = rs.Fields.Item("shape").Value
        pt = line.Extent.Center

        If Not _frmMain.IsWithin(_frmMain.Map.Extent, pt) Then
            _frmMain.Map.CenterAt(pt.X, pt.Y)
        End If

        ' 其次设置_environment.m_drawLine和_environment.m_buses
        Dim pts As MapObjects2.Points
        pts = line.Parts.Item(0)

        _frmMain._environment.m_drawLine = Nothing
        ReDim _frmMain._environment.m_drawLine(0)
        _frmMain._environment.m_drawLine(0) = New MLine()
        _frmMain._environment.m_drawLine(0).nPointNumber = pts.Count
        ReDim _frmMain._environment.m_drawLine(0).pPoint(pts.Count - 1)

        Dim i As Integer
        For i = 0 To pts.Count - 1
            pt = pts.Item(i)
            _frmMain._environment.m_drawLine(0).pPoint(i) = New MPoint()
            _frmMain._environment.m_drawLine(0).pPoint(i).x = pt.X
            _frmMain._environment.m_drawLine(0).pPoint(i).y = pt.Y
        Next

        _frmMain._environment.m_buses = New Buses()
        Dim nCount As Integer = 0
        If Not _frmMain._environment.GetStation(szName, _frmMain._environment.m_buses, nCount) Then
            _frmMain._environment.m_buses = Nothing
        Else
            _frmMain._environment.m_buses.nNum = nCount
        End If

        ' 闪烁,重画
        _frmMain.Map.FlashShape(rs.Fields.Item("shape").Value, 4)
        _frmMain.Map.Extent = _frmMain.Map.Extent
    End Sub
    '---------------------------------------------------------------------
    Private Sub _listBox_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles _listBox.DoubleClick
        If _listBox.Text = "" Then
            Return
        End If

        Dim frm As New frmLine(_frmMain, _listBox.Text)
        Visible = False
        frm.ShowDialog(_frmMain)
        Close()
    End Sub
    '---------------------------------------------------------------------
    Private Sub _listBox_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles _listBox.SelectedIndexChanged
        button1.Enabled = True
    End Sub
    '---------------------------------------------------------------------
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -