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("IntrastatHeader - Disable DocumentNumber", AppearanceItemType.ViewItem, "1=1", TargetItems:="DocumentNumber", Enabled:=False)> _
<Appearance("IntrastatHeader - Disable ObjectCreated", AppearanceItemType.ViewItem, "1=1", TargetItems:="ObjectCreated", Enabled:=False)> _
<Appearance("IntrastatHeader - Disable UserCreate", AppearanceItemType.ViewItem, "1=1", TargetItems:="UserCreate", Enabled:=False)> _
Public Class IntrastatHeader
    Inherits BaseObject

    Private _IntrastatParameters As IntrastatParameters
    Private _UserCreated As User
    Private _ObjectCreated As Date
    Private _DateExecution As Date 'Időszak Év, hónap
    Private _DocumentNumber As String
    Private _DocumentFile As FileData

    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
        If String.IsNullOrEmpty(DocumentNumber) Then DocumentNumber = IntrastatParameters.NumberGenerator.GetNewNumber(IntrastatParameters.NumberGenerator)
    End Sub

    <RuleRequiredField("IntrastatHeader - IntrastatParameters", DefaultContexts.Save)> _
    Property IntrastatParameters As IntrastatParameters
        Get
            Return _IntrastatParameters
        End Get
        Set(value As IntrastatParameters)
            SetPropertyValue("IntrastatParameters", _IntrastatParameters, 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
    <NonCloneable> _
    Property ObjectCreated As Date
        Get
            Return _ObjectCreated
        End Get
        Set(value As Date)
            SetPropertyValue("ObjectCreated", _ObjectCreated, value)
        End Set
    End Property
    Property DateExecution As Date
        Get
            Return _DateExecution
        End Get
        Set(value As Date)
            SetPropertyValue("DateExecution", _DateExecution, value)
        End Set
    End Property
    Property DocumentNumber As String
        Get
            Return _DocumentNumber
        End Get
        Set(value As String)
            SetPropertyValue("DocumentNumber", _DocumentNumber, value)
        End Set
    End Property
    Property DocumentFile As FileData
        Get
            Return _DocumentFile
        End Get
        Set(value As FileData)
            SetPropertyValue("DocumentFile", _DocumentFile, value)
        End Set
    End Property

    '-------ReadONLY-------
    <Association("IntrastatHeader - IntrastatRows", GetType(IntrastatRows)), VisibleInListView(False)> _
    ReadOnly Property IntrastatRows As XPCollection(Of IntrastatRows)
        Get
            Return GetCollection(Of IntrastatRows)("IntrastatRows")
        End Get
    End Property

End Class
