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("Disable Cars - UniqueObjects", AppearanceItemType.ViewItem, "1=1", TargetItems:="UniqueObjects", Enabled:=False)> _
<Appearance("Disable Cars - ObjectCreated", AppearanceItemType.ViewItem, "1=1", TargetItems:="ObjectCreated", Enabled:=False)> _
<Appearance("Disable Cars - UserCreated", AppearanceItemType.ViewItem, "1=1", TargetItems:="UserCreated", Enabled:=False)> _
Public Class Cars
    Inherits BaseObject

    Private _VIN As String 'Alvázszám
    Private _MotorNumber As String 'Motorszám
    Private _CarMarks As CarMarks 'Autó márka
    Private _CarTypes As CarTypes 'Autó tipusa
    Private _LicensePlateNumber As String 'Forgalmi rendszám
    Private _DateFirstOnRoad As Date 'Első forgalombahelyezés

    Private _ObjectCreated As Date
    Private _UserCreated As User

    Private _UniqueObjects As UniqueObjects
    Private _GLReport As GLReport

    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    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))
            UniqueObjects = New UniqueObjects(Session)
            UniqueObjects.Name = LicensePlateNumber
            UniqueObjects.Cars = Me
            UniqueObjects.Save()
        End If
    End Sub

    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
    End Sub

    <Size(255)> _
    Property VIN As String
        Get
            Return _VIN
        End Get
        Set(value As String)
            SetPropertyValue("VIN", _VIN, value)
        End Set
    End Property
    <Size(255)> _
    Property MotorNumber As String
        Get
            Return _MotorNumber
        End Get
        Set(value As String)
            SetPropertyValue("MotorNumber", _MotorNumber, value)
        End Set
    End Property
    Property CarMarks As CarMarks
        Get
            Return _CarMarks
        End Get
        Set(value As CarMarks)
            SetPropertyValue("CarMarks", _CarMarks, value)
        End Set
    End Property
    <ImmediatePostData(True), DataSourceCriteria("CarMarks='@This.CarMarks'")>
    Property CarTypes As CarTypes
        Get
            Return _CarTypes
        End Get
        Set(value As CarTypes)
            SetPropertyValue("CarTypes", _CarTypes, value)
        End Set
    End Property
    <RuleRequiredField("Car - LicensePlateNumber", DefaultContexts.Save)> _
    <RuleUniqueValue("Car.LicensePlateNumber.RuleUniqueValue", DefaultContexts.Save, CriteriaEvaluationBehavior:=PersistentCriteriaEvaluationBehavior.BeforeTransaction)> _
    Property LicensePlateNumber As String
        Get
            Return _LicensePlateNumber
        End Get
        Set(value As String)
            SetPropertyValue("LicensePlateNumber", _LicensePlateNumber, value)
        End Set
    End Property
    Property DateFirstOnRoad As Date
        Get
            Return _DateFirstOnRoad
        End Get
        Set(value As Date)
            SetPropertyValue("DateFirstOnRoad", _DateFirstOnRoad, value.Date)
        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 UniqueObjects As UniqueObjects
        Get
            Return _UniqueObjects
        End Get
        Set(value As UniqueObjects)
            SetPropertyValue("UniqueObjects", _UniqueObjects, value)
        End Set
    End Property

    <ImmediatePostData(True)> _
    Property GLReport As GLReport
        Get
            Return _GLReport
        End Get
        Set(value As GLReport)
            SetPropertyValue("GLReport", _GLReport, value)
        End Set
    End Property
    <VisibleInListView(False), VisibleInLookupListView(False)> _
    ReadOnly Property GLReportRows As XPCollection(Of GLReportRows)
        Get
            Dim _GLReportRows_Collection As XPCollection(Of GLReportRows)
            If Me.GLReport IsNot Nothing Then
                _GLReportRows_Collection = New XPCollection(Of GLReportRows)(Session, CriteriaOperator.Parse("GLReport.Oid=? and UniqueObjects.Oid=?", Me.GLReport.Oid, Me.UniqueObjects.Oid))
                Return _GLReportRows_Collection
            Else
                Return Nothing
            End If
        End Get
    End Property

End Class
