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.ExpressApp.Editors
Imports DevExpress.ExpressApp.SystemModule
Imports DevExpress.Data.Filtering
Imports DevExpress.ExpressApp.Utils
Imports DevExpress.Persistent.BaseImpl

Public Class InvoiceRowVC
    Inherits DevExpress.ExpressApp.ViewController
    Public Event InitWork(ByVal _Minimum As Long, ByVal _Step As Long, ByVal _Maximum As Long)
    Public Event DoWork()
    Public Event FinalWork
    Protected _noselect As Boolean = False
    Protected _selection As ArrayList
    Public Sub New()
        MyBase.New()
        InitializeComponent()
        RegisterActions(components)
        _selection = New ArrayList()
    End Sub
    Private _InvoiceRows_Corr As InvoiceRows
    Protected Overrides Sub OnActivated()
        MyBase.OnActivated()

        Frame.GetController(Of InvoiceRowVC).aToTable_Invoice.Active.SetItemValue("", False)
        Frame.GetController(Of InvoiceRowVC).aBackToRowEdit_Invoice.Active.SetItemValue("", False)
        Frame.GetController(Of InvoiceRowVC).aToTableD_Invoice.Active.SetItemValue("", False)
        Frame.GetController(Of InvoiceRowVC).aChoiceProducts.Active.SetItemValue("", False)
        Frame.GetController(Of InvoiceRowVC).aChoiceService.Active.SetItemValue("", False)

        If View.Id = "InvoiceHeader_DetailView" Then
            Dim _InvoiceHeader As InvoiceHeader = Nothing
            If View.SelectedObjects.Count > 0 Then
                _InvoiceHeader = TryCast(View.SelectedObjects(0), InvoiceHeader)
            End If
            If _InvoiceHeader IsNot Nothing Then
                If _InvoiceHeader.IsEditable = True Then
                    Frame.GetController(Of InvoiceRowVC).aToTable_Invoice.Active.SetItemValue("", True)
                    Frame.GetController(Of InvoiceRowVC).aBackToRowEdit_Invoice.Active.SetItemValue("", True)
                    Frame.GetController(Of InvoiceRowVC).aToTableD_Invoice.Active.SetItemValue("", True)
                    Frame.GetController(Of InvoiceRowVC).aChoiceProducts.Active.SetItemValue("", True)
                    Frame.GetController(Of InvoiceRowVC).aChoiceService.Active.SetItemValue("", True)
                End If
            End If
        End If

        If View.Id = "InvoiceHeader_InvoiceRows_ListView" Then
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.LinkUnlinkController)().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 DevExpress.ExpressApp.SystemModule.NewObjectViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of InvoiceVC)().aDeleteSelectedInvoiceRows.Active.SetItemValue("", False) ' Kijelölt sor törlése
            Frame.GetController(Of ListViewProcessCurrentObjectController).Active.SetItemValue("", False)
        End If

        If View.Id = "InvoiceHeader_InvoiceVATRows_ListView" Then
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.LinkUnlinkController)().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 DevExpress.ExpressApp.SystemModule.NewObjectViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of ListViewProcessCurrentObjectController).Active.SetItemValue("", False)
        End If
        If View.Id = "InvoiceRows_ListView_Table" Then
            AddHandler View.SelectionChanged, AddressOf view_SelectionChanged
        End If
        If View.Id = "OrderInHeader_InvoiceRows_ListView" Or View.Id = "InvoiceHeader_InvoiceRows_ListView" Then
            Frame.GetController(Of InvoiceRowVC).aInvoiceRowPrint.Active.SetItemValue("", False)
        End If

    End Sub
    Protected Overrides Sub OnDeactivated()
        MyBase.OnDeactivated()
        If View.Id = "InvoiceHeader_InvoiceRows_ListView" Then
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.LinkUnlinkController)().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 DevExpress.ExpressApp.SystemModule.NewObjectViewController)().Active.SetItemValue("", True)
            Frame.GetController(Of InvoiceVC)().aDeleteSelectedInvoiceRows.Active.SetItemValue("", True) ' Kijelölt sor törlése
            Frame.GetController(Of ListViewProcessCurrentObjectController).Active.SetItemValue("", True)
        End If

        If View.Id = "InvoiceHeader_InvoiceVATRows_ListView" Then
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.LinkUnlinkController)().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 DevExpress.ExpressApp.SystemModule.NewObjectViewController)().Active.SetItemValue("", True)
            Frame.GetController(Of ListViewProcessCurrentObjectController).Active.SetItemValue("", True)
        End If
        If View.Id = "InvoiceRows_ListView_Table" Then
            RemoveHandler View.SelectionChanged, AddressOf view_SelectionChanged
        End If
        If View.Id = "OrderInHeader_InvoiceRows_ListView" Or View.Id = "InvoiceHeader_InvoiceRows_ListView" Then
            Frame.GetController(Of InvoiceRowVC).aInvoiceRowPrint.Active.SetItemValue("", True)
        End If
    End Sub
    Private Sub aToTable_Invoice_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aToTable_Invoice.Execute
        Dim _InvoiceHeader As InvoiceHeader = CType(e.SelectedObjects(0), InvoiceHeader)

        If _InvoiceHeader.IsCorrigendum Then
            Dim _ItemInvoiceRows As ListPropertyEditor = TryCast(View, DetailView).FindItem("@InvoiceHeader.InvoiceRows")
            If _ItemInvoiceRows IsNot Nothing Then
                _InvoiceRows_Corr = TryCast(_ItemInvoiceRows.ListView.SelectedObjects(0), InvoiceRows)
            End If
        End If

        If _InvoiceRows_Corr IsNot Nothing Then
            Frame.GetController(Of DevExpress.ExpressApp.Validation.PersistenceValidationController)().Active.SetItemValue("", False)
        End If
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)


        Dim _InvoiceRows_Originalminus As InvoiceRows = Nothing
        If _InvoiceRows_Corr IsNot Nothing Then
            _InvoiceRows_Originalminus = _ocur.FindObject(Of InvoiceRows)(CriteriaOperator.Parse("InvoiceRowCorrigendumType=1 AND InvoiceRows.Oid=?", _InvoiceRows_Corr.Oid))
        End If

        If _InvoiceRows_Originalminus Is Nothing Then
            Dim _InvoiceRows As InvoiceRows = _ocur.CreateObject(Of InvoiceRows)()
            _InvoiceRows.AddRows(_InvoiceHeader, _InvoiceRows_Corr, _ocur)

            Dim ItemToFocus As ViewItem = TryCast(View, DetailView).FindItem("row_Products")
            If ItemToFocus IsNot Nothing Then
                Dim ItemControl As Object
                ItemControl = ItemToFocus.Control
                If ItemControl IsNot Nothing Then 'A Control ha ures lépjen tovább
                    ItemControl.Focus()
                End If
            End If

            _ocur.CommitChanges()
            _InvoiceRows_Corr = Nothing
            If _InvoiceRows_Corr IsNot Nothing Then
                _InvoiceHeader.row_QTT = 0
            Else
                _InvoiceHeader.row_QTT = 1
            End If
            _InvoiceHeader.row_ShortName = ""
            _InvoiceHeader.row_Description = ""
            _InvoiceHeader.row_ListPriceHUF = 0
            _InvoiceHeader.row_ListPriceDEV = 0
            _InvoiceHeader.row_DiscountPercent = 0
            _InvoiceHeader.row_QualityOption = Nothing
            _InvoiceHeader.row_Controlling = Nothing
            _InvoiceHeader.row_UniqueObjects = Nothing
            _InvoiceHeader.row_CostHolder = Nothing
            _InvoiceHeader.row_CostPlace = Nothing
            _InvoiceHeader.row_JobNumberObjects = Nothing



            If _InvoiceRows_Corr IsNot Nothing Then
                Frame.GetController(Of DevExpress.ExpressApp.Validation.PersistenceValidationController)().Active.SetItemValue("", True)
            End If
        Else
            '_ocur.Rollback()
            Throw New Exception("*Ez a sor már módosítva lett!")
        End If
        View.Refresh()
    End Sub
    Private Sub aToTableD_Invoice_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aToTableD_Invoice.Execute
        Dim _InvoiceRows As InvoiceRows
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _InvoiceHeader As InvoiceHeader = TryCast(View.SelectedObjects(0), InvoiceHeader)
        Dim _InvoiceRows_ListEditor As ListPropertyEditor

        _InvoiceRows_ListEditor = TryCast(View, DetailView).FindItem("InvoiceRows")
        For Each _InvoiceRows In _InvoiceRows_ListEditor.ListView.SelectedObjects
            If _InvoiceRows.InvoiceRowCorrigendumType <> eInvoiceRowCorrigendumType.eNormal Then
                Dim _InvoiceRows_Link As InvoiceRows = Nothing
                If _InvoiceRows.InvoiceRowCorrigendumType = eInvoiceRowCorrigendumType.eNew Then
                    _InvoiceRows_Link = _ocur.FindObject(Of InvoiceRows)(CriteriaOperator.Parse("InvoiceRowCorrigendumType=1 AND InvoiceRows.Oid=?", _InvoiceRows.InvoiceRows.Oid))
                End If
                If _InvoiceRows.InvoiceRowCorrigendumType = eInvoiceRowCorrigendumType.eOriginalMinus Then
                    _InvoiceRows_Link = _ocur.FindObject(Of InvoiceRows)(CriteriaOperator.Parse("InvoiceRowCorrigendumType=2 AND InvoiceRows.Oid=?", _InvoiceRows.InvoiceRows.Oid))
                End If
                _InvoiceRows_Link.Delete()

            End If
            _InvoiceRows.RemoveRows(_InvoiceHeader)
        Next
        _InvoiceHeader.Save()

        View.Refresh()
    End Sub
    Private Sub aBackToRowEdit_Invoice_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aBackToRowEdit_Invoice.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _InvoiceHeader As InvoiceHeader = View.SelectedObjects(0) 'Kijelölt elem fejlécének betöltése
        Dim _ListView As ListPropertyEditor
        If _InvoiceHeader.IsCorrigendum = True Then
            _ListView = TryCast(View, DetailView).FindItem("@InvoiceHeader.InvoiceRows") 'Sorok összeszedése
        Else
            _ListView = TryCast(View, DetailView).FindItem("InvoiceRows") 'Sorok összeszedése
        End If
        If _ListView.ListView.SelectedObjects.Count > 0 Then

            Dim _InvoiceRows As InvoiceRows = _ListView.ListView.SelectedObjects(0)  'Régi sor változóba töltése
            _InvoiceHeader.row_Controlling = _InvoiceRows.Controlling
            _InvoiceHeader.row_CostHolder = _InvoiceRows.CostHolder
            _InvoiceHeader.row_CostPlace = _InvoiceRows.CostPlace
            _InvoiceHeader.row_Description = _InvoiceRows.Description
            _InvoiceHeader.row_DiscountPercent = _InvoiceRows.DiscountPercent
            _InvoiceHeader.row_JobNumberObjects = _InvoiceRows.JobNumberObjects
            _InvoiceHeader.row_ListPriceDEV = _InvoiceRows.ListPriceDEV
            _InvoiceHeader.row_ListPriceHUF = _InvoiceRows.ListPriceHUF
            _InvoiceHeader.row_QTT = _InvoiceRows.QTT
            _InvoiceHeader.row_QualityOption = _InvoiceRows.QualityOption
            _InvoiceHeader.row_ShortName = _InvoiceRows.ShortName
            _InvoiceHeader.row_UniqueObjects = _InvoiceRows.UniqueObjects
            _InvoiceHeader.row_Units = _InvoiceRows.Units
            _InvoiceHeader.row_VAT = _InvoiceRows.VAT
            _InvoiceHeader.row_InvoicePeriod = _InvoiceRows.InvoicePeriod
            _InvoiceHeader.row_CustomsTariffs = _InvoiceRows.CustomsTariffs
            If View.Id = "InvoiceHeader_DetailView_Corrigendum" Then
                _InvoiceRows_Corr = _InvoiceRows
            End If
        End If
    End Sub
    Private Sub aUp_InvoiceRow_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aUp_InvoiceRow.Execute
        ' A kiválaszott sort egy sorral feljebb helyezi
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _InvoiceHeader As InvoiceHeader = TryCast(View.SelectedObjects(0), InvoiceRows).InvoiceHeader
        Dim _InvoiceRowsSelected As InvoiceRows
        Dim _InvoiceRowsMinus As InvoiceRows = Nothing
        Dim _InvoiceRows As InvoiceRows

        Try
            _InvoiceRowsSelected = TryCast(View.SelectedObjects(0), InvoiceRows) ' Az editor egy listview, kiveszi az első kijelölt sorát
        Catch
            ' TESZT MIATT!!!! ----------------------------------------------------------------
            Throw New Exception("*Nincs sor kiválasztva, vagy nem a sor kijelölése az aktív!")
        End Try

        If _InvoiceRowsSelected.RowIndex > 0 Then
            For Each _InvoiceRows In _InvoiceHeader.InvoiceRows
                If _InvoiceRows.RowIndex = _InvoiceRowsSelected.RowIndex - 1 Then
                    _InvoiceRowsMinus = _InvoiceRows
                    Exit For
                End If
            Next

            If _InvoiceRowsMinus IsNot Nothing Then
                _InvoiceRowsSelected.RowIndex -= 1
                _InvoiceRowsMinus.RowIndex += 1
            End If
            _InvoiceRowsMinus.Save()
            _InvoiceRowsSelected.Save()
            _ocur.CommitChanges()
            View.Refresh()
        End If
    End Sub
    Private Sub aDown_InvoiceRow_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aDown_InvoiceRow.Execute
        ' A kiválaszott sort egy sorral lejebb helyezi
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _InvoiceHeader As InvoiceHeader = TryCast(View.CurrentObject, InvoiceRows).InvoiceHeader
        Dim _InvoiceRowsSelected As InvoiceRows
        Dim _InvoiceRowsPlus As InvoiceRows = Nothing
        Dim _InvoiceRows As InvoiceRows

        Try
            _InvoiceRowsSelected = TryCast(View.SelectedObjects(0), InvoiceRows) ' Kiveszi a kijelölt sorok közül az elsőt
        Catch
            ' TESZT MIATT!!!! ----------------------------------------------------------------
            Throw New Exception("*Nincs sor kiválasztva, vagy nem a sor kijelölése az aktív!")
        End Try

        If _InvoiceRowsSelected.RowIndex < _InvoiceHeader.InvoiceRows.Count - 1 Then
            For Each _InvoiceRows In _InvoiceHeader.InvoiceRows
                If _InvoiceRows.RowIndex = _InvoiceRowsSelected.RowIndex + 1 Then
                    _InvoiceRowsPlus = _InvoiceRows
                    Exit For
                End If
            Next

            If _InvoiceRowsPlus IsNot Nothing Then
                _InvoiceRowsSelected.RowIndex += 1
                _InvoiceRowsPlus.RowIndex -= 1
            End If
            _InvoiceRowsPlus.Save()
            _InvoiceRowsSelected.Save()
            _ocur.CommitChanges()
            View.Refresh()
        End If
    End Sub

    Private Sub aPrintInvoiceByRows_Execute(sender As Object, e As SimpleActionExecuteEventArgs) Handles aPrintInvoiceByRows.Execute
        Dim _ReportData As ReportData
        Dim _ReportData_DEV As ReportData
        Dim _ReportData_DEV_EU As ReportData
        Dim _InvoiceHeader As InvoiceHeader
        Dim _CurrencyName As CurrencyName
        If e.SelectedObjects.Count > 0 Then
            _InvoiceHeader = TryCast(e.SelectedObjects.Item(0), InvoiceRows).InvoiceHeader
            _CurrencyName = _InvoiceHeader.CurrencyName
            If _InvoiceHeader IsNot Nothing Then
                Dim _XAFPrintHelper_I As New XAFPrintHelper(Nothing, Frame, _InvoiceHeader.InvoiceType.ReportDataV2, CriteriaOperator.Parse("InvoiceHeader.Oid = ?", _InvoiceHeader.Oid))
                _XAFPrintHelper_I.ShowPreviewV2()
            End If
        End If
    End Sub

    Private Sub aChangeInvoiceByRows_CustomizePopupWindowParams(sender As Object, e As CustomizePopupWindowParamsEventArgs) Handles aChangeInvoiceByRows.CustomizePopupWindowParams
        Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
        Dim _InvoiceRows_Changer_Popup As InvoiceRows_Changer_Popup = _onew.CreateObject(Of InvoiceRows_Changer_Popup)()
        _noselect = True
        e.View = Application.CreateDetailView(_onew, "InvoiceRows_Changer_Popup_DetailView", False, _InvoiceRows_Changer_Popup)
    End Sub

    Private Sub aChangeInvoiceByRows_Execute(sender As Object, e As PopupWindowShowActionExecuteEventArgs) Handles aChangeInvoiceByRows.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _InvoiceRows As InvoiceRows
        Dim _InvoiceRows_Selected As InvoiceRows
        Dim _InvoiceRows_Changer_Popup As InvoiceRows_Changer_Popup = TryCast(e.PopupWindow.View.SelectedObjects(0), InvoiceRows_Changer_Popup)
        Dim _GLRows As GLRows = Nothing
        RaiseEvent InitWork(1, 1, _selection.Count)
        For Each _InvoiceRows_Selected In _selection
            RaiseEvent DoWork()
            _InvoiceRows = _ocur.GetObject(_InvoiceRows_Selected)
            _InvoiceRows.DateExecution = _InvoiceRows_Changer_Popup.DateExecution

            If _InvoiceRows.InvoiceHeader.GLAccounts IsNot Nothing Then
                _GLRows = _ocur.FindObject(Of GLRows)(CriteriaOperator.Parse("InvoiceRows=?", _InvoiceRows))
                If _GLRows IsNot Nothing Then
                    _GLRows.DateExecution = _InvoiceRows.DateExecution
                End If
            End If
            If _InvoiceRows_Changer_Popup.Controlling IsNot Nothing Then
                _InvoiceRows.Controlling = _ocur.GetObject(_InvoiceRows_Changer_Popup.Controlling)
                If _GLRows IsNot Nothing Then
                    _GLRows.Controlling = _ocur.GetObject(_InvoiceRows_Changer_Popup.Controlling)
                End If
            End If

            If _InvoiceRows_Changer_Popup.CostHolder IsNot Nothing Then
                _InvoiceRows.CostHolder = _ocur.GetObject(_InvoiceRows_Changer_Popup.CostHolder)
                If _GLRows IsNot Nothing Then
                    _GLRows.CostHolder = _ocur.GetObject(_InvoiceRows_Changer_Popup.CostHolder)
                End If
            End If

            If _InvoiceRows_Changer_Popup.CostPlace IsNot Nothing Then
                _InvoiceRows.CostPlace = _ocur.GetObject(_InvoiceRows_Changer_Popup.CostPlace)
                If _GLRows IsNot Nothing Then
                    _GLRows.CostPlace = _ocur.GetObject(_InvoiceRows_Changer_Popup.CostPlace)
                End If
            End If

            If _InvoiceRows_Changer_Popup.UniqueObjects IsNot Nothing Then
                _InvoiceRows.UniqueObjects = _ocur.GetObject(_InvoiceRows_Changer_Popup.UniqueObjects)
                If _GLRows IsNot Nothing Then
                    _GLRows.UniqueObjects = _ocur.GetObject(_InvoiceRows_Changer_Popup.UniqueObjects)
                End If
            End If

            If _InvoiceRows_Changer_Popup.JobNumberObjects IsNot Nothing Then
                _InvoiceRows.JobNumberObjects = _ocur.GetObject(_InvoiceRows_Changer_Popup.JobNumberObjects)
                If _GLRows IsNot Nothing Then
                    _GLRows.JobNumberObjects = _ocur.GetObject(_InvoiceRows_Changer_Popup.JobNumberObjects)
                End If
            End If
            _ocur.CommitChanges()
        Next
        RaiseEvent FinalWork
        _noselect = False
    End Sub

    Private Sub view_SelectionChanged(sender As Object, e As EventArgs)
        Dim i As Long = 0
        Dim _InvoiceRows As InvoiceRows

        If View Is Nothing Then Exit Sub

        If View.Id = "InvoiceRows_ListView_Table" Then
            If _noselect = False Then
                _selection.Clear()
                For Each _InvoiceRows In View.SelectedObjects
                    _selection.Add(_InvoiceRows)
                Next
            End If
        End If
    End Sub

    Private Sub aInvoiceRowPrint_Execute(sender As Object, e As SimpleActionExecuteEventArgs) Handles aInvoiceRowPrint.Execute
        Try
            If View.SelectedObjects.Count = 0 Then Throw New Exception("*Nincs kiválasztva egyetlen sor sem!")
            Dim _InvoiceRows As InvoiceRows = TryCast(View.SelectedObjects(0), InvoiceRows)
            If _InvoiceRows Is Nothing Then Throw New Exception("*Váratlan hiba történt a folyamat megszakadt!")
            If _InvoiceRows.InvoiceHeader.IsEditable = False Then Throw New Exception("*Szerkeszthető számlát nem lehet nyomtatni!")

            Dim _XAFPrintHelper As New XAFPrintHelper(Nothing, Frame, _InvoiceRows.InvoiceHeader.InvoiceType.ReportDataV2, CriteriaOperator.Parse("InvoiceHeader.Oid=?", _InvoiceRows.InvoiceHeader.Oid))
            _XAFPrintHelper.ShowPreviewV2()

        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, String.Format(CaptionHelper.GetLocalizedText("Exceptions\NuvolarExceptions", "MsgBoxCheckItAgain")))
        End Try
    End Sub

    Private Sub aChoiceProducts_CustomizePopupWindowParams(sender As Object, e As CustomizePopupWindowParamsEventArgs) Handles aChoiceProducts.CustomizePopupWindowParams
        Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
        Dim _Products_CollectionSource As New CollectionSource(_onew, GetType(Products))

        e.View = Application.CreateListView("Products_ListView_Choice", _Products_CollectionSource, False)
    End Sub

    Private Sub aChoiceProducts_Execute(sender As Object, e As PopupWindowShowActionExecuteEventArgs) Handles aChoiceProducts.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _InvoiceHeader As InvoiceHeader = TryCast(View.SelectedObjects(0), InvoiceHeader)
        Dim _Products As Products = _ocur.GetObject(TryCast(e.PopupWindow.View.SelectedObjects(0), Products))

        If _InvoiceHeader IsNot Nothing Then
            If _Products IsNot Nothing Then
                _InvoiceHeader.row_ShortName = _Products.ShortName
                _InvoiceHeader.row_CustomsTariffs = _Products.CustomsTariff
                _InvoiceHeader.row_Description = _Products.Description
                _InvoiceHeader.row_ListPriceHUF = _Products.ListPriceOutHUF
                '_InvoiceHeader.row_ListPriceDEV = _Products.ListPriceOutDEV
                _InvoiceHeader.row_VAT = _Products.VAT
                _InvoiceHeader.row_Units = _Products.Units
                _InvoiceHeader.row_Products = _Products
            End If
        End If


    End Sub

    Private Sub aChoiceService_CustomizePopupWindowParams(sender As Object, e As CustomizePopupWindowParamsEventArgs) Handles aChoiceService.CustomizePopupWindowParams
        Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
        Dim _Services_CollectionSource As New CollectionSource(_onew, GetType(Services))

        e.View = Application.CreateListView("Services_ListView_Choice", _Services_CollectionSource, False)
    End Sub

    Private Sub aChoiceService_Execute(sender As Object, e As PopupWindowShowActionExecuteEventArgs) Handles aChoiceService.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _InvoiceHeader As InvoiceHeader = TryCast(View.SelectedObjects(0), InvoiceHeader)
        Dim _Services As Services = _ocur.GetObject(TryCast(e.PopupWindow.View.SelectedObjects(0), Services))

        If _InvoiceHeader IsNot Nothing Then
            If _Services IsNot Nothing Then
                _InvoiceHeader.row_ShortName = _Services.ShortName
                _InvoiceHeader.row_CustomsTariffs = _Services.CustomsTariffs
                _InvoiceHeader.row_Description = _Services.Description
                _InvoiceHeader.row_ListPriceHUF = _Services.ListPriceHUF
                '_InvoiceHeader.row_ListPriceDEV = _Services.ListPriceDEV
                _InvoiceHeader.row_VAT = _Services.VAT
                _InvoiceHeader.row_Units = _Services.Units
                _InvoiceHeader.row_Services = _Services
            End If
        End If
    End Sub
End Class
