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.ExpressApp.Editors
Imports DevExpress.ExpressApp.ConditionalAppearance

Public Enum eOrderOutStockQueryType
    eNotSet = 0
    eProduct = 1 'Teljes terméktörzs
    eStorageComputed = 2 'Valaha raktáron lévő tételek
    eInMinimum = 3 'Minimumkészleten, vagy az alatt
End Enum
<DefaultClassOptions(), NavigationItem(False), CreatableItem(False)> _
<Appearance("Disable OrderOutStockQueryType", AppearanceItemType:="ViewItem", Criteria:="OrderOutStockQueryType<>'eNotSet'", TargetItems:="OrderOutStockQueryType", Enabled:=False)> _
<Appearance("Hide Criterion", AppearanceItemType:="ViewItem", Criteria:="OrderOutStockQueryType='eNotSet'", TargetItems:="Criterion", Visibility:=Editors.ViewItemVisibility.Hide)> _
Public Class OrderOutStockHeader 'Raktárfeltöltő rendelés elemző rész
    Inherits BaseObject

    Private _OrderOutStockQueryType As eOrderOutStockQueryType
    Private _CustomersFrom As CustomersFrom
    Private _ShortName As String
    Private _UserCreated As User
    Private _ObjectCreated As Date
    Private _Criterion As String
    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.
        Me.OrderOutStockQueryType = eOrderOutStockQueryType.eNotSet
    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
    <ImmediatePostData()> _
    Property OrderOutStockQueryType As eOrderOutStockQueryType
        Get
            Return _OrderOutStockQueryType
        End Get
        Set(value As eOrderOutStockQueryType)
            SetPropertyValue("OrderOutStockQueryType", _OrderOutStockQueryType, value)
        End Set
    End Property
    Property CustomersFrom As CustomersFrom
        Get
            Return _CustomersFrom
        End Get
        Set(value As CustomersFrom)
            SetPropertyValue("CustomersFrom", _CustomersFrom, 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
    <NonCloneable> _
    Property UserCreated As User
        Get
            Return _UserCreated
        End Get
        Set(value As User)
            SetPropertyValue("UserCreated", _UserCreated, 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
    Private ReadOnly Property ObjectType() As Type
        Get
            Select Case Me.OrderOutStockQueryType
                Case eOrderOutStockQueryType.eInMinimum
                    Return GetType(StorageComputed)
                Case eOrderOutStockQueryType.eProduct
                    Return GetType(Products)
                Case eOrderOutStockQueryType.eStorageComputed
                    Return GetType(StorageComputed)
                Case Else
                    Return GetType(Products)
            End Select

        End Get
    End Property
    <CriteriaOptions("ObjectType"), Size(-1), ImmediatePostData()> _
    Public Property Criterion() As String
        Get
            Return _Criterion
        End Get
        Set(ByVal value As String)
            SetPropertyValue("Criterion", _Criterion, value)
        End Set
    End Property


    <Association("OrderOutStockHeader-OrderOutStockRows", GetType(OrderOutStockRows)), VisibleInListView(False), VisibleInLookupListView(False)> _
    ReadOnly Property OrderOutStockRows As XPCollection(Of OrderOutStockRows)
        Get
            Return GetCollection(Of OrderOutStockRows)("OrderOutStockRows")
        End Get
    End Property
End Class
