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

Public Enum eVATAvowalType 'ÁFA bevallási mód
    eGeneral = 0 'Általános
    eFinancial = 1 'Pénzügyi
End Enum
<DefaultClassOptions()> _
<NavigationItem("Customers")> _
<DefaultProperty("FullName")> _
<Appearance("APCSheetHeader - Disable all properties, when IsNull(Url_DH)=False AND Url_DH=''", AppearanceItemType.ViewItem, "IsNull(Url_DH)=False AND Url_DH<>''", TargetItems:="*", Enabled:=False)> _
Public Class Customers
    Inherits Organization

    Private _CustomerNumber As String = "" 'Ügyfél azonosítója
    Private _VATNumber As String 'Adószám (belföldi)
    Private _VATNumberEU As String 'EU adószám
    Private _CustomersGLParameters As CustomersGLParameters 'Ügyfél főkönyvi kategária
    Private _CustomersNG As CustomersNG 'Ügyfél sorszám generátor
    Private _Pricing As Pricing 'Árképzés ha vevő az ügyfél
    Private _PricingIn As Pricing 'Árképzés ha vásárolunk tőle
    Private _CreditlineAmountHUF As Double 'Hitelkeret forintos összege
    Private _CreditlineAmountDEV As Double 'Hitelkeret devizás összege
    Private _CreditlineDay As Long 'Hitelkeret max késés nap.
    Private _IsAssetsHandling As Boolean  'Lesz e kinnlévőség kezelése
    Private _CRM_Leads As CRM_Leads
    Private _ImportedID As Long
    Private _LateChargesCountMode As LateChargesCountMode 'A késedelmes kamatszámítás módja
    Private _Citizen As String 'Állampolgársága
    Private _AssetsHandling_Note As String 'Kinnlévőség megjegyzés

    Private _PaymentOption As PaymentOption
    Private _ShipmentOption As ShipmentOption
    Private _QualityOption As QualityOption

    Private _FarmerCardNumber As String 'Őstermelői igazolvány száma
    Private _BusinessCardNumber As String 'Vállalkozói igazolvány száma
    Private _MVHRegistrationNumber As String 'MVH regisztrációs szám
    Private _CompanyRegistrationNumber As String 'Cégjegyzékszám
    Private _CompanyStatisticsNumber As String 'Cég statisztikai számjele
    Private _FamilyFarmNumber As String 'Családi gazdaság azonosító szám
    Private _MotherName As String 'Anyja neve
    Private _BirthAddress As Address 'Születési helye
    Private _BirthDate As Date 'Születési ideje
    Private _TAJNumber As String

    Private _LyonessID As String 'Lyoness ID azonosító
    Private _LyonessCardID As String 'Lyoness kártyaszám azonosító

    Private _ClassificationByProduct As ClassificationByProduct
    Private _ClassificationByMoney As ClassificationByMoney
    Private _ClassificationByPersonal As ClassificationByPersonal

    Private _SupplierMark As String 'Ha a partner beszállító, akkor egy rövid karaktersorozat
    Private _SupplierMarkInfo As String 'Beszállítói azonosító string

    Private _Checked As Boolean
    Private _CheckedDate As DateTime
    Private _CheckStatus As String

    Private _Contact_Decision As Contacts 'Döntéshozó, ügyvezető
    Private _Contact_Finance As Contacts 'Pénzüggyel kapcsolatos kapcsolattartó
    Private _EMail_Invoice As String 'e-mail cím, ahova PDF-ben elmegy a kiállított számla

    Private _HRPerson_SalesPerson As HRPerson 'A céghez tartozó HRPerson mint üzletkötő
    Private _MasterBusinessDirectory As BusinessDirectory
    Private _DocumentPath As String 'Windows Explorer path
    Private _VATAvowalType As eVATAvowalType 'ÁFA bevallás módja
    Private _Oid_DH As String
    Private _Url_DH As String
    Private _CanUseMarketingInfo As Boolean 'Marketininfó
    Private _CanUseMarketingInfoThirdParts As Boolean 'Marketing info 3. félnek

    Private _ObjectCreated As Date
    Private _UserCreated As User
    Private _ObjectChanged As Date
    Private _UserChanged As User
    Private _QueueUpdated As Date

    Private _PriceColumn As Integer 'Ároszlop, melyik PriceColumnBruttoHUFXX ára van

    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Protected Overrides Sub OnSaving()
        MyBase.OnSaving()
        If Session.IsNewObject(Me) Then
            If SecuritySystem.CurrentUser IsNot Nothing Then
                UserCreated = Session.GetObjectByKey(Of User)(Session.GetKeyValue(SecuritySystem.CurrentUser))
            End If
            UserChanged = UserCreated
            ObjectCreated = GetSQLTime(Session)
            ObjectChanged = ObjectCreated
            QueueUpdated = Date.MinValue
        Else
            If SecuritySystem.CurrentUser IsNot Nothing Then
                UserChanged = Session.GetObjectByKey(Of User)(Session.GetKeyValue(SecuritySystem.CurrentUser))
                ObjectChanged = GetSQLTime(Session)
            End If
        End If
        ' Az partner duplázódás elkerülése miatt megkeressük, hogy létezik-e ilyen partner a megadott adószámmal

        'If Me.VATNumber <> "" Then
        '    Dim _Customers As Customers = Session.FindObject(Of Customers)(CriteriaOperator.Parse("VATNumber=?", Me.VATNumber))
        '    If _Customers IsNot Nothing Then
        '        If _Customers.Oid <> Me.Oid Then
        '            '----TESZT MIATT-----------------------------------------------
        '            Throw New Exception("*A megadott adószámmal már létezik ügyfél!")
        '        End If
        '    End If
        'End If
        'Sorszám kiosztása
        If LTrim(RTrim(Me.CustomerNumber)) = "" Then
            If Me.CustomersNG IsNot Nothing Then
                If Session.IsNewObject(Me) = True Then
                    Me.CustomerNumber = Me.CustomersNG.NumberGenerator.GetNewNumber(Me.CustomersNG.NumberGenerator)
                End If
            Else
                '--------- TESZT MIATT!! --------------------------------------
                Throw New Exception("*Nincs beállítva a sorszámgenerátor paraméter!")
            End If
        End If
        If IsDeleted = False Then
            If Name = "" And FullName <> "" Then
                Name = FullName
            End If
            If FullName = "" And Name <> "" Then
                FullName = Name
            End If
        End If
        If Checked = True Then
            CheckedDate = GetSQLTime(Session)
        End If
    End Sub

    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
        CustomersNG = Session.FindObject(Of CustomersNG)(CriteriaOperator.Parse("Oid=Oid"))
        Citizen = "Magyar"
        IsAssetsHandling = True
        Checked = False
        CanUseMarketingInfo = False
        CanUseMarketingInfoThirdParts = False
        Url_DH = Nothing
        CustomersGLParameters = Session.FindObject(Of CustomersGLParameters)(CriteriaOperator.Parse("DefaultforBusiness=True"))
    End Sub

    <RuleUniqueValue("Customers-CustomerNumber", DefaultContexts.Save, CriteriaEvaluationBehavior:=PersistentCriteriaEvaluationBehavior.InTransaction)> _
    <NonCloneable()> _
    Property CustomerNumber As String
        Get
            Return _CustomerNumber
        End Get
        Set(ByVal value As String)
            SetPropertyValue("CustomerNumber", _CustomerNumber, value)
        End Set
    End Property
    <RuleUniqueValue("Customers-VATNumber", DefaultContexts.Save, skipnulloremptyvalues:=True)> _
    Property VATNumber As String
        Get
            Return _VATNumber
        End Get
        Set(ByVal value As String)
            SetPropertyValue("VATNumber", _VATNumber, value)
        End Set
    End Property
    <RuleUniqueValue("Customers-VATNumberEU", DefaultContexts.Save, skipnulloremptyvalues:=True)> _
    Property VATNumberEU As String
        Get
            Return _VATNumberEU
        End Get
        Set(ByVal value As String)
            SetPropertyValue("VATNumberEU", _VATNumberEU, value)
        End Set
    End Property
    <RuleRequiredField("Customers-CustomersGLParameters", DefaultContexts.Save)> _
    <VisibleInDetailView(False)> _
    <VisibleInListView(False)> _
    <VisibleInLookupListView(False)> _
    Property CustomersGLParameters() As CustomersGLParameters
        Get
            Return _CustomersGLParameters
        End Get
        Set(ByVal value As CustomersGLParameters)
            SetPropertyValue("CustomersGLParameters", _CustomersGLParameters, value)
        End Set
    End Property
    <RuleRequiredField("Customers-CustomersNG", DefaultContexts.Save)> _
    Property CustomersNG As CustomersNG
        Get
            If _CustomersNG Is Nothing Then
                If (Not IsSaving) AndAlso (Not IsLoading) Then
                    _CustomersNG = Session.FindObject(Of CustomersNG)(1, CriteriaOperator.Parse("Oid=Oid"))
                End If
            End If
            Return _CustomersNG
        End Get
        Set(ByVal value As CustomersNG)
            SetPropertyValue("CustomersNG", _CustomersNG, value)
        End Set
    End Property
    Property Pricing As Pricing
        Get
            Return _Pricing
        End Get
        Set(ByVal value As Pricing)
            SetPropertyValue("Pricing", _Pricing, value)
        End Set
    End Property
    Property PricingIn As Pricing
        Get
            Return _PricingIn
        End Get
        Set(ByVal value As Pricing)
            SetPropertyValue("PricingIn", _PricingIn, value)
        End Set
    End Property
    Property IsAssetsHandling As Boolean
        Get
            Return _IsAssetsHandling
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsAssetsHandling", _IsAssetsHandling, value)
        End Set
    End Property
    <Browsable(False)> _
    Property CRM_Leads As CRM_Leads
        Get
            Return _CRM_Leads
        End Get
        Set(value As CRM_Leads)
            SetPropertyValue("CRM_Leads", _CRM_Leads, value)
        End Set
    End Property
    <Browsable(False)> _
    Property ImportedID As Long
        Get
            Return _ImportedID
        End Get
        Set(value As Long)
            SetPropertyValue("ImportedID", _ImportedID, value)
        End Set
    End Property
    Property CreditlineAmountHUF As Double
        Get
            Return _CreditlineAmountHUF
        End Get
        Set(value As Double)
            SetPropertyValue("CreditlineAmountHUF", _CreditlineAmountHUF, value)
        End Set
    End Property
    Property CreditlineAmountDEV As Double
        Get
            Return _CreditlineAmountDEV
        End Get
        Set(value As Double)
            SetPropertyValue("CreditlineAmountDEV", _CreditlineAmountDEV, value)
        End Set
    End Property
    Property CreditlineDay As Long
        Get
            Return _CreditlineDay
        End Get
        Set(value As Long)
            SetPropertyValue("CreditlineDay", _CreditlineDay, value)
        End Set
    End Property
    Property LateChargesCountMode As LateChargesCountMode
        Get
            Return _LateChargesCountMode
        End Get
        Set(value As LateChargesCountMode)
            SetPropertyValue("LateChargesCountMode", _LateChargesCountMode, value)
        End Set
    End Property
    Property Citizen As String
        Get
            Return _Citizen
        End Get
        Set(value As String)
            SetPropertyValue("Citizen", _Citizen, value)
        End Set
    End Property
    <Size(-1)> _
    Property AssetsHandling_Note As String
        Get
            Return _AssetsHandling_Note
        End Get
        Set(value As String)
            SetPropertyValue("AssetsHandling_Note", _AssetsHandling_Note, value)
        End Set
    End Property
    Public Property PaymentOption() As PaymentOption
        Get
            Return _PaymentOption
        End Get
        Set(ByVal value As PaymentOption)
            SetPropertyValue("PaymentOption", _PaymentOption, value)
        End Set
    End Property
    Public Property ShipmentOption() As ShipmentOption
        Get
            Return _ShipmentOption
        End Get
        Set(ByVal value As ShipmentOption)
            SetPropertyValue("ShipmentOption", _ShipmentOption, value)
        End Set
    End Property
    Public Property QualityOption() As QualityOption
        Get
            Return _QualityOption
        End Get
        Set(ByVal value As QualityOption)
            SetPropertyValue("QualityOption", _QualityOption, value)
        End Set
    End Property

    Property ClassificationByProduct As ClassificationByProduct
        Get
            Return _ClassificationByProduct
        End Get
        Set(value As ClassificationByProduct)
            SetPropertyValue("ClassificationByProduct", _ClassificationByProduct, value)
        End Set
    End Property
    Property ClassificationByMoney As ClassificationByMoney
        Get
            Return _ClassificationByMoney
        End Get
        Set(value As ClassificationByMoney)
            SetPropertyValue("ClassificationByMoney", _ClassificationByMoney, value)
        End Set
    End Property
    Property ClassificationByPersonal As ClassificationByPersonal
        Get
            Return _ClassificationByPersonal
        End Get
        Set(value As ClassificationByPersonal)
            SetPropertyValue("ClassificationByPersonal", _ClassificationByPersonal, value)
        End Set
    End Property
    '// Őstermelőhöz
    Property FarmerCardNumber As String
        Get
            Return _FarmerCardNumber
        End Get
        Set(value As String)
            SetPropertyValue("FarmerCardNumber", _FarmerCardNumber, value)
        End Set
    End Property
    Property BusinessCardNumber As String
        Get
            Return _BusinessCardNumber
        End Get
        Set(value As String)
            SetPropertyValue("BusinessCardNumber", _BusinessCardNumber, value)
        End Set
    End Property
    Property MVHRegistrationNumber As String
        Get
            Return _MVHRegistrationNumber
        End Get
        Set(value As String)
            SetPropertyValue("MVHRegistrationNumber", _MVHRegistrationNumber, value)
        End Set
    End Property
    Property CompanyRegistrationNumber As String
        Get
            Return _CompanyRegistrationNumber
        End Get
        Set(value As String)
            SetPropertyValue("CompanyRegistrationNumber", _CompanyRegistrationNumber, value)
        End Set
    End Property
    Property CompanyStatisticsNumber As String
        Get
            Return _CompanyStatisticsNumber
        End Get
        Set(value As String)
            SetPropertyValue("CompanyStatisticsNumber", _CompanyStatisticsNumber, value)
        End Set
    End Property
    Property FamilyFarmNumber As String
        Get
            Return _FamilyFarmNumber
        End Get
        Set(value As String)
            SetPropertyValue("FamilyFarmNumber", _FamilyFarmNumber, value)
        End Set
    End Property
    Property MotherName As String
        Get
            Return _MotherName
        End Get
        Set(value As String)
            SetPropertyValue("MotherName", _MotherName, value)
        End Set
    End Property
    Property BirthAddress As Address
        Get
            Return _BirthAddress
        End Get
        Set(value As Address)
            SetPropertyValue("BirthAddress", _BirthAddress, value)
        End Set
    End Property
    Property BirthDate As Date
        Get
            Return _BirthDate
        End Get
        Set(value As Date)
            SetPropertyValue("BirthDate", _BirthDate, value)
        End Set
    End Property
    Property TAJNumber As String
        Get
            Return _TAJNumber
        End Get
        Set(value As String)
            SetPropertyValue("TAJNumber", _TAJNumber, value)
        End Set
    End Property
    '//--- Egyéb
    Property SupplierMark As String
        Get
            Return _SupplierMark
        End Get
        Set(value As String)
            SetPropertyValue("SupplierMark", _SupplierMark, value)
        End Set
    End Property
    <Size(-1)> _
    Property SupplierMarkInfo As String
        Get
            Return _SupplierMarkInfo
        End Get
        Set(value As String)
            SetPropertyValue("SupplierMarkInfo", _SupplierMarkInfo, value)
        End Set
    End Property

    <ImmediatePostData> _
    Property Checked As Boolean
        Get
            Return _Checked
        End Get
        Set(value As Boolean)
            SetPropertyValue("Checked", _Checked, value)
        End Set
    End Property
    Property CheckStatus As String
        Get
            Return _CheckStatus
        End Get
        Set(value As String)
            SetPropertyValue("CheckStatus", _CheckStatus, value)
        End Set
    End Property
    Property CheckedDate As Date
        Get
            Return _CheckedDate
        End Get
        Set(value As Date)
            SetPropertyValue("CheckedDate", _CheckedDate, value)
        End Set
    End Property
    Property HRPerson_SalesPerson As HRPerson
        Get
            Return _HRPerson_SalesPerson
        End Get
        Set(value As HRPerson)
            SetPropertyValue("HRPerson_SalesPerson", _HRPerson_SalesPerson, 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
    <Size(900)> _
    Property DocumentPath As String
        Get
            Return _DocumentPath
        End Get
        Set(value As String)
            SetPropertyValue("DocumentPath", _DocumentPath, value)
        End Set
    End Property
    Property LyonessID As String
        Get
            Return _LyonessID
        End Get
        Set(value As String)
            SetPropertyValue("LyonessID", _LyonessID, value)
        End Set
    End Property
    Property LyonessCardID As String
        Get
            Return _LyonessCardID
        End Get
        Set(value As String)
            SetPropertyValue("LyonessCardID", _LyonessCardID, value)
        End Set
    End Property
    Property VATAvowalType As eVATAvowalType
        Get
            Return _VATAvowalType
        End Get
        Set(value As eVATAvowalType)
            SetPropertyValue("VATAvowalType", _VATAvowalType, value)
        End Set
    End Property
    <Browsable(False)> _
    Property Oid_DH As String
        Get
            Return _Oid_DH
        End Get
        Set(value As String)
            SetPropertyValue("Oid_DH", _Oid_DH, value)
        End Set
    End Property
    Property Url_DH As String
        Get
            Return _Url_DH
        End Get
        Set(value As String)
            SetPropertyValue("Url_DH", _Url_DH, value)
        End Set
    End Property
    Property CanUseMarketingInfo As Boolean
        Get
            Return _CanUseMarketingInfo
        End Get
        Set(value As Boolean)
            SetPropertyValue("CanUseMarketingInfo", _CanUseMarketingInfo, value)
        End Set
    End Property
    Property CanUseMarketingInfoThirdParts As Boolean
        Get
            Return _CanUseMarketingInfoThirdParts
        End Get
        Set(value As Boolean)
            SetPropertyValue("CanUseMarketingInfoThirdParts", _CanUseMarketingInfoThirdParts, value)
        End Set
    End Property
    <VisibleInDetailView(False)> _
    <VisibleInListView(False)> _
    <VisibleInLookupListView(False)> _
    Property ObjectCreated As Date
        Get
            Return _ObjectCreated
        End Get
        Set(value As Date)
            SetPropertyValue("ObjectCreated", _ObjectCreated, value)
        End Set
    End Property
    <VisibleInDetailView(False)> _
    <VisibleInListView(False)> _
    <VisibleInLookupListView(False)> _
    Property UserCreated As User
        Get
            Return _UserCreated
        End Get
        Set(value As User)
            SetPropertyValue("UserCreated", _UserCreated, value)
        End Set
    End Property
    <VisibleInDetailView(False)> _
    <VisibleInListView(False)> _
    <VisibleInLookupListView(False)> _
    Property ObjectChanged As Date
        Get
            Return _ObjectChanged
        End Get
        Set(value As Date)
            SetPropertyValue("ObjectChanged", _ObjectChanged, value)
        End Set
    End Property
    <VisibleInDetailView(False)> _
    <VisibleInListView(False)> _
    <VisibleInLookupListView(False)> _
    Property UserChanged As User
        Get
            Return _UserChanged
        End Get
        Set(value As User)
            SetPropertyValue("UserChanged", _UserChanged, value)
        End Set
    End Property
    <VisibleInDetailView(False)> _
    <VisibleInListView(False)> _
    <VisibleInLookupListView(False)> _
    Property QueueUpdated As Date
        Get
            Return _QueueUpdated
        End Get
        Set(value As Date)
            SetPropertyValue("QueueUpdated", _QueueUpdated, value)
        End Set
    End Property

    Property Contact_Decision As Contacts
        Get
            Return _Contact_Decision
        End Get
        Set(value As Contacts)
            SetPropertyValue("Contact_Decision", _Contact_Decision, value)
        End Set
    End Property
    Property Contact_Finance As Contacts
        Get
            Return _Contact_Finance
        End Get
        Set(value As Contacts)
            SetPropertyValue("Contact_Finance", _Contact_Finance, value)
        End Set
    End Property
    <Size(255)> _
    Property EMail_Invoice As String
        Get
            Return _EMail_Invoice
        End Get
        Set(value As String)
            SetPropertyValue("EMail_Invoice", _EMail_Invoice, value)
        End Set
    End Property

    'Ároszlop
    Property PriceColumn As Integer
        Get
            Return _PriceColumn
        End Get
        Set(value As Integer)
            SetPropertyValue("PriceColumn", _PriceColumn, value)
        End Set
    End Property
    '-----ReadOnly---------------
    Overloads ReadOnly Property IsDeleted As Boolean
        Get
            'Dim _IsDeleted As Boolean = False
            'For Each _PropertyInfo As PropertyInfo In Me.GetType.GetProperties
            '    If _PropertyInfo.PropertyType.Name = "GCRecord" Then
            '        _IsDeleted = _PropertyInfo.GetValue(Me, Nothing)
            '    End If
            'Next
            'Return _IsDeleted
            Return MyBase.IsDeleted
        End Get
    End Property
    <VisibleInListView(False)> _
    <Association("Customers-CustomersFileAttachment", GetType(CustomersFileAttachment))> _
    ReadOnly Property CustomersFileAttachment As XPCollection(Of CustomersFileAttachment)
        Get
            Return GetCollection(Of CustomersFileAttachment)("CustomersFileAttachment")
        End Get
    End Property
    <VisibleInListView(False)> _
    ReadOnly Property CRM_Opportunities As XPCollection(Of CRM_Opportunities)
        Get
            If Session.IsObjectsLoading = False And Session.IsObjectsSaving = False Then
                Return New XPCollection(Of CRM_Opportunities)(Session, CriteriaOperator.Parse("Customers.Oid=?", Me.Oid))
            Else
                Return Nothing
            End If
        End Get
    End Property
    <VisibleInListView(False)> _
    <Association("CustomerBankAccounts", GetType(CustomerBankAccounts))> _
    Public ReadOnly Property CustomerBankAccounts() As XPCollection(Of CustomerBankAccounts)
        Get
            Return GetCollection(Of CustomerBankAccounts)("CustomerBankAccounts")
        End Get
    End Property
    <VisibleInListView(False)> _
    <Association("Contacts", GetType(Contacts))> _
    Public ReadOnly Property Contacts() As XPCollection(Of Contacts)
        Get
            Return GetCollection(Of Contacts)("Contacts")
        End Get
    End Property
    <VisibleInListView(False)> _
    <Association("Customers-CustomersNGCollection", GetType(CustomersNGCollection)), Aggregated(), ExpandObjectMembers(ExpandObjectMembers.Never)> _
    Public ReadOnly Property CustomersNGCollection As XPCollection(Of CustomersNGCollection)
        Get
            Return GetCollection(Of CustomersNGCollection)("CustomersNGCollection")
        End Get
    End Property
    <VisibleInListView(False)> _
    <Association("Customers-CustomersAddress", GetType(CustomersAddress))> _
    Public ReadOnly Property CustomersAddress As XPCollection(Of CustomersAddress)
        Get
            Return GetCollection(Of CustomersAddress)("CustomersAddress")
        End Get
    End Property
    <VisibleInListView(False)> _
   <Association("Customers-CustomersNGCollectionWorkSheetType", GetType(CustomersNGCollectionWorkSheetType))> _
    Public ReadOnly Property CustomersNGCollectionWorkSheetType As XPCollection(Of CustomersNGCollectionWorkSheetType)
        Get
            Return GetCollection(Of CustomersNGCollectionWorkSheetType)("CustomersNGCollectionWorkSheetType")
        End Get
    End Property
    <VisibleInListView(False), VisibleInLookupListView(False)> _
    ReadOnly Property ContractProductsCredit As XPCollection(Of ContractProductsCredit)
        Get
            Return New XPCollection(Of ContractProductsCredit)(Session, CriteriaOperator.Parse("Contract.Customers=?", Me))
        End Get
    End Property

    ReadOnly Property CustomersCCustomers As XPCollection(Of CustomersCCustomers)
        Get
            Return New XPCollection(Of CustomersCCustomers)(Session, CriteriaOperator.Parse("Customers=?", Me))
        End Get
    End Property
    ReadOnly Property Customers_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

    <VisibleInListView(False), VisibleInLookupListView(False)> _
    ReadOnly Property OfferOutRows As XPCollection(Of OfferOutRows)
        Get
            Return New XPCollection(Of OfferOutRows)(Session, CriteriaOperator.Parse("OfferOutHeader.Customers=?", Me))
        End Get
    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





