Imports System
Imports System.ComponentModel

Imports DevExpress.Xpo
Imports DevExpress.Data.Filtering

Imports DevExpress.ExpressApp
Imports DevExpress.Persistent.Base
Imports DevExpress.Persistent.BaseImpl
Imports DevExpress.Persistent.Validation
Imports DevExpress.ExpressApp.ConditionalAppearance

<DefaultClassOptions()> _
<NavigationItem(False)> _
<CreatableItem(False)> _
<Appearance("RTFDocumentsHandler - Disable ObjectCreated", AppearanceItemType.ViewItem, "1=1", TargetItems:="ObjectCreated", Enabled:=False)> _
<Appearance("RTFDocumentsHandler - Disable UserCreated", AppearanceItemType.ViewItem, "1=1", TargetItems:="UserCreated", Enabled:=False)> _
Public Class RTFDocumentsHandler
    Inherits BaseObject

    Private _ShortName As String
    Private _Version As String

    Private _ObjectCreated As Date
    Private _UserCreated As User
    Private _HRPerson As HRPerson

    Private _DocumentBody As String
    Private _IsEditable As Boolean = True

    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
    End Sub
    Protected Overrides Sub OnSaving()
        MyBase.OnSaving()
        If Session.IsNewObject(Me) Then
            ObjectCreated = GetSQLTime(Session)
            UserCreated = Session.GetObjectByKey(Of User)(Session.GetKeyValue(SecuritySystem.CurrentUser))
        End If
    End Sub
    <RuleRequiredField("RTFDocumentsHandler-ShortName", DefaultContexts.Save)> _
    Property ShortName As String
        Get
            Return _ShortName
        End Get
        Set(value As String)
            SetPropertyValue("ShortName", _ShortName, value)
        End Set
    End Property
    Property Version As String
        Get
            Return _Version
        End Get
        Set(value As String)
            SetPropertyValue("Version", _Version, value)
        End Set
    End Property
    <NonCloneable> _
    Property ObjectCreated As Date
        Get
            Return _ObjectCreated
        End Get
        Set(value As Date)
            SetPropertyValue("ObjectCreated", _ObjectCreated, value)
        End Set
    End Property
    <NonCloneable> _
    Property UserCreated As User
        Get
            Return _UserCreated
        End Get
        Set(value As User)
            SetPropertyValue("UserCreated", _UserCreated, value)
        End Set
    End Property
    Property HRPerson As HRPerson
        Get
            Return _HRPerson
        End Get
        Set(value As HRPerson)
            SetPropertyValue("HRPerson", _HRPerson, value)
        End Set
    End Property
    <Size(-1), ImmediatePostData()> _
    Property DocumentBody As String
        Get
            Return _DocumentBody
        End Get
        Set(value As String)
            SetPropertyValue("DocumentBody", _DocumentBody, value)
        End Set
    End Property
    Property IsEditable As Boolean
        Get
            Return _IsEditable
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsEditable", _IsEditable, value)
        End Set
    End Property

    '-------Audit--------------
    <VisibleInListView(False)> _
    <VisibleInLookupListView(False)> _
    ReadOnly Property AuditTrail() As XPCollection(Of AuditDataItemPersistent)
        Get
            Return AuditedObjectWeakReference.GetAuditTrail(Session, Me)
        End Get
    End Property
    'Dim _AuditDataItemPersistent_Collection As XPCollection(Of AuditDataItemPersistent)
    'Dim _AuditDataItemPersistent As AuditDataItemPersistent

    '    If TryCast(_Object, RegistryHeader) IsNot Nothing Then
    '        _AuditDataItemPersistent_Collection = AuditedObjectWeakReference.GetAuditTrail(_uow, _Object)
    '        For Each _AuditDataItemPersistent In _AuditDataItemPersistent_Collection
    '            If _AuditDataItemPersistent.PropertyName = "DocumentNumber" Then

    '            End If
    '        Next
    '    End If

End Class
