Timestamper Class Extension
TimestampPropPage.cls

' Copyright 2006 ESRI
'                 
' All rights reserved under the copyright laws of the United States
' and applicable international laws, treaties, and conventions.
' 
' You may freely redistribute and use this sample code, with or
' without modification, provided you include the original copyright
' notice and use restrictions.
' 
' See the use restrictions.

Option Explicit

Implements IComPropertyPage

Private m_pFrm As frmTimestampPropPage
Private m_sTitle As String
Private m_pObjectClass As IObjectClass


Private Sub Class_Initialize()

  ' Create the form but don't load it
  ' loading will be performed in the Activate method
  Set m_pFrm = New frmTimestampPropPage
  m_sTitle = m_pFrm.Caption
  
End Sub

Private Sub Class_Terminate()
  ' Cleanup
  Set m_pFrm = Nothing
  Set m_pObjectClass = Nothing
End Sub

 
Private Property Let IComPropertyPage_Title(ByVal bStr As String)
  m_sTitle = bStr
End Property
 
Private Property Get IComPropertyPage_Title() As String
  IComPropertyPage_Title = m_sTitle
End Property
 
Private Property Let IComPropertyPage_Priority(ByVal lValue As Long)

End Property
 
Private Property Get IComPropertyPage_Priority() As Long
  ' Appear after other property pages
  IComPropertyPage_Priority = -1
End Property
 
Private Property Get IComPropertyPage_Width() As Long
  m_pFrm.Picture1.ScaleMode = vbPixels
  IComPropertyPage_Width = m_pFrm.Picture1.ScaleWidth
End Property
 
Private Property Get IComPropertyPage_Height() As Long
  m_pFrm.Picture1.ScaleMode = vbPixels
  IComPropertyPage_Height = m_pFrm.Picture1.ScaleHeight
End Property
 
Private Property Set IComPropertyPage_PageSite(ByVal pComPropertyPageSite As esriFramework.IComPropertyPageSite)
  ' Set the PageSite in the form
  ' The PageSite will be used to enable the apply button when the content of
  ' the page has changed
  m_pFrm.PageSite = pComPropertyPageSite
End Property
 
Private Property Get IComPropertyPage_IsPageDirty() As Boolean
  ' If the form has changed return True for IsPageDirty
  IComPropertyPage_IsPageDirty = m_pFrm.IsDirty
End Property
 
Private Property Get IComPropertyPage_HelpFile() As String
  
  ' TODO: Add your implementation here
  
End Property
 
Private Property Get IComPropertyPage_HelpContextID(ByVal controlID As Long) As Long
  
  ' TODO: Add your implementation here
  
End Property
 
Private Function IComPropertyPage_Activate() As esriSystem.OLE_HANDLE
  Load m_pFrm

  ' Update the content of the property page with the current data
  ' from the object class
  Dim pTimestampClassExt As ITimestampClassExtension
  Set pTimestampClassExt = m_pObjectClass.Extension

  m_pFrm.cmbCreField.Clear
  m_pFrm.cmbModField.Clear
  m_pFrm.cmbUsrField.Clear
  
  m_pFrm.cmbCreField = pTimestampClassExt.CreationFieldName
  If Len(pTimestampClassExt.CreationFieldName) = 0 Then
    m_pFrm.cmbCreField.Text = "Not in use"
  End If
  
  m_pFrm.cmbModField = pTimestampClassExt.ModificationFieldName
  If Len(pTimestampClassExt.ModificationFieldName) = 0 Then
    m_pFrm.cmbModField.Text = "Not in use"
  End If

  m_pFrm.cmbUsrField = pTimestampClassExt.UserFieldName
  If Len(pTimestampClassExt.UserFieldName) = 0 Then
    m_pFrm.cmbUsrField.Text = "Not in use"
  End If
  
  m_pFrm.cmbCreField.AddItem "Not in use"
  m_pFrm.cmbModField.AddItem "Not in use"
  m_pFrm.cmbUsrField.AddItem "Not in use"
  
  Dim pFields As IFields
  Dim pField As IField
  Set pFields = m_pObjectClass.Fields
  Dim i As Long
  For i = 0 To pFields.FieldCount - 1
    Set pField = pFields.Field(i)
    If pField.Type = esriFieldTypeDate Then
      m_pFrm.cmbCreField.AddItem pField.Name
      m_pFrm.cmbModField.AddItem pField.Name
    ElseIf pField.Type = esriFieldTypeString Then
      m_pFrm.cmbUsrField.AddItem pField.Name
    End If
  Next i
  
  IComPropertyPage_Activate = m_pFrm.Picture1.hWnd
