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

📄 frmquery.vb

📁 用VB.NET开发的GeoMedia一个实例
💻 VB
📖 第 1 页 / 共 2 页
字号:
        '
        Me.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.btnClose.Location = New System.Drawing.Point(264, 8)
        Me.btnClose.Name = "btnClose"
        Me.btnClose.Size = New System.Drawing.Size(64, 24)
        Me.btnClose.TabIndex = 7
        Me.btnClose.Text = "关闭"
        '
        'btnSearch
        '
        Me.btnSearch.Anchor = (System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom)
        Me.btnSearch.Enabled = False
        Me.btnSearch.Location = New System.Drawing.Point(136, 8)
        Me.btnSearch.Name = "btnSearch"
        Me.btnSearch.Size = New System.Drawing.Size(64, 24)
        Me.btnSearch.TabIndex = 6
        Me.btnSearch.Text = "查找"
        '
        'Splitter1
        '
        Me.Splitter1.Dock = System.Windows.Forms.DockStyle.Top
        Me.Splitter1.Location = New System.Drawing.Point(0, 232)
        Me.Splitter1.Name = "Splitter1"
        Me.Splitter1.Size = New System.Drawing.Size(464, 4)
        Me.Splitter1.TabIndex = 7
        Me.Splitter1.TabStop = False
        '
        'GroupBox2
        '
        Me.GroupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.DataGrid1})
        Me.GroupBox2.Dock = System.Windows.Forms.DockStyle.Fill
        Me.GroupBox2.Location = New System.Drawing.Point(0, 236)
        Me.GroupBox2.Name = "GroupBox2"
        Me.GroupBox2.Size = New System.Drawing.Size(464, 203)
        Me.GroupBox2.TabIndex = 9
        Me.GroupBox2.TabStop = False
        Me.GroupBox2.Text = "查询结果"
        '
        'DataGrid1
        '
        Me.DataGrid1.CaptionVisible = False
        Me.DataGrid1.DataMember = ""
        Me.DataGrid1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.DataGrid1.Location = New System.Drawing.Point(3, 17)
        Me.DataGrid1.Name = "DataGrid1"
        Me.DataGrid1.ReadOnly = True
        Me.DataGrid1.Size = New System.Drawing.Size(458, 183)
        Me.DataGrid1.TabIndex = 0
        '
        'StatusBar1
        '
        Me.StatusBar1.Location = New System.Drawing.Point(0, 439)
        Me.StatusBar1.Name = "StatusBar1"
        Me.StatusBar1.Panels.AddRange(New System.Windows.Forms.StatusBarPanel() {Me.StatusBarPanel1})
        Me.StatusBar1.ShowPanels = True
        Me.StatusBar1.Size = New System.Drawing.Size(464, 22)
        Me.StatusBar1.SizingGrip = False
        Me.StatusBar1.TabIndex = 10
        Me.StatusBar1.Text = "StatusBar1"
        '
        'StatusBarPanel1
        '
        Me.StatusBarPanel1.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring
        Me.StatusBarPanel1.Width = 464
        '
        'FrmQuery
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.CancelButton = Me.btnClose
        Me.ClientSize = New System.Drawing.Size(464, 461)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.GroupBox2, Me.Splitter1, Me.GroupBox1, Me.StatusBar1})
        Me.Name = "FrmQuery"
        Me.Text = "查找"
        Me.GroupBox1.ResumeLayout(False)
        Me.Panel6.ResumeLayout(False)
        Me.Panel4.ResumeLayout(False)
        Me.Panel7.ResumeLayout(False)
        Me.Panel3.ResumeLayout(False)
        CType(Me.DataGridAttributeContent, System.ComponentModel.ISupportInitialize).EndInit()
        Me.Panel2.ResumeLayout(False)
        Me.Panel1.ResumeLayout(False)
        Me.Panel5.ResumeLayout(False)
        Me.GroupBox2.ResumeLayout(False)
        CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.StatusBarPanel1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        '查询符合条件的记录
        Me.InitResultTable()    '初始化记录查询结果的datatable
        ListResult()            '显示查询结果
    End Sub

    '显示查询结果
    Private Sub ListResult()
        Dim objRecord As Object
        Dim objRS As GDO.GRecordset
        Dim dr, drNew As DataRow
        Dim bFinded As Boolean
        Dim strFilter, strOrigin, strAttribute, strValue As String
        Dim i As Integer

        Try
            Cursor.Current = Cursors.WaitCursor
            Me.StatusBarPanel1.Text = "正在查找..."

            OcxMapView.HighlightedObjects.Clear()           '清除所有高亮显示
            OcxMapView.MapViewSelectedObjects.Clear()       '清除所有选中的图形

            '生成过滤条件
            strFilter = ""
            For Each dr In Me.dtCondition.Rows
                strAttribute = dr("属性").ToString
                strValue = dr("值").ToString.ToUpper
                If strFilter <> "" Then
                    strFilter = strFilter + " and " + strAttribute + " Like '*" + strValue + "*' "
                Else
                    strFilter = strAttribute + " Like '*" + strValue + "*' "
                End If
            Next
            '生成记录集
            Common.GeometryOP.CreateRecordset(objRS, Me.strActiveTableName, strFilter)

            If objRS.RecordCount <= 0 Then
                Throw New Exception("查找数据库出错!")
            End If
            '生成查找结果DataTable
            objRS.MoveFirst()
            While Not objRS.EOF
                drNew = dtResult.NewRow
                For i = 0 To Me.chklistAttribute.Items.Count - 1
                    drNew(Me.chklistAttribute.Items(i)) = objRS.GFields(Me.chklistAttribute.Items(i)).Value
                Next
                dtResult.Rows.Add(drNew)
                objRS.MoveNext()
            End While

            Cursor.Current = Cursors.Default
            Me.DataGrid1.DataSource = dtResult      '显示查询结果
            Me.StatusBarPanel1.Text = "共找到" + dtResult.Rows.Count.ToString + "条记录"
            Exit Sub
        Catch ex As Exception
            Cursor.Current = Cursors.Default
            MsgBox(ex.Message, MSGBOX_ERROR)
            Me.StatusBarPanel1.Text = "查找出错!"
            Exit Sub
        End Try
    End Sub

    '初始化查询条件DataTable
    Private Sub InitConditionTable()
        Dim dc As DataColumn
        Me.dtCondition = New DataTable()
        dc = New DataColumn("属性")
        dc.ReadOnly = True
        dtCondition.Columns.Add(dc)
        dc = New DataColumn("值")
        dtCondition.Columns.Add(dc)

        Me.DataGridAttributeContent.DataSource = dtCondition
    End Sub

    '初始化查询结果DataTable
    Private Sub InitResultTable()
        Dim dc As DataColumn
        Dim i As Integer
        Me.dtResult = New DataTable()
        For i = 0 To Me.chklistAttribute.Items.Count - 1        '添加所有属性列(不包括图形列)
            dc = New DataColumn(Me.chklistAttribute.Items(i))
            dtResult.Columns.Add(dc)
        Next

        Me.DataGrid1.DataSource = dtResult
    End Sub

    Private Sub DataGrid1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.Click
        Dim objRS As GDO.GRecordset
        If DataGrid1.IsSelected(DataGrid1.CurrentRowIndex) Then
            '生成记录集
            Common.GeometryOP.CreateRecordset(objRS, strActiveTableName, "")
            Common.GeometryOP.HighlightGeometry(dtResult.Rows(DataGrid1.CurrentRowIndex)("ID"), objRS, Me.OcxMapView) '在图上高亮选中的记录对应的图形
            If OcxMapView.MapViewSelectedObjects.Count > 0 Then
                OcxMapView.CenterSelectedObjects()      '居中显示
            End If
        End If
    End Sub

    Private Sub InitForm()
        On Error GoTo ErrorHandler
        Dim alFeatureName As ArrayList
        Dim i As Integer

        Me.lstFeature.Items.Clear()
        '生成所有设备的列表
        alFeatureName = Common.GeometryOP.GetFeatureNameList()
        For i = 0 To alFeatureName.Count - 1
            Me.lstFeature.Items.Add(alFeatureName.Item(i))
        Next

        Exit Sub
