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

<DefaultClassOptions()> _
<NavigationItem("BusinessTransactions")> _
<Appearance("DeliveryNoteOutHeader - Disabled IsEditable and IsStorno", "1=1", TargetItems:="IsEditable;IsStorno", Enabled:=False)> _
<Appearance("DeliveryNoteOutHeader - Disable DeliveryNoteOutHeader-DocumentNumber", AppearanceItemType.ViewItem, "1=1", TargetItems:="DocumentNumber", Enabled:=False)> _
<Appearance("DeliveryNoteOutHeader - Disable ObjectCreated DeliveryNoteOutHeader", AppearanceItemType.ViewItem, "1=1", TargetItems:="ObjectCreated", Enabled:=False)> _
<Appearance("DeliveryNoteOutHeader - Disable UserCreated DeliveryNoteOutHeader", AppearanceItemType.ViewItem, "IsEditable=False", TargetItems:="*", Enabled:=False)> _
<Appearance("DeliveryNoteOutHeader - Disable all property when IsEditable=False DeliveryNoteOutHeader", AppearanceItemType.ViewItem, "1=1", TargetItems:="UserCreated", Enabled:=False)> _
<Appearance("DeliveryNoteOutHeader - Hide Item2 DeliveryNoteOutHeader", AppearanceItemType.LayoutItem, "IsNull(DocumentNumber) Or IsNull(DeliveryNoteOutType) Or IsNull(Customers) Or IsNull(CustomersFrom) Or IsNull(ShipmentOption)", TargetItems:="Item2", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("DeliveryNoteOutHeader - Disable aTotable_DeliveryNoteOut", AppearanceItemType.Action, "IsEditable = False", TargetItems:="aTotable_DeliveryNoteOut", Enabled:=False)> _
<Appearance("DeliveryNoteOutHeader - Hide aTotableD_DeliveryNoteOut", AppearanceItemType.Action, "IsEditable = False", TargetItems:="aTotableD_DeliveryNoteOut", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("DeliveryNoteOutHeader - Hide aFinalize_DeliveryNoteOut", AppearanceItemType.Action, "IsEditable = False", TargetItems:="aFinalize_DeliveryNoteOut", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("DeliveryNoteOutHeader - Disable aDown_DeliveryNoteOut", AppearanceItemType.Action, "IsEditable = False", TargetItems:="aDown_DeliveryNoteOut", Enabled:=False)> _
<Appearance("DeliveryNoteOutHeader - Disable aUp_DeliveryNoteOut", AppearanceItemType.Action, "IsEditable = False", TargetItems:="aUp_DeliveryNoteOut", Enabled:=False)> _
<Appearance("DeliveryNoteOutHeader - Disable aBackToEdit_DeliveryNoteOut", AppearanceItemType.Action, "IsEditable = True", TargetItems:="aBackToEdit_DeliveryNoteOut", Enabled:=False)> _
<Appearance("DeliveryNoteOutHeader -  Hide all row_ properties, when IsEditable = False", AppearanceItemType.ViewItem, "IsEditable = False", TargetItems:="row_StorageOutRowsInRows;row_QTT;row_NoteRows", visibility:=Editors.ViewItemVisibility.Hide)> _
Public Class DeliveryNoteOutHeader 'Kimenő szállítólevél fejléc
    Inherits BaseObject
    Private _DeliveryNoteOutType As DeliveryNoteOutType
    Private _DocumentNumber As String ' Sorszám
    Private _CustomersFrom As CustomersFrom ' Sajátcég
    Private _Customers As Customers ' Ügyfél
    Private _DateCreated As Date ' Létrehozás dátuma
    Private _DateExecution As Date ' Végrehajtás dátuma
    Private _ShipmentOption As ShipmentOption ' Szállítási opció
    Private _QualityOption As QualityOption ' Minőségi opció
    Private _CurrencyName As CurrencyName ' Deviza
    Private _Note As String ' Megjegyzés
    Private _TransportAddress As Address ' -- Szállítási cím
    Private _IsEditable As Boolean = True 'Szerkeszthető
    Private _IsStorno As Boolean = False 'Végleges
    Private _ObjectCreated As Date 'Objektum keletkezésének dátuma
    Private _UserCreated As User
    Private _ConnectInfo As String

    '--Nonpersistent propertyk
    Private _row_StorageOutRowsInRows As StorageOutRowsInRows
    Private _row_QTT As Double
    Private _row_NoteRows As String 'Sor megjegyzés

    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Protected Overrides Sub OnSaving()
        MyBase.OnSaving()
        If String.IsNullOrEmpty(DocumentNumber) Then _
        _DocumentNumber = DeliveryNoteOutType.NumberGenerator.GetNewNumber(DeliveryNoteOutType.NumberGenerator)
        If String.IsNullOrEmpty(ConnectInfo) Then ConnectInfo = DocumentNumber
        If Session.IsNewObject(Me) Then
            ObjectCreated = GetSQLTime(Session)
            UserCreated = Session.GetObjectByKey(Of User)(Session.GetKeyValue(SecuritySystem.CurrentUser))
        End If
    End Sub
    <RuleRequiredField("DeliveryNoteOutHeader.DeliveryNoteOutType", DefaultContexts.Save)> _
    Property DeliveryNoteOutType As DeliveryNoteOutType
        Get
            Return _DeliveryNoteOutType
        End Get
        Set(value As DeliveryNoteOutType)
            SetPropertyValue("DeliveryNoteOutType", _DeliveryNoteOutType, value)
        End Set
    End Property
    <NonCloneable()> _
    Property DocumentNumber() As String
        Get
            Return _DocumentNumber
        End Get
        Set(ByVal value As String)
            SetPropertyValue("DocumentNumber", _DocumentNumber, value)
        End Set
    End Property
    <RuleRequiredField("DeliveryNoteOutHeader.Customers", DefaultContexts.Save)> _
    Property Customers() As Customers
        Get
            Return _Customers
        End Get
        Set(ByVal value As Customers)
            SetPropertyValue("Customers", _Customers, value)
        End Set
    End Property
    <RuleRequiredField("DeliveryNoteOutHeader.CustomersFrom", DefaultContexts.Save)> _
    Property CustomersFrom() As CustomersFrom
        Get
            Return _CustomersFrom
        End Get
        Set(ByVal value As CustomersFrom)
            SetPropertyValue("CustomersFrom", _CustomersFrom, value)
        End Set
    End Property
    Property DateCreated() As Date
        Get
            Return _DateCreated
        End Get
        Set(ByVal value As Date)
            SetPropertyValue("DateCreated", _DateCreated, value)
        End Set
    End Property
    Property DateExecution() As Date
        Get
            Return _DateExecution
        End Get
        Set(ByVal value As Date)
            SetPropertyValue("DateExecution", _DateExecution, value)
        End Set
    End Property
    <RuleRequiredField("DeliveryNoteOutHeader.ShipmentOption", DefaultContexts.Save)> _
    Property ShipmentOption() As ShipmentOption
        Get
            Return _ShipmentOption
        End Get
        Set(ByVal value As ShipmentOption)
            SetPropertyValue("ShipmentOption", _ShipmentOption, value)
        End Set
    End Property
    Property QualityOption() As QualityOption
        Get
            Return _QualityOption
        End Get
        Set(ByVal value As QualityOption)
            SetPropertyValue("QualityOption", _QualityOption, value)
        End Set
    End Property
    Property CurrencyName() As CurrencyName
        Get
            Return _CurrencyName
        End Get
        Set(ByVal value As CurrencyName)
            SetPropertyValue("CurrencyName", _CurrencyName, value)
        End Set
    End Property
    <Size(-1)> _
    Property Note() As String
        Get
            Return _Note
        End Get
        Set(ByVal value As String)
            SetPropertyValue("Note", _Note, value)
        End Set
    End Property
    <RuleRequiredField("DeliveryNoteOutHeader.TransportAddress", DefaultContexts.Save)> _
    Property TransportAddress As Address
        Get
            Return _TransportAddress
        End Get
        Set(value As Address)
            SetPropertyValue("TransportAddress", _TransportAddress, 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
    Property IsStorno() As Boolean
        Get
            Return _IsStorno
        End Get
        Set(ByVal value As Boolean)
            SetPropertyValue("IsStorno", _IsStorno, 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
    Property ConnectInfo As String
        Get
            Return _ConnectInfo
        End Get
        Set(value As String)
            SetPropertyValue("ConnectInfo", _ConnectInfo, value)
        End Set
    End Property

    '------ReadOnly--------
    <Association("DeliveryNoteOutHeader-DeliveryNoteOutRows", GetType(DeliveryNoteOutRows)), VisibleInListView(False)> _
    ReadOnly Property DeliveryNoteOutRows() As XPCollection(Of DeliveryNoteOutRows)
        Get
            Return GetCollection(Of DeliveryNoteOutRows)("DeliveryNoteOutRows")
        End Get
    End Property

    '--Nonpersistent propertyk
    <NonPersistent()> _
    <DataSourceProperty("StorageOutRowsInRows")> _
    Property row_StorageOutRowsInRows As StorageOutRowsInRows
        Get
            Return _row_StorageOutRowsInRows
        End Get
        Set(value As StorageOutRowsInRows)
            SetPropertyValue("row_StorageOutRowsInRows", _row_StorageOutRowsInRows, value)
        End Set
    End Property
    <NonPersistent()> _
    Property row_QTT As Double
        Get
            Return _row_QTT
        End Get
        Set(value As Double)
            SetPropertyValue("row_QTT", _row_QTT, value)
        End Set
    End Property
    <NonPersistent()> _
    Property row_NoteRows As String
        Get
            Return _row_NoteRows
        End Get
        Set(value As String)
            SetPropertyValue("row_NoteRows", _row_NoteRows, value)
        End Set
    End Property

    <VisibleInListView(False)> _
   <Browsable(False)> _
    Private ReadOnly Property StorageOutRowsInRows As XPCollection(Of StorageOutRowsInRows)
        Get

            Dim _StorageOutRowsInRows_Collection As XPCollection(Of StorageOutRowsInRows)
            Dim _Criteria As String

            _Criteria = "(QTT_To_DeliveryOut + QTT_Will) < QTT"

            _StorageOutRowsInRows_Collection = New XPCollection(Of StorageOutRowsInRows)(Session, CriteriaOperator.Parse(_Criteria))
            Return _StorageOutRowsInRows_Collection
        End Get
    End Property
End Class




