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

Public Class SupportDocuments
    Inherits DevExpress.ExpressApp.ViewController

    Public Sub New()
        MyBase.New()

        InitializeComponent()
        RegisterActions(components)

    End Sub

    Protected Overrides Sub OnActivated()
        MyBase.OnActivated()

        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)

        If View.Id = "SubcontractorDocuments_ListView" Then
            Frame.GetController(Of NewObjectViewController).Active.SetItemValue("", False)
            Frame.GetController(Of DeleteObjectsViewController).Active.SetItemValue("", False)
            Frame.GetController(Of CloneObjectViewController).Active.SetItemValue("", False)
            Frame.GetController(Of LinkUnlinkController)().Active.SetItemValue("", False)
            Frame.GetController(Of ListViewProcessCurrentObjectController).Active.SetItemValue("", False)
            Frame.GetController(Of CloneObjectViewController).Active.SetItemValue("", False)

            Dim _User As Contacts = _ocur.FindObject(Of Contacts)(CriteriaOperator.Parse("User = ?", _ocur.GetObject(SecuritySystem.CurrentUser)))

            If _User IsNot Nothing Then
                If _User.Customers IsNot Nothing Then
                    TryCast(View, ListView).CollectionSource.Criteria("BySubcontractor") = CriteriaOperator.Parse("Subcontractor.Customers = ?", _User.Customers)
                Else
                    TryCast(View, ListView).CollectionSource.Criteria("BySubcontractor") = CriteriaOperator.Parse("1=2")
                End If
            Else
                TryCast(View, ListView).CollectionSource.Criteria("BySubcontractor") = CriteriaOperator.Parse("1=2")
            End If
        End If
    End Sub
    Protected Overrides Sub OnDeactivated()
        MyBase.OnDeactivated()
        If View.Id = "SubcontractorDocuments_ListView" Then
            Frame.GetController(Of NewObjectViewController).Active.SetItemValue("", True)
            Frame.GetController(Of DeleteObjectsViewController).Active.SetItemValue("", True)
            Frame.GetController(Of CloneObjectViewController).Active.SetItemValue("", True)
            Frame.GetController(Of LinkUnlinkController)().Active.SetItemValue("", True)
            Frame.GetController(Of ListViewProcessCurrentObjectController).Active.SetItemValue("", True)
            Frame.GetController(Of CloneObjectViewController).Active.SetItemValue("", True)
        End If
    End Sub
End Class
