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

<DefaultClassOptions(), NavigationItem(False), CreatableItem(False), NonPersistent> _
Public Class RecalcDEV
    Inherits BaseObject
    Private _PriceMode As ePriceMode
    Private _CurrencyRate As Double
    Private _CurrencyName As CurrencyName
    Private _DateExecution As Date
    Public Sub New(ByVal session As Session)
        MyBase.New(session)
        ' This constructor is used when an object is loaded from a persistent storage.
        ' Do not place any code here or place it only when the IsLoading property is false:
        ' if (!IsLoading){
        '   It is now OK to place your initialization code here.
        ' }
        ' or as an alternative, move your initialization code into the AfterConstruction method.
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
        ' Place here your initialization code.
    End Sub
    <ImmediatePostData()> _
    Property PriceMode As ePriceMode
        Get
            Return _PriceMode
        End Get
        Set(value As ePriceMode)
            SetPropertyValue("PriceMode", _PriceMode, value)
            If Session.IsObjectsLoading = False And Session.IsObjectsSaving = False Then
                DateExecution = DateExecution
            End If
        End Set
    End Property
    <ImmediatePostData()> _
    Property CurrencyName As CurrencyName
        Get
            Return _CurrencyName
        End Get
        Set(value As CurrencyName)
            SetPropertyValue("CurrencyName", _CurrencyName, value)
            If Session.IsObjectsLoading = False And Session.IsObjectsSaving = False Then
                DateExecution = DateExecution
            End If
        End Set
    End Property
    Property CurrencyRate As Double
        Get
            Return _CurrencyRate
        End Get
        Set(value As Double)
            SetPropertyValue("CurrencyRate", _CurrencyRate, value)
        End Set
    End Property
    <ImmediatePostData()> _
    Property DateExecution As Date
        Get
            Return _DateExecution
        End Get
        Set(value As Date)
            SetPropertyValue("DateExecution", _DateExecution, value)
            If Session.IsObjectsLoading = False And Session.IsObjectsSaving = False Then
                '// MNB árfolyam lekérése
                If CurrencyName IsNot Nothing Then
                    Dim _CurrencyRate_MNB_Collection = New XPCollection(Of CurrencyRate) _
                    (Session, CriteriaOperator.Parse("CurrencyName.ShortName=? and IsMNB=True and GetDate(DateValid)<=?", _
                    CurrencyName.ShortName, DateExecution.Date))
                    _CurrencyRate_MNB_Collection.Sorting.Add(New SortProperty("DateValid", DB.SortingDirection.Descending))
                    If _CurrencyRate_MNB_Collection.Count > 0 Then
                        For Each _CurrencyRate_MNB In _CurrencyRate_MNB_Collection
                            If _CurrencyRate_MNB.DateValid.Date = value.Date Then 'Now
                                CurrencyRate = _CurrencyRate_MNB.RateAverage
                                Exit For
                            Else
                                CurrencyRate = 0
                            End If
                            Exit For
                        Next
                    End If
                End If
            End If
        End Set
    End Property
End Class
