
Imports DevExpress.ExpressApp

Imports DevExpress.ExpressApp.SystemModule
Imports DevExpress.Data.Filtering

Public Class InstallationVC
    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()

        If View.Id = "Installation_InstallationDocumentations_ListView_Support" Then
            Frame.GetController(Of ListViewProcessCurrentObjectController).Active.SetItemValue("", False)

            Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
            Dim _Contacts As Contacts = _ocur.FindObject(Of Contacts)(CriteriaOperator.Parse("User = ?", _ocur.GetObject(SecuritySystem.CurrentUser)))

            If _Contacts IsNot Nothing Then
                If _Contacts.Customers IsNot Nothing Then
                    TryCast(View, ListView).CollectionSource.Criteria("ByPartner") = CriteriaOperator.Parse("Installation.TakeoverProtocolRows.TakeoverProtocolHeader.Customers.Oid = ? and Installation.TakeoverProtocolRows.TakeoverProtocolHeader.IsEditable=False ", _Contacts.Customers.Oid)
                Else
                    TryCast(View, ListView).CollectionSource.Criteria("ByPartner") = CriteriaOperator.Parse("1=2")
                End If
            Else
                TryCast(View, ListView).CollectionSource.Criteria("ByPartner") = CriteriaOperator.Parse("1=2")
            End If
            Frame.GetController(Of InstallationVC).aInstallation_ChangeGroups.Active.SetItemValue("", False)
        End If

    End Sub
    Protected Overrides Sub OnDeactivated()
        MyBase.OnDeactivated()
        If View.Id = "Installation_InstallationDocumentations_ListView_Support" Then
            Frame.GetController(Of ListViewProcessCurrentObjectController).Active.SetItemValue("", False)
            Frame.GetController(Of InstallationVC).aInstallation_ChangeGroups.Active.SetItemValue("", True)
        End If
    End Sub

    Private Sub aInstallation_ChangeGroups_CustomizePopupWindowParams(sender As Object, e As DevExpress.ExpressApp.Actions.CustomizePopupWindowParamsEventArgs) Handles aInstallation_ChangeGroups.CustomizePopupWindowParams
        Try
            If View.SelectedObjects.Count = 0 Then Throw New Exception("*Nincs kiválasztva egyetlen sor sem!")
            Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
            Dim _Installation_ChangeGroups_PopUp As Installation_ChangeGroups_PopUp = _onew.CreateObject(Of Installation_ChangeGroups_PopUp)()

            _Installation_ChangeGroups_PopUp.RowGroup1 = TryCast(View.SelectedObjects(0), InstallationDocumentations).RowGroup1
            _Installation_ChangeGroups_PopUp.RowGroup2 = TryCast(View.SelectedObjects(0), InstallationDocumentations).RowGroup2

            e.View = Application.CreateDetailView(_onew, "Installation_ChangeGroups_PopUp_DetailView", False, _Installation_ChangeGroups_PopUp)
        Catch ext As Exception
            MsgBox(ext.Message)
        End Try
    End Sub
    Private Sub aInstallation_ChangeGroups_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.PopupWindowShowActionExecuteEventArgs) Handles aInstallation_ChangeGroups.Execute
        Try
            Dim _ocur As Xpo.XPObjectSpace = View.ObjectSpace
            Dim _Installation_ChangeGroups_PopUp As Installation_ChangeGroups_PopUp = TryCast(e.PopupWindow.View.SelectedObjects(0), Installation_ChangeGroups_PopUp)
            If _Installation_ChangeGroups_PopUp Is Nothing Then Throw New Exception("*Váratlan hiba történt, a folyamat megszakadt!")
            For Each _InstallationDocumentations As InstallationDocumentations In View.SelectedObjects
                If _Installation_ChangeGroups_PopUp.Change_RowGroup1 Then
                    _InstallationDocumentations.RowGroup1 = _Installation_ChangeGroups_PopUp.RowGroup1
                End If
                If _Installation_ChangeGroups_PopUp.Change_RowGroup2 Then
                    _InstallationDocumentations.RowGroup2 = _Installation_ChangeGroups_PopUp.RowGroup2
                End If
            Next
            _ocur.CommitChanges()
        Catch ext As Exception
            MsgBox(ext.Message)
        End Try
    End Sub
End Class
