BudgetAnalyser.LedgerBook.LedgerBookGridBuilderV2.DynamicallyCreateLedgerBookGrid C# (CSharp) Method

DynamicallyCreateLedgerBookGrid() private method

private DynamicallyCreateLedgerBookGrid ( int numberOfMonthsToShow ) : void
numberOfMonthsToShow int
return void
        private void DynamicallyCreateLedgerBookGrid(int numberOfMonthsToShow)
        {
            if (this.ledgerBook == null)
            {
                this.contentPresenter = null;
                return;
            }

            // Sort ledgers so that the ledgers in the same bank account are grouped together
            // this.sortedLedgers = this.ledgerBook.Ledgers.OrderBy(l => l.StoredInAccount.Name).ThenBy(l => l.BudgetBucket.Code).ToList();
            this.sortedLedgers = this.ledgerBook.Reconciliations.SelectMany(line => line.Entries).Select(e => e.LedgerBucket)
                .OrderBy(l => l.StoredInAccount.Name).ThenBy(l => l.BudgetBucket.Code)
                .Distinct()
                .ToList();

            var grid = new Grid();
            // Date
            grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
            // Ledgers 
            AddLedgerRows(grid);
            // Surplus
            grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
            // Adjustments
            grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
            // Ledger Balance
            grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
            // Remarks
            grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
            // Bank account heading lines
            this.sortedLedgers.Select(l => l.StoredInAccount).Distinct().ToList().ForEach(x => grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }));

            this.contentPresenter.Content = grid;
            AddGridColumns(grid, numberOfMonthsToShow);

            AddHeadingColumnContent(grid);
            AddLedgerEntryLinesVertically(grid, numberOfMonthsToShow);

            AddShowMoreLessColumnsButtons(grid, numberOfMonthsToShow);
        }