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.SystemModule
Imports DevExpress.ExpressApp.Editors

Public Class CustomersBankAccountsLookupVC
    Inherits ViewController
    Public Sub New()
        TargetObjectType = GetType(CustomerBankAccounts)
        TargetViewType = ViewType.ListView
        TargetViewId = "CustomerBankAccounts_LookupListView"
    End Sub
    Protected Overrides Sub OnActivated()
        MyBase.OnActivated()
        Dim c As NewObjectViewController = Frame.GetController(Of NewObjectViewController)()
        AddHandler c.ObjectCreated, AddressOf c_ObjectCreated
    End Sub

    Private Sub c_ObjectCreated(ByVal sender As Object, ByVal e As ObjectCreatedEventArgs)
        If TypeOf Frame Is NestedFrame Then
            'for ASP.NET
            Dim editor As PropertyEditor = TryCast((CType(Frame, NestedFrame)).ViewItem, PropertyEditor)
            SetupNewObjectFromParent(e, editor)
        End If
        'for WinForms
        Dim controller As LinkToLookupViewController = Frame.GetController(Of LinkToLookupViewController)()
        If controller IsNot Nothing AndAlso controller.Lookup IsNot Nothing Then
            SetupNewObjectFromParent(e, controller.Lookup)
        End If
    End Sub
    Private Sub SetupNewObjectFromParent(ByVal e As ObjectCreatedEventArgs, ByVal editor As PropertyEditor)
        '/// ITT KELL NEVESÍTENI !!!

        If GetType(CustomerBankAccounts).IsInstanceOfType(e.CreatedObject) Then
            If editor IsNot Nothing Then
                If GetType(RegistryHeader).IsAssignableFrom(editor.ObjectType) Then
                    Dim _RegistryHeader As RegistryHeader = DirectCast(editor.CurrentObject, RegistryHeader)
                    If Not editor.View.ObjectSpace.IsNewObject(_RegistryHeader.Customers) Then
                        CType(e.CreatedObject, CustomerBankAccounts).Customers = e.ObjectSpace.GetObject(Of Customers)(_RegistryHeader.Customers)
                    End If
                End If
                If GetType(GLAccounts).IsAssignableFrom(editor.ObjectType) Then
                    Dim _GLAccounts As GLAccounts = DirectCast(editor.CurrentObject, GLAccounts)
                    If Not editor.View.ObjectSpace.IsNewObject(_GLAccounts.Customers) Then
                        CType(e.CreatedObject, CustomerBankAccounts).Customers = e.ObjectSpace.GetObject(Of Customers)(_GLAccounts.Customers)
                    End If
                End If
            End If
        End If
    End Sub
End Class
