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

'CreditNoteRows
<DefaultClassOptions()> _
<NavigationItem(False)> _
<CreatableItem(False)> _
<Appearance("InvoiceCreditNoteHeader - Disable UserCreated all time", AppearanceItemType.ViewItem, "1=1", TargetItems:="UserCreated", Enabled:=False)> _
<Appearance("InvoiceCreditNoteHeader - Disable ObjectCreated all time", AppearanceItemType.ViewItem, "1=1", TargetItems:="ObjectCreated", Enabled:=False)> _
<Appearance("InvoiceCreditNoteHeader - Disable CustomersFrom when not empty", AppearanceItemType.ViewItem, "IsNull(CustomersFrom)=False", TargetItems:="CustomersFrom", Enabled:=False)> _
<Appearance("InvoiceCreditNoteHeader - Disable Customers when not empty", AppearanceItemType.ViewItem, "IsNull(Customers)=False", TargetItems:="Customers", Enabled:=False)> _
<Appearance("InvoiceCreditNoteHeader - Hide Item2 when IsNewObject", AppearanceItemType.LayoutItem, "IsNull(ObjectCreated) Or IsNull(UserCreated)", TargetItems:="Item2", visibility:=Editors.ViewItemVisibility.Hide)> _
Public Class InvoiceCreditNoteHeader
    Inherits BaseObject

    Private _CustomersFrom As CustomersFrom
    Private _Customers As Customers
    Private _Storage As Storage
    Private _StorageMoveType As StorageMoveType
    Private _DateExecution As Date
    Private _ObjectCreated As Date
    Private _UserCreated As User
    Private _PaymentOption As PaymentOption
    Private _DatePayment As Date
    Private _Description As String

    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
        DateExecution = GetSQLTime(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

    <RuleRequiredField("InvoiceCreditNoteHeader - CustomersFrom", DefaultContexts.Save)> _
    Property CustomersFrom As CustomersFrom
        Get
            Return _CustomersFrom
        End Get
        Set(value As CustomersFrom)
            SetPropertyValue("CustomersFrom", _CustomersFrom, value)
        End Set
    End Property
    <RuleRequiredField("InvoiceCreditNoteHeader - Customers", DefaultContexts.Save)> _
    Property Customers As Customers
        Get
            Return _Customers
        End Get
        Set(value As Customers)
            SetPropertyValue("Customers", _Customers, value)
        End Set
    End Property
    <RuleRequiredField("InvoiceCreditNoteHeader - Storage", DefaultContexts.Save)> _
    Property Storage As Storage
        Get
            Return _Storage
        End Get
        Set(value As Storage)
            SetPropertyValue("Storage", _Storage, value)
        End Set
    End Property

    <RuleRequiredField("InvoiceCreditNoteHeader-StorageMoveType", DefaultContexts.Save)>
    <ImmediatePostData(True), DataSourceCriteria("Storage='@This.Storage' AND MoveType=8")>
    Property StorageMoveType As StorageMoveType
        Get
            Return _StorageMoveType
        End Get
        Set(value As StorageMoveType)
            SetPropertyValue("StorageMoveType", _StorageMoveType, value)
        End Set
    End Property
    Property DateExecution As Date
        Get
            Return _DateExecution
        End Get
        Set(value As Date)
            SetPropertyValue("DateExecution", _DateExecution, value)
        End Set
    End Property
    Property ObjectCreated As Date
        Get
            Return _ObjectCreated
        End Get
        Set(value As Date)
            SetPropertyValue("ObjectCreated", _ObjectCreated, value)
        End Set
    End Property
    Property UserCreated As User
        Get
            Return _UserCreated
        End Get
        Set(value As User)
            SetPropertyValue("UserCreated", _UserCreated, value)
        End Set
    End Property
    <RuleRequiredField("InvoiceCreditNoteHeader - PaymentOption", DefaultContexts.Save)> _
    Property PaymentOption As PaymentOption
        Get
            Return _PaymentOption
        End Get
        Set(value As PaymentOption)
            SetPropertyValue("PaymentOption", _PaymentOption, value)
        End Set
    End Property
    Property DatePayment As Date
        Get
            Return _DatePayment
        End Get
        Set(value As Date)
            SetPropertyValue("DatePayment", _DatePayment, value)
        End Set
    End Property
    <Size(-1)> _
    Property Description As String
        Get
            Return _Description
        End Get
        Set(value As String)
            SetPropertyValue("Description", _Description, value)
        End Set
    End Property

    '--==ReadOnly==--
    <VisibleInListView(False)> _
    <Association("InvoiceCreditNoteHeader-InvoiceCreditNoteRows", GetType(InvoiceCreditNoteRows))> _
    ReadOnly Property InvoiceCreditNoteRows As XPCollection(Of InvoiceCreditNoteRows)
        Get
            Return GetCollection(Of InvoiceCreditNoteRows)("InvoiceCreditNoteRows")
        End Get
    End Property
End Class
