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 StorageComputedLocations_VC
    Inherits DevExpress.ExpressApp.ViewController

    Public Sub New()
        MyBase.New()
        InitializeComponent()
        RegisterActions(components)
    End Sub
    Protected Overrides Sub OnActivated()
        MyBase.OnActivated()
        If View.Id = "MoveProductsOtherLocation_PopUp_StorageComputedLocations_ListView" Then
            Frame.GetController(Of NewObjectViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of DeleteObjectsViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of ModificationsController)().Active.SetItemValue("", False)
            Frame.GetController(Of ListViewProcessCurrentObjectController)().Active.SetItemValue("", False)
            Frame.GetController(Of NewObjectViewController).Active.SetItemValue("", False)
            Frame.GetController(Of CloneObjectViewController).Active.SetItemValue("", False)
            Frame.GetController(Of LinkUnlinkController).Active.SetItemValue("", False)
        End If
    End Sub
    Protected Overrides Sub OnDeactivated()
        MyBase.OnDeactivated()
        Frame.GetController(Of NewObjectViewController)().Active.SetItemValue("", True)
        Frame.GetController(Of DeleteObjectsViewController)().Active.SetItemValue("", True)
        Frame.GetController(Of ModificationsController)().Active.SetItemValue("", True)
        Frame.GetController(Of ListViewProcessCurrentObjectController)().Active.SetItemValue("", True)
        Frame.GetController(Of NewObjectViewController).Active.SetItemValue("", True)
        Frame.GetController(Of CloneObjectViewController).Active.SetItemValue("", True)
        Frame.GetController(Of LinkUnlinkController).Active.SetItemValue("", True)
    End Sub

    Private Sub aMoveProductsOtherLocation_CustomizePopupWindowParams(sender As Object, e As DevExpress.ExpressApp.Actions.CustomizePopupWindowParamsEventArgs) Handles aMoveProductsOtherLocation.CustomizePopupWindowParams
        Try
            Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
            Dim _MoveProductsOtherLocation_PopUp As MoveProductsOtherLocation_PopUp = _onew.CreateObject(Of MoveProductsOtherLocation_PopUp)()
            Dim _StorageComputedLocations As StorageComputedLocations = TryCast(View.SelectedObjects(0), StorageComputedLocations)
            _MoveProductsOtherLocation_PopUp.StorageLocation = _onew.GetObject(_StorageComputedLocations.StorageLocation)
            _MoveProductsOtherLocation_PopUp.Criteria = "Oid in ('"

            For Each _StorageComputedLocations_Selected As StorageComputedLocations In View.SelectedObjects
                _MoveProductsOtherLocation_PopUp.Criteria += TryCast(_StorageComputedLocations_Selected, StorageComputedLocations).Oid.ToString + "','"
            Next
            _MoveProductsOtherLocation_PopUp.Criteria = _MoveProductsOtherLocation_PopUp.Criteria.Remove(_MoveProductsOtherLocation_PopUp.Criteria.Length - 2, 2)
            _MoveProductsOtherLocation_PopUp.Criteria += ")"

            e.View = Application.CreateDetailView(_onew, "MoveProductsOtherLocation_PopUp_DetailView", False, _MoveProductsOtherLocation_PopUp)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.OkOnly)
        End Try
    End Sub
    Private Sub aMoveProductsOtherLocation_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.PopupWindowShowActionExecuteEventArgs) Handles aMoveProductsOtherLocation.Execute
        Try
            Dim _onew As Xpo.XPObjectSpace = e.PopupWindow.View.ObjectSpace
            Dim _MoveProductsOtherLocation_PopUp As MoveProductsOtherLocation_PopUp = TryCast(e.PopupWindow.View.SelectedObjects(0), MoveProductsOtherLocation_PopUp)
            If _MoveProductsOtherLocation_PopUp.StorageComputedLocations.Count = 0 Then Throw New Exception("*Nem lett kijelölve lokalizált termék!")

            For Each _StorageComputedLocations As StorageComputedLocations In _MoveProductsOtherLocation_PopUp.StorageComputedLocations
                _StorageComputedLocations.StorageLocation = _MoveProductsOtherLocation_PopUp.NewStorageLocation
            Next
            _onew.CommitChanges()
        Catch ex As Exception

        End Try
    End Sub
    Private Sub aMoveLocationOtherLocation_CustomizePopupWindowParams(sender As Object, e As DevExpress.ExpressApp.Actions.CustomizePopupWindowParamsEventArgs) Handles aMoveLocationOtherLocation.CustomizePopupWindowParams
        Try
            Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
            Dim _MoveLocationOtherLocation_PopUp As MoveLocationOtherLocation_PopUp = _onew.CreateObject(Of MoveLocationOtherLocation_PopUp)()
            Dim _StorageComputedLocations As StorageComputedLocations = TryCast(View.SelectedObjects(0), StorageComputedLocations)
            _MoveLocationOtherLocation_PopUp.StorageLocation = _onew.GetObject(_StorageComputedLocations.StorageLocation)

            e.View = Application.CreateDetailView(_onew, "MoveLocationOtherLocation_PopUp_DetailView", False, _MoveLocationOtherLocation_PopUp)
            View.Refresh()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.OkOnly)
        End Try
    End Sub
    Private Sub aMoveLocationOtherLocation_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.PopupWindowShowActionExecuteEventArgs) Handles aMoveLocationOtherLocation.Execute
        Try
            Dim _ocur As Xpo.XPObjectSpace = View.ObjectSpace
            Dim _MoveLocationOtherLocation_PopUp As MoveLocationOtherLocation_PopUp = TryCast(e.PopupWindow.View.SelectedObjects(0), MoveLocationOtherLocation_PopUp)
            Dim _NewStorageLocation As StorageLocation = _ocur.GetObjectByKey(Of StorageLocation)(_MoveLocationOtherLocation_PopUp.NewStorageLocation.Oid)

            Dim _StorageComputedLocations_Collection As New XPCollection(Of StorageComputedLocations)(_ocur.Session, CriteriaOperator.Parse("StorageLocation=?", TryCast(View.SelectedObjects(0), StorageComputedLocations).StorageLocation))

            If _StorageComputedLocations_Collection.Count = 0 Then Throw New Exception("*Nincs kiválasztva egyetlen sor sem, így nem lehet azonosítani a mozgatásra váró lokációt!")

            For Each _StorageComputedLocations As StorageComputedLocations In _StorageComputedLocations_Collection
                _StorageComputedLocations.StorageLocation = _NewStorageLocation
            Next
            _ocur.CommitChanges()
            View.Refresh()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.OkOnly)
        End Try
    End Sub
End Class
