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.XtraGrid.Views.Grid
Imports DevExpress.XtraGrid.Columns

Public Class GLBaseVC
    Inherits Nuvolar.Module.GLBaseVC
    Dim _WaitFormClass as New WaitFormClass
    Private _GridView As GridView
    Public Sub New()
        MyBase.New()

        'This call is required by the Component Designer.
        InitializeComponent()
        RegisterActions(components)

    End Sub
    Protected Overrides Sub OnActivated()
        MyBase.OnActivated()
        AddHandler DoWork, AddressOf _WaitFormClass.DoWork
        AddHandler InitWork, AddressOf _WaitFormClass.Initwork
        AddHandler FinalWork, AddressOf _WaitFormClass.Finalwork
        If View.Id = "GLDetails_ListView" Then
            AddHandler View.ControlsCreated, AddressOf View_ControlsCreated
        End If
    End Sub
    Protected Overrides Sub OnDeactivated()
        MyBase.OnDeactivated()
        RemoveHandler DoWork, AddressOf _WaitFormClass.DoWork
        RemoveHandler InitWork, AddressOf _WaitFormClass.Initwork
        RemoveHandler FinalWork, AddressOf _WaitFormClass.Finalwork
    End Sub

    Private Sub View_ControlsCreated(sender As Object, e As EventArgs)
        Dim _GridListEditor As GridListEditor = DirectCast(DirectCast(View, ListView).Editor, GridListEditor)

        _GridView = DirectCast(DirectCast(View, ListView).Editor, GridListEditor).GridView

        If _GridView IsNot Nothing Then
            'Dim unbColumn As GridColumn = _GridView.Columns.AddField("AmountHUF_Rolling")
            'unbColumn.VisibleIndex = _GridView.Columns.Count
            'unbColumn.UnboundType = DevExpress.Data.UnboundColumnType.Decimal
            'unbColumn.OptionsColumn.AllowEdit = False
            'unbColumn.DisplayFormat.FormatString = "{0:#,##0}"


        End If
    End Sub

    

    Private Sub aUpdateRolling_Execute(sender As Object, e As SimpleActionExecuteEventArgs) Handles aUpdateRolling.Execute

        Dim _Prev_AccountNumber As String = ""
        Dim _Act_AccountNumber As String = ""
        Dim _AmountHUF_Rolling As Double = 0
        Try
            Dim _DataRowCount As Integer = _GridView.DataRowCount

            _WaitFormClass.Initwork(1, 1, _DataRowCount)
            For i = 0 To _DataRowCount - 1
                _WaitFormClass.DoWork()
                Dim _GLDetails As GLDetails = TryCast(_GridView.GetRow(i), GLDetails)
                _Act_AccountNumber = _GLDetails.ChartOfAccounts.AccountNumber
                If _Act_AccountNumber <> _Prev_AccountNumber Then
                    _AmountHUF_Rolling = 0
                    _Prev_AccountNumber = _Act_AccountNumber
                End If
                _AmountHUF_Rolling += _GLDetails.AmountHUF_Ballance
                _GLDetails.AmountHUF_Rolling = _AmountHUF_Rolling
            Next
        Finally
            _Waitformclass.FinalWork
        End Try
    End Sub
End Class
