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 eSalesPolicyDocumentState
    eDeleted = -1
    eReadyforSign = 0
    eSigned = 2
End Enum
<DefaultClassOptions()> _
<NavigationItem(False)> _
<CreatableItem(False)> _
<DefaultProperty("DocumentNumber")> _
<Appearance("APCSheetByProductsSalesPolicyH - Disable DocumentNumber all time", AppearanceItemType.ViewItem, "1=1", TargetItems:="DocumentNumber", Enabled:=False)> _
<Appearance("APCSheetByProductsSalesPolicyH - Disable ObjectCreated all time", AppearanceItemType.ViewItem, "1=1", TargetItems:="ObjectCreated", Enabled:=False)> _
<Appearance("APCSheetByProductsSalesPolicyH - Disable UserCreated all time", AppearanceItemType.ViewItem, "1=1", TargetItems:="UserCreated", Enabled:=False)> _
<Appearance("APCSheetByProductsSalesPolicyH - Disable APCSheetHeader", AppearanceItemType.ViewItem, "IsNull(DocumentNumber)=False", TargetItems:="APCSheetHeader", Enabled:=False)> _
Public Class APCSheetByProductsSalesPolicyH 'Értékesítési szándéknyilatkozat fejléc termeltetési szerződéshez
    Inherits BaseObject

    Private _CustomersFrom As CustomersFrom
    Private _APCSheetHeader As APCSheetHeader 'Termeltetési szerz.
    Private _DocumentNumber As String 'Sorszám
    Private _Customers As Customers 'Vevő
    Private _DateCreated As Date 'Dátum
    Private _SalesPolicyDocumentState As eSalesPolicyDocumentState
    Private _FileData As FileData 'Az aláírt szkennelt file
    Private _ObjectCreated As Date
    Private _UserCreated As User

    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
    End Sub
    Protected Overrides Sub OnSaving()
        MyBase.OnSaving()
        ' Dim _APCParameters As APCParameters = Session.FindObject(Of APCParameters)(CriteriaOperator.Parse("CustomersFrom=? AND NumberGenaratorSalesPolicy<>?", CustomersFrom, Nothing))
        Dim _APCParameters As APCParameters = Me._APCSheetHeader.APCParameters
        If _APCParameters IsNot Nothing Then
            If _APCParameters.NumberGenaratorSalesPolicy IsNot Nothing Then
                If String.IsNullOrEmpty(DocumentNumber) Then DocumentNumber = _APCParameters.NumberGenaratorSalesPolicy.GetNewNumber(_APCParameters.NumberGenaratorSalesPolicy)
            End If
        End If

        If Session.IsNewObject(Me) Then
            ObjectCreated = GetSQLTime(Session)
            UserCreated = Session.GetObjectByKey(Of User)(Session.GetKeyValue(SecuritySystem.CurrentUser))
        End If
    End Sub

    <RuleRequiredField("APCSheetByProductsSalesPolicyH - 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("APCSheetByProductsSalesPolicyH - APCSheetHeader", DefaultContexts.Save)> _
    Property APCSheetHeader As APCSheetHeader
        Get
            Return _APCSheetHeader
        End Get
        Set(value As APCSheetHeader)
            SetPropertyValue("APCSheetHeader", _APCSheetHeader, value)
        End Set
    End Property
    Property DocumentNumber As String
        Get
            Return _DocumentNumber
        End Get
        Set(value As String)
            SetPropertyValue("DocumentNumber", _DocumentNumber, value)
        End Set
    End Property
    Property Customers As Customers
        Get
            Return _Customers
        End Get
        Set(value As Customers)
            SetPropertyValue("Customers", _Customers, value)
        End Set
    End Property
    Property DateCreated As Date
        Get
            Return _DateCreated
        End Get
        Set(value As Date)
            SetPropertyValue("DateCreated", _DateCreated, value)
        End Set
    End Property
    Property SalesPolicyDocumentState As eSalesPolicyDocumentState
        Get
            Return _SalesPolicyDocumentState
        End Get
        Set(value As eSalesPolicyDocumentState)
            SetPropertyValue("SalesPolicyDocumentState", _SalesPolicyDocumentState, value)
        End Set
    End Property
    Property FileData As FileData
        Get
            Return _FileData
        End Get
        Set(value As FileData)
            SetPropertyValue("FileData", _FileData, 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

    <VisibleInListView(False)> _
    <Association("APCSheetByProductsSalesPolicyH - APCSheetByProductsSalesPolicyR", GetType(APCSheetByProductsSalesPolicyR))> _
    ReadOnly Property APCSheetByProductsSalesPolicyR As XPCollection(Of APCSheetByProductsSalesPolicyR)
        Get
            Return GetCollection(Of APCSheetByProductsSalesPolicyR)("APCSheetByProductsSalesPolicyR")
        End Get
    End Property
End Class
