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")> _
<DefaultProperty("DisplayName")> _
Public Class Immovables
    Inherits BaseObject
    Private _ImmovableGroups As ImmovablesGroups 'Ingatlan csoport
    Private _ImmovableSoldState As eImmovableSoldState 'Ingatlan eladható státusz
    Private _ImmovablesRentState As eImmovablesRentState 'Ingatlan bérelhető státusz
    Private _ImmovableTypes As eImmovablesTypes 'Ingatlan tipus
    Private _LotNumber As String 'Helyrajzi szám
    Private _Address As Address 'Cím
    Private _ImagePicture1 As Image '1. kép
    Private _ImagePicture2 As Image '2. kép
    Private _ImagePicture3 As Image '3. kép
    Private _CustomersOwner As Customers 'Tulajdonos.
    Private _CustomersLessor As Customers 'Bérbeadó
    Private _CanforSale As Boolean 'Eladható
    Private _CanForRent As Boolean 'Bérelhető
    Private _UniqueObjects As UniqueObjects 'Egyedi azonosító
    Private _PriceNettoHUFRent As Double 'Ingatlan bérleti dija / hó bruttó
    Private _PriceBruttoHUFRent As Double 'Ingatlan bérleti dija / hó nettó
    Private _PriceNettoDEVRent As Double 'Ingatlan bérleti dija / hó bruttó
    Private _PriceBruttoDEVRent As Double 'Ingatlan bérleti dija / hó nettó
    Private _PriceAreaNettoHUFRent As Double 'Netto négyzetméter /hó
    Private _PriceAreaBruttoHUFRent As Double 'Brutto négyzetméter /hó
    Private _PriceAreaNettoDEVRent As Double 'Netto bérleti négyzetméter ár 
    Private _PriceAreaBruttoDEVRent As Double 'Brutto bérleti négyzetméter ár 

    Private _Ownership1 As String 'Tulajdoni hányadot jelölő tört szám pld 715/100.000
    Private _Ownership2 As String 'Tulajdoni hányadot jelölő tört szám pld 715/100.000
    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Public Sub RecalculatePriceRent()

        'Lakások esetében
        If TryCast(Me, Apartments) IsNot Nothing Then
            Dim _Immo As Apartments = TryCast(Me, Apartments)
            _Immo.PriceNettoHUFRent = Math.Round(_Immo.AreaNettoForSale * _Immo.PriceAreaNettoHUFRent, 0, MidpointRounding.AwayFromZero)
            _Immo.PriceNettoDEVRent = Math.Round(_Immo.AreaNettoForSale * _Immo.PriceAreaNettoDEVRent, 0, MidpointRounding.AwayFromZero)
        End If

        'Irodák esetében
        If TryCast(Me, Offices) IsNot Nothing Then
            Dim _Immo As Offices = TryCast(Me, Offices)
            _Immo.PriceNettoHUFRent = Math.Round(_Immo.AreaNettoForSale * _Immo.PriceAreaNettoHUFRent, 0, MidpointRounding.AwayFromZero)
            _Immo.PriceNettoDEVRent = Math.Round(_Immo.AreaNettoForSale * _Immo.PriceAreaNettoDEVRent, 0, MidpointRounding.AwayFromZero)
        End If

        Me.PriceAreaBruttoHUFRent = Math.Round(PriceAreaNettoHUFRent * 1.25, 0, MidpointRounding.AwayFromZero)
        Me.PriceAreaBruttoDEVRent = Math.Round(PriceAreaNettoDEVRent * 1.25, 0, MidpointRounding.AwayFromZero)

    End Sub
    Private Sub RecalculatePriceBruttoRent()
        PriceBruttoHUFRent = Math.Round(PriceNettoHUFRent * 1.25, 0, MidpointRounding.AwayFromZero)
        PriceBruttoDEVRent = Math.Round(PriceNettoDEVRent * 1.25, 0, MidpointRounding.AwayFromZero)
    End Sub
    <VisibleInListView(False)> _
    <Association("Immovables-DocumentAttachments", GetType(DocumentAttachments))> _
        ReadOnly Property DocumentAttachments() As XPCollection(Of DocumentAttachments)
        Get
            Return GetCollection(Of DocumentAttachments)("DocumentAttachments")
        End Get
    End Property
    <RuleRequiredField("Immovables-ImmovableGroups", DefaultContexts.Save)> _
    Property ImmovableGroups() As ImmovablesGroups
        Get
            Return _ImmovableGroups
        End Get
        Set(ByVal value As ImmovablesGroups)
            SetPropertyValue("ImmovableGroups", _ImmovableGroups, value)
        End Set
    End Property
    Property ImmovableSoldState As eImmovableSoldState
        Get
            Return _ImmovableSoldState
        End Get
        Set(value As eImmovableSoldState)
            SetPropertyValue("ImmovableSoldState", _ImmovableSoldState, value)
        End Set
    End Property
    Property ImmovablesRentState As eImmovablesRentState
        Get
            Return _ImmovablesRentState
        End Get
        Set(value As eImmovablesRentState)
            SetPropertyValue("ImmovablesRentState", _ImmovablesRentState, value)
        End Set
    End Property
    Property ImmovablesTypes() As eImmovablesTypes
        Get
            Return _ImmovableTypes
        End Get
        Set(ByVal value As eImmovablesTypes)
            SetPropertyValue("ImmovablesTypes", _ImmovableTypes, value)
        End Set
    End Property
    Property LotNumber() As String
        Get
            Return _LotNumber
        End Get
        Set(ByVal value As String)
            SetPropertyValue("LotNumber", _LotNumber, value)
        End Set
    End Property
    Property Address() As Address
        Get
            Return _Address
        End Get
        Set(ByVal value As Address)
            SetPropertyValue("Address", _Address, value)
        End Set
    End Property
    <ValueConverter(GetType(DevExpress.Xpo.Metadata.ImageValueConverter))> _
    <NonCloneable()> _
    Property ImagePicture1() As Image
        Get
            Return _ImagePicture1
        End Get
        Set(ByVal Value As System.Drawing.Image)
            If Value Is _ImagePicture1 Then Exit Property
            _ImagePicture1 = Value
        End Set
    End Property
    <ValueConverter(GetType(DevExpress.Xpo.Metadata.ImageValueConverter))> _
    <NonCloneable()> _
    Property ImagePicture2() As Image
        Get
            Return _ImagePicture2
        End Get
        Set(ByVal Value As System.Drawing.Image)
            If Value Is _ImagePicture2 Then Exit Property
            _ImagePicture2 = Value
        End Set
    End Property
    <ValueConverter(GetType(DevExpress.Xpo.Metadata.ImageValueConverter))> _
    <NonCloneable()> _
    Property ImagePicture3() As Image
        Get
            Return _ImagePicture3
        End Get
        Set(ByVal Value As System.Drawing.Image)
            If Value Is _ImagePicture3 Then Exit Property
            _ImagePicture3 = Value
        End Set
    End Property
    Property CustomersOwner() As Customers
        Get
            Return _CustomersOwner
        End Get
        Set(ByVal value As Customers)
            SetPropertyValue("CustomersOwner", _CustomersOwner, value)
        End Set
    End Property
    Property CustomersLessor() As Customers
        Get
            Return _CustomersLessor
        End Get
        Set(ByVal value As Customers)
            SetPropertyValue("CustomersLessor", _CustomersLessor, value)
        End Set
    End Property
    <NonCloneable()> _
    Property UniqueObjects() As UniqueObjects
        Get
            Return _UniqueObjects
        End Get
        Set(ByVal value As UniqueObjects)
            SetPropertyValue("UniqueObjects", _UniqueObjects, value)
        End Set
    End Property
    <NonCloneable()> _
    Property CanForSale As Boolean
        Get
            Return _CanforSale
        End Get
        Set(ByVal value As Boolean)
            SetPropertyValue("CanForSale", _CanforSale, value)
        End Set
    End Property
    <NonCloneable()> _
    Property CanForRent As Boolean
        Get
            Return _CanForRent
        End Get
        Set(ByVal value As Boolean)
            SetPropertyValue("CanForRent", _CanForRent, value)
        End Set
    End Property
    ReadOnly Property DisplayName As String
        Get
            If _UniqueObjects IsNot Nothing Then
                Return _UniqueObjects.Name
            Else
                Return ""
            End If
        End Get
    End Property
    Property PriceNettoHUFRent As Double
        Get
            Return _PriceNettoHUFRent
        End Get
        Set(value As Double)
            SetPropertyValue("PriceNettoHUFRent", _PriceNettoHUFRent, value)
            If Not Session.IsObjectsSaving And Not Session.IsObjectsLoading Then
                RecalculatePriceBruttoRent()
            End If
        End Set
    End Property
    Property PriceBruttoHUFRent As Double
        Get
            Return _PriceBruttoHUFRent
        End Get
        Set(value As Double)
            SetPropertyValue("PriceBruttoHUFRent", _PriceBruttoHUFRent, value)
        End Set
    End Property
    Property PriceNettoDEVRent As Double
        Get
            Return _PriceNettoDEVRent
        End Get
        Set(value As Double)
            SetPropertyValue("PriceNettoDEVRent", _PriceNettoDEVRent, value)
            If Not Session.IsObjectsSaving And Not Session.IsObjectsLoading Then
                RecalculatePriceBruttoRent()
            End If
        End Set
    End Property
    Property PriceBruttoDEVRent As Double
        Get
            Return _PriceBruttoDEVRent
        End Get
        Set(value As Double)
            SetPropertyValue("PriceBruttoDEVRent", _PriceBruttoDEVRent, value)
        End Set
    End Property
    Property PriceAreaNettoHUFRent As Double
        Get
            Return _PriceAreaNettoHUFRent
        End Get
        Set(value As Double)
            SetPropertyValue("PriceAreaNettoHUFRent", _PriceAreaNettoHUFRent, value)
            If Not Session.IsObjectsLoading And Not Session.IsObjectsSaving And Not value = 0 Then
                RecalculatePriceRent()
            End If
        End Set
    End Property
    Property PriceAreaBruttoHUFRent As Double
        Get
            Return _PriceAreaBruttoHUFRent
        End Get
        Set(value As Double)
            SetPropertyValue("PriceAreaBruttoHUFRent", _PriceAreaBruttoHUFRent, value)
        End Set
    End Property
    Property PriceAreaBruttoDEVRent As Double
        Get
            Return _PriceAreaBruttoDEVRent
        End Get
        Set(value As Double)
            SetPropertyValue("PriceAreaBruttoDEVRent", _PriceAreaBruttoDEVRent, value)
        End Set
    End Property
    Property PriceAreaNettoDEVRent As Double
        Get
            Return _PriceAreaNettoDEVRent
        End Get
        Set(value As Double)
            SetPropertyValue("PriceAreaNettoDEVRent", _PriceAreaNettoDEVRent, value)
        End Set
    End Property

    Property Ownership1 As String
        Get
            Return _Ownership1
        End Get
        Set(value As String)
            SetPropertyValue("Ownership1", _Ownership1, value)
        End Set
    End Property
    Property Ownership2 As String
        Get
            Return _Ownership2
        End Get
        Set(value As String)
            SetPropertyValue("Ownership2", _Ownership2, value)
        End Set
    End Property


    '// Bérleti lekérdezési információk
    Private _Last_ContractsRows As ContractRows
    Property Last_ContractsRows As ContractRows
        Get
            Return _Last_ContractsRows
        End Get
        Set(value As ContractRows)
            SetPropertyValue("Last_ContractsRows", _Last_ContractsRows, value)
        End Set
    End Property

End Class ' Ingatlanok
