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.Persistent.Base.General
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Linq
Imports System.Linq.Expressions
Imports DevExpress.ExpressApp.ConditionalAppearance

<DefaultClassOptions()> _
<NavigationItem(False), CreatableItem(False)> _
<DeferredDeletion(False)> _
<Appearance("Disable UserCreated,ObjectCreated-SpecTranRevaluation", AppearanceItemType:="ViewItem", Enabled:=False, TargetItems:="ObjectCreated,UserCreated", Criteria:="1=1")> _
Public Class SpecTranRevaluation 'Devizás átértékelés
    Inherits BaseObject
    Private _CustomersFrom As CustomersFrom
    Private _DateClose As Date '-- Záró dátum
    Private _ShortName As String '-- Lekérdezés megnevezése
    Private _CurrencyName As CurrencyName '-- Záró kimutatás devizaneme
    Private _CurrencyRate As Double '-- Záró kimutatás átértékelési árfolyama
    Private _ObjectCreated As Date
    Private _UserCreated As User
    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))
        End If
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
        If Session.IsNewObject(Me) Then
            Me.DateClose = Now
        End If
    End Sub
    Property CustomersFrom As CustomersFrom
        Get
            Return _CustomersFrom
        End Get
        Set(value As CustomersFrom)
            SetPropertyValue("CustomersFrom", _CustomersFrom, value)
        End Set
    End Property
    Property DateClose As Date
        Get
            Return _DateClose
        End Get
        Set(ByVal value As Date)
            SetPropertyValue("DateClose", _DateClose, value)
        End Set
    End Property
    Property ShortName As String
        Get
            Return _ShortName
        End Get
        Set(value As String)
            SetPropertyValue("ShortName", _ShortName, value)
        End Set
    End Property
    <ImmediatePostData(True)> _
    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
                '// MNB Árfolyam lekérése a záró dátumra
                Dim _CurrencyRate As CurrencyRate = Session.FindObject(Of CurrencyRate)(CriteriaOperator.Parse("IsMNB=True and GetDate(DateValid)=? and CurrencyName.ShortName=?", Me.DateClose.Date, value.ShortName))
                If _CurrencyRate IsNot Nothing Then
                    If CurrencyRate = 0 Then
                        CurrencyRate = _CurrencyRate.RateAverage
                    End If
                End If
            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
    <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

    <Association("SpecTranRevaluation-SpecTranRevaluationRowsAccounts", GetType(SpecTranRevaluationRowsAccounts)), VisibleInListView(False)> _
    ReadOnly Property SpecTranRevaluationRowsAccounts As XPCollection(Of SpecTranRevaluationRowsAccounts)
        Get
            Return GetCollection(Of SpecTranRevaluationRowsAccounts)("SpecTranRevaluationRowsAccounts")
        End Get
    End Property
    <Association("SpecTranRevaluation-SpecTranRevaluationLiquidAssets", GetType(SpecTranRevaluationLiquidAssets))> _
    ReadOnly Property SpecTranRevaluationLiquidAssets As XPCollection(Of SpecTranRevaluationLiquidAssets)
        Get
            Return GetCollection(Of SpecTranRevaluationLiquidAssets)("SpecTranRevaluationLiquidAssets")
        End Get
    End Property
End Class

