Пример #1
0
 private static void RunAllRowAndColCalcsForCellRecursive(CellVm cell, List<CalcExpressionVm> rowCalcs, List<CalcExpressionVm> colCalcs, GridVm grid)
 {
     var affectedRowCalcs = rowCalcs.Where(r => r.Operands.Any(o => o.RowCode == cell.RowCode && o.GridCode == cell.GridCode)).ToList();
     if (affectedRowCalcs.Any())
     {
         var col = grid.Columns.FirstOrDefault(c => c.ColCode == cell.ColCode);
         foreach (var rowCalc in affectedRowCalcs)
         {
             var expandedRowCalc = ExpandRowCalcForCol(rowCalc, col);
             var targetCell = col.Cells.FirstOrDefault(c => c.GridCode == expandedRowCalc.TargetGridCode && c.RowCode == expandedRowCalc.TargetRowCode);
             EvaluateExpressionAndAssign(expandedRowCalc, targetCell);
             if (UpdateContextIsCellValue(expandedRowCalc.UpdateContext))
             {
                 RunAllRowAndColCalcsForCellRecursive(targetCell, rowCalcs, colCalcs, grid);
             }
         }
     }
     var affectedColCalcs = colCalcs.Where(r => r.Operands.Any(o => o.ColCode == cell.ColCode && o.GridCode == cell.GridCode)).ToList();
     if (affectedColCalcs.Any())
     {
         var row = grid.Rows.FirstOrDefault(c => c.RowCode == cell.RowCode);
         foreach (var colCalc in affectedColCalcs)
         {
             var expandedColCalc = ExpandColCalcForRow(colCalc, row);
             var targetCell = row.Cells.FirstOrDefault(c => c.GridCode == expandedColCalc.TargetGridCode && c.ColCode == expandedColCalc.TargetColCode);
             EvaluateExpressionAndAssign(expandedColCalc, targetCell);
             if (UpdateContextIsCellValue(expandedColCalc.UpdateContext))
             {
                 RunAllRowAndColCalcsForCellRecursive(targetCell, rowCalcs, colCalcs, grid);
             }
         }
     }
 }
Пример #2
0
        private static void RunRowCalcSumChildrenLoop(RowVm targetRow, GridVm grid)
        {
            while (true)
            {
                var resultDic = new Dictionary<string, double>();
                //Go through operand rows and add up numeric and percent cells, saving into dictionary
                foreach (var operandRowCode in targetRow.ChildRowCodes)
                {
                    var operandRow = grid.Rows.FirstOrDefault(r => r.RowCode == operandRowCode);
                    if (operandRow == null) continue;
                    foreach (var cell in operandRow.Cells.Where(CellIsNumericOrPercent))
                    {
                        if (resultDic.ContainsKey(cell.ColCode))
                        {
                            resultDic[cell.ColCode] = resultDic[cell.ColCode] + GetCellValue(cell);
                        }
                        else
                        {
                            resultDic.Add(cell.ColCode, GetCellValue(cell));
                        }
                    }
                }

                foreach (var cell in targetRow.Cells.Where(CellIsNumericOrPercent))
                {
                    if(resultDic.ContainsKey(cell.ColCode)) cell.Value = FormatCellValue(resultDic[cell.ColCode], cell);
                }

                if (!string.IsNullOrEmpty(targetRow.ParentRowCode))
                {
                    var parentRow = grid.Rows.FirstOrDefault(r => r.RowCode == targetRow.ParentRowCode);
                    if (parentRow != null)
                    {
                        targetRow = parentRow;
                        continue;
                    }
                }
                break;
            }
        }
Пример #3
0
 private static void SetGridAttribsFromRowAttribs(GridVm grid, Attributes rowAttrib)
 {
     grid.HasSelectCol = (rowAttrib.CanSelect ?? false) || grid.HasSelectCol;
     grid.HasCollapseCol = (rowAttrib.CanCollapse ?? false) || grid.HasCollapseCol;
     grid.HasAddCol = (rowAttrib.CanAdd ?? false) || grid.HasAddCol;
     grid.HasDeleteCol = (rowAttrib.CanDelete ?? false) || grid.HasDeleteCol;
 }
Пример #4
0
        private static int GetCellSpan(GridVm grid, RowVm row, ColumnVm col, int? cellSpanAttrib)
        {
            if (row.Type != Literals.Attribute.RowType.Header && row.Type != Literals.Attribute.RowType.Blank) return cellSpanAttrib ?? col.ColSpan;

            if (col.ColCode != Literals.UniversalColCode.RowText) return 0;

            var span = grid.Columns.Count(c => c.Level == 0 && !c.IsHidden);
            span += (grid.HasSelectCol ? 1 : 0) + (grid.HasCollapseCol ? 1 : 0) + (grid.HasAddCol ? 1 : 0) + (grid.HasDeleteCol ? 1 : 0);
            return span;
        }
Пример #5
0
 private static CellVm BuildCellVmFromAttributes(GridVm grid, RowVm row, ColumnVm col, Attributes cellAttrib)
 {
     var overrideColSettings = cellAttrib.OverrideColSettings ?? false;
     var cellType = overrideColSettings ? cellAttrib.Type            : col.Type;
     var decimals = overrideColSettings ? cellAttrib.DecimalPlaces   : col.DecimalPlaces;
     var maxChars = overrideColSettings ? cellAttrib.MaxChars        : col.MaxChars;
     var cellVal = cellAttrib.Value;
     var textColor = "";
     if (row.Type != Literals.Attribute.RowType.Blank && (IsNumericOrPercentType(cellType)))
     {
         double parsedNum;
         var parsed = double.TryParse(cellAttrib.Value, out parsedNum);
         if (parsed)
         {
             cellVal = String.Format("{0:n" + decimals + "}", parsedNum);
             //if (parsedNum < 0) textColor = "red";
         }
     }
     if (!string.IsNullOrEmpty(cellAttrib.HoverBase)) textColor = "green";
     if (!string.IsNullOrEmpty(cellAttrib.HoverAddition))
     {
         double parsedHoverAddition;
         var parsed = double.TryParse(cellAttrib.HoverAddition, out parsedHoverAddition);
         if (parsed && parsedHoverAddition != 0)
         {
             textColor = "red";
         }
     }
     //var valParsed = double.TryParse(cellVal, out numval);
     var span = cellAttrib.ColSpan ?? col.ColSpan;
     return new CellVm()
     {
         GridCode = grid.GridCode,
         RowCode = row.RowCode,
         ColCode = col.ColCode,
         Type = cellType,
         MaxChars = maxChars,
         DecimalPlaces = decimals,
         ColSpan = GetCellSpan(grid, row, col, cellAttrib.ColSpan),
         ColumnHeader = col.DisplayText,
         Indent = cellAttrib.Indent ?? 0,
         IsEditable = (cellAttrib.IsEditable ?? false) && row.IsEditable && col.IsEditable && grid.IsEditable,
         //IsHidden = cellAttrib.IsHidden ?? false,  //todo: DisplayInCycle
         IsHidden = cellAttrib.DisplayInCycle == "None",
         Value = cellVal,
         //NumValue = valParsed ? numval : 0,
         Width = (span == 1 ? col.Width : "100%"),
         Alignment = cellAttrib.Alignment ?? "right",
         HoverBase = cellAttrib.HoverBase,
         HoverAddition = cellAttrib.HoverAddition,
         TextColor = textColor,
         Calcs = null
     };
 }