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.Data.Filtering

Public Class ProductsGroups_VC
	Inherits DevExpress.ExpressApp.ViewController

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

	End Sub

    Private Sub aProductsGroups_CreateBusinessDirectory_Execute(sender As Object, e As SimpleActionExecuteEventArgs) Handles aProductsGroups_CreateBusinessDirectory.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _ProductsGroups As ProductsGroups = TryCast(View.SelectedObjects, ProductsGroups)

        If _ProductsGroups.MasterBusinessDirectory Is Nothing Then
            Dim _ProductsBaseBusinessDirectory As BusinessDirectory = _ocur.FindObject(Of BusinessDirectory)(CriteriaOperator.Parse("ShortName='Termékek' AND IsNull(BusinessDirectory_Parent)=True"))

            If _ProductsBaseBusinessDirectory Is Nothing Then
                _ProductsBaseBusinessDirectory = New BusinessDirectory(_ocur.Session)
                With _ProductsBaseBusinessDirectory
                    .ShortName = "Termékek"
                    .BusinessDirectory_Parent = Nothing
                End With
            End If

            Dim _ProductsGroupsBusinessDirectory As New BusinessDirectory(_ocur.Session)
            With _ProductsGroupsBusinessDirectory
                .ShortName = _ProductsGroups.ShortName
                .BusinessDirectory_Parent = _ProductsBaseBusinessDirectory
            End With
            _ProductsGroups.MasterBusinessDirectory = _ProductsGroupsBusinessDirectory

            _ocur.CommitChanges()
        End If
    End Sub
End Class
