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 eFixedAssetsState
    eWaitForActivate = 0 ' Aktiválásra vár
    eReadyForUse = 1 ' Használható, de nincs kiadva
    eInUse = 2 ' Használatban van valakinél
    eWaitForOther = 3 ' Egyéb ok miatt a használat felfüggesztve
    eTerminated = 4 'Kivezetve
End Enum
<DefaultClassOptions()> _
<NavigationItem(False)> _
<CreatableItem(False)> _
<Appearance("Disable FixedAssets defaults", AppearanceItemType.ViewItem, "1=1", TargetItems:="HRPerson_Using;Customers_Using;CostHolder_Using;CostPlace_Using;ObjectCreated;UserCreated", Enabled:=False)> _
Public Class FixedAssets
    Inherits BaseObject

    Private _CustomersFrom As CustomersFrom
    Private _UniqueObjects As UniqueObjects
    Private _FixedAssetsGroup1 As FixedAssetsGroup1
    Private _ShortName As String
    Private _Description As String

    Private _DatePurchase As Date ' Vásárlás dátuma
    Private _DateTerminal As Date ' Kivezetés dátuma
    Private _FixedAssetsState As eFixedAssetsState

    Private _HRPerson_Using As HRPerson
    Private _Customers_Using As Customers
    Private _CostHolder_Using As CostHolder
    Private _CostPlace_Using As CostPlace

    Private _ObjectCreated As Date
    Private _UserCreated As User

    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
    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
    End Sub

    Property CustomersFrom As CustomersFrom
        Get
            Return _CustomersFrom
        End Get
        Set(value As CustomersFrom)
            SetPropertyValue("CustomersFrom", _CustomersFrom, value)
        End Set
    End Property
    '<RuleUniqueValue("FixedAssets-UniqueObjects", DefaultContexts.Save, criteriaevaluationbehavior:=PersistentCriteriaEvaluationBehavior.BeforeTransaction, targetcriteria:="")> _
    <ImmediatePostData(True)> _
    Property UniqueObjects As UniqueObjects
        Get
            Return _UniqueObjects
        End Get
        Set(value As UniqueObjects)
            SetPropertyValue("UniqueObjects", _UniqueObjects, value)
            If Session.IsObjectsLoading = False And Session.IsObjectsSaving = False Then
                If value.Cars IsNot Nothing Then
                    Me.ShortName = value.Cars.LicensePlateNumber & ", " & value.Cars.CarMarks.ShortName & " " & value.Cars.CarTypes.ShortName
                    Me.DatePurchase = value.Cars.DateFirstOnRoad.Date
                End If
            End If
        End Set
    End Property
    <RuleRequiredField("FixedAssets-FixedAssetsGroup1", DefaultContexts.Save)> _
    Property FixedAssetsGroup1 As FixedAssetsGroup1
        Get
            Return _FixedAssetsGroup1
        End Get
        Set(value As FixedAssetsGroup1)
            SetPropertyValue("FixedAssetsGroup1", _FixedAssetsGroup1, value)
        End Set
    End Property
    Property ShortName As String
        Get
            Return _ShortName
        End Get
        Set(value As String)
            SetPropertyValue("ShortName", _ShortName, value)
        End Set
    End Property
    <Size(-1)> _
    Property Description As String
        Get
            Return _Description
        End Get
        Set(value As String)
            SetPropertyValue("Description", _Description, value)
        End Set
    End Property

    Property DatePurchase As Date
        Get
            Return _DatePurchase
        End Get
        Set(value As Date)
            SetPropertyValue("DatePurchase", _DatePurchase, value)
        End Set
    End Property
    Property DateTerminal As Date
        Get
            Return _DateTerminal
        End Get
        Set(value As Date)
            SetPropertyValue("DateTerminal", _DateTerminal, value)
        End Set
    End Property

    Property FixedAssetsState As eFixedAssetsState
        Get
            Return _FixedAssetsState
        End Get
        Set(value As eFixedAssetsState)
            SetPropertyValue("FixedAssetsState", _FixedAssetsState, value)
        End Set
    End Property

    Property HRPerson_Using As HRPerson
        Get
            Return _HRPerson_Using
        End Get
        Set(value As HRPerson)
            SetPropertyValue("HRPerson_Using", _HRPerson_Using, value)
        End Set
    End Property
    Property Customers_Using As Customers
        Get
            Return _Customers_Using
        End Get
        Set(value As Customers)
            SetPropertyValue("Customers_Using", _Customers_Using, value)
        End Set
    End Property
    Property CostHolder_Using As CostHolder
        Get
            Return _CostHolder_Using
        End Get
        Set(value As CostHolder)
            SetPropertyValue("CostHolder_Using", _CostHolder_Using, value)
        End Set
    End Property
    Property CostPlace_Using As CostPlace
        Get
            Return _CostPlace_Using
        End Get
        Set(value As CostPlace)
            SetPropertyValue("CostPlace_Using", _CostPlace_Using, 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
End Class
