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
Public Enum eOwnerState
    eOwner = 0
    eRenter = 1
    eCourtesyUse = 2
End Enum
<DefaultClassOptions(), CreatableItem(False), NavigationItem(False), DefaultProperty("LotNumber")> _
Public Class APCSheetByTerritorial
    Inherits BaseObject
    Private _APCSheetHeader As APCSheetHeader
    Private _RowIndex As Long
    Private _Involved As Boolean 'Termelésbe bevont terület ?
    Private _City As String 'település
    Private _LotNumber As String 'Helyrajzi szám
    Private _BlockNumber As String 'Termőterülethez tartozó blokkszám
    Private _Area As Double 'termőterület mérete ha
    Private _Products As Products
    Private _OwnerState As eOwnerState 'Bérlő, tulajdonos vagy szívességi földhasználó
    Private _DueDateRent As Date 'Bérlet lejárta dátuma

    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
        Involved = True
    End Sub

    <Association("APCSheetHeader-APCSheetByTerritorial", GetType(APCSheetHeader)), VisibleInListView(False)> _
    Property APCSheetHeader As APCSheetHeader
        Get
            Return _APCSheetHeader
        End Get
        Set(value As APCSheetHeader)
            SetPropertyValue("APCSheetHeader", _APCSheetHeader, value)
        End Set
    End Property
    Property RowIndex As Long
        Get
            Return _RowIndex
        End Get
        Set(value As Long)
            SetPropertyValue("RowIndex", _RowIndex, value)
        End Set
    End Property
    Property Involved As Boolean
        Get
            Return _Involved
        End Get
        Set(value As Boolean)
            SetPropertyValue("Involved", _Involved, value)
        End Set
    End Property
    <Size(255)> _
    Property City As String
        Get
            Return _City
        End Get
        Set(value As String)
            SetPropertyValue("City", _City, value)
        End Set
    End Property
    <Size(255)> _
    Property LotNumber As String
        Get
            Return _LotNumber
        End Get
        Set(value As String)
            SetPropertyValue("LotNumber", _LotNumber, value)
        End Set
    End Property
    <Size(255)> _
    Property BlockNumber As String
        Get
            Return _BlockNumber
        End Get
        Set(value As String)
            SetPropertyValue("BlockNumber", _BlockNumber, value)
        End Set
    End Property
    Property Area As Double
        Get
            Return _Area
        End Get
        Set(value As Double)
            SetPropertyValue("Area", _Area, value)
        End Set
    End Property
    <ImmediatePostData(True), DataSourceProperty("TerritorialProducts")>
    Property Products As Products
        Get
            Return _Products
        End Get
        Set(value As Products)
            SetPropertyValue("Products", _Products, value)
        End Set
    End Property
    Property OwnerState As eOwnerState
        Get
            Return _OwnerState
        End Get
        Set(value As eOwnerState)
            SetPropertyValue("OwnerState", _OwnerState, value)
        End Set
    End Property
    Property DueDateRent As Date
        Get
            Return _DueDateRent
        End Get
        Set(value As Date)
            SetPropertyValue("DueDateRent", _DueDateRent, value)
        End Set
    End Property
    <Browsable(False)> _
    ReadOnly Property TerritorialProducts As XPCollection(Of Products)
        Get
            Dim _ProductsCoollection As XPCollection(Of Products) = Nothing

            If APCSheetHeader IsNot Nothing Then
                If APCSheetHeader.APCSheetByProducts.Count > 0 Then
                    Dim _Filter As String = "Oid in("

                    For Each _APCSheetByProducts As APCSheetByProducts In APCSheetHeader.APCSheetByProducts
                        _Filter += "'" + _APCSheetByProducts.Products.Oid.ToString + "',"
                    Next
                    _Filter = _Filter.Remove(_Filter.Length - 1, 1)
                    _Filter += ")"
                    _ProductsCoollection = New XPCollection(Of Products)(Session, CriteriaOperator.Parse(_Filter))
                End If
            End If

            Return _ProductsCoollection
        End Get
    End Property
End Class
