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.Xpo.Metadata
Imports System.Drawing
<DefaultClassOptions()> _
<NavigationItem("RealEstateStocks")> _
Public Class Garages
    Inherits Immovables
    Private _Floor As Floors
    Private _GarageType As String
    Private _AreaNetto As Double
    Private _AreaNettoForCostRecord As Double = 0 'Költség számító négyzetméter
    Private _PriceBruttoHUF As Double 'Bruttó listaár számoltatni a nettó vételárból (HUF)
    Private _PriceNettoHUF As Double 'Nettó vételár (HUF)
    Private _PriceBruttoDEV As Double
    Private _PriceNettoDEV As Double 'Nettó vételár
    Private _Note As String
    Private _UniqueTag As String
    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
        Me.ImmovablesTypes = eImmovablesTypes.eGarage
    End Sub
    Protected Overrides Sub OnSaving()
        If Session.IsNewObject(Me) Then
            If UniqueTag <> "*" Then Me.MakeUniqueObjects_Garages()
        End If
        MyBase.OnSaving()
    End Sub
    Protected Sub RecalculatePriceBrutto()
        PriceBruttoHUF = Math.Round(PriceNettoHUF * 1.25, 0, MidpointRounding.AwayFromZero)
        PriceBruttoDEV = Math.Round(PriceNettoDEV * 1.25, 0, MidpointRounding.AwayFromZero)
    End Sub
    Property Floor() As Floors
        Get
            Return _Floor
        End Get
        Set(ByVal value As Floors)
            SetPropertyValue("Floor", _Floor, value)
        End Set
    End Property
    Property GarageType() As String
        Get
            Return _GarageType
        End Get
        Set(ByVal value As String)
            SetPropertyValue("GarageType", _GarageType, value)
        End Set
    End Property
    Property AreaNetto() As Double
        Get
            Return _AreaNetto
        End Get
        Set(ByVal value As Double)
            SetPropertyValue("AreaNetto", _AreaNetto, value)
        End Set
    End Property
    Property AreaNettoForCostRecord As Double
        Get
            Return _AreaNettoForCostRecord
        End Get
        Set(value As Double)
            SetPropertyValue("AreaNettoForCostRecord", _AreaNettoForCostRecord, value)
        End Set
    End Property
    Property PriceBruttoHUF() As Double
        Get
            Return _PriceBruttoHUF
        End Get
        Set(ByVal value As Double)
            SetPropertyValue("PriceBruttoHUF", _PriceBruttoHUF, value)
        End Set
    End Property
    <ImmediatePostData(True)> _
    Property PriceNettoHUF As Double
        Get
            Return _PriceNettoHUF
        End Get
        Set(ByVal value As Double)
            SetPropertyValue("PriceNettoHUF", _PriceNettoHUF, value)
            If Session.IsObjectsLoading = False And Session.IsObjectsSaving = False Then
                Me.RecalculatePriceBrutto()
            End If
        End Set
    End Property
    Property PriceBruttoDEV() As Double
        Get
            Return _PriceBruttoDEV
        End Get
        Set(ByVal value As Double)
            SetPropertyValue("PriceBruttoDEV", _PriceBruttoDEV, value)
        End Set
    End Property
    <ImmediatePostData(True)> _
    Property PriceNettoDEV As Double
        Get
            Return _PriceNettoDEV
        End Get
        Set(ByVal value As Double)
            SetPropertyValue("PriceNettoDEV", _PriceNettoDEV, value)
            If Session.IsObjectsSaving = False And Session.IsObjectsLoading = False Then
                RecalculatePriceBrutto()
            End If
        End Set
    End Property
    <Size(-1)> _
    Property Note() As String
        Get
            Return _Note
        End Get
        Set(ByVal value As String)
            SetPropertyValue("Note", _Note, value)
        End Set
    End Property
    <VisibleInListView(False)> _
    <Association("Garages-Container", GetType(Container))> _
    ReadOnly Property Container() As XPCollection(Of Container)
        Get
            Return GetCollection(Of Container)("Container")
        End Get
    End Property
    <RuleRequiredField("Garages-UniqueTag", DefaultContexts.Save)> _
    Property UniqueTag() As String
        Get
            Return _UniqueTag
        End Get
        Set(ByVal value As String)
            SetPropertyValue("UniqueTag", _UniqueTag, value)
        End Set
    End Property
    Public Sub MakeUniqueObjects_Garages()
        Dim _Name_ImmovablesGroups As String : Dim _UniqueObjects_ImmovablesGroups As UniqueObjects
        Dim _Name_ImmovablesGroups_X As String : Dim _UniqueObjects_ImmovablesGroups_X As UniqueObjects
        Dim _Name_Floor As String : Dim _UniqueObjects_Floor As UniqueObjects
        Dim _Name_Floor_X As String : Dim _UniqueObjects_Floor_X As UniqueObjects
        Dim _Name_Garages As String : Dim _UniqueObjects_Garages As UniqueObjects

        _Name_ImmovablesGroups = Me.ImmovableGroups.UniqueTag
        _Name_ImmovablesGroups_X = Me.ImmovableGroups.UniqueTag & "-X"

        _UniqueObjects_ImmovablesGroups = Session.FindObject(Of UniqueObjects)(CriteriaOperator.Parse("Name=?", _Name_ImmovablesGroups))
        If _UniqueObjects_ImmovablesGroups Is Nothing Then
            _UniqueObjects_ImmovablesGroups = New UniqueObjects(Session)
            _UniqueObjects_ImmovablesGroups.Name = _Name_ImmovablesGroups
            _UniqueObjects_ImmovablesGroups.Save()
        End If
        _UniqueObjects_ImmovablesGroups_X = Session.FindObject(Of UniqueObjects)(CriteriaOperator.Parse("Name=?", _Name_ImmovablesGroups_X))
        If _UniqueObjects_ImmovablesGroups_X Is Nothing Then
            _UniqueObjects_ImmovablesGroups_X = New UniqueObjects(Session)
            _UniqueObjects_ImmovablesGroups_X.Name = _Name_ImmovablesGroups_X
            _UniqueObjects_ImmovablesGroups_X.Parent = _UniqueObjects_ImmovablesGroups
            _UniqueObjects_ImmovablesGroups_X.Save()
        End If

        _Name_Floor = _Name_ImmovablesGroups & "-" & "-" & Me.Floor.UniqueTag
        _Name_Floor_X = _Name_ImmovablesGroups & "-" & "-" & Me.Floor.UniqueTag & "-X"

        _UniqueObjects_Floor = Session.FindObject(Of UniqueObjects)(CriteriaOperator.Parse("Name=?", _Name_Floor))
        If _UniqueObjects_Floor Is Nothing Then
            _UniqueObjects_Floor = New UniqueObjects(Session)
            _UniqueObjects_Floor.Name = _Name_Floor
            _UniqueObjects_Floor.Parent = _UniqueObjects_ImmovablesGroups
            _UniqueObjects_Floor.Save()
        End If
        _UniqueObjects_Floor_X = Session.FindObject(Of UniqueObjects)(CriteriaOperator.Parse("Name=?", _Name_Floor_X))
        If _UniqueObjects_Floor_X Is Nothing Then
            _UniqueObjects_Floor_X = New UniqueObjects(Session)
            _UniqueObjects_Floor_X.Name = _Name_Floor_X
            _UniqueObjects_Floor_X.Parent = _UniqueObjects_Floor
            _UniqueObjects_Floor_X.Save()
        End If

        _Name_Garages = Me.ImmovableGroups.UniqueTag & "-" & Me.Floor.UniqueTag & UniqueTag

        _UniqueObjects_Garages = Session.FindObject(Of UniqueObjects)(CriteriaOperator.Parse("Name=?", _Name_Garages))
        If _UniqueObjects_Garages Is Nothing Then
            _UniqueObjects_Garages = New UniqueObjects(Session)
            _UniqueObjects_Garages.Name = _Name_Garages
            _UniqueObjects_Garages.Parent = _UniqueObjects_Floor
            _UniqueObjects_Garages.Save()
            Me.UniqueObjects = _UniqueObjects_Garages
        End If
    End Sub

    '-----NonPersistes-----
    <NonPersistent(), VisibleInListView(False), VisibleInLookupListView(False)> _
    Property OfferListPriceNettoHUF As Double = 0
    <NonPersistent(), VisibleInListView(False), VisibleInLookupListView(False)> _
    Property OfferListPriceNettoHUFRent As Double = 0
    <NonPersistent(), VisibleInListView(False), VisibleInLookupListView(False)> _
    Property OfferListPriceBruttoHUF As Double = 0
    <NonPersistent(), VisibleInListView(False), VisibleInLookupListView(False)> _
    Property OfferListPriceBruttoHUFRent As Double = 0
End Class 'Garázsok
