Imports System.ComponentModel
Imports DevExpress.Xpo
Imports DevExpress.Persistent.Base
Imports DevExpress.Persistent.BaseImpl
Imports DevExpress.Persistent.Validation

<DefaultClassOptions()> _
<NavigationItem(False), CreatableItem(False)> _
<DeferredDeletion(False)> _
Public Class StoragePDACollectionRows
    Inherits BaseObject

    Private _StoragePDACollectionHeader As StoragePDACollectionHeader
    Private _RowIndex As Long 'Sor index, ami alapján látszik, mi lett beolvasva utoljára
    Private _Barcode As String 'Termék vonalkódja
    Private _Products As Products 'Termék
    Private _QTT As Double 'Mennyiség
    Private _QTT_Processed As Double 'Szándék
    Private _Description As String 'Leírás
    Private _StorageLocation As StorageLocation 'Raktári lokáció
    Private _DateModified As Date 'Módosítás dátuma
    Private _ConnectOid As Guid
    Private _PacketNumber As String 'Kötegszám
    Private _SerialNumber As String 'Sorozatszám

    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
        Me.QTT = 0
    End Sub
    Protected Overrides Sub OnSaving()
        MyBase.OnSaving()
        If Session.IsNewObject(Me) Then
            If Me.RowIndex = 0 Then
                Dim _MaxRowIndex As Long = Val(Session.ExecuteScalar(String.Format("select max(RowIndex) from StoragePDACollectionRows Where StoragePDACollectionHeader='{0}'", _StoragePDACollectionHeader.Oid)))
                Me.RowIndex = _MaxRowIndex + 1
            End If
        End If
    End Sub
    Protected Overrides Sub OnDeleting()
        MyBase.OnDeleting()
        Session.ExecuteNonQuery(String.Format("update StoragePDACollectionRows set RowIndex=RowIndex-1 where RowIndex>{0} and StoragePDACollectionHeader='{1}'", Me.RowIndex, _StoragePDACollectionHeader.Oid))
    End Sub
    <RuleRequiredField("StoragePDACollectionRows-StoragePDACollectionHeader", DefaultContexts.Save)> _
    <Association("StoragePDACollectionHeader-StoragePDACollectionRows", GetType(StoragePDACollectionHeader))> _
    Property StoragePDACollectionHeader As StoragePDACollectionHeader
        Get
            Return _StoragePDACollectionHeader
        End Get
        Set(value As StoragePDACollectionHeader)
            SetPropertyValue("StoragePDACollectionHeader", _StoragePDACollectionHeader, 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 Barcode As String
        Get
            Return _Barcode
        End Get
        Set(value As String)
            SetPropertyValue("Barcode", _Barcode, value)
        End Set
    End Property
    <RuleRequiredField("StoragePDACollectionRows-Products", DefaultContexts.Save)> _
    <NoForeignKey> _
    Property Products As Products
        Get
            Return _Products
        End Get
        Set(value As Products)
            SetPropertyValue("Products", _Products, value)
        End Set
    End Property
    Property QTT As Double
        Get
            Return _QTT
        End Get
        Set(value As Double)
            SetPropertyValue("QTT", _QTT, value)
        End Set
    End Property
    Property QTT_Processed As Double
        Get
            Return _QTT_Processed
        End Get
        Set(value As Double)
            SetPropertyValue("QTT_Processed", _QTT_Processed, value)
        End Set
    End Property
    <Size(-1)> _
    Property Description As String
        Get
            Return _Description
        End Get
        Set(value As String)
            SetPropertyValue("Description", _Description, value)
        End Set
    End Property
    Property StorageLocation As StorageLocation
        Get
            Return _StorageLocation
        End Get
        Set(value As StorageLocation)
            SetPropertyValue("StorageLocation", _StorageLocation, value)
        End Set
    End Property
    Property DateModified As Date
        Get
            Return _DateModified
        End Get
        Set(value As Date)
            SetPropertyValue("DateModified", _DateModified, value)
        End Set
    End Property
    <Browsable(False)> _
    Property ConnectOid As Guid
        Get
            Return _ConnectOid
        End Get
        Set(value As Guid)
            SetPropertyValue("ConnectOid", _ConnectOid, value)
        End Set
    End Property
    Property PacketNumber As String
        Get
            Return _PacketNumber
        End Get
        Set(value As String)
            SetPropertyValue("PacketNumber", _PacketNumber, value)
        End Set
    End Property
    Property SerialNumber As String
        Get
            Return _SerialNumber
        End Get
        Set(value As String)
            SetPropertyValue("SerialNumber", _SerialNumber, value)
        End Set
    End Property

End Class
