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.XtraPivotGrid
Imports DevExpress.ExpressApp.PivotGrid.Win
Imports DevExpress.Data.Filtering
Imports SISBusiness.Module
Imports DevExpress.ExpressApp.SystemModule
Imports System.IO
Imports DevExpress.Xpo
Imports DevExpress.Persistent.BaseImpl
Imports DevExpress.ExpressApp.Editors
Imports DevExpress.ExpressApp.ViewVariantsModule
Imports DevExpress.ExpressApp.Win.Editors
Imports DevExpress.XtraGrid

Public Class GLReportRowsVC
    Inherits DevExpress.ExpressApp.ViewController
    Private _PivotGridListEditor As PivotGridListEditor
    Private _PivotGrdidControl As PivotGridControl
    Private _GridListEditor As GridListEditor
    Private _GridControl As GridControl
    Private _Criteria As String = ""
    Dim _WaitFormClass As New WaitFormClass
    Private _MasterKey As Guid
    Private _VariantSelectedItemID As String = ""
    Public Sub New()
        MyBase.New()

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

    End Sub
    Protected Overrides Sub OnActivated()
        MyBase.OnActivated()
        If View.Id Like "GLReport_DetailView" Then
            Dim _GLReport As GLReport = TryCast(View.SelectedObjects(0), GLReport)
            If _GLReport IsNot Nothing Then
                _MasterKey = _GLReport.Oid
            End If
            AddHandler Frame.GetController(Of ModificationsController).SaveAction.Executing, AddressOf Save_Executing
            AddHandler Frame.GetController(Of ModificationsController).SaveAndCloseAction.Executing, AddressOf Save_Executing
            AddHandler Frame.GetController(Of ModificationsController).SaveAndNewAction.Executing, AddressOf Save_Executing

            AddHandler View.ControlsCreated, AddressOf GLReport_DetailView_ControlCreated
        End If
        If View.Id Like "GLReport_GLReportRows*" Then
            AddHandler View.ControlsCreated, AddressOf ListView_ControlsCreated
        End If
    End Sub
    Protected Overrides Sub OnViewControlsCreated()
        MyBase.OnViewControlsCreated()
        
    End Sub
    Private Sub GLReport_DetailView_ControlCreated(sender As Object, e As EventArgs)
        
    End Sub
    Protected Overrides Sub OnDeactivated()
        MyBase.OnDeactivated()
        If _PivotGrdidControl IsNot Nothing Then
            RemoveHandler _PivotGrdidControl.CellClick, AddressOf PivotGrdidControl_CellClick
        End If

    End Sub

    Private Sub ListView_ControlsCreated(sender As Object, e As EventArgs)
        Dim _PropertyCollectionSource As PropertyCollectionSource = TryCast(TryCast(View, ListView).CollectionSource, PropertyCollectionSource)
        If _PropertyCollectionSource IsNot Nothing Then
            _MasterKey = _PropertyCollectionSource.MasterObject.oid
        End If

        _PivotGridListEditor = TryCast(TryCast(View, ListView).Editor, PivotGridListEditor)

        If _PivotGridListEditor IsNot Nothing Then
            _PivotGrdidControl = _PivotGridListEditor.PivotGridControl
            AddHandler _PivotGrdidControl.CellClick, AddressOf PivotGrdidControl_CellClick
        End If
    End Sub

    Private Sub aViewPivotDetail_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aViewPivotDetail.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
        Dim _CS As CollectionSource = New CollectionSource(_onew, GetType(GLReportRows))
        Dim _GLReport As GLReport = Nothing

        If TryCast(TryCast(View, ListView).CollectionSource, PropertyCollectionSource) IsNot Nothing Then
            _GLReport = TryCast(TryCast(TryCast(View, ListView).CollectionSource, PropertyCollectionSource).MasterObject, GLReport)
        Else
            If TryCast(View, ListView).CollectionSource.List.Count > 0 Then
                _GLReport = TryCast(TryCast(View, ListView).CollectionSource.List(0), GLReportRows).GLReport
            End If
        End If


        If LTrim(RTrim(_Criteria <> "")) Then
            _CS.BeginUpdateCriteria()
            _CS.Criteria("MasterFilter") = CriteriaOperator.Parse("GLReport.Oid=?", _GLReport.Oid)
            _CS.Criteria("DetailFilter") = CriteriaOperator.Parse(_Criteria)
            _CS.EndUpdateCriteria()

            e.ShowViewParameters.CreatedView = Application.CreateListView("GLReportRows_ListView_PivotDetail", _CS, True)

        End If
    End Sub
    Private Sub aViewPivotDetail_2_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aViewPivotDetail_2.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
        Dim _CS As CollectionSource = New CollectionSource(_onew, GetType(GLReportRows))
        Dim _GLReport As GLReport = Nothing

        If TryCast(TryCast(View, ListView).CollectionSource, PropertyCollectionSource) IsNot Nothing Then
            _GLReport = TryCast(TryCast(TryCast(View, ListView).CollectionSource, PropertyCollectionSource).MasterObject, GLReport)
        Else
            If TryCast(View, ListView).CollectionSource.List.Count > 0 Then
                _GLReport = TryCast(TryCast(View, ListView).CollectionSource.List(0), GLReportRows).GLReport
            End If
        End If

        If _GLReport Is Nothing Then Exit Sub

        If LTrim(RTrim(_Criteria <> "")) Then
            _CS.BeginUpdateCriteria()
            _CS.Criteria("MasterFilter") = CriteriaOperator.Parse("GLReport.Oid=?", _GLReport.Oid)
            _CS.Criteria("DetailFilter") = CriteriaOperator.Parse(_Criteria)
            _CS.EndUpdateCriteria()

            e.ShowViewParameters.CreatedView = Application.CreateListView("GLReportRows_ListView_PivotDetail_2", _CS, True)

        End If
    End Sub

    Private Sub PivotGrdidControl_CellClick(sender As Object, e As PivotCellEventArgs)
        Dim _RowPivotGridField As PivotGridField
        Dim _ColumnPivotGridField As PivotGridField
        Dim s As String
        If e.RowValueType = PivotGridValueType.Value Then
            If e.ColumnValueType = PivotGridValueType.Value Then
                _Criteria = ""
                For Each _RowPivotGridField In e.GetRowFields
                    s = CStr(_PivotGrdidControl.GetFieldValue(_RowPivotGridField, e.RowIndex))
                    If LTrim(RTrim(s)) <> "" Then
                        If _Criteria = "" Then
                            _Criteria = _RowPivotGridField.ExpressionFieldName.ToString & "='"
                            _Criteria = _Criteria & s & "'" & Chr(13) & Chr(10)
                        Else
                            _Criteria = _Criteria & " and " & _RowPivotGridField.ExpressionFieldName.ToString & "='"
                            _Criteria = _Criteria & s & "'" & Chr(13) & Chr(10)
                        End If
                    End If
                Next

                For Each _ColumnPivotGridField In e.GetColumnFields
                    s = CStr(_PivotGrdidControl.GetFieldValue(_ColumnPivotGridField, e.ColumnIndex))
                    If LTrim(RTrim(s)) <> "" Then
                        If _Criteria = "" Then
                            _Criteria = _ColumnPivotGridField.ExpressionFieldName.ToString & "='"
                            _Criteria = _Criteria & s & "'" & Chr(13) & Chr(10)
                        Else
                            _Criteria = _Criteria & " and " & _ColumnPivotGridField.ExpressionFieldName.ToString & "='"
                            _Criteria = _Criteria & s & "'" & Chr(13) & Chr(10)
                        End If
                    End If
                Next
            ElseIf e.ColumnValueType = PivotGridValueType.GrandTotal Then
                _Criteria = ""
                For Each _RowPivotGridField In e.GetRowFields
                    s = CStr(_PivotGrdidControl.GetFieldValue(_RowPivotGridField, e.RowIndex))
                    If LTrim(RTrim(s)) <> "" Then
                        If _Criteria = "" Then
                            _Criteria = _RowPivotGridField.ExpressionFieldName.ToString & "='"
                            _Criteria = _Criteria & s & "'" & Chr(13) & Chr(10)
                        Else
                            _Criteria = _Criteria & " and " & _RowPivotGridField.ExpressionFieldName.ToString & "='"
                            _Criteria = _Criteria & s & "'" & Chr(13) & Chr(10)
                        End If
                    End If
                Next

                For Each _ColumnPivotGridField In e.GetColumnFields
                    s = CStr(_PivotGrdidControl.GetFieldValue(_ColumnPivotGridField, e.ColumnIndex))
                    If LTrim(RTrim(s)) <> "" Then
                        If _Criteria = "" Then
                            _Criteria = _ColumnPivotGridField.ExpressionFieldName.ToString & "='"
                            _Criteria = _Criteria & s & "'" & Chr(13) & Chr(10)
                        Else
                            _Criteria = _Criteria & " and " & _ColumnPivotGridField.ExpressionFieldName.ToString & "='"
                            _Criteria = _Criteria & s & "'" & Chr(13) & Chr(10)
                        End If
                    End If
                Next
            End If
        End If
    End Sub

    Private Sub aViewRegistry_GLReportRows_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aViewRegistry_GLReportRows.Execute
        Dim _GLReportRows As GLReportRows = TryCast(View.SelectedObjects(0), GLReportRows)
        Dim _CustomersFrom As CustomersFrom = _GLReportRows.GLReport.CustomersFrom
        Dim _Customers As Customers = _GLReportRows.Customers
        Dim _DocumentNumber As String = _GLReportRows.ConnectInfo
        ViewRegistry.ViewRegistry(View.ObjectSpace, Application, e, _CustomersFrom, _Customers, _DocumentNumber)
    End Sub
    Private Sub aViewAttacments_GLReportRows_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aViewAttacments_GLReportRows.Execute
        Dim _GLReportRows As GLReportRows = TryCast(View.SelectedObjects(0), GLReportRows)
        Dim _CustomersFrom As CustomersFrom = _GLReportRows.GLReport.CustomersFrom
        Dim _Customers As Customers = _GLReportRows.Customers
        Dim _DocumentNumber As String = _GLReportRows.ConnectInfo

        Dim _GLMixed As GLMixed = Nothing

        If _GLReportRows.GLRows IsNot Nothing Then
            _GLMixed = TryCast(_GLReportRows.GLRows.GLHeader, GLMixed)
        End If

        ViewAttachments.ViewAttachments(View.ObjectSpace, Frame, _CustomersFrom, _Customers, _DocumentNumber, "", _GLMixed)
    End Sub

    Private Sub aGLReportRows_ChangeParam_CustomizePopupWindowParams(sender As Object, e As DevExpress.ExpressApp.Actions.CustomizePopupWindowParamsEventArgs) Handles aGLReportRows_ChangeParam.CustomizePopupWindowParams
        Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
        Dim _GLRowsCheck As GLRowsCheck = _onew.CreateObject(Of GLRowsCheck)()
        Dim _GLReportRows As GLReportRows = TryCast(View.SelectedObjects(0), GLReportRows)

        If _GLReportRows IsNot Nothing Then
            If _GLReportRows.GLRows IsNot Nothing Then
                _GLRowsCheck.ChartOfAccountsYear = _onew.FindObject(Of ChartOfAccountsYear)(CriteriaOperator.Parse("AccountYear=?", _GLReportRows.GLRows.GLHeader.DateExecution.Year))
            Else
                _GLRowsCheck.ChartOfAccountsYear = _onew.FindObject(Of ChartOfAccountsYear)(CriteriaOperator.Parse("AccountYear=?", GetSQLTime(_onew.Session).Year))
            End If
        Else
            _GLRowsCheck.ChartOfAccountsYear = _onew.FindObject(Of ChartOfAccountsYear)(CriteriaOperator.Parse("AccountYear=?", GetSQLTime(_onew.Session).Year))
        End If

        e.View = Application.CreateDetailView(_onew, "GLRowsCheck_DetailView", False, _GLRowsCheck)
    End Sub
    Private Sub aGLReportRows_ChangeParam_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.PopupWindowShowActionExecuteEventArgs) Handles aGLReportRows_ChangeParam.Execute
        Frame.GetController(Of DevExpress.ExpressApp.Validation.PersistenceValidationController)().Active.SetItemValue("", False)

        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _GLRowsCheck As GLRowsCheck = TryCast(e.PopupWindow.View.SelectedObjects(0), GLRowsCheck)
        Dim _GLRows As GLRows
        Dim _InvoiceRows As InvoiceRows
        Dim _RegistryRowsFinancialControlling As RegistryRowsFinancialControlling
        Dim _GLReportRows As GLReportRows
        Dim I As Long = 0
        Dim _Controlling As Controlling
        Dim _JobNumberObjects As JobNumberObjects
        Dim _CostHolder As CostHolder
        Dim _CostPlace As CostPlace
        Dim _UniqueObjects As UniqueObjects
        Dim _DebitChartOfAccounts As ChartOfAccounts
        Dim _CreditChartOfAccounts As ChartOfAccounts

        If _GLRowsCheck.Controlling IsNot Nothing Then
            _Controlling = _ocur.FindObject(Of Controlling)(CriteriaOperator.Parse("Oid=?", _GLRowsCheck.Controlling.Oid), True)
            If _Controlling.Children.Count > 0 Then
                Throw New Exception(String.Format("Nem gyermekobjektum. <<{0}>> Csak gyermekobjektum választható ki !", _Controlling.Name))
                Exit Sub
            End If
        Else
            _Controlling = Nothing
        End If
        If _GLRowsCheck.JobNumberObjects IsNot Nothing Then
            _JobNumberObjects = _ocur.FindObject(Of JobNumberObjects)(CriteriaOperator.Parse("Oid=?", _GLRowsCheck.JobNumberObjects.Oid), True)
        Else
            _JobNumberObjects = Nothing
        End If
        If _GLRowsCheck.CostHolder IsNot Nothing Then
            _CostHolder = _ocur.FindObject(Of CostHolder)(CriteriaOperator.Parse("Oid=?", _GLRowsCheck.CostHolder.Oid), True)
        Else
            _CostHolder = Nothing
        End If
        If _GLRowsCheck.CostPlace IsNot Nothing Then
            _CostPlace = _ocur.FindObject(Of CostPlace)(CriteriaOperator.Parse("Oid=?", _GLRowsCheck.CostPlace.Oid), True)
        Else
            _CostPlace = Nothing
        End If
        If _GLRowsCheck.UniqueObjects IsNot Nothing Then
            _UniqueObjects = _ocur.FindObject(Of UniqueObjects)(CriteriaOperator.Parse("Oid=?", _GLRowsCheck.UniqueObjects.Oid), True)
        Else
            _UniqueObjects = Nothing
        End If
        If _GLRowsCheck.DebitChartOfAccounts IsNot Nothing Then
            _DebitChartOfAccounts = _ocur.FindObject(Of ChartOfAccounts)(CriteriaOperator.Parse("Oid=?", _GLRowsCheck.DebitChartOfAccounts.Oid), True)
        Else
            _DebitChartOfAccounts = Nothing
        End If
        If _GLRowsCheck.CreditChartOfAccounts IsNot Nothing Then
            _CreditChartOfAccounts = _ocur.FindObject(Of ChartOfAccounts)(CriteriaOperator.Parse("Oid=?", _GLRowsCheck.CreditChartOfAccounts.Oid), True)
        Else
            _CreditChartOfAccounts = Nothing
        End If

        If _DebitChartOfAccounts IsNot Nothing And _CreditChartOfAccounts IsNot Nothing Then
            If _DebitChartOfAccounts.Oid = _CreditChartOfAccounts.Oid Then
                Throw New Exception("*A tartozik és a követel számlaszám NEM lehet azonos !")
                Exit Sub
            End If
        End If

        _WaitFormClass.Initwork(1, 1, View.SelectedObjects.Count)
        For Each _GLReportRows In View.SelectedObjects
            I += 1
            _WaitFormClass.DoWork()
            _GLRows = _GLReportRows.GLRows
            If _GLRows IsNot Nothing Then
                If _Controlling IsNot Nothing Then _GLRows.Controlling = _Controlling
                If _JobNumberObjects IsNot Nothing Then _GLRows.JobNumberObjects = _JobNumberObjects
                If _CostHolder IsNot Nothing Then _GLRows.CostHolder = _CostHolder
                If _CostPlace IsNot Nothing Then _GLRows.CostPlace = _CostPlace
                If _UniqueObjects IsNot Nothing Then _GLRows.UniqueObjects = _UniqueObjects
                If _DebitChartOfAccounts IsNot Nothing Then _GLRows.DebitChartOfAccounts = _DebitChartOfAccounts
                If _CreditChartOfAccounts IsNot Nothing Then _GLRows.CreditChartOfAccounts = _CreditChartOfAccounts
                If _GLRowsCheck.IsDateExecution = True Then _GLRows.DateExecution = _GLRowsCheck.DateExecution
                _GLRows.Save()

                _GLReportRows.Controlling = _GLRows.Controlling
                _GLReportRows.JobNumberObjects = _GLRows.JobNumberObjects
                _GLReportRows.CostHolder = _GLRows.CostHolder
                _GLReportRows.CostPlace = _GLRows.CostPlace
                _GLReportRows.UniqueObjects = _GLRows.UniqueObjects
                _GLReportRows.Save()
            End If
            _InvoiceRows = _GLReportRows.InvoiceRows
            If _InvoiceRows IsNot Nothing Then
                If _Controlling IsNot Nothing Then _InvoiceRows.Controlling = _Controlling
                If _JobNumberObjects IsNot Nothing Then _InvoiceRows.JobNumberObjects = _JobNumberObjects
                If _CostHolder IsNot Nothing Then _InvoiceRows.CostHolder = _CostHolder
                If _CostPlace IsNot Nothing Then _InvoiceRows.CostPlace = _CostPlace
                If _UniqueObjects IsNot Nothing Then _InvoiceRows.UniqueObjects = _UniqueObjects
                If _GLRowsCheck.IsDateExecution = True Then _InvoiceRows.DateExecution = _GLRowsCheck.DateExecution
                _InvoiceRows.Save()

                _GLReportRows.Controlling = _InvoiceRows.Controlling
                _GLReportRows.JobNumberObjects = _InvoiceRows.JobNumberObjects
                _GLReportRows.CostHolder = _InvoiceRows.CostHolder
                _GLReportRows.CostPlace = _InvoiceRows.CostPlace
                _GLReportRows.UniqueObjects = _InvoiceRows.UniqueObjects
                _GLReportRows.Save()
            End If
            _RegistryRowsFinancialControlling = _GLReportRows.RegistryRowsFinancialControlling
            If _RegistryRowsFinancialControlling IsNot Nothing Then
                If _Controlling IsNot Nothing Then _RegistryRowsFinancialControlling.Controlling = _Controlling
                If _JobNumberObjects IsNot Nothing Then _RegistryRowsFinancialControlling.JobNumberObjects = _JobNumberObjects
                If _CostHolder IsNot Nothing Then _RegistryRowsFinancialControlling.CostHolder = _CostHolder
                If _CostPlace IsNot Nothing Then _RegistryRowsFinancialControlling.CostPlace = _CostPlace
                If _UniqueObjects IsNot Nothing Then _RegistryRowsFinancialControlling.UniqueObjects = _UniqueObjects
                If _GLRowsCheck.IsDateExecution = True Then _RegistryRowsFinancialControlling.DateExecution = _GLRowsCheck.DateExecution

                _RegistryRowsFinancialControlling.Save()

                _GLReportRows.Controlling = _RegistryRowsFinancialControlling.Controlling
                _GLReportRows.JobNumberObjects = _RegistryRowsFinancialControlling.JobNumberObjects
                _GLReportRows.CostHolder = _RegistryRowsFinancialControlling.CostHolder
                _GLReportRows.CostPlace = _RegistryRowsFinancialControlling.CostPlace
                _GLReportRows.UniqueObjects = _RegistryRowsFinancialControlling.UniqueObjects
                _GLReportRows.Save()
            End If

            If I Mod 100 = 0 Then _ocur.CommitChanges()
        Next
        _ocur.CommitChanges()
        _Waitformclass.FinalWork()

        Frame.GetController(Of DevExpress.ExpressApp.Validation.PersistenceValidationController)().Active.SetItemValue("", True)

        View.Refresh()
    End Sub

    

    Private Sub aGLReportRows_DivideRows_CustomizePopupWindowParams(sender As Object, e As DevExpress.ExpressApp.Actions.CustomizePopupWindowParamsEventArgs) Handles aGLReportRows_DivideRows.CustomizePopupWindowParams
        Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
        Dim _GLRowsDivideH As GLRowsDivideH = _onew.CreateObject(Of GLRowsDivideH)()
        Dim _GLReportRows As GLReportRows = TryCast(View.SelectedObjects(0), GLReportRows)

        If _GLReportRows Is Nothing Then Exit Sub

        Dim _GLRows As GLRows = _GLReportRows.GLRows

        If _GLRows IsNot Nothing Then
            If _GLRows.PartnerType = ePartnerType.ePayabels Or _GLRows.PartnerType = ePartnerType.eReceivables Then
                _GLRowsDivideH.GLRows_Oid = _GLRows.Oid
                _GLRowsDivideH.row_Customers = _onew.GetObject(_GLRows.Customer)
                _GLRowsDivideH.row_PartnerType = _GLRows.PartnerType
                e.View = Application.CreateDetailView(_onew, "GLRowsDivideH_DetailView_ConnectionDivide", False, _GLRowsDivideH)
            Else
                _GLRowsDivideH.GLRows_Oid = _GLRows.Oid
                _GLRowsDivideH.row_PartnerType = ePartnerType.eNotSet
                e.View = Application.CreateDetailView(_onew, "GLRowsDivideH_DetailView", False, _GLRowsDivideH)
            End If

        End If
    End Sub
    Private Sub aGLReportRows_DivideRows_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.PopupWindowShowActionExecuteEventArgs) Handles aGLReportRows_DivideRows.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _GLReportRows As GLReportRows = TryCast(View.SelectedObjects(0), GLReportRows)

        If _GLReportRows Is Nothing Then Exit Sub

        Dim _GLRows As GLRows = _GLReportRows.GLRows

        Dim _GLRowsDivideH As GLRowsDivideH = TryCast(e.PopupWindow.View.SelectedObjects(0), GLRowsDivideH)

        If _GLRows IsNot Nothing Then

            _GLRows.DivideRows(_ocur, _GLRows, _GLRowsDivideH, True)

        End If
    End Sub

    Private Sub aViewPCID_GLReportRows_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aViewPCID_GLReportRows.Execute
        Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _GLReportRows As GLReportRows = TryCast(View.SelectedObjects(0), GLReportRows)

        If _GLReportRows IsNot Nothing Then
            If _GLReportRows.GLRows IsNot Nothing Then
                ViewPDCI.ViewPDCIDetail(_onew, Application, e, _GLReportRows.GLRows.GLHeader.CustomersFrom, _
                          _GLReportRows.Customers, _GLReportRows.GLRows.PartnerType, _
                          _GLReportRows.ConnectInfo)
            End If
            If _GLReportRows.InvoiceHeader IsNot Nothing Then
                ViewPDCI.ViewPDCIDetail(_onew, Application, e, _GLReportRows.InvoiceHeader.CustomersFrom, _
                          _GLReportRows.Customers, 0, _
                          _GLReportRows.ConnectInfo)
            End If
            If _GLReportRows.RegistryHeader IsNot Nothing Then
                ViewPDCI.ViewPDCIDetail(_onew, Application, e, _GLReportRows.RegistryHeader.CustomersFrom, _
                          _GLReportRows.Customers, 1, _
                          _GLReportRows.ConnectInfo)
            End If
        End If

    End Sub

    Private Sub aViewPivotDetail_3_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aViewPivotDetail_3.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
        Dim _CS As CollectionSource = New CollectionSource(_onew, GetType(GLReportRowsCostHolder))
        Dim _GLReport As GLReport = Nothing

        If TryCast(TryCast(View, ListView).CollectionSource, PropertyCollectionSource) IsNot Nothing Then
            _GLReport = TryCast(TryCast(TryCast(View, ListView).CollectionSource, PropertyCollectionSource).MasterObject, GLReport)
        Else
            If TryCast(View, ListView).CollectionSource.List.Count > 0 Then
                _GLReport = TryCast(TryCast(View, ListView).CollectionSource.List(0), GLReportRowsCostHolder).GLReport
            End If
        End If

        If _GLReport Is Nothing Then Exit Sub

        If LTrim(RTrim(_Criteria <> "")) Then
            _CS.BeginUpdateCriteria()
            _CS.Criteria("MasterFilter") = CriteriaOperator.Parse("GLReport.Oid=?", _GLReport.Oid)
            _CS.Criteria("DetailFilter") = CriteriaOperator.Parse(_Criteria)
            _CS.EndUpdateCriteria()

            e.ShowViewParameters.CreatedView = Application.CreateListView("GLReportRowsCostHolder_ListView_PivotDetail", _CS, True)

        End If
    End Sub

    Private Sub aViewRegistry_GLReportRowsCostHolderCostHolder_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aViewRegistry_GLReportRowsCostHolder.Execute
        Dim _GLReportRowsCostHolder As GLReportRowsCostHolder = TryCast(View.SelectedObjects(0), GLReportRowsCostHolder)
        Dim _CustomersFrom As CustomersFrom = _GLReportRowsCostHolder.GLReport.CustomersFrom
        Dim _Customers As Customers = _GLReportRowsCostHolder.GLReportRows.Customers
        Dim _DocumentNumber As String = _GLReportRowsCostHolder.GLReportRows.ConnectInfo
        ViewRegistry.ViewRegistry(View.ObjectSpace, Application, e, _CustomersFrom, _Customers, _DocumentNumber)
    End Sub
    Private Sub aViewAttacments_GLReportRowsCostHolderCostHolder_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aViewAttacments_GLReportRowsCostHolder.Execute
        Dim _GLReportRowsCostHolder As GLReportRowsCostHolder = TryCast(View.SelectedObjects(0), GLReportRowsCostHolder)
        Dim _CustomersFrom As CustomersFrom = _GLReportRowsCostHolder.GLReport.CustomersFrom
        Dim _Customers As Customers = _GLReportRowsCostHolder.GLReportRows.Customers
        Dim _DocumentNumber As String = _GLReportRowsCostHolder.GLReportRows.ConnectInfo
        Dim _GLMixed As GLMixed = Nothing

        If _GLReportRowsCostHolder.GLReportRows.GLRows IsNot Nothing Then
            _GLMixed = TryCast(_GLReportRowsCostHolder.GLReportRows.GLRows.GLHeader, GLMixed)
        End If

        ViewAttachments.ViewAttachments(View.ObjectSpace, Frame, _CustomersFrom, _Customers, _DocumentNumber, "", _GLMixed)
    End Sub
    Private Sub aViewPCID_GLReportRowsCostHolder_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aViewPCID_GLReportRowsCostHolder.Execute
        Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _GLReportRows As GLReportRows = TryCast(View.SelectedObjects(0), GLReportRowsCostHolder).GLReportRows

        If _GLReportRows IsNot Nothing Then
            If _GLReportRows.GLRows IsNot Nothing Then
                ViewPDCI.ViewPDCIDetail(_onew, Application, e, _GLReportRows.GLReport.CustomersFrom, _
                          _GLReportRows.Customers, _GLReportRows.GLRows.PartnerType, _
                          _GLReportRows.ConnectInfo)
            End If
            If _GLReportRows.InvoiceHeader IsNot Nothing Then
                ViewPDCI.ViewPDCIDetail(_onew, Application, e, _GLReportRows.GLReport.CustomersFrom, _
                          _GLReportRows.Customers, 0, _
                          _GLReportRows.ConnectInfo)
            End If
            If _GLReportRows.RegistryHeader IsNot Nothing Then
                ViewPDCI.ViewPDCIDetail(_onew, Application, e, _GLReportRows.GLReport.CustomersFrom, _
                          _GLReportRows.Customers, 1, _
                          _GLReportRows.ConnectInfo)
            End If
        End If
    End Sub

    Private Sub aDivide_GLReportRowsCostHolder_CustomizePopupWindowParams(sender As Object, e As DevExpress.ExpressApp.Actions.CustomizePopupWindowParamsEventArgs) Handles aDivide_GLReportRowsCostHolder.CustomizePopupWindowParams
        '// Sorbontás vezetői ellenőrzésen !
        Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
        Dim _GLRowsDivide As GLRowsDivide = _onew.CreateObject(Of GLRowsDivide)()
        Dim _GLReportRowsCostHolder As GLReportRowsCostHolder = TryCast(View.SelectedObjects(0), GLReportRowsCostHolder)

        If _GLReportRowsCostHolder.GLReportRows.RegistryRowsFinancialControlling IsNot Nothing Then
            _GLRowsDivide.AmountHUF = _GLReportRowsCostHolder.GLReportRows.RegistryRowsFinancialControlling.Amount
        ElseIf _GLReportRowsCostHolder.GLReportRows.GLRows IsNot Nothing Then
            Select Case _GLReportRowsCostHolder.GLReportRows.GLRows.GLHeader.GLDocumentType
                Case eGLDocumentType.eGLAccount
                Case eGLDocumentType.eGLBank, eGLDocumentType.eGLCassa, eGLDocumentType.eGLCompensation, eGLDocumentType.eGLMixed
            End Select
        End If
        e.View = Application.CreateDetailView(_onew, "GLRowsDivide_DetailView", False, _GLRowsDivide)
    End Sub
    Private Sub aDivide_GLReportRowsCostHolder_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.PopupWindowShowActionExecuteEventArgs) Handles aDivide_GLReportRowsCostHolder.Execute
        '// Sorbontás vezetői ellenőrzéshez
    End Sub

    Private Sub Save_Executing(sender As Object, e As CancelEventArgs)
        'Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        If View.Id Like "GLReport_DetailView" Then
            Dim _GLReport As GLReport = TryCast(View.SelectedObjects(0), GLReport)
            If _GLReport IsNot Nothing Then

                Dim _ListPropertyEditor As ListPropertyEditor = TryCast(View, DetailView).FindItem("GLReportRows")

                If _ListPropertyEditor IsNot Nothing Then
                    _GLReport.VariantSelectedItemID = _ListPropertyEditor.ListView.Id
                End If

                
            End If
        End If
    End Sub

    

End Class
