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

    Private _PhoneNumber As String
    Private _PhoneProvider As Customers
    Private _DateLoyalityStart As Date
    Private _DateLoyalityEnd As Date
    Private _ObjectCreated As Date
    Private _UserCreated As User
    Private _UniqueObjects As UniqueObjects
    Private _GLReport As GLReport
    Private _AmountHUF_Subscription As Double

    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
        ' Place here your initialization code.
    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))
            UniqueObjects = New UniqueObjects(Session)
            UniqueObjects.Name = PhoneNumber
            UniqueObjects.Phones = Me
            UniqueObjects.Save()
        End If
    End Sub

    <RuleRequiredField("Phones - PhoneNumber", DefaultContexts.Save)> _
    <RuleUniqueValue("Phones.PhoneNumber.RuleUniqueValue", DefaultContexts.Save, CriteriaEvaluationBehavior:=PersistentCriteriaEvaluationBehavior.BeforeTransaction)> _
    Property PhoneNumber As String
        Get
            Return _PhoneNumber
        End Get
        Set(value As String)
            SetPropertyValue("PhoneNumber", _PhoneNumber, value)
        End Set
    End Property
    Property PhoneProvider As Customers
        Get
            Return _PhoneProvider
        End Get
        Set(value As Customers)
            SetPropertyValue("PhoneProvider", _PhoneProvider, value)
        End Set
    End Property
    Property DateLoyalityStart As Date
        Get
            Return _DateLoyalityStart
        End Get
        Set(value As Date)
            SetPropertyValue("DateLoyalityStart", _DateLoyalityStart, value)
        End Set
    End Property
    Property DateLoyalityEnd As Date
        Get
            Return _DateLoyalityEnd
        End Get
        Set(value As Date)
            SetPropertyValue("DateLoyalityEnd", _DateLoyalityEnd, value)
        End Set
    End Property
    Property AmountHUF_Subscription As Double
        Get
            Return _AmountHUF_Subscription
        End Get
        Set(value As Double)
            SetPropertyValue("AmountHUF_Subscription", _AmountHUF_Subscription, 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

    Property UniqueObjects As UniqueObjects
        Get
            Return _UniqueObjects
        End Get
        Set(value As UniqueObjects)
            SetPropertyValue("UniqueObjects", _UniqueObjects, value)
        End Set
    End Property

    <ImmediatePostData(True)> _
    Property GLReport As GLReport
        Get
            Return _GLReport
        End Get
        Set(value As GLReport)
            SetPropertyValue("GLReport", _GLReport, value)
        End Set
    End Property
    <VisibleInListView(False), VisibleInLookupListView(False)> _
    ReadOnly Property GLReportRows As XPCollection(Of GLReportRows)
        Get
            Dim _GLReportRows_Collection As XPCollection(Of GLReportRows)
            If Me.GLReport IsNot Nothing Then
                _GLReportRows_Collection = New XPCollection(Of GLReportRows)(Session, CriteriaOperator.Parse("GLReport.Oid=? and UniqueObjects.Oid=?", Me.GLReport.Oid, Me.UniqueObjects.Oid))
                Return _GLReportRows_Collection
            Else
                Return Nothing
            End If
        End Get
    End Property
End Class
