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.Data.Filtering
Imports DevExpress.ExpressApp.SystemModule
Imports DevExpress.ExpressApp.CloneObject
Public Class RegistryBankTransferVC
    Inherits DevExpress.ExpressApp.ViewController

    Public Sub New()
        MyBase.New()

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

    End Sub
    Protected Overrides Sub OnActivated()
        MyBase.OnActivated()
        Frame.GetController(Of RegistryBankTransferVC).aBlockBankTransfer.Active.SetItemValue("", False)
        If View.Id = "RegistryBankTransfer_ListView_Not_Transfered" Then
            Frame.GetController(Of RegistryBankTransferVC).aBlockBankTransfer.Active.SetItemValue("", True)
        End If
        If View.Id Like "*RegistryBankTransfer*" Then
            Frame.GetController(Of CloneObjectViewController).Active.SetItemValue("", False)
        End If
    End Sub
    Protected Overrides Sub OnDeactivated()
        MyBase.OnDeactivated()
        Frame.GetController(Of RegistryBankTransferVC).aBlockBankTransfer.Active.SetItemValue("", True)
        If View.Id = "RegistryBankTransfer_ListView_Not_Transfered" Then
            Frame.GetController(Of RegistryBankTransferVC).aBlockBankTransfer.Active.SetItemValue("", False)
        End If
        If View.Id Like "*RegistryBankTransfer*" Then
            Frame.GetController(Of CloneObjectViewController).Active.SetItemValue("", True)
        End If
    End Sub

    Private Sub aBlockBankTransfer_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aBlockBankTransfer.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As New UnitOfWork(_ocur.Session.DataLayer)

        Dim _RegistryBankTransferView As RegistryBankTransferView
        Dim _RegistryBankTransfer As RegistryBankTransfer
        For Each _RegistryBankTransferView In View.SelectedObjects
            _RegistryBankTransfer = _uow.GetObjectByKey(Of RegistryBankTransfer)(_RegistryBankTransferView.Oid)
            If _RegistryBankTransfer IsNot Nothing Then
                If _RegistryBankTransfer.BankSavedFileName = "" Then
                    If _RegistryBankTransfer.IsBlocked = True Then
                        _RegistryBankTransfer.IsBlocked = False
                    Else
                        _RegistryBankTransfer.IsBlocked = True
                    End If
                End If
            End If
        Next
        _uow.CommitChanges()
        Frame.GetController(Of RefreshController).RefreshAction.DoExecute()
    End Sub
End Class
