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
Public Enum eAlertType
    eNormal = 0 'Normál
    eDaily = 1 'Naponta
    eWeekly = 2 'Hetente
    eMonthly = 3 'Havonta
    eOnLoggedOn = 4 'Bejelentkezéskor
    eOnLoggingOff = 5 'Kijelentkezéskor
End Enum
<DefaultClassOptions(), NavigationItem(False), CreatableItem(False), DefaultProperty("DisplayName")> _
<Appearance("AlertPeriod - Hide properties without DisplayName, when AlartType=0 ", AppearanceItemType:="ViewItem", criteria:="AlertType=0", targetitems:="AlertPeriodDaily;AlertPeriodWeekly;AlertPeriodMonthly", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("AlertPeriod - Hide AlertPeriodWeekly;AlertPeriodMonthly;DateDayBefore;PeriodHour;PeriodMinute, when AlartType=1 ", AppearanceItemType:="ViewItem", criteria:="AlertType=1", targetitems:="AlertPeriodWeekly;AlertPeriodMonthly;DateDayBefore;PeriodHour;PeriodMinute", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("AlertPeriod - Hide AlertPeriodDaily;AlertPeriodMonthly;DateDayBefore;PeriodHour;PeriodMinute, when AlartType=2 ", AppearanceItemType:="ViewItem", criteria:="AlertType=2", targetitems:="AlertPeriodDaily;AlertPeriodMonthly;DateDayBefore;PeriodHour;PeriodMinute", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("AlertPeriod - Hide AlertPeriodDaily;AlertPeriodWeekly;DateDayBefore;PeriodHour;PeriodMinute, when AlartType=3 ", AppearanceItemType:="ViewItem", criteria:="AlertType=3", targetitems:="AlertPeriodDaily;AlertPeriodWeekly;DateDayBefore;PeriodHour;PeriodMinute", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("AlertPeriod - Hide XPCollections and properties, when AlartType in(4,5)", AppearanceItemType:="ViewItem", criteria:="AlertType in (4,5)", targetitems:="AlertPeriodDaily;AlertPeriodWeekly;AlertPeriodMonthly,DateDayBefore;PeriodHour;PeriodMinute", visibility:=Editors.ViewItemVisibility.Hide)> _
Public Class AlertPeriod
    Inherits BaseObject
    Private _AlertType As eAlertType = eAlertType.eNormal
    Private _DateDayBefore As Long = 1 '? nappal előtte (a Task DueDate - DateDayBefore !)
    Private _PeriodHour As Long = 1 '? óránként 
    Private _PeriodMinute As Long = 0 '? percenként

    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
    End Sub

    <ImmediatePostData()> _
    Property AlertType As eAlertType
        Get
            Return _AlertType
        End Get
        Set(value As eAlertType)
            SetPropertyValue("AlertType", _AlertType, value)
        End Set
    End Property
    Property DateDayBefore As Long
        Get
            Return _DateDayBefore
        End Get
        Set(value As Long)
            SetPropertyValue("DateDayBefore", _DateDayBefore, value)
        End Set
    End Property
    Property PeriodHour As Long
        Get
            Return _PeriodHour
        End Get
        Set(value As Long)
            SetPropertyValue("PeriodHour", _PeriodHour, value)
        End Set
    End Property
    Property PeriodMinute As Long
        Get
            Return _PeriodMinute
        End Get
        Set(value As Long)
            SetPropertyValue("PeriodMinute", _PeriodMinute, value)
        End Set
    End Property
    ReadOnly Property DisplayName As String
        Get
            Dim _Message As String = ""
            Select Case AlertType
                Case eAlertType.eNormal
                    _Message = String.Format("Határidő előtt {0} nappal, {1} óra és {2} percenként", _DateDayBefore, PeriodHour, PeriodMinute)
                Case eAlertType.eDaily
                    _Message = String.Format("Naponta")
                Case eAlertType.eWeekly
                    _Message = String.Format("Hetente")
                Case eAlertType.eMonthly
                    _Message = String.Format("Havonta")
                Case eAlertType.eOnLoggedOn
                    _Message = String.Format("Bejelentkezéskor")
                Case eAlertType.eOnLoggingOff
                    _Message = String.Format("Kijelentkezéskor")
            End Select

            Return _Message
        End Get
    End Property
    <Association("AlertPeriod-AlertPeriodDaily", GetType(AlertPeriodDaily)), VisibleInListView(False), VisibleInLookupListView(False)> _
    ReadOnly Property AlertPeriodDaily As XPCollection(Of AlertPeriodDaily)
        Get
            Return GetCollection(Of AlertPeriodDaily)("AlertPeriodDaily")
        End Get
    End Property
    <Association("AlertPeriod-AlertPeriodWeekly", GetType(AlertPeriodWeekly)), VisibleInListView(False), VisibleInLookupListView(False)> _
    ReadOnly Property AlertPeriodWeekly As XPCollection(Of AlertPeriodWeekly)
        Get
            Return GetCollection(Of AlertPeriodWeekly)("AlertPeriodWeekly")
        End Get
    End Property
    <Association("AlertPeriod-AlertPeriodMonthly", GetType(AlertPeriodMonthly)), VisibleInListView(False), VisibleInLookupListView(False)> _
    ReadOnly Property AlertPeriodMonthly As XPCollection(Of AlertPeriodMonthly)
        Get
            Return GetCollection(Of AlertPeriodMonthly)("AlertPeriodMonthly")
        End Get
    End Property
End Class
