public void UpdateData()
        {
            // Rows
            int r = 2;

            foreach (var row in Rows)
            {
                var prop = row.Key;
                var expr = row.Value;

                int c = 2;
                foreach (var year in Years)
                {
                    int y = DocumentManager.CurrentDocument.City.C02 + year.Year;
                    if (year.IsEditable && IsRowEditable(row.Key))
                    {
                    }
                    else
                    {
                        double value = 0;
                        if (year.Year == YearDefinition.CodeForAverage)
                        {
                            var temp = Years.Where(x => YearDefinition.IsNormalYear(x.Year)).Select(x => expr[x.Year]).Where(x => !double.IsNaN(x));
                            value = temp.Count() > 0 ? temp.Average() : 0;
                        }
                        else if (year.Year == YearDefinition.CodeForSum)
                        {
                            var temp = Years.Where(x => YearDefinition.IsNormalYear(x.Year)).Select(x => expr[x.Year]).Where(x => !double.IsNaN(x));
                            value = temp.Count() > 0 ? temp.Sum() : 0;
                        }
                        else
                        {
                            value = expr.Year(y);
                        }
                        var border = _cells.First(x => x.Value.Row == r && x.Value.Col == c).Key as Border;
                        (border.Child as TextBlock).Text = double.IsNaN(value) ? "na" : FormatValue(prop, value);
                    }
                    c++;
                }
                r++;
            }
        }
        public void Render()
        {
            _cells.Clear();
            LayoutRoot.Children.Clear();
            LayoutBorder.BorderBrush = Brush_TableBorder;
            LayoutRoot.RowDefinitions.Clear();
            LayoutRoot.ColumnDefinitions.Clear();

            Enumerable.Range(0, Rows.Count() + 2).ToList().ForEach(i => LayoutRoot.RowDefinitions.Add(new RowDefinition()));
            Enumerable.Range(0, Years.Count() + 2).ToList().ForEach(i => LayoutRoot.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(GetColWidth(i))
            }));
            LayoutRoot.RowDefinitions[0].Height = new GridLength(25);

            // Row 1
            _cells.Add(Table.BuildTextBlock(SectionNumber, Brush_TitleCell, Brush_TitleCell, Brush_Title, true), new CellPosition(0, 0));
            _cells.Add(Table.BuildTextBlock(Title, Brush_TitleCell, Brush_TitleCell, Brush_Title), new CellPosition(0, 1, 1, Years.Count + 1));

            // Row 2
            _cells.Add(Table.BuildEmptyCell(Brush_Cell, Brush_CellBorder), new CellPosition(1, 0));
            _cells.Add(Table.BuildEmptyCell(Brush_Cell, Brush_CellBorder), new CellPosition(1, 1));
            Enumerable.Range(0, Years.Count).ToList().ForEach(i => _cells.Add(Table.BuildTextBlock(GetYearHeader(Years[i].Year), Brush_Cell, Brush_CellBorder, Brushes.White, true), new CellPosition(1, i + 2)));

            // Rows
            int r = 2;

            foreach (var row in Rows)
            {
                _cells.Add(Table.BuildTextBlock(row.Key.Last().ToString(), Brush_Cell, Brush_CellBorder, Brushes.White, true), new CellPosition(r, 0));
                _cells.Add(Table.BuildTextBlock(Table.GetRowDescription(row.Key), Brush_LabelCell, Brush_CellBorder, Brushes.White), new CellPosition(r, 1));

                var prop = row.Key;
                var expr = row.Value;

                int c = 2;
                foreach (var year in Years)
                {
                    int y = DocumentManager.CurrentDocument.City.C02 + year.Year;
                    if (year.IsEditable && IsRowEditable(row.Key))
                    {
                        var     valueString = FormatValue(prop, expr[y]);
                        TextBox tb          = Table.BuildTextBox(valueString, Brush_EditCell) as TextBox;
                        tb.GotFocus += (sender, e) =>
                        {
                            (sender as TextBox).BorderBrush     = Brushes.Black;
                            (sender as TextBox).BorderThickness = new Thickness(2);
                        };
                        tb.LostFocus += (sender, e) =>
                        {
                            (sender as TextBox).BorderBrush     = Brushes.WhiteSmoke;
                            (sender as TextBox).BorderThickness = new Thickness(0);

                            double num = 0;
                            double.TryParse((sender as TextBox).Text, out num);
                            if ((sender as TextBox).Text.Contains('%'))
                            {
                                if (double.TryParse((sender as TextBox).Text.Trim('%'), out num))
                                {
                                    num = Convert.ToDouble((sender as TextBox).Text.Trim('%')) / 100.0;
                                }
                            }
                            expr[y] = num;
                            (sender as TextBox).Text = FormatValue(prop, num);
                            base.OnUserInput(e);
                        };
                        _cells.Add(tb, new CellPosition(r, c));
                    }
                    else
                    {
                        double value = 0;
                        if (year.Year == YearDefinition.CodeForAverage)
                        {
                            var temp = Years.Where(x => YearDefinition.IsNormalYear(x.Year)).Select(x => row.Value[x.Year]).Where(x => !double.IsNaN(x));
                            value = temp.Count() > 0 ? temp.Average() : 0;
                            //value = row.Value.KnownYearsAverage;
                        }
                        else if (year.Year == YearDefinition.CodeForSum)
                        {
                            var temp = Years.Where(x => YearDefinition.IsNormalYear(x.Year)).Select(x => row.Value[x.Year]).Where(x => !double.IsNaN(x));
                            value = temp.Count() > 0 ? temp.Sum() : 0;
                            //value = row.Value.KnownYearsSum;
                        }
                        else
                        {
                            value = row.Value.Year(y);
                        }
                        _cells.Add(Table.BuildTextBlock(FormatValue(prop, value), Brush_Cell, Brush_CellBorder, Brushes.White), new CellPosition(r, c));
                    }
                    c++;
                }

                r++;
            }

            foreach (var cell in _cells)
            {
                Grid.SetRow(cell.Key, cell.Value.Row);
                Grid.SetRowSpan(cell.Key, cell.Value.RowSpan);
                Grid.SetColumn(cell.Key, cell.Value.Col);
                Grid.SetColumnSpan(cell.Key, cell.Value.ColSpan);
                LayoutRoot.Children.Add(cell.Key);
            }
        }