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.Persistent.BaseImpl

Public Class RTFDocumentsHandlerVC
	Inherits DevExpress.ExpressApp.ViewController

	Public Sub New()
		MyBase.New()

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

    End Sub

    Private Sub aRTFDocumentsHandlerOpenPreviousDocument_CustomizePopupWindowParams(sender As Object, e As DevExpress.ExpressApp.Actions.CustomizePopupWindowParamsEventArgs) Handles aRTFDocumentsHandlerOpenPreviousDocument.CustomizePopupWindowParams
        Try
            Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
            Dim _RTFDocumentsHandler As RTFDocumentsHandler = TryCast(View.SelectedObjects(0), RTFDocumentsHandler)

            If _RTFDocumentsHandler Is Nothing Then Throw New Exception("*Nincs kiválasztva egyetlen sor sem!")
            Dim _CS As New CollectionSource(_onew, GetType(RTFDocumentsAuditBody))
            For Each _AuditDataItemPersistent As AuditDataItemPersistent In _RTFDocumentsHandler.AuditTrail
                If _AuditDataItemPersistent.PropertyName = "DocumentBody" Then
                    Dim _RTFDocumentsAuditBody As RTFDocumentsAuditBody = _onew.CreateObject(Of RTFDocumentsAuditBody)()
                    _RTFDocumentsAuditBody.ModifiedOn = _AuditDataItemPersistent.ModifiedOn
                    _RTFDocumentsAuditBody.UserName = _AuditDataItemPersistent.UserName
                    _RTFDocumentsAuditBody.DocumentBody = _AuditDataItemPersistent.NewValue

                    _CS.Add(_RTFDocumentsAuditBody)
                End If
            Next

            e.View = Application.CreateListView("RTFDocumentsAuditBody_ListView", _CS, False)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.OkOnly)
        End Try
    End Sub
    Private Sub aRTFDocumentsHandlerOpenPreviousDocument_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.PopupWindowShowActionExecuteEventArgs) Handles aRTFDocumentsHandlerOpenPreviousDocument.Execute
        Try

            Dim _ocur As Xpo.XPObjectSpace = View.ObjectSpace
            Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
            Dim _RTFDocumentsHandler As RTFDocumentsHandler = TryCast(View.SelectedObjects(0), RTFDocumentsHandler)
            If _RTFDocumentsHandler Is Nothing Then Throw New Exception("*Váratlan hiba történt, a folyamat megszakadt!")

            Dim _RTFDocumentsAuditBody As RTFDocumentsAuditBody = TryCast(e.PopupWindow.View.SelectedObjects(0), RTFDocumentsAuditBody)

            Dim _RTFDocumentsHandler_NEW As RTFDocumentsHandler = _onew.CreateObject(Of RTFDocumentsHandler)()

            _RTFDocumentsHandler_NEW.ShortName = _RTFDocumentsHandler.ShortName
            _RTFDocumentsHandler_NEW.DocumentBody = _RTFDocumentsAuditBody.DocumentBody

            Dim _ShowViewParameters As New ShowViewParameters
            Dim _ShowViewSource As New ShowViewSource(Frame, Nothing)

            e.ShowViewParameters.CreatedView = Application.CreateDetailView(_onew, "RTFDocumentsHandler_DetailView", True, _RTFDocumentsHandler_NEW)
            _ShowViewParameters.NewWindowTarget = NewWindowTarget.MdiChild
            _ShowViewParameters.TargetWindow = TargetWindow.NewWindow
            Application.ShowViewStrategy.ShowView(_ShowViewParameters, _ShowViewSource)

        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.OkOnly)
        End Try
    End Sub

   
End Class
