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.Win
Imports DevExpress.ExpressApp.Win.Editors
Imports DevExpress.Data.Filtering

Public Class ContractRowsVC
    Inherits SISBusiness.Module.ContractRowsVC
    Dim _WaitFormClass As New WaitFormClass
    '###################################################################################################################################
    '############################Ez a controller a ContractRows típusra van irányítva!##################################################
    '###################################################################################################################################
    Public Sub New()
        MyBase.New()

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

    End Sub
    Protected Overrides Sub OnActivated()
        MyBase.OnActivated()

        AddHandler DoWork, AddressOf _WaitFormClass.DoWork
        AddHandler InitWork, AddressOf _WaitFormClass.Initwork
        AddHandler FinalWork, AddressOf _WaitFormClass.Finalwork

    End Sub
    Protected Overrides Sub OnDeactivated()
        MyBase.OnDeactivated()
        RemoveHandler DoWork, AddressOf _WaitFormClass.DoWork
        RemoveHandler InitWork, AddressOf _WaitFormClass.Initwork
        RemoveHandler FinalWork, AddressOf _WaitFormClass.Finalwork
    End Sub
    Protected Overrides Sub OnViewControlsCreated()
        MyBase.OnViewControlsCreated()

        If TryCast(View, DetailView) IsNot Nothing Then
            '-- a controlling lookupeditorjának elkapása a registryrowsfinancialcontrolling_detailview-n, hogy meg lehessen szûrni a lookuplistview-t (csak kiadás vagy nem beállított jöhet fel)
            Dim _ControllingLookupEditor As PropertyEditor = TryCast(View, DetailView).FindItem("Controlling")
            AddHandler TryCast(_ControllingLookupEditor, LookupPropertyEditor).Control.Popup, AddressOf lookuppropertyeditor_popup
        End If
    End Sub
    Private Sub lookuppropertyeditor_popup(sender As Object, e As EventArgs)
        TryCast(sender, LookupEdit).PopupForm.ListView.CollectionSource.Criteria.Remove("ControllingFilter")
        If TryCast(View.SelectedObjects(0), ContractRows).Contracts.ContractTemplate.PartnerType = ePartnerType.eReceivables Then
            TryCast(sender, LookupEdit).PopupForm.ListView.CollectionSource.Criteria.Add("ControllingFilter", CriteriaOperator.Parse("Controllingdirection In (0, -1)"))
        Else
            TryCast(sender, LookupEdit).PopupForm.ListView.CollectionSource.Criteria.Add("ControllingFilter", CriteriaOperator.Parse("Controllingdirection In (1, -1)"))
        End If
    End Sub
End Class