End Function
 
Private Sub IComPropertyPage_Deactivate()
  ' Unload the form when this page is decativated
  Unload m_pFrm
End Sub
 
Private Function IComPropertyPage_Applies(ByVal Objects As esriSystem.ISet) As Boolean

  IComPropertyPage_Applies = False
  'Apply if object class has a timestamp extension
  
  If (Objects.Count < 1) Then
    Exit Function
  End If

  Objects.Reset
  Dim pObject As IUnknown
  Set pObject = Objects.Next
  Do Until pObject Is Nothing
    If (TypeOf pObject Is IObjectClass) Then
      Dim pObjectClass As IObjectClass
      Set pObjectClass = pObject
      If Not pObjectClass.Extension Is Nothing Then
        If TypeOf pObjectClass.Extension Is ITimestampClassExtension Then
          IComPropertyPage_Applies = True
          Exit Function
        End If
      End If
    End If
    Set pObject = Objects.Next
  Loop
  
End Function
 
Private Sub IComPropertyPage_SetObjects(ByVal Objects As esriSystem.ISet)
  
  Objects.Reset
  Dim pObject As IUnknown
  Set pObject = Objects.Next
  Do Until pObject Is Nothing
    If (TypeOf pObject Is IObjectClass) Then
      Dim pObjectClass As IObjectClass
      Set pObjectClass = pObject
      
      If TypeOf pObjectClass.Extension Is ITimestampClassExtension Then
        Set m_pObjectClass = pObjectClass
        Exit Sub
      End If
    End If
    Set pObject = Objects.Next
  Loop

End Sub
 
Private Sub IComPropertyPage_Show()
  ' Show the property page by making the PictureBox visible.
  m_pFrm.Picture1.Visible = True
End Sub
 
Private Sub IComPropertyPage_Hide()
  m_pFrm.Picture1.Visible = False
End Sub
 
Private Sub IComPropertyPage_Apply()
  On Error GoTo ErrorHandler

  ' Make changes to extension properties to reflect what is on the form
  ' First take out a schema lock, to ensure no-one else is using the
  ' object class
  Dim pSchLock As ISchemaLock
  Set pSchLock = m_pObjectClass
  pSchLock.ChangeSchemaLock esriExclusiveSchemaLock
  Dim pTimestampClassExt As ITimestampClassExtension
  Set pTimestampClassExt = m_pObjectClass.Extension

  ' Set the class extension properties according to the form
  pTimestampClassExt.CreationFieldName = m_pFrm.cmbCreField
  If m_pFrm.cmbCreField = "Not in use" Then
    pTimestampClassExt.CreationFieldName = ""
  End If

  pTimestampClassExt.ModificationFieldName = m_pFrm.cmbModField
  If m_pFrm.cmbModField = "Not in use" Then
    pTimestampClassExt.ModificationFieldName = ""
  End If

  pTimestampClassExt.UserFieldName = m_pFrm.cmbUsrField
  If m_pFrm.cmbUsrField = "Not in use" Then
    pTimestampClassExt.UserFieldName = ""
  End If
 
  ' Update the properties in the geodatabase
  pTimestampClassExt.UpdateProperties
  
  ' Release schema lock
  pSchLock.ChangeSchemaLock esriSharedSchemaLock
  
  ' ObjectClass now reflects what is on form, so set IsDirty to false.
  m_pFrm.IsDirty = False
  Exit Sub
ErrorHandler:
' Report the error and release the lock
  MsgBox "Failed to apply the changes." & vbNewLine _
      & Err.Number & vbNewLine & Err.Description
  pSchLock.ChangeSchemaLock esriSharedSchemaLock

End Sub
 
Private Sub IComPropertyPage_Cancel()
  m_pFrm.IsDirty = False
End Sub