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.Win.Editors
Imports DevExpress.ExpressApp.SystemModule
Imports DevExpress.XtraGrid.Columns

Public Class OrderInRowsOtherVC
    Inherits DevExpress.ExpressApp.ViewController(Of ListView)

    Private _GridListEditor As GridListEditor

    Public Sub New()
        MyBase.New()
        InitializeComponent()
        RegisterActions(components)
    End Sub
    Protected Overrides Sub OnDeactivated()
        MyBase.OnDeactivated()
        If View.Id = "OrderInHeader_OrderInRows_ListView" Then
            If _GridListEditor IsNot Nothing Then
                If _GridListEditor.GridView IsNot Nothing Then
                    RemoveHandler _GridListEditor.GridView.CellValueChanged, AddressOf OrderInHeader_OrderInRows_ListView_CellValueChanged
                End If
            End If
        End If
    End Sub
    Protected Overrides Sub OnViewControlsCreated()
        MyBase.OnViewControlsCreated()

        'If View.Id = "OrderInHeader_OrderInRowsOther_ListView" Then
        '    Dim _ListView As ListView = CType(View, ListView)
        '    Dim _PropertyCollectionSource As PropertyCollectionSource = CType(_ListView.CollectionSource, PropertyCollectionSource)
        '    Dim _OrderInHeader As OrderInHeader = CType(_PropertyCollectionSource.MasterObject, OrderInHeader)
        '    If _OrderInHeader.IsEditable = True Then
        '        _GridListEditor = TryCast(View.Editor, GridListEditor)
        '        If _GridListEditor IsNot Nothing Then
        '            _GridListEditor.AllowEdit = True

        '            If _OrderInHeader.OrderInParameters.CurrencyName IsNot Nothing Then
        '                For i As Integer = 0 To _GridListEditor.Columns.Count - 1
        '                    If _OrderInHeader.OrderInParameters.CurrencyName.ShortName = "HUF" Then
        '                        If _GridListEditor.GridView.Columns(i).FieldName <> "QTT" _
        '                            And _GridListEditor.GridView.Columns(i).FieldName <> "Description" _
        '                            And _GridListEditor.GridView.Columns(i).FieldName <> "DiscountPriceHUF" Then
        '                            _GridListEditor.GridView.Columns(i).OptionsColumn.ReadOnly = True
        '                            _GridListEditor.GridView.Columns(i).OptionsColumn.AllowEdit = False
        '                            _GridListEditor.GridView.Columns(i).OptionsColumn.TabStop = False
        '                        End If
        '                    Else
        '                        If _GridListEditor.GridView.Columns(i).FieldName <> "QTT" _
        '                            And _GridListEditor.GridView.Columns(i).FieldName <> "Description" _
        '                            And _GridListEditor.GridView.Columns(i).FieldName <> "DiscountPriceDEV" Then

        '                            _GridListEditor.GridView.Columns(i).OptionsColumn.ReadOnly = True
        '                            _GridListEditor.GridView.Columns(i).OptionsColumn.AllowEdit = False
        '                            _GridListEditor.GridView.Columns(i).OptionsColumn.TabStop = False
        '                        End If
        '                    End If

        '                Next i
        '            End If
        '        End If
        '    End If
        'End If
        If View.Id = "OrderInHeader_OrderInRows_ListView" Then
            Dim _ListView As ListView = CType(View, ListView)
            Dim _PropertyCollectionSource As PropertyCollectionSource = CType(_ListView.CollectionSource, PropertyCollectionSource)
            Dim _OrderInHeader As OrderInHeader = CType(_PropertyCollectionSource.MasterObject, OrderInHeader)
            If _OrderInHeader.IsEditable = True Then
                _GridListEditor = TryCast(View.Editor, GridListEditor)
                If _GridListEditor IsNot Nothing Then
                    AddHandler _GridListEditor.GridView.CellValueChanged, AddressOf OrderInHeader_OrderInRows_ListView_CellValueChanged
                End If
            End If
        End If
    End Sub

    Private Sub OrderInHeader_OrderInRows_ListView_CellValueChanged(sender As Object, e As DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs)
        If TryCast(e.Column, GridColumn).FieldName = "QTT_Process" Then
            Dim nestedFrame As NestedFrame = TryCast(Frame, NestedFrame)
            If nestedFrame IsNot Nothing Then
                Dim parentView As View = nestedFrame.View
                TryCast(parentView.ObjectSpace, Xpo.XPObjectSpace).CommitChanges()
                parentView.ObjectSpace.Refresh()
            End If
        End If
    End Sub
End Class
