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.Xpo
Imports DevExpress.Data.Filtering
Imports System.Linq
Imports DevExpress.ExpressApp.SystemModule
Imports Nuvolar.Module.SIS.Linq.Dynamic
Imports DevExpress.Persistent.BaseImpl

Public Class ABRQueryVC
    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
    Public Sub New()
        MyBase.New()

        'This call is required by the Component Designer.
        InitializeComponent()
        RegisterActions(components)

    End Sub
    Protected Overrides Sub OnActivated()
        MyBase.OnActivated()
        Frame.GetController(Of ABRQueryVC).aGenerateABRQuery.Active.SetItemValue("", False)
        Frame.GetController(Of ABRQueryVC).aSelectCustomersFromABR.Active.SetItemValue("", False)
        Frame.GetController(Of ABRQueryVC).aViewAttachmentsABR.Active.SetItemValue("", False)
        Frame.GetController(Of ABRQueryVC).aViewRegistryABR.Active.SetItemValue("", False)
        Frame.GetController(Of ABRQueryVC).aPrintABRReport.Active.SetItemValue("", False)

        If View.Id = "ABRQueryHeader_DetailView" Then
            Frame.GetController(Of ABRQueryVC).aGenerateABRQuery.Active.SetItemValue("", True)
            Frame.GetController(Of ABRQueryVC).aPrintABRReport.Active.SetItemValue("", True)
        End If
        If View.Id = "ABRQueryHeader_ListView" Then
            Frame.GetController(Of ABRQueryVC).aPrintABRReport.Active.SetItemValue("", True)
        End If
        If View.Id = "ABRQueryHeader_ABRQueryCustomersFrom_ListView" Then
            Frame.GetController(Of NewObjectViewController).Active.SetItemValue("", False)
            Frame.GetController(Of CloneObject.CloneObjectViewController).Active.SetItemValue("", False)
            Frame.GetController(Of LinkUnlinkController).Active.SetItemValue("", False)
            Frame.GetController(Of DeleteObjectsViewController).Active.SetItemValue("", True)
            Frame.GetController(Of ABRQueryVC).aSelectCustomersFromABR.Active.SetItemValue("", True)
        End If
        If View.Id = "ABRQueryHeader_ABRQueryRowsDetail_ListView_HUF" Then
            Frame.GetController(Of ABRQueryVC).aViewAttachmentsABR.Active.SetItemValue("", True)
            Frame.GetController(Of ABRQueryVC).aViewRegistryABR.Active.SetItemValue("", True)
        End If
        If View.Id = "ABRQueryHeader_ABRQueryRowsDetail_ListView_DEV" Then
            Frame.GetController(Of ABRQueryVC).aViewAttachmentsABR.Active.SetItemValue("", True)
            Frame.GetController(Of ABRQueryVC).aViewRegistryABR.Active.SetItemValue("", True)
        End If

    End Sub
    Protected Overrides Sub OnDeactivated()
        MyBase.OnDeactivated()
        If View.Id = "ABRQueryHeader_ABRQueryCustomersFrom_ListView" Then
            Frame.GetController(Of NewObjectViewController).Active.SetItemValue("", True)
            Frame.GetController(Of CloneObject.CloneObjectViewController).Active.SetItemValue("", True)
            Frame.GetController(Of LinkUnlinkController).Active.SetItemValue("", True)
        End If
    End Sub
    Private Sub aGenerateABRQuery_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aGenerateABRQuery.Execute
        '-- Az adott záródátumra vonatkozó partner connection infot adja meg
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As UnitOfWork = New UnitOfWork(_ocur.Session.DataLayer)
        Dim i As Long = 0
        Dim _DifDay As Long
        Dim _ABRQueryRows As ABRQueryRows
        Dim _ABRQueryRowsDetail As ABRQueryRowsDetail


        '// Mielőtt bármi van, le kell futtatni:
        'UPDATE GLHeader
        'DateCreated = DateExecution
        'Where(DateCreated Is NULL)
        Dim _SQL As String = ""
        Select Case GLOBAL_SQLType
            Case eSQLType.MSSQL
                _SQL = "UPDATE  GLHeader Set  DateCreated = DateExecution   WHERE DateCreated Is NULL"
            Case eSQLType.MySQL
                _SQL = "UPDATE  GLHeader Set  DateCreated = DateExecution   WHERE DateCreated Is NULL"
            Case eSQLType.PostgreSQL
                _SQL = "UPDATE  ""GLHeader"" Set  ""DateCreated"" = ""DateExecution""   WHERE ""DateCreated"" Is NULL"
        End Select
        _uow.ExecuteNonQuery(_SQL)
        _uow.CommitChanges()

        Dim _ABRQueryHeader As ABRQueryHeader = _uow.GetObjectByKey(Of ABRQueryHeader) _
            (TryCast(View.SelectedObjects(0), ABRQueryHeader).Oid)

        If _ABRQueryHeader Is Nothing Then Exit Sub

        _ABRQueryHeader.Save()

        Dim _ABRQueryRows_Collection As New XPCollection(Of ABRQueryRows) _
            (_uow, CriteriaOperator.Parse("ABRQueryHeader=?", _ABRQueryHeader))
        _uow.Delete(_ABRQueryRows_Collection)

        Dim _ABRQueryRowsDetail_Collection As New XPCollection(Of ABRQueryRowsDetail) _
            (_uow, CriteriaOperator.Parse("ABRQueryHeader=?", _ABRQueryHeader))
        _uow.Delete(_ABRQueryRowsDetail_Collection)


        '-- Lekérdezés, adott teljesítési dátumig történõ lekérdezés LINQ paranccsal
        Dim _CustomersFrom_List As New List(Of Guid)()
        For Each _ABRQueryCustomersFrom As ABRQueryCustomersFrom In _ABRQueryHeader.ABRQueryCustomersFrom
            _CustomersFrom_List.Add(_ABRQueryCustomersFrom.CustomersFrom.Oid)
        Next

        Dim PCI As New XPQuery(Of PCIDetail)(_uow)
        Dim query As System.Linq.IQueryable(Of Object)
        If _ABRQueryHeader.ABRQueryDateType = eABRQueryDateType.eFromDateExecution Then
            query = From _PCI In PCI
                    Where _PCI.DateExecution.Date <= _ABRQueryHeader.DateClose.Date And
                                _PCI.Customers IsNot Nothing And
                                _PCI.ConnectInfo IsNot Nothing And
                                _CustomersFrom_List.Contains(_PCI.PCIGroup.CustomersFrom.Oid) And
                                _PCI.PartnerType = _ABRQueryHeader.PartnerType
                    Group _PCI By _PCI.CustomersFrom,
                              _PCI.Customers,
                              _PCI.PartnerType,
                              _PCI.CurrencyName_Account,
                              _PCI.ConnectInfo Into g = Group
                    Order By PartnerType, CurrencyName_Account, CustomersFrom, Customers, ConnectInfo
                    Select New With {Key .CustomersFrom = CustomersFrom,
                                 Key .Customers = Customers,
                                 Key .PartnerType = PartnerType,
                                 Key .ConnectInfo = ConnectInfo,
                                 Key .CurrencyName_Account = CurrencyName_Account,
                                 Key .DocumentNumber = g.Max(Function(inv) inv.DocumentNumber),
                                 Key .RegistryNumber = g.Max(Function(inv) inv.RegistryNumber),
                                 Key .AmountHUF = g.Sum(Function(inv) inv.AmountHUF_Account),
                                  Key .AmountDEV = g.Sum(Function(inv) inv.AmountDEV_Account),
                                 Key .BallanceHUF = g.Sum(Function(inv) inv.BallanceHUF),
                                 Key .BallanceDEV = g.Sum(Function(inv) inv.BallanceDEV),
                                 Key .DatePayment = g.Max(Function(inv) inv.DatePayment_Account),
                                 Key .DateExecution = g.Max(Function(inv) inv.DateExecution_Account)
                                }
        Else
            query = From _PCI In PCI
                    Where If(String.IsNullOrEmpty(_PCI.DateCreated.Date), _PCI.DateExecution.Date, _PCI.DateCreated.Date) <= _ABRQueryHeader.DateClose.Date And
                              _PCI.Customers IsNot Nothing And
                              _PCI.ConnectInfo IsNot Nothing And
                              _CustomersFrom_List.Contains(_PCI.PCIGroup.CustomersFrom.Oid) And
                             _PCI.PartnerType = _ABRQueryHeader.PartnerType
                    Group _PCI By _PCI.CustomersFrom,
                              _PCI.Customers,
                              _PCI.PartnerType,
                              _PCI.CurrencyName_Account,
                              _PCI.ConnectInfo Into g = Group
                    Order By PartnerType, CurrencyName_Account, CustomersFrom, Customers, ConnectInfo
                    Select New With {Key .CustomersFrom = CustomersFrom,
                                 Key .Customers = Customers,
                                 Key .PartnerType = PartnerType,
                                 Key .ConnectInfo = ConnectInfo,
                                 Key .CurrencyName_Account = CurrencyName_Account,
                                 Key .DocumentNumber = g.Max(Function(inv) inv.DocumentNumber),
                                 Key .RegistryNumber = g.Max(Function(inv) inv.RegistryNumber),
                                 Key .AmountHUF = g.Sum(Function(inv) inv.AmountHUF_Account),
                                  Key .AmountDEV = g.Sum(Function(inv) inv.AmountDEV_Account),
                                 Key .BallanceHUF = g.Sum(Function(inv) inv.BallanceHUF),
                                 Key .BallanceDEV = g.Sum(Function(inv) inv.BallanceDEV),
                                 Key .DatePayment = g.Max(Function(inv) inv.DatePayment_Account),
                                 Key .DateExecution = g.Max(Function(inv) inv.DateExecution_Account)
                                }
        End If
        RaiseEvent InitWork(1, 1, query.Count)
        For Each item In query
            Dim _CurrencyName_Account As String = ""
            If item.CurrencyName_Account Is Nothing Then
                _CurrencyName_Account = ""
            Else
                _CurrencyName_Account = item.CurrencyName_Account.ShortName
            End If
            i += 1
            If _CurrencyName_Account = "" Then
                _ABRQueryRowsDetail = New ABRQueryRowsDetail(_uow)
                _ABRQueryRowsDetail.ABRQueryHeader = _ABRQueryHeader
                _ABRQueryRowsDetail.BallanceDEV = Math.Round(item.BallanceDEV, 2, MidpointRounding.AwayFromZero)
                _ABRQueryRowsDetail.BallanceHUF = Math.Round(item.BallanceHUF, 2, MidpointRounding.AwayFromZero)
                _ABRQueryRowsDetail.CustomersFrom = item.CustomersFrom
                _ABRQueryRowsDetail.Customers = item.Customers
                _ABRQueryRowsDetail.PartnerType = item.PartnerType
                _ABRQueryRowsDetail.ConnectInfo = item.ConnectInfo
                _ABRQueryRowsDetail.DocumentNumber = item.DocumentNumber
                _ABRQueryRowsDetail.RegistryNumber = item.RegistryNumber
                _ABRQueryRowsDetail.DateExecution = item.DateExecution.Date
                _ABRQueryRowsDetail.DatePayment = item.DatePayment.Date
                _ABRQueryRowsDetail.AmountHUF = Math.Round(item.AmountHUF, 2, MidpointRounding.AwayFromZero)
                _ABRQueryRowsDetail.AmountDEV = item.AmountDEV
                _ABRQueryRowsDetail.D00_OpenLiquidHUF = item.BallanceHUF
                _ABRQueryRowsDetail.D00_OpenLiquidDEV = item.BallanceDEV

            ElseIf (_CurrencyName_Account = "HUF" And Math.Round(item.BallanceHUF, 0, MidpointRounding.AwayFromZero) <> 0) Or _
                    _CurrencyName_Account <> "HUF" And Math.Round(item.BallanceDEV, 2, MidpointRounding.AwayFromZero) <> 0 Then

                _ABRQueryRowsDetail = New ABRQueryRowsDetail(_uow)
                _ABRQueryRowsDetail.ABRQueryHeader = _ABRQueryHeader
                _ABRQueryRowsDetail.BallanceDEV = item.BallanceDEV
                _ABRQueryRowsDetail.BallanceHUF = item.BallanceHUF
                _ABRQueryRowsDetail.CustomersFrom = item.CustomersFrom
                _ABRQueryRowsDetail.Customers = item.Customers
                _ABRQueryRowsDetail.PartnerType = item.PartnerType
                _ABRQueryRowsDetail.ConnectInfo = item.ConnectInfo
                _ABRQueryRowsDetail.DocumentNumber = item.DocumentNumber
                _ABRQueryRowsDetail.RegistryNumber = item.RegistryNumber
                _ABRQueryRowsDetail.DateExecution = item.DateExecution.Date
                _ABRQueryRowsDetail.DatePayment = item.DatePayment.Date
                _ABRQueryRowsDetail.CurrencyName_Account = item.CurrencyName_Account
                _ABRQueryRowsDetail.AmountHUF = item.AmountHUF
                _ABRQueryRowsDetail.AmountDEV = item.AmountDEV

                If _ABRQueryHeader.DateClose.Date <= GetSQLTime(_ocur.Session).Date Then
                    _DifDay = DateDiff(DateInterval.Day, item.DatePayment.Date, _ABRQueryHeader.DateClose.Date)
                Else
                    _DifDay = DateDiff(DateInterval.Day, item.DatePayment.Date, GetSQLTime(_ocur.Session).Date)
                End If


                _ABRQueryRowsDetail.DelayedDay = _DifDay
                Select Case _DifDay
                    Case Is <= 0
                        _ABRQueryRowsDetail.D01_NotExpiredHUF = item.BallanceHUF
                        _ABRQueryRowsDetail.D01_NotExpiredDEV = item.BallanceDEV
                    Case 1 To 15
                        _ABRQueryRowsDetail.D02_001_015DEV = item.BallanceDEV
                        _ABRQueryRowsDetail.D02_001_015HUF = item.BallanceHUF
                    Case 16 To 30
                        _ABRQueryRowsDetail.D03_016_030DEV = item.BallanceDEV
                        _ABRQueryRowsDetail.D03_016_030HUF = item.BallanceHUF
                    Case 31 To 60
                        _ABRQueryRowsDetail.D04_031_060DEV = item.BallanceDEV
                        _ABRQueryRowsDetail.D04_031_060HUF = item.BallanceHUF
                    Case 61 To 90
                        _ABRQueryRowsDetail.D05_061_090DEV = item.BallanceDEV
                        _ABRQueryRowsDetail.D05_061_090HUF = item.BallanceHUF
                    Case 91 To 150
                        _ABRQueryRowsDetail.D06_091_150DEV = item.BallanceDEV
                        _ABRQueryRowsDetail.D06_091_150HUF = item.BallanceHUF
                    Case 151 To 365
                        _ABRQueryRowsDetail.D07_151_365DEV = item.BallanceDEV
                        _ABRQueryRowsDetail.D07_151_365HUF = item.BallanceHUF
                    Case Is > 365
                        _ABRQueryRowsDetail.D08_OverOneYearDEV = item.BallanceDEV
                        _ABRQueryRowsDetail.D08_OverOneYearHUF = item.BallanceHUF

                End Select
            End If
            If i Mod 1000 Then _uow.CommitChanges()
            RaiseEvent DoWork()
        Next
        _uow.CommitChanges()
        RaiseEvent FinalWork
        i = 0
        Dim PCI2 As New XPQuery(Of ABRQueryRowsDetail)(_uow)
        Dim query2 = From _PCI2 In PCI2
                    Where _PCI2.ABRQueryHeader Is _ABRQueryHeader
                    Group _PCI2 By
                          _PCI2.CustomersFrom, _
                          _PCI2.Customers, _
                          _PCI2.PartnerType, _
                          _PCI2.CurrencyName_Account Into g = Group
                   Order By CustomersFrom, Customers, PartnerType, CurrencyName_Account
                   Select New With {Key .CustomersFrom = CustomersFrom, _
                             Key .Customers = Customers, _
                             Key .PartnerType = PartnerType,
                             Key .CurrencyName_Account = CurrencyName_Account,
                             Key .BallanceDEV = g.Sum(Function(inv) inv.BallanceDEV),
                             Key .BallanceHUF = g.Sum(Function(inv) inv.BallanceHUF),
                             Key .D00_OpenLiquidDEV = g.Sum(Function(inv) inv.D00_OpenLiquidDEV),
                             Key .D00_OpenLiquidHUF = g.Sum(Function(inv) inv.D00_OpenLiquidHUF),
                             Key .D02_001_015DEV = g.Sum(Function(inv) inv.D02_001_015DEV),
                             Key .D02_001_015HUF = g.Sum(Function(inv) inv.D02_001_015HUF),
                             Key .D03_016_030DEV = g.Sum(Function(inv) inv.D03_016_030DEV),
                             Key .D03_016_030HUF = g.Sum(Function(inv) inv.D03_016_030HUF),
                             Key .D04_031_060DEV = g.Sum(Function(inv) inv.D04_031_060DEV),
                             Key .D04_031_060HUF = g.Sum(Function(inv) inv.D04_031_060HUF),
                             Key .D05_061_090DEV = g.Sum(Function(inv) inv.D05_061_090DEV),
                             Key .D05_061_090HUF = g.Sum(Function(inv) inv.D05_061_090HUF),
                             Key .D06_091_150DEV = g.Sum(Function(inv) inv.D06_091_150DEV),
                             Key .D06_091_150HUF = g.Sum(Function(inv) inv.D06_091_150HUF),
                             Key .D07_151_365DEV = g.Sum(Function(inv) inv.D07_151_365DEV),
                             Key .D07_151_365HUF = g.Sum(Function(inv) inv.D07_151_365HUF),
                             Key .D01_NotExpiredHUF = g.Sum(Function(inv) inv.D01_NotExpiredHUF),
                             Key .D01_NotExpiredDEV = g.Sum(Function(inv) inv.D01_NotExpiredDEV),
                             Key .D08_OverOneYearHUF = g.Sum(Function(inv) inv.D08_OverOneYearHUF),
                             Key .D08_OverOneYearDEV = g.Sum(Function(inv) inv.D08_OverOneYearDEV)}
        RaiseEvent InitWork(1, 1, query2.Count)

        For Each item In query2
            i += 1
            RaiseEvent DoWork()
            _ABRQueryRows = New ABRQueryRows(_uow)
            _ABRQueryRows.ABRQueryHeader = _ABRQueryHeader
            _ABRQueryRows.BallanceDEV = item.BallanceDEV
            _ABRQueryRows.BallanceHUF = item.BallanceHUF
            _ABRQueryRows.CurrencyName_Account = item.CurrencyName_Account
            _ABRQueryRows.Customers = item.Customers
            _ABRQueryRows.CustomersFrom = item.CustomersFrom
            _ABRQueryRows.PartnerType = item.PartnerType

            _ABRQueryRows.D00_OpenLiquidDEV = item.D00_OpenLiquidDEV
            _ABRQueryRows.D00_OpenLiquidHUF = item.D00_OpenLiquidHUF

            _ABRQueryRows.D01_NotExpiredDEV = item.D01_NotExpiredDEV
            _ABRQueryRows.D01_NotExpiredHUF = item.D01_NotExpiredHUF

            _ABRQueryRows.D02_001_015DEV = item.D02_001_015DEV
            _ABRQueryRows.D02_001_015HUF = item.D02_001_015HUF

            _ABRQueryRows.D03_016_030DEV = item.D03_016_030DEV
            _ABRQueryRows.D03_016_030HUF = item.D03_016_030HUF

            _ABRQueryRows.D04_031_060DEV = item.D04_031_060DEV
            _ABRQueryRows.D04_031_060HUF = item.D04_031_060HUF

            _ABRQueryRows.D05_061_090DEV = item.D05_061_090DEV
            _ABRQueryRows.D05_061_090HUF = item.D05_061_090HUF

            _ABRQueryRows.D06_091_150DEV = item.D06_091_150DEV
            _ABRQueryRows.D06_091_150HUF = item.D06_091_150HUF

            _ABRQueryRows.D07_151_365DEV = item.D07_151_365DEV
            _ABRQueryRows.D07_151_365HUF = item.D07_151_365HUF

            _ABRQueryRows.D08_OverOneYearDEV = item.D08_OverOneYearDEV
            _ABRQueryRows.D08_OverOneYearHUF = item.D08_OverOneYearHUF

            If i Mod 1000 Then _uow.CommitChanges()
        Next
        _uow.CommitChanges()
        RaiseEvent FinalWork
        If Frame.GetController(Of RefreshController).RefreshAction.Enabled Then
            Frame.GetController(Of RefreshController).RefreshAction.DoExecute()
        End If
    End Sub

    Private Sub aSelectCustomersFromABR_CustomizePopupWindowParams(sender As Object, e As DevExpress.ExpressApp.Actions.CustomizePopupWindowParamsEventArgs) Handles aSelectCustomersFromABR.CustomizePopupWindowParams
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace


        Dim _CS As New CollectionSource(_onew, GetType(CustomersFrom))

        '_CS.BeginUpdateCriteria()
        '_CS.Criteria.Clear()
        '_CS.Criteria("First") = ""
        '_CS.EndUpdateCriteria()

        e.View = Application.CreateListView("CustomersFrom_ListView_Select", _CS, False)
    End Sub

    Private Sub aSelectCustomersFromABR_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.PopupWindowShowActionExecuteEventArgs) Handles aSelectCustomersFromABR.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As New UnitOfWork(_ocur.Session.DataLayer)
        Dim _Customersfrom As CustomersFrom
        Dim _ABRQueryHeader As ABRQueryHeader = TryCast(TryCast(View, ListView).CollectionSource, PropertyCollectionSource).MasterObject
        Dim _ABRQueryCustomersFrom As ABRQueryCustomersFrom

        If _ABRQueryHeader Is Nothing Then Exit Sub

        If e.PopupWindow.View.SelectedObjects.Count > 0 Then

            For Each _Customersfrom In e.PopupWindow.View.SelectedObjects
                _ABRQueryCustomersFrom = New ABRQueryCustomersFrom(_uow)
                _ABRQueryCustomersFrom.ABRQueryHeader = _uow.GetObjectByKey(Of ABRQueryHeader)(_ABRQueryHeader.Oid)
                _ABRQueryCustomersFrom.CustomersFrom = _uow.GetObjectByKey(Of CustomersFrom)(_Customersfrom.Oid)
            Next
            _uow.CommitChanges()
        End If

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

    End Sub

    Private Sub aViewAttachmentsABR_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aViewAttachmentsABR.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _ABRQueryRowsDetail As ABRQueryRowsDetail = TryCast(View.SelectedObjects(0), ABRQueryRowsDetail)

        If _ABRQueryRowsDetail IsNot Nothing Then
            ViewAttachments.ViewAttachments(_ocur, Frame, _ABRQueryRowsDetail.CustomersFrom, _
                                             _ABRQueryRowsDetail.Customers, _ABRQueryRowsDetail.ConnectInfo, _
                                             "")
        End If
    End Sub

    Private Sub aViewRegistryABR_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aViewRegistryABR.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _ABRQueryRowsDetail As ABRQueryRowsDetail = TryCast(View.SelectedObjects(0), ABRQueryRowsDetail)

        If _ABRQueryRowsDetail IsNot Nothing Then
            ViewRegistry.ViewRegistry(_ocur, Application, e, _ABRQueryRowsDetail.CustomersFrom, _
                                      _ABRQueryRowsDetail.Customers, _ABRQueryRowsDetail.ConnectInfo)
        End If
    End Sub

    Private Sub aViewPCIDABR_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aViewPCIDABR.Execute
        Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _ABRQueryRowsDetail As ABRQueryRowsDetail = TryCast(View.SelectedObjects(0), ABRQueryRowsDetail)

        ViewPDCI.ViewPDCIDetail(_onew, Application, e, _ABRQueryRowsDetail.CustomersFrom, _
                          _ABRQueryRowsDetail.Customers, _ABRQueryRowsDetail.PartnerType, _
                          _ABRQueryRowsDetail.ConnectInfo)
    End Sub

    Private Sub aPrintABRReport_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aPrintABRReport.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _ReportData As ReportData
        Dim _ABRQueryHeader As ABRQueryHeader = TryCast(View.SelectedObjects(0), ABRQueryHeader)

        If _ABRQueryHeader IsNot Nothing Then
            _ReportData = _ocur.FindObject(Of ReportData)(CriteriaOperator.Parse("Name=?", "Korosított kinnlévőség Riport"))

            If _ReportData IsNot Nothing Then
                Frame.GetController(Of Reports.ReportServiceController).ShowPreview(_ReportData, CriteriaOperator.Parse("ABRQueryHeader=?", _ABRQueryHeader), True)
            Else
                Throw New UserFriendlyException("Nincs beállítva a Korosított kinnlévőség Riport nyomtatvány !")
            End If
        End If
    End Sub

    Private Sub aPCICheck_ABRReport_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aPCICheck_ABRReport.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As New UnitOfWork(_ocur.Session.DataLayer)
        Dim _ABRQueryRowsDetail As ABRQueryRowsDetail

        RaiseEvent InitWork(1, 1, View.SelectedObjects.Count)
        For Each _ABRQueryRowsDetail In View.SelectedObjects
            RaiseEvent DoWork()
            GLFunctions.ReconfigurePCI(_uow, _ABRQueryRowsDetail.CustomersFrom, _ABRQueryRowsDetail.Customers, _ABRQueryRowsDetail.PartnerType, _ABRQueryRowsDetail.ConnectInfo)

        Next
        RaiseEvent FinalWork
    End Sub

    Private Sub aViewPCIDABR_GLDetails_Execute(sender As Object, e As SimpleActionExecuteEventArgs) Handles aViewPCIDABR_GLDetails.Execute
        Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _ABRQueryRowsDetail As ABRQueryRowsDetail = TryCast(View.SelectedObjects(0), ABRQueryRowsDetail)

        ViewPDCI.ViewGLDetails(_onew, Application, e, _ABRQueryRowsDetail.CustomersFrom, _
                          _ABRQueryRowsDetail.Customers, _ABRQueryRowsDetail.PartnerType, _
                          _ABRQueryRowsDetail.ConnectInfo)
    End Sub
End Class
