예제 #1
0
 private static bool CellIsNumericOrPercent(CellVm cell)
 {
     return
         String.Equals(cell.Type, Literals.Attribute.ColCellType.Numeric,
             StringComparison.CurrentCultureIgnoreCase) ||
         String.Equals(cell.Type, Literals.Attribute.ColCellType.Numeric,
             StringComparison.CurrentCultureIgnoreCase);
 }
예제 #2
0
 private static void FormatCellHoverAddition(double value, CellVm cellVm)
 {
     var hoverAddition = "";
     var textColor = "";
     if (value == 0)
     {
         textColor = "blue";
         hoverAddition = "<div class='delta-balanced'>In Balance</div>";
     }
     else if (value < 0)
     {
         textColor = "red";
         hoverAddition = "<div class='delta-negative'>" + FormatCellValue(value, cellVm) + "</div>";
     }
     else
     {
         textColor = "red";
         hoverAddition = "<div class='delta-positive'>" + FormatCellValue(value, cellVm) + "</div>";
     }
     cellVm.TextColor = textColor;
     cellVm.HoverAddition = hoverAddition;
 }
예제 #3
0
 private static string FormatCellValue(double value, CellVm cellVm)
 {
     return cellVm.DecimalPlaces != null ? String.Format("{0:n" + cellVm.DecimalPlaces + "}", value) : String.Format("{0:n0}", value);
 }
예제 #4
0
 private static void EvaluateExpressionAndAssign(CalcExpressionVm calcVm, CellVm targetCell)
 {
     var expr = new CalcEngine.CalcEngine();
     var result = (double)expr.Evaluate(calcVm.Expression);
     if (UpdateContextIsCellValue(calcVm.UpdateContext))
     {
         targetCell.Value = FormatCellValue(result, targetCell);
     }
     else
     {
         FormatCellHoverAddition(result, targetCell);
     }
 }
예제 #5
0
 private static double GetCellValue(CellVm cell)
 {
     if (cell == null) return 0;
     double cellValue;
     var parsed = double.TryParse(cell.Value, out cellValue);
     if (!parsed) return 0;
     if (String.Equals(cell.Type, Literals.Attribute.ColCellType.Percent, StringComparison.CurrentCultureIgnoreCase))
     {
         cellValue = cellValue / 100;
     }
     return cellValue;
 }
예제 #6
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);
             }
         }
     }
 }
예제 #7
0
 private static bool CellIsOperandOfCalc(CellVm cell, UspGetCalcs_Result calcResult)
 {
     return cell.GridCode == calcResult.GridCode && cell.RowCode == calcResult.RowCode && cell.ColCode == calcResult.ColCode;
 }
예제 #8
0
 private static bool CellIsTargetOfCalc(CellVm cell, UspGetCalcs_Result calcResult)
 {
     return cell.GridCode == calcResult.TargetGridCode && cell.RowCode == calcResult.TargetRowCode && cell.ColCode == calcResult.TargetColCode;
 }