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

'<Appearance("Disable DateTo - SetHRPersonToCostHolder", AppearanceItemType:="ViewItem", Criteria:="1=1", TargetItems:="DateTo", Enabled:=False)> _
'<Appearance("Disable DateFrom - SetHRPersonToCostHolder", AppearanceItemType:="ViewItem", Criteria:="1=1", TargetItems:="DateFrom", Enabled:=False)> _

<DefaultClassOptions(), NonPersistent(), NavigationItem(False), CreatableItem(False)> _
<Appearance("Hide SetHRPersonToCostHolderHRPerson when Mode=1", AppearanceItemType:="ViewItem", Criteria:="Mode=1", targetitems:="SetHRPersonToCostHolderHRPerson", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("Hide SetHRPersonToCostHolderCostHolder when Mode=0", AppearanceItemType:="ViewItem", Criteria:="Mode=0", targetitems:="SetHRPersonToCostHolderCostHolder", visibility:=Editors.ViewItemVisibility.Hide)> _
Public Class SetHRPersonToCostHolder
    Inherits BaseObject

    Private _Mode As Long
    Private _HRPerson As HRPerson
    Private _CostHolder As CostHolder
    Private _DateFrom As Date
    Private _DateTo As Date
    Private _MasterKey As Guid
    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
    End Sub
    <Browsable(False)> Property Mode As Long
        Get
            Return _Mode
        End Get
        Set(value As Long)
            SetPropertyValue("Mode", _Mode, value)
        End Set
    End Property
    <Browsable(False)> _
    Property MasterKey As Guid
        Get
            Return _MasterKey
        End Get
        Set(value As Guid)
            SetPropertyValue("MasterKey", _MasterKey, value)
        End Set
    End Property
    <Browsable(False)> Property HRPerson As HRPerson
        Get
            Return _HRPerson
        End Get
        Set(value As HRPerson)
            SetPropertyValue("HRPerson", _HRPerson, value)
        End Set
    End Property
    <Browsable(False)> Property CostHolder As CostHolder
        Get
            Return _CostHolder
        End Get
        Set(value As CostHolder)
            SetPropertyValue("CostHolder", _CostHolder, value)
        End Set
    End Property
    Property DateFrom As Date
        Get
            Return _DateFrom
        End Get
        Set(value As Date)
            SetPropertyValue("DateFrom", _DateFrom, value)
        End Set
    End Property
    Property DateTo As Date
        Get
            Return _DateTo
        End Get
        Set(value As Date)
            SetPropertyValue("DateTo", _DateTo, value)
        End Set
    End Property

    <VisibleInListView(False), VisibleInLookupListView(False)> _
    <Appearance("Disable OpeneObject - SetHRPersonToCostHolder", AppearanceItemType.Action, "1=1", TargetItems:="OpenObject", visibility:=Editors.ViewItemVisibility.Hide)> _
    ReadOnly Property SetHRPersonToCostHolderHRPerson As XPCollection(Of SetHRPersonToCostHolderHRPerson)
        Get
            Dim _SetHRPersonToCostHolderHRPerson_Collection As New XPCollection(Of SetHRPersonToCostHolderHRPerson)(Session, CriteriaOperator.Parse("1=2"))
            Dim _HRPerson_Collection = New XPCollection(Of HRPerson)(PersistentCriteriaEvaluationBehavior.InTransaction, Session, CriteriaOperator.Parse("1=1"))
            Dim _HRPerson As HRPerson
            Dim _HRPersonCostHolder As HRPersonCostHolder
            Dim _SetHRPersonToCostHolderHRPerson As SetHRPersonToCostHolderHRPerson
            For Each _HRPerson In _HRPerson_Collection
                _SetHRPersonToCostHolderHRPerson = New SetHRPersonToCostHolderHRPerson(Session)
                _SetHRPersonToCostHolderHRPerson.MasterKey = Me._MasterKey
                _SetHRPersonToCostHolderHRPerson.HRPerson = _HRPerson

                _HRPersonCostHolder = Session.FindObject(Of HRPersonCostHolder)(CriteriaOperator.Parse("CostHolder=? And HRPerson=? And DateFrom=? And DateTo=?", Me.CostHolder, _HRPerson, Me.DateFrom, Me.DateTo))
                If _HRPersonCostHolder IsNot Nothing Then
                    _SetHRPersonToCostHolderHRPerson.WorkPercent = _HRPersonCostHolder.WorkPercent
                End If

                _SetHRPersonToCostHolderHRPerson_Collection.Add(_SetHRPersonToCostHolderHRPerson)
            Next
            Return _SetHRPersonToCostHolderHRPerson_Collection
        End Get
    End Property

    <VisibleInListView(False), VisibleInLookupListView(False)> _
    ReadOnly Property SetHRPersonToCostHolderCostHolder As XPCollection(Of SetHRPersonToCostHolderCostHolder)
        Get
            Dim _SetHRPersonToCostHolderCostHolder_Collection As New XPCollection(Of SetHRPersonToCostHolderCostHolder)(Session, CriteriaOperator.Parse("1=2"))
            Dim _CostHolder_Collection = New XPCollection(Of CostHolder)(PersistentCriteriaEvaluationBehavior.InTransaction, Session, CriteriaOperator.Parse("1=1"))
            Dim _CostHolder As CostHolder
            Dim _HRPersonCostHolder As HRPersonCostHolder
            Dim _SetHRPersonToCostHolderCostHolder As SetHRPersonToCostHolderCostHolder
            For Each _CostHolder In _CostHolder_Collection
                _SetHRPersonToCostHolderCostHolder = New SetHRPersonToCostHolderCostHolder(Session)
                _SetHRPersonToCostHolderCostHolder.MasterKey = Me._MasterKey
                _SetHRPersonToCostHolderCostHolder.CostHolder = _CostHolder

                _HRPersonCostHolder = Session.FindObject(Of HRPersonCostHolder)(CriteriaOperator.Parse("CostHolder=? And HRPerson=? And DateFrom=? And DateTo=?", _CostHolder, Me.HRPerson, Me.DateFrom, Me.DateTo))
                If _HRPersonCostHolder IsNot Nothing Then
                    _SetHRPersonToCostHolderCostHolder.WorkPercent = _HRPersonCostHolder.WorkPercent
                End If

                _SetHRPersonToCostHolderCostHolder_Collection.Add(_SetHRPersonToCostHolderCostHolder)
            Next
            Return _SetHRPersonToCostHolderCostHolder_Collection
        End Get
    End Property
End Class
