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

📄 form2.frm

📁 实现SDE图层和数据表的动态关联,时时更新
💻 FRM
字号:
VERSION 5.00
Object = "{9BD6A640-CE75-11D1-AF04-204C4F4F5020}#2.0#0"; "Mo20.ocx"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "Comdlg32.ocx"
Begin VB.Form Form2 
   Caption         =   "Form2"
   ClientHeight    =   5955
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   9285
   LinkTopic       =   "Form2"
   ScaleHeight     =   5955
   ScaleWidth      =   9285
   StartUpPosition =   3  'Windows Default
   Begin VB.TextBox Text1 
      Height          =   315
      Left            =   5865
      TabIndex        =   4
      Text            =   "Text1"
      Top             =   1605
      Width           =   2610
   End
   Begin MapObjects2.Map Map1 
      Height          =   5250
      Left            =   105
      TabIndex        =   3
      Top             =   75
      Width           =   5400
      _Version        =   131072
      _ExtentX        =   9525
      _ExtentY        =   9260
      _StockProps     =   225
      BackColor       =   16777215
      BorderStyle     =   1
      Contents        =   "Form2.frx":0000
   End
   Begin VB.ListBox List1 
      Height          =   2400
      Left            =   5790
      TabIndex        =   2
      Top             =   2055
      Width           =   1905
   End
   Begin VB.CommandButton Command2 
      Caption         =   "Command2"
      Height          =   420
      Left            =   6765
      TabIndex        =   1
      Top             =   1005
      Width           =   1860
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Command1"
      Height          =   450
      Left            =   6615
      TabIndex        =   0
      Top             =   285
      Width           =   1560
   End
   Begin MSComDlg.CommonDialog CommonDialog1 
      Left            =   5805
      Top             =   450
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin VB.Label Label1 
      Caption         =   "Label1"
      Height          =   285
      Left            =   7950
      TabIndex        =   5
      Top             =   2670
      Width           =   615
   End
End
Attribute VB_Name = "Form2"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub Command1_Click()
  '
  ' Ask user to identify the DBF for the Related table.
  '
'  Dim fName As String, dName As String
'  CommonDialog1.Filter = "dBASE files (*.dbf)|*.dbf"
'  CommonDialog1.ShowOpen
  '
  ' Connect to the DBF using DAO.
  '
'  If CommonDialog1.FileName <> "" And List1.ListIndex > -1 Then
    Dim pTable As New MapObjects2.Table
'    pTable.Database = "dBase IV;DATABASE=" & Left(CommonDialog1.FileName, Len(CommonDialog1.FileName) - Len(CommonDialog1.FileTitle) - 1)
'
'    pTable.Name = Left(CommonDialog1.FileTitle, Len(CommonDialog1.FileTitle) - 4)
'
'    pTable.Database = "Provider=SQLOLEDB.1;Persist Security Info=TRUE;User ID=sa;Password=110;Initial Catalog=patrolrPd;Data Source=readearth"
'    pTable.Name = "DBO.v_booster"
    
    Dim pLayer As MapObjects2.MapLayer, pFName As String, i As Integer
    Set pLayer = Map1.Layers(0)
    pFName = List1.List(List1.ListIndex)
    '
    ' First, check that the selected Field also appears in the Table.
    '
'    For i = 0 To pTable.Records.TableDesc.FieldCount - 1
'      If pTable.Records.TableDesc.FieldName(i) = pFName Then
        '
        ' Set cache size.

        '
        Dim pStrings As New MapObjects2.Strings
'        Dim pFields As New MapObjects2.Strings
        
        pStrings.Add "PDGAS.DBO.V_UniqueValue"
'        pFields.Add "编号"
'        pFields.Add "sde.v_Booster.AddNum"
         Set pLayer.FilterTables = pStrings
'         Set pLayer.FilterFields = pFields
         pLayer.FilterExpression = " PDGAS.SDE.TIAOYAQI.编号=PDGAS.DBO.V_UniqueValue.编号 "

        '
        ' Now perform the relate to the selected Field.
        '
'        If pLayer.AddRelate(pFName, pTable, "AddNum", True) Then
          ListLayers
'        Else
'          MsgBox "Failed Relate"
'        End If
'      End If
'    Next i

        Dim recE As MapObjects2.Recordset
        Dim pF As MapObjects2.Field
        Set recE = pLayer.Records
        recE.MoveFirst
        
        For Each pF In recE.Fields
            Debug.Print pF.Name & pF.ValueAsString
        Next
        Do While Not recE.EOF
'            For Each pF In recE.Fields
            Debug.Print recE("编号").Value
            Debug.Print recE("PDGAS.DBO.V_UniqueValue.UniqueType").ValueAsString
'            Next
            recE.MoveNext
        Loop
'  Else
'    MsgBox "Please select a Field from the list, and a file, and try again."
'  End If
End Sub

Private Sub Command2_Click()
  '
  ' Remove all existing Relates.

  '
  Map1.Layers(0).RemoveRelates
  ListLayers
End Sub

Private Sub ListLayers()
  '
  ' This procedure lists all the Fields in the MapLayer.
  '
  List1.Clear
  Dim pFld As MapObjects2.Field
  For Each pFld In Map1.Layers(0).Records.Fields
    List1.AddItem pFld.Name
  Next pFld
End Sub

Private Sub Form_Load()
Dim dc As New MapObjects2.DataConnection

    dc.Server = "SDE92:mm"
  dc.User = "sde"
  dc.Password = "sde"
  dc.Database = "instance=port:5152"

  
   
    
  If dc.Connect Then
    
     Dim layer As New MapObjects2.MapLayer
    layer.GeoDataset = dc.FindGeoDataset("PDGAS.SDE.TIAOYAQI.SHAPE.Points")
    Me.Map1.Layers.Add layer
End If
ListLayers
  Command1.Caption = "Add Relate"
  Command2.Caption = "Remove Relates"
  Text1.Text = "100"
  Label1.Caption = "Max cache size"

  Label1.Alignment = 1
  
  
  
End Sub

Private Sub Form_Resize()
  Map1.Move 0, 0, Me.ScaleWidth * 0.7, (Me.ScaleHeight * 0.8) - 60
  Label1.Move 0, Map1.Top + Map1.Height + 30, Map1.Width * 0.49, Me.ScaleHeight * 0.09
  Text1.Move Label1.Left + Label1.Width + 60, Label1.Top, Label1.Width, Label1.Height
  Command1.Move Label1.Left, Label1.Top + Label1.Height + 30, Label1.Width, Label1.Height
  Command2.Move Text1.Left, Command1.Top, Command1.Width, Command1.Height
  List1.Move Map1.Left + Map1.Width + 30, 0, Me.ScaleWidth * 0.3 - 30, Me.ScaleHeight

  
End Sub

⌨️ 快捷键说明

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