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.ConditionalAppearance

Public Enum eInventoryStatus
    eOpen = 0
    eClosed = 1
End Enum
<DefaultClassOptions()> _
<NavigationItem("StorageTransactions"), CreatableItem(False)> _
<Appearance("Disable InventoryHeader-ObjectCreated", AppearanceItemType.ViewItem, "1=1", TargetItems:="ObjectCreated", Enabled:=False)> _
<Appearance("Disable InventoryHeader-UserCreated", AppearanceItemType.ViewItem, "1=1", TargetItems:="UserCreated", Enabled:=False)> _
<Appearance("Disable InventoryHeader-InventoryStatus", AppearanceItemType.ViewItem, "1=1", TargetItems:="InventoryStatus", Enabled:=False)> _
<Appearance("Disable InventoryHeader-InventoryHeaderDateClose", AppearanceItemType.ViewItem, "1=1", TargetItems:="InventoryHeaderDateClose", Enabled:=False)> _
<Appearance("Disable InventoryHeader-Storage", AppearanceItemType.ViewItem, "1=1", TargetItems:="Storage", Enabled:=False)> _
<Appearance("Disable InventoryHeader-DocumentNumber", AppearanceItemType.ViewItem, "1=1", TargetItems:="DocumentNumber", Enabled:=False)> _
Public Class InventoryHeader
    Inherits BaseObject

    Private _DocumentNumber As String
    Private _Storage As Storage
    Private _InventoryStatus As eInventoryStatus
    Private _InventoryParameters As InventoryParameters
    Private _DateClose As Date
    Private _InventoryHeaderDateClose As Date
    Private _ObjectCreated As Date
    Private _UserCreated As User
    Private _ExcelProperty As String
    Private _ExcelFile As FileData
    Private _InventoryInspector As HRPerson 'Ellenőr
    Private _InventoryCreator As HRPerson 'Leltárt készítő/elvégző/végrehejtó
    Private _InventorySignedDocument As FileData

    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
        Me.InventoryStatus = eInventoryStatus.eOpen
    End Sub

    Protected Overrides Sub OnSaving()
        MyBase.OnSaving()
        If String.IsNullOrEmpty(DocumentNumber) Then
            DocumentNumber = InventoryParameters.NumberGenerator.GetNewNumber(InventoryParameters.NumberGenerator)
        End If
        If Session.IsNewObject(Me) Then
            ObjectCreated = GetSQLTime(Session)
            UserCreated = Session.GetObjectByKey(Of User)(Session.GetKeyValue(SecuritySystem.CurrentUser))
        End If
    End Sub
    Property DocumentNumber As String
        Get
            Return _DocumentNumber
        End Get
        Set(value As String)
            SetPropertyValue("DocumentNumber", _DocumentNumber, value)
        End Set
    End Property
    Property Storage As Storage
        Get
            Return _Storage
        End Get
        Set(value As Storage)
            SetPropertyValue("Storage", _Storage, value)
        End Set
    End Property
    Property InventoryStatus As eInventoryStatus
        Get
            Return _InventoryStatus
        End Get
        Set(value As eInventoryStatus)
            SetPropertyValue("InventoryStatus", _InventoryStatus, value)
        End Set
    End Property
    <RuleRequiredField("InventoryHeader -InventoryParameters ", DefaultContexts.Save)> _
    Property InventoryParameters As InventoryParameters
        Get
            Return _InventoryParameters
        End Get
        Set(value As InventoryParameters)
            SetPropertyValue("InventoryParameters", _InventoryParameters, value)
        End Set
    End Property
    Property DateClose As Date
        Get
            Return _DateClose
        End Get
        Set(value As Date)
            SetPropertyValue("DateClose", _DateClose, value)
        End Set
    End Property
    Property InventoryHeaderDateClose As Date
        Get
            Return _InventoryHeaderDateClose
        End Get
        Set(value As Date)
            SetPropertyValue("InventoryHeaderDateClose", _InventoryHeaderDateClose, 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
    <Size(-1)> _
   <ImmediatePostData(True)> _
    Property ExcelProperty As String
        Get
            Return _ExcelProperty
        End Get
        Set(value As String)
            SetPropertyValue("ExcelProperty", _ExcelProperty, value)
        End Set
    End Property
    <VisibleInListView(False)> _
    <VisibleInDetailView(False)> _
    Property ExcelFile As FileData
        Get
            Return _ExcelFile
        End Get
        Set(value As FileData)
            SetPropertyValue("ExcelFile", _ExcelFile, value)
        End Set
    End Property
    <RuleRequiredField("InventoryHeader - InventoryInspector ", DefaultContexts.Save)> _
    Property InventoryInspector As HRPerson
        Get
            Return _InventoryInspector
        End Get
        Set(value As HRPerson)
            SetPropertyValue("InventoryInspector", _InventoryInspector, value)
        End Set
    End Property
    <RuleRequiredField("InventoryHeader - InventoryCreator ", DefaultContexts.Save)> _
    Property InventoryCreator As HRPerson
        Get
            Return _InventoryCreator
        End Get
        Set(value As HRPerson)
            SetPropertyValue("InventoryCreator", _InventoryCreator, value)
        End Set
    End Property
    Property InventorySignedDocument As FileData
        Get
            Return _InventorySignedDocument
        End Get
        Set(value As FileData)
            SetPropertyValue("InventorySignedDocument", _InventorySignedDocument, value)
        End Set
    End Property

    '-------------------------ReadOnly-----------------------
    <VisibleInListView(False)> _
    <Aggregated()> _
    <Association("InventoryHeader-InventorySC", GetType(InventorySC))> _
    Public ReadOnly Property InventorySC() As XPCollection(Of InventorySC)
        Get
            Return GetCollection(Of InventorySC)("InventorySC")
        End Get
    End Property
    <VisibleInListView(False)> _
    <Aggregated()> _
    <Association("InventoryHeader-InventorySIR", GetType(InventorySIR))> _
    Public ReadOnly Property InventorySIR() As XPCollection(Of InventorySIR)
        Get
            Return GetCollection(Of InventorySIR)("InventorySIR")
        End Get
    End Property
    <VisibleInListView(False)> _
   <Aggregated()> _
   <Association("InventoryHeader-InventoryPDA", GetType(InventoryPDA))> _
    Public ReadOnly Property InventoryPDA() As XPCollection(Of InventoryPDA)
        Get
            Return GetCollection(Of InventoryPDA)("InventoryPDA")
        End Get
    End Property
    <VisibleInListView(False)> _
    <Aggregated()> _
    <Association("InventoryHeader-InventoryDifferent", GetType(InventoryDifferent))> _
    Public ReadOnly Property InventoryDifferent() As XPCollection(Of InventoryDifferent)
        Get
            Return GetCollection(Of InventoryDifferent)("InventoryDifferent")
        End Get
    End Property
End Class
