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.Xpo
Imports DevExpress.Persistent.BaseImpl
Imports DevExpress.Data.Filtering

Public Class AuditTrailVC
    Inherits DevExpress.ExpressApp.ViewController

    Public Sub New()
        MyBase.New()

        'This call is required by the Component Designer.
        InitializeComponent()
        RegisterActions(components)
        TargetViewType = ViewType.ListView

    End Sub
    Protected Overrides Sub OnActivated()
        MyBase.OnActivated()
        GLOBAL_HAS_Audit = True
        If View.Id Like "*AuditDataItemPersistent*" Then
            Frame.GetController(Of AuditTrailVC).aGetAuditTrail.Active.SetItemValue("", False)
        End If
    End Sub
    Protected Overrides Sub OnDeactivated()
        MyBase.OnDeactivated()
        If View.Id Like "*AuditDataItemPersistent*" Then
            Frame.GetController(Of AuditTrailVC).aGetAuditTrail.Active.SetItemValue("", True)
        End If
    End Sub
    Private Sub aGetAuditTrail_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aGetAuditTrail.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _AuditDataItemPersistent_Collection As XPCollection(Of AuditDataItemPersistent)
        Dim _AuditDataItemPersistent As AuditDataItemPersistent
        Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
        Dim _CS As New CollectionSource(_onew, GetType(AuditDataItemPersistent))

        _AuditDataItemPersistent_Collection = AuditedObjectWeakReference.GetAuditTrail(_ocur.Session, View.SelectedObjects(0))

        _CS.BeginUpdateCriteria()
        _CS.Criteria.Clear()
        _CS.Criteria("First") = CriteriaOperator.Parse("1=2")
        _CS.EndUpdateCriteria()

        If _AuditDataItemPersistent_Collection IsNot Nothing Then
            For Each _AuditDataItemPersistent In _AuditDataItemPersistent_Collection
                _CS.Add(_onew.GetObject(_AuditDataItemPersistent))
            Next

            e.ShowViewParameters.CreatedView = Application.CreateListView("AuditDataItemPersistent_ListView", _CS, False)
            e.ShowViewParameters.NewWindowTarget = NewWindowTarget.Separate
            e.ShowViewParameters.TargetWindow = TargetWindow.NewModalWindow

        End If
    End Sub
End Class
