Imports System
Imports System.ComponentModel
Imports System.Collections.Generic
Imports System.Diagnostics
Imports System.Text

Imports DevExpress.ExpressApp
Imports DevExpress.ExpressApp.Actions
Imports DevExpress.Persistent.Base
Imports DevExpress.Persistent.Validation
Imports DevExpress.ExpressApp.Editors
Imports DevExpress.Xpo
Imports DevExpress.ExpressApp.SystemModule
Imports DevExpress.Data.Filtering
Imports DevExpress.Persistent.BaseImpl
Imports DevExpress.ExpressApp.Utils


Public Class DeliveryNoteOutVC
    Inherits DevExpress.ExpressApp.ViewController

    Public Sub New()
        MyBase.New()
        InitializeComponent()
        RegisterActions(components)
    End Sub
    Protected Overrides Sub OnActivated()
        MyBase.OnActivated()
        Frame.GetController(Of DeliveryNoteOutVC).aUp_DeliveryNoteOut.Active.SetItemValue("", False) ' kiválasztott sor fel
        Frame.GetController(Of DeliveryNoteOutVC).aDown_DeliveryNoteOut.Active.SetItemValue("", False) ' kiválasztott sor le

        Frame.GetController(Of DeliveryNoteOutVC).aTotable_DeliveryNoteOut.Active.SetItemValue("", False)
        Frame.GetController(Of DeliveryNoteOutVC).aTotableD_DeliveryNoteOut.Active.SetItemValue("", False)
        Frame.GetController(Of DeliveryNoteOutVC).aFinalize_DeliveryNoteOut.Active.SetItemValue("", False)
        Frame.GetController(Of DeliveryNoteOutVC).aStorno_DeliveryNoteOut.Active.SetItemValue("", False)
        Frame.GetController(Of DeliveryNoteOutVC).aBackToEdit_DeliveryNoteOut.Active.SetItemValue("", False)
        Frame.GetController(Of DeliveryNoteOutVC).aDeliveryNoteOutPrint.Active.SetItemValue("", False)
        Frame.GetController(Of DeliveryNoteOutVC).aDown_DeliveryNoteOut.Active.SetItemValue("", False)
        Frame.GetController(Of DeliveryNoteOutVC).aUp_DeliveryNoteOut.Active.SetItemValue("", False)
        Frame.GetController(Of DeliveryNoteOutVC).aFinalizeAndNew_DeliveryNoteOut.Active.SetItemValue("", False)
        Frame.GetController(Of DeliveryNoteOutVC).aCreate_DeliveryNoteOutFromStorageORIR.Active.SetItemValue("", False)
        Frame.GetController(Of DeliveryNoteOutVC).aCreate_InvoiceFromStorageORIR.Active.SetItemValue("", False)

        If View.Id = "DeliveryNoteOutHeader_ListView_Editable" Then
            Frame.GetController(Of DeliveryNoteOutVC).aFinalize_DeliveryNoteOut.Active.SetItemValue("", False)
            Frame.GetController(Of DeliveryNoteOutVC).aFinalizeAndNew_DeliveryNoteOut.Active.SetItemValue("", False)
        End If

        If View.Id = "DeliveryNoteOutRows_ListView_Invoice" Then
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.NewObjectViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.DeleteObjectsViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of DevExpress.ExpressApp.CloneObject.CloneObjectViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of DeliveryNoteOutVC).aCreate_InvoiceFromStorageORIR.Active.SetItemValue("", True)

            AddHandler View.SelectionChanged, AddressOf DeliveryNoteOutRows_ListView_Invoice_ViewSelectionChanged
        End If

        If View.Id = "StorageOutRowsInRows_ListView_DeliveryNote_OrderIn" Then
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.ListViewProcessCurrentObjectController)().Active.SetItemValue("", False)
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.NewObjectViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.DeleteObjectsViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of DevExpress.ExpressApp.CloneObject.CloneObjectViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of DeliveryNoteOutVC).aCreate_DeliveryNoteOutFromStorageORIR.Active.SetItemValue("", True)

            AddHandler View.SelectionChanged, AddressOf StorageOutRowsInRows_ListView_DeliveryNote_Transfer_ViewSelectionChanged
        End If

        If View.Id = "StorageOutRowsInRows_ListView_DeliveryNote_Transfer" Then
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.ListViewProcessCurrentObjectController)().Active.SetItemValue("", False)
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.NewObjectViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.DeleteObjectsViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of DevExpress.ExpressApp.CloneObject.CloneObjectViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of DeliveryNoteOutVC).aCreate_DeliveryNoteOutFromStorageORIR.Active.SetItemValue("", True)

            AddHandler View.SelectionChanged, AddressOf StorageOutRowsInRows_ListView_DeliveryNote_Transfer_ViewSelectionChanged
        End If

        If View.Id = "StorageOutRowsInRows_LookupListView" Then
            Frame.GetController(Of DevExpress.ExpressApp.CloneObject.CloneObjectViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.NewObjectViewController)().Active.SetItemValue("", False)
        End If

        If View.Id = "DeliveryNoteOutHeader_ListView_NonEditable" Then
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.DeleteObjectsViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of DevExpress.ExpressApp.CloneObject.CloneObjectViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.NewObjectViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of DeliveryNoteOutVC).aStorno_DeliveryNoteOut.Active.SetItemValue("", True)
            Frame.GetController(Of DeliveryNoteOutVC).aBackToEdit_DeliveryNoteOut.Active.SetItemValue("", True)
            Frame.GetController(Of DeliveryNoteOutVC)().aDeliveryNoteOutPrint.Active.SetItemValue("", True)
        End If
        '------------------- LISTVIEWS -------------------------------------------------------------------------------------------------------------------------------
        If View.Id = "DeliveryNoteOutHeader_DeliveryNoteOutRows_ListView" Then
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.DeleteObjectsViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.LinkUnlinkController)().Active.SetItemValue("", False)
            Frame.GetController(Of DevExpress.ExpressApp.CloneObject.CloneObjectViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.NewObjectViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.ListViewProcessCurrentObjectController)().Active.SetItemValue("", False)
            Frame.GetController(Of DeliveryNoteOutVC).aUp_DeliveryNoteOut.Active.SetItemValue("", True)
            Frame.GetController(Of DeliveryNoteOutVC).aDown_DeliveryNoteOut.Active.SetItemValue("", True)
        End If

        '------------------- DETAILVIEWS -------------------------------------------------------------------------------------------------------------------------------
        If View.Id = "DeliveryNoteView_DetailView" Then

            AddHandler Frame.GetController(Of DevExpress.ExpressApp.SystemModule.DialogController)().AcceptAction.Executing, AddressOf AcceptAction_Executing
        End If
        If View.Id = "DeliveryNoteOutHeader_DetailView" Then
            Dim _DeliveryNoteOutHeader As DeliveryNoteOutHeader = TryCast(View.SelectedObjects(0), DeliveryNoteOutHeader)
            If _DeliveryNoteOutHeader IsNot Nothing Then
                If _DeliveryNoteOutHeader.IsEditable = False Then
                    Frame.GetController(Of DevExpress.ExpressApp.CloneObject.CloneObjectViewController)().Active.SetItemValue("", False)
                    Frame.GetController(Of DevExpress.ExpressApp.SystemModule.NewObjectViewController)().Active.SetItemValue("", False)
                    Frame.GetController(Of DevExpress.ExpressApp.SystemModule.DeleteObjectsViewController)().Active.SetItemValue("", False)
                    Frame.GetController(Of DevExpress.ExpressApp.SystemModule.ModificationsController)().SaveAction.Active.SetItemValue("", False)
                    Frame.GetController(Of DevExpress.ExpressApp.SystemModule.ModificationsController)().SaveAndCloseAction.Active.SetItemValue("", False)
                    Frame.GetController(Of DevExpress.ExpressApp.SystemModule.ModificationsController)().SaveAndNewAction.Active.SetItemValue("", False)
                Else
                    Frame.GetController(Of DeliveryNoteOutVC).aTotable_DeliveryNoteOut.Active.SetItemValue("", True)
                    Frame.GetController(Of DeliveryNoteOutVC).aTotableD_DeliveryNoteOut.Active.SetItemValue("", True)
                    Frame.GetController(Of DeliveryNoteOutVC).aFinalize_DeliveryNoteOut.Active.SetItemValue("", True)
                    Frame.GetController(Of DeliveryNoteOutVC).aFinalizeAndNew_DeliveryNoteOut.Active.SetItemValue("", True)
                End If
            End If
        End If
    End Sub
    Protected Overrides Sub OnDeactivated()
        MyBase.OnDeactivated()
        If View.Id = "DeliveryNoteOutHeader_ListView_Editable" Then
            Frame.GetController(Of DeliveryNoteOutVC).aFinalize_DeliveryNoteOut.Active.SetItemValue("", False)
            Frame.GetController(Of DeliveryNoteOutVC).aFinalizeAndNew_DeliveryNoteOut.Active.SetItemValue("", False)
        End If

        If View.Id = "StorageOutRowsInRows_ListView_DeliveryNote_OrderIn" Then
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.ListViewProcessCurrentObjectController)().Active.SetItemValue("", True)
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.NewObjectViewController)().Active.SetItemValue("", True)
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.DeleteObjectsViewController)().Active.SetItemValue("", True)
            Frame.GetController(Of DevExpress.ExpressApp.CloneObject.CloneObjectViewController)().Active.SetItemValue("", True)
            Frame.GetController(Of DeliveryNoteOutVC).aCreate_DeliveryNoteOutFromStorageORIR.Active.SetItemValue("", False)

            RemoveHandler View.SelectionChanged, AddressOf StorageOutRowsInRows_ListView_DeliveryNote_Transfer_ViewSelectionChanged
        End If

        If View.Id = "StorageOutRowsInRows_ListView_DeliveryNote_Transfer" Then
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.ListViewProcessCurrentObjectController)().Active.SetItemValue("", True)
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.NewObjectViewController)().Active.SetItemValue("", True)
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.DeleteObjectsViewController)().Active.SetItemValue("", True)
            Frame.GetController(Of DevExpress.ExpressApp.CloneObject.CloneObjectViewController)().Active.SetItemValue("", True)
            Frame.GetController(Of DeliveryNoteOutVC).aCreate_DeliveryNoteOutFromStorageORIR.Active.SetItemValue("", True)

            RemoveHandler View.SelectionChanged, AddressOf StorageOutRowsInRows_ListView_DeliveryNote_Transfer_ViewSelectionChanged
        End If

        If View.Id = "StorageOutRowsInRows_LookupListView" Then
            Frame.GetController(Of DevExpress.ExpressApp.CloneObject.CloneObjectViewController)().Active.SetItemValue("", True)
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.NewObjectViewController)().Active.SetItemValue("", True)
        End If

        If View.Id = "DeliveryNoteOutHeader_ListView_NonEditable" Then
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.DeleteObjectsViewController)().Active.SetItemValue("", True)
            Frame.GetController(Of DevExpress.ExpressApp.CloneObject.CloneObjectViewController)().Active.SetItemValue("", True)
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.NewObjectViewController)().Active.SetItemValue("", True)
            Frame.GetController(Of DeliveryNoteOutVC).aStorno_DeliveryNoteOut.Active.SetItemValue("", False)
            Frame.GetController(Of DeliveryNoteOutVC).aBackToEdit_DeliveryNoteOut.Active.SetItemValue("", False)
            Frame.GetController(Of DeliveryNoteOutVC)().aDeliveryNoteOutPrint.Active.SetItemValue("", False)
        End If
        '------------------- LISTVIEWS -------------------------------------------------------------------------------------------------------------------------------
        If View.Id = "DeliveryNoteOutHeader_DeliveryNoteOutRows_ListView" Then
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.DeleteObjectsViewController)().Active.SetItemValue("", True)
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.LinkUnlinkController)().Active.SetItemValue("", True)
            Frame.GetController(Of DevExpress.ExpressApp.CloneObject.CloneObjectViewController)().Active.SetItemValue("", True)
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.NewObjectViewController)().Active.SetItemValue("", True)
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.ListViewProcessCurrentObjectController)().Active.SetItemValue("", True)
            Frame.GetController(Of DeliveryNoteOutVC).aUp_DeliveryNoteOut.Active.SetItemValue("", False)
            Frame.GetController(Of DeliveryNoteOutVC).aDown_DeliveryNoteOut.Active.SetItemValue("", False)
        End If

        '------------------- DETAILVIEWS -------------------------------------------------------------------------------------------------------------------------------
        If View.Id = "DeliveryNoteView_DetailView" Then

            RemoveHandler Frame.GetController(Of DevExpress.ExpressApp.SystemModule.DialogController)().AcceptAction.Executing, AddressOf AcceptAction_Executing
        End If
        If View.Id = "DeliveryNoteOutHeader_DetailView" Then
            Dim _DeliveryNoteOutHeader As DeliveryNoteOutHeader = TryCast(View.SelectedObjects(0), DeliveryNoteOutHeader)
            If _DeliveryNoteOutHeader IsNot Nothing Then
                If _DeliveryNoteOutHeader.IsEditable = False Then
                    Frame.GetController(Of DevExpress.ExpressApp.CloneObject.CloneObjectViewController)().Active.SetItemValue("", True)
                    Frame.GetController(Of DevExpress.ExpressApp.SystemModule.NewObjectViewController)().Active.SetItemValue("", True)
                    Frame.GetController(Of DevExpress.ExpressApp.SystemModule.DeleteObjectsViewController)().Active.SetItemValue("", True)
                    Frame.GetController(Of DevExpress.ExpressApp.SystemModule.ModificationsController)().SaveAction.Active.SetItemValue("", True)
                    Frame.GetController(Of DevExpress.ExpressApp.SystemModule.ModificationsController)().SaveAndCloseAction.Active.SetItemValue("", True)
                    Frame.GetController(Of DevExpress.ExpressApp.SystemModule.ModificationsController)().SaveAndNewAction.Active.SetItemValue("", True)
                Else
                    Frame.GetController(Of DeliveryNoteOutVC).aTotable_DeliveryNoteOut.Active.SetItemValue("", False)
                    Frame.GetController(Of DeliveryNoteOutVC).aTotableD_DeliveryNoteOut.Active.SetItemValue("", False)
                    Frame.GetController(Of DeliveryNoteOutVC).aFinalize_DeliveryNoteOut.Active.SetItemValue("", False)
                    Frame.GetController(Of DeliveryNoteOutVC).aFinalizeAndNew_DeliveryNoteOut.Active.SetItemValue("", False)
                End If
            End If
        End If
    End Sub
    Private Sub AcceptAction_Executing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
        Validator.RuleSet.ValidateAll(View.ObjectSpace, View.SelectedObjects, DefaultContexts.Save)
    End Sub
    Private Sub aUp_DeliveryNoteOut_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aUp_DeliveryNoteOut.Execute
        If View.SelectedObjects(0) IsNot Nothing Then
            Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
            Dim _DeliveryNoteOutHeader As DeliveryNoteOutHeader = _ocur.GetObjectByKey(Of DeliveryNoteOutHeader)(TryCast(View.SelectedObjects(0), DeliveryNoteOutRows).DeliveryNoteOutHeader.Oid)
            _DeliveryNoteOutHeader.DeliveryNoteOutRows.Sorting.Add(New SortProperty("RowIndex", DB.SortingDirection.Ascending))
            Dim _DeliveryNoteOutRowsSelected As DeliveryNoteOutRows = TryCast(View.SelectedObjects(0), DeliveryNoteOutRows)
            Dim _DeliveryNoteOutRows_Previous As DeliveryNoteOutRows = Nothing
            Dim _DeliveryNoteOutRows As DeliveryNoteOutRows = Nothing
            Dim _Valid_RowIndex = False

            For Each _DeliveryNoteOutRows In _DeliveryNoteOutHeader.DeliveryNoteOutRows
                If _DeliveryNoteOutRows.Oid = _DeliveryNoteOutRowsSelected.Oid Then
                    If _DeliveryNoteOutRows.Oid <> _DeliveryNoteOutHeader.DeliveryNoteOutRows(0).Oid Then
                        _DeliveryNoteOutRows.RowIndex -= 1
                        _Valid_RowIndex = True
                        Exit For
                    End If
                End If
                _DeliveryNoteOutRows_Previous = _DeliveryNoteOutRows
            Next

            If _DeliveryNoteOutRows_Previous IsNot Nothing And _Valid_RowIndex = True Then
                _DeliveryNoteOutRows_Previous.RowIndex += 1
            End If

            _ocur.CommitChanges()

            Dim nestedFrame As NestedFrame = TryCast(Frame, NestedFrame)
            If nestedFrame IsNot Nothing Then
                Dim parentView As View = nestedFrame.View
                parentView.ObjectSpace.Refresh()
            End If

        Else
            '----------------------------TESZT MIATT!!!! ----------------------------------------------------------------
            Throw New Exception("***Nincs sor kiválasztva, vagy nem a sor kijelölése az aktív!")
        End If

    End Sub
    Private Sub aDown_DeliveryNoteOut_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aDown_DeliveryNoteOut.Execute
        If View.SelectedObjects(0) IsNot Nothing Then
            Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
            Dim _DeliveryNoteOutHeader As DeliveryNoteOutHeader = _ocur.GetObjectByKey(Of DeliveryNoteOutHeader)(TryCast(View.SelectedObjects(0), DeliveryNoteOutRows).DeliveryNoteOutHeader.Oid)
            _DeliveryNoteOutHeader.DeliveryNoteOutRows.Sorting.Add(New SortProperty("RowIndex", DB.SortingDirection.Ascending))
            Dim _DeliveryNoteOutRowsSelected As DeliveryNoteOutRows = TryCast(View.SelectedObjects(0), DeliveryNoteOutRows)
            Dim _DeliveryNoteOutRows_Next As DeliveryNoteOutRows = Nothing
            Dim _DeliveryNoteOutRows As DeliveryNoteOutRows = Nothing
            Dim _Valid_RowIndex = False

            For Each _DeliveryNoteOutRows In _DeliveryNoteOutHeader.DeliveryNoteOutRows
                If _DeliveryNoteOutRows.Oid = _DeliveryNoteOutRowsSelected.Oid Then
                    If _DeliveryNoteOutRows.Oid <> _DeliveryNoteOutHeader.DeliveryNoteOutRows(_DeliveryNoteOutHeader.DeliveryNoteOutRows.Count - 1).Oid Then
                        _DeliveryNoteOutRows_Next = _ocur.FindObject(Of DeliveryNoteOutRows)(CriteriaOperator.Parse("RowIndex=?", _DeliveryNoteOutRows.RowIndex + 1))
                        _DeliveryNoteOutRows.RowIndex += 1
                        _Valid_RowIndex = True
                        Exit For
                    End If
                End If
            Next

            If _DeliveryNoteOutRows_Next IsNot Nothing And _Valid_RowIndex = True Then
                _DeliveryNoteOutRows_Next.RowIndex -= 1
            End If

            _ocur.CommitChanges()

            Dim nestedFrame As NestedFrame = TryCast(Frame, NestedFrame)
            If nestedFrame IsNot Nothing Then
                Dim parentView As View = nestedFrame.View
                parentView.ObjectSpace.Refresh()
            End If

        Else
            '----------------------------TESZT MIATT!!!! ----------------------------------------------------------------
            Throw New Exception("*Nincs sor kiválasztva, vagy nem a sor kijelölése az aktív!")
        End If

    End Sub
    Private Sub aDeliveryNoteOutPrint_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aDeliveryNoteOutPrint.Execute
        Dim _DeliveryNoteOutHeader As DeliveryNoteOutHeader = TryCast(View.SelectedObjects(0), DeliveryNoteOutHeader)
        If _DeliveryNoteOutHeader IsNot Nothing Then
            Dim _ReportData As ReportData = _DeliveryNoteOutHeader.DeliveryNoteOutType.ReportData
            If _ReportData IsNot Nothing Then
                Frame.GetController(Of Reports.ReportServiceController).ShowPreview(_ReportData, CriteriaOperator.Parse("DeliveryNoteOutHeader.DocumentNumber = ?", _DeliveryNoteOutHeader.DocumentNumber), True)
            Else
                '-----------------TESZT MAITT----------------------------
                Throw New Exception("*Nincs beállítva nyomtatvány!")
            End If
        End If
    End Sub
    Private Sub aTotable_DeliveryNoteOut_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aTotable_DeliveryNoteOut.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _DeliveryNoteOutHeader As DeliveryNoteOutHeader = _ocur.GetObjectByKey(Of DeliveryNoteOutHeader)(TryCast(View.SelectedObjects(0), DeliveryNoteOutHeader).Oid)
        Dim _DeliveryNoteOutRows As DeliveryNoteOutRows = Nothing
        If _DeliveryNoteOutHeader IsNot Nothing Then
            Dim _StorageOutRowsInRows As StorageOutRowsInRows = _ocur.GetObjectByKey(Of StorageOutRowsInRows)(TryCast(View.SelectedObjects(0), DeliveryNoteOutHeader).row_StorageOutRowsInRows.Oid)
            Dim _row_QTT As Double = TryCast(View.SelectedObjects(0), DeliveryNoteOutHeader).row_QTT
            Dim _row_NoteRows As String = TryCast(View.SelectedObjects(0), DeliveryNoteOutHeader).row_NoteRows

            If _row_QTT <= _StorageOutRowsInRows.QTT - _StorageOutRowsInRows.StorageOutRows.QTT_To_DeliveryOut Then
                For Each _DeliveryNoteOutRows_Exist As DeliveryNoteOutRows In _DeliveryNoteOutHeader.DeliveryNoteOutRows
                    If _DeliveryNoteOutRows_Exist.StorageOutRowsInRows.Oid = _StorageOutRowsInRows.Oid Then
                        _DeliveryNoteOutRows = _DeliveryNoteOutRows_Exist
                        Exit For
                    End If
                Next
                If _DeliveryNoteOutRows Is Nothing Then
                    _DeliveryNoteOutRows = New DeliveryNoteOutRows(_ocur.Session)
                    _DeliveryNoteOutRows.DeliveryNoteOutHeader = _DeliveryNoteOutHeader
                    _DeliveryNoteOutRows.StorageOutRowsInRows = _StorageOutRowsInRows
                    _DeliveryNoteOutRows.RowIndex = _DeliveryNoteOutHeader.DeliveryNoteOutRows.Count
                End If

                _DeliveryNoteOutRows.QTT += _row_QTT
                _DeliveryNoteOutRows.Note = _row_NoteRows
                _DeliveryNoteOutRows.StorageOutRowsInRows.QTT_To_DeliveryOut += _row_QTT



                _StorageOutRowsInRows.StorageOutRows.QTT_To_DeliveryOut += _row_QTT

                _ocur.CommitChanges()
            Else
                '-----------------TESZT MAITT----------------------------
                Throw New Exception("*A kiszállítani kívánt mennyiség meghaladja kitárolt mennyiséget!" & vbNewLine & vbNewLine & _
                                    "Kérem ellenőrizze a beírt mennyiséget!")
            End If
            _DeliveryNoteOutHeader.row_NoteRows = ""
            _DeliveryNoteOutHeader.row_QTT = 0
            _DeliveryNoteOutHeader.row_StorageOutRowsInRows = Nothing
        End If

        If Frame.GetController(Of RefreshController).RefreshAction.Enabled = True Then
            Frame.GetController(Of RefreshController).RefreshAction.DoExecute()
        End If
    End Sub
    Private Sub aTotableD_DeliveryNoteOut_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aTotableD_DeliveryNoteOut.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _DeliveryNoteOutHeader As DeliveryNoteOutHeader = _ocur.GetObjectByKey(Of DeliveryNoteOutHeader)(TryCast(View.SelectedObjects(0), DeliveryNoteOutHeader).Oid)
        Dim _DeliveryNoteOutRows As DeliveryNoteOutRows = Nothing
        Dim _DeliveryNoteOutRows_Del_Collection As New ArrayList
        Dim _DeliveryNoteOutRows_ListEditor As ListPropertyEditor = TryCast(View, DetailView).FindItem("DeliveryNoteOutRows")
        If _DeliveryNoteOutRows_ListEditor IsNot Nothing Then
            For Each _DeliveryNoteOutRows_Ocur As DeliveryNoteOutRows In _DeliveryNoteOutRows_ListEditor.ListView.SelectedObjects
                _DeliveryNoteOutRows = _ocur.GetObjectByKey(Of DeliveryNoteOutRows)(_DeliveryNoteOutRows_Ocur.Oid)
                _DeliveryNoteOutRows.StorageOutRowsInRows.StorageOutRows.QTT_To_DeliveryOut -= _DeliveryNoteOutRows.QTT
                _DeliveryNoteOutRows.StorageOutRowsInRows.QTT_To_DeliveryOut -= _DeliveryNoteOutRows.QTT

                _DeliveryNoteOutRows_Del_Collection.Add(_DeliveryNoteOutRows)
            Next
            _ocur.Delete(_DeliveryNoteOutRows_Del_Collection)

            _ocur.CommitChanges()

            If Frame.GetController(Of RefreshController).RefreshAction.Enabled = True Then
                Frame.GetController(Of RefreshController).RefreshAction.DoExecute()
            End If
        End If
    End Sub
    Private Sub aFinalize_DeliveryNoteOut_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aFinalize_DeliveryNoteOut.Execute, aFinalizeAndNew_DeliveryNoteOut.Execute
        Dim _ocur As Xpo.XPObjectSpace = View.ObjectSpace
        Dim _DeliveryNoteOutHeader As DeliveryNoteOutHeader = TryCast(View.SelectedObjects(0), DeliveryNoteOutHeader)
        If _DeliveryNoteOutHeader.DeliveryNoteOutType.ReportData IsNot Nothing And _DeliveryNoteOutHeader.DeliveryNoteOutRows.Count > 0 Then
            _DeliveryNoteOutHeader.IsEditable = False

            _ocur.CommitChanges()

            Dim _ReportData As ReportData = _ocur.FindObject(Of ReportData)(CriteriaOperator.Parse("Oid=?", _DeliveryNoteOutHeader.DeliveryNoteOutType.ReportData.Oid), True)
            Frame.GetController(Of Reports.ReportServiceController).ShowPreview(_ReportData, CriteriaOperator.Parse("DeliveryNoteOutHeader.DocumentNumber =?", _DeliveryNoteOutHeader.DocumentNumber), True)

            If e.Action.Id = "aFinalizeAndNew_DeliveryNoteOut" Then
                Frame.GetController(Of NewObjectViewController)().NewObjectAction.DoExecute(Frame.GetController(Of NewObjectViewController)().NewObjectAction.Items(0))
            End If
        Else
            '-----------------TESZT MAITT----------------------------
            Throw New Exception("*Nincs beállítva nyomtatvány vagy nincs egy sora sem a kimenő szállítólevélnek!")
        End If
    End Sub
    Private Sub aStorno_DeliveryNoteOut_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aStorno_DeliveryNoteOut.Execute
        Try
            Dim _ocur As Xpo.XPObjectSpace = View.ObjectSpace
            Dim _DeliveryNoteOutHeader As DeliveryNoteOutHeader = TryCast(View.SelectedObjects(0), DeliveryNoteOutHeader)
            If _DeliveryNoteOutHeader Is Nothing Then Throw New Exception("*Nincs kiválasztva egyetlen sor sem!")
            If _DeliveryNoteOutHeader.IsStorno = True Then Throw New Exception("*A szállítólevél már stornózva lett!")

            For Each _DeliveryNoteOutRows As DeliveryNoteOutRows In _DeliveryNoteOutHeader.DeliveryNoteOutRows
                _DeliveryNoteOutRows.StorageOutRowsInRows.StorageOutRows.QTT_To_DeliveryOut -= _DeliveryNoteOutRows.QTT
            Next

            _DeliveryNoteOutHeader.IsEditable = False
            _DeliveryNoteOutHeader.IsStorno = True

            _ocur.CommitChanges()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, String.Format(CaptionHelper.GetLocalizedText("Exceptions\SISBusinessExceptions", "MsgBoxCheckItAgain")))
        End Try
    End Sub
    Private Sub aBackToEdit_DeliveryNoteOut_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aBackToEdit_DeliveryNoteOut.Execute
        Try
            Dim _ocur As Xpo.XPObjectSpace = View.ObjectSpace
            Dim _DeliveryNoteOutHeader As DeliveryNoteOutHeader = TryCast(View.SelectedObjects(0), DeliveryNoteOutHeader)
            If _DeliveryNoteOutHeader Is Nothing Then Throw New Exception("*Nincs kiválasztva egyetlen sor sem!")
            If _DeliveryNoteOutHeader.IsStorno = True Then Throw New Exception("*Stornózott szállítólevelet nem lehet újra szerkeszteni!")
            _DeliveryNoteOutHeader.IsEditable = True

            _ocur.CommitChanges()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, String.Format(CaptionHelper.GetLocalizedText("Exceptions\SISBusinessExceptions", "MsgBoxCheckItAgain")))
        End Try
    End Sub
    Private Sub aCreate_DeliveryNoteOutFromStorageORIR_Cancel(sender As Object, e As System.EventArgs) Handles aCreate_DeliveryNoteOutFromStorageORIR.Cancel


    End Sub
    Private Sub aCreate_DeliveryNoteOutFromStorageORIR_CustomizePopupWindowParams(sender As System.Object, e As DevExpress.ExpressApp.Actions.CustomizePopupWindowParamsEventArgs) Handles aCreate_DeliveryNoteOutFromStorageORIR.CustomizePopupWindowParams
        Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
        Dim _StorageOutRowsInRows As StorageOutRowsInRows = _onew.GetObjectByKey(Of StorageOutRowsInRows)(TryCast(View.SelectedObjects(0), StorageOutRowsInRows).Oid)
        Dim _DeliveryNoteOutfromStorageOutrowsInRowsPopup As DeliveryNoteOutfromStorageOutrowsInRowsPopup = _onew.CreateObject(Of DeliveryNoteOutfromStorageOutrowsInRowsPopup)()
        Dim _DeliveryNoteOutType_Collection As New XPCollection(Of DeliveryNoteOutType)(_onew.Session)

        If _DeliveryNoteOutType_Collection.Count = 1 Then
            _DeliveryNoteOutfromStorageOutrowsInRowsPopup.DeliveryNoteOutType = _onew.GetObject(_DeliveryNoteOutType_Collection(0))
        End If

        _DeliveryNoteOutfromStorageOutrowsInRowsPopup.CustomersFrom = _StorageOutRowsInRows.StorageOutRows.StorageOutHeader.CustomersFrom
        _DeliveryNoteOutfromStorageOutrowsInRowsPopup.Customers = _StorageOutRowsInRows.StorageOutRows.StorageOutHeader.Customers

        If _StorageOutRowsInRows.StorageOutRows.OrderInRows.OrderInHeader.ShipmentOption IsNot Nothing Then
            _DeliveryNoteOutfromStorageOutrowsInRowsPopup.ShipmentOption = _onew.GetObject(_StorageOutRowsInRows.StorageOutRows.OrderInRows.OrderInHeader.ShipmentOption)
        Else
            _DeliveryNoteOutfromStorageOutrowsInRowsPopup.ShipmentOption = _onew.GetObject(_StorageOutRowsInRows.StorageOutRows.StorageOutHeader.Customers.ShipmentOption)
        End If
        If _StorageOutRowsInRows.StorageOutRows.OrderInRows.OrderInHeader.QualityOption IsNot Nothing Then
            _DeliveryNoteOutfromStorageOutrowsInRowsPopup.QualityOption = _onew.GetObject(_StorageOutRowsInRows.StorageOutRows.OrderInRows.OrderInHeader.QualityOption)
        Else
            _DeliveryNoteOutfromStorageOutrowsInRowsPopup.QualityOption = _onew.GetObject(_StorageOutRowsInRows.StorageOutRows.StorageOutHeader.Customers.QualityOption)
        End If

        If _StorageOutRowsInRows.StorageOutRows.OrderInRows.OrderInHeader.Customers.Address2 IsNot Nothing Then
            _DeliveryNoteOutfromStorageOutrowsInRowsPopup.TransportAddress = _onew.GetObject(_StorageOutRowsInRows.StorageOutRows.OrderInRows.OrderInHeader.Customers.Address2)
        End If

        e.View = Application.CreateDetailView(_onew, "DeliveryNoteOutfromStorageOutrowsInRowsPopup_DetailView", False, _DeliveryNoteOutfromStorageOutrowsInRowsPopup)
    End Sub
    Private Sub aCreate_DeliveryNoteOutFromStorageORIR_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.PopupWindowShowActionExecuteEventArgs) Handles aCreate_DeliveryNoteOutFromStorageORIR.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _DeliveryNOutFStorageORIR_Popup As DeliveryNoteOutfromStorageOutrowsInRowsPopup = TryCast(e.PopupWindow.View.SelectedObjects(0), DeliveryNoteOutfromStorageOutrowsInRowsPopup)
        Try
            Dim _DeliveryNoteOutType As DeliveryNoteOutType = _ocur.GetObjectByKey(Of DeliveryNoteOutType)(_DeliveryNOutFStorageORIR_Popup.DeliveryNoteOutType.Oid)
            Dim _Customers As Customers = _ocur.GetObjectByKey(Of Customers)(_DeliveryNOutFStorageORIR_Popup.Customers.Oid)
            Dim _CustomersFrom As CustomersFrom = _ocur.GetObjectByKey(Of CustomersFrom)(_DeliveryNOutFStorageORIR_Popup.CustomersFrom.Oid)
            Dim _ShipmentOption As ShipmentOption = _ocur.GetObjectByKey(Of ShipmentOption)(_DeliveryNOutFStorageORIR_Popup.ShipmentOption.Oid)
            Dim _QualityOption As QualityOption = _ocur.GetObjectByKey(Of QualityOption)(_DeliveryNOutFStorageORIR_Popup.QualityOption.Oid)
            Dim _CurrencyName As CurrencyName = _ocur.GetObjectByKey(Of CurrencyName)(_DeliveryNOutFStorageORIR_Popup.CurrencyName.Oid)
            Dim _TransportAddress As Address = _ocur.GetObjectByKey(Of Address)(_DeliveryNOutFStorageORIR_Popup.TransportAddress.Oid)
            Dim _Note As String = _DeliveryNOutFStorageORIR_Popup.Note
            Dim _StorageOutRowsInRows As StorageOutRowsInRows = Nothing
            Dim _StorageOutRowsInRows_OrigView As StorageOutRowsInRows = Nothing
            Dim _DeliveryNoteOutRows As DeliveryNoteOutRows = Nothing

            Dim _DeliveryNoteOutHeader As New DeliveryNoteOutHeader(_ocur.Session)
            _DeliveryNoteOutHeader.DeliveryNoteOutType = _DeliveryNoteOutType
            _DeliveryNoteOutHeader.Customers = _Customers
            _DeliveryNoteOutHeader.CustomersFrom = _CustomersFrom
            _DeliveryNoteOutHeader.ShipmentOption = _ShipmentOption
            _DeliveryNoteOutHeader.QualityOption = _QualityOption
            _DeliveryNoteOutHeader.CurrencyName = _CurrencyName
            _DeliveryNoteOutHeader.TransportAddress = _TransportAddress
            _DeliveryNoteOutHeader.Note = _Note
            _DeliveryNoteOutHeader.IsEditable = False
            _DeliveryNoteOutHeader.DateCreated = GetSQLTime(_ocur.Session)
            _DeliveryNoteOutHeader.DateExecution = GetSQLTime(_ocur.Session)


            For Each _StorageOutRowsInRows_OrigView In View.SelectedObjects
                _StorageOutRowsInRows = _ocur.GetObjectByKey(Of StorageOutRowsInRows)(_StorageOutRowsInRows_OrigView.Oid)
                If _StorageOutRowsInRows_OrigView.QTT_Will > 0 And _StorageOutRowsInRows_OrigView.QTT_Will <= _StorageOutRowsInRows_OrigView.QTT - _StorageOutRowsInRows_OrigView.QTT_To_DeliveryOut Then
                    _DeliveryNoteOutRows = New DeliveryNoteOutRows(_ocur.Session)
                    If View.Id = "StorageOutRowsInRows_ListView_DeliveryNote_OrderIn" Then
                        _StorageOutRowsInRows.StorageOutRows.OrderInRows.QTT_DeliveryNoted += _StorageOutRowsInRows_OrigView.QTT_Will
                    End If

                    _DeliveryNoteOutRows.DeliveryNoteOutHeader = _DeliveryNoteOutHeader
                    _DeliveryNoteOutRows.StorageOutRowsInRows = _StorageOutRowsInRows
                    _DeliveryNoteOutRows.QTT = _StorageOutRowsInRows_OrigView.QTT_Will
                    _DeliveryNoteOutRows.RowIndex = _DeliveryNoteOutHeader.DeliveryNoteOutRows.Count

                    _StorageOutRowsInRows.QTT_To_DeliveryOut += _StorageOutRowsInRows_OrigView.QTT_Will
                    _StorageOutRowsInRows_OrigView.QTT_Will = 0
                End If
            Next
            If _DeliveryNoteOutHeader.DeliveryNoteOutRows.Count = 0 Then Throw New Exception("*Nincs egy olyan sor sem, amin lenne legalább 1db kiszállítandó mennyiség!" & vbNewLine & vbNewLine & _
                                                                                            "Üres szállítólevél nem hozható létre!")

            _ocur.CommitChanges()

            If _DeliveryNoteOutType.ReportData IsNot Nothing Then
                Dim _ReportData As ReportData = _ocur.FindObject(Of ReportData)(CriteriaOperator.Parse("Oid=?", _DeliveryNoteOutType.ReportData.Oid), True)
                If _ReportData IsNot Nothing Then
                    Frame.GetController(Of Reports.ReportServiceController).ShowPreview(_ReportData, CriteriaOperator.Parse("_DeliveryNoteOutHeader.DocumentNumber =?", _DeliveryNoteOutHeader.DocumentNumber), True)
                End If
                If Frame.GetController(Of RefreshController).RefreshAction.Enabled Then
                    Frame.GetController(Of RefreshController).RefreshAction.DoExecute()
                End If
            End If
        Catch exp As Exception
            MsgBox(exp.Message, MsgBoxStyle.OkOnly, "Hiba!")
        End Try
    End Sub
    Private Sub aCreate_InvoiceFromStorageORIR_Cancel(sender As Object, e As System.EventArgs) Handles aCreate_InvoiceFromStorageORIR.Cancel

    End Sub
    Private Sub aCreate_InvoiceFromStorageORIR_CustomizePopupWindowParams(sender As Object, e As DevExpress.ExpressApp.Actions.CustomizePopupWindowParamsEventArgs) Handles aCreate_InvoiceFromStorageORIR.CustomizePopupWindowParams
        Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
        Dim _DeliveryNoteOutRows As DeliveryNoteOutRows = TryCast(View.SelectedObjects(0), DeliveryNoteOutRows)
        Dim _ORI_Invoice_Popup As ORI_Invoice_Popup = _onew.CreateObject(Of ORI_Invoice_Popup)()

        Dim _InvoiceType_Collection As New XPCollection(Of InvoiceType)(_onew.Session, CriteriaOperator.Parse("CustomersFrom=? AND InvoiceTypeBase=2", _
                                                        _onew.GetObject(_DeliveryNoteOutRows.StorageOutRowsInRows.StorageOutRows.OrderInRows.OrderInHeader.CustomersFrom)))
        If _InvoiceType_Collection.Count = 1 Then
            _ORI_Invoice_Popup.InvoiceType = _onew.GetObject(_InvoiceType_Collection(0))
        End If

        _ORI_Invoice_Popup.CustomersFrom = _onew.GetObject(_DeliveryNoteOutRows.StorageOutRowsInRows.StorageOutRows.OrderInRows.OrderInHeader.CustomersFrom)
        _ORI_Invoice_Popup.Customers = _onew.GetObject(_DeliveryNoteOutRows.StorageOutRowsInRows.StorageOutRows.OrderInRows.OrderInHeader.Customers)
        _ORI_Invoice_Popup.CurrencyName = _onew.GetObject(_DeliveryNoteOutRows.DeliveryNoteOutHeader.CurrencyName)
        _ORI_Invoice_Popup.ShipmentOption = _onew.GetObject(_DeliveryNoteOutRows.StorageOutRowsInRows.StorageOutRows.OrderInRows.OrderInHeader.Customers.ShipmentOption)
        _ORI_Invoice_Popup.PaymentOption = _onew.GetObject(_DeliveryNoteOutRows.StorageOutRowsInRows.StorageOutRows.OrderInRows.OrderInHeader.Customers.PaymentOption)
        _ORI_Invoice_Popup.DateExecution = GetSQLTime(_onew.Session)

        e.View = Application.CreateDetailView(_onew, "ORI_Invoice_Popup_DetailView", False, _ORI_Invoice_Popup)
    End Sub
    Private Sub aCreate_InvoiceFromStorageORIR_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.PopupWindowShowActionExecuteEventArgs) Handles aCreate_InvoiceFromStorageORIR.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _ORI_Invoice_Popup As ORI_Invoice_Popup = TryCast(e.PopupWindow.View.SelectedObjects(0), ORI_Invoice_Popup)
        Try
            Dim _InvoiceType As InvoiceType = _ocur.GetObjectByKey(Of InvoiceType)(_ORI_Invoice_Popup.InvoiceType.Oid)
            Dim _CustomersFrom As CustomersFrom = _ocur.GetObjectByKey(Of CustomersFrom)(_ORI_Invoice_Popup.CustomersFrom.Oid)
            Dim _Customers As Customers = _ocur.GetObjectByKey(Of Customers)(_ORI_Invoice_Popup.Customers.Oid)
            Dim _DateCreated As Date = _ORI_Invoice_Popup.DateCreated
            Dim _DateExecution As Date = _ORI_Invoice_Popup.DateExecution
            Dim _DatePayment As Date = _ORI_Invoice_Popup.DatePayment
            Dim _PaymentOption As PaymentOption = _ocur.GetObjectByKey(Of PaymentOption)(_ORI_Invoice_Popup.PaymentOption.Oid)
            Dim _ShipmentOption As ShipmentOption = _ocur.GetObjectByKey(Of ShipmentOption)(_ORI_Invoice_Popup.ShipmentOption.Oid)
            Dim _CurrencyName As CurrencyName = _ocur.GetObjectByKey(Of CurrencyName)(_ORI_Invoice_Popup.CurrencyName.Oid)
            Dim _BankInformation As BankInformation = _ocur.GetObjectByKey(Of BankInformation)(_ORI_Invoice_Popup.BankInformation.Oid)
            Dim _Description As String = _ORI_Invoice_Popup.Description
            Dim _DeliveryNoteOutRows As DeliveryNoteOutRows = Nothing
            Dim _NG As NumberGenerator

            Dim _InvoiceHeader As New InvoiceHeader(_ocur.Session)
            _InvoiceHeader.InvoiceType = _InvoiceType
            _InvoiceHeader.CustomersFrom = _CustomersFrom
            _InvoiceHeader.Customers = _Customers
            _InvoiceHeader.DateCreated = _DateCreated
            _InvoiceHeader.DateExecution = _DateExecution
            _InvoiceHeader.DatePayment = _DatePayment
            _InvoiceHeader.PaymentOption = _PaymentOption
            _InvoiceHeader.ShipmentOption = _ShipmentOption
            _InvoiceHeader.CurrencyName = _CurrencyName
            _InvoiceHeader.BankInformation = _BankInformation
            _InvoiceHeader.Description = _Description
            _InvoiceHeader.IsEditable = False
            _InvoiceHeader.IsProforma = True
            _InvoiceHeader.IsStorno = False
            If _InvoiceHeader.PaymentOption.PayMode = ePayMode.InContinuous Then
                _InvoiceHeader.DatePayment = _InvoiceHeader.DateExecution
            Else
                If _InvoiceHeader.PaymentOption.DatePaymentMode = eDatePaymentMode.eDateCreated Then
                    _InvoiceHeader.DatePayment = _InvoiceHeader.DateCreated.AddDays(_InvoiceHeader.PaymentOption.PayDay)
                Else
                    _InvoiceHeader.DatePayment = _InvoiceHeader.DateExecution.AddDays(_InvoiceHeader.PaymentOption.PayDay)
                End If
            End If
            If _InvoiceHeader.InvoiceType.NumberGeneratorProforma IsNot Nothing Then
                _NG = _InvoiceHeader.InvoiceType.NumberGeneratorProforma
                _InvoiceHeader.DocumentNumberProforma = _NG.GetNewNumber(_NG)
            End If

            For Each _DeliveryNoteOutRows_OrigView As DeliveryNoteOutRows In View.SelectedObjects
                _DeliveryNoteOutRows = _ocur.GetObjectByKey(Of DeliveryNoteOutRows)(_DeliveryNoteOutRows_OrigView.Oid)

                Dim _InvoiceRows As New InvoiceRows(_ocur.Session)

                _InvoiceRows.InvoiceHeader = _InvoiceHeader
                _InvoiceRows.OrderInRows = _DeliveryNoteOutRows.StorageOutRowsInRows.StorageOutRows.OrderInRows
                _InvoiceRows.InvoiceRowtype = eInvoiceRowType.FromOrder
                _InvoiceRows.DiscountPriceDEV = _DeliveryNoteOutRows.StorageOutRowsInRows.StorageOutRows.OrderInRows.DiscountPriceDEV
                _InvoiceRows.DiscountPriceHUF = _DeliveryNoteOutRows.StorageOutRowsInRows.StorageOutRows.OrderInRows.DiscountPriceHUF
                _InvoiceRows.ListPriceDEV = _DeliveryNoteOutRows.StorageOutRowsInRows.StorageOutRows.OrderInRows.ListPriceDEV
                _InvoiceRows.ListPriceHUF = _DeliveryNoteOutRows.StorageOutRowsInRows.StorageOutRows.OrderInRows.ListPriceHUF
                _InvoiceRows.QTT = _DeliveryNoteOutRows.QTT_Will
                _InvoiceRows.QualityOption = _DeliveryNoteOutRows.StorageOutRowsInRows.StorageOutRows.OrderInRows.QualityOption
                _InvoiceRows.RowIndex = _InvoiceHeader.InvoiceRows.Count
                _InvoiceRows.ShortName = _DeliveryNoteOutRows.StorageOutRowsInRows.StorageOutRows.OrderInRows.Products.ProductNumber & vbNewLine & _
                                         _DeliveryNoteOutRows.StorageOutRowsInRows.StorageOutRows.OrderInRows.Products.ShortName
                _InvoiceRows.Units = _DeliveryNoteOutRows.StorageOutRowsInRows.StorageOutRows.OrderInRows.Products.Units
                _InvoiceRows.VAT = _DeliveryNoteOutRows.StorageOutRowsInRows.StorageOutRows.OrderInRows.Products.VAT
                _InvoiceRows.Description = _DeliveryNoteOutRows.StorageOutRowsInRows.StorageOutRows.OrderInRows.Description
                _InvoiceRows.CustomsTariffs = _DeliveryNoteOutRows.StorageOutRowsInRows.StorageOutRows.OrderInRows.Products.CustomsTariff
            Next

            _ocur.CommitChanges()
        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try
    End Sub
    '----------------------View.SelectionChanged Z ----------------------------------------------------
    Private Sub StorageOutRowsInRows_ListView_DeliveryNote_Transfer_ViewSelectionChanged(sender As Object, e As EventArgs)
        If View.SelectedObjects.Count = 0 Then Exit Sub
        Dim _ActionEnabled As Boolean = True
        If View.SelectedObjects.Count = 1 Then
            If TryCast(View.SelectedObjects(0), StorageOutRowsInRows).QTT < TryCast(View.SelectedObjects(0), StorageOutRowsInRows).QTT_Will Then
                _ActionEnabled = False
            End If
        Else
            Dim _Act_CustomersFrom As CustomersFrom = TryCast(View.SelectedObjects(0), StorageOutRowsInRows).StorageOutRows.StorageOutHeader.CustomersFrom
            If _Act_CustomersFrom IsNot Nothing Then
                For Each _StorageOutRowsInRows As StorageOutRowsInRows In View.SelectedObjects
                    If _StorageOutRowsInRows.StorageOutRows.StorageOutHeader.CustomersFrom.Oid <> _Act_CustomersFrom.Oid Or _
                        _StorageOutRowsInRows.QTT < _StorageOutRowsInRows.QTT_Will Then
                        _ActionEnabled = False
                        Exit For
                    End If
                Next
            End If
        End If

        Frame.GetController(Of DeliveryNoteOutVC).aCreate_DeliveryNoteOutFromStorageORIR.Enabled.SetItemValue("", _ActionEnabled)

    End Sub
    Private Sub DeliveryNoteOutRows_ListView_Invoice_ViewSelectionChanged(sender As Object, e As EventArgs)
        If View.SelectedObjects.Count = 0 Then Exit Sub
        Dim _ActionEnabled As Boolean = True
        If View.SelectedObjects.Count = 1 Then
            If TryCast(View.SelectedObjects(0), DeliveryNoteOutRows).QTT < TryCast(View.SelectedObjects(0), DeliveryNoteOutRows).QTT_Will Then
                _ActionEnabled = False
            End If
        Else
            Dim _Act_CustomersFrom As CustomersFrom = TryCast(View.SelectedObjects(0), DeliveryNoteOutRows).DeliveryNoteOutHeader.CustomersFrom
            If _Act_CustomersFrom IsNot Nothing Then
                For Each _DeliveryNoteOutRows As DeliveryNoteOutRows In View.SelectedObjects
                    If _DeliveryNoteOutRows.DeliveryNoteOutHeader.CustomersFrom.Oid <> _Act_CustomersFrom.Oid Or _
                        _DeliveryNoteOutRows.QTT < _DeliveryNoteOutRows.QTT_Will Then
                        _ActionEnabled = False
                        Exit For
                    End If
                Next
            End If
        End If

        Frame.GetController(Of DeliveryNoteOutVC).aCreate_InvoiceFromStorageORIR.Enabled.SetItemValue("", _ActionEnabled)
    End Sub
    Private Sub aDeliveryNoteOutRowsPrint_Execute(sender As Object, e As SimpleActionExecuteEventArgs) Handles aDeliveryNoteOutRowsPrint.Execute
        Try
            If View.SelectedObjects.Count = 0 Then Throw New Exception("*Nincs kiválasztva egyetlen sor sem!")
            Dim _DeliveryNoteOutHeader As DeliveryNoteOutHeader = TryCast(View.SelectedObjects(0), DeliveryNoteOutRows).DeliveryNoteOutHeader
            If _DeliveryNoteOutHeader Is Nothing Then Throw New Exception("*Váratlan hiba történt a folyamat megszakadt!")
            Dim _ReportData As ReportData = _DeliveryNoteOutHeader.DeliveryNoteOutType.ReportData
            If _ReportData Is Nothing Then Throw New Exception("*Nincs beállítva nyomtatvány!")

            Frame.GetController(Of Reports.ReportServiceController).ShowPreview(_ReportData, CriteriaOperator.Parse("DeliveryNoteOutHeader.DocumentNumber =?", _DeliveryNoteOutHeader.DocumentNumber), True)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, String.Format(CaptionHelper.GetLocalizedText("Exceptions\SISBusinessExceptions", "MsgBoxCheckItAgain")))
        End Try
    End Sub

    Private Sub aCheckDeliveryNoteOutWeight_Execute(sender As Object, e As SimpleActionExecuteEventArgs) Handles aCheckDeliveryNoteOutWeight.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _DeliveryNoteOutHeader As DeliveryNoteOutHeader
        Dim _DeliveryNoteOutRows As DeliveryNoteOutRows

        For Each _DeliveryNoteOutHeader In View.SelectedObjects
            For Each _DeliveryNoteOutRows In _DeliveryNoteOutHeader.DeliveryNoteOutRows
                If _DeliveryNoteOutRows.StorageOutRowsInRows.StorageInRows.DeliveryNoteInRows IsNot Nothing Then
                    _DeliveryNoteOutRows.StorageOutRowsInRows.StorageInRows.Weight = _DeliveryNoteOutRows.StorageOutRowsInRows.StorageInRows.DeliveryNoteInRows.Weight
                    _DeliveryNoteOutRows.StorageOutRowsInRows.StorageInRows.WeightMode = _DeliveryNoteOutRows.StorageOutRowsInRows.StorageInRows.DeliveryNoteInRows.WeightMode
                    _DeliveryNoteOutRows.StorageOutRowsInRows.StorageInRows.Save()
                End If
            Next
        Next
        _ocur.CommitChanges()

    End Sub
End Class
