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 StorageInfromDeliveryNoteInRowsRows
    Inherits BaseObject
    Private _StorageInfromDeliveryNoteInRowsHeader As StorageInfromDeliveryNoteInRowsHeader
    Private _DeliveryNoteInRows As DeliveryNoteInRows
    Private _QTT_Process As Double ' a betárolni kívánt mennyiség a sorról
    Private _QTT_Max As Double ' Maximum mennyit lehet még betárolni a sorról
    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
    End Sub
    <Association("StorageInfromDeliveryNoteInRowsHeader-StorageInfromDeliveryNoteInRowsRows", GetType(StorageInfromDeliveryNoteInRowsHeader))> _
    Property StorageInfromDeliveryNoteInRowsHeader As StorageInfromDeliveryNoteInRowsHeader
        Get
            Return _StorageInfromDeliveryNoteInRowsHeader
        End Get
        Set(value As StorageInfromDeliveryNoteInRowsHeader)
            SetPropertyValue("StorageInfromDeliveryNoteInRowsHeader", _StorageInfromDeliveryNoteInRowsHeader, value)
        End Set
    End Property
    Property DeliveryNoteInRows As DeliveryNoteInRows
        Get
            Return _DeliveryNoteInRows
        End Get
        Set(value As DeliveryNoteInRows)
            SetPropertyValue("DeliveryNoteInRows", _DeliveryNoteInRows, value)
        End Set
    End Property
    Property QTT_Process As Double
        Get
            Return _QTT_Process
        End Get
        Set(value As Double)
            SetPropertyValue("QTT_Process", _QTT_Process, value)
        End Set
    End Property
    ReadOnly Property QTT_StorageIn As Double
        Get
            Dim _StorageInRows As New XPQuery(Of StorageInRows)(Session)
            Dim _QTT_Sum As Double = 0
            Dim query = From _SIR In _StorageInRows
                    Where _SIR.DeliveryNoteInRows Is DeliveryNoteInRows
            Group _SIR By _SIR.DeliveryNoteInRows Into g = Group _
            Select New With {Key .QTT_Sum = g.Sum(Function(inv) inv.QTT)}

            For Each item In query
                _QTT_Sum = item.QTT_Sum
            Next

            Return _QTT_Sum
        End Get
    End Property
    <NonPersistent()> _
    Property QTT_Max As Double
        Get
            Return _QTT_Max
        End Get
        Set(value As Double)
            SetPropertyValue("QTT_Max", _QTT_Max, value)
        End Set
    End Property
End Class
