Imports System.Diagnostics
Imports System.Text

Imports DevExpress.ExpressApp
Imports DevExpress.ExpressApp.Actions
Imports DevExpress.Persistent.Base
Imports DevExpress.ExpressApp.Win.SystemModule
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.ExpressApp.Editors
Imports DevExpress.ExpressApp.Win.Editors

Public Class GLCassaVC
    Inherits DevExpress.ExpressApp.ViewController
    Private _GridListEditor As GridListEditor

    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 = "GLCassa_DetailView" Or View.Id = "GLCassa_GLRows_ListView" Then
            Frame.GetController(Of WinModificationsController).ModificationsHandlingMode = SystemModule.ModificationsHandlingMode.AutoCommit
        End If
    End Sub
    Protected Overrides Sub OnDeactivated()
        MyBase.OnDeactivated()
        If View.Id = "GLCassa_ListView" Then
            Dim editor As ListEditor = (CType(View, ListView)).Editor
            Dim gridView As GridView = (CType(editor, GridListEditor)).GridView

            RemoveHandler gridView.SelectionChanged, AddressOf GridView_SelectionChanged
        End If
    End Sub
    Protected Overrides Sub OnViewControlsCreated()
        MyBase.OnViewControlsCreated()
        If View.Id = "GLCassa_ListView" Then
            Dim editor As ListEditor = (CType(View, ListView)).Editor
            Dim gridView As GridView = (CType(editor, GridListEditor)).GridView

            AddHandler gridView.SelectionChanged, AddressOf GridView_SelectionChanged
        End If

        'If View.Id = "GLRows_ListView_Cassa" Then
        '    Dim _ListView As ListView = CType(View, ListView)
        '    _GridListEditor = TryCast(_ListView.Editor, GridListEditor)
        '    If _GridListEditor IsNot Nothing Then
        '        _GridListEditor.AllowEdit = True

        '        For i As Integer = 0 To _GridListEditor.Columns.Count - 1

        '            If _GridListEditor.GridView.Columns(i).FieldName <> "NoteRows" And _
        '               _GridListEditor.GridView.Columns(i).FieldName <> "Controlling!" And _
        '               _GridListEditor.GridView.Columns(i).FieldName <> "CostHolder!" And _
        '               _GridListEditor.GridView.Columns(i).FieldName <> "CostPlace!" And _
        '               _GridListEditor.GridView.Columns(i).FieldName <> "JobNumberObjects!" And _
        '               _GridListEditor.GridView.Columns(i).FieldName <> "UniqueObjects!" Then
        '                _GridListEditor.GridView.Columns(i).OptionsColumn.ReadOnly = True
        '                _GridListEditor.GridView.Columns(i).OptionsColumn.AllowEdit = False
        '                _GridListEditor.GridView.Columns(i).OptionsColumn.TabStop = False
        '            End If

        '        Next

        '    End If
        'End If

    End Sub
    Private Sub GridView_SelectionChanged(ByVal sender As Object, ByVal e As DevExpress.Data.SelectionChangedEventArgs)
        Dim gridView As GridView = TryCast(sender, GridView)
        If View.SelectedObjects.Count = 1 Then
            Dim _GLCassa As GLCassa = TryCast(View.SelectedObjects(0), GLCassa)
            If _GLCassa Is Nothing Then
            Else
                Frame.GetController(Of DevExpress.ExpressApp.SystemModule.DeleteObjectsViewController).Active.SetItemValue("", True)
                If _GLCassa.IsEditable = False Then
                    Frame.GetController(Of DevExpress.ExpressApp.SystemModule.DeleteObjectsViewController).Active.SetItemValue("", False)
                End If
            End If
        ElseIf View.SelectedObjects.Count > 1 Then
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.DeleteObjectsViewController).Active.SetItemValue("", False)

        End If
    End Sub
End Class
