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

'<EditorStateRule("Disabled properties when IsEditable=False", "*", ViewType.DetailView, "IsEditable = False", EditorState.Disabled)> _

<Appearance("Disabled properties when IsEditable=False", TargetItems:="*", Criteria:="IsEditable = False", Enabled:=False, Context:="DetailView")> _
<Appearance("Hide row_ properties when IsEditable=False", AppearanceItemType.ViewItem, "IsEditable=False", TargetItems:="row_Products;row_QTT_WILL;row_PacketNumber;row_SerialNumber;row_Weight", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("Disable aToTable_StorageIn", AppearanceItemType.Action, "IsEditable = False", TargetItems:="aToTable_StorageIn", Enabled:=False)> _
<Appearance("Hide aToTable_StorageIn", AppearanceItemType.Action, "StorageMoveType.MoveType=6", TargetItems:="aToTable_StorageIn", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("Hide aStorageInFromPdaCollection", AppearanceItemType.Action, "StorageMoveType.MoveType=6", TargetItems:="aStorageInFromPdaCollection", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("Disable aToTableD_SIH", AppearanceItemType.Action, "IsEditable = False", TargetItems:="aToTableD_SIH", Enabled:=False)> _
<Appearance("Hide Item3 StorageOutHeader", AppearanceItemType.LayoutItem, "IsNull(Storage) Or IsNull(DocumentNumber) Or IsNull(StorageMoveType)", TargetItems:="Item3", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("Disable StorageInRows when IsStorno=True", AppearanceItemType.ViewItem, "IsStorno=True", TargetItems:="StorageInRows", Enabled:=False)> _
<Appearance("Hide row_PacketNumber when row_Products.ProductType!=2", AppearanceItemType.ViewItem, "row_Products.ProductType!=2", TargetItems:="row_PacketNumber", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("Hide row_SerialNumber when row_Products.ProductType!=1", AppearanceItemType.ViewItem, "row_Products.ProductType!=1", TargetItems:="row_SerialNumber", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("Hide StorageFrom property when StorageMoveType.MoveType<>6", AppearanceItemType.ViewItem, "StorageMoveType.MoveType<>6", TargetItems:="StorageFrom", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("Hide aStorageInHeader_InsertInventoryTransfer when StorageMoveType.MoveType<>6", AppearanceItemType.Action, "StorageMoveType.MoveType<>6", TargetItems:="aStorageInHeader_InsertInventoryTransfer,aStorageInHeader_InsertInventoryTransfer_FIFO,aCheckInventoryTransfer", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("Hide row_ properties when StorageMoveType.MoveType<>6", AppearanceItemType.ViewItem, "StorageMoveType.MoveType=6", TargetItems:="row_Weight;row_Products;row_QTT_WILL;row_PacketNumber;row_SerialNumber", visibility:=Editors.ViewItemVisibility.Hide)> _
<DefaultClassOptions()> _
<NavigationItem("StorageTransactions")> _
Public Class StorageInHeader
    Inherits BaseObject
    Private _StorageMoveType As StorageMoveType
    Private _DocumentNumber As String ' Bizonylatszám
    Private _ConnectInfo As String
    Private _Storage As Storage ' Raktár
    Private _StorageFrom As Storage '
    Private _CreateDate As Date ' Kiállítás dátuma
    Private _Active As Boolean = True ' Aktív
    Private _ObjectCreated As Date ' Objektum mikor készült
    Private _UserCreated As User 'Ki készítette
    Private _IsStorno As Boolean = False 'Storno e?
    Private _IsEditable As Boolean = True 'Végleges e?
    Private _IsFinalized As Boolean = False 'Volt-e már véglegesítve ?
    Private _RecipeExecutionSimple As RecipeExecutionSimple 'Melyik gyártáshoz kapcs. betárolás
    Private _StoragePDACollectionHeader As StoragePDACollectionHeader
    '--------------------------------------------------------
    Private _row_Products As Products ' Termék
    Private _row_QTT_Will As Double ' Mennyiség (szándék)
    Private _row_PacketNumber As String 'Kötegszám
    Private _row_SerialNumber As String ' Sorozatszám
    Private _row_Weight As Double
    Private _row_WeightMode As eWeightMode
    '--------------------------------------------------------
    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Protected Overrides Sub OnSaving()
        MyBase.OnSaving()
        If String.IsNullOrEmpty(DocumentNumber) Then
            DocumentNumber = _Storage.NumberGeneratorIn.GetNewNumber(_Storage.NumberGeneratorIn)
            If String.IsNullOrEmpty(ConnectInfo) Then ConnectInfo = DocumentNumber
        End If
        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()
        CreateDate = GetSQLTime(Session)
    End Sub
    <ImmediatePostData()> _
    <RuleRequiredField("StorageInHeader-StorageMoveType", DefaultContexts.Save)> _
     <DataSourceCriteria("Storage='@This.Storage'")> _
    Property StorageMoveType As StorageMoveType
        Get
            Return _StorageMoveType
        End Get
        Set(value As StorageMoveType)
            SetPropertyValue("StorageMoveType", _StorageMoveType, value)
        End Set
    End Property
    <VisibleInListView(False)> _
    <Association("StorageIn", GetType(StorageInRows))> _
    Public ReadOnly Property StorageInRows() As XPCollection(Of StorageInRows)
        Get
            Return GetCollection(Of StorageInRows)("StorageInRows")
        End Get
    End Property
    Property DocumentNumber As String
        Get
            Return _DocumentNumber
        End Get
        Set(ByVal value As String)
            SetPropertyValue("DocumentNumber", _DocumentNumber, value)
        End Set
    End Property
    Property ConnectInfo As String
        Get
            Return _ConnectInfo
        End Get
        Set(value As String)
            SetPropertyValue("ConnectInfo", _ConnectInfo, value)
        End Set
    End Property
    <RuleRequiredField("", DefaultContexts.Save)> _
    Property Storage As Storage
        Get
            Return _Storage
        End Get
        Set(ByVal value As Storage)
            SetPropertyValue("Storage", _Storage, value)
        End Set
    End Property
    <ImmediatePostData()> _
    <RuleRequiredField("StorageInHeader - StorageFrom", DefaultContexts.Save, TargetCriteria:="StorageMoveType.MoveType=6")> _
    Property StorageFrom As Storage
        Get
            Return _StorageFrom
        End Get
        Set(value As Storage)
            SetPropertyValue("StorageFrom", _StorageFrom, value)
        End Set
    End Property
    <RuleRequiredField("StorageInHeader-CreateDate", DefaultContexts.Save)> _
    Property CreateDate As Date
        Get
            Return _CreateDate
        End Get
        Set(ByVal value As Date)
            SetPropertyValue("CreateDate", _CreateDate, value)
        End Set
    End Property
    Property Active As Boolean
        Get
            Return _Active
        End Get
        Set(ByVal value As Boolean)
            SetPropertyValue("Active", _Active, value)
        End Set
    End Property
    <NonCloneable> _
    Property ObjectCreated As Date
        Get
            Return _ObjectCreated
        End Get
        Set(ByVal 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
    Property IsStorno As Boolean
        Get
            Return _IsStorno
        End Get
        Set(ByVal value As Boolean)
            SetPropertyValue("IsStorno", _IsStorno, value)
        End Set
    End Property
    Property IsEditable As Boolean
        Get
            Return _IsEditable
        End Get
        Set(ByVal value As Boolean)
            SetPropertyValue("IsEditable", _IsEditable, value)
        End Set
    End Property
    <Browsable(False)> _
    Property IsFinalized As Boolean
        Get
            Return _IsFinalized
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsFinalized", _IsFinalized, value)
        End Set
    End Property
    Property RecipeExecutionSimple As RecipeExecutionSimple
        Get
            Return _RecipeExecutionSimple
        End Get
        Set(value As RecipeExecutionSimple)
            SetPropertyValue("RecipeExecutionSimple", _RecipeExecutionSimple, value)
        End Set
    End Property
    Property StoragePDACollectionHeader As StoragePDACollectionHeader
        Get
            Return _StoragePDACollectionHeader
        End Get
        Set(value As StoragePDACollectionHeader)
            SetPropertyValue("StoragePDACollectionHeader", _StoragePDACollectionHeader, value)
        End Set
    End Property

    <NonPersistent()> _
    <RuleRequiredField("StorageInHeader-row_Products", "aToTable_StorageIn_Context")> _
    <VisibleInListView(False)> _
    <ImmediatePostData()> _
    Property row_Products As Products
        Get
            Return _row_Products
        End Get
        Set(ByVal value As Products)
            SetPropertyValue("row_Products", _row_Products, value)
        End Set
    End Property
    <NonPersistent()> _
    <RuleRange("StorageInHeader-row_QTT_Will", "aToTable_StorageIn_Context", 0.0001, Double.MaxValue, TargetCriteria:="IsEditable=True")> _
    <VisibleInListView(False)> _
    Property row_QTT_WILL As Double
        Get
            Return _row_QTT_Will
        End Get
        Set(ByVal value As Double)
            SetPropertyValue("row_QTT_Will", _row_QTT_Will, value)
        End Set
    End Property
    <NonPersistent()> _
    <VisibleInListView(False)> _
    Property row_PacketNumber As String
        Get
            Return _row_PacketNumber
        End Get
        Set(value As String)
            SetPropertyValue(" row_PacketNumber", _row_PacketNumber, value)
        End Set
    End Property
    <NonPersistent()> _
    <VisibleInListView(False)> _
    Property row_SerialNumber As String
        Get
            Return _row_SerialNumber
        End Get
        Set(value As String)
            SetPropertyValue("row_SerialNumber", _row_SerialNumber, value)
        End Set
    End Property
    <NonPersistent()> _
   <VisibleInListView(False)> _
    Property row_Weight As Double
        Get
            Return _row_Weight
        End Get
        Set(value As Double)
            SetPropertyValue("row_Weight", _row_Weight, value)
        End Set
    End Property
    <NonPersistent>
    Property row_WeightMode As eWeightMode
        Get
            Return _row_WeightMode
        End Get
        Set(value As eWeightMode)
            SetPropertyValue("row_WeightMode", _row_WeightMode, value)
        End Set
    End Property
End Class
