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
Imports DevExpress.ExpressApp.Editors

<DefaultClassOptions(), NavigationItem(False), CreatableItem(False)> _
<Appearance("Hide CustomersFrom if IsCustomersFrom=True", AppearanceItemType:="ViewItem", criteria:="IsCustomersFrom=True", targetitems:="CustomersFrom", visibility:=ViewItemVisibility.Hide)> _
Public Class GLReportCashflowHeader
    Inherits BaseObject

    Private _GLReportDashboardType As eGLReportDashboardType
    Private _CustomersFrom As CustomersFrom
    Private _ShortName As String
    Private _FromDate As Date
    Private _ToDate As Date
    Private _ObjectCreated As Date
    Private _UserCreated As User
    Private _IsCustomersFrom As Boolean = False 'True akkor cégfüggetlen lekérdezés

    Public Sub New(ByVal session As Session)
        MyBase.New(session)
        ' This constructor is used when an object is loaded from a persistent storage.
        ' Do not place any code here or place it only when the IsLoading property is false:
        ' if (!IsLoading){
        '   It is now OK to place your initialization code here.
        ' }
        ' or as an alternative, move your initialization code into the AfterConstruction method.
    End Sub
    Protected Overrides Sub OnSaving()
        MyBase.OnSaving()
        MyBase.OnSaving()
        If Session.IsNewObject(Me) Then
            ObjectCreated = GetSQLTime(Session)
            UserCreated = Session.GetObjectByKey(Of User)(Session.GetKeyValue(SecuritySystem.CurrentUser))
        End If
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
        ' Place here your initialization code.
        Me.FromDate = FirstDayOfYear(GetSQLTime(Session))
        Me.ToDate = LastDayOfYear(GetSQLTime(Session))
    End Sub

    Property GLReportDashboardType As eGLReportDashboardType
        Get
            Return _GLReportDashboardType
        End Get
        Set(value As eGLReportDashboardType)
            SetPropertyValue("GLReportDashboardType", _GLReportDashboardType, value)
        End Set
    End Property
    Property CustomersFrom As CustomersFrom
        Get
            Return _CustomersFrom
        End Get
        Set(value As CustomersFrom)
            SetPropertyValue("CustomersFrom", _CustomersFrom, value)
        End Set
    End Property
    <RuleRequiredField("GLReportCashflowHeader-ShortName", DefaultContexts.Save)> _
    Property ShortName As String
        Get
            Return _ShortName
        End Get
        Set(ByVal value As String)
            SetPropertyValue("ShortName", _ShortName, value)
        End Set
    End Property
    Property FromDate As Date
        Get
            Return _FromDate
        End Get
        Set(value As Date)
            SetPropertyValue("FromDate", _FromDate, value)
        End Set
    End Property
    Property ToDate As Date
        Get
            Return _ToDate
        End Get
        Set(value As Date)
            SetPropertyValue("ToDate", _ToDate, 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
    <ImmediatePostData(True)> _
    Property IsCustomersFrom As Boolean
        Get
            Return _IsCustomersFrom
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsCustomersFrom", _IsCustomersFrom, value)
        End Set
    End Property

    <Association("GLReportCashflowHeader-GLReportCashflowRows", GetType(GLReportCashflowRows)), VisibleInListView(False), VisibleInLookupListView(False)> _
    ReadOnly Property GLReportCashflowRows As XPCollection(Of GLReportCashflowRows)
        Get
            Return GetCollection(Of GLReportCashflowRows)("GLReportCashflowRows")
        End Get
    End Property
    <VisibleInListView(False), VisibleInLookupListView(False)> _
    ReadOnly Property QueryStatistics As XPCollection(Of QueryStatistics)
        Get
            Return New XPCollection(Of QueryStatistics)(Session, CriteriaOperator.Parse("ObjectName=? and ObjectKey=?", "GLReportCashflowHeader", Me.Oid))
        End Get
    End Property
End Class
