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 System.Linq

<DefaultClassOptions()> _
<NavigationItem(False), CreatableItem(False)> _
Public Class ContractProductRows
    Inherits ContractRows
    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
    End Sub

    Private _Products As Products
    Private _QTT_Out As Double
    Private _ContractProductHeader As ContractProductHeader
    Private _RowIndex As Long 'Sor index (mozgathatónak kell lennie !)
    Private _APCSheetByProducts As APCSheetByProducts 'Termeltetési szerződési sor
    Property Products As Products
        Get
            Return _Products
        End Get
        Set(value As Products)
            SetPropertyValue("Products", _Products, value)
        End Set
    End Property
    Property QTT_Out As Double
        Get
            Return _QTT_Out
        End Get
        Set(value As Double)
            SetPropertyValue("QTT_Out", _QTT_Out, value)
        End Set
    End Property
    <Association("ContractProductHeader-ContractProductRows", GetType(ContractProductHeader))> _
    Property ContractProductHeader() As ContractProductHeader
        Get
            Return _ContractProductHeader
        End Get
        Set(ByVal value As ContractProductHeader)
            SetPropertyValue("ContractProductHeader", _ContractProductHeader, value)
        End Set
    End Property
    Property RowIndex() As Long
        Get
            Return _RowIndex
        End Get
        Set(ByVal value As Long)
            SetPropertyValue("RowIndex", _RowIndex, value)
        End Set
    End Property
    Property APCSheetByProducts As APCSheetByProducts
        Get
            Return _APCSheetByProducts
        End Get
        Set(value As APCSheetByProducts)
            SetPropertyValue("APCSheetByProducts", _APCSheetByProducts, value)
        End Set
    End Property


    Public Sub AddRows(ByVal _p_ContractProductHeader As ContractProductHeader)
        ' Sor hozzáadása
        Me.ContractProductHeader = _p_ContractProductHeader
        If _p_ContractProductHeader.row_Products IsNot Nothing Then
            Me.Products = _p_ContractProductHeader.row_Products
        Else
            Me.Products = _p_ContractProductHeader.row_ContractProductRows.Products
        End If
        Me.QTT = _p_ContractProductHeader.row_QTT
        Me.Units = _p_ContractProductHeader.row_Units
        Me.VAT = _p_ContractProductHeader.row_VAT
        Me.RowGroup1 = _p_ContractProductHeader.row_RowGroup1
        Me.RowGroup2 = _p_ContractProductHeader.row_RowGroup2
        Me.NettoPriceDEV = _p_ContractProductHeader.row_NettoPriceDEV
        Me.NettoPriceHUF = _p_ContractProductHeader.row_NettoPriceHUF
        Me.DateExecution = _p_ContractProductHeader.DateExecution
        Me.ContractRowsType = eContractRowsType.eFix
        Me.Controlling = _ContractProductHeader.ContractTemplate.Controlling

        Dim _PaymentOption As PaymentOption = Session.FindObject(Of PaymentOption)(CriteriaOperator.Parse("DefaultForBusinnes=True"))
        Me.Contracts = TryCast(_p_ContractProductHeader, Contracts)
        If _p_ContractProductHeader.row_PaymentOption IsNot Nothing Then
            Me.PaymentOption = _p_ContractProductHeader.row_PaymentOption
        Else
            If _PaymentOption IsNot Nothing Then
                Me.PaymentOption = _PaymentOption
            End If
        End If
        'Me.Controlling = _p_ContractProductHeader.row_Controlling
        If _p_ContractProductHeader.row_Products IsNot Nothing Then
            Me.ShortName = _p_ContractProductHeader.row_Products.ShortName
        Else
            Me.ShortName = _p_ContractProductHeader.row_ContractProductRows.ShortName
        End If
        ' Indexelés
        If _p_ContractProductHeader.ContractProductRows.Count = 0 Then
            Me.RowIndex = 0
        Else
            Me.RowIndex = _p_ContractProductHeader.ContractProductRows.Count - 1
        End If
        Me.APCSheetByProducts = _p_ContractProductHeader.row_APCSheetByProducts
        Me.Contracts.ContractRows.Add(TryCast(Me, ContractRows))
    End Sub
    Public Sub RemoveRows()
        Me.Delete()
    End Sub
End Class
