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

'--- Kimenő szállítólevelek
<DefaultClassOptions()> _
<NavigationItem(False), CreatableItem(False)> _
Public Class DeliveryNoteOutRows 'Szállítólevél sorok
    Inherits BaseObject
    Private _RowIndex As Long
    Private _DeliveryNoteOutHeader As DeliveryNoteOutHeader
    Private _StorageOutRowsInRows As StorageOutRowsInRows
    Private _QTT As Double
    Private _QTT_Invoiced As Double
    Private _QTT_Will As Double
    Private _Note As String
    Private _ADRNumber As Double
    Private _OrderInRows As OrderInRows 'Szétosztás miatt kell ez a segéd mező
    Private _DividedOriginal As Long '-- 0: nincs bontva 1: fő sor 2: bontott sor
    Private _DividedGUID As Guid '-- Az összekapcsoló GUID ami a bontáshoz kell

    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Protected Overrides Sub OnSaving()
        MyBase.OnSaving()
        '// ADR számolás !!!
        If StorageOutRowsInRows IsNot Nothing Then
            Dim _ADRFactor As Long = 0
            If StorageOutRowsInRows.StorageOutRows IsNot Nothing Then
                If StorageOutRowsInRows.StorageOutRows.Products IsNot Nothing Then
                    Select Case StorageOutRowsInRows.StorageOutRows.Products.ADRPackingUnit
                        Case eADRPackingUnit.eNotSet
                            _ADRFactor = 0
                        Case eADRPackingUnit.eUnit_I
                            _ADRFactor = 50
                        Case eADRPackingUnit.eUnit_II
                            _ADRFactor = 3
                        Case eADRPackingUnit.eUnit_III
                            _ADRFactor = 1
                    End Select
                    If StorageOutRowsInRows.StorageOutRows.Products.Units.ShortName = "to" Or StorageOutRowsInRows.StorageOutRows.Products.Units.ShortName = "tonna" Then
                        ADRNumber = _ADRFactor * QTT * 1000
                    Else
                        ADRNumber = _ADRFactor * QTT
                    End If

                    ' ADRNumber = _ADRFactor * QTT
                End If
            End If
        End If
    End Sub
    Property RowIndex As Long
        Get
            Return _RowIndex
        End Get
        Set(ByVal value As Long)
            SetPropertyValue("RowIndex", _RowIndex, value)
        End Set
    End Property
    <Association("DeliveryNoteOutHeader-DeliveryNoteOutRows", GetType(DeliveryNoteOutHeader))> _
    Property DeliveryNoteOutHeader() As DeliveryNoteOutHeader
        Get
            Return _DeliveryNoteOutHeader
        End Get
        Set(ByVal value As DeliveryNoteOutHeader)
            SetPropertyValue("DeliveryNoteOutHeader", _DeliveryNoteOutHeader, value)
        End Set
    End Property
    <ImmediatePostData(True), DataSourceCriteria("(QTT-QTT_To_DeliveryOut)>0")>
    Property StorageOutRowsInRows() As StorageOutRowsInRows
        Get
            Return _StorageOutRowsInRows
        End Get
        Set(ByVal value As StorageOutRowsInRows)
            SetPropertyValue("StorageOutRowsInRows", _StorageOutRowsInRows, value)
        End Set
    End Property
    Property QTT() As Double
        Get
            Return _QTT
        End Get
        Set(ByVal value As Double)
            SetPropertyValue("QTT", _QTT, value)
        End Set
    End Property
    Property QTT_Invoiced As Double
        Get
            Return _QTT_Invoiced
        End Get
        Set(value As Double)
            SetPropertyValue("QTT_Invoiced", _QTT_Invoiced, value)
        End Set
    End Property
    Property QTT_Will As Double
        Get
            Return _QTT_Will
        End Get
        Set(value As Double)
            SetPropertyValue("QTT_Will", _QTT_Will, value)
        End Set
    End Property
    ''' <summary>
    ''' Megjegyzés (Note)
    ''' </summary>
    ''' <returns></returns>
    <Size(-1)>
    Property Note() As String
        Get
            Return _Note
        End Get
        Set(ByVal value As String)
            SetPropertyValue("Note", _Note, value)
        End Set
    End Property
    ''' <summary>
    ''' ADR szám a szállításhoz (ADRNumber)
    ''' </summary>
    ''' <returns></returns>
    Property ADRNumber As Double
        Get
            Return _ADRNumber
        End Get
        Set(value As Double)
            SetPropertyValue("ADRNumber", _ADRNumber, value)
        End Set
    End Property
    ''' <summary>
    ''' Eredeti megosztási sor
    ''' </summary>
    ''' <returns></returns>
    <VisibleInDetailView(False), VisibleInLookupListView(False), VisibleInListView(False)>
    Property DividedOriginal As Long
        Get
            Return _DividedOriginal
        End Get
        Set(value As Long)
            SetPropertyValue("DividedOriginal", _DividedOriginal, value)
        End Set
    End Property

    ''' <summary>
    ''' Megosztási sor azonosító
    ''' </summary>
    ''' <returns></returns>
    <VisibleInDetailView(False), VisibleInLookupListView(False), VisibleInListView(False)>
    Property DividedGUID As Guid
        Get
            Return _DividedGUID
        End Get
        Set(value As Guid)
            SetPropertyValue("DividedGUID", _DividedGUID, value)
        End Set
    End Property
End Class


