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

'User.Oid = CurrentUserId()

Public Enum eViewMode
    eTableView = 0
    ePivotView = 1
    eBothView = 2
End Enum
<Appearance("InvoiceRowsPivot - Hide InvoiceRows_Table",
    AppearanceItemType:="ViewItem",
    Criteria:="ViewMode in (1)",
    TargetItems:="InvoiceRows_Table",
    Visibility:=ViewItemVisibility.Hide)> _
<Appearance("InvoiceRowsPivot - Hide InvoiceRows_Pivot",
    AppearanceItemType:="ViewItem",
    Criteria:="ViewMode in (0)",
    TargetItems:="InvoiceRows_Pivot",
    Visibility:=ViewItemVisibility.Hide)> _
<Appearance("InvoiceRowsPivot - Hide Criteria",
    AppearanceItemType:="ViewItem",
    Criteria:="UserCreated.Oid = CurrentUserId()",
    TargetItems:="Criteria",
    Visibility:=ViewItemVisibility.Hide)> _
<DefaultClassOptions(), NavigationItem(False), CreatableItem(False)> _
Public Class InvoiceRowsPivot
    Inherits BaseObject

    Private _CustomersFrom As CustomersFrom
    Private _ShortName As String
    Private _ObjectCreated As Date
    Private _UserCreated As User

    Private _Criteria As String 'Kritéria szûréshez !
    Private _ViewMode As eViewMode
    Private _InvoiceRows As InvoiceRows

    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
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
        ' Place here your initialization code.
    End Sub
    Protected Overrides Sub OnSaving()
        MyBase.OnSaving()
        If Me.UserCreated Is Nothing Then
            ObjectCreated = GetSQLTime(Session)
            UserCreated = Session.GetObjectByKey(Of User)(Session.GetKeyValue(SecuritySystem.CurrentUser))
        End If
    End Sub
    <RuleRequiredField("InvoiceRowsPivot-CustomersFrom", DefaultContexts.Save)> _
    Property CustomersFrom As CustomersFrom
        Get
            Return _CustomersFrom
        End Get
        Set(value As CustomersFrom)
            SetPropertyValue("CustomersFrom", _CustomersFrom, value)
        End Set
    End Property
    <RuleRequiredField("InvoiceRowsPivot-ShortName", DefaultContexts.Save)> _
    Property ShortName As String
        Get
            Return _ShortName
        End Get
        Set(value As String)
            SetPropertyValue("ShortName", _ShortName, 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
    <CriteriaOptionsAttribute("ObjectType"), Size(-1), ImmediatePostData(True)> _
    Property Criteria As String
        Get
            Return _Criteria
        End Get
        Set(value As String)
            SetPropertyValue("Criteria", _Criteria, value)
        End Set
    End Property
    <NonPersistent(), MemberDesignTimeVisibility(False)> _
    Public Property ObjectType() As Type
        Get
            Return GetType(InvoiceRows)
        End Get
        Set(ByVal value As Type)

        End Set
    End Property
    Property ViewMode As eViewMode
        Get
            Return _ViewMode
        End Get
        Set(value As eViewMode)
            SetPropertyValue("ViewMode", _ViewMode, value)
        End Set
    End Property
    ReadOnly Property InvoiceRows_Table As XPCollection(Of InvoiceRows)
        Get
            Dim _InvoiceRows_Collection As XPCollection(Of InvoiceRows)
            Dim _FullCriteria As String = "isnull(InvoiceHeader.GCRecord)=True and InvoiceHeader.CustomersFrom=? and InvoiceHeader.IsEditable=False and InvoiceHeader.DocumentNumber !=''"

            If String.IsNullOrEmpty(Criteria) = False Then
                _FullCriteria = "(" & _FullCriteria & ") and (" & Criteria & ")"
            End If

            _InvoiceRows_Collection = New XPCollection(Of InvoiceRows)(Session, CriteriaOperator.Parse(_FullCriteria, CustomersFrom))

            Return _InvoiceRows_Collection
        End Get
    End Property
    ReadOnly Property InvoiceRows_Pivot As XPCollection(Of InvoiceRows)
        Get
            Dim _InvoiceRows_Collection As XPCollection(Of InvoiceRows)
            Dim _FullCriteria As String = "isnull(InvoiceHeader.GCRecord)=True and InvoiceHeader.CustomersFrom=? and InvoiceHeader.IsEditable=False and InvoiceHeader.DocumentNumber !=''"

            If String.IsNullOrEmpty(Criteria) = False Then
                _FullCriteria = "(" & _FullCriteria & ") and (" & Criteria & ")"
            End If

            _InvoiceRows_Collection = New XPCollection(Of InvoiceRows)(Session, CriteriaOperator.Parse(_FullCriteria, CustomersFrom))

            Return _InvoiceRows_Collection
        End Get
    End Property

    <Association("InvoiceRowsPivot-InvoiceRowsPivotUser", GetType(InvoiceRowsPivotUser)), VisibleInListView(False), VisibleInLookupListView(False)> _
    ReadOnly Property InvoiceRowsPivotUser As XPCollection(Of InvoiceRowsPivotUser)
        Get
            Return GetCollection(Of InvoiceRowsPivotUser)("InvoiceRowsPivotUser")
        End Get
    End Property
End Class