ErrorHandler:
        MsgBox(Err.Description, MSGBOX_ERROR, "Select Feature")
    End Sub


    Private Sub lstFeature_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstFeature.SelectedIndexChanged
        On Error GoTo ErrorHandler
        Dim objMDSrvc As New GMService.MetadataService()
        'Populate attribute list with field names of currently selected table.
        '获取选中的设备所有的属性(图形除外)名称
        objMDSrvc.Connection = gobjConnection
        objMDSrvc.TableName = lstFeature.SelectedItem
        Me.strActiveTableName = lstFeature.SelectedItem

        Dim vFields As Object
        objMDSrvc.GetFields(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256, vFields) 'gmmfBoolean + gmmfByte + gmmfInteger + gmmfLong + gmmfCurrency + gmmfSingle + gmmfDouble + gmmfDate + gmmfText
        Me.chklistAttribute.Items.Clear()
        Me.dtCondition.Rows.Clear()

        '显示所有的属性
        Dim i As Long
        For i = LBound(vFields) To UBound(vFields) - 1
            chklistAttribute.Items.Add(vFields(i), False)
        Next
        chklistAttribute.SelectedIndex = 0   'select the first item
        GoTo Finish

ErrorHandler:
        MsgBox(Err.Number & " - " & Err.Source & Chr(13) & _
            Err.Description, vbOKOnly + vbExclamation)

Finish:
        On Error Resume Next
    End Sub

    Private Sub chklistAttribute_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles chklistAttribute.ItemCheck
        Dim i As Integer
        Dim dr, drTmp As DataRow

        '选中某一个属性则在属性内容列表中添加一个该属性条件
        If e.NewValue = CheckState.Checked Then
            dr = dtCondition.NewRow
            dr("属性") = chklistAttribute.Items(e.Index)
            dr("值") = ""
            dtCondition.Rows.Add(dr)
        Else    '否则,如果已有这个条件,则删除该条件
            For Each drTmp In dtCondition.Rows
                If drTmp("属性") = chklistAttribute.Items(e.Index) Then
                    drTmp.Delete()
                End If
            Next
        End If
        dtCondition.AcceptChanges()

        If dtCondition.Rows.Count > 0 Then
            Me.btnSearch.Enabled = True
        End If
    End Sub

    Private Sub FrmQuery_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.InitForm()
        Me.InitConditionTable()
    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub
End Class

⌨️ 快捷键说明

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