Beispiel #1
0
 private static bool ColumnIsNumericOrPercent(ColumnVm cell)
 {
     return
         String.Equals(cell.Type, Literals.Attribute.ColCellType.Numeric,
             StringComparison.CurrentCultureIgnoreCase) ||
         String.Equals(cell.Type, Literals.Attribute.ColCellType.Percent,
             StringComparison.CurrentCultureIgnoreCase);
 }
Beispiel #2
0
 private static void RunRowCalcRecursive(CalcExpressionVm calcToRun, List<CalcExpressionVm> allRowCalcs, ColumnVm col)
 {
     var expandedRowCalc = ExpandRowCalcForCol(calcToRun, col);
     var targetCell = col.Cells.FirstOrDefault(c => c.GridCode == expandedRowCalc.TargetGridCode && c.RowCode == expandedRowCalc.TargetRowCode && c.ColCode == expandedRowCalc.TargetColCode);
     if (targetCell == null) return;
     EvaluateExpressionAndAssign(expandedRowCalc, targetCell);
     if (!UpdateContextIsCellValue(calcToRun.UpdateContext)) return;
     var cascadedRowCalcs = allRowCalcs.Where(c => c.Operands.Any(o => o.GridCode == targetCell.GridCode && o.RowCode == targetCell.RowCode)).ToList();
     if (cascadedRowCalcs.Any())
     {
         cascadedRowCalcs.ForEach(cc => 
         {
             RunRowCalcRecursive(cc, allRowCalcs, col);
         });
     }
 }
Beispiel #3
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;
        }
Beispiel #4
0
 private static CalcExpressionVm ExpandRowCalcForCol(CalcExpressionVm rowCalc, ColumnVm col)
 {
     var calc =  new CalcExpressionVm()
     {
         TargetGridCode = rowCalc.TargetGridCode,
         TargetColCode = col.ColCode,
         TargetRowCode = rowCalc.TargetRowCode,
         Expression = rowCalc.Expression.Split('.').Aggregate((c, n) => n == "" ? c + "." + col.ColCode + n : c + "." + n),
         UpdateContext = rowCalc.UpdateContext,
         Operands = rowCalc.Operands.Select(o => new CalcOperandVm()
         {
             GridCode = o.GridCode,
             ColCode = col.ColCode,
             RowCode = o.RowCode
         }).ToList()
     };
     foreach (var operand in calc.Operands)
     {
         var cell = col.Cells.FirstOrDefault(c => c.GridCode == operand.GridCode && c.RowCode == operand.RowCode && c.ColCode == operand.ColCode);
         var cellValue = GetCellValue(cell);
         var operandToken = GetCellToken(operand.GridCode, operand.RowCode, operand.ColCode);
         calc.Expression = calc.Expression.Replace(operandToken, cellValue.ToString());
     }
     return calc;
 }
Beispiel #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
     };
 }