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.Xpo
Imports DevExpress.Data.Filtering
Imports DevExpress.Persistent.BaseImpl
Imports DevExpress.ExpressApp.Utils

Public Class ProjectVC
    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 = "ProjectHeader_ProjectHRPerson_ListView" Then
            Frame.GetController(Of LinkUnlinkController)().Active.SetItemValue("", False)
            Frame.GetController(Of NewObjectViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of CloneObject.CloneObjectViewController).Active.SetItemValue("", False)
        End If
        If View.Id = "ProjectHeader_ProjectSubcontractor_ListView" Then
            Frame.GetController(Of LinkUnlinkController)().Active.SetItemValue("", False)
            Frame.GetController(Of NewObjectViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of CloneObject.CloneObjectViewController).Active.SetItemValue("", False)
        End If
        If View.Id = "ProjectHeader_ProjectCustomers_ListView" Then
            Frame.GetController(Of LinkUnlinkController)().Active.SetItemValue("", False)
            Frame.GetController(Of NewObjectViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of CloneObject.CloneObjectViewController).Active.SetItemValue("", False)
        End If
        If View.Id = "ProjectRows_ProjectRowsCustomers_ListView" Then
            Frame.GetController(Of LinkUnlinkController)().Active.SetItemValue("", False)
            Frame.GetController(Of NewObjectViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of CloneObject.CloneObjectViewController).Active.SetItemValue("", False)
        End If
        If View.Id = "ProjectRows_ProjectRowsHRPerson_ListView" Then
            Frame.GetController(Of LinkUnlinkController)().Active.SetItemValue("", False)
            Frame.GetController(Of NewObjectViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of CloneObject.CloneObjectViewController).Active.SetItemValue("", False)
        End If
        If View.Id = "ProjectRows_ProjectRowsSubcontractor_ListView" Then
            Frame.GetController(Of LinkUnlinkController)().Active.SetItemValue("", False)
            Frame.GetController(Of NewObjectViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of CloneObject.CloneObjectViewController).Active.SetItemValue("", False)
        End If
    End Sub
    Protected Overrides Sub OnDeactivated()
        MyBase.OnDeactivated()
        If View.Id = "ProjectHeader_ProjectHRPerson_ListView" Then
            Frame.GetController(Of LinkUnlinkController)().Active.SetItemValue("", True)
            Frame.GetController(Of NewObjectViewController)().Active.SetItemValue("", True)
            Frame.GetController(Of CloneObject.CloneObjectViewController).Active.SetItemValue("", True)
        End If
        If View.Id = "ProjectHeader_ProjectSubcontractor_ListView" Then
            Frame.GetController(Of LinkUnlinkController)().Active.SetItemValue("", True)
            Frame.GetController(Of NewObjectViewController)().Active.SetItemValue("", True)
            Frame.GetController(Of CloneObject.CloneObjectViewController).Active.SetItemValue("", True)
        End If
        If View.Id = "ProjectHeader_ProjectCustomers_ListView" Then
            Frame.GetController(Of LinkUnlinkController)().Active.SetItemValue("", True)
            Frame.GetController(Of NewObjectViewController)().Active.SetItemValue("", True)
            Frame.GetController(Of CloneObject.CloneObjectViewController).Active.SetItemValue("", True)
        End If
        If View.Id = "ProjectRows_ProjectRowsCustomers_ListView" Then
            Frame.GetController(Of LinkUnlinkController)().Active.SetItemValue("", True)
            Frame.GetController(Of NewObjectViewController)().Active.SetItemValue("", True)
            Frame.GetController(Of CloneObject.CloneObjectViewController).Active.SetItemValue("", True)
        End If
        If View.Id = "ProjectRows_ProjectRowsHRPerson_ListView" Then
            Frame.GetController(Of LinkUnlinkController)().Active.SetItemValue("", True)
            Frame.GetController(Of NewObjectViewController)().Active.SetItemValue("", True)
            Frame.GetController(Of CloneObject.CloneObjectViewController).Active.SetItemValue("", True)
        End If
        If View.Id = "ProjectRows_ProjectRowsSubcontractor_ListView" Then
            Frame.GetController(Of LinkUnlinkController)().Active.SetItemValue("", True)
            Frame.GetController(Of NewObjectViewController)().Active.SetItemValue("", True)
            Frame.GetController(Of CloneObject.CloneObjectViewController).Active.SetItemValue("", True)
        End If
    End Sub
    Overridable Sub aProjectEditRow_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aProjectEditRow.Execute
    End Sub
    Overridable Sub aProjectAddRow_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aProjectAddRow.Execute
    End Sub
    Overridable Sub aProjectDeleteRow_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aProjectDeleteRow.Execute
    End Sub
    Private Sub aProjectRowsHRPerson_AddHRPerson_CustomizePopupWindowParams(sender As Object, e As CustomizePopupWindowParamsEventArgs) Handles aProjectRowsHRPerson_AddHRPerson.CustomizePopupWindowParams
        Try
            Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
            Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
            Dim _HRPerson_CollectionSource As New CollectionSource(_onew, GetType(HRPerson))

            e.View = Application.CreateListView("HRPerson_ListView", _HRPerson_CollectionSource, False)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, String.Format(CaptionHelper.GetLocalizedText("Exceptions\SISBusinessExceptions", "MsgBoxCheckItAgain")))
        End Try
    End Sub
    Private Sub aProjectRowsHRPerson_AddHRPerson_Execute(sender As Object, e As PopupWindowShowActionExecuteEventArgs) Handles aProjectRowsHRPerson_AddHRPerson.Execute
        Try
            If e.PopupWindow.View.SelectedObjects.Count = 0 Then Throw New Exception("*Nem lett kiválasztva egyetlen sor sem!")
            Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
            Dim _ProjectRows As ProjectRows = TryCast(TryCast(TryCast(View, ListView).CollectionSource, PropertyCollectionSource).MasterObject, ProjectRows)
            If _ProjectRows Is Nothing Then Throw New Exception("*Váratlan hiba történt, a folyamat megszakadt!")
            For Each _HRPerson As HRPerson In e.PopupWindow.View.SelectedObjects
                Dim _ProjectRowsHRPerson As New ProjectRowsHRPerson(_ocur.Session)
                With (_ProjectRowsHRPerson)
                    .ProjectRows = _ocur.GetObjectByKey(Of ProjectRows)(_ProjectRows.Oid)
                    .HRPerson = _ocur.GetObjectByKey(Of HRPerson)(_HRPerson.Oid)
                End With
            Next

            _ocur.CommitChanges()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, String.Format(CaptionHelper.GetLocalizedText("Exceptions\SISBusinessExceptions", "MsgBoxCheckItAgain")))
        End Try
    End Sub
    Private Sub aProjectRowsSubcontractor_AddSubcontractor_CustomizePopupWindowParams(sender As Object, e As CustomizePopupWindowParamsEventArgs) Handles aProjectRowsSubcontractor_AddSubcontractor.CustomizePopupWindowParams
        Try
            Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
            Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
            Dim _Subcontractor_CollectionSource As New CollectionSource(_onew, GetType(Subcontractor))
            Dim _User_Collection As New XPCollection(Of User)(_onew.Session)
            Dim _Filter As String = "Oid in("
            For Each _User As User In _User_Collection
                Dim _Contacts As Contacts = _onew.FindObject(Of Contacts)(CriteriaOperator.Parse("User=?", _User))
                If _Contacts IsNot Nothing Then
                    If _Contacts.Customers IsNot Nothing Then
                        Dim _Subcontractor As Subcontractor = _onew.FindObject(Of Subcontractor)(CriteriaOperator.Parse("Customers=?", _Contacts.Customers))
                        If _Subcontractor IsNot Nothing Then
                            _Filter += "'" + _Subcontractor.Oid.ToString + "',"
                        End If
                    End If
                End If
            Next
            _Filter = _Filter.Remove(_Filter.Length - 1, 1)
            _Filter += ")"
            _Subcontractor_CollectionSource.BeginUpdateCriteria()
            _Subcontractor_CollectionSource.Criteria.Clear()
            If _Filter.Length > 8 Then
                _Subcontractor_CollectionSource.Criteria.Add("1", CriteriaOperator.Parse(_Filter))
            Else
                _Subcontractor_CollectionSource.Criteria.Add("1", CriteriaOperator.Parse("1=2"))
            End If

            e.View = Application.CreateListView("Subcontractor_ListView", _Subcontractor_CollectionSource, False)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, String.Format(CaptionHelper.GetLocalizedText("Exceptions\SISBusinessExceptions", "MsgBoxCheckItAgain")))
        End Try
    End Sub
    Private Sub aProjectRowsSubcontractor_AddSubcontractor_Execute(sender As Object, e As PopupWindowShowActionExecuteEventArgs) Handles aProjectRowsSubcontractor_AddSubcontractor.Execute
        Try
            If e.PopupWindow.View.SelectedObjects.Count = 0 Then Throw New Exception("*Nem lett kiválasztva egyetlen sor sem!")
            Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
            Dim _ProjectRows As ProjectRows = TryCast(TryCast(TryCast(View, ListView).CollectionSource, PropertyCollectionSource).MasterObject, ProjectRows)
            If _ProjectRows Is Nothing Then Throw New Exception("*Váratlan hiba történt, a folyamat megszakadt!")
            For Each _Subcontractor As Subcontractor In e.PopupWindow.View.SelectedObjects
                Dim _ProjectRowsSubcontractor As New ProjectRowsSubcontractor(_ocur.Session)
                With (_ProjectRowsSubcontractor)
                    .ProjectRows = _ocur.GetObjectByKey(Of ProjectRows)(_ProjectRows.Oid)
                    .Subcontractor = _ocur.GetObjectByKey(Of Subcontractor)(_Subcontractor.Oid)
                End With
            Next

            _ocur.CommitChanges()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, String.Format(CaptionHelper.GetLocalizedText("Exceptions\SISBusinessExceptions", "MsgBoxCheckItAgain")))
        End Try
    End Sub
    Private Sub aProjectRowsCustomers_AddRowsCustomers_CustomizePopupWindowParams(sender As Object, e As CustomizePopupWindowParamsEventArgs) Handles aProjectRowsCustomers_AddRowsCustomers.CustomizePopupWindowParams
        Try
            Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
            Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
            Dim _Customers_CollectionSource As New CollectionSource(_onew, GetType(Customers))
            Dim _User_Collection As New XPCollection(Of User)(_onew.Session)
            Dim _Filter As String = "Oid in("
            For Each _User As User In _User_Collection
                Dim _Contacts As Contacts = _onew.FindObject(Of Contacts)(CriteriaOperator.Parse("User=?", _User))
                If _Contacts IsNot Nothing Then
                    If _Contacts.Customers IsNot Nothing Then
                        _Filter += "'" + _Contacts.Customers.Oid.ToString + "',"
                    End If
                End If
            Next
            _Filter = _Filter.Remove(_Filter.Length - 1, 1)
            _Filter += ")"

            _Customers_CollectionSource.BeginUpdateCriteria()
            _Customers_CollectionSource.Criteria.Clear()
            If _Filter.Length > 8 Then
                _Customers_CollectionSource.Criteria.Add("1", CriteriaOperator.Parse(_Filter))
            Else
                _Customers_CollectionSource.Criteria.Add("1", CriteriaOperator.Parse("1=2"))
            End If
            _Customers_CollectionSource.EndUpdateCriteria()

            e.View = Application.CreateListView("Customers_ListView", _Customers_CollectionSource, False)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, String.Format(CaptionHelper.GetLocalizedText("Exceptions\SISBusinessExceptions", "MsgBoxCheckItAgain")))
        End Try
    End Sub
    Private Sub aProjectRowsCustomers_AddRowsCustomers_Execute(sender As Object, e As PopupWindowShowActionExecuteEventArgs) Handles aProjectRowsCustomers_AddRowsCustomers.Execute
        Try
            If e.PopupWindow.View.SelectedObjects.Count = 0 Then Throw New Exception("*Nem lett kiválasztva egyetlen sor sem!")
            Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
            Dim _ProjectRows As ProjectRows = TryCast(TryCast(TryCast(View, ListView).CollectionSource, PropertyCollectionSource).MasterObject, ProjectRows)
            If _ProjectRows Is Nothing Then Throw New Exception("*Váratlan hiba történt, a folyamat megszakadt!")
            For Each _Customers As Customers In e.PopupWindow.View.SelectedObjects
                Dim _ProjectRowsCustomers As New ProjectRowsCustomers(_ocur.Session)
                With (_ProjectRowsCustomers)
                    .ProjectRows = _ocur.GetObjectByKey(Of ProjectRows)(_ProjectRows.Oid)
                    .Customers = _ocur.GetObjectByKey(Of Customers)(_Customers.Oid)
                End With
            Next

            _ocur.CommitChanges()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, String.Format(CaptionHelper.GetLocalizedText("Exceptions\SISBusinessExceptions", "MsgBoxCheckItAgain")))
        End Try
    End Sub
    Private Sub aProjectHRPerson_AddHRPerson_CustomizePopupWindowParams(sender As Object, e As CustomizePopupWindowParamsEventArgs) Handles aProjectHRPerson_AddHRPerson.CustomizePopupWindowParams
        Try
            Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
            Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
            Dim _HRPerson_CollectionSource As New CollectionSource(_onew, GetType(HRPerson))

            e.View = Application.CreateListView("HRPerson_ListView", _HRPerson_CollectionSource, False)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, String.Format(CaptionHelper.GetLocalizedText("Exceptions\SISBusinessExceptions", "MsgBoxCheckItAgain")))
        End Try
    End Sub
    Private Sub aProjectHRPerson_AddHRPerson_Execute(sender As Object, e As PopupWindowShowActionExecuteEventArgs) Handles aProjectHRPerson_AddHRPerson.Execute
        Try
            If e.PopupWindow.View.SelectedObjects.Count = 0 Then Throw New Exception("*Nem lett kiválasztva egyetlen sor sem!")
            Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
            Dim _ProjectHeader As ProjectHeader = TryCast(TryCast(TryCast(View, ListView).CollectionSource, PropertyCollectionSource).MasterObject, ProjectHeader)
            If _ProjectHeader Is Nothing Then Throw New Exception("*Váratlan hiba történt, a folyamat megszakadt!")
            For Each _HRPerson As HRPerson In e.PopupWindow.View.SelectedObjects
                Dim _ProjectHRPerson As New ProjectHRPerson(_ocur.Session)
                With (_ProjectHRPerson)
                    .ProjectHeader = _ProjectHeader
                    .HRPerson = _ocur.GetObjectByKey(Of HRPerson)(_HRPerson.Oid)
                End With
            Next

            _ocur.CommitChanges()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, String.Format(CaptionHelper.GetLocalizedText("Exceptions\SISBusinessExceptions", "MsgBoxCheckItAgain")))
        End Try
    End Sub
    Private Sub aProjectCustomers_AddRowsCustomers_CustomizePopupWindowParams(sender As Object, e As CustomizePopupWindowParamsEventArgs) Handles aProjectCustomers_AddRowsCustomers.CustomizePopupWindowParams
        Try
            Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
            Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
            Dim _Customers_CollectionSource As New CollectionSource(_onew, GetType(Customers))
            Dim _User_Collection As New XPCollection(Of User)(_onew.Session)
            Dim _Filter As String = "Oid in("
            For Each _User As User In _User_Collection
                Dim _Contacts As Contacts = _onew.FindObject(Of Contacts)(CriteriaOperator.Parse("User=?", _User))
                If _Contacts IsNot Nothing Then
                    If _Contacts.Customers IsNot Nothing Then
                        _Filter += "'" + _Contacts.Customers.Oid.ToString + "',"
                    End If
                End If
            Next
            _Filter = _Filter.Remove(_Filter.Length - 1, 1)
            _Filter += ")"

            _Customers_CollectionSource.BeginUpdateCriteria()
            _Customers_CollectionSource.Criteria.Clear()
            If _Filter.Length > 8 Then
                _Customers_CollectionSource.Criteria.Add("1", CriteriaOperator.Parse(_Filter))
            Else
                _Customers_CollectionSource.Criteria.Add("1", CriteriaOperator.Parse("1=2"))
            End If
            _Customers_CollectionSource.EndUpdateCriteria()

            e.View = Application.CreateListView("Customers_ListView", _Customers_CollectionSource, False)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, String.Format(CaptionHelper.GetLocalizedText("Exceptions\SISBusinessExceptions", "MsgBoxCheckItAgain")))
        End Try
    End Sub
    Private Sub aProjectCustomers_AddRowsCustomers_Execute(sender As Object, e As PopupWindowShowActionExecuteEventArgs) Handles aProjectCustomers_AddRowsCustomers.Execute
        Try
            If e.PopupWindow.View.SelectedObjects.Count = 0 Then Throw New Exception("*Nem lett kiválasztva egyetlen sor sem!")
            Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
            Dim _ProjectHeader As ProjectHeader = TryCast(TryCast(TryCast(View, ListView).CollectionSource, PropertyCollectionSource).MasterObject, ProjectHeader)
            If _ProjectHeader Is Nothing Then Throw New Exception("*Váratlan hiba történt, a folyamat megszakadt!")
            For Each _Customers As Customers In e.PopupWindow.View.SelectedObjects
                Dim _ProjectCustomers As New ProjectCustomers(_ocur.Session)
                With (_ProjectCustomers)
                    .ProjectHeader = _ProjectHeader
                    .Customers = _ocur.GetObjectByKey(Of Customers)(_Customers.Oid)
                End With
            Next

            _ocur.CommitChanges()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, String.Format(CaptionHelper.GetLocalizedText("Exceptions\SISBusinessExceptions", "MsgBoxCheckItAgain")))
        End Try
    End Sub
    Private Sub aProjectSubcontractor_AddSubcontractor_CustomizePopupWindowParams(sender As Object, e As CustomizePopupWindowParamsEventArgs) Handles aProjectSubcontractor_AddSubcontractor.CustomizePopupWindowParams
        Try
            Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
            Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
            Dim _Subcontractor_CollectionSource As New CollectionSource(_onew, GetType(Subcontractor))
            Dim _User_Collection As New XPCollection(Of User)(_onew.Session)
            Dim _Filter As String = "Oid in("
            For Each _User As User In _User_Collection
                Dim _Contacts As Contacts = _onew.FindObject(Of Contacts)(CriteriaOperator.Parse("User=?", _User))
                If _Contacts IsNot Nothing Then
                    If _Contacts.Customers IsNot Nothing Then
                        Dim _Subcontractor As Subcontractor = _onew.FindObject(Of Subcontractor)(CriteriaOperator.Parse("Customers=?", _Contacts.Customers))
                        If _Subcontractor IsNot Nothing Then
                            _Filter += "'" + _Subcontractor.Oid.ToString + "',"
                        End If
                    End If
                End If
            Next
            _Filter = _Filter.Remove(_Filter.Length - 1, 1)
            _Filter += ")"
            _Subcontractor_CollectionSource.BeginUpdateCriteria()
            _Subcontractor_CollectionSource.Criteria.Clear()
            If _Filter.Length > 8 Then
                _Subcontractor_CollectionSource.Criteria.Add("1", CriteriaOperator.Parse(_Filter))
            Else
                _Subcontractor_CollectionSource.Criteria.Add("1", CriteriaOperator.Parse("1=2"))
            End If

            e.View = Application.CreateListView("Subcontractor_ListView", _Subcontractor_CollectionSource, False)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, String.Format(CaptionHelper.GetLocalizedText("Exceptions\SISBusinessExceptions", "MsgBoxCheckItAgain")))
        End Try
    End Sub
    Private Sub aProjectSubcontractor_AddSubcontractor_Execute(sender As Object, e As PopupWindowShowActionExecuteEventArgs) Handles aProjectSubcontractor_AddSubcontractor.Execute
        Try
            If e.PopupWindow.View.SelectedObjects.Count = 0 Then Throw New Exception("*Nem lett kiválasztva egyetlen sor sem!")
            Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
            Dim _ProjectHeader As ProjectHeader = TryCast(TryCast(TryCast(View, ListView).CollectionSource, PropertyCollectionSource).MasterObject, ProjectHeader)
            If _ProjectHeader Is Nothing Then Throw New Exception("*Váratlan hiba történt, a folyamat megszakadt!")
            For Each _Subcontractor As Subcontractor In e.PopupWindow.View.SelectedObjects
                Dim _ProjectSubcontractor As New ProjectSubcontractor(_ocur.Session)
                With (_ProjectSubcontractor)
                    .ProjectHeader = _ProjectHeader
                    .Subcontractor = _ocur.GetObjectByKey(Of Subcontractor)(_Subcontractor.Oid)
                End With
            Next

            _ocur.CommitChanges()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, String.Format(CaptionHelper.GetLocalizedText("Exceptions\SISBusinessExceptions", "MsgBoxCheckItAgain")))
        End Try
    End Sub

    Private Sub aProjectCustomers_AddRowsContacts_CustomizePopupWindowParams(sender As Object, e As CustomizePopupWindowParamsEventArgs) Handles aProjectCustomers_AddRowsContacts.CustomizePopupWindowParams
        Try
            Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
            Dim _Contacts_CollectionSource As New CollectionSource(_onew, GetType(Contacts))

            e.View = Application.CreateListView("Contacts_ListView", _Contacts_CollectionSource, False)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, "Hiba!")
        End Try
    End Sub
    Private Sub aProjectCustomers_AddRowsContacts_Execute(sender As Object, e As PopupWindowShowActionExecuteEventArgs) Handles aProjectCustomers_AddRowsContacts.Execute
        Try
            Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
            Dim _ProjectHeader As ProjectHeader = TryCast(TryCast(TryCast(View, ListView).CollectionSource, PropertyCollectionSource).MasterObject, ProjectHeader)
            If _ProjectHeader Is Nothing Then Throw New Exception("*Váratlan hiba történt, a folyamat megszakadt!")

            For Each _Contacts As Contacts In e.PopupWindow.View.SelectedObjects
                Dim _ProjectContacts As New ProjectContacts(_ocur.Session)
                With _ProjectContacts
                    .ProjectHeader = _ProjectHeader
                    .Contacts = _ocur.GetObject(_Contacts)
                End With
            Next

            _ocur.CommitChanges()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, "Hiba!")
        End Try
    End Sub
    Private Sub aProjectRowsCustomers_AddRowsContacts_CustomizePopupWindowParams(sender As Object, e As CustomizePopupWindowParamsEventArgs) Handles aProjectRowsCustomers_AddRowsContacts.CustomizePopupWindowParams
        Try
            Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
            Dim _Contacts_CollectionSource As New CollectionSource(_onew, GetType(Contacts))

            e.View = Application.CreateListView("Contacts_ListView", _Contacts_CollectionSource, False)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, "Hiba!")
        End Try
    End Sub
    Private Sub aProjectRowsCustomers_AddRowsContacts_Execute(sender As Object, e As PopupWindowShowActionExecuteEventArgs) Handles aProjectRowsCustomers_AddRowsContacts.Execute
        Try
            Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
            Dim _ProjectRows As ProjectRows = TryCast(TryCast(TryCast(View, ListView).CollectionSource, PropertyCollectionSource).MasterObject, ProjectRows)
            If _ProjectRows Is Nothing Then Throw New Exception("*Váratlan hiba történt, a folyamat megszakadt!")

            For Each _Contacts As Contacts In e.PopupWindow.View.SelectedObjects
                Dim _ProjectRowsContacts As New ProjectRowsContacts(_ocur.Session)
                With _ProjectRowsContacts
                    .ProjectRows = _ProjectRows
                    .Contacts = _ocur.GetObject(_Contacts)
                End With
            Next

            _ocur.CommitChanges()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, "Hiba!")
        End Try
    End Sub
End Class
