Imports DevExpress.Xpo
Imports DevExpress.Data.Filtering
Imports DevExpress.Persistent.Base
Imports DevExpress.Persistent.BaseImpl
Imports DevExpress.Persistent.Validation

<DefaultClassOptions()> _
<NavigationItem("BusinessStocks")> _
Public Class ProductsGroups
    Inherits HCategory
    Private _ShortName As String
    Private _Description As String
    Private _ReportData As ReportData
    Private _MasterBusinessDirectory As BusinessDirectory
    Private _DocumentPath As String 'Windows Explorer path

    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    <RuleRequiredField("ProductsGroups - 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
    <Size(-1)> _
    Property Description() As String
        Get
            Return _Description
        End Get
        Set(ByVal value As String)
            SetPropertyValue("Description", _Description, value)
        End Set
    End Property
    Property ReportData As ReportData
        Get
            Return _ReportData
        End Get
        Set(value As ReportData)
            SetPropertyValue("ReportData", _ReportData, value)
        End Set
    End Property
    Property MasterBusinessDirectory As BusinessDirectory
        Get
            Return _MasterBusinessDirectory
        End Get
        Set(value As BusinessDirectory)
            SetPropertyValue("MasterBusinessDirectory", _MasterBusinessDirectory, value)
        End Set
    End Property
    <VisibleInListView(False), Aggregated(), Association("ProductsGroups-ProductsGroupsDocumentations", GetType(ProductsGroupsDocumentations))> _
    Public ReadOnly Property ProductsGroupsDocumentations() As XPCollection(Of ProductsGroupsDocumentations)
        Get
            Return GetCollection(Of ProductsGroupsDocumentations)("ProductsGroupsDocumentations")
        End Get
    End Property
    <VisibleInListView(False), VisibleInLookupListView(False)> _
    Public ReadOnly Property ProductsGroups_BusinessDirectory As XPCollection(Of BusinessDirectory)
        Get
            Dim _BusinessDirectory_Collection As New XPCollection(Of BusinessDirectory)(Session, CriteriaOperator.Parse("1=2"))

            If MasterBusinessDirectory IsNot Nothing Then
                If MasterBusinessDirectory.Children.Count > 0 Then
                    _BusinessDirectory_Collection.Add(MasterBusinessDirectory)
                    RecursiveBusinessDirectory(_BusinessDirectory_Collection, MasterBusinessDirectory.NestedBusinessDirectory)
                Else
                    _BusinessDirectory_Collection.Add(MasterBusinessDirectory)
                End If
            End If
            Return _BusinessDirectory_Collection
        End Get
    End Property
    <Size(900)> _
    Property DocumentPath As String
        Get
            Return _DocumentPath
        End Get
        Set(value As String)
            SetPropertyValue("DocumentPath", _DocumentPath, value)
        End Set
    End Property

#Region "Other subs"
    Private Sub RecursiveBusinessDirectory(_BusinessDirectoryList As XPCollection(Of BusinessDirectory), _NestedBusinessDirectory As XPCollection(Of BusinessDirectory))
        For Each _BusinessDirectory As BusinessDirectory In _NestedBusinessDirectory
            If _BusinessDirectory.Children.Count > 0 Then
                _BusinessDirectoryList.Add(_BusinessDirectory)
                RecursiveBusinessDirectory(_BusinessDirectoryList, _BusinessDirectory.NestedBusinessDirectory)
            Else
                _BusinessDirectoryList.Add(_BusinessDirectory)
            End If
        Next
    End Sub
#End Region

End Class







