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.CloneObject

Public Class Services_VC
    Inherits DevExpress.ExpressApp.ViewController

    Public Sub New()
        MyBase.New()
        InitializeComponent()
        RegisterActions(components)
    End Sub

#Region "Overrides"
    Protected Overrides Sub OnActivated()
        MyBase.OnActivated()
        If View.Id = "Services_Services_BusinessDirectory_ListView" Then
            Frame.GetController(Of LinkUnlinkController)().Active.SetItemValue("", False)
            Frame.GetController(Of CloneObjectViewController)().Active.SetItemValue("", False)
        End If
    End Sub
    Protected Overrides Sub OnDeactivated()
        MyBase.OnDeactivated()
        If View.Id = "Services_Services_BusinessDirectory_ListView" Then
            Frame.GetController(Of LinkUnlinkController)().Active.SetItemValue("", True)
            Frame.GetController(Of CloneObjectViewController)().Active.SetItemValue("", True)
        End If
    End Sub
#End Region
    Private Sub aServices_CreateBusinessDirectory_Execute(sender As Object, e As SimpleActionExecuteEventArgs) Handles aServices_CreateBusinessDirectory.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _Services As Services = TryCast(View.SelectedObjects(0), Services)

        If _Services.MasterBusinessDirectory Is Nothing Then
            Dim _ServicesBaseBusinessDirectory As BusinessDirectory = _ocur.FindObject(Of BusinessDirectory)(DevExpress.Data.Filtering.CriteriaOperator.Parse("ShortName='Szolgáltatások' AND IsNull(BusinessDirectory_Parent)=True"))

            If _ServicesBaseBusinessDirectory Is Nothing Then
                _ServicesBaseBusinessDirectory = New BusinessDirectory(_ocur.Session)
                With _ServicesBaseBusinessDirectory
                    .ShortName = "Szolgáltatások"
                    .BusinessDirectory_Parent = Nothing
                End With
            End If

            Dim _ServicesBusinessDirectory As New BusinessDirectory(_ocur.Session)
            With _ServicesBusinessDirectory
                .ShortName = _Services.ShortName
                .BusinessDirectory_Parent = _ServicesBaseBusinessDirectory
            End With
            _Services.MasterBusinessDirectory = _ServicesBusinessDirectory

            _ocur.CommitChanges()
        End If

    End Sub
End Class
