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("Disable ObjectCreated TakeoverProtocolHeader", AppearanceItemType.ViewItem, "1=1", TargetItems:="ObjectCreated", Enabled:=False)> _
<Appearance("Disable UserCreated TakeoverProtocolHeader", AppearanceItemType.ViewItem, "1=1", TargetItems:="UserCreated", Enabled:=False)> _
<Appearance("Disable IsEditable TakeoverProtocolHeader", AppearanceItemType.ViewItem, "1=1", TargetItems:="IsEditable", Enabled:=False)> _
<Appearance("Disable IsStorno TakeoverProtocolHeader", AppearanceItemType.ViewItem, "1=1", TargetItems:="IsStorno", Enabled:=False)> _
<Appearance("Disable DocumentNumber TakeoverProtocolHeader", AppearanceItemType.ViewItem, "1=1", TargetItems:="DocumentNumber", Enabled:=False)> _
<Appearance("Disable all property, when IsEditable=False TakeoverProtocolHeader", AppearanceItemType.ViewItem, "*", TargetItems:="IsEditable=False", Enabled:=False)> _
<Appearance("Disable all property, when IsStorno=False TakeoverProtocolHeader", AppearanceItemType.ViewItem, "*", TargetItems:="IsStorno=False", Enabled:=False)> _
<Appearance("Disable CustomersFrom, when not empty TakeoverProtocolHeader", AppearanceItemType.ViewItem, "IsNull(CustomersFrom)=False", TargetItems:="CustomersFrom", Enabled:=False)> _
<Appearance("Disable Customers, when not empty TakeoverProtocolHeader", AppearanceItemType.ViewItem, "IsNull(Customers)=False", TargetItems:="Customers", Enabled:=False)> _
<Appearance("Disable TakeoverProtocolType, when not empty TakeoverProtocolHeader", AppearanceItemType.ViewItem, "IsNull(TakeoverProtocolType)=False", TargetItems:="TakeoverProtocolType", Enabled:=False)> _
<Appearance("Hide TakeoverProtocolRowsTab TakeoverProtocolHeader", AppearanceItemType.LayoutItem, "IsNull(DocumentNumber) Or IsNull(CustomersFrom) Or IsNull(Customers) Or IsNull(TakeoverProtocolType)", TargetItems:="TakeoverProtocolRowsTab", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("Hide TakeoverProtocolHeader aToTable_TPR when IsEditable = False", AppearanceItemType.Action, "IsEditable = False", TargetItems:="aToTable_TPR", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("Hide TakeoverProtocolHeader aToTableD_TPR when IsEditable = False", AppearanceItemType.Action, "IsEditable = False", TargetItems:="aToTableD_TPR", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("Hide TakeoverProtocolHeader aToTable_TPR when IsStorno = True", AppearanceItemType.Action, "IsStorno = True", TargetItems:="aToTable_TPR", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("Hide TakeoverProtocolHeader aToTableD_TPR when IsStorno = True", AppearanceItemType.Action, "IsStorno = True", TargetItems:="aToTableD_TPR", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("Hide TakeoverProtocolHeader all row properties", AppearanceItemType.LayoutItem, "IsEditable = False OR IsStorno = True", TargetItems:="row_Installation;row_UniqueObjects", visibility:=Editors.ViewItemVisibility.Hide)> _
Public Class TakeoverProtocolHeader
    Inherits BaseObject
    Private _CustomersFrom As CustomersFrom
    Private _DocumentNumber As String
    Private _TakeoverProtocolType As TakeoverProtocolType
    Private _DateExecution As Date
    Private _Customers As Customers
    Private _ObjectCreated As Date 'Objektum keletkezésének dátuma
    Private _UserCreated As User
    Private _IsEditable As Boolean = True
    Private _IsStorno As Boolean = False
    '--------------NonPersistent--------------
    Private _row_Installation As Installation
    Private _row_UniqueObjects As UniqueObjects

    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
        IsEditable = True
       
    End Sub
    Protected Overrides Sub OnSaving()
        MyBase.OnSaving()
        If String.IsNullOrEmpty(DocumentNumber) Then
            DocumentNumber = TakeoverProtocolType.NumberGenerator.GetNewNumber(TakeoverProtocolType.NumberGenerator)
        End If
        If Session.IsNewObject(Me) Then
            ObjectCreated = GetSQLTime(Session)
            UserCreated = Session.GetObjectByKey(Of User)(Session.GetKeyValue(SecuritySystem.CurrentUser))
        End If
    End Sub
    <RuleRequiredField("TakeoverProtocolHeader-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
    Property DocumentNumber() As String
        Get
            Return _DocumentNumber
        End Get
        Set(ByVal value As String)
            SetPropertyValue("DocumentNumber", _DocumentNumber, value)
        End Set
    End Property
    <RuleRequiredField("TakeoverProtocolHeader-TakeoverProtocolType", DefaultContexts.Save)> _
    <DataSourceCriteria("CustomersFrom='@This.CustomersFrom'")> _
    Property TakeoverProtocolType As TakeoverProtocolType
        Get
            Return _TakeoverProtocolType
        End Get
        Set(value As TakeoverProtocolType)
            SetPropertyValue("TakeoverProtocolType", _TakeoverProtocolType, value)
        End Set
    End Property
    <RuleRequiredField("TakeoverProtocolHeader-DateExecution", DefaultContexts.Save)> _
    Property DateExecution As Date
        Get
            Return _DateExecution
        End Get
        Set(ByVal value As Date)
            SetPropertyValue("DateExecution", _DateExecution, value)
        End Set
    End Property
    <RuleRequiredField("TakeoverProtocolHeader-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
    <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 IsEditable As Boolean
        Get
            Return _IsEditable
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsEditable", _IsEditable, value)
        End Set
    End Property
    Property IsStorno As Boolean
        Get
            Return _IsStorno
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsStorno", _IsStorno, value)
        End Set
    End Property

    '--------------NonPersistent--------------
    <NonPersistent()> _
    <VisibleInListView(False)> _
     <DataSourceProperty("RowInstallationCollection")> _
    Property row_Installation() As Installation
        Get
            Return _row_Installation
        End Get
        Set(ByVal value As Installation)
            SetPropertyValue("row_Installation", _row_Installation, value)
        End Set
    End Property
    <NonPersistent()> _
    <VisibleInListView(False)> _
    Property row_UniqueObjects() As UniqueObjects
        Get
            Return _row_UniqueObjects
        End Get
        Set(ByVal value As UniqueObjects)
            SetPropertyValue("row_UniqueObjects", _row_UniqueObjects, value)
        End Set
    End Property

    '----------ReadOnly--------------------
    <VisibleInListView(False)> _
    <Association("TakeOverProtocol", GetType(TakeoverProtocolRows))> _
    Public ReadOnly Property TakeOverProtocolRows() As XPCollection(Of TakeoverProtocolRows)
        Get
            Return GetCollection(Of TakeoverProtocolRows)("TakeOverProtocolRows")
        End Get
    End Property
    <VisibleInListView(False)> _
    <Browsable(False)> _
    Private ReadOnly Property RowInstallationCollection As XPCollection(Of Installation)
        Get
            Dim _RowInstallationCollection_Collection As XPCollection(Of Installation)
            _RowInstallationCollection_Collection = New XPCollection(Of Installation)(Session, CriteriaOperator.Parse("isnull(TakeoverProtocolRows)=True or (InstallationType.IsVirtual=True)"))
            Return _RowInstallationCollection_Collection
        End Get
    End Property
End Class
