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
Imports DevExpress.ExpressApp.Editors

<DefaultClassOptions(), NavigationItem(False), CreatableItem(False)> _
<Appearance("Hide HRPersonTasks View info", AppearanceItemType:="ViewItem", criteria:="IsView=False", targetitems:="ViewID", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("Hide HRPersonTasks View action", AppearanceItemType:="Action", criteria:="IsView=False", targetitems:="aHRPersonTask_SetViewID", visibility:=Editors.ViewItemVisibility.Hide)> _
Public Class HRPersonTasks
    Inherits Task
    Private _HRPerson As HRPerson
    Private _HRPersonAlias As HRPerson
    Private _ObjectCreated As Date
    Private _UserCreated As User
    Private _AlertPeriod As AlertPeriod 'A feladat ütemezése
    Private _AlertPeriodAlias As AlertPeriod 'A feladatot kiadta

    Private _HRPersonEvent As HRPersonEvent
    Private _HRPersonEventAlias As HRPersonEvent

    Private _IsView As Boolean = False 'Van-e valamilyen view, amit az alertből lehet meghívni
    Private _ViewID As String 'View ID 

    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
        Dim _User As User = Session.GetObjectByKey(Of User)(Session.GetKeyValue(SecuritySystem.CurrentUser))
        If _User IsNot Nothing Then
            Me.HRPersonAlias = Session.FindObject(Of HRPerson)(CriteriaOperator.Parse("User=?", _User))
        End If
    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))
        End If
        '//Esemény lejárt határidővel a felelősnek !

        If Me.HRPersonEvent Is Nothing Then
            Me.HRPersonEvent = New HRPersonEvent(Session)
            Me.HRPersonEvent.Resources.Add(HRPerson)
        End If
        Me.HRPersonEvent.StartOn = New Date(Me.DueDate.Year, Me.DueDate.Month, Me.DueDate.Day, 8, 0, 0)
        Me.HRPersonEvent.EndOn = New Date(Me.DueDate.Year, Me.DueDate.Month, Me.DueDate.Day, 10, 0, 0)
        Me.HRPersonEvent.Subject = Me.Subject
        Me.HRPersonEvent.Description = Me.Description

        '//Esemény lejárt határidővel a feladatot kiadónak
        If Me.HRPersonEventAlias Is Nothing Then
            Me.HRPersonEventAlias = New HRPersonEvent(Session)
            Me.HRPersonEventAlias.Resources.Add(HRPersonAlias)
        End If
        Me.HRPersonEventAlias.StartOn = New Date(Me.DueDate.Year, Me.DueDate.Month, Me.DueDate.Day, 8, 0, 0)
        Me.HRPersonEventAlias.EndOn = New Date(Me.DueDate.Year, Me.DueDate.Month, Me.DueDate.Day, 10, 0, 0)
        Me.HRPersonEventAlias.Subject = Me.Subject
        Me.HRPersonEventAlias.Description = Me.Description

    End Sub
    Protected Overrides Sub OnDeleting()
        MyBase.OnDeleting()
        If Me.HRPersonEvent IsNot Nothing Then
            Session.Delete(Me.HRPersonEvent)
        End If
        If Me.HRPersonEventAlias IsNot Nothing Then
            Session.Delete(Me.HRPersonEventAlias)
        End If
    End Sub
    <RuleRequiredField("HRPersonTasks-HRPerson", DefaultContexts.Save)> _
    Property HRPerson As HRPerson
        Get
            Return _HRPerson
        End Get
        Set(value As HRPerson)
            SetPropertyValue("HRPerson", _HRPerson, value)
        End Set
    End Property
    <RuleRequiredField("HRPersonTasks-HRPersonAlias", DefaultContexts.Save)> _
    Property HRPersonAlias As HRPerson
        Get
            Return _HRPersonAlias
        End Get
        Set(value As HRPerson)
            SetPropertyValue("HRPersonAlias", _HRPersonAlias, value)
        End Set
    End Property
    <Browsable(False)> _
    Overloads Property AssignedTo As Party
        Get
            Return MyBase.AssignedTo
        End Get
        Set(value As Party)
            MyBase.AssignedTo = 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 AlertPeriod As AlertPeriod
        Get
            Return _AlertPeriod
        End Get
        Set(value As AlertPeriod)
            SetPropertyValue("AlertPeriod", _AlertPeriod, value)
        End Set
    End Property
    Property AlertPeriodAlias As AlertPeriod
        Get
            Return _AlertPeriodAlias
        End Get
        Set(value As AlertPeriod)
            SetPropertyValue("AlertPeriodAlias", _AlertPeriodAlias, value)
        End Set
    End Property

    <Browsable(False)> _
    Property HRPersonEvent As HRPersonEvent
        Get
            Return _HRPersonEvent
        End Get
        Set(value As HRPersonEvent)
            SetPropertyValue("HRPersonEvent", _HRPersonEvent, value)
        End Set
    End Property
    <Browsable(False)> _
    Property HRPersonEventAlias As HRPersonEvent
        Get
            Return _HRPersonEventAlias
        End Get
        Set(value As HRPersonEvent)
            SetPropertyValue("HRPersonEventAlias", _HRPersonEventAlias, value)
        End Set
    End Property

    <ImmediatePostData()> _
    Property IsView As Boolean
        Get
            Return _IsView
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsView", _IsView, value)
        End Set
    End Property
    <Size(255)> _
    <ImmediatePostData()> _
    Property ViewID As String
        Get
            Return _ViewID
        End Get
        Set(value As String)
            SetPropertyValue("ViewID", _ViewID, value)

        End Set
    End Property
End Class
