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 StudentHostel
    Inherits Immovables
    Private _Apartments As Apartments
    Private _PriceBruttoHUF As Double
    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.eStudentHostel
    End Sub
    Protected Overrides Sub OnSaving()
        If Session.IsNewObject(Me) Then
            If UniqueTag <> "*" Then Me.MakeUniqueObjects_StudentHostel()
        End If
        MyBase.OnSaving()
    End Sub
    Property Apartments() As Apartments
        Get
            Return _Apartments
        End Get
        Set(ByVal value As Apartments)
            SetPropertyValue("Apartments", _Apartments, 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

    Property PriceBruttoDEV() As Double
        Get
            Return _PriceBruttoDEV
        End Get
        Set(ByVal value As Double)
            SetPropertyValue("PriceBruttoDEV", _PriceBruttoDEV, value)
        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
    <RuleRequiredField("StudentHostel-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_StudentHostel()
        Dim _Name_Apartments As String : Dim _UniqueObjects_Apartments As UniqueObjects
        Dim _Name_Apartments_X As String : Dim _UniqueObjects_Apartments_X As UniqueObjects
        Dim _Name_StudentHostel As String : Dim _UniqueObjects_StudentHostel As UniqueObjects
        'Dim _Name_StudentHostel_X As String : Dim _UniqueObjects_StudentHostel_X As UniqueObjects

        _Name_Apartments = Me._Apartments.UniqueObjects.ToString
        _Name_Apartments_X = Me.Apartments.UniqueObjects.ToString & "-X"

        _UniqueObjects_Apartments = Session.FindObject(Of UniqueObjects)(CriteriaOperator.Parse("Name=?", _Name_Apartments))
        If _UniqueObjects_Apartments Is Nothing Then
            _UniqueObjects_Apartments = New UniqueObjects(Session)
            _UniqueObjects_Apartments.Name = _Name_Apartments
            _UniqueObjects_Apartments.Save()
        End If
        _UniqueObjects_Apartments_X = Session.FindObject(Of UniqueObjects)(CriteriaOperator.Parse("Name=?", _Name_Apartments_X))
        If _UniqueObjects_Apartments_X Is Nothing Then
            _UniqueObjects_Apartments_X = New UniqueObjects(Session)
            _UniqueObjects_Apartments_X.Name = _Name_Apartments_X
            _UniqueObjects_Apartments_X.Parent = _UniqueObjects_Apartments
            _UniqueObjects_Apartments_X.Save()
        End If

        _Name_StudentHostel = Me._Apartments.UniqueObjects.ToString & "-" & _UniqueTag

        _UniqueObjects_StudentHostel = Session.FindObject(Of UniqueObjects)(CriteriaOperator.Parse("Name=?", _Name_StudentHostel))
        If _UniqueObjects_StudentHostel Is Nothing Then
            _UniqueObjects_StudentHostel = New UniqueObjects(Session)
            _UniqueObjects_StudentHostel.Name = _Name_StudentHostel
            _UniqueObjects_StudentHostel.Parent = _UniqueObjects_Apartments
            _UniqueObjects_StudentHostel.Save()
            Me.UniqueObjects = _UniqueObjects_StudentHostel
        End If

    End Sub
End Class 'Bérlemények (kollégiumi férőhelyek
