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

Public Class Operation_VC
    Inherits DevExpress.ExpressApp.ViewController

    Public Sub New()
        MyBase.New()
        InitializeComponent()
        RegisterActions(components)
    End Sub

    Private Sub aCustomersQualitificationFromOperation_CustomizePopupWindowParams(sender As Object, e As DevExpress.ExpressApp.Actions.CustomizePopupWindowParamsEventArgs) Handles aCustomersQualitificationFromOperation.CustomizePopupWindowParams
        Try
            Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
            Dim _CustomersQualificationPopUp As CustomersQualificationPopUp = _onew.CreateObject(Of CustomersQualificationPopUp)()
            _CustomersQualificationPopUp.FromOperations = True

            e.View = Application.CreateDetailView(_onew, "CustomersQualificationPopUp_DetailView", False, _CustomersQualificationPopUp)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.OkOnly)
        End Try
    End Sub
    Private Sub aCustomersQualitificationFromOperation_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.PopupWindowShowActionExecuteEventArgs) Handles aCustomersQualitificationFromOperation.Execute
        Try
            Dim _ocur As Xpo.XPObjectSpace = View.ObjectSpace
            Dim _CustomersQualificationPopUp As CustomersQualificationPopUp = TryCast(e.PopupWindow.View.SelectedObjects(0), CustomersQualificationPopUp)
            Dim _Customers As Customers = _ocur.GetObjectByKey(Of Customers)(_CustomersQualificationPopUp.Customers.Oid)
            If _Customers Is Nothing Then Throw New Exception("*Nincs kiválasztva minősítendő ügyfél!")

            For Each _Operations As Operations In View.SelectedObjects
                Dim _CustomersQualification As CustomersQualification = _ocur.FindObject(Of CustomersQualification)(CriteriaOperator.Parse("Customers=? AND Operations=?", _Customers, _Operations))

                If _CustomersQualification Is Nothing Then
                    _CustomersQualification = _ocur.CreateObject(Of CustomersQualification)()
                    _CustomersQualification.Customers = _Customers
                    _CustomersQualification.Operations = _Operations
                End If

                If _CustomersQualificationPopUp.Change_Price Then
                    _CustomersQualification.Price = _CustomersQualificationPopUp.Price
                End If
                If _CustomersQualificationPopUp.Change_Quality Then
                    _CustomersQualification.Quality = _CustomersQualificationPopUp.Quality
                End If
                If _CustomersQualificationPopUp.Change_Speed Then
                    _CustomersQualification.Speed = _CustomersQualificationPopUp.Speed
                End If
                If _CustomersQualificationPopUp.Change_Other1 Then
                    _CustomersQualification.Other1 = _CustomersQualificationPopUp.Other1
                End If
                If _CustomersQualificationPopUp.Change_Other2 Then
                    _CustomersQualification.Other2 = _CustomersQualificationPopUp.Other2
                End If
                If _CustomersQualificationPopUp.Change_Other3 Then
                    _CustomersQualification.Other3 = _CustomersQualificationPopUp.Other3
                End If
            Next

            _ocur.CommitChanges()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.OkOnly)
        End Try
    End Sub
    Private Sub aCustomersQualitificationFromCustomersQualitification_CustomizePopupWindowParams(sender As Object, e As DevExpress.ExpressApp.Actions.CustomizePopupWindowParamsEventArgs) Handles aCustomersQualitificationFromCustomers.CustomizePopupWindowParams
        Try
            Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
            Dim _CustomersQualificationPopUp As CustomersQualificationPopUp = _onew.CreateObject(Of CustomersQualificationPopUp)()
            _CustomersQualificationPopUp.FromCustomers = True

            e.View = Application.CreateDetailView(_onew, "CustomersQualificationPopUp_DetailView", False, _CustomersQualificationPopUp)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.OkOnly)
        End Try
    End Sub
    Private Sub aCustomersQualitificationFromCustomersQualitification_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.PopupWindowShowActionExecuteEventArgs) Handles aCustomersQualitificationFromCustomers.Execute
        Try
            Dim _ocur As Xpo.XPObjectSpace = View.ObjectSpace
            Dim _CustomersQualificationPopUp As CustomersQualificationPopUp = TryCast(e.PopupWindow.View.SelectedObjects(0), CustomersQualificationPopUp)
            Dim _Operations As Operations = _ocur.GetObjectByKey(Of Operations)(_CustomersQualificationPopUp.Operations.Oid)
            If _Operations Is Nothing Then Throw New Exception("*Nincs kiválasztott művelet!")

            For Each _Customers As Customers In View.SelectedObjects
                Dim _CustomersQualification As CustomersQualification = _ocur.FindObject(Of CustomersQualification)(CriteriaOperator.Parse("Customers=? AND Operations=?", _Customers, _Operations))

                If _CustomersQualification Is Nothing Then
                    _CustomersQualification = _ocur.CreateObject(Of CustomersQualification)()
                    _CustomersQualification.Customers = _Customers
                    _CustomersQualification.Operations = _Operations
                End If

                If _CustomersQualificationPopUp.Change_Price Then
                    _CustomersQualification.Price = _CustomersQualificationPopUp.Price
                End If
                If _CustomersQualificationPopUp.Change_Quality Then
                    _CustomersQualification.Quality = _CustomersQualificationPopUp.Quality
                End If
                If _CustomersQualificationPopUp.Change_Speed Then
                    _CustomersQualification.Speed = _CustomersQualificationPopUp.Speed
                End If
                If _CustomersQualificationPopUp.Change_Other1 Then
                    _CustomersQualification.Other1 = _CustomersQualificationPopUp.Other1
                End If
                If _CustomersQualificationPopUp.Change_Other2 Then
                    _CustomersQualification.Other2 = _CustomersQualificationPopUp.Other2
                End If
                If _CustomersQualificationPopUp.Change_Other3 Then
                    _CustomersQualification.Other3 = _CustomersQualificationPopUp.Other3
                End If
            Next
            _ocur.CommitChanges()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.OkOnly)
        End Try
    End Sub
End Class
