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("EMailSendQueueHeader - Disable QueueNumber", TargetItems:="QueueNumber", Criteria:="1=1", Enabled:=False, Context:="DetailView")> _
<Appearance("EMailSendQueueHeader - Disable ObjectCreated", TargetItems:="ObjectCreated", Criteria:="1=1", Enabled:=False, Context:="DetailView")> _
<Appearance("EMailSendQueueHeader - Disable UserCreated", TargetItems:="UserCreated", Criteria:="1=1", Enabled:=False, Context:="DetailView")> _
<Appearance("EMailSendQueueHeader - Disable IsExecuted", TargetItems:="IsExecuted", Criteria:="1=1", Enabled:=False, Context:="DetailView")> _
Public Class EMailSendQueueHeader
    Inherits BaseObject
    Private _QueueNumber As String
    Private _ShortName As String 'Csomag megnevezése
    Private _EmailSendQueueParameters As EMailSendQueueParameters
    Private _UserCreated As User 'Létrehozta
    Private _ObjectCreated As Date 'Létrehozva
    Private _ScheduleDateTime As Date 'Mikorra ütemezzük
    Private _IsExecuted As Boolean 'El lett-e már küldve

    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
        IsExecuted = False
       
    End Sub
    Protected Overrides Sub OnSaving()
        MyBase.OnSaving()
        If String.IsNullOrEmpty(QueueNumber) Then QueueNumber = EmailSendQueueParameters.NumberGenerator.GetNewNumber(EmailSendQueueParameters.NumberGenerator)
        If Session.IsNewObject(Me) Then
            ObjectCreated = GetSQLTime(Session)
            UserCreated = Session.GetObjectByKey(Of User)(Session.GetKeyValue(SecuritySystem.CurrentUser))
        End If
    End Sub

    Property QueueNumber As String
        Get
            Return _QueueNumber
        End Get
        Set(value As String)
            SetPropertyValue("QueueNumber", _QueueNumber, value)
        End Set
    End Property
    <Size(255)> _
    Property ShortName As String
        Get
            Return _ShortName
        End Get
        Set(value As String)
            SetPropertyValue("ShortName", _ShortName, value)
        End Set
    End Property
    <RuleRequiredField("EMailSendQueueHeader - EmailSendQueueParameters ", DefaultContexts.Save)> _
    Property EmailSendQueueParameters As EMailSendQueueParameters
        Get
            Return _EmailSendQueueParameters
        End Get
        Set(value As EMailSendQueueParameters)
            SetPropertyValue("EmailSendQueueParameters", _EmailSendQueueParameters, 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
    <NonCloneable> _
    Property ObjectCreated As Date
        Get
            Return _ObjectCreated
        End Get
        Set(value As Date)
            SetPropertyValue("ObjectCreated", _ObjectCreated, value)
        End Set
    End Property
    Property ScheduleDateTime As Date
        Get
            Return _ScheduleDateTime
        End Get
        Set(value As Date)
            SetPropertyValue("ScheduleDateTime", _ScheduleDateTime, value)
        End Set
    End Property
    Property IsExecuted As Boolean
        Get
            Return _IsExecuted
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsExecuted", _IsExecuted, value)
        End Set
    End Property

    '-------------ReadOnly------------
    <Association("EMailSendQueueHeader-EMailSendQueueRows", GetType(EMailSendQueueRows)), VisibleInListView(False)> _
    ReadOnly Property EMailSendQueueRows As XPCollection(Of EMailSendQueueRows)
        Get
            Return GetCollection(Of EMailSendQueueRows)("EMailSendQueueRows")
        End Get
    End Property
End Class
